@cloud-ru/uikit-product-fields-predefined 0.13.11 → 0.14.1
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 +22 -0
- package/README.md +161 -0
- package/dist/cjs/components/FieldAi/FieldAi.d.ts +2 -2
- 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/FieldPhone/FieldPhone.d.ts +1 -1
- 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 +2 -2
- 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/FieldPhone/FieldPhone.d.ts +1 -1
- 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 +13 -11
- 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,28 @@
|
|
|
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.1 (2025-12-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **UIIAAS-1251:** docs ([0226b84](https://gitverse.ru/cloud-ru-tech/uikit-product/commits/0226b8456be07d407c614979552ce88023eb8bd9))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# 0.14.0 (2025-12-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **UIIAAS-1251:** added FieldDescription & FieldName ([e03ba16](https://gitverse.ru/cloud-ru-tech/uikit-product/commits/e03ba16f0bbe62d0c00e7e109727a4b49f13fc6b))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## 0.13.11 (2025-11-28)
|
|
7
29
|
|
|
8
30
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
44
44
|
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
45
45
|
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
46
|
+
| onClearButtonClick | `() => void` | - | Колбек клика по кнопке очистки поля |
|
|
46
47
|
| scrollList | `boolean` | - | Включить скролл для основной части списка стран |
|
|
47
48
|
| searchPlaceholder | `string` | - | |
|
|
48
49
|
| onChangeCountry | `(country: FieldPhoneOptionsProps) => void` | - | |
|
|
@@ -144,6 +145,166 @@
|
|
|
144
145
|
| name | type | default value | description |
|
|
145
146
|
|------|------|---------------|-------------|
|
|
146
147
|
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
148
|
+
## FieldName
|
|
149
|
+
Поле имя c локальным стейтом и валидацией
|
|
150
|
+
### Props
|
|
151
|
+
| name | type | default value | description |
|
|
152
|
+
|------|------|---------------|-------------|
|
|
153
|
+
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
154
|
+
| value | `string` | - | Значение input |
|
|
155
|
+
| onChange | `(value: string, e?: ChangeEvent<HTMLInputElement>) => void` | - | Колбек смены значения |
|
|
156
|
+
| id | `string` | - | Значение html-атрибута id |
|
|
157
|
+
| name | `string` | - | Значение html-атрибута name |
|
|
158
|
+
| maxLength | `number` | - | Максимальная длина вводимого значения |
|
|
159
|
+
| disabled | `boolean` | false | Является ли поле деактивированным |
|
|
160
|
+
| readonly | `boolean` | false | Является ли поле доступным только для чтения |
|
|
161
|
+
| onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
|
|
162
|
+
| onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
|
|
163
|
+
| autoComplete | `string \| boolean` | false | Включен ли автокомплит для поля |
|
|
164
|
+
| autoFocus | `boolean` | false | Включен ли авто-фокус для поля |
|
|
165
|
+
| onPaste | `ClipboardEventHandler<HTMLInputElement>` | - | Колбек обработки вставки значения |
|
|
166
|
+
| onKeyDown | `KeyboardEventHandler<HTMLInputElement>` | - | Колбек обработки начала нажатия клавиши клавиатуры |
|
|
167
|
+
| spellCheck | `boolean` | true | Значение атрибута spellcheck (проверка орфографии) |
|
|
168
|
+
| pattern | `string` | - | Регулярное выражение валидного инпута |
|
|
169
|
+
| className | `string` | - | CSS-класс |
|
|
170
|
+
| labelTooltip | `ReactNode` | - | Всплывающая подсказка лейбла |
|
|
171
|
+
| required | `boolean` | - | Является ли поле обязательным |
|
|
172
|
+
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
173
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | - | Размер |
|
|
174
|
+
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
175
|
+
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
176
|
+
| error | `string` | - | |
|
|
177
|
+
| prefix | `ReactNode` | - | Произвольный префикс для поля |
|
|
178
|
+
| prefixIcon | `ReactElement<any, string \| JSXElementConstructor<any>>` | - | Иконка-префикс для поля |
|
|
179
|
+
| postfix | `ReactNode` | - | Произвольный постфикс для поля |
|
|
180
|
+
| allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
|
|
181
|
+
| button | `Button` | - | Кнопка действия внутри поля |
|
|
182
|
+
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
183
|
+
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
184
|
+
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
185
|
+
| onClearButtonClick | `() => void` | - | Колбек клика по кнопке очистки поля |
|
|
186
|
+
| showLabel | `boolean` | - | |
|
|
187
|
+
| customSchema | `StringSchema<string, AnyObject, undefined, "">` | - | |
|
|
188
|
+
| onValidationError | `(error: ValidationError) => void` | - | Колбэк, вызываемый при изменении ошибки валидации |
|
|
189
|
+
| 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} |
|
|
190
|
+
| key | `Key` | - | |
|
|
191
|
+
## FieldNameRHF
|
|
192
|
+
Поле имя c оберткой для React Hook Form
|
|
193
|
+
### Props
|
|
194
|
+
| name | type | default value | description |
|
|
195
|
+
|------|------|---------------|-------------|
|
|
196
|
+
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
197
|
+
| controllerProps* | `Omit<ControllerProps<FieldValues>, "disabled" \| "render" \| "rules">` | - | Режим контроллера с использованием react-hook-form |
|
|
198
|
+
| value | `string` | - | Значение input |
|
|
199
|
+
| onChange | `(value: string, e?: ChangeEvent<HTMLInputElement>) => void` | - | Колбек смены значения |
|
|
200
|
+
| id | `string` | - | Значение html-атрибута id |
|
|
201
|
+
| name | `string` | - | Значение html-атрибута name |
|
|
202
|
+
| maxLength | `number` | - | Максимальная длина вводимого значения |
|
|
203
|
+
| disabled | `boolean` | false | Является ли поле деактивированным |
|
|
204
|
+
| readonly | `boolean` | false | Является ли поле доступным только для чтения |
|
|
205
|
+
| onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
|
|
206
|
+
| onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
|
|
207
|
+
| autoComplete | `string \| boolean` | false | Включен ли автокомплит для поля |
|
|
208
|
+
| autoFocus | `boolean` | false | Включен ли авто-фокус для поля |
|
|
209
|
+
| onPaste | `ClipboardEventHandler<HTMLInputElement>` | - | Колбек обработки вставки значения |
|
|
210
|
+
| onKeyDown | `KeyboardEventHandler<HTMLInputElement>` | - | Колбек обработки начала нажатия клавиши клавиатуры |
|
|
211
|
+
| spellCheck | `boolean` | true | Значение атрибута spellcheck (проверка орфографии) |
|
|
212
|
+
| pattern | `string` | - | Регулярное выражение валидного инпута |
|
|
213
|
+
| className | `string` | - | CSS-класс |
|
|
214
|
+
| labelTooltip | `ReactNode` | - | Всплывающая подсказка лейбла |
|
|
215
|
+
| required | `boolean` | - | Является ли поле обязательным |
|
|
216
|
+
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
217
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | - | Размер |
|
|
218
|
+
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
219
|
+
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
220
|
+
| error | `string` | - | |
|
|
221
|
+
| prefix | `ReactNode` | - | Произвольный префикс для поля |
|
|
222
|
+
| prefixIcon | `ReactElement<any, string \| JSXElementConstructor<any>>` | - | Иконка-префикс для поля |
|
|
223
|
+
| postfix | `ReactNode` | - | Произвольный постфикс для поля |
|
|
224
|
+
| allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
|
|
225
|
+
| button | `Button` | - | Кнопка действия внутри поля |
|
|
226
|
+
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
227
|
+
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
228
|
+
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
229
|
+
| onClearButtonClick | `() => void` | - | Колбек клика по кнопке очистки поля |
|
|
230
|
+
| showLabel | `boolean` | - | |
|
|
231
|
+
| customSchema | `StringSchema<string, AnyObject, undefined, "">` | - | |
|
|
232
|
+
| 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} |
|
|
233
|
+
| key | `Key` | - | |
|
|
234
|
+
## FieldDescription
|
|
235
|
+
Поле описание c локальным стейтом и валидацией
|
|
236
|
+
### Props
|
|
237
|
+
| name | type | default value | description |
|
|
238
|
+
|------|------|---------------|-------------|
|
|
239
|
+
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
240
|
+
| value | `string` | - | HTML-аттрибут value |
|
|
241
|
+
| onChange | `(value: string, e?: ChangeEvent<HTMLTextAreaElement>) => void` | - | Колбек смены значения |
|
|
242
|
+
| id | `string` | - | HTML-аттрибут id |
|
|
243
|
+
| maxLength | `number` | 255 | Максимальное кол-во символов |
|
|
244
|
+
| disabled | `boolean` | - | Является ли поле деактивированным |
|
|
245
|
+
| readonly | `boolean` | - | Является ли поле доступным только на чтение |
|
|
246
|
+
| onFocus | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек получения фокуса |
|
|
247
|
+
| onBlur | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек потери фокуса |
|
|
248
|
+
| autoFocus | `boolean` | - | Включен ли авто-фокус |
|
|
249
|
+
| onKeyDown | `KeyboardEventHandler<HTMLTextAreaElement>` | - | Колбек нажатия клавиши клавиатуры |
|
|
250
|
+
| spellCheck | `boolean` | true | Включение проверки орфографии |
|
|
251
|
+
| className | `string` | - | CSS-класс |
|
|
252
|
+
| labelTooltip | `ReactNode` | - | Всплывающая подсказка лейбла |
|
|
253
|
+
| required | `boolean` | - | Является ли поле обязательным |
|
|
254
|
+
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
255
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер |
|
|
256
|
+
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
257
|
+
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
258
|
+
| error | `string` | - | |
|
|
259
|
+
| allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
|
|
260
|
+
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
261
|
+
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
262
|
+
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
263
|
+
| minRows | `number` | 3 | Минимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
264
|
+
| maxRows | `number` | 1000 | Максимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
265
|
+
| resizable | `boolean` | true | Может ли ли пользователь изменять размеры поля (если св-во не включено, поле автоматически меняет свой размер) |
|
|
266
|
+
| customSchema | `StringSchema<string, AnyObject, undefined, "">` | - | |
|
|
267
|
+
| addButton | `boolean` | - | Поле появляется по кнопке "Добавить описание" (только для опционального поля) |
|
|
268
|
+
| onValidationError | `(error: ValidationError) => void` | - | Колбэк, вызываемый при изменении ошибки валидации (только в standalone режиме) |
|
|
269
|
+
| 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} |
|
|
270
|
+
| key | `Key` | - | |
|
|
271
|
+
## FieldDescriptionRHF
|
|
272
|
+
Поле описание c оберткой для React Hook Form
|
|
273
|
+
### Props
|
|
274
|
+
| name | type | default value | description |
|
|
275
|
+
|------|------|---------------|-------------|
|
|
276
|
+
| layoutType* | enum LayoutType: `"mobile"`, `"tablet"`, `"desktop"`, `"desktopSmall"` | - | |
|
|
277
|
+
| controllerProps* | `Omit<ControllerProps<FieldValues>, "disabled" \| "render" \| "rules">` | - | Режим контроллера с использованием react-hook-form |
|
|
278
|
+
| value | `string` | - | HTML-аттрибут value |
|
|
279
|
+
| onChange | `(value: string, e?: ChangeEvent<HTMLTextAreaElement>) => void` | - | Колбек смены значения |
|
|
280
|
+
| id | `string` | - | HTML-аттрибут id |
|
|
281
|
+
| maxLength | `number` | 255 | Максимальное кол-во символов |
|
|
282
|
+
| disabled | `boolean` | - | Является ли поле деактивированным |
|
|
283
|
+
| readonly | `boolean` | - | Является ли поле доступным только на чтение |
|
|
284
|
+
| onFocus | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек получения фокуса |
|
|
285
|
+
| onBlur | `FocusEventHandler<HTMLTextAreaElement>` | - | Колбек потери фокуса |
|
|
286
|
+
| autoFocus | `boolean` | - | Включен ли авто-фокус |
|
|
287
|
+
| onKeyDown | `KeyboardEventHandler<HTMLTextAreaElement>` | - | Колбек нажатия клавиши клавиатуры |
|
|
288
|
+
| spellCheck | `boolean` | true | Включение проверки орфографии |
|
|
289
|
+
| className | `string` | - | CSS-класс |
|
|
290
|
+
| labelTooltip | `ReactNode` | - | Всплывающая подсказка лейбла |
|
|
291
|
+
| required | `boolean` | - | Является ли поле обязательным |
|
|
292
|
+
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
293
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер |
|
|
294
|
+
| validationState | enum ValidationState: `"error"`, `"default"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
295
|
+
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
296
|
+
| error | `string` | - | |
|
|
297
|
+
| allowMoreThanMaxLength | `boolean` | - | Можно ли вводить больше разрешённого кол-ва символов |
|
|
298
|
+
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
299
|
+
| onCopyButtonClick | `() => void` | - | Колбек клика по кнопке Копировать для поля |
|
|
300
|
+
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
301
|
+
| minRows | `number` | 3 | Минимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
302
|
+
| maxRows | `number` | 1000 | Максимальное кол-во строк, до которого размер поля может быть увеличен |
|
|
303
|
+
| resizable | `boolean` | true | Может ли ли пользователь изменять размеры поля (если св-во не включено, поле автоматически меняет свой размер) |
|
|
304
|
+
| customSchema | `StringSchema<string, AnyObject, undefined, "">` | - | |
|
|
305
|
+
| addButton | `boolean` | - | Поле появляется по кнопке "Добавить описание" (только для опционального поля) |
|
|
306
|
+
| 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} |
|
|
307
|
+
| key | `Key` | - | |
|
|
147
308
|
|
|
148
309
|
|
|
149
310
|
[//]: 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
|
/** Колбек действия при отправке */
|
|
@@ -16,5 +16,5 @@ export declare const FieldAi: import("react").ForwardRefExoticComponent<Omit<Fie
|
|
|
16
16
|
/** Действие при клике по кнопке сброса контекста */
|
|
17
17
|
onResetContextClick?(): void;
|
|
18
18
|
} & {
|
|
19
|
-
layoutType: import("@cloud-ru/uikit-product-utils
|
|
19
|
+
layoutType: import("@cloud-ru/uikit-product-utils").LayoutType;
|
|
20
20
|
} & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
@@ -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>>;
|