iguazio.dashboard-react-controls 0.0.13 → 0.0.16
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/FormChipCell/FormChip/FormChip.js +143 -0
- package/dist/components/FormChipCell/FormChip/formChip.scss +74 -0
- package/dist/components/FormChipCell/FormChipCell.js +313 -0
- package/dist/components/FormChipCell/FormChipCellView.js +178 -0
- package/dist/components/FormChipCell/NewChipForm/NewChipForm.js +244 -0
- package/dist/components/FormChipCell/NewChipForm/newChipForm.scss +62 -0
- package/dist/components/FormChipCell/NewChipInput/NewChipInput.js +73 -0
- package/dist/components/FormChipCell/formChipCell.scss +52 -0
- package/dist/components/FormCombobox/formCombobox.scss +1 -1
- package/dist/components/FormInput/FormInput.js +1 -1
- package/dist/components/Modal/Modal.js +4 -4
- package/dist/components/Modal/Modal.scss +2 -2
- package/dist/components/Wizard/Wizard.js +5 -27
- package/dist/components/Wizard/Wizard.scss +1 -0
- package/dist/components/Wizard/WizardSteps/WizardSteps.scss +7 -1
- package/dist/components/index.js +8 -0
- package/dist/constants.js +13 -1
- package/dist/elements/HiddenChipsBlock/HiddenChipsBlock.js +188 -0
- package/dist/elements/HiddenChipsBlock/hiddenChipsBlock.scss +58 -0
- package/dist/scss/mixins.scss +14 -14
- package/dist/types.js +35 -1
- package/dist/utils/generateChipsList.util.js +25 -0
- package/dist/utils/getFirstScrollableParent.util.js +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
+
|
|
16
|
+
var _NewChipForm = _interopRequireDefault(require("../NewChipForm/NewChipForm"));
|
|
17
|
+
|
|
18
|
+
var _types = require("../../../types");
|
|
19
|
+
|
|
20
|
+
var _close = require("../../../images/close.svg");
|
|
21
|
+
|
|
22
|
+
require("./formChip.scss");
|
|
23
|
+
|
|
24
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
+
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
+
|
|
32
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
33
|
+
|
|
34
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
35
|
+
|
|
36
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
|
+
|
|
38
|
+
var FormChip = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
39
|
+
var _chip$delimiter;
|
|
40
|
+
|
|
41
|
+
var chip = _ref.chip,
|
|
42
|
+
chipClassNames = _ref.chipClassNames,
|
|
43
|
+
chipIndex = _ref.chipIndex,
|
|
44
|
+
chipOptions = _ref.chipOptions,
|
|
45
|
+
className = _ref.className,
|
|
46
|
+
editConfig = _ref.editConfig,
|
|
47
|
+
handleEditChip = _ref.handleEditChip,
|
|
48
|
+
handleIsEdit = _ref.handleIsEdit,
|
|
49
|
+
handleRemoveChip = _ref.handleRemoveChip,
|
|
50
|
+
isDeleteMode = _ref.isDeleteMode,
|
|
51
|
+
isEditMode = _ref.isEditMode,
|
|
52
|
+
keyName = _ref.keyName,
|
|
53
|
+
onClick = _ref.onClick,
|
|
54
|
+
setChipsSizes = _ref.setChipsSizes,
|
|
55
|
+
setEditConfig = _ref.setEditConfig,
|
|
56
|
+
textOverflowEllipsis = _ref.textOverflowEllipsis,
|
|
57
|
+
valueName = _ref.valueName;
|
|
58
|
+
|
|
59
|
+
var chipRef = _react.default.useRef();
|
|
60
|
+
|
|
61
|
+
var chipLabelClassNames = (0, _classnames.default)('chip__label', (textOverflowEllipsis || isEditMode) && 'data-ellipsis');
|
|
62
|
+
var chipValueClassNames = (0, _classnames.default)('chip__value', (textOverflowEllipsis || isEditMode) && 'data-ellipsis', chipOptions.boldValue && 'chip-value_bold');
|
|
63
|
+
(0, _react.useEffect)(function () {
|
|
64
|
+
if (chipRef.current && setChipsSizes) {
|
|
65
|
+
setChipsSizes(function (state) {
|
|
66
|
+
return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, chipIndex, chipRef.current.getBoundingClientRect().width));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}, [chipIndex, setChipsSizes]);
|
|
70
|
+
return isEditMode && chipIndex === editConfig.chipIndex ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_NewChipForm.default, {
|
|
71
|
+
chip: chip,
|
|
72
|
+
chipOptions: chipOptions,
|
|
73
|
+
className: "input-label-key",
|
|
74
|
+
editConfig: editConfig,
|
|
75
|
+
keyName: keyName,
|
|
76
|
+
onChange: handleEditChip,
|
|
77
|
+
ref: ref,
|
|
78
|
+
setEditConfig: setEditConfig,
|
|
79
|
+
valueName: valueName
|
|
80
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
81
|
+
className: chipClassNames,
|
|
82
|
+
onClick: function onClick(event) {
|
|
83
|
+
return handleIsEdit(event, chipIndex);
|
|
84
|
+
},
|
|
85
|
+
ref: chipRef,
|
|
86
|
+
children: [chip.key && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
87
|
+
className: chipLabelClassNames,
|
|
88
|
+
children: chip.key
|
|
89
|
+
}), chip.value && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
90
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
91
|
+
className: "chip__delimiter",
|
|
92
|
+
children: (_chip$delimiter = chip.delimiter) !== null && _chip$delimiter !== void 0 ? _chip$delimiter : ':'
|
|
93
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
94
|
+
className: chipValueClassNames,
|
|
95
|
+
children: chip.value
|
|
96
|
+
})]
|
|
97
|
+
}), (isEditMode || isDeleteMode) && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
98
|
+
className: "item-icon-close",
|
|
99
|
+
onClick: function onClick(event) {
|
|
100
|
+
return handleRemoveChip(event, chipIndex);
|
|
101
|
+
},
|
|
102
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_close.ReactComponent, {})
|
|
103
|
+
})]
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
FormChip.defaultProps = {
|
|
108
|
+
chipOptions: {
|
|
109
|
+
background: 'purple',
|
|
110
|
+
boldValue: false,
|
|
111
|
+
borderRadius: 'primary',
|
|
112
|
+
borderColor: 'transparent',
|
|
113
|
+
density: 'dense',
|
|
114
|
+
font: 'purple'
|
|
115
|
+
},
|
|
116
|
+
isDeleteMode: false,
|
|
117
|
+
isEditMode: false,
|
|
118
|
+
keyName: '',
|
|
119
|
+
onClick: function onClick() {},
|
|
120
|
+
textOverflowEllipsis: false,
|
|
121
|
+
valueName: ''
|
|
122
|
+
};
|
|
123
|
+
FormChip.propTypes = {
|
|
124
|
+
chip: _propTypes.default.object.isRequired,
|
|
125
|
+
chipClassNames: _propTypes.default.string.isRequired,
|
|
126
|
+
chipIndex: _propTypes.default.number.isRequired,
|
|
127
|
+
chipOptions: _types.CHIP_OPTIONS,
|
|
128
|
+
className: _propTypes.default.string,
|
|
129
|
+
editConfig: _propTypes.default.object.isRequired,
|
|
130
|
+
handleEditChip: _propTypes.default.func.isRequired,
|
|
131
|
+
handleIsEdit: _propTypes.default.func.isRequired,
|
|
132
|
+
handleRemoveChip: _propTypes.default.func.isRequired,
|
|
133
|
+
isDeleteMode: _propTypes.default.bool,
|
|
134
|
+
isEditMode: _propTypes.default.bool,
|
|
135
|
+
keyName: _propTypes.default.string,
|
|
136
|
+
onClick: _propTypes.default.func,
|
|
137
|
+
setChipsSizes: _propTypes.default.func.isRequired,
|
|
138
|
+
setEditConfig: _propTypes.default.func.isRequired,
|
|
139
|
+
textOverflowEllipsis: _propTypes.default.bool,
|
|
140
|
+
valueName: _propTypes.default.string
|
|
141
|
+
};
|
|
142
|
+
var _default = FormChip;
|
|
143
|
+
exports.default = _default;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
@import '../../../scss/variables';
|
|
2
|
+
@import '../../../scss/colors';
|
|
3
|
+
@import '../../../scss/borders';
|
|
4
|
+
@import '../../../scss/mixins';
|
|
5
|
+
|
|
6
|
+
.chip {
|
|
7
|
+
position: relative;
|
|
8
|
+
margin: 2px 8px 2px 0;
|
|
9
|
+
padding: 4px 8px;
|
|
10
|
+
font-size: 14px;
|
|
11
|
+
line-height: 16px;
|
|
12
|
+
visibility: hidden;
|
|
13
|
+
cursor: default;
|
|
14
|
+
|
|
15
|
+
&_visible {
|
|
16
|
+
visibility: visible;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&__content {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&__delimiter {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
margin: 0 4px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&__value {
|
|
31
|
+
min-width: 10px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&.editable {
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&.chips_button {
|
|
39
|
+
padding: 8px 7px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.item-icon-close {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
margin-left: 5px;
|
|
47
|
+
padding: 0;
|
|
48
|
+
|
|
49
|
+
svg {
|
|
50
|
+
transform: scale(0.7);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&-background {
|
|
55
|
+
@include chipBackground(false);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&-border {
|
|
59
|
+
@include chipBorder();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&-density {
|
|
63
|
+
@include chipDensity(false, false);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&-font {
|
|
67
|
+
@include chipsFont(Chip);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&-value_bold {
|
|
71
|
+
font-weight: 700;
|
|
72
|
+
font-size: 15px;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _lodash = require("lodash");
|
|
15
|
+
|
|
16
|
+
var _FormChipCellView = _interopRequireDefault(require("./FormChipCellView"));
|
|
17
|
+
|
|
18
|
+
var _common = require("../../utils/common.util");
|
|
19
|
+
|
|
20
|
+
var _generateChipsList = require("../../utils/generateChipsList.util");
|
|
21
|
+
|
|
22
|
+
var _types = require("../../types");
|
|
23
|
+
|
|
24
|
+
var _constants = require("../../constants");
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
35
|
+
|
|
36
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
37
|
+
|
|
38
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
39
|
+
|
|
40
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
41
|
+
|
|
42
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
43
|
+
|
|
44
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
45
|
+
|
|
46
|
+
var FormChipCell = function FormChipCell(_ref) {
|
|
47
|
+
var chipOptions = _ref.chipOptions,
|
|
48
|
+
className = _ref.className,
|
|
49
|
+
delimiter = _ref.delimiter,
|
|
50
|
+
formState = _ref.formState,
|
|
51
|
+
initialValues = _ref.initialValues,
|
|
52
|
+
isEditMode = _ref.isEditMode,
|
|
53
|
+
name = _ref.name,
|
|
54
|
+
onClick = _ref.onClick,
|
|
55
|
+
shortChips = _ref.shortChips,
|
|
56
|
+
visibleChipsMaxLength = _ref.visibleChipsMaxLength;
|
|
57
|
+
|
|
58
|
+
var _useState = (0, _react.useState)({}),
|
|
59
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
60
|
+
chipsSizes = _useState2[0],
|
|
61
|
+
setChipsSizes = _useState2[1];
|
|
62
|
+
|
|
63
|
+
var _useState3 = (0, _react.useState)(false),
|
|
64
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
65
|
+
showHiddenChips = _useState4[0],
|
|
66
|
+
setShowHiddenChips = _useState4[1];
|
|
67
|
+
|
|
68
|
+
var _useState5 = (0, _react.useState)({
|
|
69
|
+
chipIndex: null,
|
|
70
|
+
isEdit: false,
|
|
71
|
+
isKeyFocused: true,
|
|
72
|
+
isValueFocused: false,
|
|
73
|
+
isNewChip: false
|
|
74
|
+
}),
|
|
75
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
76
|
+
editConfig = _useState6[0],
|
|
77
|
+
setEditConfig = _useState6[1];
|
|
78
|
+
|
|
79
|
+
var _useState7 = (0, _react.useState)(false),
|
|
80
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
81
|
+
showChips = _useState8[0],
|
|
82
|
+
setShowChips = _useState8[1];
|
|
83
|
+
|
|
84
|
+
var _useState9 = (0, _react.useState)(8),
|
|
85
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
86
|
+
visibleChipsCount = _useState10[0],
|
|
87
|
+
setVisibleChipsCount = _useState10[1];
|
|
88
|
+
|
|
89
|
+
var chipsCellRef = (0, _react.useRef)();
|
|
90
|
+
var chipsWrapperRef = (0, _react.useRef)();
|
|
91
|
+
var handleShowElements = (0, _react.useCallback)(function () {
|
|
92
|
+
if (!isEditMode || isEditMode && visibleChipsMaxLength) {
|
|
93
|
+
setShowHiddenChips(function (state) {
|
|
94
|
+
return !state;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}, [isEditMode, visibleChipsMaxLength]);
|
|
98
|
+
var chips = (0, _react.useMemo)(function () {
|
|
99
|
+
return isEditMode || visibleChipsMaxLength === 'all' ? {
|
|
100
|
+
visibleChips: formState.values[name]
|
|
101
|
+
} : (0, _generateChipsList.generateChipsList)(formState.values[name], visibleChipsMaxLength ? visibleChipsMaxLength : visibleChipsCount, delimiter);
|
|
102
|
+
}, [visibleChipsMaxLength, isEditMode, formState.values, name, visibleChipsCount, delimiter]);
|
|
103
|
+
var handleResize = (0, _react.useCallback)(function () {
|
|
104
|
+
if (!isEditMode && !(0, _common.isEveryObjectValueEmpty)(chipsSizes)) {
|
|
105
|
+
var _chipsCellRef$current;
|
|
106
|
+
|
|
107
|
+
var parentSize = (_chipsCellRef$current = chipsCellRef.current) === null || _chipsCellRef$current === void 0 ? void 0 : _chipsCellRef$current.getBoundingClientRect().width;
|
|
108
|
+
var maxLength = 0;
|
|
109
|
+
var chipIndex = 0;
|
|
110
|
+
var padding = 65;
|
|
111
|
+
Object.values(chipsSizes).every(function (chipSize, index) {
|
|
112
|
+
if (maxLength + chipSize > parentSize || Object.values(chipsSizes).length > 1 && maxLength + chipSize + padding > parentSize) {
|
|
113
|
+
chipIndex = index;
|
|
114
|
+
return false;
|
|
115
|
+
} else {
|
|
116
|
+
maxLength += chipSize;
|
|
117
|
+
|
|
118
|
+
if (index === Object.values(chipsSizes).length - 1) {
|
|
119
|
+
chipIndex = 8;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
setVisibleChipsCount(chipIndex);
|
|
126
|
+
setShowChips(true);
|
|
127
|
+
}
|
|
128
|
+
}, [chipsSizes, isEditMode]);
|
|
129
|
+
(0, _react.useEffect)(function () {
|
|
130
|
+
handleResize();
|
|
131
|
+
}, [handleResize, showChips]);
|
|
132
|
+
(0, _react.useEffect)(function () {
|
|
133
|
+
if (!isEditMode) {
|
|
134
|
+
window.addEventListener('resize', handleResize);
|
|
135
|
+
return function () {
|
|
136
|
+
return window.removeEventListener('resize', handleResize);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}, [handleResize, isEditMode]);
|
|
140
|
+
(0, _react.useEffect)(function () {
|
|
141
|
+
window.addEventListener('mainResize', handleResize);
|
|
142
|
+
return function () {
|
|
143
|
+
return window.removeEventListener('mainResize', handleResize);
|
|
144
|
+
};
|
|
145
|
+
}, [handleResize]);
|
|
146
|
+
(0, _react.useEffect)(function () {
|
|
147
|
+
if (showHiddenChips) {
|
|
148
|
+
window.addEventListener('click', handleShowElements);
|
|
149
|
+
return function () {
|
|
150
|
+
return window.removeEventListener('click', handleShowElements);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}, [showHiddenChips, handleShowElements]);
|
|
154
|
+
var checkChipsList = (0, _react.useCallback)(function (currentChipsList) {
|
|
155
|
+
if ((0, _lodash.isEqual)(initialValues[name], currentChipsList)) {
|
|
156
|
+
formState.initialValues[name] = currentChipsList;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
formState.form.mutators.setFieldState(name, {
|
|
160
|
+
modified: true
|
|
161
|
+
});
|
|
162
|
+
formState.form.mutators.setFieldState(name, {
|
|
163
|
+
touched: true
|
|
164
|
+
});
|
|
165
|
+
}, [initialValues, name, formState]);
|
|
166
|
+
var handleAddNewChip = (0, _react.useCallback)(function (event, fields) {
|
|
167
|
+
if (!editConfig.isEdit && !editConfig.chipIndex) {
|
|
168
|
+
formState.form.mutators.push(name, {
|
|
169
|
+
key: '',
|
|
170
|
+
value: '',
|
|
171
|
+
delimiter: delimiter
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (showHiddenChips) {
|
|
176
|
+
setShowHiddenChips(false);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
event && event.preventDefault();
|
|
180
|
+
setEditConfig({
|
|
181
|
+
chipIndex: fields.value.length,
|
|
182
|
+
isEdit: true,
|
|
183
|
+
isKeyFocused: true,
|
|
184
|
+
isValueFocused: false,
|
|
185
|
+
isNewChip: true
|
|
186
|
+
});
|
|
187
|
+
}, [editConfig.isEdit, editConfig.chipIndex, showHiddenChips, formState, name, delimiter]);
|
|
188
|
+
var handleRemoveChip = (0, _react.useCallback)(function (event, fields, chipIndex) {
|
|
189
|
+
checkChipsList(formState.values[name].filter(function (_, index) {
|
|
190
|
+
return index !== chipIndex;
|
|
191
|
+
}));
|
|
192
|
+
fields.remove(chipIndex);
|
|
193
|
+
event && event.stopPropagation();
|
|
194
|
+
}, [checkChipsList, formState.values, name]);
|
|
195
|
+
var handleEditChip = (0, _react.useCallback)(function (event, fields, nameEvent) {
|
|
196
|
+
var chip = formState.values[name][editConfig.chipIndex];
|
|
197
|
+
var isChipNotEmpty = !!(chip.key && chip.value);
|
|
198
|
+
|
|
199
|
+
if (nameEvent === _constants.CLICK) {
|
|
200
|
+
if (editConfig.isNewChip && !isChipNotEmpty) {
|
|
201
|
+
handleRemoveChip(event, fields, editConfig.chipIndex);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
setEditConfig({
|
|
205
|
+
chipIndex: null,
|
|
206
|
+
isEdit: false,
|
|
207
|
+
isKeyFocused: true,
|
|
208
|
+
isValueFocused: false,
|
|
209
|
+
isNewChip: false
|
|
210
|
+
});
|
|
211
|
+
} else if (nameEvent === _constants.TAB) {
|
|
212
|
+
if (editConfig.isNewChip && !isChipNotEmpty) {
|
|
213
|
+
handleRemoveChip(event, fields, editConfig.chipIndex);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setEditConfig(function (prevState) {
|
|
217
|
+
var lastChipSelected = prevState.chipIndex + 1 > fields.value.length - 1;
|
|
218
|
+
return {
|
|
219
|
+
chipIndex: lastChipSelected ? null : prevState.chipIndex + 1,
|
|
220
|
+
isEdit: !lastChipSelected,
|
|
221
|
+
isKeyFocused: true,
|
|
222
|
+
isValueFocused: false,
|
|
223
|
+
isNewChip: false
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
} else if (nameEvent === _constants.TAB_SHIFT) {
|
|
227
|
+
if (editConfig.isNewChip && !isChipNotEmpty) {
|
|
228
|
+
handleRemoveChip(event, fields, editConfig.chipIndex);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
setEditConfig(function (prevState) {
|
|
232
|
+
var isPrevChipIndexExists = prevState.chipIndex - 1 < 0;
|
|
233
|
+
return {
|
|
234
|
+
chipIndex: isPrevChipIndexExists ? null : prevState.chipIndex - 1,
|
|
235
|
+
isEdit: !isPrevChipIndexExists,
|
|
236
|
+
isKeyFocused: isPrevChipIndexExists,
|
|
237
|
+
isValueFocused: !isPrevChipIndexExists,
|
|
238
|
+
isNewChip: false
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
event && event.preventDefault();
|
|
244
|
+
checkChipsList(formState.values[name]);
|
|
245
|
+
}, [editConfig.chipIndex, editConfig.isNewChip, handleRemoveChip, name, formState, checkChipsList]);
|
|
246
|
+
var handleIsEdit = (0, _react.useCallback)(function (event, index) {
|
|
247
|
+
if (isEditMode) {
|
|
248
|
+
event.stopPropagation();
|
|
249
|
+
setEditConfig({
|
|
250
|
+
chipIndex: index,
|
|
251
|
+
isEdit: true,
|
|
252
|
+
isKeyFocused: true,
|
|
253
|
+
isValueFocused: false
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
onClick && onClick();
|
|
258
|
+
}, [isEditMode, onClick]);
|
|
259
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormChipCellView.default, {
|
|
260
|
+
chipOptions: chipOptions,
|
|
261
|
+
chips: chips,
|
|
262
|
+
className: className,
|
|
263
|
+
editConfig: editConfig,
|
|
264
|
+
handleAddNewChip: handleAddNewChip,
|
|
265
|
+
handleEditChip: handleEditChip,
|
|
266
|
+
handleIsEdit: handleIsEdit,
|
|
267
|
+
handleRemoveChip: handleRemoveChip,
|
|
268
|
+
handleShowElements: handleShowElements,
|
|
269
|
+
isEditMode: isEditMode,
|
|
270
|
+
name: name,
|
|
271
|
+
ref: {
|
|
272
|
+
chipsCellRef: chipsCellRef,
|
|
273
|
+
chipsWrapperRef: chipsWrapperRef
|
|
274
|
+
},
|
|
275
|
+
setChipsSizes: setChipsSizes,
|
|
276
|
+
setEditConfig: setEditConfig,
|
|
277
|
+
shortChips: shortChips,
|
|
278
|
+
showChips: showChips,
|
|
279
|
+
showHiddenChips: showHiddenChips
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
FormChipCell.defaultProps = {
|
|
284
|
+
chipOptions: {
|
|
285
|
+
background: 'purple',
|
|
286
|
+
boldValue: false,
|
|
287
|
+
borderRadius: 'primary',
|
|
288
|
+
borderColor: 'transparent',
|
|
289
|
+
density: 'dense',
|
|
290
|
+
font: 'purple'
|
|
291
|
+
},
|
|
292
|
+
delimiter: null,
|
|
293
|
+
onClick: function onClick() {},
|
|
294
|
+
shortChips: false,
|
|
295
|
+
isEditMode: false,
|
|
296
|
+
visibleChipsMaxLength: 'all'
|
|
297
|
+
};
|
|
298
|
+
FormChipCell.propTypes = {
|
|
299
|
+
chipOptions: _types.CHIP_OPTIONS,
|
|
300
|
+
className: _propTypes.default.string,
|
|
301
|
+
delimiter: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element]),
|
|
302
|
+
onClick: _propTypes.default.func,
|
|
303
|
+
shortChips: _propTypes.default.bool,
|
|
304
|
+
name: _propTypes.default.string.isRequired,
|
|
305
|
+
formState: _propTypes.default.shape({}).isRequired,
|
|
306
|
+
initialValues: _propTypes.default.object.isRequired,
|
|
307
|
+
isEditMode: _propTypes.default.bool,
|
|
308
|
+
visibleChipsMaxLength: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
var _default = /*#__PURE__*/_react.default.memo(FormChipCell);
|
|
312
|
+
|
|
313
|
+
exports.default = _default;
|