UNPKG

2.22 kBTypeScriptView Raw
1/// <reference types="react" />
2import type { DropdownContextValue } from './DropdownContext';
3export interface UseDropdownParameters {
4 /**
5 * If `true`, the dropdown is initially open.
6 */
7 defaultOpen?: boolean;
8 /**
9 * Callback fired when the component requests to be opened or closed.
10 */
11 onOpenChange?: (event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, open: boolean) => void;
12 /**
13 * Allows to control whether the dropdown is open.
14 * This is a controlled counterpart of `defaultOpen`.
15 */
16 open?: boolean;
17 /**
18 * The name of the component using useDropdown.
19 * For debugging purposes.
20 * @default 'useDropdown'
21 */
22 componentName?: string;
23}
24export interface UseDropdownReturnValue {
25 /**
26 * The value to be passed into the DropdownContext provider.
27 */
28 contextValue: DropdownContextValue;
29 /**
30 * If `true`, the dropdown is open.
31 */
32 open: boolean;
33}
34export declare const DropdownActionTypes: {
35 readonly blur: "dropdown:blur";
36 readonly escapeKeyDown: "dropdown:escapeKeyDown";
37 readonly toggle: "dropdown:toggle";
38 readonly open: "dropdown:open";
39 readonly close: "dropdown:close";
40};
41interface DropdownBlurAction {
42 type: typeof DropdownActionTypes.blur;
43 event: React.FocusEvent;
44}
45interface DropdownEscapeKeyDownAction {
46 type: typeof DropdownActionTypes.escapeKeyDown;
47 event: React.KeyboardEvent;
48}
49interface DropdownToggleAction {
50 type: typeof DropdownActionTypes.toggle;
51 event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null;
52}
53interface DropdownOpenAction {
54 type: typeof DropdownActionTypes.open;
55 event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null;
56}
57interface DropdownCloseAction {
58 type: typeof DropdownActionTypes.close;
59 event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null;
60}
61export type DropdownAction = DropdownBlurAction | DropdownEscapeKeyDownAction | DropdownToggleAction | DropdownOpenAction | DropdownCloseAction;
62export type DropdownState = {
63 open: boolean;
64 changeReason: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null;
65};
66export {};