2024-06-02 23:41:46 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { Overlay } from '@/components/Container';
|
2025-01-28 23:23:42 +03:00
|
|
|
import { IconSearch } from '@/components/Icons';
|
|
|
|
import { CProps } from '@/components/props';
|
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
import { TextInput } from './TextInput';
|
|
|
|
|
2024-01-04 19:30:10 +03:00
|
|
|
interface SearchBarProps extends CProps.Styling {
|
2024-11-21 15:09:51 +03:00
|
|
|
/** Id of the search bar. */
|
2024-03-18 16:21:39 +03:00
|
|
|
id?: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Search query. */
|
|
|
|
query: string;
|
|
|
|
|
|
|
|
/** Placeholder text. */
|
2024-06-02 23:41:46 +03:00
|
|
|
placeholder?: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Callback to be called when the search query changes. */
|
|
|
|
onChangeQuery?: (newValue: string) => void;
|
|
|
|
|
|
|
|
/** Disable search icon. */
|
|
|
|
noIcon?: boolean;
|
|
|
|
|
|
|
|
/** Disable border. */
|
2023-12-28 14:04:44 +03:00
|
|
|
noBorder?: boolean;
|
2023-11-06 02:20:16 +03:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:09:51 +03:00
|
|
|
/**
|
|
|
|
* Displays a search bar with a search icon and text input.
|
|
|
|
*/
|
2025-02-07 10:54:47 +03:00
|
|
|
export function SearchBar({
|
2024-11-21 15:09:51 +03:00
|
|
|
id,
|
|
|
|
query,
|
|
|
|
noIcon,
|
|
|
|
onChangeQuery,
|
|
|
|
noBorder,
|
|
|
|
placeholder = 'Поиск',
|
|
|
|
...restProps
|
|
|
|
}: SearchBarProps) {
|
2023-11-06 02:20:16 +03:00
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<div {...restProps}>
|
2024-06-02 23:41:46 +03:00
|
|
|
{!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}
|
2023-12-28 14:04:44 +03:00
|
|
|
<TextInput
|
2024-03-18 16:21:39 +03:00
|
|
|
id={id}
|
2023-12-28 14:04:44 +03:00
|
|
|
noOutline
|
2024-06-02 23:41:46 +03:00
|
|
|
placeholder={placeholder}
|
2024-01-04 19:30:10 +03:00
|
|
|
type='search'
|
2024-09-21 20:04:07 +03:00
|
|
|
className={clsx('outline-none bg-transparent', !noIcon && 'pl-10')}
|
2023-12-28 14:04:44 +03:00
|
|
|
noBorder={noBorder}
|
2024-11-21 15:09:51 +03:00
|
|
|
value={query}
|
2025-02-19 22:33:09 +03:00
|
|
|
onChange={event => onChangeQuery?.(event.target.value)}
|
2023-12-28 14:04:44 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2023-11-06 02:20:16 +03:00
|
|
|
}
|