mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import clsx from 'clsx';
|
|
|
|
import { Overlay } from '@/components/Container';
|
|
import { IconSearch } from '@/components/Icons';
|
|
import { CProps } from '@/components/props';
|
|
|
|
import { TextInput } from './TextInput';
|
|
|
|
interface SearchBarProps extends CProps.Styling {
|
|
/** Id of the search bar. */
|
|
id?: string;
|
|
|
|
/** Search query. */
|
|
query: string;
|
|
|
|
/** Placeholder text. */
|
|
placeholder?: string;
|
|
|
|
/** Callback to be called when the search query changes. */
|
|
onChangeQuery?: (newValue: string) => void;
|
|
|
|
/** Disable search icon. */
|
|
noIcon?: boolean;
|
|
|
|
/** Disable border. */
|
|
noBorder?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Displays a search bar with a search icon and text input.
|
|
*/
|
|
export function SearchBar({
|
|
id,
|
|
query,
|
|
noIcon,
|
|
onChangeQuery,
|
|
noBorder,
|
|
placeholder = 'Поиск',
|
|
...restProps
|
|
}: SearchBarProps) {
|
|
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'
|
|
className={clsx('outline-none bg-transparent', !noIcon && 'pl-10')}
|
|
noBorder={noBorder}
|
|
value={query}
|
|
onChange={event => (onChangeQuery ? onChangeQuery(event.target.value) : undefined)}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|