@cloud-ru/uikit-product-fields-predefined 0.13.11 → 0.14.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.
- package/CHANGELOG.md +11 -0
- package/README.md +28 -103
- package/dist/cjs/components/FieldAi/FieldAi.d.ts +1 -1
- package/dist/cjs/components/FieldAi/components/MobileFieldAi/MobileFieldAi.d.ts +1 -1
- package/dist/cjs/components/FieldDescription/FieldDescription.d.ts +12 -0
- package/dist/cjs/components/FieldDescription/FieldDescription.js +68 -0
- package/dist/cjs/components/FieldDescription/FieldDescriptionRHF.d.ts +11 -0
- package/dist/cjs/components/FieldDescription/FieldDescriptionRHF.js +62 -0
- package/dist/cjs/components/FieldDescription/components/FieldWithAddButton.d.ts +7 -0
- package/dist/cjs/components/FieldDescription/components/FieldWithAddButton.js +21 -0
- package/dist/cjs/components/FieldDescription/components/index.d.ts +1 -0
- package/dist/cjs/components/FieldDescription/components/index.js +5 -0
- package/dist/cjs/components/FieldDescription/constants.d.ts +1 -0
- package/dist/cjs/components/FieldDescription/constants.js +4 -0
- package/dist/cjs/components/FieldDescription/index.d.ts +3 -0
- package/dist/cjs/components/FieldDescription/index.js +7 -0
- package/dist/cjs/components/FieldDescription/types.d.ts +16 -0
- package/dist/cjs/components/FieldDescription/types.js +2 -0
- package/dist/cjs/components/FieldName/FieldName.d.ts +12 -0
- package/dist/cjs/components/FieldName/FieldName.js +95 -0
- package/dist/cjs/components/FieldName/FieldNameRHF.d.ts +11 -0
- package/dist/cjs/components/FieldName/FieldNameRHF.js +81 -0
- package/dist/cjs/components/FieldName/constants.d.ts +1 -0
- package/dist/cjs/components/FieldName/constants.js +4 -0
- package/dist/cjs/components/FieldName/index.d.ts +3 -0
- package/dist/cjs/components/FieldName/index.js +7 -0
- package/dist/cjs/components/FieldName/types.d.ts +15 -0
- package/dist/cjs/components/FieldName/types.js +2 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +2 -0
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useCustomFieldValidation.d.ts +12 -0
- package/dist/cjs/hooks/useCustomFieldValidation.js +32 -0
- package/dist/esm/components/FieldAi/FieldAi.d.ts +1 -1
- package/dist/esm/components/FieldAi/components/MobileFieldAi/MobileFieldAi.d.ts +1 -1
- package/dist/esm/components/FieldDescription/FieldDescription.d.ts +12 -0
- package/dist/esm/components/FieldDescription/FieldDescription.js +62 -0
- package/dist/esm/components/FieldDescription/FieldDescriptionRHF.d.ts +11 -0
- package/dist/esm/components/FieldDescription/FieldDescriptionRHF.js +56 -0
- package/dist/esm/components/FieldDescription/components/FieldWithAddButton.d.ts +7 -0
- package/dist/esm/components/FieldDescription/components/FieldWithAddButton.js +18 -0
- package/dist/esm/components/FieldDescription/components/index.d.ts +1 -0
- package/dist/esm/components/FieldDescription/components/index.js +1 -0
- package/dist/esm/components/FieldDescription/constants.d.ts +1 -0
- package/dist/esm/components/FieldDescription/constants.js +1 -0
- package/dist/esm/components/FieldDescription/index.d.ts +3 -0
- package/dist/esm/components/FieldDescription/index.js +2 -0
- package/dist/esm/components/FieldDescription/types.d.ts +16 -0
- package/dist/esm/components/FieldDescription/types.js +1 -0
- package/dist/esm/components/FieldName/FieldName.d.ts +12 -0
- package/dist/esm/components/FieldName/FieldName.js +89 -0
- package/dist/esm/components/FieldName/FieldNameRHF.d.ts +11 -0
- package/dist/esm/components/FieldName/FieldNameRHF.js +75 -0
- package/dist/esm/components/FieldName/constants.d.ts +1 -0
- package/dist/esm/components/FieldName/constants.js +1 -0
- package/dist/esm/components/FieldName/index.d.ts +3 -0
- package/dist/esm/components/FieldName/index.js +2 -0
- package/dist/esm/components/FieldName/types.d.ts +15 -0
- package/dist/esm/components/FieldName/types.js +1 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useCustomFieldValidation.d.ts +12 -0
- package/dist/esm/hooks/useCustomFieldValidation.js +28 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +8 -6
- package/src/components/FieldDescription/FieldDescription.tsx +97 -0
- package/src/components/FieldDescription/FieldDescriptionRHF.tsx +93 -0
- package/src/components/FieldDescription/components/FieldWithAddButton.tsx +43 -0
- package/src/components/FieldDescription/components/index.ts +1 -0
- package/src/components/FieldDescription/constants.ts +1 -0
- package/src/components/FieldDescription/index.ts +3 -0
- package/src/components/FieldDescription/types.ts +23 -0
- package/src/components/FieldName/FieldName.tsx +125 -0
- package/src/components/FieldName/FieldNameRHF.tsx +112 -0
- package/src/components/FieldName/constants.ts +1 -0
- package/src/components/FieldName/index.ts +3 -0
- package/src/components/FieldName/types.ts +22 -0
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useCustomFieldValidation.ts +38 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.14.0 (2025-12-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **UIIAAS-1251:** added FieldDescription & FieldName ([e03ba16](https://gitverse.ru/cloud-ru-tech/uikit-product/commits/e03ba16f0bbe62d0c00e7e109727a4b49f13fc6b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.13.11 (2025-11-28)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -14,39 +14,6 @@
|
|
|
14
14
|
### Props
|
|
15
15
|
| name | type | default value | description |
|
|
16
16
|
|------|------|---------------|-------------|
|
|
17
|
-
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
18
|
-
| value | `string` | - | Значение input |
|
|
19
|
-
| onChange | `((value: string, e?: ChangeEvent<HTMLInputElement>) => void) & ((value: string) => void)` | - | Колбек смены значения |
|
|
20
|
-
| id | `string` | - | Значение html-атрибута id |
|
|
21
|
-
| name | `string` | - | Значение html-атрибута name |
|
|
22
|
-
| disabled | `boolean` | false | Является ли поле деактивированным |
|
|
23
|
-
| readonly | `boolean` | false | Является ли поле доступным только для чтения |
|
|
24
|
-
| onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
|
|
25
|
-
| onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
|
|
26
|
-
| autoComplete | `string \| boolean` | false | Включен ли автокомплит для поля |
|
|
27
|
-
| autoFocus | `boolean` | false | Включен ли авто-фокус для поля |
|
|
28
|
-
| onPaste | `ClipboardEventHandler<HTMLInputElement>` | - | Колбек обработки вставки значения |
|
|
29
|
-
| spellCheck | `boolean` | true | Значение атрибута spellcheck (проверка орфографии) |
|
|
30
|
-
| pattern | `string` | - | Регулярное выражение валидного инпута |
|
|
31
|
-
| className | `string` | - | CSS-класс |
|
|
32
|
-
| label | `string` | - | Лейбл |
|
|
33
|
-
| labelTooltip | `ReactNode` | - | Всплывающая подсказка лейбла |
|
|
34
|
-
| required | `boolean` | - | Является ли поле обязательным |
|
|
35
|
-
| caption | `string` | - | Подпись справа от лейбла |
|
|
36
|
-
| hint | `string` | - | Подсказка внизу |
|
|
37
|
-
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
38
|
-
| size | enum Size: `"s"`, `"m"`, `"l"` | - | Размер |
|
|
39
|
-
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
40
|
-
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
41
|
-
| error | `string` | - | |
|
|
42
|
-
| type | "text" \| "tel" \| "email" | - | |
|
|
43
|
-
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
44
|
-
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
45
|
-
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
46
|
-
| scrollList | `boolean` | - | Включить скролл для основной части списка стран |
|
|
47
|
-
| searchPlaceholder | `string` | - | |
|
|
48
|
-
| onChangeCountry | `(country: FieldPhoneOptionsProps) => void` | - | |
|
|
49
|
-
| options | `CountrySettings` | - | options — объект конфигурации для изменения стандартного списка стран |
|
|
50
17
|
| ref | `LegacyRef<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 {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
|
|
51
18
|
| key | `Key` | - | |
|
|
52
19
|
## useCountries
|
|
@@ -60,90 +27,48 @@
|
|
|
60
27
|
### Props
|
|
61
28
|
| name | type | default value | description |
|
|
62
29
|
|------|------|---------------|-------------|
|
|
63
|
-
| selectProps* | `FieldSelectProps` | - | Пропсы прокидываемые в селект |
|
|
64
|
-
| submitHandler* | `() => Promise<string \| void>` | - | Коллбек создания новой опции, при успешном выполнении возвращает value новой опции |
|
|
65
|
-
| entityName* | `EntityName` | - | Тип объекта для создания новой опции (в единственном числе вин.падеже для кнопки Создать <entityName> и множественном числе) |
|
|
66
|
-
| createLayoutProps* | `CreateLayoutModalProps \| CreateLayoutDrawerProps` | - | Пропсы передаваемые в модалку или дровер создания новой опции |
|
|
67
|
-
| createLayoutType* | "modal" \| "drawer" | - | По клику на кнопку создания открывать модальное окно или дровер |
|
|
68
|
-
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
69
|
-
| onRefetch | `VoidFunction` | - | Коллбек рефетча запроса на получение списка опций в случае ошибки (при передаче dataError в selectProps). |
|
|
70
|
-
| className | `string` | - | CSS-класс |
|
|
71
|
-
| afterClose | `VoidFunction` | - | Коллбек после закрытия модального окна/дровера |
|
|
72
|
-
| entityIcon | `JSXElementConstructor<{ size?: number; className?: string; }>` | - | Иконка сервиса |
|
|
73
|
-
| permission | "none" \| "canRead" \| "canCreate" | - | Управление состоянием компонента в зависимости от прав пользователя (по дефолту permission = 'canCreate') |
|
|
74
30
|
## FieldAi
|
|
75
31
|
### Props
|
|
76
32
|
| name | type | default value | description |
|
|
77
33
|
|------|------|---------------|-------------|
|
|
78
|
-
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
79
|
-
| onSubmit* | `(value: string) => void` | - | Колбек действия при отправке |
|
|
80
|
-
| value | `string` | - | HTML-аттрибут value |
|
|
81
|
-
| onChange | `(value: string, e?: ChangeEvent<HTMLTextAreaElement>) => void` | - | Колбек смены значения |
|
|
82
|
-
| inputMode | enum InputMode: `"none"`, `"text"`, `"tel"`, `"email"`, `"search"`, `"decimal"`, `"numeric"`, `"url"` | - | Режим работы экранной клавиатуры |
|
|
83
|
-
| id | `string` | - | HTML-аттрибут id |
|
|
84
|
-
| name | `string` | - | HTML-аттрибут name |
|
|
85
|
-
| maxLength | `number` | - | Максимальное кол-во символов |
|
|
86
|
-
| disabled | `boolean` | - | Является ли поле деактивированным |
|
|
87
|
-
| readonly | `boolean` | - | Является ли поле доступным только на чтение |
|
|
88
|
-
| onFocus | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек получения фокуса |
|
|
89
|
-
| onBlur | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек потери фокуса |
|
|
90
|
-
| autoFocus | `boolean` | - | Включен ли авто-фокус |
|
|
91
|
-
| onKeyDown | `KeyboardEventHandler<HTMLTextAreaElement>` | - | Колбек нажатия клавиши клавиатуры |
|
|
92
|
-
| className | `string` | - | CSS-класс |
|
|
93
|
-
| caption | `string` | - | Подпись справа от лейбла |
|
|
94
|
-
| hint | `string` | - | Подсказка внизу |
|
|
95
|
-
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
96
|
-
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
97
|
-
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
98
|
-
| error | `string` | - | |
|
|
99
|
-
| allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
|
|
100
|
-
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
101
|
-
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
102
|
-
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
103
|
-
| minRows | `number` | 3 | Минимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
104
|
-
| maxRows | `number` | 1000 | Максимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
105
|
-
| resizable | `boolean` | - | Может ли ли пользователь изменять размеры поля (если св-во не включено, поле автоматически меняет свой размер) |
|
|
106
|
-
| secure | `boolean \| "password"` | - | Режим ввода sensitive данных (пароля, API ключей, токенов, etc) |
|
|
107
|
-
| onResetContextClick | `() => void` | - | Действие при клике по кнопке сброса контекста |
|
|
108
34
|
| ref | `LegacyRef<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 {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
|
|
109
35
|
| key | `Key` | - | |
|
|
110
36
|
## FieldChat
|
|
111
37
|
### Props
|
|
112
38
|
| name | type | default value | description |
|
|
113
39
|
|------|------|---------------|-------------|
|
|
114
|
-
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
115
|
-
| handleSubmit* | `(value: string) => void` | - | Колбек действия при отправке |
|
|
116
|
-
| value | `string` | - | HTML-аттрибут value |
|
|
117
|
-
| onChange | `(value: string, e?: ChangeEvent<HTMLTextAreaElement>) => void` | - | Колбек смены значения |
|
|
118
|
-
| inputMode | enum InputMode: `"none"`, `"text"`, `"tel"`, `"email"`, `"search"`, `"decimal"`, `"numeric"`, `"url"` | - | Режим работы экранной клавиатуры |
|
|
119
|
-
| id | `string` | - | HTML-аттрибут id |
|
|
120
|
-
| name | `string` | - | HTML-аттрибут name |
|
|
121
|
-
| maxLength | `number` | - | Максимальное кол-во символов |
|
|
122
|
-
| disabled | `boolean` | - | Является ли поле деактивированным |
|
|
123
|
-
| readonly | `boolean` | - | Является ли поле доступным только на чтение |
|
|
124
|
-
| onFocus | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек получения фокуса |
|
|
125
|
-
| onBlur | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек потери фокуса |
|
|
126
|
-
| autoFocus | `boolean` | - | Включен ли авто-фокус |
|
|
127
|
-
| onKeyDown | `KeyboardEventHandler<HTMLTextAreaElement>` | - | Колбек нажатия клавиши клавиатуры |
|
|
128
|
-
| className | `string` | - | CSS-класс |
|
|
129
|
-
| caption | `string` | - | Подпись справа от лейбла |
|
|
130
|
-
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
131
|
-
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
132
|
-
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
133
|
-
| error | `string` | - | |
|
|
134
|
-
| allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
|
|
135
|
-
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
136
|
-
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
137
|
-
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
138
|
-
| minRows | `number` | 3 | Минимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
139
|
-
| maxRows | `number` | 1000 | Максимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
140
|
-
| resizable | `boolean` | - | Может ли ли пользователь изменять размеры поля (если св-во не включено, поле автоматически меняет свой размер) |
|
|
141
|
-
| attachment | `Pick<FileUploadProps, "onFilesUpload" \| "accept"> & { files?: File[]; onFileDelete: (file?: File) => void; }` | - | |
|
|
142
40
|
## AIDisclaimer
|
|
143
41
|
### Props
|
|
144
42
|
| name | type | default value | description |
|
|
145
43
|
|------|------|---------------|-------------|
|
|
146
|
-
|
|
44
|
+
## FieldName
|
|
45
|
+
Поле имя c локальным стейтом и валидацией
|
|
46
|
+
### Props
|
|
47
|
+
| name | type | default value | description |
|
|
48
|
+
|------|------|---------------|-------------|
|
|
49
|
+
| ref | `LegacyRef<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 {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
|
|
50
|
+
| key | `Key` | - | |
|
|
51
|
+
## FieldNameRHF
|
|
52
|
+
Поле имя c оберткой для React Hook Form
|
|
53
|
+
### Props
|
|
54
|
+
| name | type | default value | description |
|
|
55
|
+
|------|------|---------------|-------------|
|
|
56
|
+
| ref | `LegacyRef<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 {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
|
|
57
|
+
| key | `Key` | - | |
|
|
58
|
+
## FieldDescription
|
|
59
|
+
Поле описание c локальным стейтом и валидацией
|
|
60
|
+
### Props
|
|
61
|
+
| name | type | default value | description |
|
|
62
|
+
|------|------|---------------|-------------|
|
|
63
|
+
| ref | `LegacyRef<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 {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
|
|
64
|
+
| key | `Key` | - | |
|
|
65
|
+
## FieldDescriptionRHF
|
|
66
|
+
Поле описание c оберткой для React Hook Form
|
|
67
|
+
### Props
|
|
68
|
+
| name | type | default value | description |
|
|
69
|
+
|------|------|---------------|-------------|
|
|
70
|
+
| ref | `LegacyRef<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 {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
|
|
71
|
+
| key | `Key` | - | |
|
|
147
72
|
|
|
148
73
|
|
|
149
74
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -8,7 +8,7 @@ export type FieldAiProps = WithLayoutType<Omit<FieldTextAreaProps, 'placeholder'
|
|
|
8
8
|
/** Действие при клике по кнопке сброса контекста */
|
|
9
9
|
onResetContextClick?(): void;
|
|
10
10
|
}>;
|
|
11
|
-
export declare const FieldAi: import("react").ForwardRefExoticComponent<Omit<FieldTextAreaProps, "size" | "
|
|
11
|
+
export declare const FieldAi: import("react").ForwardRefExoticComponent<Omit<FieldTextAreaProps, "size" | "label" | "required" | "placeholder" | "spellCheck" | "labelTooltip" | "footer"> & {
|
|
12
12
|
/** Режим ввода sensitive данных (пароля, API ключей, токенов, etc) */
|
|
13
13
|
secure?: boolean | "password";
|
|
14
14
|
/** Колбек действия при отправке */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldTextAreaProps } from '@cloud-ru/uikit-product-mobile-fields';
|
|
2
|
-
export declare const MobileFieldAi: import("react").ForwardRefExoticComponent<Omit<FieldTextAreaProps, "size" | "
|
|
2
|
+
export declare const MobileFieldAi: import("react").ForwardRefExoticComponent<Omit<FieldTextAreaProps, "size" | "label" | "required" | "placeholder" | "spellCheck" | "labelTooltip" | "footer"> & {
|
|
3
3
|
onSubmit(): void;
|
|
4
4
|
submitEnabled: boolean;
|
|
5
5
|
} & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidationError } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Поле описание c локальным стейтом и валидацией
|
|
4
|
+
*/
|
|
5
|
+
export declare const FieldDescription: import("react").ForwardRefExoticComponent<Omit<import("@cloud-ru/uikit-product-mobile-fields").FieldTextAreaProps, "name" | "caption" | "label" | "hint" | "placeholder" | "inputMode" | "searchPlaceholder" | "footer"> & {
|
|
6
|
+
customSchema?: import("yup").StringSchema;
|
|
7
|
+
addButton?: boolean;
|
|
8
|
+
} & {
|
|
9
|
+
onValidationError?: (error: ValidationError | null) => void;
|
|
10
|
+
} & {
|
|
11
|
+
layoutType: import("@cloud-ru/uikit-product-utils/.").LayoutType;
|
|
12
|
+
} & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.FieldDescription = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const merge_refs_1 = __importDefault(require("merge-refs"));
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
const yup_1 = require("yup");
|
|
22
|
+
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
23
|
+
const uikit_product_mobile_fields_1 = require("@cloud-ru/uikit-product-mobile-fields");
|
|
24
|
+
const hooks_1 = require("../../hooks");
|
|
25
|
+
const components_1 = require("./components");
|
|
26
|
+
const constants_1 = require("./constants");
|
|
27
|
+
/**
|
|
28
|
+
* Поле описание c локальным стейтом и валидацией
|
|
29
|
+
*/
|
|
30
|
+
exports.FieldDescription = (0, react_1.forwardRef)((_a, ref) => {
|
|
31
|
+
var _b;
|
|
32
|
+
var { size = 'm', required = false, maxLength = constants_1.DEFAULT_MAX_LENGTH, customSchema, resizable = true, addButton, onValidationError } = _a, props = __rest(_a, ["size", "required", "maxLength", "customSchema", "resizable", "addButton", "onValidationError"]);
|
|
33
|
+
const { t } = (0, uikit_product_locale_1.useLocale)('FieldsPredefined');
|
|
34
|
+
const textareaRef = (0, react_1.useRef)(null);
|
|
35
|
+
const validationSchema = (0, react_1.useMemo)(() => {
|
|
36
|
+
let baseSchema = (0, yup_1.string)()
|
|
37
|
+
.trim()
|
|
38
|
+
.max(maxLength, t('FieldDescription.maxSymbols', { max: maxLength }));
|
|
39
|
+
if (customSchema) {
|
|
40
|
+
baseSchema = baseSchema.concat(customSchema);
|
|
41
|
+
}
|
|
42
|
+
return required ? baseSchema.required(t('FieldDescription.required')) : baseSchema;
|
|
43
|
+
}, [customSchema, maxLength, required, t]);
|
|
44
|
+
const { validate } = (0, hooks_1.useCustomFieldValidation)({ schema: validationSchema });
|
|
45
|
+
const [value, setValue] = (0, react_1.useState)('');
|
|
46
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
47
|
+
const handleChange = (newValue) => {
|
|
48
|
+
var _a;
|
|
49
|
+
setValue(newValue);
|
|
50
|
+
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, newValue);
|
|
51
|
+
const result = validate(newValue);
|
|
52
|
+
setError(result.error);
|
|
53
|
+
onValidationError === null || onValidationError === void 0 ? void 0 : onValidationError(result.error);
|
|
54
|
+
};
|
|
55
|
+
const handleBlur = (newValue) => {
|
|
56
|
+
var _a;
|
|
57
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, newValue);
|
|
58
|
+
const result = validate(value);
|
|
59
|
+
setError(result.error);
|
|
60
|
+
onValidationError === null || onValidationError === void 0 ? void 0 : onValidationError(result.error);
|
|
61
|
+
};
|
|
62
|
+
const errorMes = (_b = props.error) !== null && _b !== void 0 ? _b : error === null || error === void 0 ? void 0 : error.message;
|
|
63
|
+
const standaloneComponent = ((0, jsx_runtime_1.jsx)(uikit_product_mobile_fields_1.AdaptiveFieldTextArea, Object.assign({}, props, { resizable: resizable, label: t('FieldDescription.label'), inputMode: 'text', ref: (0, merge_refs_1.default)(ref, textareaRef), size: size, maxLength: maxLength, value: value, onChange: handleChange, onBlur: handleBlur, validationState: errorMes ? 'error' : props.validationState, hint: errorMes, caption: !required ? t('FieldDescription.optional') : undefined })));
|
|
64
|
+
if (addButton && !required) {
|
|
65
|
+
return ((0, jsx_runtime_1.jsx)(components_1.FieldWithAddButton, { autoFocusRef: textareaRef, size: size, children: standaloneComponent }));
|
|
66
|
+
}
|
|
67
|
+
return standaloneComponent;
|
|
68
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Поле описание c оберткой для React Hook Form
|
|
3
|
+
*/
|
|
4
|
+
export declare const FieldDescriptionRHF: import("react").ForwardRefExoticComponent<Omit<import("@cloud-ru/uikit-product-mobile-fields").FieldTextAreaProps, "name" | "caption" | "label" | "hint" | "placeholder" | "inputMode" | "searchPlaceholder" | "footer"> & {
|
|
5
|
+
customSchema?: import("yup").StringSchema;
|
|
6
|
+
addButton?: boolean;
|
|
7
|
+
} & {
|
|
8
|
+
controllerProps: Omit<import("react-hook-form").ControllerProps<import("react-hook-form").FieldValues>, "render" | "rules" | "disabled">;
|
|
9
|
+
} & {
|
|
10
|
+
layoutType: import("@cloud-ru/uikit-product-utils/.").LayoutType;
|
|
11
|
+
} & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.FieldDescriptionRHF = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const merge_refs_1 = __importDefault(require("merge-refs"));
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
22
|
+
const yup_1 = require("yup");
|
|
23
|
+
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
24
|
+
const uikit_product_mobile_fields_1 = require("@cloud-ru/uikit-product-mobile-fields");
|
|
25
|
+
const hooks_1 = require("../../hooks");
|
|
26
|
+
const FieldWithAddButton_1 = require("./components/FieldWithAddButton");
|
|
27
|
+
const constants_1 = require("./constants");
|
|
28
|
+
/**
|
|
29
|
+
* Поле описание c оберткой для React Hook Form
|
|
30
|
+
*/
|
|
31
|
+
exports.FieldDescriptionRHF = (0, react_1.forwardRef)((_a, ref) => {
|
|
32
|
+
var { controllerProps, customSchema, size = 'm', required = false, maxLength = constants_1.DEFAULT_MAX_LENGTH, addButton, resizable = true } = _a, props = __rest(_a, ["controllerProps", "customSchema", "size", "required", "maxLength", "addButton", "resizable"]);
|
|
33
|
+
const { t } = (0, uikit_product_locale_1.useLocale)('FieldsPredefined');
|
|
34
|
+
const textareaRef = (0, react_1.useRef)(null);
|
|
35
|
+
const validationSchema = (0, react_1.useMemo)(() => {
|
|
36
|
+
let baseSchema = (0, yup_1.string)()
|
|
37
|
+
.trim()
|
|
38
|
+
.max(maxLength, t('FieldDescription.maxSymbols', { max: maxLength }));
|
|
39
|
+
if (customSchema) {
|
|
40
|
+
baseSchema = baseSchema.concat(customSchema);
|
|
41
|
+
}
|
|
42
|
+
return required ? baseSchema.required(t('FieldDescription.required')) : baseSchema;
|
|
43
|
+
}, [customSchema, maxLength, required, t]);
|
|
44
|
+
const { validateRHF } = (0, hooks_1.useCustomFieldValidation)({ schema: validationSchema });
|
|
45
|
+
const controllerComponent = ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, Object.assign({}, controllerProps, { rules: { validate: validateRHF }, render: ({ field: { value, ref: localRef, onBlur, onChange }, fieldState: { error } }) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const errorMes = (_a = props.error) !== null && _a !== void 0 ? _a : error === null || error === void 0 ? void 0 : error.message;
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(uikit_product_mobile_fields_1.AdaptiveFieldTextArea, Object.assign({}, props, { resizable: resizable, size: size, label: t('FieldDescription.label'), inputMode: 'text', ref: (0, merge_refs_1.default)(ref, localRef, textareaRef), maxLength: maxLength, value: value, onChange: newValue => {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, newValue);
|
|
51
|
+
onChange(newValue);
|
|
52
|
+
}, onBlur: value => {
|
|
53
|
+
var _a;
|
|
54
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, value);
|
|
55
|
+
onBlur();
|
|
56
|
+
}, validationState: errorMes ? 'error' : props.validationState, hint: errorMes, caption: !required ? t('FieldDescription.optional') : undefined })));
|
|
57
|
+
} })));
|
|
58
|
+
if (addButton && !required) {
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(FieldWithAddButton_1.FieldWithAddButton, { autoFocusRef: textareaRef, size: size, children: controllerComponent }));
|
|
60
|
+
}
|
|
61
|
+
return controllerComponent;
|
|
62
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { FieldTextAreaProps } from '@cloud-ru/uikit-product-mobile-fields';
|
|
3
|
+
export declare function FieldWithAddButton({ children, size, autoFocusRef, }: {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
size?: FieldTextAreaProps['size'];
|
|
6
|
+
autoFocusRef: RefObject<HTMLTextAreaElement | null>;
|
|
7
|
+
}): string | number | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import("react").ReactNode> | null | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldWithAddButton = FieldWithAddButton;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const uikit_product_icons_1 = require("@cloud-ru/uikit-product-icons");
|
|
7
|
+
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
8
|
+
const button_1 = require("@snack-uikit/button");
|
|
9
|
+
function FieldWithAddButton({ children, size, autoFocusRef, }) {
|
|
10
|
+
const { t } = (0, uikit_product_locale_1.useLocale)('FieldsPredefined');
|
|
11
|
+
const [showField, setShowField] = (0, react_1.useState)(false);
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
if (showField && autoFocusRef.current) {
|
|
14
|
+
autoFocusRef.current.focus();
|
|
15
|
+
}
|
|
16
|
+
}, [showField, autoFocusRef]);
|
|
17
|
+
if (showField) {
|
|
18
|
+
return children;
|
|
19
|
+
}
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: !showField && ((0, jsx_runtime_1.jsx)(button_1.ButtonFunction, { icon: (0, jsx_runtime_1.jsx)(uikit_product_icons_1.PlusSVG, {}), iconPosition: 'before', label: t('FieldDescription.addButton'), onClick: () => setShowField(true), size: size })) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldWithAddButton } from './FieldWithAddButton';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldWithAddButton = void 0;
|
|
4
|
+
var FieldWithAddButton_1 = require("./FieldWithAddButton");
|
|
5
|
+
Object.defineProperty(exports, "FieldWithAddButton", { enumerable: true, get: function () { return FieldWithAddButton_1.FieldWithAddButton; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_LENGTH = 255;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldDescriptionRHF = exports.FieldDescription = void 0;
|
|
4
|
+
var FieldDescription_1 = require("./FieldDescription");
|
|
5
|
+
Object.defineProperty(exports, "FieldDescription", { enumerable: true, get: function () { return FieldDescription_1.FieldDescription; } });
|
|
6
|
+
var FieldDescriptionRHF_1 = require("./FieldDescriptionRHF");
|
|
7
|
+
Object.defineProperty(exports, "FieldDescriptionRHF", { enumerable: true, get: function () { return FieldDescriptionRHF_1.FieldDescriptionRHF; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ControllerProps, FieldValues } from 'react-hook-form';
|
|
2
|
+
import { StringSchema, ValidationError } from 'yup';
|
|
3
|
+
import { FieldTextAreaProps } from '@cloud-ru/uikit-product-mobile-fields';
|
|
4
|
+
export type FieldDescriptionPropsBase = Omit<FieldTextAreaProps, 'placeholder' | 'label' | 'footer' | 'searchPlaceholder' | 'hint' | 'inputMode' | 'caption' | 'name'> & {
|
|
5
|
+
customSchema?: StringSchema;
|
|
6
|
+
/** Поле появляется по кнопке "Добавить описание" (только для опционального поля) */
|
|
7
|
+
addButton?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type FieldDescriptionProps = FieldDescriptionPropsBase & {
|
|
10
|
+
/** Колбэк, вызываемый при изменении ошибки валидации (только в standalone режиме) */
|
|
11
|
+
onValidationError?: (error: ValidationError | null) => void;
|
|
12
|
+
};
|
|
13
|
+
export type FieldDescriptionRHFProps = FieldDescriptionPropsBase & {
|
|
14
|
+
/** Режим контроллера с использованием react-hook-form */
|
|
15
|
+
controllerProps: Omit<ControllerProps<FieldValues>, 'render' | 'rules' | 'disabled'>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidationError } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Поле имя c локальным стейтом и валидацией
|
|
4
|
+
*/
|
|
5
|
+
export declare const FieldName: import("react").ForwardRefExoticComponent<Omit<import("@cloud-ru/uikit-product-mobile-fields").FieldTextProps, "type" | "caption" | "label" | "hint" | "placeholder" | "inputMode" | "footer"> & {
|
|
6
|
+
showLabel?: boolean;
|
|
7
|
+
customSchema?: import("yup").StringSchema;
|
|
8
|
+
} & {
|
|
9
|
+
onValidationError?: (error: ValidationError | null) => void;
|
|
10
|
+
} & {
|
|
11
|
+
layoutType: import("@cloud-ru/uikit-product-utils/.").LayoutType;
|
|
12
|
+
} & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.FieldName = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const merge_refs_1 = __importDefault(require("merge-refs"));
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
const yup_1 = require("yup");
|
|
22
|
+
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
23
|
+
const uikit_product_mobile_fields_1 = require("@cloud-ru/uikit-product-mobile-fields");
|
|
24
|
+
const input_private_1 = require("@snack-uikit/input-private");
|
|
25
|
+
const hooks_1 = require("../../hooks");
|
|
26
|
+
const constants_1 = require("./constants");
|
|
27
|
+
/**
|
|
28
|
+
* Поле имя c локальным стейтом и валидацией
|
|
29
|
+
*/
|
|
30
|
+
exports.FieldName = (0, react_1.forwardRef)((props, ref) => {
|
|
31
|
+
const { t } = (0, uikit_product_locale_1.useLocale)('FieldsPredefined');
|
|
32
|
+
const { value: propValue = '', onChange: propOnChange, onBlur: propOnBlur, error: propError, maxLength = constants_1.DEFAULT_MAX_NAME_LENGTH, required = true, customSchema, showLabel = true, allowMoreThanMaxLength = true, size = 'm' } = props, inputProps = __rest(props, ["value", "onChange", "onBlur", "error", "maxLength", "required", "customSchema", "showLabel", "allowMoreThanMaxLength", "size"]);
|
|
33
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)(propValue);
|
|
34
|
+
const [validationError, setValidationError] = (0, react_1.useState)(null);
|
|
35
|
+
const [isFocused, setIsFocused] = (0, react_1.useState)(false);
|
|
36
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
37
|
+
const validationSchema = (0, react_1.useMemo)(() => {
|
|
38
|
+
let baseSchema = (0, yup_1.string)()
|
|
39
|
+
.test('maxLength', t('FieldName.maxSymbols', { max: maxLength }), value => {
|
|
40
|
+
if (!value)
|
|
41
|
+
return true;
|
|
42
|
+
return value.length <= maxLength;
|
|
43
|
+
})
|
|
44
|
+
.matches(/^[a-zA-Z0-9.\-_]*$/, {
|
|
45
|
+
message: t('FieldName.wrongSymbols'),
|
|
46
|
+
name: 'allowedSymbols',
|
|
47
|
+
excludeEmptyString: true,
|
|
48
|
+
});
|
|
49
|
+
if (customSchema) {
|
|
50
|
+
baseSchema = baseSchema.concat(customSchema);
|
|
51
|
+
}
|
|
52
|
+
return required ? baseSchema.required(t('FieldName.required')) : baseSchema;
|
|
53
|
+
}, [customSchema, maxLength, required, t]);
|
|
54
|
+
const { validate } = (0, hooks_1.useCustomFieldValidation)({ schema: validationSchema });
|
|
55
|
+
const currentValue = 'value' in props ? propValue : internalValue;
|
|
56
|
+
const currentError = propError || (validationError === null || validationError === void 0 ? void 0 : validationError.message);
|
|
57
|
+
const isRequiredError = currentError === null || currentError === void 0 ? void 0 : currentError.match(t('FieldName.required'));
|
|
58
|
+
const handleChange = (newValue) => {
|
|
59
|
+
const result = validate(newValue);
|
|
60
|
+
// Если была required-ошибка и пользователь начал ввод, очищаем ее
|
|
61
|
+
if (isRequiredError && !isFocused) {
|
|
62
|
+
setValidationError(null);
|
|
63
|
+
}
|
|
64
|
+
else if (result.error && result.error.message !== t('FieldName.required')) {
|
|
65
|
+
// Любую НЕ required ошибку показываем сразу
|
|
66
|
+
setValidationError(result.error);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
setValidationError(null);
|
|
70
|
+
}
|
|
71
|
+
setInternalValue(newValue);
|
|
72
|
+
propOnChange === null || propOnChange === void 0 ? void 0 : propOnChange(newValue);
|
|
73
|
+
};
|
|
74
|
+
const handleBlur = (e) => {
|
|
75
|
+
var _a;
|
|
76
|
+
(0, input_private_1.runAfterRerender)(() => setIsFocused(false));
|
|
77
|
+
const result = validate(currentValue);
|
|
78
|
+
setValidationError(result.error);
|
|
79
|
+
(_a = props.onValidationError) === null || _a === void 0 ? void 0 : _a.call(props, result.error);
|
|
80
|
+
propOnBlur === null || propOnBlur === void 0 ? void 0 : propOnBlur(e);
|
|
81
|
+
};
|
|
82
|
+
const handleFocus = () => {
|
|
83
|
+
setIsFocused(true);
|
|
84
|
+
};
|
|
85
|
+
const handleClear = () => {
|
|
86
|
+
var _a;
|
|
87
|
+
const result = validate('');
|
|
88
|
+
setValidationError(result.error);
|
|
89
|
+
(_a = props.onValidationError) === null || _a === void 0 ? void 0 : _a.call(props, result.error);
|
|
90
|
+
};
|
|
91
|
+
const shouldShowCounter = currentError && ((currentError === null || currentError === void 0 ? void 0 : currentError.match(t('FieldName.maxSymbols', { max: maxLength }))) || isRequiredError);
|
|
92
|
+
// Ошибка обязательного поля появляется после blur
|
|
93
|
+
const showError = currentError && ((isRequiredError && !isFocused) || !isRequiredError);
|
|
94
|
+
return ((0, jsx_runtime_1.jsx)(uikit_product_mobile_fields_1.AdaptiveFieldText, Object.assign({}, inputProps, { inputMode: 'text', onClearButtonClick: handleClear, allowMoreThanMaxLength: allowMoreThanMaxLength, ref: (0, merge_refs_1.default)(ref, inputRef), value: currentValue, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, validationState: showError ? 'error' : inputProps.validationState, hint: showError ? currentError : undefined, maxLength: shouldShowCounter && showError ? maxLength : undefined, size: size, label: showLabel ? t('FieldName.label') : undefined, caption: !required ? t('FieldDescription.optional') : undefined })));
|
|
95
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Поле имя c оберткой для React Hook Form
|
|
3
|
+
*/
|
|
4
|
+
export declare const FieldNameRHF: import("react").ForwardRefExoticComponent<Omit<import("@cloud-ru/uikit-product-mobile-fields").FieldTextProps, "type" | "caption" | "label" | "hint" | "placeholder" | "inputMode" | "footer"> & {
|
|
5
|
+
showLabel?: boolean;
|
|
6
|
+
customSchema?: import("yup").StringSchema;
|
|
7
|
+
} & {
|
|
8
|
+
controllerProps: Omit<import("react-hook-form").ControllerProps<import("react-hook-form").FieldValues>, "render" | "rules" | "disabled">;
|
|
9
|
+
} & {
|
|
10
|
+
layoutType: import("@cloud-ru/uikit-product-utils/.").LayoutType;
|
|
11
|
+
} & import("react").RefAttributes<HTMLInputElement>>;
|