1 | import * as React from 'react';
|
2 | import { ListAction, ListState, UseListRootSlotProps } from '../useList';
|
3 | import { SelectOption } from '../useOption/useOption.types';
|
4 | import { SelectProviderValue } from './SelectProvider';
|
5 | import { MuiCancellableEventHandler } from '../utils/MuiCancellableEvent';
|
6 | import { UseButtonRootSlotProps } from '../useButton';
|
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 |
|
20 |
|
21 |
|
22 | areOptionsEqual?: (a: OptionValue, b: OptionValue) => boolean;
|
23 | |
24 |
|
25 |
|
26 |
|
27 | defaultOpen?: boolean;
|
28 | |
29 |
|
30 |
|
31 | defaultValue?: SelectValue<OptionValue, Multiple>;
|
32 | |
33 |
|
34 |
|
35 |
|
36 | disabled?: boolean;
|
37 | |
38 |
|
39 |
|
40 | buttonRef?: React.Ref<Element>;
|
41 | |
42 |
|
43 |
|
44 | listboxId?: string;
|
45 | |
46 |
|
47 |
|
48 | listboxRef?: React.Ref<Element>;
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | multiple?: Multiple;
|
56 | |
57 |
|
58 |
|
59 |
|
60 | name?: string;
|
61 | |
62 |
|
63 |
|
64 |
|
65 | required?: boolean;
|
66 | |
67 |
|
68 |
|
69 | onChange?: (event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, value: SelectValue<OptionValue, Multiple>) => void;
|
70 | |
71 |
|
72 |
|
73 | onHighlightChange?: (event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element> | React.FocusEvent<Element, Element> | null, highlighted: OptionValue | null) => void;
|
74 | |
75 |
|
76 |
|
77 | onOpenChange?: (open: boolean) => void;
|
78 | |
79 |
|
80 |
|
81 |
|
82 | open?: boolean;
|
83 | |
84 |
|
85 |
|
86 |
|
87 | options?: ReadonlyArray<SelectOptionDefinition<OptionValue>>;
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 | getSerializedValue?: (option: SelectValue<SelectOption<OptionValue>, Multiple>) => React.InputHTMLAttributes<HTMLInputElement>['value'];
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | getOptionAsString?: (option: SelectOption<OptionValue>) => string;
|
102 | |
103 |
|
104 |
|
105 |
|
106 | value?: SelectValue<OptionValue, Multiple>;
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 | componentName?: string;
|
113 | }
|
114 | interface UseSelectButtonSlotEventHandlers {
|
115 | onMouseDown: MuiCancellableEventHandler<React.MouseEvent>;
|
116 | }
|
117 | export type UseSelectButtonSlotProps<TOther = {}> = UseButtonRootSlotProps<Omit<TOther, keyof UseSelectButtonSlotEventHandlers>> & UseSelectButtonSlotEventHandlers & {
|
118 | 'aria-expanded': React.AriaAttributes['aria-expanded'];
|
119 | 'aria-controls': React.AriaAttributes['aria-controls'];
|
120 | role: React.HTMLAttributes<Element>['role'];
|
121 | ref: React.RefCallback<Element> | null;
|
122 | };
|
123 | interface UseSelectHiddenInputSlotEventHandlers {
|
124 | onChange: MuiCancellableEventHandler<React.ChangeEvent<HTMLInputElement>>;
|
125 | }
|
126 | export type UseSelectHiddenInputSlotProps<TOther = {}> = UseSelectHiddenInputSlotEventHandlers & React.InputHTMLAttributes<HTMLInputElement> & TOther;
|
127 | interface UseSelectListboxSlotEventHandlers {
|
128 | onBlur: MuiCancellableEventHandler<React.FocusEvent<HTMLElement>>;
|
129 | }
|
130 | export type UseSelectListboxSlotProps<TOther = {}> = UseListRootSlotProps<Omit<TOther, keyof UseSelectListboxSlotEventHandlers>> & UseSelectListboxSlotEventHandlers & {
|
131 | 'aria-multiselectable': React.AriaAttributes['aria-multiselectable'];
|
132 | id: string | undefined;
|
133 | role: React.HTMLAttributes<Element>['role'];
|
134 | };
|
135 | export interface UseSelectReturnValue<Value, Multiple> {
|
136 | |
137 |
|
138 |
|
139 | buttonActive: boolean;
|
140 | |
141 |
|
142 |
|
143 | buttonFocusVisible: boolean;
|
144 | |
145 |
|
146 |
|
147 | buttonRef: React.RefCallback<Element> | null;
|
148 | |
149 |
|
150 |
|
151 | disabled: boolean;
|
152 | |
153 |
|
154 |
|
155 |
|
156 | dispatch: (action: ListAction<Value> | SelectAction<Value>) => void;
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 | getButtonProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectButtonSlotProps<ExternalProps>;
|
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 | getHiddenInputProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectHiddenInputSlotProps<ExternalProps>;
|
169 | |
170 |
|
171 |
|
172 |
|
173 |
|
174 | getListboxProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectListboxSlotProps<ExternalProps>;
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | getOptionMetadata: (optionValue: Value) => SelectOption<Value> | undefined;
|
182 | |
183 |
|
184 |
|
185 | contextValue: SelectProviderValue<Value>;
|
186 | |
187 |
|
188 |
|
189 | highlightedOption: Value | null;
|
190 | |
191 |
|
192 |
|
193 | listboxRef: React.RefCallback<Element> | null;
|
194 | |
195 |
|
196 |
|
197 | open: boolean;
|
198 | |
199 |
|
200 |
|
201 | options: Value[];
|
202 | |
203 |
|
204 |
|
205 | value: SelectValue<Value, Multiple>;
|
206 | }
|
207 | export declare const SelectActionTypes: {
|
208 | readonly buttonClick: "buttonClick";
|
209 | readonly browserAutoFill: "browserAutoFill";
|
210 | };
|
211 | export interface ButtonClickAction {
|
212 | type: typeof SelectActionTypes.buttonClick;
|
213 | event: React.MouseEvent;
|
214 | }
|
215 | export interface BrowserAutofillAction<OptionValue> {
|
216 | type: typeof SelectActionTypes.browserAutoFill;
|
217 | item: OptionValue;
|
218 | event: React.ChangeEvent;
|
219 | }
|
220 | export type SelectAction<OptionValue> = ButtonClickAction | BrowserAutofillAction<OptionValue>;
|
221 | export interface SelectInternalState<OptionValue> extends ListState<OptionValue> {
|
222 | open: boolean;
|
223 | }
|
224 | export {};
|