/*! Strand UI | MIT License | dillingerstaffing.com */ import type { JSX } from "preact"; import { forwardRef } from "preact/compat"; import { cx } from "../../internal/index.js"; export interface SearchFieldProps extends Omit, "size" | "onInput"> { /** `field` is the fixed-width header presentation; `full` spans its container. Choose per breakpoint with the hide utilities, never by measuring in JS. */ variant?: "field" | "full"; /** Name real content. */ placeholder?: string; value?: string; /** Accessible name; a placeholder is not one. */ label?: string; /** Called with the value on every keystroke. */ onValueChange?: (value: string) => void; /** Renders a clear control while the field is non-empty; needs `value`. */ onClear?: () => void; /** Merged onto the wrapper. */ className?: string; } /** * A search input for page chrome, a `role="search"` landmark that renders its geometry with no JavaScript. Not the map overlay `.strand-search-bar`. * * @example * setQ("")} /> */ export const SearchField = forwardRef( ({ variant = "field", placeholder = "Search", label = "Search", value, onValueChange, onClear, className = "", ...rest }, ref) => { const clearable = Boolean(onClear) && typeof value === "string"; const hasValue = typeof value === "string" && value.length > 0; return (
onValueChange?.((event.currentTarget as HTMLInputElement).value)} {...rest} /> {clearable && ( )}
); }, ); SearchField.displayName = "SearchField";