-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnb-choices.d.ts
715 lines (621 loc) · 19.2 KB
/
nb-choices.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
declare module "choices.js" {
class Choices {
passedElement: Element;
constructor( element?: string | HTMLElement | HTMLCollectionOf<HTMLElement> | NodeList, userConfig?: Choices.Options );
new( element?: string | HTMLElement | HTMLCollectionOf<HTMLElement> | NodeList, userConfig?: Choices.Options ): this;
/**
* Initialise Choices
* @return
* @public
*/
init(): void;
/**
* Destroy Choices and nullify values
* @return
* @public
*/
destroy(): void;
/**
* Select item (a selected item can be deleted)
* @param {Element} item Element to select
* @param {boolean} runEvent Whether to highlight immediately or not. Defaults to true.
* @return {Object} Class instance
* @public
*/
highlightItem( item: Element, runEvent?: boolean ): this;
/**
* Deselect item
* @param {Element} item Element to de-select
* @return {Object} Class instance
* @public
*/
unhighlightItem( item: Element ): this;
/**
* Highlight items within store
* @return {Object} Class instance
* @public
*/
highlightAll(): this;
/**
* Deselect items within store
* @return {Object} Class instance
* @public
*/
unhighlightAll(): this;
/**
* Remove an item from the store by its value
* @param {String} value Value to search for
* @return {Object} Class instance
* @public
*/
removeItemsByValue( value: string ): this;
/**
* Remove all items from store array
* @note Removed items are soft deleted
* @param {Number} excludedId Optionally exclude item by ID
* @return {Object} Class instance
* @public
*/
removeActiveItems( excludedId?: number ): this;
/**
* Remove all selected items from store
* @note Removed items are soft deleted
* @param {boolean} runEvent Whether to remove highlighted items immediately or not. Defaults to false.
* @return {Object} Class instance
* @public
*/
removeHighlightedItems( runEvent?: boolean ): this;
/**
* Show dropdown to user by adding active state class
* @param {boolean} focusInput Whether to focus the input or not. Defaults to false.
* @return {Object} Class instance
* @public
*/
showDropdown( focusInput?: boolean ): this;
/**
* Hide dropdown from user
* @param {boolean} focusInput Whether to blur input focus or not. Defaults to false.
* @return {Object} Class instance
* @public
*/
hideDropdown( blurInput?: boolean ): this;
/**
* Determine whether to hide or show dropdown based on its current state
* @return {Object} Class instance
* @public
*/
toggleDropdown(): this;
/**
* Get value(s) of input (i.e. inputted items (text) or selected choices (select))
* @param {Boolean} valueOnly Get only values of selected items, otherwise return selected items
* @return {Array/String} selected value (select-one) or array of selected items (inputs & select-multiple)
* @public
*/
getValue( valueOnly?: boolean ): string | string[] | Choices.Choice;
getValue( valueOnly?: boolean ): Choices.Choice[];
/**
* Set value of input. If the input is a select box, a choice will be created and selected otherwise
* an item will created directly.
* @param {Array} args Array of value objects or value strings
* @return {Object} Class instance
* @public
*/
setValue( args: any[] ): this;
/**
* Select value of select box via the value of an existing choice
* @param {Array/String} value An array of strings of a single string
* @return {Object} Class instance
* @public
*/
setValueByChoice( value: string | string[] ): this;
/**
* Direct populate choices
* @param {Array} choices - Choices to insert
* @param {String} value - Name of 'value' property
* @param {String} label - Name of 'label' property
* @param {Boolean} replaceChoices Whether existing choices should be removed
* @return {Object} Class instance
* @public
*/
setChoices( choices: any[], value: string, label: string, replaceChoices?: boolean ): this;
/**
* Clear items,choices and groups
* @note Hard delete
* @return {Object} Class instance
* @public
*/
clearStore(): this;
/**
* Set value of input to blank
* @return {Object} Class instance
* @public
*/
clearInput(): this;
/**
* Enable interaction with Choices
* @return {Object} Class instance
*/
enable(): this;
/**
* Disable interaction with Choices
* @return {Object} Class instance
* @public
*/
disable(): this;
/**
* Populate options via ajax callback
* @param {Function} fn Passed
* @return {Object} Class instance
* @public
*/
ajax( fn: ( values: any ) => any ): this;
}
namespace Choices {
interface ClassNames {
/**
* @default 'choices'
*/
containerOuter?: string;
/**
* @default 'choices__inner'
*/
containerInner?: string;
/**
* @default 'choices__input'
*/
input?: string;
/**
* @default 'choices__input--cloned'
*/
inputCloned?: string;
/**
* @default 'choices__list'
*/
list?: string;
/**
* @default 'choices__list--multiple'
*/
listItems?: string;
/**
* @default 'choices__list--single'
*/
listSingle?: string;
/**
* @default 'choices__list--dropdown'
*/
listDropdown?: string;
/**
* @default 'choices__item'
*/
item?: string;
/**
* @default 'choices__item--selectable'
*/
itemSelectable?: string;
/**
* @default 'choices__item--disabled'
*/
itemDisabled?: string;
/**
* @default 'choices__item--choice'
*/
itemOption?: string;
/**
* @default 'choices__group'
*/
group?: string;
/**
* @default 'choices__heading'
*/
groupHeading?: string;
/**
* @default 'choices__placeholder'
*/
placeholder?: string;
/**
* @default 'choices__button'
*/
button?: string;
/**
* @default 'is-active'
*/
activeState?: string;
/**
* @default 'is-focused'
*/
focusState?: string;
/**
* @default 'is-open'
*/
openState?: string;
/**
* @default 'is-disabled'
*/
disabledState?: string;
/**
* @default 'is-highlighted'
*/
highlightedState?: string;
/**
* @default 'is-hidden'
*/
hiddenState?: string;
/**
* @default 'is-flipped'
*/
flippedState?: string;
/**
* @default 'is-loading'
*/
loadingState?: string;
/**
* @default 'choices__item--choice'
*/
itemChoice?: string;
/**
* @default 'has-no-results'
*/
noResults?: string;
/**
* @default 'has-no-choices'
*/
noChoices?: string;
}
interface Choice {
id: number;
highlighted: boolean;
elementId: string;
groupId: number;
value: number;
label: string;
disabled: boolean;
selected: boolean;
active: boolean;
score?: number;
customProperties: any;
placeholder: boolean;
keyCode: string;
isPlaceholder?: boolean;
}
interface Options {
/**
* Optionally suppress console errors and warnings.
*
* Input types affected: text, select-single, select-multiple
* @default false
*/
silent?: boolean;
/**
* Add pre-selected items (see terminology) to text input.
*
* Pass an array of strings:
*
* ['value 1', 'value 2', 'value 3']
*
* Pass an array of objects:
*
* [{
* value: 'Value 1',
* label: 'Label 1',
* id: 1
* },
* {
* value: 'Value 2',
* label: 'Label 2',
* id: 2,
* customProperties: {
* random: 'I am a custom property'
* }
* }]
*
* Input types affected: text
* @default []
*/
items?: any[];
/**
* Add choices (see terminology) to select input.
*
* Pass an array of objects:
*
* [{
* value: 'Option 1',
* label: 'Option 1',
* selected: true,
* disabled: false,
* },
* {
* value: 'Option 2',
* label: 'Option 2',
* selected: false,
* disabled: true,
* customProperties: {
* description: 'Custom description about Option 2',
* random: 'Another random custom property'
* },
* }]
*
* Input types affected: select-one, select-multiple
* @default []
*/
choices?: any[];
/**
* The amount of choices to be rendered within the dropdown list ("-1" indicates no limit). This is useful if you have a lot of choices where it is easier for a user to use the search area to find a choice.
*
* Input types affected: select-one, select-multiple
* @default -1
*/
renderChoiceLimit?: number;
/**
* The amount of items a user can input/select ("-1" indicates no limit).
*
* Input types affected: text, select-multiple
* @default -1
*/
maxItemCount?: number;
/**
* Whether a user can add items.
*
* Input types affected: text
* @default true
*/
addItems?: boolean;
/**
* Whether a user can remove items.
*
* Input types affected: text, select-multiple
* @default true
*/
removeItems?: boolean;
/**
* Whether each item should have a remove button.
*
* Input types affected: text, select-one, select-multiple
* @default false
*/
removeItemButton?: boolean;
/**
* Whether a user can edit items. An item's value can be edited by pressing the backspace.
*
* Input types affected: text
* @default false
*/
editItems?: boolean;
/**
* Whether each inputted/chosen item should be unique.
*
* Input types affected: text, select-multiple
* @default true
*/
duplicateItems?: boolean;
/**
* What divides each value. The default delimiter seperates each value with a comma: "Value 1, Value 2, Value 3".
*
* Input types affected: text, select-multiple
* @default true
*/
delimiter?: string;
/**
* Whether a user can paste into the input.
*
* Input types affected: text, select-multiple
* @default true
*/
paste?: boolean;
/**
* Whether a search area should be shown. *Note:* Multiple select boxes will _always_ show search areas.
*
* Input types affected: select-one
* @default true
*/
searchEnabled?: boolean;
/**
* Whether choices should be filtered by input or not. If false, the search event will still emit, but choices will not be filtered.
*
* Input types affected: select-one
* @default true
*/
searchChoices?: boolean;
/**
* Specify which fields should be used when a user is searching. If you have added custom properties to your choices, you can add these values thus: ['label', 'value', 'customProperties.example'].
*
* Input types affected: select-one, select-multiple
* @default ['label', 'value']
*/
searchFields?: string[];
/**
* The minimum length a search value should be before choices are searched.
*
* Input types affected: select-one, select-multiple
* @default 1
*/
searchFloor?: number;
/**
* The maximum amount of search results to show.
*
* Input types affected: select-one, select-multiple
* @default 4
*/
searchResultLimit?: number;
/**
* Whether the dropdown should appear above (top) or below (bottom) the input. By default, if there is not enough space within the window the dropdown will appear above the input, otherwise below it.
*
* Input types affected: select-one, select-multiple
* @default 'auto'
*/
position?: string;
/**
* Whether the scroll position should reset after adding an item.
*
* Input types affected: select-multiple
* @default true
*/
resetScrollPosition?: boolean;
/**
* A filter that will need to pass for a user to successfully add an item.
*
* Input types affected: text
* @default null
*/
regexFilter?: RegExp;
/**
* Whether choices and groups should be sorted. If false, choices/groups will appear in the order they were given.
*
* Input types affected: select-one, select-multiple
* @default true
*/
shouldSort?: boolean;
/**
* Whether items should be sorted. If false, items will appear in the order they were selected.
*
* Input types affected: text, select-multiple
* @default false
*/
shouldSortItems?: boolean;
/**
* The function that will sort choices and items before they are displayed (unless a user is searching). By default choices and items are sorted by alphabetical order.
*
* Input types affected: select-one, select-multiple
*
* @example
* // Sorting via length of label from largest to smallest
* const example = new Choices(element, {
* sortFilter: function(a, b) {
* return b.label.length - a.label.length;
* },
* };
*
* @default sortByAlpha
*/
sortFilter?: ( current: any, next: any ) => number;
/**
* Whether the input should show a placeholder. Used in conjunction with placeholderValue. If placeholder is set to true and no value is passed to placeholderValue, the passed input's placeholder attribute will be used as the placeholder value.
*
* Note: For single select boxes, the recommended way of adding a placeholder is as follows:
* <select>
* <option placeholder>This is a placeholder</option>
* <option>...</option>
* <option>...</option>
* <option>...</option>
* </select>
*
* Input types affected: text, select-multiple
* @default true
*/
placeholder?: boolean;
/**
* The value of the inputs placeholder.
*
* Input types affected: text, select-multiple
* @default null
*/
placeholderValue?: string;
/**
* The value of the search inputs placeholder.
*
* Input types affected: select-one
* @default null
*/
searchPlaceholderValue?: string;
/**
* Prepend a value to each item added/selected.
*
* Input types affected: text, select-one, select-multiple
* @default null
*/
prependValue?: string;
/**
* Append a value to each item added/selected.
*
* Input types affected: text, select-one, select-multiple
* @default null
*/
appendValue?: string;
/**
* Whether selected choices should be removed from the list. By default choices are removed when they are selected in multiple select box. To always render choices pass always.
*
* Input types affected: select-one, select-multiple
* @default 'auto'
*/
renderSelectedChoices?: string;
/**
* The text that is shown whilst choices are being populated via AJAX.
*
* Input types affected: select-one, select-multiple
* @default 'Loading...'
*/
loadingText?: string;
/**
* The text that is shown when a user's search has returned no results. Optionally pass a function returning a string.
*
* Input types affected: select-one, select-multiple
* @default 'No results found'
*/
noResultsText?: string | (() => string);
/**
* The text that is shown when a user has selected all possible choices. Optionally pass a function returning a string.
*
* Input types affected: select-multiple
* @default 'No choices to choose from'
*/
noChoicesText?: string | (() => string);
/**
* The text that is shown when a user hovers over a selectable choice.
*
* Input types affected: select-one, select-multiple
* @default 'Press to select'
*/
itemSelectText?: string;
/**
* The text that is shown when a user has inputted a new item but has not pressed the enter key. To access the current input value, pass a function with a value argument (see the [default config](https://github.com/jshjohnson/Choices#setup) for an example), otherwise pass a string.
*
* Input types affected: text
* @default 'Press Enter to add "${value}"'
*/
addItemText?: (( value: string ) => string) | string;
/**
* The text that is shown when a user has focus on the input but has already reached the max item count. To access the max item count, pass a function with a maxItemCount argument (see the [default config](https://github.com/jshjohnson/Choices#setup) for an example), otherwise pass a string.
*
* Input types affected: text
* @default 'Only ${maxItemCount} values can be added.'
*/
maxItemText?: ( maxItemCount: number ) => string,
/**
* The text that is shown when a user has submitted a new item that is already present in the selected list. To access the current input value, pass a function with a value argument, otherwise pass a string.
*
* @default 'Only unique values can be added.'
*/
uniqueItemText?: (( value: string ) => string) | string;
/**
* Classes added to HTML generated by Choices. By default classnames follow the BEM notation.
*/
classNames?: ClassNames;
/**
* Choices uses the great Fuse library for searching. You can find more options here: https://github.com/krisk/Fuse#options
*/
fuseOptions?: {
[index: string]: any;
/**
* @default 'score'
*/
include?: string;
};
/**
* Function to run once Choices initialises.
*
* Input types affected: text, select-one, select-multiple
*
* @default null
*/
callbackOnInit?: () => any;
/**
* Function to run on template creation. Through this callback it is possible to provide custom templates for the various components of Choices (see terminology). For Choices to work with custom templates, it is important you maintain the various data attributes defined [here](https://github.com/jshjohnson/Choices/blob/67f29c286aa21d88847adfcd6304dc7d068dc01f/assets/scripts/src/choices.js#L1993-L2067).
*
* Input types affected: text, select-one, select-multiple
*
* @default null
*/
callbackOnCreateTemplates?: ( template: string ) => string;
}
}
export = Choices;
}