@spark-ui/dropdown
Version:
Displays a list of options for the user to pick from—triggered by a button. Differs from Select in that it offers multiple select and its list is not native.
82 lines (81 loc) • 3.1 kB
TypeScript
import { Dispatch, PropsWithChildren, SetStateAction } from 'react';
import { type DownshiftState, type DropdownItem, type ItemsMap } from './types';
export interface DropdownContextState extends DownshiftState {
itemsMap: ItemsMap;
highlightedItem: DropdownItem | undefined;
hasPopover: boolean;
setHasPopover: Dispatch<SetStateAction<boolean>>;
multiple: boolean;
disabled: boolean;
readOnly: boolean;
state?: 'error' | 'alert' | 'success';
lastInteractionType: 'mouse' | 'keyboard';
setLastInteractionType: (type: 'mouse' | 'keyboard') => void;
}
export type DropdownContextCommonProps = PropsWithChildren<{
/**
* The controlled open state of the select. Must be used in conjunction with `onOpenChange`.
*/
open?: boolean;
/**
* Event handler called when the open state of the select changes.
*/
onOpenChange?: (isOpen: boolean) => void;
/**
* The open state of the select when it is initially rendered. Use when you do not need to control its open state.
*/
defaultOpen?: boolean;
/**
* Use `state` prop to assign a specific state to the dropdown, choosing from: `error`, `alert` and `success`. By doing so, the outline styles will be updated.
*/
state?: 'error' | 'alert' | 'success';
/**
* When true, prevents the user from interacting with the dropdown.
*/
disabled?: boolean;
/**
* Sets the dropdown as interactive or not.
*/
readOnly?: boolean;
}>;
interface DropdownPropsSingle {
/**
* Prop 'multiple' indicating whether multiple values are allowed.
*/
multiple?: false;
/**
* The value of the select when initially rendered. Use when you do not need to control the state of the select.
*/
defaultValue?: string;
/**
* The controlled value of the select. Should be used in conjunction with `onValueChange`.
*/
value?: string;
/**
* Event handler called when the value changes.
*/
onValueChange?: (value: string) => void;
}
interface DropdownPropsMultiple {
/**
* Prop 'multiple' indicating whether multiple values are allowed.
*/
multiple: true;
/**
* The value of the select when initially rendered. Use when you do not need to control the state of the select.
*/
defaultValue?: string[];
/**
* The controlled value of the select. Should be used in conjunction with `onValueChange`.
*/
value?: string[];
/**
* Event handler called when the value changes.
*/
onValueChange?: (value: string[]) => void;
}
export type DropdownContextProps = DropdownContextCommonProps & (DropdownPropsSingle | DropdownPropsMultiple);
export declare const ID_PREFIX = ":dropdown";
export declare const DropdownProvider: ({ children, defaultValue, value, onValueChange, open, onOpenChange, defaultOpen, multiple, disabled: disabledProp, readOnly: readOnlyProp, state: stateProp, }: DropdownContextProps) => import("react").JSX.Element;
export declare const useDropdownContext: () => DropdownContextState;
export {};