@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/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@cloud-ru/ds-field-decorator",
3
+ "version": "1.0.0",
4
+ "description": "Структурная обёртка label/caption/hint/error/length для нестандартных input'ов и сложных композиций.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/cloud-ru-tech/snack-v2.git",
8
+ "directory": "packages/field-decorator"
9
+ },
10
+ "homepage": "https://github.com/cloud-ru-tech/snack-v2/tree/master/packages/field-decorator",
11
+ "license": "Apache-2.0",
12
+ "author": "Nikita Ershov <niershov@cloud.ru>",
13
+ "type": "module",
14
+ "main": "./dist/cjs/index.js",
15
+ "module": "./dist/esm/index.js",
16
+ "types": "./dist/esm/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "source": "./src/index.ts",
20
+ "types": "./dist/esm/index.d.ts",
21
+ "import": "./dist/esm/index.js",
22
+ "require": "./dist/cjs/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "src",
28
+ "./CHANGELOG.md",
29
+ "./LICENSE"
30
+ ],
31
+ "sideEffects": [
32
+ "*.css",
33
+ "**/*.css"
34
+ ],
35
+ "dependencies": {
36
+ "classnames": "^2.5.1",
37
+ "@cloud-ru/ds-tooltip": "^1.0.0",
38
+ "@cloud-ru/ds-icons": "^1.0.0",
39
+ "@cloud-ru/ds-truncate-string": "^1.0.0",
40
+ "@cloud-ru/ds-utils": "^1.0.0"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }
@@ -0,0 +1,77 @@
1
+ import { extractSupportProps, withInnerRefSupport } from '@cloud-ru/ds-utils';
2
+ import cn from 'classnames';
3
+
4
+ import { SIZE, VALIDATION_STATE } from '../../constants';
5
+ import { FieldDecoratorProps } from '../../types';
6
+ import { Hint } from '../Hint';
7
+ import { Label } from '../Label';
8
+ import styles from './styles.module.scss';
9
+
10
+ export function FieldDecorator({
11
+ className,
12
+ innerRef,
13
+ children,
14
+ label,
15
+ labelTooltip,
16
+ caption,
17
+ required,
18
+ labelFor,
19
+ hint,
20
+ error,
21
+ validationState: validationStateProp = VALIDATION_STATE.Default,
22
+ showHintIcon = true,
23
+ length,
24
+ size = SIZE.M,
25
+ disabled,
26
+ readonly: readOnly,
27
+ ...rest
28
+ }: FieldDecoratorProps) {
29
+ const showLabelContent = label || required || labelTooltip;
30
+ const showHeader = showLabelContent || caption;
31
+ const hintText = error || hint;
32
+ const isFieldActive = !disabled && !readOnly;
33
+ const showLength = isFieldActive && Boolean(length);
34
+ const showFooter = hintText || showLength;
35
+ const validationState = error ? VALIDATION_STATE.Error : validationStateProp;
36
+
37
+ return (
38
+ <div
39
+ {...extractSupportProps(rest)}
40
+ ref={innerRef}
41
+ className={cn(styles.fieldDecorator, className)}
42
+ data-size={size}
43
+ data-validation-state={validationState}
44
+ data-disabled={disabled || undefined}
45
+ data-readonly={readOnly || undefined}
46
+ >
47
+ {showHeader && (
48
+ <Label
49
+ label={label}
50
+ labelTooltip={labelTooltip}
51
+ caption={caption}
52
+ required={required}
53
+ labelFor={labelFor}
54
+ size={size}
55
+ disabled={disabled}
56
+ />
57
+ )}
58
+
59
+ <div className={styles.content}>{children}</div>
60
+
61
+ {showFooter && (
62
+ <Hint
63
+ hint={hint}
64
+ error={error}
65
+ validationState={validationStateProp}
66
+ showHintIcon={showHintIcon}
67
+ length={length}
68
+ size={size}
69
+ disabled={disabled}
70
+ readonly={readOnly}
71
+ />
72
+ )}
73
+ </div>
74
+ );
75
+ }
76
+
77
+ withInnerRefSupport(FieldDecorator);
@@ -0,0 +1 @@
1
+ export * from './FieldDecorator';
@@ -0,0 +1,24 @@
1
+ @use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
2
+ @use '@cloud-ru/ds-figma-variables/build/scss/components/labelDecorator.module' as labelDecorator;
3
+
4
+ $sizes: 's', 'm', 'l';
5
+
6
+ .fieldDecorator {
7
+ display: flex;
8
+ flex-direction: column;
9
+ align-items: flex-start;
10
+
11
+ box-sizing: border-box;
12
+ width: 100%;
13
+ min-width: 0;
14
+
15
+ @each $size in $sizes {
16
+ &[data-size='#{$size}'] {
17
+ gap: base.simple-var(labelDecorator.$labelDecorator, 'size', $size, 'gap');
18
+ }
19
+ }
20
+ }
21
+
22
+ .content {
23
+ align-self: stretch;
24
+ }
@@ -0,0 +1,79 @@
1
+ import {
2
+ NotifierCriticalFilledSVG,
3
+ NotifierSuccessFilledSVG,
4
+ NotifierWarningFilledSVG,
5
+ } from '@cloud-ru/ds-icons/interface/system';
6
+ import { TruncateString } from '@cloud-ru/ds-truncate-string';
7
+ import { extractSupportProps, withInnerRefSupport } from '@cloud-ru/ds-utils';
8
+ import cn from 'classnames';
9
+
10
+ import { SIZE, TEST_IDS, VALIDATION_STATE } from '../../constants';
11
+ import { HintProps, ValidationState } from '../../types';
12
+ import styles from './styles.module.scss';
13
+
14
+ function getHintIcon(validationState: ValidationState) {
15
+ switch (validationState) {
16
+ case VALIDATION_STATE.Error:
17
+ return <NotifierCriticalFilledSVG />;
18
+ case VALIDATION_STATE.Warning:
19
+ return <NotifierWarningFilledSVG />;
20
+ case VALIDATION_STATE.Success:
21
+ return <NotifierSuccessFilledSVG />;
22
+ default:
23
+ return null;
24
+ }
25
+ }
26
+
27
+ export function Hint({
28
+ className,
29
+ innerRef,
30
+ hint,
31
+ error,
32
+ validationState: validationStateProp = VALIDATION_STATE.Default,
33
+ showHintIcon = true,
34
+ length,
35
+ maxLines,
36
+ size = SIZE.M,
37
+ disabled,
38
+ readonly: readOnly,
39
+ ...rest
40
+ }: HintProps) {
41
+ const hintText = error || hint;
42
+ // На неактивном поле (disabled/readonly) счётчик скрыт, а подсказка показывается нейтрально,
43
+ // без иконки валидации — паритет с легаси FieldDecorator (isFieldActive).
44
+ const isFieldActive = !disabled && !readOnly;
45
+ const showLength = isFieldActive && Boolean(length);
46
+ const limitExceeded = Boolean(length && length.max != null && length.current > length.max);
47
+ const validationState = error ? VALIDATION_STATE.Error : validationStateProp;
48
+ const hintIcon = isFieldActive ? getHintIcon(validationState) : null;
49
+
50
+ return (
51
+ <div
52
+ {...extractSupportProps(rest)}
53
+ ref={innerRef}
54
+ className={cn(styles.hintWrapper, className)}
55
+ data-size={size}
56
+ data-validation-state={validationState}
57
+ data-disabled={disabled || undefined}
58
+ data-readonly={readOnly || undefined}
59
+ >
60
+ <div className={styles.hintContent}>
61
+ {showHintIcon && hintText && hintIcon && <div className={styles.hintIcon}>{hintIcon}</div>}
62
+ {hintText && (
63
+ <div className={styles.hintText} data-test-id={TEST_IDS.hint} data-clamp={maxLines ? '' : undefined}>
64
+ {maxLines ? <TruncateString text={hintText} maxLines={maxLines} /> : hintText}
65
+ </div>
66
+ )}
67
+ </div>
68
+
69
+ {showLength && length && (
70
+ <div className={styles.length} data-test-id={TEST_IDS.counter} data-limit-exceeded={limitExceeded || undefined}>
71
+ <span className={styles.lengthCurrent}>{length.current}</span>
72
+ {length.max != null && `/${length.max}`}
73
+ </div>
74
+ )}
75
+ </div>
76
+ );
77
+ }
78
+
79
+ withInnerRefSupport(Hint);
@@ -0,0 +1 @@
1
+ export * from './Hint';
@@ -0,0 +1,143 @@
1
+ @use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
2
+ @use '@cloud-ru/ds-figma-variables/build/scss/components/labelDecorator.module' as labelDecorator;
3
+
4
+ $sizes: 's', 'm', 'l';
5
+
6
+ $validationStates: warning, error, success;
7
+
8
+ $validationStateColor: (
9
+ 'warning': base.$sn-theme-color-yellow-text,
10
+ 'error': base.$sn-theme-color-red-text,
11
+ 'success': base.$sn-theme-color-green-text,
12
+ );
13
+
14
+ $validationIconColor: (
15
+ 'warning': base.$sn-theme-color-yellow-accent,
16
+ 'error': base.$sn-theme-color-red-accent,
17
+ 'success': base.$sn-theme-color-green-accent,
18
+ );
19
+
20
+ $hintTypography: (
21
+ 's': base.$sn-thin-label-s,
22
+ 'm': base.$sn-thin-label-m,
23
+ 'l': base.$sn-thin-label-l,
24
+ );
25
+
26
+ .hintWrapper {
27
+ display: flex;
28
+ align-items: flex-start;
29
+ align-self: stretch;
30
+
31
+ width: 100%;
32
+ min-width: 0;
33
+
34
+ .hintContent {
35
+ display: flex;
36
+ flex: 1 0 0;
37
+ align-items: flex-start;
38
+ min-width: 0;
39
+ }
40
+
41
+ // Длинная подсказка с непереносимым токеном переносится внутри футера,
42
+ // а не выталкивает счётчик за край (паритет с легаси `word-break: break-word`).
43
+ .hintText {
44
+ overflow-wrap: anywhere;
45
+ }
46
+
47
+ // В режиме клэмпа (`maxLines`) подсказку рендерит TruncateString: ему нужен
48
+ // ограниченный по ширине контейнер, иначе в column-flex с центрированием
49
+ // (overlay квадратной карточки) он берёт натуральную ширину текста и не
50
+ // распознаёт переполнение — многоточие не появляется, текст просто клипится.
51
+ .hintText[data-clamp] {
52
+ width: 100%;
53
+ min-width: 0;
54
+ }
55
+
56
+ .hintIcon {
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ }
61
+
62
+ .hintIcon > svg {
63
+ max-width: base.$sn-primitive-dimension-16;
64
+ max-height: base.$sn-primitive-dimension-16;
65
+ }
66
+
67
+ .hintText,
68
+ .length {
69
+ color: base.$sn-theme-color-available-version-textTertiary;
70
+ }
71
+
72
+ @each $size in $sizes {
73
+ &[data-size='#{$size}'] {
74
+ gap: base.simple-var(labelDecorator.$labelDecorator, 'size', $size, 'hintWrapper', 'gap');
75
+
76
+ .hintContent {
77
+ gap: base.simple-var(labelDecorator.$labelDecorator, 'size', $size, 'hintWrapper', 'hintContent', 'gap');
78
+ }
79
+
80
+ .hintIcon {
81
+ width: base.simple-var(
82
+ labelDecorator.$labelDecorator,
83
+ 'size',
84
+ $size,
85
+ 'hintWrapper',
86
+ 'hintContent',
87
+ 'iconWrapper',
88
+ 'height'
89
+ );
90
+ height: base.simple-var(
91
+ labelDecorator.$labelDecorator,
92
+ 'size',
93
+ $size,
94
+ 'hintWrapper',
95
+ 'hintContent',
96
+ 'iconWrapper',
97
+ 'height'
98
+ );
99
+ }
100
+
101
+ .hintText,
102
+ .length {
103
+ @include base.composite-var($hintTypography, $size);
104
+ }
105
+ }
106
+
107
+ @each $validationState in $validationStates {
108
+ &[data-validation-state='#{$validationState}'] {
109
+ .hintText,
110
+ .length {
111
+ color: base.simple-var($validationStateColor, $validationState);
112
+ }
113
+
114
+ .hintIcon {
115
+ color: base.simple-var($validationIconColor, $validationState);
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ &[data-disabled='true'] {
122
+ .hintText,
123
+ .length,
124
+ .hintIcon {
125
+ color: base.$sn-theme-color-available-version-textDisabled;
126
+ }
127
+ }
128
+
129
+ // readonly: подсказка нейтральная (без цвета валидации), паритет с легаси.
130
+ // Идёт после [data-disabled] — выше специфичность (:not), no-descending-specificity.
131
+ &[data-readonly='true']:not([data-disabled='true']) {
132
+ .hintIcon,
133
+ .hintText,
134
+ .length {
135
+ color: base.$sn-theme-color-available-version-textTertiary;
136
+ }
137
+ }
138
+
139
+ // Превышение лимита длины — текущее значение счётчика акцентируется красным.
140
+ .length[data-limit-exceeded='true'] .lengthCurrent {
141
+ color: base.$sn-theme-color-red-text;
142
+ }
143
+ }
@@ -0,0 +1,58 @@
1
+ import { QuestionTooltip } from '@cloud-ru/ds-tooltip';
2
+ import { extractSupportProps, withInnerRefSupport } from '@cloud-ru/ds-utils';
3
+ import cn from 'classnames';
4
+
5
+ import { SIZE, TEST_IDS } from '../../constants';
6
+ import { LabelProps } from '../../types';
7
+ import styles from './styles.module.scss';
8
+
9
+ export function Label({
10
+ className,
11
+ innerRef,
12
+ label,
13
+ labelTooltip,
14
+ caption,
15
+ required,
16
+ labelFor,
17
+ disabled,
18
+ size = SIZE.M,
19
+ ...rest
20
+ }: LabelProps) {
21
+ const showLabelContent = label || required || labelTooltip;
22
+
23
+ return (
24
+ <div
25
+ {...extractSupportProps(rest)}
26
+ ref={innerRef}
27
+ className={cn(styles.labelWrapper, className)}
28
+ data-size={size}
29
+ data-disabled={disabled || undefined}
30
+ >
31
+ {showLabelContent && (
32
+ <div className={styles.labelContent}>
33
+ <label className={styles.label} htmlFor={labelFor} data-test-id={TEST_IDS.label}>
34
+ {label}
35
+ </label>
36
+ {required && (
37
+ <div className={styles.required} data-test-id={TEST_IDS.required}>
38
+ *
39
+ </div>
40
+ )}
41
+ {labelTooltip && (
42
+ <div className={styles.labelTooltip} data-test-id={TEST_IDS.labelTooltip}>
43
+ <QuestionTooltip {...labelTooltip} />
44
+ </div>
45
+ )}
46
+ </div>
47
+ )}
48
+
49
+ {caption && (
50
+ <div className={styles.caption} data-test-id={TEST_IDS.caption}>
51
+ {caption}
52
+ </div>
53
+ )}
54
+ </div>
55
+ );
56
+ }
57
+
58
+ withInnerRefSupport(Label);
@@ -0,0 +1 @@
1
+ export * from './Label';
@@ -0,0 +1,98 @@
1
+ @use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
2
+ @use '@cloud-ru/ds-figma-variables/build/scss/components/labelDecorator.module' as labelDecorator;
3
+
4
+ $sizes: 's', 'm', 'l';
5
+
6
+ $labelTypography: (
7
+ 's': base.$sn-regular-label-s,
8
+ 'm': base.$sn-regular-label-m,
9
+ 'l': base.$sn-regular-label-l,
10
+ );
11
+
12
+ $captionTypography: (
13
+ 's': base.$sn-thin-label-s,
14
+ 'm': base.$sn-thin-label-m,
15
+ 'l': base.$sn-thin-label-l,
16
+ );
17
+
18
+ .labelWrapper {
19
+ display: flex;
20
+ align-items: center;
21
+ align-self: stretch;
22
+
23
+ width: 100%;
24
+ min-width: 0;
25
+
26
+ .labelContent {
27
+ display: flex;
28
+ align-items: center;
29
+ min-width: 0;
30
+ }
31
+
32
+ // Длинный заголовок усекается многоточием (паритет с легаси `TruncateString`),
33
+ // а не переносится/распирает строку с caption.
34
+ .label {
35
+ overflow: hidden;
36
+ color: base.$sn-theme-color-available-version-textSecondary;
37
+ text-overflow: ellipsis;
38
+ white-space: nowrap;
39
+ }
40
+
41
+ .required {
42
+ color: base.$sn-theme-color-red-text;
43
+ }
44
+
45
+ .labelTooltip {
46
+ display: flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ }
50
+
51
+ .caption {
52
+ overflow: hidden;
53
+ flex: 1 0 0;
54
+
55
+ color: base.$sn-theme-color-available-version-textTertiary;
56
+ text-align: right;
57
+ text-overflow: ellipsis;
58
+ white-space: nowrap;
59
+ }
60
+
61
+ @each $size in $sizes {
62
+ &[data-size='#{$size}'] {
63
+ gap: base.simple-var(labelDecorator.$labelDecorator, 'size', $size, 'labelWrapper', 'gap');
64
+
65
+ .labelContent {
66
+ gap: base.simple-var(labelDecorator.$labelDecorator, 'size', $size, 'labelWrapper', 'labelContent', 'gap');
67
+ }
68
+
69
+ .labelTooltip {
70
+ max-height: base.simple-var(
71
+ labelDecorator.$labelDecorator,
72
+ 'size',
73
+ $size,
74
+ 'labelWrapper',
75
+ 'questionTooltipWrapper',
76
+ 'max-height'
77
+ );
78
+ }
79
+
80
+ .label,
81
+ .required {
82
+ @include base.composite-var($labelTypography, $size);
83
+ }
84
+
85
+ .caption {
86
+ @include base.composite-var($captionTypography, $size);
87
+ }
88
+ }
89
+ }
90
+
91
+ &[data-disabled='true'] {
92
+ .label,
93
+ .required,
94
+ .caption {
95
+ color: base.$sn-theme-color-available-version-textDisabled;
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,3 @@
1
+ export * from './FieldDecorator';
2
+ export * from './Hint';
3
+ export * from './Label';
@@ -0,0 +1,22 @@
1
+ export const SIZE = {
2
+ S: 's',
3
+ M: 'm',
4
+ L: 'l',
5
+ } as const;
6
+
7
+ export const VALIDATION_STATE = {
8
+ Default: 'default',
9
+ Error: 'error',
10
+ Warning: 'warning',
11
+ Success: 'success',
12
+ } as const;
13
+
14
+ export const TEST_IDS = {
15
+ fieldDecorator: 'field-decorator',
16
+ label: 'field-decorator__label',
17
+ required: 'field-decorator__required-sign',
18
+ labelTooltip: 'field-decorator__label-tooltip',
19
+ caption: 'field-decorator__caption',
20
+ hint: 'field-decorator__hint',
21
+ counter: 'field-decorator__counter',
22
+ } as const;
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export * from './constants';
3
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,101 @@
1
+ import { QuestionTooltipProps } from '@cloud-ru/ds-tooltip';
2
+ import { ValueOf, WithSupportProps } from '@cloud-ru/ds-utils';
3
+ import { ReactNode, Ref } from 'react';
4
+
5
+ import { SIZE, VALIDATION_STATE } from './constants';
6
+
7
+ export type Size = ValueOf<typeof SIZE>;
8
+ export type ValidationState = ValueOf<typeof VALIDATION_STATE>;
9
+
10
+ export type FieldLength = {
11
+ /** Текущая длина текста */
12
+ current: number;
13
+ /** Максимально допустимая длина */
14
+ max?: number;
15
+ };
16
+
17
+ export type LabelProps = WithSupportProps<{
18
+ /** CSS-класс */
19
+ className?: string;
20
+ /** Ref на корневой DOM-элемент */
21
+ innerRef?: Ref<HTMLDivElement>;
22
+ /** Заголовок */
23
+ label?: string;
24
+ /** Подсказка (question-tooltip) у заголовка */
25
+ labelTooltip?: QuestionTooltipProps;
26
+ /** Вторичная подпись справа */
27
+ caption?: string;
28
+ /** Показать знак обязательности `*` */
29
+ required?: boolean;
30
+ /** Размер */
31
+ size?: Size;
32
+ /** HTML-атрибут `for` для `<label>` */
33
+ labelFor?: string;
34
+ /** Поле выключено */
35
+ disabled?: boolean;
36
+ }>;
37
+
38
+ export type HintProps = WithSupportProps<{
39
+ /** CSS-класс */
40
+ className?: string;
41
+ /** Ref на корневой DOM-элемент */
42
+ innerRef?: Ref<HTMLDivElement>;
43
+ /** Подсказка */
44
+ hint?: string;
45
+ /** Ошибка (приоритетнее `hint`; форсит `validationState=error`) */
46
+ error?: string;
47
+ /** Состояние валидации */
48
+ validationState?: ValidationState;
49
+ /** Отображение статус-иконки у подсказки (по умолчанию `true`) */
50
+ showHintIcon?: boolean;
51
+ /** Счётчик длины `current/max` */
52
+ length?: FieldLength;
53
+ /**
54
+ * Обрезать подсказку до N строк многоточием (через `TruncateString`, с тултипом
55
+ * полного текста на ховере). Без значения подсказка переносится без ограничения
56
+ * (дефолт поля). Нужно для карточек фиксированной высоты (`@cloud-ru/ds-attachment`), где
57
+ * длинный текст ошибки иначе выходит за границы.
58
+ */
59
+ maxLines?: number;
60
+ /** Размер */
61
+ size?: Size;
62
+ /** Поле выключено */
63
+ disabled?: boolean;
64
+ /** Только для чтения */
65
+ readonly?: boolean;
66
+ }>;
67
+
68
+ export type FieldDecoratorProps = WithSupportProps<{
69
+ /** CSS-класс */
70
+ className?: string;
71
+ /** Ref на корневой DOM-элемент */
72
+ innerRef?: Ref<HTMLDivElement>;
73
+ /** Содержимое (декорируемое поле) */
74
+ children: ReactNode;
75
+ /** Заголовок */
76
+ label?: string;
77
+ /** Подсказка (question-tooltip) у заголовка */
78
+ labelTooltip?: QuestionTooltipProps;
79
+ /** Вторичная подпись справа */
80
+ caption?: string;
81
+ /** Показать знак обязательности `*` */
82
+ required?: boolean;
83
+ /** HTML-атрибут `for` для `<label>` */
84
+ labelFor?: string;
85
+ /** Подсказка */
86
+ hint?: string;
87
+ /** Ошибка (приоритетнее `hint`; форсит `validationState=error`) */
88
+ error?: string;
89
+ /** Состояние валидации */
90
+ validationState?: ValidationState;
91
+ /** Отображение статус-иконки у подсказки (по умолчанию `true`) */
92
+ showHintIcon?: boolean;
93
+ /** Счётчик длины `current/max` */
94
+ length?: FieldLength;
95
+ /** Размер */
96
+ size?: Size;
97
+ /** Поле выключено */
98
+ disabled?: boolean;
99
+ /** Только для чтения */
100
+ readonly?: boolean;
101
+ }>;