forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-select.d.ts
306 lines (283 loc) · 8.95 KB
/
react-select.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// Type definitions for react-select v1.0.0
// Project: https://github.com/JedWatson/react-select
// Definitions by: ESQUIBET Hugo <https://github.com/Hesquibet/>, Gilad Gray <https://github.com/giladgray/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../react/react.d.ts"/>
declare namespace ReactSelect {
interface Option {
/** Text for rendering */
label: string;
/** Value for searching */
value: string | number;
/**
* Allow this option to be cleared
* @default true
*/
clearableValue?: boolean;
}
interface ReactSelectProps extends __React.Props<ReactSelect> {
/**
* text to display when `allowCreate` is true.
* @default 'Add "{label}"?'
*/
addLabelText?: string;
/**
* blurs the input element after a selection has been made. Handy for lowering the keyboard on mobile devices.
* @default false
*/
autoBlur?: boolean;
/**
* allow new options to be created in multi mode (displays an "Add <option> ?" item
* when a value not already in the options array is entered)
* @default false
*/
allowCreate?: boolean;
/**
* whether to auto-load the default async options set
* @default true
*/
autoload?: boolean;
/**
* whether pressing backspace removes the last item when there is no input value
* @default true
*/
backspaceRemoves?: boolean;
/**
* enables the options cache for `asyncOptions`
* @default true
*/
cacheAsyncResults?: boolean;
/**
* CSS className for the outer element
*/
className?: string;
/**
* whether it is possible to reset value. if enabled, an X button will appear at the right side.
* @default true
*/
clearable?: boolean;
/**
* title for the "clear" control when `multi` is true
* @default "Clear all"
*/
clearAllText?: string;
/**
* title for the "clear" control
* @default "Clear value"
*/
clearValueText?: string;
/**
* delimiter to use to join multiple values
* @default ","
*/
delimiter?: string;
/**
* whether the Select is disabled or not
* @default false
*/
disabled?: boolean;
/**
* method to filter a single option
*/
filterOption?: (option: Option, filter: string) => Option;
/**
* method to filter the options array
*/
filterOptions?: (options: Array<Option>, filter: string, currentValues: (string | number)[]) => Array<Option>;
/**
* whether to perform case-insensitive filtering
* @default true
*/
ignoreCase?: boolean;
/**
* custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
* @default {}
*/
inputProps?: Object;
/**
* whether the Select is loading externally or not (such as options being loaded).
* if true, a loading spinner will be shown at the right side.
* @default false
*/
isLoading?: boolean;
/**
* the option property to use for the label
* @default "label"
*/
labelKey?: string;
/**
* function that calls a callback with the options
*/
loadOptions?: (input: string, callback: (options: Option[]) => any) => any;
/**
* (any, start) match the start or entire string when filtering
* @default "any"
*/
matchPos?: string;
/**
* (any, label, value) which option property to filter on
* @default "any"
*/
matchProp?: string;
/**
* buffer of px between the base of the dropdown and the viewport to shift if menu doesnt fit in viewport
* @default 0
*/
menuBuffer?: number;
/**
* multi-value input
* @default false
*/
multi?: boolean;
/**
* field name, for hidden `<input>` tag
*/
name?: string;
/**
* factory to create new options when `allowCreate` is true
* @default false
*/
newOptionCreator?: (input: string) => Option;
/**
* placeholder displayed when there are no matching search results or a falsy value to hide it
* @default "No results found"
*/
noResultsText?: string;
onBlur?: __React.FocusEventHandler;
/**
* whether to clear input on blur or not
* @default true
*/
onBlurResetsInput?: boolean;
onChange?: (newValue: Option | Option[]) => void;
onClose?: () => void;
onFocus?: __React.FocusEventHandler;
onInputChange?: (inputValue: string) => void;
onOpen?: () => void;
onOptionLabelClick?: (value: string, event: Event) => void;
/**
* function which returns a custom way to render the options in the menu
*/
optionRenderer?: (option: Option) => JSX.Element;
/**
* array of Select options
* @default false
*/
options?: Array<Option>;
/**
* field placeholder, displayed when there's no value
* @default "Select..."
*/
placeholder?: string;
/**
* whether to enable searching feature or not
* @default true;
*/
searchable?: boolean;
/**
* message to display whilst options are loading via asyncOptions, or when `isLoading` is true
* @default "Searching..."
*/
searchingText?: string;
/**
* label to prompt for search input
* @default "Type to search"
*/
searchPromptText?: string;
/**
* initial field value
*/
value?: Option | Option[];
/**
* the option property to use for the value
* @default "value"
*/
valueKey?: string;
/**
* function which returns a custom way to render the value selected
* @default false
*/
valueRenderer?: () => void;
/**
* optional style to apply to the control
*/
style?: any;
/**
* optional tab index of the control
*/
tabIndex?: string;
/**
* value component to render
*/
valueComponent?: Function;
/**
* optional style to apply to the component wrapper
*/
wrapperStyle?: any;
/**
* onClick handler for value labels: function (value, event) {}
*/
onValueClick?: Function;
/**
* pass the value to onChange as a simple value (legacy pre 1.0 mode), defaults to false
*/
simpleValue?: boolean;
}
interface ReactAsyncSelectProps extends ReactSelectProps {
/**
* object to use to cache results; can be null to disable cache
*/
cache?: any;
/**
* whether to strip diacritics when filtering (shared with Select)
*/
ignoreAccents?: boolean;
/**
* whether to perform case-insensitive filtering (shared with Select)
*/
ignoreCase?: boolean;
/**
* overrides the isLoading state when set to true
*/
isLoading?: boolean;
/**
* function to call to load options asynchronously
*/
loadOptions: (input: string, callback: (options: Option[]) => any) => any;
/**
* replaces the placeholder while options are loading
*/
loadingPlaceholder?: string;
/**
* the minimum number of characters that trigger loadOptions
*/
minimumInput?: number;
/**
* placeholder displayed when there are no matching search results (shared with Select)
*/
noResultsText?: string;
/**
* field placeholder; displayed when there's no value (shared with Select)
*/
placeholder?: string;
/**
* label to prompt for search input
*/
searchPromptText?: string;
/**
* message to display while options are loading
*/
searchingText?: string;
}
interface ReactSelect extends __React.ReactElement<ReactSelectProps> { }
interface ReactSelectAsyncClass extends __React.ComponentClass<ReactAsyncSelectProps> {
}
const Async: ReactSelectAsyncClass;
interface ReactSelectClass extends __React.ComponentClass<ReactSelectProps> {
Async: ReactSelectAsyncClass;
}
}
declare module "react-select" {
const select: ReactSelect.ReactSelectClass;
export = select;
}