ConceptPortal-public/rsconcept/frontend/src/components/ui/SearchBar.tsx

62 lines
1.4 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
2024-05-02 17:04:18 +03:00
import { IconSearch } from '../Icons';
import { CProps } from '../props';
2023-12-08 19:24:08 +03:00
import Overlay from './Overlay';
2023-11-06 02:20:16 +03:00
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. */
2023-12-28 14:04:44 +03:00
noBorder?: boolean;
2023-11-06 02:20:16 +03:00
}
/**
* Displays a search bar with a search icon and text input.
*/
function SearchBar({
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}>
{!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
id={id}
2023-12-28 14:04:44 +03:00
noOutline
placeholder={placeholder}
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}
value={query}
onChange={event => (onChangeQuery ? onChangeQuery(event.target.value) : undefined)}
2023-12-28 14:04:44 +03:00
/>
</div>
);
2023-11-06 02:20:16 +03:00
}
export default SearchBar;