@cloud-ru/ds-field-decorator 1.0.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 (68) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +201 -0
  3. package/README.md +333 -0
  4. package/dist/cjs/components/FieldDecorator/FieldDecorator.d.ts +2 -0
  5. package/dist/cjs/components/FieldDecorator/FieldDecorator.js +24 -0
  6. package/dist/cjs/components/FieldDecorator/index.d.ts +1 -0
  7. package/dist/cjs/components/FieldDecorator/index.js +17 -0
  8. package/dist/cjs/components/FieldDecorator/styles.module.css +21 -0
  9. package/dist/cjs/components/Hint/Hint.d.ts +2 -0
  10. package/dist/cjs/components/Hint/Hint.js +37 -0
  11. package/dist/cjs/components/Hint/index.d.ts +1 -0
  12. package/dist/cjs/components/Hint/index.js +17 -0
  13. package/dist/cjs/components/Hint/styles.module.css +166 -0
  14. package/dist/cjs/components/Label/Label.d.ts +2 -0
  15. package/dist/cjs/components/Label/Label.js +17 -0
  16. package/dist/cjs/components/Label/index.d.ts +1 -0
  17. package/dist/cjs/components/Label/index.js +17 -0
  18. package/dist/cjs/components/Label/styles.module.css +117 -0
  19. package/dist/cjs/components/index.d.ts +3 -0
  20. package/dist/cjs/components/index.js +19 -0
  21. package/dist/cjs/constants.d.ts +20 -0
  22. package/dist/cjs/constants.js +23 -0
  23. package/dist/cjs/index.d.ts +3 -0
  24. package/dist/cjs/index.js +19 -0
  25. package/dist/cjs/package.json +3 -0
  26. package/dist/cjs/style.css +304 -0
  27. package/dist/cjs/types.d.ts +95 -0
  28. package/dist/cjs/types.js +2 -0
  29. package/dist/esm/components/FieldDecorator/FieldDecorator.d.ts +2 -0
  30. package/dist/esm/components/FieldDecorator/FieldDecorator.js +18 -0
  31. package/dist/esm/components/FieldDecorator/index.d.ts +1 -0
  32. package/dist/esm/components/FieldDecorator/index.js +1 -0
  33. package/dist/esm/components/FieldDecorator/styles.module.css +21 -0
  34. package/dist/esm/components/Hint/Hint.d.ts +2 -0
  35. package/dist/esm/components/Hint/Hint.js +31 -0
  36. package/dist/esm/components/Hint/index.d.ts +1 -0
  37. package/dist/esm/components/Hint/index.js +1 -0
  38. package/dist/esm/components/Hint/styles.module.css +166 -0
  39. package/dist/esm/components/Label/Label.d.ts +2 -0
  40. package/dist/esm/components/Label/Label.js +11 -0
  41. package/dist/esm/components/Label/index.d.ts +1 -0
  42. package/dist/esm/components/Label/index.js +1 -0
  43. package/dist/esm/components/Label/styles.module.css +117 -0
  44. package/dist/esm/components/index.d.ts +3 -0
  45. package/dist/esm/components/index.js +3 -0
  46. package/dist/esm/constants.d.ts +20 -0
  47. package/dist/esm/constants.js +20 -0
  48. package/dist/esm/index.d.ts +3 -0
  49. package/dist/esm/index.js +3 -0
  50. package/dist/esm/style.css +304 -0
  51. package/dist/esm/types.d.ts +95 -0
  52. package/dist/esm/types.js +1 -0
  53. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  54. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  55. package/package.json +45 -0
  56. package/src/components/FieldDecorator/FieldDecorator.tsx +77 -0
  57. package/src/components/FieldDecorator/index.ts +1 -0
  58. package/src/components/FieldDecorator/styles.module.scss +24 -0
  59. package/src/components/Hint/Hint.tsx +79 -0
  60. package/src/components/Hint/index.ts +1 -0
  61. package/src/components/Hint/styles.module.scss +143 -0
  62. package/src/components/Label/Label.tsx +58 -0
  63. package/src/components/Label/index.ts +1 -0
  64. package/src/components/Label/styles.module.scss +98 -0
  65. package/src/components/index.ts +3 -0
  66. package/src/constants.ts +22 -0
  67. package/src/index.ts +3 -0
  68. package/src/types.ts +101 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.0.0 (2026-08-18)
7
+
8
+ Initial stable release under the `@cloud-ru/ds-*` scope.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 Cloud technology Limited (Ltd.)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # FieldDecorator
2
+
3
+ `@cloud-ru/ds-field-decorator` — Структурная обёртка label/caption/hint/error/length для нестандартных input'ов и сложных композиций.
4
+
5
+ Низкоуровневый каркас для полей: рендерит блоки label, caption, hint, error, счётчик length и звёздочку required, а в `children` подставляется любой input или композиция (`@cloud-ru/ds-input-private`, дата-пикеры, селекты).
6
+
7
+ Пакет отдаёт три публичных компонента:
8
+
9
+ - `Label` — строка заголовка: текст, звёздочка required, question-tooltip и подпись caption.
10
+ - `Hint` — подвал поля: подсказка/ошибка со статус-иконкой по валидации и счётчик length.
11
+ - `FieldDecorator` — композиция `Label` + `children` + `Hint` в единой сетке.
12
+
13
+ ## Когда использовать
14
+
15
+ - Когда нужно обернуть нестандартный input в типовую разметку поля.
16
+ - Когда `FieldText` / `FieldSecure` не подходят:
17
+ - отдельный date-picker;
18
+ - masked input;
19
+ - кастомная композиция со счётчиком `length` или валидационной подсказкой.
20
+
21
+ ## Анатомия
22
+
23
+ ### Size (default `m`)
24
+
25
+ | Значение | Когда |
26
+ |----------|-------|
27
+ | `s` | Плотные таблицы, inline-редактирование |
28
+ | `m` | Стандартные формы (по умолчанию) |
29
+ | `l` | Лендинги, primary-формы |
30
+
31
+ ### ValidationState (default `default`)
32
+
33
+ Управляет цветом подсказки и иконкой `showHintIcon`. Проп `error` форсит `error` поверх любого `validationState`. На неактивном поле (`disabled` / `readonly`) иконка валидации не выводится — подсказка нейтральна.
34
+
35
+ | Значение | Когда |
36
+ |----------|-------|
37
+ | `default` | Нет валидации — нейтральный baseline: подсказка в `textTertiary`, без иконки и без заливки |
38
+ | `error` | Не прошло валидацию |
39
+ | `warning` | Предупреждение |
40
+ | `success` | Подтверждение |
41
+
42
+ ### Состояния (`disabled` / `readonly`)
43
+
44
+ Оси неактивного поля. Не комбинируются с цветом валидации: на неактивном поле иконка валидации не выводится, счётчик `length` скрыт.
45
+
46
+ | Значение | Поведение |
47
+ |----------|-----------|
48
+ | `disabled` | Поле выключено: счётчик скрыт, подсказка нейтральна |
49
+ | `readonly` | Только для чтения: то же поведение подвала, что у `disabled` |
50
+
51
+ ### Заголовок (`Label`)
52
+
53
+ Шапка поля складывается из слотов:
54
+
55
+ - `label` — текст заголовка; `labelFor` связывает его с input через HTML-атрибут `for`.
56
+ - `required` — звёздочка `*` рядом с заголовком, маркирует обязательное поле.
57
+ - `labelTooltip` — иконка вопроса с подсказкой (`QuestionTooltip`) после заголовка. Требует `PortalContextProvider` в дереве.
58
+ - `caption` — вспомогательная подпись справа в шапке.
59
+
60
+ ### Подвал (`Hint`)
61
+
62
+ Под содержимым выводится:
63
+
64
+ - `hint` / `error` — текст подсказки. `error` имеет приоритет над `hint` и форсит `validationState='error'`.
65
+ - `length` — счётчик длины `current/max`. Когда `current` превышает `max`, счётчик подсвечивается (`data-limit-exceeded`). На `disabled` / `readonly` счётчик скрыт.
66
+
67
+ ## Установка
68
+
69
+ ```bash
70
+ pnpm add @cloud-ru/ds-field-decorator
71
+ ```
72
+
73
+ ```ts
74
+ import { FieldDecorator, Label, Hint } from '@cloud-ru/ds-field-decorator'
75
+ ```
76
+
77
+ ## Примеры использования
78
+
79
+ ### Базовая обёртка
80
+
81
+ FieldDecorator оборачивает InputPrivate в типовую разметку label/hint.
82
+
83
+ ```tsx
84
+ import { FieldDecorator } from '@cloud-ru/ds-field-decorator';
85
+ import { InputPrivate } from '@cloud-ru/ds-input-private';
86
+ import { useState } from 'react';
87
+
88
+ export function DecoratorBasic() {
89
+ const [value, setValue] = useState('');
90
+ return (
91
+ <FieldDecorator label='Custom field' hint='FieldDecorator оборачивает любой input' showHintIcon>
92
+ <InputPrivate value={value} onChange={setValue} placeholder='Type here' />
93
+ </FieldDecorator>
94
+ );
95
+ }
96
+ ```
97
+
98
+ ### Счётчик длины
99
+
100
+ Length показывает «текущая/максимум», обновляется по изменению значения.
101
+
102
+ ```tsx
103
+ import { FieldDecorator } from '@cloud-ru/ds-field-decorator';
104
+ import { InputPrivate } from '@cloud-ru/ds-input-private';
105
+ import { useState } from 'react';
106
+
107
+ export function DecoratorLength() {
108
+ const [value, setValue] = useState('');
109
+ return (
110
+ <FieldDecorator
111
+ label='Bio'
112
+ caption='Опционально'
113
+ hint='Кратко расскажите о себе'
114
+ length={{ current: value.length, max: 120 }}
115
+ >
116
+ <InputPrivate value={value} onChange={setValue} maxLength={120} placeholder='Hi there' />
117
+ </FieldDecorator>
118
+ );
119
+ }
120
+ ```
121
+
122
+ ### Превышение лимита
123
+
124
+ Когда current больше max, счётчик подсвечивается (data-limit-exceeded).
125
+
126
+ ```tsx
127
+ import { FieldDecorator } from '@cloud-ru/ds-field-decorator';
128
+ import { InputPrivate } from '@cloud-ru/ds-input-private';
129
+ import { useState } from 'react';
130
+
131
+ export function DecoratorLimitExceeded() {
132
+ const [value, setValue] = useState('Слишком длинное значение, которое превышает лимит');
133
+ return (
134
+ <FieldDecorator
135
+ label='Заголовок'
136
+ hint='Счётчик подсвечивается, когда current превышает max'
137
+ length={{ current: value.length, max: 20 }}
138
+ >
139
+ <InputPrivate value={value} onChange={setValue} placeholder='Введите текст' />
140
+ </FieldDecorator>
141
+ );
142
+ }
143
+ ```
144
+
145
+ ### Подсказка к заголовку
146
+
147
+ labelTooltip добавляет иконку вопроса после label; required рисует звёздочку. Требует PortalContextProvider.
148
+
149
+ ```tsx
150
+ import { FieldDecorator } from '@cloud-ru/ds-field-decorator';
151
+ import { InputPrivate } from '@cloud-ru/ds-input-private';
152
+ import { useState } from 'react';
153
+
154
+ export function DecoratorLabelTooltip() {
155
+ const [value, setValue] = useState('');
156
+ return (
157
+ <FieldDecorator
158
+ label='Идентификатор'
159
+ required
160
+ labelTooltip={{ tip: 'Уникальный идентификатор ресурса. Наведите на иконку рядом с заголовком.' }}
161
+ hint='Подсказка к заголовку выводится через иконку вопроса'
162
+ >
163
+ <InputPrivate value={value} onChange={setValue} placeholder='res-id' />
164
+ </FieldDecorator>
165
+ );
166
+ }
167
+ ```
168
+
169
+ ### Disabled и Readonly
170
+
171
+ На неактивном поле счётчик скрыт, а иконка валидации не выводится — подсказка нейтральна.
172
+
173
+ ```tsx
174
+ import { FieldDecorator } from '@cloud-ru/ds-field-decorator';
175
+ import { InputPrivate } from '@cloud-ru/ds-input-private';
176
+
177
+ export function DecoratorDisabledReadonly() {
178
+ return (
179
+ <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', alignItems: 'flex-start' }}>
180
+ <FieldDecorator
181
+ label='Disabled'
182
+ hint='На неактивном поле счётчик скрыт, подсказка нейтральна'
183
+ validationState='error'
184
+ showHintIcon
185
+ disabled
186
+ length={{ current: 5, max: 20 }}
187
+ >
188
+ <InputPrivate value='value' onChange={() => undefined} disabled />
189
+ </FieldDecorator>
190
+ <FieldDecorator
191
+ label='Readonly'
192
+ hint='Readonly также нейтрализует подсказку и прячет счётчик'
193
+ validationState='warning'
194
+ showHintIcon
195
+ readonly
196
+ length={{ current: 5, max: 20 }}
197
+ >
198
+ <InputPrivate value='value' onChange={() => undefined} readonly />
199
+ </FieldDecorator>
200
+ </div>
201
+ );
202
+ }
203
+ ```
204
+
205
+ ### Label отдельно
206
+
207
+ Строку заголовка можно рендерить самостоятельно — например, над кастомной композицией.
208
+
209
+ ```tsx
210
+ import { Label } from '@cloud-ru/ds-field-decorator';
211
+
212
+ export function LabelStandalone() {
213
+ return (
214
+ <Label
215
+ label='Заголовок поля'
216
+ caption='Опционально'
217
+ required
218
+ labelTooltip={{ tip: 'Пояснение к заголовку через иконку вопроса' }}
219
+ />
220
+ );
221
+ }
222
+ ```
223
+
224
+ ### Hint по состояниям валидации
225
+
226
+ Подсказка меняет цвет и статус-иконку по validationState.
227
+
228
+ ```tsx
229
+ import { Hint } from '@cloud-ru/ds-field-decorator';
230
+
231
+ export function HintStandalone() {
232
+ return (
233
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
234
+ <Hint hint='Нейтральная подсказка под полем' length={{ current: 12, max: 100 }} />
235
+ <Hint hint='Ошибка валидации' validationState='error' showHintIcon />
236
+ <Hint hint='Предупреждение' validationState='warning' showHintIcon />
237
+ <Hint hint='Проверка пройдена' validationState='success' showHintIcon />
238
+ </div>
239
+ );
240
+ }
241
+ ```
242
+
243
+ ## Props
244
+
245
+ ### FieldDecorator
246
+
247
+ **FieldDecoratorProps**
248
+
249
+ | Prop | Type | Default | Description |
250
+ |------|------|---------|-------------|
251
+ | `caption` | `string` | — | Вторичная подпись справа |
252
+ | `children` | `ReactNode` | — | Содержимое (декорируемое поле) |
253
+ | `className` | `string` | — | CSS-класс |
254
+ | `data-test-id` | `string` | — | |
255
+ | `disabled` | `boolean` | — | Поле выключено |
256
+ | `error` | `string` | — | Ошибка (приоритетнее `hint`; форсит `validationState=error`) |
257
+ | `hint` | `string` | — | Подсказка |
258
+ | `innerRef` | `Ref<HTMLDivElement>` | — | Ref на корневой DOM-элемент |
259
+ | `label` | `string` | — | Заголовок |
260
+ | `labelFor` | `string` | — | HTML-атрибут `for` для `<label>` |
261
+ | `labelTooltip` | `QuestionTooltipProps` | — | Подсказка (question-tooltip) у заголовка |
262
+ | `length` | `FieldLength` | — | Счётчик длины `current/max` |
263
+ | `readonly` | `boolean` | — | Только для чтения |
264
+ | `required` | `boolean` | — | Показать знак обязательности `*` |
265
+ | `showHintIcon` | `boolean` | `true` | Отображение статус-иконки у подсказки (по умолчанию `true`) |
266
+ | `size` | `"l"` \| `"m"` \| `"s"` | `m` | Размер |
267
+ | `validationState` | `"default"` \| `"error"` \| `"success"` \| `"warning"` | `default` | Состояние валидации |
268
+
269
+ #### Related types
270
+
271
+ **FieldLength**
272
+
273
+ | Prop | Type | Default | Description |
274
+ |------|------|---------|-------------|
275
+ | `current` | `number` | — | Текущая длина текста |
276
+ | `max` | `number \| undefined` | — | Максимально допустимая длина |
277
+
278
+ - `Size` = `"l"` \| `"m"` \| `"s"`
279
+
280
+ - `ValidationState` = `"default"` \| `"error"` \| `"success"` \| `"warning"`
281
+
282
+ ### Label
283
+
284
+ **LabelProps**
285
+
286
+ | Prop | Type | Default | Description |
287
+ |------|------|---------|-------------|
288
+ | `caption` | `string` | — | Вторичная подпись справа |
289
+ | `className` | `string` | — | CSS-класс |
290
+ | `data-test-id` | `string` | — | |
291
+ | `disabled` | `boolean` | — | Поле выключено |
292
+ | `innerRef` | `Ref<HTMLDivElement>` | — | Ref на корневой DOM-элемент |
293
+ | `label` | `string` | — | Заголовок |
294
+ | `labelFor` | `string` | — | HTML-атрибут `for` для `<label>` |
295
+ | `labelTooltip` | `QuestionTooltipProps` | — | Подсказка (question-tooltip) у заголовка |
296
+ | `required` | `boolean` | — | Показать знак обязательности `*` |
297
+ | `size` | `"l"` \| `"m"` \| `"s"` | `m` | Размер |
298
+
299
+ #### Related types
300
+
301
+ - `Size` = `"l"` \| `"m"` \| `"s"`
302
+
303
+ ### Hint
304
+
305
+ **HintProps**
306
+
307
+ | Prop | Type | Default | Description |
308
+ |------|------|---------|-------------|
309
+ | `className` | `string` | — | CSS-класс |
310
+ | `data-test-id` | `string` | — | |
311
+ | `disabled` | `boolean` | — | Поле выключено |
312
+ | `error` | `string` | — | Ошибка (приоритетнее `hint`; форсит `validationState=error`) |
313
+ | `hint` | `string` | — | Подсказка |
314
+ | `innerRef` | `Ref<HTMLDivElement>` | — | Ref на корневой DOM-элемент |
315
+ | `length` | `FieldLength` | — | Счётчик длины `current/max` |
316
+ | `maxLines` | `number` | — | Обрезать подсказку до N строк многоточием (через `TruncateString`, с тултипом <br/> полного текста на ховере). Без значения подсказка переносится без ограничения <br/> (дефолт поля). Нужно для карточек фиксированной высоты (`@cloud-ru/ds-attachment`), где <br/> длинный текст ошибки иначе выходит за границы. |
317
+ | `readonly` | `boolean` | — | Только для чтения |
318
+ | `showHintIcon` | `boolean` | `true` | Отображение статус-иконки у подсказки (по умолчанию `true`) |
319
+ | `size` | `"l"` \| `"m"` \| `"s"` | `m` | Размер |
320
+ | `validationState` | `"default"` \| `"error"` \| `"success"` \| `"warning"` | `default` | Состояние валидации |
321
+
322
+ #### Related types
323
+
324
+ **FieldLength**
325
+
326
+ | Prop | Type | Default | Description |
327
+ |------|------|---------|-------------|
328
+ | `current` | `number` | — | Текущая длина текста |
329
+ | `max` | `number \| undefined` | — | Максимально допустимая длина |
330
+
331
+ - `Size` = `"l"` \| `"m"` \| `"s"`
332
+
333
+ - `ValidationState` = `"default"` \| `"error"` \| `"success"` \| `"warning"`
@@ -0,0 +1,2 @@
1
+ import { FieldDecoratorProps } from '../../types';
2
+ export declare function FieldDecorator({ className, innerRef, children, label, labelTooltip, caption, required, labelFor, hint, error, validationState: validationStateProp, showHintIcon, length, size, disabled, readonly: readOnly, ...rest }: FieldDecoratorProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FieldDecorator = FieldDecorator;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const utils_1 = require("@cloud-ru/ds-utils");
9
+ const classnames_1 = __importDefault(require("classnames"));
10
+ const constants_1 = require("../../constants");
11
+ const Hint_1 = require("../Hint");
12
+ const Label_1 = require("../Label");
13
+ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
14
+ function FieldDecorator({ className, innerRef, children, label, labelTooltip, caption, required, labelFor, hint, error, validationState: validationStateProp = constants_1.VALIDATION_STATE.Default, showHintIcon = true, length, size = constants_1.SIZE.M, disabled, readonly: readOnly, ...rest }) {
15
+ const showLabelContent = label || required || labelTooltip;
16
+ const showHeader = showLabelContent || caption;
17
+ const hintText = error || hint;
18
+ const isFieldActive = !disabled && !readOnly;
19
+ const showLength = isFieldActive && Boolean(length);
20
+ const showFooter = hintText || showLength;
21
+ const validationState = error ? constants_1.VALIDATION_STATE.Error : validationStateProp;
22
+ return ((0, jsx_runtime_1.jsxs)("div", { ...(0, utils_1.extractSupportProps)(rest), ref: innerRef, className: (0, classnames_1.default)(styles_module_scss_1.default.fieldDecorator, className), "data-size": size, "data-validation-state": validationState, "data-disabled": disabled || undefined, "data-readonly": readOnly || undefined, children: [showHeader && ((0, jsx_runtime_1.jsx)(Label_1.Label, { label: label, labelTooltip: labelTooltip, caption: caption, required: required, labelFor: labelFor, size: size, disabled: disabled })), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.content, children: children }), showFooter && ((0, jsx_runtime_1.jsx)(Hint_1.Hint, { hint: hint, error: error, validationState: validationStateProp, showHintIcon: showHintIcon, length: length, size: size, disabled: disabled, readonly: readOnly }))] }));
23
+ }
24
+ (0, utils_1.withInnerRefSupport)(FieldDecorator);
@@ -0,0 +1 @@
1
+ export * from './FieldDecorator';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./FieldDecorator"), exports);
@@ -0,0 +1,21 @@
1
+ .fieldDecorator{
2
+ display:flex;
3
+ flex-direction:column;
4
+ align-items:flex-start;
5
+ box-sizing:border-box;
6
+ width:100%;
7
+ min-width:0;
8
+ }
9
+ .fieldDecorator[data-size=s]{
10
+ gap:var(--sn-labelDecorator-size-s-gap, var(--sn-primitive-dimension-4, 4px));
11
+ }
12
+ .fieldDecorator[data-size=m]{
13
+ gap:var(--sn-labelDecorator-size-m-gap, var(--sn-primitive-dimension-4, 4px));
14
+ }
15
+ .fieldDecorator[data-size=l]{
16
+ gap:var(--sn-labelDecorator-size-l-gap, var(--sn-primitive-dimension-4, 4px));
17
+ }
18
+
19
+ .content{
20
+ align-self:stretch;
21
+ }
@@ -0,0 +1,2 @@
1
+ import { HintProps } from '../../types';
2
+ export declare function Hint({ className, innerRef, hint, error, validationState: validationStateProp, showHintIcon, length, maxLines, size, disabled, readonly: readOnly, ...rest }: HintProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Hint = Hint;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const system_1 = require("@cloud-ru/ds-icons/interface/system");
9
+ const truncate_string_1 = require("@cloud-ru/ds-truncate-string");
10
+ const utils_1 = require("@cloud-ru/ds-utils");
11
+ const classnames_1 = __importDefault(require("classnames"));
12
+ const constants_1 = require("../../constants");
13
+ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
14
+ function getHintIcon(validationState) {
15
+ switch (validationState) {
16
+ case constants_1.VALIDATION_STATE.Error:
17
+ return (0, jsx_runtime_1.jsx)(system_1.NotifierCriticalFilledSVG, {});
18
+ case constants_1.VALIDATION_STATE.Warning:
19
+ return (0, jsx_runtime_1.jsx)(system_1.NotifierWarningFilledSVG, {});
20
+ case constants_1.VALIDATION_STATE.Success:
21
+ return (0, jsx_runtime_1.jsx)(system_1.NotifierSuccessFilledSVG, {});
22
+ default:
23
+ return null;
24
+ }
25
+ }
26
+ function Hint({ className, innerRef, hint, error, validationState: validationStateProp = constants_1.VALIDATION_STATE.Default, showHintIcon = true, length, maxLines, size = constants_1.SIZE.M, disabled, readonly: readOnly, ...rest }) {
27
+ const hintText = error || hint;
28
+ // На неактивном поле (disabled/readonly) счётчик скрыт, а подсказка показывается нейтрально,
29
+ // без иконки валидации — паритет с легаси FieldDecorator (isFieldActive).
30
+ const isFieldActive = !disabled && !readOnly;
31
+ const showLength = isFieldActive && Boolean(length);
32
+ const limitExceeded = Boolean(length && length.max != null && length.current > length.max);
33
+ const validationState = error ? constants_1.VALIDATION_STATE.Error : validationStateProp;
34
+ const hintIcon = isFieldActive ? getHintIcon(validationState) : null;
35
+ return ((0, jsx_runtime_1.jsxs)("div", { ...(0, utils_1.extractSupportProps)(rest), ref: innerRef, className: (0, classnames_1.default)(styles_module_scss_1.default.hintWrapper, className), "data-size": size, "data-validation-state": validationState, "data-disabled": disabled || undefined, "data-readonly": readOnly || undefined, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.hintContent, children: [showHintIcon && hintText && hintIcon && (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.hintIcon, children: hintIcon }), hintText && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.hintText, "data-test-id": constants_1.TEST_IDS.hint, "data-clamp": maxLines ? '' : undefined, children: maxLines ? (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { text: hintText, maxLines: maxLines }) : hintText }))] }), showLength && length && ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.length, "data-test-id": constants_1.TEST_IDS.counter, "data-limit-exceeded": limitExceeded || undefined, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.lengthCurrent, children: length.current }), length.max != null && `/${length.max}`] }))] }));
36
+ }
37
+ (0, utils_1.withInnerRefSupport)(Hint);
@@ -0,0 +1 @@
1
+ export * from './Hint';