1 | import * as React from 'react';
|
2 | import { ListAction, ListState, UseListRootSlotProps } from '../useList';
|
3 | import { SelectOption } from '../useOption/useOption.types';
|
4 | import { EventHandlers } from '../utils/types';
|
5 | import { SelectProviderValue } from './SelectProvider';
|
6 | import { MuiCancellableEventHandler } from '../utils/muiCancellableEvent';
|
7 | export type SelectChangeEventType = React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element> | React.FocusEvent<Element, Element> | null;
|
8 | export type SelectValue<Value, Multiple> = Multiple extends true ? Value[] : Value | null;
|
9 | export interface SelectOptionDefinition<Value> {
|
10 | value: Value;
|
11 | disabled?: boolean;
|
12 | label: string;
|
13 | }
|
14 | export interface UseSelectParameters<OptionValue, Multiple extends boolean = false> {
|
15 | |
16 |
|
17 |
|
18 |
|
19 | defaultOpen?: boolean;
|
20 | |
21 |
|
22 |
|
23 | defaultValue?: SelectValue<OptionValue, Multiple>;
|
24 | |
25 |
|
26 |
|
27 |
|
28 | disabled?: boolean;
|
29 | |
30 |
|
31 |
|
32 | buttonRef?: React.Ref<Element>;
|
33 | |
34 |
|
35 |
|
36 | listboxId?: string;
|
37 | |
38 |
|
39 |
|
40 | listboxRef?: React.Ref<Element>;
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | multiple?: Multiple;
|
48 | |
49 |
|
50 |
|
51 | onChange?: (event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, value: SelectValue<OptionValue, Multiple>) => void;
|
52 | |
53 |
|
54 |
|
55 | onHighlightChange?: (event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element> | React.FocusEvent<Element, Element> | null, highlighted: OptionValue | null) => void;
|
56 | |
57 |
|
58 |
|
59 | onOpenChange?: (open: boolean) => void;
|
60 | |
61 |
|
62 |
|
63 |
|
64 | open?: boolean;
|
65 | |
66 |
|
67 |
|
68 |
|
69 | options?: SelectOptionDefinition<OptionValue>[];
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | getOptionAsString?: (option: SelectOption<OptionValue>) => string;
|
78 | |
79 |
|
80 |
|
81 |
|
82 | value?: SelectValue<OptionValue, Multiple>;
|
83 | }
|
84 | interface UseSelectButtonSlotEventHandlers {
|
85 | onClick: MuiCancellableEventHandler<React.MouseEvent>;
|
86 | }
|
87 | export type UseSelectButtonSlotProps<TOther = {}> = UseListRootSlotProps<Omit<TOther, keyof UseSelectButtonSlotEventHandlers>> & UseSelectButtonSlotEventHandlers & {
|
88 | 'aria-expanded': React.AriaAttributes['aria-expanded'];
|
89 | 'aria-controls': React.AriaAttributes['aria-controls'];
|
90 | role: React.HTMLAttributes<Element>['role'];
|
91 | ref: React.RefCallback<Element> | null;
|
92 | };
|
93 | interface UseSelectListboxSlotEventHandlers {
|
94 | onMouseDown: React.MouseEventHandler;
|
95 | }
|
96 | export type UseSelectListboxSlotProps<TOther = {}> = Omit<TOther, keyof UseSelectListboxSlotEventHandlers> & UseSelectListboxSlotEventHandlers & {
|
97 | 'aria-multiselectable': React.AriaAttributes['aria-multiselectable'];
|
98 | id: string | undefined;
|
99 | ref: React.RefCallback<Element> | null;
|
100 | role: React.HTMLAttributes<Element>['role'];
|
101 | };
|
102 | export interface UseSelectReturnValue<Value, Multiple> {
|
103 | |
104 |
|
105 |
|
106 | buttonActive: boolean;
|
107 | |
108 |
|
109 |
|
110 | buttonFocusVisible: boolean;
|
111 | |
112 |
|
113 |
|
114 | buttonRef: React.RefCallback<Element> | null;
|
115 | |
116 |
|
117 |
|
118 | disabled: boolean;
|
119 | |
120 |
|
121 |
|
122 |
|
123 | dispatch: (action: ListAction<Value> | SelectAction) => void;
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 | getButtonProps: <OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectButtonSlotProps<OtherHandlers>;
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 | getListboxProps: <OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectListboxSlotProps<OtherHandlers>;
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | getOptionMetadata: (optionValue: Value) => SelectOption<Value> | undefined;
|
143 | |
144 |
|
145 |
|
146 | contextValue: SelectProviderValue<Value>;
|
147 | |
148 |
|
149 |
|
150 | highlightedOption: Value | null;
|
151 | |
152 |
|
153 |
|
154 | listboxRef: React.RefCallback<Element> | null;
|
155 | |
156 |
|
157 |
|
158 | open: boolean;
|
159 | |
160 |
|
161 |
|
162 | options: Value[];
|
163 | |
164 |
|
165 |
|
166 | value: SelectValue<Value, Multiple>;
|
167 | }
|
168 | export declare const SelectActionTypes: {
|
169 | readonly buttonClick: "buttonClick";
|
170 | };
|
171 | export interface ButtonClickAction {
|
172 | type: typeof SelectActionTypes.buttonClick;
|
173 | event: React.MouseEvent;
|
174 | }
|
175 | export type SelectAction = ButtonClickAction;
|
176 | export interface SelectInternalState<OptionValue> extends ListState<OptionValue> {
|
177 | open: boolean;
|
178 | }
|
179 | export {};
|