@snack-uikit/fields 0.18.3 → 0.19.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 (41) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +0 -204
  3. package/dist/components/FieldDate/FieldDate.js +1 -1
  4. package/dist/components/FieldSelect/FieldSelectMultiple.d.ts +3 -1
  5. package/dist/components/FieldSelect/FieldSelectMultiple.js +9 -2
  6. package/dist/components/FieldSelect/FieldSelectSingle.d.ts +3 -1
  7. package/dist/components/FieldSelect/FieldSelectSingle.js +16 -4
  8. package/dist/components/FieldSelect/hooks.js +8 -2
  9. package/dist/components/FieldSelect/legacy/components/Items/hooks.d.ts +12 -0
  10. package/dist/components/FieldSelect/legacy/components/Items/hooks.js +33 -0
  11. package/dist/components/FieldSelect/legacy/components/index.d.ts +1 -0
  12. package/dist/components/FieldSelect/legacy/components/index.js +1 -0
  13. package/dist/components/FieldSelect/legacy/hooks.d.ts +5 -0
  14. package/dist/components/FieldSelect/legacy/hooks.js +19 -0
  15. package/dist/components/FieldSelect/legacy/index.d.ts +3 -0
  16. package/dist/components/FieldSelect/legacy/index.js +3 -0
  17. package/dist/components/FieldSelect/legacy/utils.d.ts +29 -0
  18. package/dist/components/FieldSelect/legacy/utils.js +107 -0
  19. package/dist/components/FieldSelect/types.d.ts +6 -3
  20. package/dist/components/FieldSelect/utils/extractListProps.d.ts +1 -1
  21. package/dist/components/FieldSelect/utils/extractListProps.js +1 -3
  22. package/dist/components/FieldSelect/utils/options.js +1 -1
  23. package/dist/components/FieldSelect/utils/typeGuards.js +1 -1
  24. package/dist/components/FieldSelect/utils/updateItems.d.ts +6 -6
  25. package/dist/components/FieldSelect/utils/updateItems.js +12 -3
  26. package/dist/helperComponents/FieldContainerPrivate/styles.module.css +1 -1
  27. package/package.json +15 -13
  28. package/src/components/FieldDate/FieldDate.tsx +1 -1
  29. package/src/components/FieldSelect/FieldSelectMultiple.tsx +10 -2
  30. package/src/components/FieldSelect/FieldSelectSingle.tsx +14 -3
  31. package/src/components/FieldSelect/hooks.ts +11 -2
  32. package/src/components/FieldSelect/legacy/components/Items/hooks.tsx +53 -0
  33. package/src/components/FieldSelect/legacy/components/index.ts +1 -0
  34. package/src/components/FieldSelect/legacy/hooks.ts +32 -0
  35. package/src/components/FieldSelect/legacy/index.ts +3 -0
  36. package/src/components/FieldSelect/legacy/utils.ts +166 -0
  37. package/src/components/FieldSelect/types.ts +29 -12
  38. package/src/components/FieldSelect/utils/extractListProps.ts +0 -4
  39. package/src/components/FieldSelect/utils/options.ts +2 -1
  40. package/src/components/FieldSelect/utils/typeGuards.ts +1 -1
  41. package/src/components/FieldSelect/utils/updateItems.ts +14 -4
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.19.0 (2024-04-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **PDS-59:** upd tests ([df72712](https://github.com/cloud-ru-tech/snack-uikit/commit/df7271268ac1621316dbb98b274e3d6602515b23))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+
17
+ * **PDS-59:** upd typings accordance with list; fix focus control ([827ff9f](https://github.com/cloud-ru-tech/snack-uikit/commit/827ff9f03ca5bae4664bc69664e4b8d812191103))
18
+
19
+
20
+
21
+
6
22
  ## 0.18.3 (2024-04-22)
7
23
 
8
24
 
package/README.md CHANGED
@@ -167,111 +167,22 @@ const [isOpen, setIsOpen] = useState(false);
167
167
  ### Props
168
168
  | name | type | default value | description |
169
169
  |------|------|---------------|-------------|
170
- | children* | `ReactNode` | - | Контент |
171
- | className | `string` | - | CSS-класс |
172
- | disabled | `boolean` | - | Деактивирован ли элемент Является ли поле деактивированным |
173
- | readonly | `boolean` | - | Является ли поле доступным только на чтение Доступно ли поле только на чтение |
174
- | error | `string` | - | |
175
- | label | `string` | - | Лейбл |
176
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
177
- | labelFor | `string` | - | Аттрибут for |
178
- | required | `boolean` | - | Является ли поле обязательным |
179
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
180
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
181
- | length | `{ current: number; max?: number; }` | - | Допустимая длинна текста |
182
- | hint | `string` | - | Подсказка внизу |
183
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | - | Состояние валидации |
184
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
185
170
  ## FieldText
186
171
  ### Props
187
172
  | name | type | default value | description |
188
173
  |------|------|---------------|-------------|
189
- | showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
190
- | showClearButton | `boolean` | true | Отображение кнопки очистки поля |
191
- | allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
192
- | prefixIcon | `ReactElement<any, string \| JSXElementConstructor<any>>` | - | Иконка-префикс для поля |
193
- | value | `string` | - | Значение input |
194
- | onChange | `(value: string, e?: ChangeEvent<HTMLInputElement>) => void` | - | Колбек смены значения |
195
- | disabled | `boolean` | - | Является ли поле деактивированным |
196
- | readonly | `boolean` | - | Является ли поле доступным только для чтения |
197
- | id | `string` | - | Значение html-атрибута id |
198
- | name | `string` | - | Значение html-атрибута name |
199
- | placeholder | `string` | - | Значение плейсхолдера |
200
- | maxLength | `number` | - | Максимальная длина вводимого значения |
201
- | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
202
- | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
203
- | error | `string` | - | |
204
- | className | `string` | - | CSS-класс |
205
- | label | `string` | - | Лейбл |
206
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
207
- | required | `boolean` | - | Является ли поле обязательным |
208
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
209
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
210
- | hint | `string` | - | Подсказка внизу |
211
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | default | Состояние валидации |
212
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
213
174
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
214
175
  | key | `Key` | - | |
215
176
  ## FieldTextArea
216
177
  ### Props
217
178
  | name | type | default value | description |
218
179
  |------|------|---------------|-------------|
219
- | maxRows | `number` | - | Максимальное кол-во строк, до которого размер поля может быть увеличен |
220
- | resizable | `boolean` | - | Может ли ли пользователь изменять размеры поля (если св-во не включено, поле автоматически меняет свой размер) |
221
- | onChange | `(value: string, e?: ChangeEvent<HTMLTextAreaElement>) => void` | - | Колбек смены значения |
222
- | showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
223
- | showClearButton | `boolean` | true | Отображение кнопки очистки поля |
224
- | allowMoreThanMaxLength | `boolean` | true | Можно ли вводить больше разрешённого кол-ва символов |
225
- | value | `string` | - | HTML-аттрибут value |
226
- | disabled | `boolean` | - | Является ли поле деактивированным |
227
- | readonly | `boolean` | - | Является ли поле доступным только на чтение |
228
- | id | `string` | - | HTML-аттрибут id |
229
- | name | `string` | - | HTML-аттрибут name |
230
- | placeholder | `string` | - | Плейсхолдер |
231
- | maxLength | `number` | - | Максимальное кол-во символов |
232
- | onFocus | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек получения фокуса |
233
- | onBlur | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек потери фокуса |
234
- | error | `string` | - | |
235
- | className | `string` | - | CSS-класс |
236
- | label | `string` | - | Лейбл |
237
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
238
- | required | `boolean` | - | Является ли поле обязательным |
239
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
240
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
241
- | hint | `string` | - | Подсказка внизу |
242
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | default | Состояние валидации |
243
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
244
180
  | ref | `Ref<HTMLTextAreaElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
245
181
  | key | `Key` | - | |
246
182
  ## FieldSecure
247
183
  ### Props
248
184
  | name | type | default value | description |
249
185
  |------|------|---------------|-------------|
250
- | hidden | `boolean` | - | Замаскированно ли значение поля |
251
- | onHiddenChange | `(value: boolean) => void` | - | Колбек смены маскирования |
252
- | showCopyButton | `boolean` | - | Отображение кнопки копирования |
253
- | allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
254
- | prefixIcon | `ReactElement<any, string \| JSXElementConstructor<any>>` | - | Иконка-префикс для поля |
255
- | value | `string` | - | Значение input |
256
- | onChange | `(value: string, e?: ChangeEvent<HTMLInputElement>) => void` | - | Колбек смены значения |
257
- | disabled | `boolean` | - | Является ли поле деактивированным |
258
- | readonly | `boolean` | - | Является ли поле доступным только для чтения |
259
- | id | `string` | - | Значение html-атрибута id |
260
- | name | `string` | - | Значение html-атрибута name |
261
- | placeholder | `string` | - | Значение плейсхолдера |
262
- | maxLength | `number` | - | Максимальная длина вводимого значения |
263
- | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
264
- | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
265
- | error | `string` | - | |
266
- | className | `string` | - | CSS-класс |
267
- | label | `string` | - | Лейбл |
268
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
269
- | required | `boolean` | - | Является ли поле обязательным |
270
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
271
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
272
- | hint | `string` | - | Подсказка внизу |
273
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | default | Состояние валидации |
274
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
275
186
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
276
187
  | key | `Key` | - | |
277
188
  ## parseDate
@@ -282,139 +193,24 @@ const [isOpen, setIsOpen] = useState(false);
282
193
  ### Props
283
194
  | name | type | default value | description |
284
195
  |------|------|---------------|-------------|
285
- | value* | `string` | - | Значение input |
286
- | open | `boolean` | - | Открыт date-picker |
287
- | onOpenChange | `(value: boolean) => void` | - | Колбек открытия пикера |
288
- | onChange | `(value: string) => void` | - | Колбек смены значения |
289
- | showCopyButton | `boolean` | - | Отображение кнопки копирования |
290
- | showClearButton | `boolean` | true | Отображение кнопки Очистки поля |
291
- | locale | `Locale` | new Intl.Locale('ru-RU') | Текущая локаль календаря |
292
- | buildCellProps | `(date: Date, viewMode: ViewMode) => { isDisabled?: boolean; isHoliday?: boolean };` | - | Колбек установки свойств ячеек календаря. Вызывается на построение каждой ячейки. Принимает два параметра: <br> `Date` - дата ячейки <br> `ViewMode`: <br> - `month` отображение месяца, каждая ячейка - 1 день <br> - `year` отображение года, каждая ячейка - 1 месяц <br> - `decade` отображение декады, каждая ячейка - 1 год <br><br> Колбек должен возвращать объект с полями, отвечающими за отключение и подкраску ячейки. |
293
- | disabled | `boolean` | - | Является ли поле деактивированным |
294
- | readonly | `boolean` | - | Является ли поле доступным только для чтения |
295
- | id | `string` | - | Значение html-атрибута id |
296
- | name | `string` | - | Значение html-атрибута name |
297
- | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
298
- | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
299
- | error | `string` | - | |
300
- | className | `string` | - | CSS-класс |
301
- | label | `string` | - | Лейбл |
302
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
303
- | required | `boolean` | - | Является ли поле обязательным |
304
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
305
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
306
- | hint | `string` | - | Подсказка внизу |
307
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | default | Состояние валидации |
308
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
309
196
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
310
197
  | key | `Key` | - | |
311
198
  ## FieldSelect
312
199
  ### Props
313
200
  | name | type | default value | description |
314
201
  |------|------|---------------|-------------|
315
- | options* | `OptionProps[]` | - | |
316
- | disabled | `boolean` | false | Является ли поле деактивированным |
317
- | readonly | `boolean` | false false | Является ли поле доступным только для чтения |
318
- | id | `string` | - | Значение html-атрибута id |
319
- | name | `string` | - | Значение html-атрибута name |
320
- | placeholder | `string` | - | Значение плейсхолдера |
321
- | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
322
- | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
323
- | onKeyDown | `KeyboardEventHandler<HTMLInputElement>` | - | Колбек обработки нажатия клавиши клавиатуры |
324
- | error | `string` | - | |
325
- | className | `string` | - | CSS-класс |
326
- | label | `string` | - | Лейбл |
327
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
328
- | required | `boolean` | - | Является ли поле обязательным |
329
- | size | enum Size: `"s"`, `"m"`, `"l"` | - | Размер |
330
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
331
- | hint | `string` | - | Подсказка внизу |
332
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | - | Состояние валидации |
333
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
334
- | loading | `boolean` | - | |
335
- | value | `SelectionSingleValueType \| SelectionSingleValueType[]` | - | Controlled состояние |
336
- | onChange | `((value: any) => void) \| ((value: any) => void)` | - | Controlled обработчик измения состояния |
337
- | defaultValue | `SelectionSingleValueType \| SelectionSingleValueType[]` | - | Начальное состояние |
338
- | searchable | `boolean` | - | |
339
- | showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
340
- | showClearButton | `boolean` | true | Отображение кнопки очистки поля |
341
- | prefixIcon | `ReactElement<any, string \| JSXElementConstructor<any>>` | - | Иконка-префикс для поля |
342
- | footer | `ReactNode` | - | |
343
- | widthStrategy | enum PopoverWidthStrategy: `"auto"`, `"gte"`, `"eq"` | - | |
344
- | search | `SearchState` | - | |
345
- | autocomplete | `boolean` | - | |
346
- | addOptionByEnter | `boolean` | - | |
347
- | open | `boolean` | - | |
348
- | onOpenChange | `(open: boolean) => void` | - | |
349
- | selectedOptionFormatter | `SelectedOptionFormatter` | - | |
350
- | pinTop | `ItemProps[]` | - | Элементы списка, закрепленные сверху |
351
- | pinBottom | `ItemProps[]` | - | Элементы списка, закрепленные снизу |
352
- | dataFiltered | `boolean` | - | |
353
- | dataError | `boolean` | - | |
354
- | noDataState | `EmptyStateProps` | - | Экран при отстутствии данных |
355
- | noResultsState | `EmptyStateProps` | - | Экран при отстутствии результатов поиска или фильтров |
356
- | errorDataState | `EmptyStateProps` | - | Экран при ошибке запроса |
357
- | selection | "single" \| "multiple" | - | |
358
202
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
359
203
  | key | `Key` | - | |
360
- | removeByBackspace | `boolean` | - | |
361
204
  ## FieldStepper
362
205
  ### Props
363
206
  | name | type | default value | description |
364
207
  |------|------|---------------|-------------|
365
- | value | `number` | - | Значение поля |
366
- | onChange | `(value: number, e?: ChangeEvent<HTMLInputElement>) => void` | - | Колбек смены значения |
367
- | step | `number` | 1 | Шаг поля |
368
- | allowMoreThanLimits | `boolean` | true | Можно ли вводить c клавиатуры числа, выходящие за пределы min/max |
369
- | disabled | `boolean` | - | Является ли поле деактивированным |
370
- | readonly | `boolean` | - | Является ли поле доступным только для чтения |
371
- | id | `string` | - | Значение html-атрибута id |
372
- | name | `string` | - | Значение html-атрибута name |
373
- | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
374
- | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
375
- | min | `number` | Number.NEGATIVE_INFINITY | Минимальное значение поля |
376
- | max | `number` | Number.POSITIVE_INFINITY | Максимальное значение поля |
377
- | error | `string` | - | |
378
- | className | `string` | - | CSS-класс |
379
- | label | `string` | - | Лейбл |
380
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
381
- | required | `boolean` | - | Является ли поле обязательным |
382
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
383
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
384
- | hint | `string` | - | Подсказка внизу |
385
- | validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | default | Состояние валидации |
386
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
387
208
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
388
209
  | key | `Key` | - | |
389
210
  ## FieldSlider
390
211
  ### Props
391
212
  | name | type | default value | description |
392
213
  |------|------|---------------|-------------|
393
- | postfixIcon | `ReactElement<any, string \| JSXElementConstructor<any>>` | - | Иконка-постфикс для поля |
394
- | showScaleBar | `boolean` | true | Отображение линейки |
395
- | textInputFormatter | `TextInputFormatter` | - | Функция для форматирования значений в текстовом поле |
396
- | disabled | `boolean` | - | Является ли поле деактивированным |
397
- | readonly | `boolean` | - | Является ли поле доступным только для чтения |
398
- | id | `string` | - | Значение html-атрибута id |
399
- | name | `string` | - | Значение html-атрибута name |
400
- | onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
401
- | onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
402
- | value | `number \| number[]` | - | |
403
- | onChange | `(value: number \| number[]) => void` | - | |
404
- | range | `boolean` | - | |
405
- | tipFormatter | `(value: string \| number) => ReactNode` | - | |
406
- | step | `number` | - | |
407
- | min | `number` | - | |
408
- | max | `number` | - | |
409
- | marks | `Record<string \| number, ReactNode \| MarkObj>` | - | |
410
- | className | `string` | - | CSS-класс |
411
- | label | `string` | - | Лейбл |
412
- | labelTooltip | `string` | - | Всплывающая подсказка лейбла |
413
- | required | `boolean` | - | Является ли поле обязательным |
414
- | size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
415
- | labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
416
- | hint | `string` | - | Подсказка внизу |
417
- | showHintIcon | `boolean` | - | Отображать иконку подсказки |
418
214
  | ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
419
215
  | key | `Key` | - | |
420
216
 
@@ -14,7 +14,7 @@ import mergeRefs from 'merge-refs';
14
14
  import { forwardRef, useCallback, useEffect, useMemo, useRef, useState, } from 'react';
15
15
  import { useUncontrolledProp } from 'uncontrollable';
16
16
  import { Calendar } from '@snack-uikit/calendar';
17
- import { Dropdown } from '@snack-uikit/droplist';
17
+ import { Dropdown } from '@snack-uikit/dropdown';
18
18
  import { CalendarSVG } from '@snack-uikit/icons';
19
19
  import { ICON_SIZE, InputPrivate, runAfterRerender, SIZE, useButtonNavigation, useClearButton, } from '@snack-uikit/input-private';
20
20
  import { extractSupportProps } from '@snack-uikit/utils';
@@ -9,6 +9,8 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
9
9
  'data-test-id'?: string | undefined;
10
10
  } & import("react").AriaAttributes & {
11
11
  options: import("./types").OptionProps[];
12
+ pinTop: import("./types").OptionProps[];
13
+ pinBottom: import("./types").OptionProps[];
12
14
  searchable?: boolean | undefined;
13
15
  showCopyButton?: boolean | undefined;
14
16
  showClearButton?: boolean | undefined;
@@ -22,4 +24,4 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
22
24
  open?: boolean | undefined;
23
25
  onOpenChange?(open: boolean): void;
24
26
  selectedOptionFormatter?: SelectedOptionFormatter | undefined;
25
- } & Pick<import("@snack-uikit/list").DroplistProps, "pinTop" | "pinBottom" | "dataFiltered" | "dataError" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton"> & import("react").RefAttributes<HTMLInputElement>>;
27
+ } & Pick<import("@snack-uikit/list").DroplistProps, "dataError" | "dataFiltered" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton"> & import("react").RefAttributes<HTMLInputElement>>;
@@ -14,7 +14,7 @@ import cn from 'classnames';
14
14
  import mergeRefs from 'merge-refs';
15
15
  import { forwardRef, useLayoutEffect, useRef, useState } from 'react';
16
16
  import { InputPrivate } from '@snack-uikit/input-private';
17
- import { Droplist, useFuzzySearch } from '@snack-uikit/list';
17
+ import { Droplist } from '@snack-uikit/list';
18
18
  import { Tag } from '@snack-uikit/tag';
19
19
  import { extractSupportProps } from '@snack-uikit/utils';
20
20
  import { FieldContainerPrivate } from '../../helperComponents';
@@ -22,10 +22,14 @@ import { useValueControl } from '../../hooks';
22
22
  import { FieldDecorator } from '../FieldDecorator';
23
23
  import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
24
24
  import { useButtons, useHandleDeleteItem, useHandleOnKeyDown, useSearchInput } from './hooks';
25
+ import { useFuzzySearch } from './legacy';
25
26
  import styles from './styles.module.css';
26
27
  import { extractListProps, getArrowIcon, updateMultipleItems } from './utils';
27
28
  const BASE_MIN_WIDTH = 4;
28
- const defaultSelectedOptionFormatter = item => (item === null || item === void 0 ? void 0 : item.content.option) || '';
29
+ const defaultSelectedOptionFormatter = item =>
30
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31
+ // @ts-expect-error
32
+ (item === null || item === void 0 ? void 0 : item.content.option) || '';
29
33
  export const FieldSelectMultiple = forwardRef((_a, ref) => {
30
34
  var _b;
31
35
  var { id, name, placeholder, size = 's', options, value: valueProp, defaultValue, onChange: onChangeProp, disabled = false, readonly = false, searchable = true, showClearButton = true, onKeyDown: onInputKeyDownProp, validationState = 'default', search, autocomplete = false, prefixIcon, removeByBackspace = false, addOptionByEnter = false, open: openProp, onOpenChange, selectedOptionFormatter = defaultSelectedOptionFormatter } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showClearButton", "onKeyDown", "validationState", "search", "autocomplete", "prefixIcon", "removeByBackspace", "addOptionByEnter", "open", "onOpenChange", "selectedOptionFormatter"]);
@@ -47,6 +51,9 @@ export const FieldSelectMultiple = forwardRef((_a, ref) => {
47
51
  var _a;
48
52
  setValue(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => item.disabled).map(item => item.id));
49
53
  (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
54
+ if (rest.required) {
55
+ setOpen(true);
56
+ }
50
57
  };
51
58
  const { ArrowIcon, arrowIconSize } = getArrowIcon({ size, open });
52
59
  const { buttons, inputKeyDownNavigationHandler, buttonsRefs } = useButtons({
@@ -7,6 +7,8 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
7
7
  'data-test-id'?: string | undefined;
8
8
  } & import("react").AriaAttributes & {
9
9
  options: import("./types").OptionProps[];
10
+ pinTop: import("./types").OptionProps[];
11
+ pinBottom: import("./types").OptionProps[];
10
12
  searchable?: boolean | undefined;
11
13
  showCopyButton?: boolean | undefined;
12
14
  showClearButton?: boolean | undefined;
@@ -20,4 +22,4 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
20
22
  open?: boolean | undefined;
21
23
  onOpenChange?(open: boolean): void;
22
24
  selectedOptionFormatter?: SelectedOptionFormatter | undefined;
23
- } & Pick<import("@snack-uikit/list").DroplistProps, "pinTop" | "pinBottom" | "dataFiltered" | "dataError" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
25
+ } & Pick<import("@snack-uikit/list").DroplistProps, "dataError" | "dataFiltered" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
@@ -14,16 +14,20 @@ import cn from 'classnames';
14
14
  import mergeRefs from 'merge-refs';
15
15
  import { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, } from 'react';
16
16
  import { InputPrivate } from '@snack-uikit/input-private';
17
- import { Droplist, useFuzzySearch } from '@snack-uikit/list';
17
+ import { Droplist } from '@snack-uikit/list';
18
18
  import { extractSupportProps } from '@snack-uikit/utils';
19
19
  import { FieldContainerPrivate } from '../../helperComponents';
20
20
  import { useValueControl } from '../../hooks';
21
21
  import { FieldDecorator } from '../FieldDecorator';
22
22
  import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
23
23
  import { useButtons, useHandleOnKeyDown, useSearchInput } from './hooks';
24
+ import { useFuzzySearch } from './legacy';
24
25
  import styles from './styles.module.css';
25
26
  import { extractListProps, getArrowIcon, updateItems } from './utils';
26
- const defaultSelectedOptionFormatter = item => (item === null || item === void 0 ? void 0 : item.content.option) || '';
27
+ const defaultSelectedOptionFormatter = item =>
28
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
29
+ // @ts-expect-error
30
+ (item === null || item === void 0 ? void 0 : item.content.option) || '';
27
31
  export const FieldSelectSingle = forwardRef((_a, ref) => {
28
32
  var _b;
29
33
  var { id, name, placeholder, size = 's', options, value: valueProp, defaultValue, onChange: onChangeProp, disabled = false, readonly = false, searchable = true, showCopyButton = true, showClearButton = true, onKeyDown: onInputKeyDownProp, required = false, validationState = 'default', search, autocomplete = false, prefixIcon, addOptionByEnter = false, open: openProp, onOpenChange, selectedOptionFormatter = defaultSelectedOptionFormatter } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showCopyButton", "showClearButton", "onKeyDown", "required", "validationState", "search", "autocomplete", "prefixIcon", "addOptionByEnter", "open", "onOpenChange", "selectedOptionFormatter"]);
@@ -35,7 +39,10 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
35
39
  onChange: onChangeProp,
36
40
  });
37
41
  const [{ selectedItem, items = [] }, setItems] = useState(() => updateItems({ options, value, currentItems: [], selectedItem: undefined }));
38
- const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput(Object.assign(Object.assign({}, search), { defaultValue: (_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option) !== null && _b !== void 0 ? _b : '', selectedOptionFormatter }));
42
+ const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput(Object.assign(Object.assign({}, search), {
43
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
44
+ // @ts-expect-error
45
+ defaultValue: (_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option) !== null && _b !== void 0 ? _b : '', selectedOptionFormatter }));
39
46
  const prevSelectedItem = useRef(selectedItem);
40
47
  useLayoutEffect(() => {
41
48
  setItems(({ selectedItem }) => updateItems({ options, value, selectedItem }));
@@ -43,6 +50,8 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
43
50
  useEffect(() => {
44
51
  if (prevSelectedItem.current &&
45
52
  prevSelectedItem.current.id === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id) &&
53
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
54
+ // @ts-expect-error
46
55
  prevSelectedItem.current.content.option === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option)) {
47
56
  return;
48
57
  }
@@ -54,7 +63,10 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
54
63
  var _a;
55
64
  setValue(undefined);
56
65
  (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
57
- }, [setValue]);
66
+ if (required) {
67
+ setOpen(true);
68
+ }
69
+ }, [required, setOpen, setValue]);
58
70
  const { ArrowIcon, arrowIconSize } = getArrowIcon({ size, open });
59
71
  const { buttons, inputKeyDownNavigationHandler, buttonsRefs } = useButtons({
60
72
  readonly,
@@ -1,7 +1,10 @@
1
1
  import { useCallback, useMemo, useRef } from 'react';
2
2
  import { useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
3
- import { extractChildIds, isAccordionItemProps, isNextListItemProps, } from '@snack-uikit/list';
3
+ import {
4
+ // extractChildIds,
5
+ isAccordionItemProps, isNextListItemProps, } from '@snack-uikit/list';
4
6
  import { useCopyButton, useValueControl } from '../../hooks';
7
+ import { extractChildIds } from './legacy';
5
8
  import { isBaseOptionProps } from './utils';
6
9
  export function useHandleOnKeyDown({ setOpen, inputKeyDownNavigationHandler, onInputKeyDownProp, }) {
7
10
  return useCallback((onKeyDown) => (e) => {
@@ -74,7 +77,10 @@ export function useHandleDeleteItem(setValue) {
74
77
  return;
75
78
  }
76
79
  if (isBaseOptionProps(item)) {
77
- setValue((value) => value === null || value === void 0 ? void 0 : value.filter(v => v !== item.id));
80
+ setValue((value) => value === null || value === void 0 ? void 0 : value.filter(v =>
81
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
82
+ // @ts-expect-error
83
+ v !== item.id));
78
84
  }
79
85
  }, [setValue]);
80
86
  }
@@ -0,0 +1,12 @@
1
+ import { ItemProps } from '@snack-uikit/list';
2
+ type UseGroupItemSelectionProps = {
3
+ items: ItemProps[];
4
+ id?: string | number;
5
+ disabled?: boolean;
6
+ };
7
+ export declare function useLegacyGroupItemSelection({ id, items, disabled }: UseGroupItemSelectionProps): {
8
+ checked: boolean | undefined;
9
+ isIndeterminate: boolean;
10
+ handleOnSelect: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,33 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useSelectionContext } from '@snack-uikit/list';
3
+ import { extractAllChildIds, extractChildIds } from '../../utils';
4
+ export function useLegacyGroupItemSelection({ id = '', items, disabled }) {
5
+ const { value, setValue, isSelectionMultiple } = useSelectionContext();
6
+ const { childIds, allChildIds } = useMemo(() => ({ childIds: extractChildIds({ items }), allChildIds: extractAllChildIds({ items }) }), [items]);
7
+ const isIndeterminate = isSelectionMultiple
8
+ ? allChildIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
9
+ : allChildIds.includes(value !== null && value !== void 0 ? value : '');
10
+ const checked = isSelectionMultiple ? allChildIds.every(childId => value === null || value === void 0 ? void 0 : value.includes(childId)) : undefined;
11
+ useEffect(() => {
12
+ if (isSelectionMultiple) {
13
+ if (checked && !(value === null || value === void 0 ? void 0 : value.includes(id))) {
14
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([id !== null && id !== void 0 ? id : '']));
15
+ }
16
+ if (!checked && (value === null || value === void 0 ? void 0 : value.includes(id))) {
17
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id));
18
+ }
19
+ }
20
+ }, [checked, disabled, id, isSelectionMultiple, setValue, value]);
21
+ const handleOnSelect = () => {
22
+ if (checked) {
23
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !childIds.includes(itemId)));
24
+ return;
25
+ }
26
+ if (isIndeterminate) {
27
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...childIds, id])));
28
+ return;
29
+ }
30
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([...childIds, id !== null && id !== void 0 ? id : '']));
31
+ };
32
+ return { checked, isIndeterminate, handleOnSelect };
33
+ }
@@ -0,0 +1 @@
1
+ export { useLegacyGroupItemSelection } from './Items/hooks';
@@ -0,0 +1 @@
1
+ export { useLegacyGroupItemSelection } from './Items/hooks';
@@ -0,0 +1,5 @@
1
+ import { ItemProps } from '@snack-uikit/list';
2
+ /**
3
+ * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
4
+ */
5
+ export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => import("@snack-uikit/list/dist/components/Items").Item[] | import("@snack-uikit/list/dist/components/Items").FlattenItem[];
@@ -0,0 +1,19 @@
1
+ import FuzzySearch from 'fuzzy-search';
2
+ import { useCallback, useMemo } from 'react';
3
+ import { kindFlattenItems } from '@snack-uikit/list';
4
+ const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
5
+ /**
6
+ * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
7
+ */
8
+ export function useFuzzySearch(items, minSearchInputLength) {
9
+ const flattenItems = useMemo(() => {
10
+ const { flattenItems } = kindFlattenItems({ items });
11
+ return Object.values(flattenItems);
12
+ }, [items]);
13
+ return useCallback((search) => {
14
+ const searcher = new FuzzySearch(flattenItems, ['content.option', 'content.caption', 'content.description', 'label'], {});
15
+ return search.length > (minSearchInputLength !== null && minSearchInputLength !== void 0 ? minSearchInputLength : DEFAULT_MIN_SEARCH_INPUT_LENGTH)
16
+ ? searcher.search(search)
17
+ : items;
18
+ }, [flattenItems, items, minSearchInputLength]);
19
+ }
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { useFuzzySearch } from './hooks';
3
+ export { extractChildIds, flattenItems } from './utils';
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { useFuzzySearch } from './hooks';
3
+ export { extractChildIds, flattenItems } from './utils';
@@ -0,0 +1,29 @@
1
+ import { RefObject } from 'react';
2
+ import { AccordionItemProps, BaseItemProps, ItemProps, NextListItemProps } from '@snack-uikit/list';
3
+ type WithCollapsedItemsProps = {
4
+ items: ItemProps[];
5
+ openCollapsedItems: Array<number | string>;
6
+ };
7
+ export declare function withCollapsedItems({ items, openCollapsedItems }: WithCollapsedItemsProps): {
8
+ items: import("@snack-uikit/list/dist/components/Items").Item[];
9
+ itemRefs: RefObject<HTMLElement>[];
10
+ ids: (string | number)[];
11
+ expandedIds: (string | number)[];
12
+ };
13
+ /**
14
+ * Функция возвращает массив id дочерних items
15
+ * @function extractItemIds
16
+ */
17
+ export declare function extractItemIds(items: ItemProps[]): Array<string | number>;
18
+ export declare function extractChildIds({ items }: {
19
+ items: ItemProps[];
20
+ }): Array<string | number>;
21
+ export declare function extractAllChildIds({ items }: {
22
+ items: ItemProps[];
23
+ }): Array<string | number>;
24
+ /**
25
+ *  Функция разворачивает массив айтемов в плоский список
26
+ * @function flattenItems
27
+ */
28
+ export declare function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[];
29
+ export {};