import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; 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 value of the search input. * @default "" */ value?: T; /** * Whether the results menu is visible. Driven by focus and available content. * @default false */ open?: boolean; /** * Set to `true` to filter items by the search value using fuzzy matching. * Unmatched items stay mounted and are hidden so later keystrokes do not * recreate option nodes. * @default true */ shouldFilter?: boolean; /** * Override how the search value is matched against each 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. Supply your own function for custom filtering * and highlighting, or pass a no-op like `() => ({ matched: true })` to keep * every item and disable highlighting. * @default fuzzyMatch */ match?: (text: string, query: string) => { matched: boolean; indices?: number[] }; /** * Specify the size of the search input. * Also accepts Carbon v11's `"md"` (`"lg"`, 40px). `"lg"` keeps this * library's 40px; Carbon v11's 48px `lg` is `"xl"` here. * @default "xl" */ size?: "xs" | "sm" | "md" | "lg" | "xl"; /** * Specify the size of the results menu, independent of the input `size`. * Defaults to the input `size`. * Also accepts Carbon v11's `"md"` (`"lg"`, 40px). `"lg"` keeps this * library's 40px; Carbon v11's 48px `lg` is `"xl"` here. */ menuSize?: "xs" | "sm" | "md" | "lg" | "xl" | undefined; /** * Override the results menu's max height. Numbers are pixels; strings * accept any CSS length (for example `"50vh"`). Defaults to 360px. */ menuMaxHeight?: number | string | undefined; /** * Set to `true` to disable the search input * @default false */ disabled?: boolean; /** * Set to `true` to use the read-only variant. * Blocks opening the results menu and selecting or submitting a value; * the current value still submits with the form. * @default false */ readonly?: boolean; /** * Specify the assistive text announced to screen readers when read-only. * Exposed because VoiceOver does not announce `aria-readonly`. * @default "Read-only" */ readonlyText?: string; /** * Set to `true` to render a skeleton menu while results are loading, for * example while fetching server-side results. Override the placeholder rows * with the `loading` slot. When results are already rendered, a single * loading row is appended below them instead. * @default false */ loading?: boolean; /** * Specify the number of skeleton rows rendered while `loading` * @default 4 */ skeletonCount?: number; /** * Wait this many milliseconds after `loading` turns `true` before showing * the skeleton menu or loading row, and the `searchLoading` spinner. Once * shown, it stays for at least 500 ms, so fast work shows nothing and slow * work never flashes. The menu sets `aria-busy` and holds back the * no-results state as soon as `loading` is `true`. * Set to `0` to show it at once. * @default 0 */ loadingDelay?: number; /** * Set to `true` to show a spinner in the search input while results are * loading. Independent of `loading`, which controls the skeleton menu — * combine both to show the spinner while the menu is also loading. * @default false */ searchLoading?: boolean; /** * Specify the placeholder text * @default "Search..." */ placeholder?: string; /** * Specify the label text * @default "" */ labelText?: string; /** * Set to `true` to visually hide the label text * @default false */ hideLabel?: boolean; /** * Specify the close button label text * @default "Clear search input" */ closeButtonLabelText?: string; /** * Specify the icon to render. */ icon?: Icon | undefined; /** * Specify the direction of the results menu. * @default "bottom" */ direction?: "bottom" | "top"; /** * Set to `true` to render the menu in a portal to escape `overflow: hidden` containers * @default true */ portal?: boolean; /** * Specify a class passed to the inner Search element * @default "" */ searchClass?: string; /** * Set an id for the search input * @default uniqueId() */ id?: string; /** * Obtain a reference to the input HTML element. * @default null */ ref?: null | HTMLInputElement; /** * Obtain a reference to the menu HTML element. * @default null */ menuRef?: null | HTMLDivElement; /** * 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`, the fuzzy-match * highlighting, and clearing all stay immediate regardless of this delay * -- only the `search` event waits. Selecting an item or submitting with * Enter cancels a pending `search` instead of also firing it. * @default 0 */ debounce?: number; before?: (this: void) => void; noResults?: (this: void) => void; children?: (this: void) => void; [key: `data-${string}`]: unknown; }; export type SearchMenuProps = Omit<$RestProps, keyof $Props> & $Props; export default class SearchMenu extends SvelteComponentTyped< SearchMenuProps, { blur: WindowEventMap["blur"]; change: WindowEventMap["change"]; clear: CustomEvent; close: CustomEvent<{ trigger: "escape-key" | "outside-click" | "select" | "blur" }>; focus: WindowEventMap["focus"]; input: WindowEventMap["input"]; keydown: WindowEventMap["keydown"]; keyup: WindowEventMap["keyup"]; paste: WindowEventMap["paste"]; /** * Dispatched when the results menu is scrolled near the bottom (load-more * signal). Not the browser's native `scrollend` (scroll stopped). */ scrollend: CustomEvent<{ scrollTop: number; scrollHeight: number; clientHeight: number }>; search: CustomEvent; select: CustomEvent<{ value: string; item: { text?: string; value?: string; href?: string }; event: Event }>; submit: CustomEvent<{ value: T }>; }, { default: Record; before: Record; loading: Record; noResults: Record; } > {}