import { type ComponentProps, type ReactNode, type RefObject } from 'react'; /** * Unstyled Carbon `Search` and `ExpandableSearch`, the behaviour of the styled Search without a single * class. `Root` holds the state and renders nothing; inside it a `Landmark` (`role="search"`, named by * its `Label`) holds the `Input` (`type="search"`), a `Clear` button and, for an `expandable` search, * the magnifier `Trigger` that opens it. * * Rules (traced on Carbon): the clear button is out of the tab order while there is nothing to clear; * pressing it keeps focus in the field (its mousedown is cancelled) and empties it with a real `input` * event, so `onChange` sees it, then calls `onClear`. Esc empties a filled field and keeps focus; on an * empty open expandable search it collapses it and focuses the magnifier. The magnifier opens it on a * click, Enter or Space and focuses the field; leaving an empty open search (for anywhere outside its * `Landmark`) collapses it. A form reset puts an uncontrolled field back to its `defaultValue`. * * State shows as data attributes to style on: `data-empty`, `data-collapsed`, `data-disabled` and * `data-readonly` on `Landmark` and `Input`; `data-hidden` on `Clear` (nothing to clear: empty or * read-only); `data-expanded` on `Trigger`. * * ```tsx * * * Search * * × * * * ``` */ type InputValue = ComponentProps<'input'>['value']; export interface RootProps { children?: ReactNode; /** The input's id (default: generated); its label's is `${inputId}-label`. */ inputId?: string; /** The text (controlled; follow the input's `onChange`). */ value?: InputValue; defaultValue?: InputValue; disabled?: boolean; /** Keeps the text: nothing to clear. */ readOnly?: boolean; /** After the clear button or Esc emptied the field. */ onClear?: () => void; /** Carbon `ExpandableSearch`: collapsed to its magnifier `Trigger` until opened. */ expandable?: boolean; /** Whether an expandable search is open (controlled). */ expanded?: boolean; defaultExpanded?: boolean; onExpandedChange?: (expanded: boolean) => void; } type FocusAfter = 'input' | 'trigger' | null; interface SearchContextValue { inputId: string; labelId: string; value: InputValue; defaultValue: InputValue; /** No text. */ empty: boolean; /** Text the user may clear (not read-only). */ clearable: boolean; disabled: boolean; readOnly: boolean; expandable: boolean; /** Not collapsed (always, unless `expandable`). */ open: boolean; input: RefObject; trigger: RefObject; landmark: RefObject; /** The input's text changed. */ typed: (text: string) => void; /** Empties the field (a real `input` event), keeps focus in it, then `onClear`. */ clear: () => void; /** Opens or collapses an expandable search, then focuses `focus`. */ setExpanded: (expanded: boolean, focus: FocusAfter) => void; } /** The state of the enclosing `Search.Root` (open, empty, clearable …). */ export declare function useSearchContext(part?: string): SearchContextValue; export declare function Root({ children, inputId, value, defaultValue, disabled, readOnly, onClear, expandable, expanded, defaultExpanded, onExpandedChange }: Readonly): import("react").JSX.Element; /** The `role="search"` landmark around the field, named by its `Label`: an empty expandable search collapses when focus leaves it. */ export declare function Landmark({ ref, ...rest }: Readonly, 'role'>>): import("react").JSX.Element; /** The field's label (Carbon hides it visually; it names the landmark and the input). */ export declare function Label(props: Readonly, 'htmlFor' | 'id'>>): import("react").JSX.Element; export type InputProps = Omit, 'type' | 'id' | 'value' | 'defaultValue' | 'disabled' | 'readOnly'>; /** The ``: Esc clears or collapses; out of the tab order while collapsed. */ export declare function Input({ ref, ...rest }: Readonly): import("react").JSX.Element; export type ClearProps = Omit, 'type' | 'disabled'>; /** Empties the field and keeps focus in it; out of the tab order while there is nothing to clear (Carbon). */ export declare function Clear(props: Readonly): import("react").JSX.Element; export type TriggerProps = Omit, 'type' | 'disabled'>; /** * An expandable search's magnifier: opens it on a click, Enter or Space; a Tab stop only while collapsed. Its * `tabIndex` is always set by the part (0 while collapsed, -1 while open): a `tabIndex` you pass is ignored. */ export declare function Trigger({ ref, ...rest }: Readonly): import("react").JSX.Element; export {};