@invoicebox/ui 0.1.0-alpha.239 → 0.1.0-alpha.241
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/dist/components/form/TagsInput/index.d.ts +1 -0
- package/dist/components/form/TagsInput/index.js +43 -32
- package/dist/components/form/TagsInput/index.stories.js +2 -1
- package/dist/components/form/TagsInput/styles.d.ts +2 -1
- package/dist/components/form/TagsInput/styles.js +12 -8
- package/package.json +1 -1
|
@@ -35,7 +35,8 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
35
35
|
label = _ref.label,
|
|
36
36
|
value = _ref.value,
|
|
37
37
|
onChange = _ref.onChange,
|
|
38
|
-
palette = _ref.palette
|
|
38
|
+
palette = _ref.palette,
|
|
39
|
+
saveLabel = _ref.saveLabel;
|
|
39
40
|
var newValueAutofillIntervalRef = (0, _react.useRef)(null);
|
|
40
41
|
var _useState = (0, _react.useState)(''),
|
|
41
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -60,30 +61,26 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
60
61
|
onChange(value !== null && value !== void 0 && value.includes(newValue) ? value : [].concat(_toConsumableArray(value ? value : []), [newValue]));
|
|
61
62
|
setInputValue('');
|
|
62
63
|
};
|
|
64
|
+
var acceptValueByTimeout = function acceptValueByTimeout(newValue) {
|
|
65
|
+
newValueAutofillIntervalRef.current = setTimeout(function () {
|
|
66
|
+
acceptNewValue(newValue);
|
|
67
|
+
}, 3000);
|
|
68
|
+
};
|
|
63
69
|
var handleChange = function handleChange(event) {
|
|
64
70
|
setInputValue(event.target.value);
|
|
65
71
|
clearNewValueAutofillInterval();
|
|
66
72
|
if (event.target.value) {
|
|
67
|
-
|
|
68
|
-
acceptNewValue(event.target.value);
|
|
69
|
-
}, 3000);
|
|
73
|
+
acceptValueByTimeout(event.target.value);
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
76
|
var handleKeyDown = function handleKeyDown(event) {
|
|
73
|
-
var target = event.target;
|
|
74
|
-
if (event.key === 'Enter' && inputValue.length) {
|
|
75
|
-
clearNewValueAutofillInterval();
|
|
76
|
-
acceptNewValue(target.value);
|
|
77
|
-
}
|
|
78
77
|
if (event.key === 'Backspace' && inputValue === '' && value !== null && value !== void 0 && value.length) {
|
|
79
78
|
// нужно чтобы после выполнения кода ниже - в handleChange не передалось значение и автоматически ч-з backspace не стёрся крайний символ
|
|
80
79
|
event.preventDefault();
|
|
81
80
|
var lastTagValue = value[value.length - 1];
|
|
82
81
|
setInputValue(lastTagValue);
|
|
83
82
|
handleTagRemove(lastTagValue);
|
|
84
|
-
|
|
85
|
-
acceptNewValue(lastTagValue);
|
|
86
|
-
}, 3000);
|
|
83
|
+
acceptValueByTimeout(lastTagValue);
|
|
87
84
|
}
|
|
88
85
|
};
|
|
89
86
|
var handleTagRemove = function handleTagRemove(tagRemoved) {
|
|
@@ -92,23 +89,32 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
92
89
|
});
|
|
93
90
|
onChange(valueWithoutRemovedTag !== null && valueWithoutRemovedTag !== void 0 && valueWithoutRemovedTag.length ? valueWithoutRemovedTag : undefined);
|
|
94
91
|
};
|
|
95
|
-
var
|
|
92
|
+
var handlePureInputWrapperBlur = function handlePureInputWrapperBlur(event) {
|
|
93
|
+
var newFocusedElement = event.relatedTarget;
|
|
94
|
+
if (!event.currentTarget.contains(newFocusedElement)) {
|
|
95
|
+
handleBlur(event);
|
|
96
|
+
clearNewValueAutofillInterval();
|
|
97
|
+
if (event.target.value) {
|
|
98
|
+
acceptNewValue(event.target.value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var handlePureInputWrapperFocus = function handlePureInputWrapperFocus(event) {
|
|
96
103
|
var _inputRef$current;
|
|
104
|
+
handleFocus(event);
|
|
97
105
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
98
106
|
};
|
|
99
|
-
var handlePureInputBlur = function handlePureInputBlur(event) {
|
|
100
|
-
handleBlur(event);
|
|
101
|
-
clearNewValueAutofillInterval();
|
|
102
|
-
if (event.target.value) {
|
|
103
|
-
acceptNewValue(event.target.value);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
107
|
var handleChipClick = function handleChipClick(chipValue) {
|
|
108
|
+
clearNewValueAutofillInterval();
|
|
107
109
|
setInputValue(chipValue);
|
|
108
110
|
handleTagRemove(chipValue);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
acceptValueByTimeout(chipValue);
|
|
112
|
+
};
|
|
113
|
+
var handleSaveButtonClick = function handleSaveButtonClick() {
|
|
114
|
+
var _inputRef$current2;
|
|
115
|
+
clearNewValueAutofillInterval();
|
|
116
|
+
acceptNewValue(inputValue);
|
|
117
|
+
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.focus();
|
|
112
118
|
};
|
|
113
119
|
return /*#__PURE__*/_react["default"].createElement(_InputLabel.InputLabel, {
|
|
114
120
|
label: label
|
|
@@ -122,7 +128,9 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
122
128
|
$paddingBottom: paddingBottom,
|
|
123
129
|
$hasError: hasError,
|
|
124
130
|
$inFocus: inFocus,
|
|
125
|
-
|
|
131
|
+
onBlur: handlePureInputWrapperBlur,
|
|
132
|
+
onFocus: handlePureInputWrapperFocus,
|
|
133
|
+
tabIndex: -1
|
|
126
134
|
}, /*#__PURE__*/_react["default"].createElement(S.TagsWrapper, null, value === null || value === void 0 ? void 0 : value.map(function (tagItem, index) {
|
|
127
135
|
return /*#__PURE__*/_react["default"].createElement(_Chip.Chip, {
|
|
128
136
|
key: tagItem + index,
|
|
@@ -142,18 +150,21 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
142
150
|
color: tagsInputPalette.chipColor,
|
|
143
151
|
bgColor: tagsInputPalette.chipBg
|
|
144
152
|
});
|
|
145
|
-
}), /*#__PURE__*/_react["default"].createElement(S.
|
|
153
|
+
}), /*#__PURE__*/_react["default"].createElement(S.InputWithSaveButtonWrapper, null, /*#__PURE__*/_react["default"].createElement(_PureInput.PureInput, {
|
|
146
154
|
ref: inputRef,
|
|
147
|
-
hasBorder:
|
|
155
|
+
hasBorder: inFocus,
|
|
148
156
|
paddingBottom: 0,
|
|
149
157
|
paddingRight: 0,
|
|
150
158
|
paddingTop: 0,
|
|
151
|
-
paddingLeft:
|
|
152
|
-
borderRadius:
|
|
159
|
+
paddingLeft: 4,
|
|
160
|
+
borderRadius: 6,
|
|
153
161
|
value: inputValue,
|
|
154
162
|
onChange: handleChange,
|
|
155
|
-
onKeyDown: handleKeyDown
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
onKeyDown: handleKeyDown
|
|
164
|
+
}), !!inputValue.length && (value !== null && value !== void 0 && value.length ? !value.includes(inputValue) : true) && /*#__PURE__*/_react["default"].createElement(S.SaveButton, {
|
|
165
|
+
type: 'button',
|
|
166
|
+
onClick: handleSaveButtonClick
|
|
167
|
+
}, /*#__PURE__*/_react["default"].createElement(_Typography.Typography, {
|
|
168
|
+
variant: 'captionRegular'
|
|
169
|
+
}, saveLabel))))));
|
|
159
170
|
};
|
|
@@ -12,6 +12,7 @@ export declare const PureInputStyledWrapper: import("styled-components/dist/type
|
|
|
12
12
|
$variant?: "headline1" | "headline2" | "headline3" | "headline4" | "headline5" | "headline6" | "headerText" | "buttonL" | "bodyL" | "bodyLUnderlined" | "buttonM" | "bodyMRegular" | "bodyMBold" | "bodyMUnderlined" | "captionRegular" | "labelsHintsRegular" | "labelsHintsBold" | "captionSRegular" | "captionUnderlined" | "smallMedium" | "labelsAndHints" | undefined;
|
|
13
13
|
}>> & string & ({} | Omit<React.ComponentClass<any, any>, keyof React.Component<any, {}, any>> | Omit<React.FunctionComponent<any>, keyof React.Component<any, {}, any>>);
|
|
14
14
|
export declare const TagsWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const InputWithSaveButtonWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
16
|
+
export declare const SaveButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
|
|
16
17
|
export declare const ChipLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
17
18
|
export declare const ChipRemoveButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TagsWrapper = exports.PureInputStyledWrapper = exports.
|
|
6
|
+
exports.TagsWrapper = exports.SaveButton = exports.PureInputStyledWrapper = exports.InputWithSaveButtonWrapper = exports.ChipRemoveButton = exports.ChipLabel = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _styles = require("../PureInput/styles");
|
|
9
9
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
@@ -15,26 +15,30 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
15
15
|
var Wrapper = function Wrapper(_ref) {
|
|
16
16
|
var children = _ref.children,
|
|
17
17
|
other = _objectWithoutProperties(_ref, _excluded);
|
|
18
|
-
return /*#__PURE__*/_react["default"].createElement("div", _extends({
|
|
18
|
+
return /*#__PURE__*/_react["default"].createElement("div", _extends({}, other, {
|
|
19
19
|
style: {
|
|
20
20
|
overflow: 'hidden'
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}), children);
|
|
23
23
|
};
|
|
24
24
|
var PureInputStyledWrapper = exports.PureInputStyledWrapper = (0, _styles.getPureInputStyled)(Wrapper);
|
|
25
25
|
var TagsWrapper = exports.TagsWrapper = _styledComponents["default"].div.withConfig({
|
|
26
26
|
displayName: "styles__TagsWrapper",
|
|
27
27
|
componentId: "sc-1uwnjdr-0"
|
|
28
28
|
})(["display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:4px;"]);
|
|
29
|
-
var
|
|
30
|
-
displayName: "
|
|
29
|
+
var InputWithSaveButtonWrapper = exports.InputWithSaveButtonWrapper = _styledComponents["default"].div.withConfig({
|
|
30
|
+
displayName: "styles__InputWithSaveButtonWrapper",
|
|
31
31
|
componentId: "sc-1uwnjdr-1"
|
|
32
|
-
})(["width:auto;"]);
|
|
32
|
+
})(["width:auto;display:flex;align-items:center;gap:12px;"]);
|
|
33
|
+
var SaveButton = exports.SaveButton = _styledComponents["default"].button.withConfig({
|
|
34
|
+
displayName: "styles__SaveButton",
|
|
35
|
+
componentId: "sc-1uwnjdr-2"
|
|
36
|
+
})(["background:transparent;border:none;cursor:pointer;"]);
|
|
33
37
|
var ChipLabel = exports.ChipLabel = _styledComponents["default"].div.withConfig({
|
|
34
38
|
displayName: "styles__ChipLabel",
|
|
35
|
-
componentId: "sc-1uwnjdr-
|
|
39
|
+
componentId: "sc-1uwnjdr-3"
|
|
36
40
|
})(["display:flex;align-items:center;gap:6px;"]);
|
|
37
41
|
var ChipRemoveButton = exports.ChipRemoveButton = _styledComponents["default"].button.withConfig({
|
|
38
42
|
displayName: "styles__ChipRemoveButton",
|
|
39
|
-
componentId: "sc-1uwnjdr-
|
|
43
|
+
componentId: "sc-1uwnjdr-4"
|
|
40
44
|
})(["display:flex;justify-content:center;align-items:center;background:transparent;border:none;cursor:pointer;outline:none;color:inherit;padding:0;"]);
|