2024-06-07 20:17:03 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
|
2025-03-12 12:04:23 +03:00
|
|
|
import { IconSearch } from '@/components/icons';
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type Styling } from '@/components/props';
|
2025-04-12 21:47:46 +03:00
|
|
|
|
|
|
|
|
import { cn } from '../utils';
|
|
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface SearchBarProps extends Styling {
|
2024-11-21 15:09:31 +03:00
|
|
|
/** Id of the search bar. */
|
2024-06-07 20:17:03 +03:00
|
|
|
id?: string;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
|
/** Search query. */
|
|
|
|
|
query: string;
|
|
|
|
|
|
|
|
|
|
/** Placeholder text. */
|
2024-06-07 20:17:03 +03:00
|
|
|
placeholder?: string;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 15:09:31 +03:00
|
|
|
/**
|
|
|
|
|
* Displays a search bar with a search icon and text input.
|
|
|
|
|
*/
|
2025-02-07 10:53:49 +03:00
|
|
|
export function SearchBar({
|
2024-11-21 15:09:31 +03:00
|
|
|
id,
|
|
|
|
|
query,
|
|
|
|
|
noIcon,
|
|
|
|
|
onChangeQuery,
|
|
|
|
|
noBorder,
|
2025-03-07 16:21:18 +03:00
|
|
|
className,
|
2024-11-21 15:09:31 +03:00
|
|
|
placeholder = 'Поиск',
|
|
|
|
|
...restProps
|
|
|
|
|
}: SearchBarProps) {
|
2024-06-07 20:17:03 +03:00
|
|
|
return (
|
2025-04-12 21:47:46 +03:00
|
|
|
<div className={cn('relative flex items-center grow', className)} {...restProps}>
|
2024-06-07 20:17:03 +03:00
|
|
|
{!noIcon ? (
|
2025-03-20 18:24:07 +03:00
|
|
|
<IconSearch className='absolute -top-0.5 left-2 translate-y-1/2 cc-search-icon' size='1.25rem' />
|
2024-06-07 20:17:03 +03:00
|
|
|
) : null}
|
2025-04-08 22:27:34 +03:00
|
|
|
<input
|
2024-06-07 20:17:03 +03:00
|
|
|
id={id}
|
|
|
|
|
type='search'
|
2025-04-08 22:27:34 +03:00
|
|
|
className={clsx(
|
|
|
|
|
'min-w-0 py-2',
|
|
|
|
|
'leading-tight truncate hover:text-clip',
|
|
|
|
|
'bg-transparent',
|
|
|
|
|
!noIcon && 'pl-8',
|
|
|
|
|
!noBorder && 'border px-3'
|
|
|
|
|
)}
|
2024-11-21 15:09:31 +03:00
|
|
|
value={query}
|
2025-02-19 22:32:50 +03:00
|
|
|
onChange={event => onChangeQuery?.(event.target.value)}
|
2025-04-08 22:27:34 +03:00
|
|
|
placeholder={placeholder}
|
2024-06-07 20:17:03 +03:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|