Portal/rsconcept/frontend/src/components/input/search-bar.tsx

63 lines
1.4 KiB
TypeScript
Raw Normal View History

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 {
/** Id of the search bar. */
2024-06-07 20:17:03 +03:00
id?: string;
/** Search query. */
query: string;
/** Placeholder text. */
2024-06-07 20:17:03 +03:00
placeholder?: string;
/** 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;
}
/**
* Displays a search bar with a search icon and text input.
*/
2025-02-07 10:53:49 +03:00
export function SearchBar({
id,
query,
noIcon,
onChangeQuery,
noBorder,
2025-03-07 16:21:18 +03:00
className,
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'
)}
value={query}
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>
);
}