import { type ComponentProps, type ReactNode, type RefObject } from 'react'; import { type DropdownStep } from '../core/dropdown.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 `Dropdown` (APG select-only combobox), the behaviour of the styled Dropdown * without a single class: a `Trigger` button with `role="combobox"` opens a `Popup` listbox in the * top layer as wide as the trigger; the highlight is `aria-activedescendant`, so focus stays on the * trigger. A click opens on the chosen option (or none), ↓ / Enter / Space on the chosen or first, * letters jump (typeahead), Tab closes without picking, a click outside closes. The options are * given as data on `Root` (`items`, for the keyboard) and rendered as `Option`s inside `Popup`. * * State shows as data attributes to style on: `data-open`, `data-disabled`, `data-readonly`, * `data-invalid`, `data-placeholder` (no value), and on options `data-highlighted`, `data-selected`, * `data-disabled`. `Label` and `Value` name the trigger; a `Group` holds a `GroupLabel` and its * options in `GroupOptions`. * * ```tsx * * Fruit * * {fruits.map((f) => {f.label})} * * ``` */ export interface RootProps { /** Options, and groups of options (`{ label, options }`): what the keys move through and typeahead searches. */ items: ListItem[]; value?: string; defaultValue?: string; /** After the user picks another option. */ onValueChange?: (value: string) => void; /** After the list opened or closed (Carbon React `onMenuChange`), e.g. to load the options on first open. */ onOpenChange?: (open: boolean) => void; disabled?: boolean; readOnly?: boolean; required?: boolean; /** Marks the trigger `aria-invalid` and `data-invalid`. */ invalid?: boolean; /** The options are on their way: the keys pick nothing, the popup is `aria-busy` (no Carbon counterpart). */ loading?: 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 the value with the form (a hidden input), unless disabled. */ name?: string; /** Base of the parts' ids (`-label`, `-value`, `-list`, `-opt-`); generated when left out. */ id?: string; children?: ReactNode; } interface DropdownContextValue { id: string; options: ListOption[]; /** Row of each option value. */ rows: ReadonlyMap; value: string; selected: number; open: boolean; active: number; disabled: boolean; readOnly: boolean; required: boolean; invalid: boolean; loading: boolean; trigger: RefObject; typeahead: RefObject; pick: (index: number) => void; close: () => void; openAt: (index: number) => void; apply: (step: DropdownStep) => void; } /** The state of the enclosing `Dropdown.Root` (open, value, highlighted row …), e.g. to turn a chevron. */ export declare function useDropdownContext(): DropdownContextValue; /** Holds the value, the open state and the highlight; renders its children (and the hidden input with `name`). */ export declare function Root({ items, value, defaultValue, onValueChange, onOpenChange, disabled, readOnly, required, invalid, loading, onInvalid, name, id, children }: Readonly): import("react").JSX.Element; /** Names the trigger (with `Value`) and the popup. */ export declare function Label({ id, ...rest }: Readonly>): import("react").JSX.Element; export type TriggerProps = Omit, 'type' | 'role' | 'disabled'>; /** The button that opens the list (`role="combobox"`); keeps focus while the list is open. */ export declare function Trigger({ ref, ...rest }: Readonly): import("react").JSX.Element; export interface ValueProps extends ComponentProps<'span'> { /** Shown while nothing is chosen. */ placeholder?: ReactNode; } /** The chosen option's label (or `placeholder`); `children` replaces it. */ export declare function Value({ placeholder, children, id, ...rest }: Readonly): import("react").JSX.Element; export type PopupProps = ListPopupProps; /** The listbox in the top layer, as wide as the trigger; its children (the `Option`s) render only while open. An outside press closes it. */ export declare function Popup(props: Readonly): import("react").JSX.Element; export { Option, Group, GroupLabel, GroupOptions, type OptionProps } from './list-parts.tsx';