import { Show, createSignal, createUniqueId } from "solid-js"; import { IconSearch, IconX } from "@/components/ui/icons"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/cn"; import { useT } from "@/stores/preferences-context"; export type DataTableSearchProps = { value: string; onChange: (value: string) => void; placeholder?: string; /** * What this particular box actually matches on, in the user's words. Shown * under the field while it has focus — a placeholder alone never says * whether a name, a code or a description is the thing to type. Keep it * honest: it must list what the filter really reads, nothing more. */ hint?: string; /** Optional styling for the focused hint, e.g. a wider panel search hint. */ hintClass?: string; onKeyDown?: (event: KeyboardEvent) => void; class?: string; }; /** Rounded search field: leading icon, conditional clear (X) button, Escape to * empty it, and an optional on-focus hint naming the fields it searches. */ export function DataTableSearch(props: DataTableSearchProps) { const t = useT(); const [focused, setFocused] = createSignal(false); const hintId = createUniqueId(); return (
setFocused(true)} onFocusOut={() => setFocused(false)} > props.onChange(event.currentTarget.value)} // Escape empties the box instead of only blurring it: a filter the // keyboard cannot undo leaves the list silently narrowed. onKeyDown={(event: KeyboardEvent) => { props.onKeyDown?.(event); if (event.defaultPrevented) return; if (event.key !== "Escape" || !props.value) return; event.preventDefault(); event.stopPropagation(); props.onChange(""); }} placeholder={props.placeholder ?? t("common.search")} aria-describedby={props.hint ? hintId : undefined} class={cn("h-8 rounded-lg bg-muted/40 text-[13px] md:text-[13px]", props.value ? "pl-9 pr-8" : "pl-9")} /> {/* Floated rather than inline: a static line would push every toolbar that carries a search box taller, on every page. */}

{props.hint}

); }