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

63 lines
1.4 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
2025-01-28 23:23:42 +03:00
import { IconSearch } from '@/components/Icons';
import { type Styling } from '@/components/props';
2025-01-28 23:23:42 +03:00
2025-02-12 15:13:37 +03:00
import { TextInput } from './TextInput';
interface SearchBarProps extends 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.
*/
2025-02-07 10:54:47 +03:00
export function SearchBar({
id,
query,
noIcon,
onChangeQuery,
noBorder,
2025-03-07 20:38:40 +03:00
className,
placeholder = 'Поиск',
...restProps
}: SearchBarProps) {
2023-11-06 02:20:16 +03:00
return (
2025-03-07 20:38:40 +03:00
<div className={clsx('relative', className)} {...restProps}>
{!noIcon ? (
2025-03-07 20:38:40 +03:00
<IconSearch
className='absolute top-[-0.125rem] left-3 translate-y-1/2 pointer-events-none clr-text-controls'
size='1.25rem'
/>
) : null}
2023-12-28 14:04:44 +03:00
<TextInput
id={id}
2023-12-28 14:04:44 +03:00
noOutline
2025-02-22 14:04:01 +03:00
transparent
placeholder={placeholder}
type='search'
2025-02-22 14:04:01 +03:00
className={clsx('bg-transparent', !noIcon && 'pl-10')}
2023-12-28 14:04:44 +03:00
noBorder={noBorder}
value={query}
onChange={event => onChangeQuery?.(event.target.value)}
2023-12-28 14:04:44 +03:00
/>
</div>
);
2023-11-06 02:20:16 +03:00
}