govuk_publishing_components 58.1.1 → 58.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/select-with-search/cross-icon.svg +6 -0
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-search-tracker.js +4 -0
  4. data/app/assets/javascripts/govuk_publishing_components/components/select-with-search.js +57 -0
  5. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  6. data/app/assets/stylesheets/govuk_publishing_components/components/_select-with-search.scss +168 -0
  7. data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +6 -0
  8. data/app/views/govuk_publishing_components/components/_select.html.erb +22 -23
  9. data/app/views/govuk_publishing_components/components/_select_with_search.html.erb +14 -0
  10. data/app/views/govuk_publishing_components/components/docs/select.yml +11 -0
  11. data/app/views/govuk_publishing_components/components/docs/select_with_search.yml +196 -0
  12. data/lib/govuk_publishing_components/presenters/select_helper.rb +8 -5
  13. data/lib/govuk_publishing_components/presenters/select_with_search_helper.rb +92 -0
  14. data/lib/govuk_publishing_components/version.rb +1 -1
  15. data/lib/govuk_publishing_components.rb +1 -0
  16. data/node_modules/choices.js/LICENSE +21 -0
  17. data/node_modules/choices.js/README.md +1360 -0
  18. data/node_modules/choices.js/package.json +173 -0
  19. data/node_modules/choices.js/public/assets/scripts/choices.js +5230 -0
  20. data/node_modules/choices.js/public/assets/scripts/choices.min.js +2 -0
  21. data/node_modules/choices.js/public/assets/scripts/choices.mjs +5222 -0
  22. data/node_modules/choices.js/public/assets/scripts/choices.search-basic.js +4748 -0
  23. data/node_modules/choices.js/public/assets/scripts/choices.search-basic.min.js +2 -0
  24. data/node_modules/choices.js/public/assets/scripts/choices.search-basic.mjs +4740 -0
  25. data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.js +3631 -0
  26. data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.min.js +2 -0
  27. data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.mjs +3623 -0
  28. data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.js +3590 -0
  29. data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.min.js +2 -0
  30. data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.mjs +3582 -0
  31. data/node_modules/choices.js/public/assets/styles/base.css +180 -0
  32. data/node_modules/choices.js/public/assets/styles/base.css.map +1 -0
  33. data/node_modules/choices.js/public/assets/styles/base.min.css +1 -0
  34. data/node_modules/choices.js/public/assets/styles/choices.css +338 -0
  35. data/node_modules/choices.js/public/assets/styles/choices.css.map +1 -0
  36. data/node_modules/choices.js/public/assets/styles/choices.min.css +1 -0
  37. data/node_modules/choices.js/public/types/src/index.d.ts +6 -0
  38. data/node_modules/choices.js/public/types/src/scripts/actions/choices.d.ts +30 -0
  39. data/node_modules/choices.js/public/types/src/scripts/actions/groups.d.ts +8 -0
  40. data/node_modules/choices.js/public/types/src/scripts/actions/items.d.ts +17 -0
  41. data/node_modules/choices.js/public/types/src/scripts/choices.d.ts +210 -0
  42. data/node_modules/choices.js/public/types/src/scripts/components/container.d.ts +36 -0
  43. data/node_modules/choices.js/public/types/src/scripts/components/dropdown.d.ts +21 -0
  44. data/node_modules/choices.js/public/types/src/scripts/components/index.d.ts +7 -0
  45. data/node_modules/choices.js/public/types/src/scripts/components/input.d.ts +37 -0
  46. data/node_modules/choices.js/public/types/src/scripts/components/list.d.ts +14 -0
  47. data/node_modules/choices.js/public/types/src/scripts/components/wrapped-element.d.ts +21 -0
  48. data/node_modules/choices.js/public/types/src/scripts/components/wrapped-input.d.ts +3 -0
  49. data/node_modules/choices.js/public/types/src/scripts/components/wrapped-select.d.ts +20 -0
  50. data/node_modules/choices.js/public/types/src/scripts/constants.d.ts +1 -0
  51. data/node_modules/choices.js/public/types/src/scripts/defaults.d.ts +4 -0
  52. data/node_modules/choices.js/public/types/src/scripts/interfaces/action-type.d.ts +13 -0
  53. data/node_modules/choices.js/public/types/src/scripts/interfaces/build-flags.d.ts +11 -0
  54. data/node_modules/choices.js/public/types/src/scripts/interfaces/choice-full.d.ts +23 -0
  55. data/node_modules/choices.js/public/types/src/scripts/interfaces/class-names.d.ts +61 -0
  56. data/node_modules/choices.js/public/types/src/scripts/interfaces/event-choice.d.ts +7 -0
  57. data/node_modules/choices.js/public/types/src/scripts/interfaces/event-type.d.ts +14 -0
  58. data/node_modules/choices.js/public/types/src/scripts/interfaces/group-full.d.ts +10 -0
  59. data/node_modules/choices.js/public/types/src/scripts/interfaces/index.d.ts +14 -0
  60. data/node_modules/choices.js/public/types/src/scripts/interfaces/input-choice.d.ts +15 -0
  61. data/node_modules/choices.js/public/types/src/scripts/interfaces/input-group.d.ts +10 -0
  62. data/node_modules/choices.js/public/types/src/scripts/interfaces/item.d.ts +17 -0
  63. data/node_modules/choices.js/public/types/src/scripts/interfaces/keycode-map.d.ts +13 -0
  64. data/node_modules/choices.js/public/types/src/scripts/interfaces/options.d.ts +566 -0
  65. data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element-type.d.ts +7 -0
  66. data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element.d.ts +95 -0
  67. data/node_modules/choices.js/public/types/src/scripts/interfaces/position-options-type.d.ts +1 -0
  68. data/node_modules/choices.js/public/types/src/scripts/interfaces/search.d.ts +11 -0
  69. data/node_modules/choices.js/public/types/src/scripts/interfaces/state.d.ts +10 -0
  70. data/node_modules/choices.js/public/types/src/scripts/interfaces/store.d.ts +64 -0
  71. data/node_modules/choices.js/public/types/src/scripts/interfaces/string-pre-escaped.d.ts +3 -0
  72. data/node_modules/choices.js/public/types/src/scripts/interfaces/string-untrusted.d.ts +4 -0
  73. data/node_modules/choices.js/public/types/src/scripts/interfaces/templates.d.ts +29 -0
  74. data/node_modules/choices.js/public/types/src/scripts/interfaces/types.d.ts +18 -0
  75. data/node_modules/choices.js/public/types/src/scripts/lib/choice-input.d.ts +9 -0
  76. data/node_modules/choices.js/public/types/src/scripts/lib/html-guard-statements.d.ts +4 -0
  77. data/node_modules/choices.js/public/types/src/scripts/lib/utils.d.ts +31 -0
  78. data/node_modules/choices.js/public/types/src/scripts/reducers/choices.d.ts +8 -0
  79. data/node_modules/choices.js/public/types/src/scripts/reducers/groups.d.ts +8 -0
  80. data/node_modules/choices.js/public/types/src/scripts/reducers/items.d.ts +9 -0
  81. data/node_modules/choices.js/public/types/src/scripts/search/fuse.d.ts +14 -0
  82. data/node_modules/choices.js/public/types/src/scripts/search/index.d.ts +3 -0
  83. data/node_modules/choices.js/public/types/src/scripts/search/kmp.d.ts +11 -0
  84. data/node_modules/choices.js/public/types/src/scripts/search/prefix-filter.d.ts +11 -0
  85. data/node_modules/choices.js/public/types/src/scripts/store/store.d.ts +59 -0
  86. data/node_modules/choices.js/public/types/src/scripts/templates.d.ts +8 -0
  87. data/node_modules/choices.js/src/entry.js +3 -0
  88. data/node_modules/choices.js/src/icons/cross-inverse.svg +1 -0
  89. data/node_modules/choices.js/src/icons/cross.svg +1 -0
  90. data/node_modules/choices.js/src/index.ts +8 -0
  91. data/node_modules/choices.js/src/scripts/actions/choices.ts +59 -0
  92. data/node_modules/choices.js/src/scripts/actions/groups.ts +14 -0
  93. data/node_modules/choices.js/src/scripts/actions/items.ts +34 -0
  94. data/node_modules/choices.js/src/scripts/choices.ts +2364 -0
  95. data/node_modules/choices.js/src/scripts/components/container.ts +157 -0
  96. data/node_modules/choices.js/src/scripts/components/dropdown.ts +50 -0
  97. data/node_modules/choices.js/src/scripts/components/index.ts +8 -0
  98. data/node_modules/choices.js/src/scripts/components/input.ts +146 -0
  99. data/node_modules/choices.js/src/scripts/components/list.ts +89 -0
  100. data/node_modules/choices.js/src/scripts/components/wrapped-element.ts +89 -0
  101. data/node_modules/choices.js/src/scripts/components/wrapped-input.ts +3 -0
  102. data/node_modules/choices.js/src/scripts/components/wrapped-select.ts +115 -0
  103. data/node_modules/choices.js/src/scripts/constants.ts +1 -0
  104. data/node_modules/choices.js/src/scripts/defaults.ts +93 -0
  105. data/node_modules/choices.js/src/scripts/interfaces/action-type.ts +15 -0
  106. data/node_modules/choices.js/src/scripts/interfaces/build-flags.ts +17 -0
  107. data/node_modules/choices.js/src/scripts/interfaces/choice-full.ts +30 -0
  108. data/node_modules/choices.js/src/scripts/interfaces/class-names.ts +61 -0
  109. data/node_modules/choices.js/src/scripts/interfaces/event-choice.ts +9 -0
  110. data/node_modules/choices.js/src/scripts/interfaces/event-type.ts +16 -0
  111. data/node_modules/choices.js/src/scripts/interfaces/group-full.ts +12 -0
  112. data/node_modules/choices.js/src/scripts/interfaces/index.ts +14 -0
  113. data/node_modules/choices.js/src/scripts/interfaces/input-choice.ts +17 -0
  114. data/node_modules/choices.js/src/scripts/interfaces/input-group.ts +11 -0
  115. data/node_modules/choices.js/src/scripts/interfaces/item.ts +17 -0
  116. data/node_modules/choices.js/src/scripts/interfaces/keycode-map.ts +13 -0
  117. data/node_modules/choices.js/src/scripts/interfaces/options.ts +619 -0
  118. data/node_modules/choices.js/src/scripts/interfaces/passed-element-type.ts +9 -0
  119. data/node_modules/choices.js/src/scripts/interfaces/passed-element.ts +96 -0
  120. data/node_modules/choices.js/src/scripts/interfaces/position-options-type.ts +1 -0
  121. data/node_modules/choices.js/src/scripts/interfaces/search.ts +12 -0
  122. data/node_modules/choices.js/src/scripts/interfaces/state.ts +12 -0
  123. data/node_modules/choices.js/src/scripts/interfaces/store.ts +84 -0
  124. data/node_modules/choices.js/src/scripts/interfaces/string-pre-escaped.ts +3 -0
  125. data/node_modules/choices.js/src/scripts/interfaces/string-untrusted.ts +5 -0
  126. data/node_modules/choices.js/src/scripts/interfaces/templates.ts +66 -0
  127. data/node_modules/choices.js/src/scripts/interfaces/types.ts +21 -0
  128. data/node_modules/choices.js/src/scripts/lib/choice-input.ts +88 -0
  129. data/node_modules/choices.js/src/scripts/lib/html-guard-statements.ts +7 -0
  130. data/node_modules/choices.js/src/scripts/lib/utils.ts +230 -0
  131. data/node_modules/choices.js/src/scripts/reducers/choices.ts +86 -0
  132. data/node_modules/choices.js/src/scripts/reducers/groups.ts +32 -0
  133. data/node_modules/choices.js/src/scripts/reducers/items.ts +86 -0
  134. data/node_modules/choices.js/src/scripts/search/fuse.ts +59 -0
  135. data/node_modules/choices.js/src/scripts/search/index.ts +17 -0
  136. data/node_modules/choices.js/src/scripts/search/kmp.ts +87 -0
  137. data/node_modules/choices.js/src/scripts/search/prefix-filter.ts +42 -0
  138. data/node_modules/choices.js/src/scripts/store/store.ts +184 -0
  139. data/node_modules/choices.js/src/scripts/templates.ts +409 -0
  140. data/node_modules/choices.js/src/styles/base.scss +189 -0
  141. data/node_modules/choices.js/src/styles/choices.scss +414 -0
  142. data/node_modules/choices.js/src/tsconfig.json +22 -0
  143. metadata +134 -1
@@ -0,0 +1,619 @@
1
+ import { IFuseOptions } from 'fuse.js';
2
+ import { InputChoice } from './input-choice';
3
+ import { ClassNames } from './class-names';
4
+ import { PositionOptionsType } from './position-options-type';
5
+ import { Types } from './types';
6
+ // eslint-disable-next-line import/no-cycle
7
+ import { CallbackOnCreateTemplatesFn } from './templates';
8
+
9
+ export const ObjectsInConfig: string[] = ['fuseOptions', 'classNames'];
10
+
11
+ /**
12
+ * Choices options interface
13
+ *
14
+ * **Terminology**
15
+ *
16
+ * - **Choice:** A choice is a value a user can select. A choice would be equivalent to the `<option></option>` element within a select input.
17
+ * - **Group:** A group is a collection of choices. A group should be seen as equivalent to a `<optgroup></optgroup>` element within a select input.
18
+ * - **Item:** An item is an inputted value **_(text input)_** or a selected choice **_(select element)_**. In the context of a select element, an item is equivelent to a selected option element: `<option value="Hello" selected></option>` whereas in the context of a text input an item is equivelant to `<input type="text" value="Hello">`
19
+ */
20
+ export interface Options {
21
+ /**
22
+ * Optionally suppress console errors and warnings.
23
+ *
24
+ * **Input types affected:** text, select-single, select-multiple
25
+ *
26
+ * @default false
27
+ */
28
+ silent: boolean;
29
+
30
+ /**
31
+ * Add pre-selected items (see terminology) to text input.
32
+ *
33
+ * **Input types affected:** text
34
+ *
35
+ * @example
36
+ * ```
37
+ * ['value 1', 'value 2', 'value 3']
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```
42
+ * [{
43
+ * value: 'Value 1',
44
+ * label: 'Label 1',
45
+ * id: 1
46
+ * },
47
+ * {
48
+ * value: 'Value 2',
49
+ * label: 'Label 2',
50
+ * id: 2,
51
+ * customProperties: {
52
+ * random: 'I am a custom property'
53
+ * }
54
+ * }]
55
+ * ```
56
+ *
57
+ * @default []
58
+ */
59
+ items: string[] | InputChoice[];
60
+
61
+ /**
62
+ * Add choices (see terminology) to select input.
63
+ *
64
+ * **Input types affected:** select-one, select-multiple
65
+ *
66
+ * @example
67
+ * ```
68
+ * [{
69
+ * value: 'Option 1',
70
+ * label: 'Option 1',
71
+ * selected: true,
72
+ * disabled: false,
73
+ * },
74
+ * {
75
+ * value: 'Option 2',
76
+ * label: 'Option 2',
77
+ * selected: false,
78
+ * disabled: true,
79
+ * customProperties: {
80
+ * description: 'Custom description about Option 2',
81
+ * random: 'Another random custom property'
82
+ * },
83
+ * },
84
+ * {
85
+ * label: 'Group 1',
86
+ * choices: [{
87
+ * value: 'Option 3',
88
+ * label: 'Option 4',
89
+ * selected: true,
90
+ * disabled: false,
91
+ * },
92
+ * {
93
+ * value: 'Option 2',
94
+ * label: 'Option 2',
95
+ * selected: false,
96
+ * disabled: true,
97
+ * customProperties: {
98
+ * description: 'Custom description about Option 2',
99
+ * random: 'Another random custom property'
100
+ * }
101
+ * }]
102
+ * }]
103
+ * ```
104
+ *
105
+ * @default []
106
+ */
107
+ choices: InputChoice[];
108
+
109
+ /**
110
+ * 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.
111
+ *
112
+ * **Input types affected:** select-one, select-multiple
113
+ *
114
+ * @default -1
115
+ */
116
+ renderChoiceLimit: number;
117
+
118
+ /**
119
+ * The amount of items a user can input/select `("-1" indicates no limit)`.
120
+ *
121
+ * **Input types affected:** text, select-multiple
122
+ *
123
+ * @default -1
124
+ */
125
+ maxItemCount: number;
126
+
127
+ /**
128
+ * Control how the dropdown closes after making a selection for select-one or select-multiple
129
+ *
130
+ * 'auto' defaults based on backing-element type:
131
+ * select-one: true
132
+ * select-multiple: false
133
+ *
134
+ * **Input types affected:** select-one, select-multiple
135
+ *
136
+ * @default 'auto'
137
+ */
138
+ closeDropdownOnSelect: boolean | 'auto';
139
+
140
+ /**
141
+ * Make select-multiple with a max item count of 1 work similar to select-one does.
142
+ * Selecting an item will auto-close the dropdown and swap any existing item for the just selected choice.
143
+ * If applied to a select-one, it functions as above and not the standard select-one.
144
+ *
145
+ * **Input types affected:** select-one, select-multiple
146
+ *
147
+ * @default false
148
+ */
149
+ singleModeForMultiSelect: boolean;
150
+
151
+ /**
152
+ * Whether a user can add choices dynamically.
153
+ *
154
+ * **Input types affected:** select-one, select-multiple
155
+ *
156
+ * @default false
157
+ */
158
+ addChoices: boolean;
159
+
160
+ /**
161
+ * Whether a user can add items.
162
+ *
163
+ * **Input types affected:** text
164
+ *
165
+ * @default true
166
+ */
167
+ addItems: boolean;
168
+
169
+ /**
170
+ * A filter that will need to pass for a user to successfully add an item.
171
+ *
172
+ * **Input types affected:** text, select-one, select-multiple
173
+ *
174
+ * @default (value) => !!value && value !== ''
175
+ */
176
+ addItemFilter: string | RegExp | Types.FilterFunction | null;
177
+
178
+ /**
179
+ * 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.
180
+ * The raw non-sanitised value is passed as a 2nd argument.
181
+ *
182
+ * Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
183
+ *
184
+ * **Input types affected:** text, one-select, select-one, select-multiple
185
+ *
186
+ * @default
187
+ * ```
188
+ * (value, valueRaw) => `Press Enter to add <b>"${value}"</b>`;
189
+ * ```
190
+ */
191
+ addItemText: string | Types.NoticeStringFunction;
192
+
193
+ /**
194
+ * The text/icon for the remove button. To access the item's 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.
195
+ * The raw non-sanitised value is passed as a 2nd argument.
196
+ *
197
+ * Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
198
+ *
199
+ * **Input types affected:** text, select-one, select-multiple
200
+ *
201
+ * @default
202
+ * ```
203
+ * (value, valueRaw) => `Remove item`;
204
+ * ```
205
+ */
206
+ removeItemIconText: string | Types.NoticeStringFunction;
207
+
208
+ /**
209
+ * The text for the remove button's aria label. To access the item's 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.
210
+ * The raw non-sanitised value is passed as a 2nd argument.
211
+ *
212
+ * Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
213
+ *
214
+ * **Input types affected:** text, select-one, select-multiple
215
+ *
216
+ * @default
217
+ * ```
218
+ * (value, valueRaw) => `Remove item: ${value}`;
219
+ * ```
220
+ */
221
+ removeItemLabelText: string | Types.NoticeStringFunction;
222
+
223
+ /**
224
+ * Whether a user can remove items.
225
+ *
226
+ * **Input types affected:** text, select-multiple
227
+ *
228
+ * @default true
229
+ */
230
+ removeItems: boolean;
231
+
232
+ /**
233
+ * Whether each item should have a remove button.
234
+ *
235
+ * **Input types affected:** text, select-one, select-multiple
236
+ *
237
+ * @default false
238
+ */
239
+ removeItemButton: boolean;
240
+ /**
241
+ * Align item remove button left vs right.
242
+ *
243
+ * **Input types affected:** text, select-one, select-multiple
244
+ *
245
+ * @default false
246
+ */
247
+ removeItemButtonAlignLeft: boolean;
248
+ /**
249
+ * Whether a user can edit items. An item's value can be edited by pressing the backspace.
250
+ *
251
+ * **Input types affected:** text
252
+ *
253
+ * @default false
254
+ */
255
+ editItems: boolean;
256
+
257
+ /**
258
+ * Whether HTML should be rendered in all Choices elements.
259
+ * If `false`, all elements (placeholder, items, etc.) will be treated as plain text.
260
+ * If `true`, this can be used to perform XSS scripting attacks if you load choices from a remote source.
261
+ *
262
+ * **Input types affected:** text, select-one, select-multiple
263
+ *
264
+ * @default false
265
+ */
266
+ allowHTML: boolean;
267
+
268
+ /**
269
+ * Whether HTML should be escaped on input when `addItems` or `addChoices` is true.
270
+ * If `false`, user input will be treated as plain text.
271
+ * If `true`, this can be used to perform XSS scripting attacks if you load previously submitted choices from a remote source.
272
+ *
273
+ * **Input types affected:** text, select-one, select-multiple
274
+ *
275
+ * @default false
276
+ */
277
+ allowHtmlUserInput: boolean;
278
+
279
+ /**
280
+ * Whether each inputted/chosen item should be unique.
281
+ *
282
+ * **Input types affected:** text, `select-multiple`, `select-one`
283
+ *
284
+ * @default true
285
+ */
286
+ duplicateItemsAllowed: boolean;
287
+
288
+ /**
289
+ * What divides each value. The default delimiter separates each value with a comma: `"Value 1, Value 2, Value 3"`.
290
+ *
291
+ * **Input types affected:** text
292
+ *
293
+ * @default ','
294
+ */
295
+ delimiter: string;
296
+
297
+ /**
298
+ * Whether a user can paste into the input.
299
+ *
300
+ * **Input types affected:** text, select-multiple
301
+ *
302
+ * @default true
303
+ */
304
+ paste: boolean;
305
+
306
+ /**
307
+ * Whether a search area should be shown.
308
+ *
309
+ * **Input types affected:** select-one, select-multiple
310
+ *
311
+ * @default true
312
+ */
313
+ searchEnabled: boolean;
314
+
315
+ /**
316
+ * Whether choices should be filtered by input or not. If `false`, the search event will still emit, but choices will not be filtered.
317
+ *
318
+ * **Input types affected:** select-one
319
+ *
320
+ * @default true
321
+ */
322
+ searchChoices: boolean;
323
+
324
+ /**
325
+ * The minimum length a search value should be before choices are searched.
326
+ *
327
+ * **Input types affected:** select-one, select-multiple
328
+ *
329
+ * @default 1
330
+ */
331
+ searchFloor: number;
332
+
333
+ /**
334
+ * The maximum amount of search results to show. `("-1" indicates no limit)`
335
+ *
336
+ * **Input types affected:** select-one, select-multiple
337
+ *
338
+ * @default 4
339
+ */
340
+ searchResultLimit: number;
341
+
342
+ /**
343
+ * 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']`.
344
+ *
345
+ * Input types affected:select-one, select-multiple
346
+ *
347
+ * @default ['label', 'value']
348
+ */
349
+ searchFields: string[];
350
+
351
+ /**
352
+ * 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.
353
+ *
354
+ * **Input types affected:** select-one, select-multiple
355
+ *
356
+ * @default 'auto'
357
+ */
358
+ position: PositionOptionsType;
359
+
360
+ /**
361
+ * Whether the scroll position should reset after adding an item.
362
+ *
363
+ * **Input types affected:** select-multiple
364
+ *
365
+ * @default true
366
+ */
367
+ resetScrollPosition: boolean;
368
+
369
+ /**
370
+ * The shadow root for use within ShadowDom
371
+ */
372
+ shadowRoot: ShadowRoot | null;
373
+
374
+ /**
375
+ * Whether choices and groups should be sorted. If false, choices/groups will appear in the order they were given.
376
+ *
377
+ * **Input types affected:** select-one, select-multiple
378
+ *
379
+ * @default true
380
+ */
381
+ shouldSort: boolean;
382
+
383
+ /**
384
+ * Whether items should be sorted. If false, items will appear in the order they were selected.
385
+ *
386
+ * **Input types affected:** text, select-multiple
387
+ *
388
+ * @default false
389
+ */
390
+ shouldSortItems: boolean;
391
+
392
+ /**
393
+ * 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.
394
+ *
395
+ * **Input types affected:** select-one, select-multiple
396
+ *
397
+ * @example
398
+ * ```
399
+ * // Sorting via length of label from largest to smallest
400
+ * const example = new Choices(element, {
401
+ * sorter: function(a, b) {
402
+ * return b.label.length - a.label.length;
403
+ * },
404
+ * };
405
+ * ```
406
+ *
407
+ * @default sortByAlpha
408
+ */
409
+ sorter: (current: Types.RecordToCompare, next: Types.RecordToCompare) => number;
410
+
411
+ /**
412
+ * 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.
413
+ *
414
+ * **Input types affected:** text, select-multiple
415
+ *
416
+ * @note For single select boxes, the recommended way of adding a placeholder is as follows:
417
+ * ```
418
+ * <select data-placeholder="This is a placeholder">
419
+ * <option>...</option>
420
+ * <option>...</option>
421
+ * <option>...</option>
422
+ * </select>
423
+ * ```
424
+ *
425
+ * @default true
426
+ */
427
+ placeholder: boolean;
428
+
429
+ /**
430
+ * The value of the inputs placeholder.
431
+ *
432
+ * **Input types affected:** text, select-multiple
433
+ *
434
+ * @default null
435
+ */
436
+ placeholderValue: string | null;
437
+
438
+ /**
439
+ * The value of the search inputs placeholder.
440
+ *
441
+ * **Input types affected:** select-one
442
+ *
443
+ * @default null
444
+ */
445
+ searchPlaceholderValue: string | null;
446
+
447
+ /**
448
+ * Prepend a value to each item added/selected.
449
+ *
450
+ * **Input types affected:** text, select-one, select-multiple
451
+ *
452
+ * @default null
453
+ */
454
+ prependValue: string | null;
455
+
456
+ /**
457
+ * Append a value to each item added/selected.
458
+ *
459
+ * **Input types affected:** text, select-one, select-multiple
460
+ *
461
+ * @default null
462
+ */
463
+ appendValue: string | null;
464
+
465
+ /**
466
+ * 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`.
467
+ *
468
+ * **Input types affected:** select-one, select-multiple
469
+ *
470
+ * @default 'auto';
471
+ */
472
+ renderSelectedChoices: 'auto' | 'always' | boolean;
473
+
474
+ /**
475
+ * The text that is shown whilst choices are being populated via AJAX.
476
+ *
477
+ * **Input types affected:** select-one, select-multiple
478
+ *
479
+ * @default 'Loading...'
480
+ */
481
+ loadingText: string;
482
+
483
+ /**
484
+ * The text that is shown when a user's search has returned no results. Optionally pass a function returning a string.
485
+ *
486
+ * **Input types affected:** select-one, select-multiple
487
+ *
488
+ * @default 'No results found'
489
+ */
490
+ noResultsText: string | Types.StringFunction;
491
+
492
+ /**
493
+ * The text that is shown when a user has selected all possible choices, or no choices exist. Optionally pass a function returning a string.
494
+ *
495
+ * **Input types affected:** select-multiple, select-one
496
+ *
497
+ * @default 'No choices to choose from'
498
+ */
499
+ noChoicesText: string | Types.StringFunction;
500
+
501
+ /**
502
+ * The text that is shown when a user hovers over a selectable choice. Set to empty to not reserve space for this text.
503
+ *
504
+ * **Input types affected:** select-multiple, select-one
505
+ *
506
+ * @default 'Press to select'
507
+ */
508
+ itemSelectText: string;
509
+
510
+ /**
511
+ * The text that is shown when a user has focus on the input but has already reached the **max item count** [https://github.com/jshjohnson/Choices#maxitemcount]. 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.
512
+ *
513
+ * **Input types affected:** text
514
+ *
515
+ * @default
516
+ * ```
517
+ * (maxItemCount) => `Only ${maxItemCount} values can be added.`;
518
+ * ```
519
+ */
520
+ maxItemText: string | Types.NoticeLimitFunction;
521
+
522
+ /**
523
+ * If no duplicates are allowed, and the value already exists in the array.
524
+ *
525
+ * Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
526
+ *
527
+ * @default 'Only unique values can be added'
528
+ */
529
+ uniqueItemText: string | Types.NoticeStringFunction;
530
+
531
+ /**
532
+ * The text that is shown when addItemFilter is passed and it returns false
533
+ *
534
+ * Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
535
+ *
536
+ * **Input types affected:** text
537
+ *
538
+ * @default 'Only values matching specific conditions can be added'
539
+ */
540
+ customAddItemText: string | Types.NoticeStringFunction;
541
+
542
+ /**
543
+ * Compare choice and value in appropriate way (e.g. deep equality for objects). To compare choice and value, pass a function with a `valueComparer` argument (see the [default config](https://github.com/jshjohnson/Choices#setup) for an example).
544
+ *
545
+ * **Input types affected:** select-one, select-multiple
546
+ *
547
+ * @default
548
+ * ```
549
+ * (choice, item) => choice === item;
550
+ * ```
551
+ */
552
+ valueComparer: Types.ValueCompareFunction;
553
+
554
+ /**
555
+ * Classes added to HTML generated by By default classnames follow the BEM notation.
556
+ *
557
+ * **Input types affected:** text, select-one, select-multiple
558
+ */
559
+ classNames: ClassNames;
560
+
561
+ /**
562
+ * Choices uses the great Fuse library for searching. You can find more options here: https://fusejs.io/api/options.html
563
+ */
564
+ fuseOptions: IFuseOptions<unknown>; // IFuseOptions<Choices>;
565
+
566
+ /**
567
+ * ID of the connected label to improve a11y. If set, aria-labelledby will be added.
568
+ */
569
+ labelId: string;
570
+
571
+ /**
572
+ * Function to run once Choices initialises.
573
+ *
574
+ * **Input types affected:** text, select-one, select-multiple
575
+ *
576
+ * @note For each callback, this refers to the current instance of This can be useful if you need access to methods `(this.disable())` or the config object `(this.config)`.
577
+ *
578
+ * @default null
579
+ */
580
+ callbackOnInit: (() => void) | null;
581
+
582
+ /**
583
+ * 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].
584
+ *
585
+ * **Input types affected:** text, select-one, select-multiple
586
+ *
587
+ * @note For each callback, `this` refers to the current instance of Choices. This can be useful if you need access to methods `(this.disable())`.
588
+ *
589
+ * @example
590
+ * ```
591
+ * const example = new Choices(element, {
592
+ * callbackOnCreateTemplates: function (template, originalTemplates, getClassNames) {
593
+ * var classNames = this.config.classNames;
594
+ * return {
595
+ * item: (data) => {
596
+ * return template(`
597
+ * <div class="${getClassNames(classNames.item).join(' ')} ${data.highlighted ? classNames.highlightedState : classNames.itemSelectable}" data-item data-id="${data.id}" data-value="${data.value}" ${data.active ? 'aria-selected="true"' : ''} ${data.disabled ? 'aria-disabled="true"' : ''}>
598
+ * <span>&bigstar;</span> ${data.label}
599
+ * </div>
600
+ * `);
601
+ * },
602
+ * choice: (data) => {
603
+ * return template(`
604
+ * <div class="${getClassNames(classNames.item).join(' ')} ${classNames.itemChoice} ${data.disabled ? classNames.itemDisabled : classNames.itemSelectable}" data-select-text="${this.config.itemSelectText}" data-choice ${data.disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable'} data-id="${data.id}" data-value="${data.value}" ${data.groupId ? 'role="treeitem"' : 'role="option"'}>
605
+ * <span>&bigstar;</span> ${data.label}
606
+ * </div>
607
+ * `);
608
+ * },
609
+ * };
610
+ * }
611
+ * });
612
+ * ```
613
+ *
614
+ * @default null
615
+ */
616
+ callbackOnCreateTemplates: CallbackOnCreateTemplatesFn | null;
617
+
618
+ appendGroupInSearch: false;
619
+ }
@@ -0,0 +1,9 @@
1
+ import { Types } from './types';
2
+
3
+ export const PassedElementTypes = {
4
+ Text: 'text',
5
+ SelectOne: 'select-one',
6
+ SelectMultiple: 'select-multiple',
7
+ } as const;
8
+
9
+ export type PassedElementType = Types.ValueOf<typeof PassedElementTypes>;