import { type ComponentProps, type ReactNode, type RefObject } from 'react'; import { type TextFilter } from '../core/listbox.js'; import { type MultiStep, type SelectionFeedback } from '../core/multi-select.js'; import { Typeahead } from '../core/typeahead.js'; import { type ListItem, type ListOption } from './list-items.js'; import { type ListPopupProps } from './list-parts.tsx'; /** * Unstyled Carbon `MultiSelect` / `FilterableMultiSelect`, the behaviour of the styled MultiSelect * without a single class: a list of options that stays open while toggling; chosen options move to * the top when the list reopens (`selectionFeedback`); `Clear` empties the choice; an optional * `SelectAll` row (mixed when some are chosen). The field is a `Trigger` button, or with * `filterable` an `Input` that narrows the list (with `ClearText` and `Toggle`). The options are * data on `Root` (`items`); `Popup` hands its render function the ones to show, in order. * * State shows as data attributes to style on: `data-open`, `data-disabled`, `data-readonly`, * `data-invalid`, `data-placeholder` (nothing chosen) on the field, and on options * `data-highlighted`, `data-selected`, `data-disabled` (`SelectAll` also `data-mixed`). * * ```tsx * * Fruits * * {(items) => items.map((f) => 'options' in f ? null : {f.label})} * * ``` */ export interface RootProps { /** Options, and groups of options (`{ label, options }`). */ items: ListItem[]; value?: string[]; defaultValue?: string[]; onValueChange?: (value: string[]) => void; /** Filterable: every keystroke (with `filter="none"` the list is yours to fill, e.g. from a server). */ onInputValueChange?: (text: string) => void; /** Filterable: the text box's text, controlled (Lit `inputValue`); typing and emptying it are reported through `onInputValueChange`. */ inputValue?: string; /** Where chosen options go: to the top when the list reopens (default), at once, or nowhere. */ selectionFeedback?: SelectionFeedback; /** Offer a `SelectAll` row before the options. */ selectAll?: boolean; /** The field is a text box (`Input`) that narrows the list. */ filterable?: boolean; /** How typed text narrows the list (filterable). */ filter?: TextFilter; /** The options are on their way: the keys pick nothing, the popup is `aria-busy`. */ loading?: boolean; /** After the list opened or closed (Carbon React `onMenuChange`). */ onOpenChange?: (open: boolean) => void; disabled?: boolean; readOnly?: boolean; required?: boolean; /** Marks the field `aria-invalid` and `data-invalid`. */ invalid?: boolean; /** * A submit attempt (or `reportValidity()`) found it `required` with nothing chosen: show the error (the form is * blocked and the field takes the focus). Not called for `checkValidity()`, which stays silent. */ onInvalid?: () => void; /** Submits each chosen value with the form (hidden inputs), unless disabled. */ name?: string; /** The input's id (filterable), and the base of the parts' ids (`-label`, `-value`, `-list`, `-opt-`, `-opt-all`); generated when left out. */ id?: string; children?: ReactNode; } interface MultiSelectContextValue { id: string; value: string[]; count: number; /** The listed rows, in order (the keys move through these). */ rows: ListOption[]; /** The same, as items (groups kept), for `Popup`'s render function. */ rowItems: ListItem[]; text: string; open: boolean; active: number; disabled: boolean; readOnly: boolean; required: boolean; invalid: boolean; loading: boolean; filterable: boolean; /** Not disabled and not read-only. */ interactive: boolean; showSelectAll: boolean; /** "Select all": every shown option chosen, some, or none. */ allState: 'none' | 'some' | 'all'; typeahead: RefObject; anchor: RefObject; trigger: RefObject; input: RefObject; apply: (step: MultiStep) => void; close: () => void; /** Toggle a row (or `SELECT_ALL`), highlighting it. */ pickRow: (row: number) => void; /** Open as a click does: on the first row when something is chosen, else with nothing highlighted. */ openOnClick: () => void; /** The text box changed. */ type: (text: string) => void; /** Close and empty the filter text (leaving the field, an outside press). */ leave: () => void; clearAll: () => void; clearText: () => void; /** The chevron (filterable): close or open; focus stays in the input. */ toggle: () => void; } /** The state of the enclosing `MultiSelect.Root` (value, open, rows …), e.g. to show the count. */ export declare function useMultiSelectContext(): MultiSelectContextValue; /** Holds the value, the open state, the highlight and the filter text; renders its children (and a hidden input per value with `name`). */ export declare function Root({ items, value, defaultValue, onValueChange, onInputValueChange, inputValue, selectionFeedback, selectAll, filterable, filter, loading, onOpenChange, disabled, readOnly, required, invalid, onInvalid, name, id, children }: Readonly): import("react").JSX.Element; /** Names the field and the popup (`-label`); filterable, point a `