import { SelectListOption } from "./SelectListOption.cjs"; import { Key, Orientation, ValidationError } from "@react-types/shared"; import { InsetSpacingTokens, PaddingSpacingTokens, SpaceProp, WidthProp } from "@marigold/system"; import { ReactNode, Ref } from "react"; import RAC from "react-aria-components"; export type SelectionMode = 'single' | 'multiple'; type RemoveProps = 'style' | 'className' | 'onSelectionChange' | 'dragAndDropHooks' | 'renderEmptyState' | 'selectionMode' | 'selectionBehavior' | 'layout' | 'keyboardNavigationBehavior' | 'isDisabled' | 'isInvalid' | 'isRequired'; type SelectListBaseProps = Omit, RemoveProps> & { /** * Visual variant of the list. * - `default`: full-width rows separated by dividers. * - `bordered`: each item is its own bordered, rounded container with a gap between items. * @default 'default' */ variant?: 'default' | 'bordered' | (string & {}); size?: string; /** * The label of the field. */ label?: ReactNode; /** * Content after the label, such as a `` or ``. Keeps * the label row's height, and a badge is read as the field's description. */ addon?: ReactNode; /** * A helpful description rendered below the list. */ description?: ReactNode; /** * An error message rendered below the list when `error` is true. */ errorMessage?: ReactNode | ((v: RAC.ValidationResult) => ReactNode); /** * If `true`, the field is considered invalid and the `errorMessage` is shown. * @default false */ error?: boolean; /** * If `true`, the field is required. * @default false */ required?: boolean; /** * If `true`, the list is disabled. * @default false */ disabled?: boolean; /** * The name used when submitting form data. */ name?: string; /** * Associates the hidden input with a `
` element by id. */ form?: string; /** * Width of the field. */ width?: WidthProp['width']; /** * The primary orientation of the options. Controls the direction items flow * and the arrow keys used to navigate between them. Horizontal lists flip * to a vertical stack automatically when the wrapping container is narrower * than 40rem. * @default 'vertical' */ orientation?: Orientation; /** * Content to render when the list has no items. */ emptyState?: ReactNode; /** * Selection mode. * - `single`: at most one option may be selected. * - `multiple`: any number of options may be selected. * @default 'single' */ selectionMode?: Mode; /** * Whether to show a select-all checkbox above the options, with a count of * what is selected. Has no effect unless `selectionMode="multiple"`. * @default false */ allowSelectAll?: boolean; /** * Whether the user may deselect the currently selected row by clicking it. * Defaults to `true` in `single` mode (radio-group semantics: clicking the * selected row keeps it selected) and `false` in `multiple` mode (checkbox * semantics: every row toggles independently). * * Set to `false` in `single` mode for clearable selection — for example a * filter picker where "no selection" is a valid state. */ disallowEmptySelection?: boolean; /** * Custom client-side validation. * - `selectionMode="single"`: receives `Key | null`. * - `selectionMode="multiple"`: receives `Key[]`. * Return a string (or array of strings) to mark the field invalid, or `true`/`null`/`undefined` for valid. */ validate?: (value: Key | null | Key[]) => ValidationError | true | null; /** * Whether to use native HTML form validation or ARIA validation. * Inherits from an ancestor `` when omitted. */ validationBehavior?: 'aria' | 'native'; /** * Handler that is called when the selection changes. The argument type * depends on `selectionMode`: * - `single`: `Key | null` (the selected key, or `null` when cleared). * - `multiple`: `Key[]` (the array of selected keys). */ onChange?: Mode extends 'multiple' ? (keys: Key[]) => void : (key: Key | null) => void; ref?: Ref; }; /** * Padding applied to every `SelectList.Option`. Either set `p` for uniform * padding, or use `px` / `py` to control the axes separately — setting both * forms is a TypeScript error, mirroring the `` and `` API. */ type SelectListPaddingProps = { /** Padding on all sides. Cannot be combined with `px` or `py`. */ p?: SpaceProp['space']; px?: never; py?: never; } | { p?: never; /** Horizontal padding applied to every option. */ px?: SpaceProp['space']; /** Vertical padding applied to every option. */ py?: SpaceProp['space']; }; export type SelectListProps = SelectListBaseProps & SelectListPaddingProps; interface SelectListComponent { (props: SelectListProps): ReactNode; (props: SelectListProps): ReactNode; Option: typeof SelectListOption; } declare const SelectListExported: SelectListComponent; export { SelectListExported as SelectList };