-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Rudnicki
committed
Sep 5, 2024
1 parent
5325511
commit 0c0ee71
Showing
6 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
designer/client/src/components/themed/InputWithAdvancedSearchOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { css, cx } from "@emotion/css"; | ||
import { styled, useTheme } from "@mui/material"; | ||
import React, { forwardRef, PropsWithChildren, ReactElement, useCallback, useImperativeHandle, useRef } from "react"; | ||
import { AdvancedOptionsIcon, ClearIcon } from "../table/SearchFilter"; | ||
import { InputProps, ThemedInput } from "./ThemedInput"; | ||
|
||
type Props = PropsWithChildren<InputProps> & { | ||
onClear?: () => void; | ||
onAddonClick?: () => void; | ||
}; | ||
|
||
export type Focusable = { | ||
focus: (options?: FocusOptions) => void; | ||
}; | ||
|
||
export const InputWithAdvancedSearchOptions = forwardRef<Focusable, Props>(function InputWithIcon( | ||
{ children, onAddonClick, onClear, ...props }, | ||
forwardedRef, | ||
): ReactElement { | ||
const theme = useTheme(); | ||
|
||
const size = theme.custom.spacing.controlHeight; | ||
|
||
const wrapperWithAddonStyles = css({ | ||
position: "relative", | ||
display: "flex", | ||
flexDirection: "row", | ||
}); | ||
|
||
const addonWrapperStyles = css({ | ||
position: "absolute", | ||
top: 0, | ||
right: 0, | ||
height: size, | ||
display: "flex", | ||
padding: size / 4, | ||
}); | ||
|
||
const addonStyles = css({ | ||
display: "flex", | ||
width: size / 2, | ||
height: size / 2, | ||
marginLeft: size / 4, | ||
}); | ||
|
||
const ref = useRef<HTMLInputElement>(); | ||
const focus = useCallback( | ||
(options?: FocusOptions) => { | ||
const input = ref.current; | ||
input.focus({ preventScroll: true }); | ||
input.setSelectionRange(0, props.value.length); | ||
setTimeout(() => { | ||
if (options?.preventScroll) return; | ||
input.scrollIntoView({ behavior: "smooth", block: "center" }); | ||
}, theme.transitions.duration.standard); | ||
}, | ||
[props.value.length, theme.transitions.duration.standard], | ||
); | ||
|
||
useImperativeHandle(forwardedRef, () => ({ focus }), [focus]); | ||
|
||
return ( | ||
<div className={cx(children && wrapperWithAddonStyles)}> | ||
<ThemedInput ref={ref} {...props} /> | ||
<div className={addonWrapperStyles}> | ||
{!!props.value && onClear && ( | ||
<div className={addonStyles} onClick={onClear}> | ||
<ClearIcon /> | ||
</div> | ||
)} | ||
{children && ( | ||
<div className={addonStyles} onClick={onAddonClick ?? (() => focus())}> | ||
{children} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
designer/client/src/components/toolbars/search/AdvancedSearchOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from "react"; | ||
|
||
export function AdvancedSearchOptions() { | ||
return <p>ADVANCED_SEARCH_OPTIONS</p>; | ||
} |
22 changes: 16 additions & 6 deletions
22
designer/client/src/components/toolbars/search/SearchPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters