import * as React from "react" import { SearchIcon, XIcon } from "lucide-react" import { cn } from "../lib/utils" /** Поле поиска на мягкой подложке: иконка, крестик очистки. */ export const SearchInput = React.forwardRef< HTMLInputElement, Omit, "value" | "onChange" | "size"> & { value: string onValueChange: (value: string) => void size?: "sm" | "md" | "lg" /** Что показать справа, пока поле пустое (подсказка клавиши). */ trailing?: React.ReactNode } >(function SearchInput({ value, onValueChange, size = "md", trailing, className, onKeyDown, ...props }, ref) { const innerRef = React.useRef(null) React.useImperativeHandle(ref, () => innerRef.current!) return (
onValueChange(e.target.value)} onKeyDown={(e) => { if (e.key === "Escape" && value) { e.stopPropagation() onValueChange("") } onKeyDown?.(e) }} className={cn( "w-full rounded-lg border border-transparent bg-muted/70 transition outline-none placeholder:text-muted-foreground/80 [&::-webkit-search-cancel-button]:hidden", "focus:border-primary/40 focus:bg-card focus:ring-4 focus:ring-primary/10", size === "sm" && "h-8 pr-8 pl-9 text-sm", size === "md" && "h-9 pr-8 pl-9 text-sm", size === "lg" && "h-12 rounded-xl pr-12 pl-12 text-base", )} {...props} />
{value ? ( ) : ( trailing )}
) })