import type { DSSuggestionElement } from '@digdir/designsystemet-web'; import { type HTMLAttributes, type ReactNode, type RefObject } from 'react'; export type SuggestionItem = { label: string; value: string; }; type EventBeforeMatch = Omit, 'currentTarget'> & { currentTarget: DSSuggestionElement; }; type Filter = (args: { /** * Index of the `option` */ index: number; /** * Label content of the `option` */ label: string; /** * Text content of the `option` */ text: string; /** * Value of the `option` */ value: string; /** * The DOM element of the `option` */ optionElement: HTMLOptionElement; /** * The DOM element of the `input` */ input: HTMLInputElement; }) => boolean; type SuggestionContextType = { handleFilter: (input?: HTMLInputElement | null) => void; isEmpty?: boolean; dsSuggestionRef?: RefObject; }; type SuggestionValue = T['multiple'] extends true ? Array : string | SuggestionItem; type SuggestionBaseProps = { /** * Filter options; boolean or a custom callback. * * See {@link Filter} for the callback signature. * * @default true */ filter?: boolean | Filter; /** * Allows the user to create new items * * @default false */ creatable?: boolean; /** * Callback when matching input value against options */ onBeforeMatch?: (event: EventBeforeMatch) => void; /** * The name of the associated form control * * @default undefined */ name?: string; /** * Change how the selected options are rendered inside the `Chip`. * * @default ({ label }) => label */ renderSelected?: (args: { label: string; value: string; }) => ReactNode; } & Omit, 'defaultValue'>; type SuggestionValueProps = { /** * Allows the user to select multiple items * * @default false */ multiple?: T['multiple']; /** * The selected item of the Suggestion. * * If `label` and `value` are the same, each item can be a `string`. Otherwise, each item must be a `SuggestionItem`. * * Using this makes the component controlled and it must be used in combination with `onSelectedChange`. */ selected?: SuggestionValue | null; /** * Default selected item when uncontrolled */ defaultSelected?: SuggestionValue; /** * Callback when selected items changes */ onSelectedChange?: (value: T['multiple'] extends true ? SuggestionItem[] : SuggestionItem | null) => void; }; export type SuggestionSingleProps = SuggestionBaseProps & SuggestionValueProps<{ multiple: false; }>; export type SuggestionMultipleProps = SuggestionBaseProps & SuggestionValueProps<{ multiple: true; }> & { multiple: true; }; export type SuggestionProps = SuggestionSingleProps | SuggestionMultipleProps; export declare const Suggestion: import("react").ForwardRefExoticComponent>; export declare const SuggestionContext: import("react").Context; export {}; //# sourceMappingURL=suggestion.d.ts.map