import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; export type HeaderSearchResult = { /** Unique result identifier; used as the each-block key when provided */ id?: string | number; href: string; text: string; description?: string; }; export type CarbonSearchMenuContext = { query: import("svelte/store").Writable; shouldFilter: import("svelte/store").Writable; match: import("svelte/store").Writable<(text: string, query: string) => { matched: boolean; indices?: number[] }>; highlightedId: import("svelte/store").Writable; setActiveId: (next: string | null) => void; selectItem: (detail: { value: string; item: { text?: string; value?: string; href?: string }; event: Event }) => void; hasPrimaryItems: import("svelte/store").Writable; registerItem: (itemId: string, filterable: boolean, inDividerGroup?: boolean) => void; unregisterItem: (itemId: string) => void; }; type $RestProps = SvelteHTMLElements["input"]; type $Props = { /** * Specify the search input value. * @default "" */ value?: string; /** * Set to `true` to activate and focus the search bar. * @default false */ active?: boolean; /** * Obtain a reference to the input HTML element. * @default null */ ref?: null | HTMLInputElement; /** * Render a list of search results. * @default [] */ results?: ReadonlyArray; /** * Specify the selected result index. * @default 0 */ selectedResultIndex?: number; /** * Specify the icon to render for the search trigger. * @default IconSearch */ icon?: Icon; /** * Specify the `placeholder` attribute of the search input. * @default "Search..." */ placeholder?: string; /** * Specify the text for the assistive label associated with the search input. * @default "Search" */ labelText?: string; /** * Specify the label for the clear button. * @default "Clear search input" */ closeButtonLabelText?: string; /** * Specify a keyboard shortcut that opens the search and focuses it, such * as `"mod+k"` or `"/"`. `mod` is Command on Apple platforms and Ctrl * elsewhere. The closed search button shows the keys in its tooltip and * gets `aria-keyshortcuts`. * @default "" */ shortcut?: string; /** * Set to `true` to filter `menu`-slot items by the search value using fuzzy * matching. Requires the `menu` slot; ignored when using the `results` prop. * @default true */ shouldFilter?: boolean; /** * Override how the search value is matched against each `menu`-slot item's * `text`. Receives the item `text` and the current search value, and returns * whether the item `matched` along with the `indices` of characters to * highlight. Defaults to fuzzy matching. Requires the `menu` slot. * @default fuzzyMatch */ match?: (text: string, query: string) => { matched: boolean; indices?: number[] }; /** * Set to `true` to render a skeleton menu while results are loading. * Override the placeholder rows with the `loading` slot. Requires the * `menu` slot. * @default false */ loading?: boolean; /** * Number of skeleton rows while `loading`. Requires the `menu` slot. * @default 4 */ skeletonCount?: number; /** * Row density for the `menu` slot. Result text stays flush with the header * input; smaller sizes shorten rows to fit more results. * @default "sm" */ size?: "sm" | "lg" | "xl"; /** * Set to `true` to select the input's text when it receives focus * @default false */ selectTextOnFocus?: boolean; /** * Milliseconds to wait after the last input before dispatching `search`. * 0 (default) does not dispatch `search`. `value` stays immediate; only * `search` waits. Selecting a result or submitting cancels a pending * `search` instead of also firing it. Clearing is always instant. * @default 0 */ debounce?: number; /** * Set an id for the top-level element. * The input, label, menu, and result ids derive from it as `{id}-input`, * `{id}-label`, `{id}-menu`, and `{id}-menuitem-{result id or index}`. * Previously a passed `id` was discarded; it now sets the top-level element * id and the input id becomes `{id}-input`. * @default uniqueId() */ id?: string; menu?: (this: void) => void; noResults?: (this: void) => void; children?: (this: void, ...args: [{ result: Result; index: number; selected: boolean; }]) => void; [key: `data-${string}`]: unknown; }; export type HeaderSearchProps = Omit<$RestProps, keyof $Props> & $Props; export default class HeaderSearch extends SvelteComponentTyped< HeaderSearchProps, { active: CustomEvent; blur: WindowEventMap["blur"]; change: WindowEventMap["change"]; clear: CustomEvent; close: CustomEvent<{ trigger: "escape-key" | "outside-click" | "select" | "blur"; }>; focus: WindowEventMap["focus"]; inactive: CustomEvent; input: WindowEventMap["input"]; keydown: WindowEventMap["keydown"]; paste: WindowEventMap["paste"]; search: CustomEvent; /** A result from `results` was chosen (`selectedResult`), or an item in the `menu` slot (`item`). */ select: CustomEvent<{ value: string; selectedResultIndex: number; selectedResult: Result } | { value: string; item: { text?: string; value?: string; href?: string }; event: Event }>; /** Dispatched when `shortcut` is pressed, before the search opens. Call `preventDefault()` to keep it closed. */ shortcut: CustomEvent; submit: CustomEvent<{ value: string }>; }, { default: { result: Result; index: number; selected: boolean; }; loading: Record; menu: Record; noResults: Record; } > {}