@snack-uikit/fields 0.53.2-preview-0a70077b.0 → 0.54.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 (70) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +28 -130
  3. package/dist/cjs/components/FieldSecure/FieldSecure.d.ts +1 -1
  4. package/dist/cjs/components/FieldSelect/FieldSelectMultiple.d.ts +3 -1
  5. package/dist/cjs/components/FieldSelect/FieldSelectMultiple.js +28 -7
  6. package/dist/cjs/components/FieldSelect/FieldSelectSingle.d.ts +3 -1
  7. package/dist/cjs/components/FieldSelect/FieldSelectSingle.js +25 -12
  8. package/dist/cjs/components/FieldSelect/{hooks.d.ts → hooks/common.d.ts} +1 -1
  9. package/dist/cjs/components/FieldSelect/{hooks.js → hooks/common.js} +4 -5
  10. package/dist/cjs/components/FieldSelect/hooks/customOption.d.ts +26 -0
  11. package/dist/cjs/components/FieldSelect/hooks/customOption.js +69 -0
  12. package/dist/cjs/components/FieldSelect/hooks/index.d.ts +2 -0
  13. package/dist/cjs/components/FieldSelect/hooks/index.js +26 -0
  14. package/dist/cjs/components/FieldSelect/index.d.ts +1 -1
  15. package/dist/cjs/components/FieldSelect/types.d.ts +20 -3
  16. package/dist/cjs/components/FieldSelect/utils/customOption.d.ts +4 -0
  17. package/dist/cjs/components/FieldSelect/utils/customOption.js +21 -0
  18. package/dist/cjs/components/FieldSelect/utils/index.d.ts +2 -0
  19. package/dist/cjs/components/FieldSelect/utils/index.js +3 -1
  20. package/dist/cjs/components/FieldText/FieldText.d.ts +1 -1
  21. package/dist/cjs/components/FieldTextArea/FieldTextArea.d.ts +1 -1
  22. package/dist/cjs/components/index.d.ts +0 -1
  23. package/dist/cjs/components/index.js +0 -1
  24. package/dist/cjs/helperComponents/ButtonFieldList/ButtonFieldList.d.ts +1 -1
  25. package/dist/esm/components/FieldSecure/FieldSecure.d.ts +1 -1
  26. package/dist/esm/components/FieldSelect/FieldSelectMultiple.d.ts +3 -1
  27. package/dist/esm/components/FieldSelect/FieldSelectMultiple.js +27 -9
  28. package/dist/esm/components/FieldSelect/FieldSelectSingle.d.ts +3 -1
  29. package/dist/esm/components/FieldSelect/FieldSelectSingle.js +24 -14
  30. package/dist/esm/components/FieldSelect/{hooks.d.ts → hooks/common.d.ts} +1 -1
  31. package/dist/esm/components/FieldSelect/{hooks.js → hooks/common.js} +3 -4
  32. package/dist/esm/components/FieldSelect/hooks/customOption.d.ts +26 -0
  33. package/dist/esm/components/FieldSelect/hooks/customOption.js +38 -0
  34. package/dist/esm/components/FieldSelect/hooks/index.d.ts +2 -0
  35. package/dist/esm/components/FieldSelect/hooks/index.js +2 -0
  36. package/dist/esm/components/FieldSelect/index.d.ts +1 -1
  37. package/dist/esm/components/FieldSelect/types.d.ts +20 -3
  38. package/dist/esm/components/FieldSelect/utils/customOption.d.ts +4 -0
  39. package/dist/esm/components/FieldSelect/utils/customOption.js +13 -0
  40. package/dist/esm/components/FieldSelect/utils/index.d.ts +2 -0
  41. package/dist/esm/components/FieldSelect/utils/index.js +2 -0
  42. package/dist/esm/components/FieldText/FieldText.d.ts +1 -1
  43. package/dist/esm/components/FieldTextArea/FieldTextArea.d.ts +1 -1
  44. package/dist/esm/components/index.d.ts +0 -1
  45. package/dist/esm/components/index.js +0 -1
  46. package/dist/esm/helperComponents/ButtonFieldList/ButtonFieldList.d.ts +1 -1
  47. package/package.json +2 -2
  48. package/src/components/FieldSelect/FieldSelectMultiple.tsx +55 -10
  49. package/src/components/FieldSelect/FieldSelectSingle.tsx +33 -15
  50. package/src/components/FieldSelect/{hooks.ts → hooks/common.ts} +4 -5
  51. package/src/components/FieldSelect/hooks/customOption.ts +90 -0
  52. package/src/components/FieldSelect/hooks/index.ts +2 -0
  53. package/src/components/FieldSelect/index.ts +2 -0
  54. package/src/components/FieldSelect/types.ts +24 -3
  55. package/src/components/FieldSelect/utils/customOption.ts +23 -0
  56. package/src/components/FieldSelect/utils/index.ts +2 -0
  57. package/src/components/index.ts +0 -1
  58. package/dist/cjs/components/FieldAdd/FieldAdd.d.ts +0 -52
  59. package/dist/cjs/components/FieldAdd/FieldAdd.js +0 -216
  60. package/dist/cjs/components/FieldAdd/index.d.ts +0 -2
  61. package/dist/cjs/components/FieldAdd/index.js +0 -13
  62. package/dist/cjs/components/FieldAdd/styles.module.css +0 -51
  63. package/dist/esm/components/FieldAdd/FieldAdd.d.ts +0 -52
  64. package/dist/esm/components/FieldAdd/FieldAdd.js +0 -31
  65. package/dist/esm/components/FieldAdd/index.d.ts +0 -2
  66. package/dist/esm/components/FieldAdd/index.js +0 -1
  67. package/dist/esm/components/FieldAdd/styles.module.css +0 -51
  68. package/src/components/FieldAdd/FieldAdd.tsx +0 -215
  69. package/src/components/FieldAdd/index.ts +0 -3
  70. package/src/components/FieldAdd/styles.module.scss +0 -60
@@ -1,216 +0,0 @@
1
- "use strict";
2
-
3
- var __rest = void 0 && (void 0).__rest || function (s, e) {
4
- var t = {};
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8
- }
9
- return t;
10
- };
11
- var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
12
- return mod && mod.__esModule ? mod : {
13
- "default": mod
14
- };
15
- };
16
- Object.defineProperty(exports, "__esModule", {
17
- value: true
18
- });
19
- exports.FieldAdd = void 0;
20
- const jsx_runtime_1 = require("react/jsx-runtime");
21
- const classnames_1 = __importDefault(require("classnames"));
22
- const react_1 = require("react");
23
- const button_1 = require("@snack-uikit/button");
24
- const icons_1 = require("@snack-uikit/icons");
25
- const skeleton_1 = require("@snack-uikit/skeleton");
26
- const tooltip_1 = require("@snack-uikit/tooltip");
27
- const utils_1 = require("@snack-uikit/utils");
28
- const FieldDecorator_1 = require("../FieldDecorator");
29
- const FieldSelect_1 = require("../FieldSelect");
30
- const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
31
- const DEFAULT_ADD_BUTTON_LABEL = 'Create';
32
- exports.FieldAdd = (0, react_1.forwardRef)((_a, ref) => {
33
- var {
34
- id,
35
- name,
36
- placeholder,
37
- size = 's',
38
- options,
39
- value,
40
- defaultValue,
41
- onChange,
42
- disabled = false,
43
- readonly = false,
44
- searchable = true,
45
- showCopyButton = true,
46
- showClearButton = true,
47
- onKeyDown,
48
- required = false,
49
- validationState = 'default',
50
- search,
51
- autocomplete = false,
52
- prefixIcon,
53
- prefix,
54
- postfix,
55
- addOptionByEnter = false,
56
- untouchableScrollbars = false,
57
- open,
58
- onOpenChange,
59
- selectedOptionFormatter,
60
- enableFuzzySearch = true,
61
- resetSearchOnOptionSelection = true,
62
- onCopyButtonClick,
63
- autoFocus,
64
- onFocus,
65
- onBlur,
66
- pinTop,
67
- pinBottom,
68
- footer,
69
- widthStrategy,
70
- dataError,
71
- noDataState,
72
- noResultsState,
73
- errorDataState,
74
- dataFiltered,
75
- loading = false,
76
- scrollToSelectedItem,
77
- virtualized,
78
- scrollRef,
79
- scrollContainerRef,
80
- onScroll,
81
- className,
82
- label,
83
- labelTooltip,
84
- caption,
85
- hint,
86
- showHintIcon,
87
- labelTooltipPlacement,
88
- error,
89
- addButton,
90
- controlTooltip,
91
- showAddButton = !readonly
92
- } = _a,
93
- rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showCopyButton", "showClearButton", "onKeyDown", "required", "validationState", "search", "autocomplete", "prefixIcon", "prefix", "postfix", "addOptionByEnter", "untouchableScrollbars", "open", "onOpenChange", "selectedOptionFormatter", "enableFuzzySearch", "resetSearchOnOptionSelection", "onCopyButtonClick", "autoFocus", "onFocus", "onBlur", "pinTop", "pinBottom", "footer", "widthStrategy", "dataError", "noDataState", "noResultsState", "errorDataState", "dataFiltered", "loading", "scrollToSelectedItem", "virtualized", "scrollRef", "scrollContainerRef", "onScroll", "className", "label", "labelTooltip", "caption", "hint", "showHintIcon", "labelTooltipPlacement", "error", "addButton", "controlTooltip", "showAddButton"]);
94
- const _b = addButton !== null && addButton !== void 0 ? addButton : {},
95
- {
96
- label: addButtonLabel = DEFAULT_ADD_BUTTON_LABEL,
97
- tooltip: addButtonTooltipProp,
98
- className: addButtonClassName,
99
- disabled: addButtonDisabled = false,
100
- 'aria-label': addButtonAriaLabel,
101
- 'data-test-id': addButtonTestId
102
- } = _b,
103
- addButtonProps = __rest(_b, ["label", "tooltip", "className", "disabled", 'aria-label', 'data-test-id']);
104
- const shouldShowAddButton = showAddButton && !readonly;
105
- const isAddButtonDisabled = disabled || loading || addButtonDisabled;
106
- const addButtonTooltip = addButtonTooltipProp !== null && addButtonTooltipProp !== void 0 ? addButtonTooltipProp : !isAddButtonDisabled ? {
107
- tip: addButtonLabel
108
- } : undefined;
109
- return (0, jsx_runtime_1.jsx)(FieldDecorator_1.FieldDecorator, Object.assign({
110
- className: className,
111
- label: label,
112
- labelTooltip: labelTooltip,
113
- labelTooltipPlacement: labelTooltipPlacement,
114
- labelFor: id,
115
- required: required,
116
- caption: caption,
117
- hint: hint,
118
- disabled: disabled,
119
- readonly: readonly,
120
- showHintIcon: showHintIcon,
121
- size: size,
122
- validationState: validationState,
123
- error: error
124
- }, (0, utils_1.extractSupportProps)(rest), {
125
- children: (0, jsx_runtime_1.jsxs)("div", {
126
- className: styles_module_scss_1.default.layout,
127
- "data-size": size,
128
- children: [(0, jsx_runtime_1.jsx)(tooltip_1.WithTooltip, {
129
- tooltip: controlTooltip,
130
- children: (0, jsx_runtime_1.jsx)("div", {
131
- className: styles_module_scss_1.default.selectTooltipTrigger,
132
- "data-test-id": 'field-add__control',
133
- children: (0, jsx_runtime_1.jsxs)("div", {
134
- className: styles_module_scss_1.default.selectWrapper,
135
- children: [(0, jsx_runtime_1.jsx)(FieldSelect_1.FieldSelect, {
136
- id: id,
137
- name: name,
138
- placeholder: loading ? '' : placeholder,
139
- size: size,
140
- options: options,
141
- value: value,
142
- defaultValue: defaultValue,
143
- onChange: onChange,
144
- disabled: disabled || loading,
145
- readonly: readonly,
146
- searchable: loading || readonly ? false : searchable,
147
- showCopyButton: showCopyButton && !loading,
148
- showClearButton: showClearButton && !loading,
149
- onKeyDown: onKeyDown,
150
- required: required,
151
- validationState: validationState,
152
- search: search,
153
- autocomplete: autocomplete,
154
- prefixIcon: prefixIcon,
155
- prefix: prefix,
156
- postfix: postfix,
157
- addOptionByEnter: addOptionByEnter,
158
- untouchableScrollbars: untouchableScrollbars,
159
- open: loading ? false : open,
160
- onOpenChange: onOpenChange,
161
- selectedOptionFormatter: selectedOptionFormatter,
162
- enableFuzzySearch: enableFuzzySearch,
163
- resetSearchOnOptionSelection: resetSearchOnOptionSelection,
164
- onCopyButtonClick: onCopyButtonClick,
165
- autoFocus: autoFocus,
166
- onFocus: onFocus,
167
- onBlur: onBlur,
168
- pinTop: pinTop,
169
- pinBottom: pinBottom,
170
- footer: footer,
171
- widthStrategy: widthStrategy,
172
- dataError: dataError,
173
- noDataState: noDataState,
174
- noResultsState: noResultsState,
175
- errorDataState: errorDataState,
176
- dataFiltered: dataFiltered,
177
- loading: loading,
178
- scrollToSelectedItem: scrollToSelectedItem,
179
- virtualized: virtualized,
180
- scrollRef: scrollRef,
181
- scrollContainerRef: scrollContainerRef,
182
- onScroll: onScroll,
183
- className: styles_module_scss_1.default.fieldSelect,
184
- selection: 'single',
185
- ref: ref
186
- }), loading && (0, jsx_runtime_1.jsx)("div", {
187
- className: styles_module_scss_1.default.loadingOverlay,
188
- "data-test-id": 'field-add__loading',
189
- children: (0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, {
190
- className: styles_module_scss_1.default.loadingSkeleton,
191
- width: '100%',
192
- height: '100%',
193
- borderRadius: 2,
194
- loading: true
195
- })
196
- })]
197
- })
198
- })
199
- }), shouldShowAddButton && (0, jsx_runtime_1.jsx)(tooltip_1.WithTooltip, {
200
- tooltip: addButtonTooltip,
201
- children: (0, jsx_runtime_1.jsx)("span", {
202
- className: styles_module_scss_1.default.buttonTooltipTrigger,
203
- children: (0, jsx_runtime_1.jsx)(button_1.ButtonOutline, Object.assign({}, addButtonProps, {
204
- appearance: 'neutral',
205
- size: size,
206
- icon: (0, jsx_runtime_1.jsx)(icons_1.PlusSVG, {}),
207
- className: (0, classnames_1.default)(styles_module_scss_1.default.addButton, addButtonClassName),
208
- disabled: isAddButtonDisabled,
209
- "aria-label": addButtonAriaLabel || addButtonLabel,
210
- "data-test-id": addButtonTestId || 'field-add__button'
211
- }))
212
- })
213
- })]
214
- })
215
- }));
216
- });
@@ -1,2 +0,0 @@
1
- export { FieldAdd } from './FieldAdd';
2
- export type { FieldAddButtonProps, FieldAddProps } from './FieldAdd';
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FieldAdd = void 0;
7
- var FieldAdd_1 = require("./FieldAdd");
8
- Object.defineProperty(exports, "FieldAdd", {
9
- enumerable: true,
10
- get: function () {
11
- return FieldAdd_1.FieldAdd;
12
- }
13
- });
@@ -1,51 +0,0 @@
1
- .layout{
2
- display:flex;
3
- gap:var(--dimension-050m, 4px);
4
- align-items:flex-start;
5
- width:100%;
6
- }
7
-
8
- .selectTooltipTrigger,
9
- .selectWrapper,
10
- .fieldSelect{
11
- width:100%;
12
- }
13
-
14
- .selectTooltipTrigger{
15
- min-width:0;
16
- }
17
-
18
- .selectWrapper{
19
- position:relative;
20
- }
21
-
22
- .loadingOverlay{
23
- pointer-events:none;
24
- position:absolute;
25
- inset:0;
26
- display:flex;
27
- align-items:center;
28
- width:100%;
29
- }
30
-
31
- .loadingSkeleton{
32
- margin-right:36px;
33
- margin-left:16px;
34
- }
35
-
36
- .buttonTooltipTrigger{
37
- display:inline-flex;
38
- flex-shrink:0;
39
- }
40
-
41
- .addButton{
42
- flex-shrink:0;
43
- }
44
-
45
- .layout[data-size=m] .loadingSkeleton{
46
- margin-right:40px;
47
- }
48
-
49
- .layout[data-size=l] .loadingSkeleton{
50
- margin-right:44px;
51
- }
@@ -1,52 +0,0 @@
1
- import { ButtonOutlineProps } from '@snack-uikit/button';
2
- import { TooltipProps } from '@snack-uikit/tooltip';
3
- import { FieldSelectSingleProps } from '../FieldSelect';
4
- export type FieldAddButtonProps = Omit<ButtonOutlineProps, 'appearance' | 'icon' | 'size' | 'label'> & {
5
- /** Текст действия для кнопки добавления; используется как fallback для `tooltip.tip` и `aria-label` */
6
- label?: string;
7
- /** Тултип кнопки добавления */
8
- tooltip?: Omit<TooltipProps, 'children'>;
9
- };
10
- export type FieldAddProps = FieldSelectSingleProps & {
11
- /** Настройки кнопки добавления справа от поля */
12
- addButton?: FieldAddButtonProps;
13
- /** Тултип над контролом выбора значения */
14
- controlTooltip?: Omit<TooltipProps, 'children'>;
15
- /** Показывать ли кнопку добавления; в `readonly` режиме кнопка скрывается независимо от значения пропса */
16
- showAddButton?: boolean;
17
- };
18
- export declare const FieldAdd: import("react").ForwardRefExoticComponent<import("../FieldSelect/types").InputProps & import("../FieldSelect/types").WrapperProps & {
19
- options: import("../FieldSelect").OptionProps[];
20
- loading?: boolean;
21
- prefix?: import("react").ReactNode;
22
- postfix?: import("react").ReactNode;
23
- } & Omit<import("@snack-uikit/list").SelectionSingleState, "mode"> & {
24
- 'data-test-id'?: string;
25
- } & import("react").AriaAttributes & {
26
- options: import("../FieldSelect").OptionProps[];
27
- pinTop?: import("../FieldSelect").OptionProps[];
28
- pinBottom?: import("../FieldSelect").OptionProps[];
29
- searchable?: boolean;
30
- showCopyButton?: boolean;
31
- onCopyButtonClick?(): void;
32
- showClearButton?: boolean;
33
- readonly?: boolean;
34
- prefixIcon?: import("react").ReactElement;
35
- footer?: import("@snack-uikit/list").DroplistProps["footer"];
36
- widthStrategy?: import("@snack-uikit/list").DroplistProps["widthStrategy"];
37
- search?: import("../FieldSelect/types").SearchState;
38
- autocomplete?: boolean;
39
- addOptionByEnter?: boolean;
40
- open?: boolean;
41
- enableFuzzySearch?: boolean;
42
- resetSearchOnOptionSelection?: boolean;
43
- onOpenChange?(open: boolean): void;
44
- selectedOptionFormatter?: import("../FieldSelect").SelectedOptionFormatter;
45
- } & Pick<import("@snack-uikit/list").DroplistProps, "onScroll" | "scrollRef" | "scrollContainerRef" | "untouchableScrollbars" | "dataError" | "dataFiltered" | "scrollToSelectedItem" | "virtualized" | "noDataState" | "noResultsState" | "errorDataState"> & {
46
- /** Настройки кнопки добавления справа от поля */
47
- addButton?: FieldAddButtonProps;
48
- /** Тултип над контролом выбора значения */
49
- controlTooltip?: Omit<TooltipProps, "children">;
50
- /** Показывать ли кнопку добавления; в `readonly` режиме кнопка скрывается независимо от значения пропса */
51
- showAddButton?: boolean;
52
- } & import("react").RefAttributes<HTMLInputElement>>;
@@ -1,31 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import cn from 'classnames';
14
- import { forwardRef } from 'react';
15
- import { ButtonOutline } from '@snack-uikit/button';
16
- import { PlusSVG } from '@snack-uikit/icons';
17
- import { Skeleton } from '@snack-uikit/skeleton';
18
- import { WithTooltip } from '@snack-uikit/tooltip';
19
- import { extractSupportProps } from '@snack-uikit/utils';
20
- import { FieldDecorator } from '../FieldDecorator';
21
- import { FieldSelect } from '../FieldSelect';
22
- import styles from './styles.module.css';
23
- const DEFAULT_ADD_BUTTON_LABEL = 'Create';
24
- export const FieldAdd = forwardRef((_a, ref) => {
25
- var { id, name, placeholder, size = 's', options, value, defaultValue, onChange, disabled = false, readonly = false, searchable = true, showCopyButton = true, showClearButton = true, onKeyDown, required = false, validationState = 'default', search, autocomplete = false, prefixIcon, prefix, postfix, addOptionByEnter = false, untouchableScrollbars = false, open, onOpenChange, selectedOptionFormatter, enableFuzzySearch = true, resetSearchOnOptionSelection = true, onCopyButtonClick, autoFocus, onFocus, onBlur, pinTop, pinBottom, footer, widthStrategy, dataError, noDataState, noResultsState, errorDataState, dataFiltered, loading = false, scrollToSelectedItem, virtualized, scrollRef, scrollContainerRef, onScroll, className, label, labelTooltip, caption, hint, showHintIcon, labelTooltipPlacement, error, addButton, controlTooltip, showAddButton = !readonly } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showCopyButton", "showClearButton", "onKeyDown", "required", "validationState", "search", "autocomplete", "prefixIcon", "prefix", "postfix", "addOptionByEnter", "untouchableScrollbars", "open", "onOpenChange", "selectedOptionFormatter", "enableFuzzySearch", "resetSearchOnOptionSelection", "onCopyButtonClick", "autoFocus", "onFocus", "onBlur", "pinTop", "pinBottom", "footer", "widthStrategy", "dataError", "noDataState", "noResultsState", "errorDataState", "dataFiltered", "loading", "scrollToSelectedItem", "virtualized", "scrollRef", "scrollContainerRef", "onScroll", "className", "label", "labelTooltip", "caption", "hint", "showHintIcon", "labelTooltipPlacement", "error", "addButton", "controlTooltip", "showAddButton"]);
26
- const _b = addButton !== null && addButton !== void 0 ? addButton : {}, { label: addButtonLabel = DEFAULT_ADD_BUTTON_LABEL, tooltip: addButtonTooltipProp, className: addButtonClassName, disabled: addButtonDisabled = false, 'aria-label': addButtonAriaLabel, 'data-test-id': addButtonTestId } = _b, addButtonProps = __rest(_b, ["label", "tooltip", "className", "disabled", 'aria-label', 'data-test-id']);
27
- const shouldShowAddButton = showAddButton && !readonly;
28
- const isAddButtonDisabled = disabled || loading || addButtonDisabled;
29
- const addButtonTooltip = addButtonTooltipProp !== null && addButtonTooltipProp !== void 0 ? addButtonTooltipProp : (!isAddButtonDisabled ? { tip: addButtonLabel } : undefined);
30
- return (_jsx(FieldDecorator, Object.assign({ className: className, label: label, labelTooltip: labelTooltip, labelTooltipPlacement: labelTooltipPlacement, labelFor: id, required: required, caption: caption, hint: hint, disabled: disabled, readonly: readonly, showHintIcon: showHintIcon, size: size, validationState: validationState, error: error }, extractSupportProps(rest), { children: _jsxs("div", { className: styles.layout, "data-size": size, children: [_jsx(WithTooltip, { tooltip: controlTooltip, children: _jsx("div", { className: styles.selectTooltipTrigger, "data-test-id": 'field-add__control', children: _jsxs("div", { className: styles.selectWrapper, children: [_jsx(FieldSelect, { id: id, name: name, placeholder: loading ? '' : placeholder, size: size, options: options, value: value, defaultValue: defaultValue, onChange: onChange, disabled: disabled || loading, readonly: readonly, searchable: loading || readonly ? false : searchable, showCopyButton: showCopyButton && !loading, showClearButton: showClearButton && !loading, onKeyDown: onKeyDown, required: required, validationState: validationState, search: search, autocomplete: autocomplete, prefixIcon: prefixIcon, prefix: prefix, postfix: postfix, addOptionByEnter: addOptionByEnter, untouchableScrollbars: untouchableScrollbars, open: loading ? false : open, onOpenChange: onOpenChange, selectedOptionFormatter: selectedOptionFormatter, enableFuzzySearch: enableFuzzySearch, resetSearchOnOptionSelection: resetSearchOnOptionSelection, onCopyButtonClick: onCopyButtonClick, autoFocus: autoFocus, onFocus: onFocus, onBlur: onBlur, pinTop: pinTop, pinBottom: pinBottom, footer: footer, widthStrategy: widthStrategy, dataError: dataError, noDataState: noDataState, noResultsState: noResultsState, errorDataState: errorDataState, dataFiltered: dataFiltered, loading: loading, scrollToSelectedItem: scrollToSelectedItem, virtualized: virtualized, scrollRef: scrollRef, scrollContainerRef: scrollContainerRef, onScroll: onScroll, className: styles.fieldSelect, selection: 'single', ref: ref }), loading && (_jsx("div", { className: styles.loadingOverlay, "data-test-id": 'field-add__loading', children: _jsx(Skeleton, { className: styles.loadingSkeleton, width: '100%', height: '100%', borderRadius: 2, loading: true }) }))] }) }) }), shouldShowAddButton && (_jsx(WithTooltip, { tooltip: addButtonTooltip, children: _jsx("span", { className: styles.buttonTooltipTrigger, children: _jsx(ButtonOutline, Object.assign({}, addButtonProps, { appearance: 'neutral', size: size, icon: _jsx(PlusSVG, {}), className: cn(styles.addButton, addButtonClassName), disabled: isAddButtonDisabled, "aria-label": addButtonAriaLabel || addButtonLabel, "data-test-id": addButtonTestId || 'field-add__button' })) }) }))] }) })));
31
- });
@@ -1,2 +0,0 @@
1
- export { FieldAdd } from './FieldAdd';
2
- export type { FieldAddButtonProps, FieldAddProps } from './FieldAdd';
@@ -1 +0,0 @@
1
- export { FieldAdd } from './FieldAdd';
@@ -1,51 +0,0 @@
1
- .layout{
2
- display:flex;
3
- gap:var(--dimension-050m, 4px);
4
- align-items:flex-start;
5
- width:100%;
6
- }
7
-
8
- .selectTooltipTrigger,
9
- .selectWrapper,
10
- .fieldSelect{
11
- width:100%;
12
- }
13
-
14
- .selectTooltipTrigger{
15
- min-width:0;
16
- }
17
-
18
- .selectWrapper{
19
- position:relative;
20
- }
21
-
22
- .loadingOverlay{
23
- pointer-events:none;
24
- position:absolute;
25
- inset:0;
26
- display:flex;
27
- align-items:center;
28
- width:100%;
29
- }
30
-
31
- .loadingSkeleton{
32
- margin-right:36px;
33
- margin-left:16px;
34
- }
35
-
36
- .buttonTooltipTrigger{
37
- display:inline-flex;
38
- flex-shrink:0;
39
- }
40
-
41
- .addButton{
42
- flex-shrink:0;
43
- }
44
-
45
- .layout[data-size=m] .loadingSkeleton{
46
- margin-right:40px;
47
- }
48
-
49
- .layout[data-size=l] .loadingSkeleton{
50
- margin-right:44px;
51
- }
@@ -1,215 +0,0 @@
1
- import cn from 'classnames';
2
- import { forwardRef } from 'react';
3
-
4
- import { ButtonOutline, ButtonOutlineProps } from '@snack-uikit/button';
5
- import { PlusSVG } from '@snack-uikit/icons';
6
- import { Skeleton } from '@snack-uikit/skeleton';
7
- import { TooltipProps, WithTooltip } from '@snack-uikit/tooltip';
8
- import { extractSupportProps } from '@snack-uikit/utils';
9
-
10
- import { FieldDecorator } from '../FieldDecorator';
11
- import { FieldSelect, FieldSelectSingleProps } from '../FieldSelect';
12
- import styles from './styles.module.scss';
13
-
14
- export type FieldAddButtonProps = Omit<ButtonOutlineProps, 'appearance' | 'icon' | 'size' | 'label'> & {
15
- /** Текст действия для кнопки добавления; используется как fallback для `tooltip.tip` и `aria-label` */
16
- label?: string;
17
- /** Тултип кнопки добавления */
18
- tooltip?: Omit<TooltipProps, 'children'>;
19
- };
20
-
21
- export type FieldAddProps = FieldSelectSingleProps & {
22
- /** Настройки кнопки добавления справа от поля */
23
- addButton?: FieldAddButtonProps;
24
- /** Тултип над контролом выбора значения */
25
- controlTooltip?: Omit<TooltipProps, 'children'>;
26
- /** Показывать ли кнопку добавления; в `readonly` режиме кнопка скрывается независимо от значения пропса */
27
- showAddButton?: boolean;
28
- };
29
-
30
- const DEFAULT_ADD_BUTTON_LABEL = 'Create';
31
-
32
- export const FieldAdd = forwardRef<HTMLInputElement, FieldAddProps>(
33
- (
34
- {
35
- id,
36
- name,
37
- placeholder,
38
- size = 's',
39
- options,
40
- value,
41
- defaultValue,
42
- onChange,
43
- disabled = false,
44
- readonly = false,
45
- searchable = true,
46
- showCopyButton = true,
47
- showClearButton = true,
48
- onKeyDown,
49
- required = false,
50
- validationState = 'default',
51
- search,
52
- autocomplete = false,
53
- prefixIcon,
54
- prefix,
55
- postfix,
56
- addOptionByEnter = false,
57
- untouchableScrollbars = false,
58
- open,
59
- onOpenChange,
60
- selectedOptionFormatter,
61
- enableFuzzySearch = true,
62
- resetSearchOnOptionSelection = true,
63
- onCopyButtonClick,
64
- autoFocus,
65
- onFocus,
66
- onBlur,
67
- pinTop,
68
- pinBottom,
69
- footer,
70
- widthStrategy,
71
- dataError,
72
- noDataState,
73
- noResultsState,
74
- errorDataState,
75
- dataFiltered,
76
- loading = false,
77
- scrollToSelectedItem,
78
- virtualized,
79
- scrollRef,
80
- scrollContainerRef,
81
- onScroll,
82
- className,
83
- label,
84
- labelTooltip,
85
- caption,
86
- hint,
87
- showHintIcon,
88
- labelTooltipPlacement,
89
- error,
90
- addButton,
91
- controlTooltip,
92
- showAddButton = !readonly,
93
- ...rest
94
- },
95
- ref,
96
- ) => {
97
- const {
98
- label: addButtonLabel = DEFAULT_ADD_BUTTON_LABEL,
99
- tooltip: addButtonTooltipProp,
100
- className: addButtonClassName,
101
- disabled: addButtonDisabled = false,
102
- 'aria-label': addButtonAriaLabel,
103
- 'data-test-id': addButtonTestId,
104
- ...addButtonProps
105
- } = addButton ?? {};
106
-
107
- const shouldShowAddButton = showAddButton && !readonly;
108
- const isAddButtonDisabled = disabled || loading || addButtonDisabled;
109
- const addButtonTooltip = addButtonTooltipProp ?? (!isAddButtonDisabled ? { tip: addButtonLabel } : undefined);
110
-
111
- return (
112
- <FieldDecorator
113
- className={className}
114
- label={label}
115
- labelTooltip={labelTooltip}
116
- labelTooltipPlacement={labelTooltipPlacement}
117
- labelFor={id}
118
- required={required}
119
- caption={caption}
120
- hint={hint}
121
- disabled={disabled}
122
- readonly={readonly}
123
- showHintIcon={showHintIcon}
124
- size={size}
125
- validationState={validationState}
126
- error={error}
127
- {...extractSupportProps(rest)}
128
- >
129
- <div className={styles.layout} data-size={size}>
130
- <WithTooltip tooltip={controlTooltip}>
131
- <div className={styles.selectTooltipTrigger} data-test-id='field-add__control'>
132
- <div className={styles.selectWrapper}>
133
- <FieldSelect
134
- id={id}
135
- name={name}
136
- placeholder={loading ? '' : placeholder}
137
- size={size}
138
- options={options}
139
- value={value}
140
- defaultValue={defaultValue}
141
- onChange={onChange}
142
- disabled={disabled || loading}
143
- readonly={readonly}
144
- searchable={loading || readonly ? false : searchable}
145
- showCopyButton={showCopyButton && !loading}
146
- showClearButton={showClearButton && !loading}
147
- onKeyDown={onKeyDown}
148
- required={required}
149
- validationState={validationState}
150
- search={search}
151
- autocomplete={autocomplete}
152
- prefixIcon={prefixIcon}
153
- prefix={prefix}
154
- postfix={postfix}
155
- addOptionByEnter={addOptionByEnter}
156
- untouchableScrollbars={untouchableScrollbars}
157
- open={loading ? false : open}
158
- onOpenChange={onOpenChange}
159
- selectedOptionFormatter={selectedOptionFormatter}
160
- enableFuzzySearch={enableFuzzySearch}
161
- resetSearchOnOptionSelection={resetSearchOnOptionSelection}
162
- onCopyButtonClick={onCopyButtonClick}
163
- autoFocus={autoFocus}
164
- onFocus={onFocus}
165
- onBlur={onBlur}
166
- pinTop={pinTop}
167
- pinBottom={pinBottom}
168
- footer={footer}
169
- widthStrategy={widthStrategy}
170
- dataError={dataError}
171
- noDataState={noDataState}
172
- noResultsState={noResultsState}
173
- errorDataState={errorDataState}
174
- dataFiltered={dataFiltered}
175
- loading={loading}
176
- scrollToSelectedItem={scrollToSelectedItem}
177
- virtualized={virtualized}
178
- scrollRef={scrollRef}
179
- scrollContainerRef={scrollContainerRef}
180
- onScroll={onScroll}
181
- className={styles.fieldSelect}
182
- selection='single'
183
- ref={ref}
184
- />
185
-
186
- {loading && (
187
- <div className={styles.loadingOverlay} data-test-id='field-add__loading'>
188
- <Skeleton className={styles.loadingSkeleton} width='100%' height='100%' borderRadius={2} loading />
189
- </div>
190
- )}
191
- </div>
192
- </div>
193
- </WithTooltip>
194
-
195
- {shouldShowAddButton && (
196
- <WithTooltip tooltip={addButtonTooltip}>
197
- <span className={styles.buttonTooltipTrigger}>
198
- <ButtonOutline
199
- {...addButtonProps}
200
- appearance='neutral'
201
- size={size}
202
- icon={<PlusSVG />}
203
- className={cn(styles.addButton, addButtonClassName)}
204
- disabled={isAddButtonDisabled}
205
- aria-label={addButtonAriaLabel || addButtonLabel}
206
- data-test-id={addButtonTestId || 'field-add__button'}
207
- />
208
- </span>
209
- </WithTooltip>
210
- )}
211
- </div>
212
- </FieldDecorator>
213
- );
214
- },
215
- );
@@ -1,3 +0,0 @@
1
- export { FieldAdd } from './FieldAdd';
2
-
3
- export type { FieldAddButtonProps, FieldAddProps } from './FieldAdd';