Portal/rsconcept/frontend/src/components/Input/SearchBar.tsx

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
import { Overlay } from '@/components/Container';
2025-01-28 23:23:03 +03:00
import { IconSearch } from '@/components/Icons';
import { CProps } from '@/components/props';
2025-02-12 15:12:59 +03:00
import { TextInput } from './TextInput';
2024-06-07 20:17:03 +03:00
interface SearchBarProps extends CProps.Styling {
/** Id of the search bar. */
2024-06-07 20:17:03 +03:00
id?: string;
/** Search query. */
query: string;
/** Placeholder text. */
2024-06-07 20:17:03 +03:00
placeholder?: string;
/** Callback to be called when the search query changes. */
onChangeQuery?: (newValue: string) => void;
/** Disable search icon. */
noIcon?: boolean;
/** Disable border. */
2024-06-07 20:17:03 +03:00
noBorder?: boolean;
}
/**
* Displays a search bar with a search icon and text input.
*/
2025-02-07 10:53:49 +03:00
export function SearchBar({
id,
query,
noIcon,
onChangeQuery,
noBorder,
placeholder = 'Поиск',
...restProps
}: SearchBarProps) {
2024-06-07 20:17:03 +03:00
return (
<div {...restProps}>
{!noIcon ? (
<Overlay position='top-[-0.125rem] left-3 translate-y-1/2' className='pointer-events-none clr-text-controls'>
<IconSearch size='1.25rem' />
</Overlay>
) : null}
<TextInput
id={id}
noOutline
placeholder={placeholder}
type='search'
2024-09-21 20:03:49 +03:00
className={clsx('outline-none bg-transparent', !noIcon && 'pl-10')}
2024-06-07 20:17:03 +03:00
noBorder={noBorder}
value={query}
onChange={event => onChangeQuery?.(event.target.value)}
2024-06-07 20:17:03 +03:00
/>
</div>
);
}