iguazio.dashboard-react-controls 1.9.2 → 2.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.
- package/dist/components/Backdrop/Backdrop.js +7 -7
- package/dist/components/Button/Button.js +20 -26
- package/dist/components/ConfirmDialog/ConfirmDialog.js +18 -17
- package/dist/components/FormCheckBox/FormCheckBox.js +28 -32
- package/dist/components/FormChipCell/FormChip/FormChip.js +46 -50
- package/dist/components/FormChipCell/FormChipCell.js +122 -142
- package/dist/components/FormChipCell/FormChipCellView.js +44 -47
- package/dist/components/FormChipCell/HiddenChipsBlock/HiddenChipsBlock.js +23 -20
- package/dist/components/FormChipCell/NewChipForm/NewChipForm.js +129 -152
- package/dist/components/FormChipCell/NewChipInput/NewChipInput.js +24 -27
- package/dist/components/FormChipCell/formChipCell.util.js +6 -16
- package/dist/components/FormCombobox/FormCombobox.js +134 -195
- package/dist/components/FormInput/FormInput.js +134 -212
- package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.js +15 -14
- package/dist/components/FormKeyValueTable/FormKeyValueTable.js +72 -72
- package/dist/components/FormRadio/FormRadio.js +21 -25
- package/dist/components/FormSelect/FormSelect.js +98 -126
- package/dist/components/FormSelect/FormSelect.test.js +56 -60
- package/dist/components/FormTextarea/FormTextarea.js +55 -71
- package/dist/components/FormToggle/FormToggle.js +25 -29
- package/dist/components/Modal/Modal.js +17 -18
- package/dist/components/PopUpDialog/PopUpDialog.js +53 -63
- package/dist/components/RoundedIcon/RoundedIcon.js +14 -13
- package/dist/components/Tip/Tip.js +58 -64
- package/dist/components/Tip/Tip.test.js +41 -64
- package/dist/components/Tooltip/Tooltip.js +75 -89
- package/dist/components/TooltipTemplate/ProducerTooltipTemplate.js +6 -5
- package/dist/components/TooltipTemplate/TextTooltipTemplate.js +10 -10
- package/dist/components/Wizard/Wizard.js +73 -107
- package/dist/components/Wizard/WizardSteps/WizardSteps.js +19 -20
- package/dist/components/index.js +18 -18
- package/dist/constants.js +26 -44
- package/dist/elements/FormActionButton/FormActionButton.js +12 -13
- package/dist/elements/FormRowActions/FormRowActions.js +19 -22
- package/dist/elements/OptionsMenu/OptionsMenu.js +10 -8
- package/dist/elements/SelectOption/SelectOption.js +14 -13
- package/dist/elements/SelectOption/SelectOption.test.js +39 -47
- package/dist/elements/ValidationTemplate/ValidationTemplate.js +7 -6
- package/dist/elements/index.js +5 -5
- package/dist/hooks/index.js +5 -5
- package/dist/hooks/useChipCell.hook.js +66 -85
- package/dist/hooks/useDebounce.hook.js +22 -24
- package/dist/hooks/useDetectOutsideClick.hook.js +4 -4
- package/dist/hooks/useFormTable.hook.js +99 -112
- package/dist/hooks/useHiddenChipsBlock.hook.js +40 -55
- package/dist/index.js +2 -3
- package/dist/scss/borders.scss +6 -0
- package/dist/scss/mixins.scss +32 -0
- package/dist/types.js +43 -67
- package/dist/utils/common.util.js +19 -23
- package/dist/utils/form.util.js +33 -39
- package/dist/utils/generateChipsList.util.js +7 -7
- package/dist/utils/getFirstScrollableParent.util.js +4 -10
- package/dist/utils/math.util.js +3 -3
- package/dist/utils/validation.util.js +74 -131
- package/package.json +34 -34
|
@@ -34,43 +34,41 @@ under the Apache 2.0 license is conditioned upon your compliance with
|
|
|
34
34
|
such restriction.
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const FormRowActions = _ref => {
|
|
38
38
|
var _editingItem$ui, _editingItem$ui2, _editingItem$ui3, _editingItem$ui4;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
let {
|
|
40
|
+
applyChanges,
|
|
41
|
+
deleteButtonIsHidden,
|
|
42
|
+
deleteRow,
|
|
43
|
+
disabled,
|
|
44
|
+
discardOrDelete,
|
|
45
|
+
editingItem,
|
|
46
|
+
fieldsPath,
|
|
47
|
+
hidden,
|
|
48
|
+
index
|
|
49
|
+
} = _ref;
|
|
48
50
|
return hidden ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
49
51
|
className: "form-table__cell form-table__actions-cell"
|
|
50
52
|
}) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
51
53
|
className: "form-table__cell form-table__actions-cell",
|
|
52
|
-
children: [(editingItem === null || editingItem === void 0
|
|
54
|
+
children: [(editingItem === null || editingItem === void 0 || (_editingItem$ui = editingItem.ui) === null || _editingItem$ui === void 0 ? void 0 : _editingItem$ui.index) === index && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
53
55
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
|
|
54
56
|
id: "apply-btn",
|
|
55
|
-
onClick:
|
|
56
|
-
return applyChanges(event, index);
|
|
57
|
-
},
|
|
57
|
+
onClick: event => applyChanges(event, index),
|
|
58
58
|
tooltipText: "Apply",
|
|
59
59
|
disabled: disabled,
|
|
60
60
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkmark.ReactComponent, {})
|
|
61
61
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
|
|
62
62
|
id: "delete-discard-btn",
|
|
63
|
-
onClick:
|
|
64
|
-
return discardOrDelete(event, fieldsPath, index);
|
|
65
|
-
},
|
|
63
|
+
onClick: event => discardOrDelete(event, fieldsPath, index),
|
|
66
64
|
tooltipText: (_editingItem$ui2 = editingItem.ui) !== null && _editingItem$ui2 !== void 0 && _editingItem$ui2.isNew ? 'Delete' : 'Discard changes',
|
|
67
65
|
disabled: disabled,
|
|
68
66
|
children: (_editingItem$ui3 = editingItem.ui) !== null && _editingItem$ui3 !== void 0 && _editingItem$ui3.isNew ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_delete.ReactComponent, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_close.ReactComponent, {})
|
|
69
67
|
})]
|
|
70
|
-
}), (!editingItem || (editingItem === null || editingItem === void 0
|
|
68
|
+
}), (!editingItem || (editingItem === null || editingItem === void 0 || (_editingItem$ui4 = editingItem.ui) === null || _editingItem$ui4 === void 0 ? void 0 : _editingItem$ui4.index) !== index) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
71
69
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
|
|
72
70
|
id: "edit-btn",
|
|
73
|
-
onClick:
|
|
71
|
+
onClick: event => {
|
|
74
72
|
event.preventDefault();
|
|
75
73
|
},
|
|
76
74
|
tooltipText: "Edit",
|
|
@@ -78,7 +76,7 @@ var FormRowActions = function FormRowActions(_ref) {
|
|
|
78
76
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.ReactComponent, {})
|
|
79
77
|
}), !deleteButtonIsHidden && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
|
|
80
78
|
id: "delete-btn",
|
|
81
|
-
onClick:
|
|
79
|
+
onClick: event => {
|
|
82
80
|
deleteRow(event, fieldsPath, index);
|
|
83
81
|
},
|
|
84
82
|
tooltipText: "Delete",
|
|
@@ -105,5 +103,4 @@ FormRowActions.propTypes = {
|
|
|
105
103
|
hidden: _propTypes.default.bool,
|
|
106
104
|
index: _propTypes.default.number.isRequired
|
|
107
105
|
};
|
|
108
|
-
var _default = FormRowActions;
|
|
109
|
-
exports.default = _default;
|
|
106
|
+
var _default = exports.default = FormRowActions;
|
|
@@ -28,12 +28,15 @@ under the Apache 2.0 license is conditioned upon your compliance with
|
|
|
28
28
|
such restriction.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const OptionsMenu = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
32
|
+
let {
|
|
33
|
+
children,
|
|
34
|
+
show,
|
|
35
|
+
timeout
|
|
36
|
+
} = _ref;
|
|
37
|
+
const {
|
|
38
|
+
width: dropdownWidth
|
|
39
|
+
} = ref.current ? ref.current.getBoundingClientRect() : {};
|
|
37
40
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactTransitionGroup.CSSTransition, {
|
|
38
41
|
in: show,
|
|
39
42
|
timeout: timeout,
|
|
@@ -68,5 +71,4 @@ OptionsMenu.propTypes = {
|
|
|
68
71
|
show: _propTypes.default.bool.isRequired,
|
|
69
72
|
timeout: _propTypes.default.number
|
|
70
73
|
};
|
|
71
|
-
var _default = OptionsMenu;
|
|
72
|
-
exports.default = _default;
|
|
74
|
+
var _default = exports.default = OptionsMenu;
|
|
@@ -30,15 +30,17 @@ under the Apache 2.0 license is conditioned upon your compliance with
|
|
|
30
30
|
such restriction.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const SelectOption = _ref => {
|
|
34
34
|
var _item$labelHtml;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
let {
|
|
36
|
+
item,
|
|
37
|
+
name,
|
|
38
|
+
onClick,
|
|
39
|
+
multiple,
|
|
40
|
+
selectedId,
|
|
41
|
+
withSelectedIcon
|
|
42
|
+
} = _ref;
|
|
43
|
+
const selectClassName = (0, _classnames.default)('select__item', multiple && 'multiple', item.hidden && 'hidden', item.disabled && 'disabled');
|
|
42
44
|
if (multiple) {
|
|
43
45
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
44
46
|
"data-testid": "select-checkbox",
|
|
@@ -56,8 +58,8 @@ var SelectOption = function SelectOption(_ref) {
|
|
|
56
58
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
57
59
|
"data-testid": "select-option",
|
|
58
60
|
className: selectClassName,
|
|
59
|
-
onClick:
|
|
60
|
-
!item.disabled &&
|
|
61
|
+
onClick: () => {
|
|
62
|
+
!item.disabled && onClick(item.id);
|
|
61
63
|
},
|
|
62
64
|
"data-custom-id": item.id,
|
|
63
65
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -95,7 +97,7 @@ var SelectOption = function SelectOption(_ref) {
|
|
|
95
97
|
});
|
|
96
98
|
};
|
|
97
99
|
SelectOption.defaultProps = {
|
|
98
|
-
onClick:
|
|
100
|
+
onClick: () => {},
|
|
99
101
|
multiple: false,
|
|
100
102
|
withSelectedIcon: true
|
|
101
103
|
};
|
|
@@ -107,5 +109,4 @@ SelectOption.propTypes = {
|
|
|
107
109
|
selectedId: _propTypes.default.string,
|
|
108
110
|
withSelectedIcon: _propTypes.default.bool
|
|
109
111
|
};
|
|
110
|
-
var _default = SelectOption;
|
|
111
|
-
exports.default = _default;
|
|
112
|
+
var _default = exports.default = SelectOption;
|
|
@@ -5,44 +5,36 @@ var _react2 = require("@testing-library/react");
|
|
|
5
5
|
var _SelectOption = _interopRequireDefault(require("./SelectOption"));
|
|
6
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
ReactComponent: 'unchecked-icon'
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
describe('SelectOption component', function () {
|
|
43
|
-
var wrapper;
|
|
44
|
-
beforeEach(function () {
|
|
45
|
-
var props = {
|
|
8
|
+
/*
|
|
9
|
+
Copyright 2022 Iguazio Systems Ltd.
|
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
11
|
+
an addition restriction as set forth herein. You may not use this
|
|
12
|
+
file except in compliance with the License. You may obtain a copy of
|
|
13
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
17
|
+
implied. See the License for the specific language governing
|
|
18
|
+
permissions and limitations under the License.
|
|
19
|
+
In addition, you may not use the software for any purposes that are
|
|
20
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
21
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
22
|
+
such restriction.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const renderComponent = props => (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectOption.default, {
|
|
26
|
+
...props
|
|
27
|
+
}));
|
|
28
|
+
jest.mock('../../images/checkbox-unchecked.svg', () => ({
|
|
29
|
+
ReactComponent: 'unchecked-icon'
|
|
30
|
+
}));
|
|
31
|
+
jest.mock('../../images/checkbox-checked.svg', () => ({
|
|
32
|
+
ReactComponent: 'unchecked-icon'
|
|
33
|
+
}));
|
|
34
|
+
describe('SelectOption component', () => {
|
|
35
|
+
let wrapper;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
const props = {
|
|
46
38
|
item: {
|
|
47
39
|
label: 'Test1',
|
|
48
40
|
id: 'test1',
|
|
@@ -56,10 +48,10 @@ describe('SelectOption component', function () {
|
|
|
56
48
|
wrapper = renderComponent(props);
|
|
57
49
|
});
|
|
58
50
|
afterEach(_react2.cleanup);
|
|
59
|
-
it('renders without crashing',
|
|
51
|
+
it('renders without crashing', () => {
|
|
60
52
|
expect(wrapper.queryByTestId('select-option')).not.toBeNull();
|
|
61
53
|
});
|
|
62
|
-
it('should display checkbox inside option if props selectType is "checkbox"',
|
|
54
|
+
it('should display checkbox inside option if props selectType is "checkbox"', () => {
|
|
63
55
|
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectOption.default, {
|
|
64
56
|
item: {
|
|
65
57
|
label: 'Test1',
|
|
@@ -70,11 +62,11 @@ describe('SelectOption component', function () {
|
|
|
70
62
|
}));
|
|
71
63
|
expect(wrapper.queryByTestId('select-checkbox')).not.toBeNull();
|
|
72
64
|
});
|
|
73
|
-
it('should display select icon if it exists in the props "item"',
|
|
65
|
+
it('should display select icon if it exists in the props "item"', () => {
|
|
74
66
|
expect(wrapper.getByTestId('select-icon')).not.toBeNull();
|
|
75
67
|
});
|
|
76
|
-
it('should won\'t call onClick callback if props disable set to "true"',
|
|
77
|
-
|
|
68
|
+
it('should won\'t call onClick callback if props disable set to "true"', () => {
|
|
69
|
+
const mockCLick = jest.fn();
|
|
78
70
|
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectOption.default, {
|
|
79
71
|
item: {
|
|
80
72
|
label: 'Test1',
|
|
@@ -84,14 +76,14 @@ describe('SelectOption component', function () {
|
|
|
84
76
|
selectType: "test1",
|
|
85
77
|
disabled: true
|
|
86
78
|
}));
|
|
87
|
-
|
|
79
|
+
const selectOption = wrapper.getByTestId('select-option');
|
|
88
80
|
_react2.fireEvent.click(selectOption);
|
|
89
81
|
expect(mockCLick).toHaveBeenCalledTimes(0);
|
|
90
82
|
});
|
|
91
|
-
it('should display subLabel if it exists in props item',
|
|
83
|
+
it('should display subLabel if it exists in props item', () => {
|
|
92
84
|
expect(wrapper.queryByTestId('tooltip-wrapper')).not.toBeNull();
|
|
93
85
|
});
|
|
94
|
-
it('should add class "disabled" to SelectOption if props disabled set to "true"',
|
|
86
|
+
it('should add class "disabled" to SelectOption if props disabled set to "true"', () => {
|
|
95
87
|
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectOption.default, {
|
|
96
88
|
item: {
|
|
97
89
|
label: 'Test1',
|
|
@@ -100,7 +92,7 @@ describe('SelectOption component', function () {
|
|
|
100
92
|
selectType: "test1",
|
|
101
93
|
disabled: true
|
|
102
94
|
}));
|
|
103
|
-
|
|
95
|
+
const selectOption = wrapper.getByTestId('select-option');
|
|
104
96
|
expect(selectOption.className).toMatch('disabled');
|
|
105
97
|
});
|
|
106
98
|
});
|
|
@@ -29,10 +29,12 @@ under the Apache 2.0 license is conditioned upon your compliance with
|
|
|
29
29
|
such restriction.
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const ValidationTemplate = _ref => {
|
|
33
|
+
let {
|
|
34
|
+
valid,
|
|
35
|
+
validationMessage
|
|
36
|
+
} = _ref;
|
|
37
|
+
const validationClasses = (0, _classnames.default)('validation-option', valid && 'text-muted');
|
|
36
38
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
37
39
|
className: validationClasses,
|
|
38
40
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
|
|
@@ -51,5 +53,4 @@ ValidationTemplate.propTypes = {
|
|
|
51
53
|
valid: _propTypes.default.bool.isRequired,
|
|
52
54
|
validationMessage: _propTypes.default.string.isRequired
|
|
53
55
|
};
|
|
54
|
-
var _default = ValidationTemplate;
|
|
55
|
-
exports.default = _default;
|
|
56
|
+
var _default = exports.default = ValidationTemplate;
|
package/dist/elements/index.js
CHANGED
|
@@ -5,31 +5,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "FormActionButton", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _FormActionButton.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "FormRowActions", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _FormRowActions.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "OptionsMenu", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _OptionsMenu.default;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "SelectOption", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _SelectOption.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "ValidationTemplate", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _ValidationTemplate.default;
|
|
34
34
|
}
|
|
35
35
|
});
|
package/dist/hooks/index.js
CHANGED
|
@@ -5,31 +5,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "useChipCell", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _useChipCell.useChipCell;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "useDebounce", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _useDebounce.useDebounce;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "useDetectOutsideClick", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _useDetectOutsideClick.useDetectOutsideClick;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "useFormTable", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _useFormTable.useFormTable;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "useHiddenChipsBlock", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _useHiddenChipsBlock.useHiddenChipsBlock;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
@@ -8,88 +8,69 @@ var _react = require("react");
|
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
var _common = require("../utils/common.util");
|
|
10
10
|
var _getFirstScrollableParent = require("../utils/getFirstScrollableParent.util");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
chipsSizes = _useState4[0],
|
|
43
|
-
setChipsSizes = _useState4[1];
|
|
44
|
-
var _useState5 = (0, _react.useState)(false),
|
|
45
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
46
|
-
showChips = _useState6[0],
|
|
47
|
-
setShowChips = _useState6[1];
|
|
48
|
-
var _useState7 = (0, _react.useState)(8),
|
|
49
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
50
|
-
visibleChipsCount = _useState8[0],
|
|
51
|
-
setVisibleChipsCount = _useState8[1];
|
|
52
|
-
var transitionEndEventName = (0, _react.useMemo)(function () {
|
|
53
|
-
return (0, _common.getTransitionEndEventName)();
|
|
54
|
-
}, []);
|
|
55
|
-
var chipsCellRef = (0, _react.useRef)();
|
|
56
|
-
var chipsWrapperRef = (0, _react.useRef)();
|
|
57
|
-
var hiddenChipsCounterRef = (0, _react.useRef)();
|
|
58
|
-
var hiddenChipsPopUpRef = (0, _react.useRef)();
|
|
59
|
-
var handleShowElements = (0, _react.useCallback)(function () {
|
|
11
|
+
/*
|
|
12
|
+
Copyright 2019 Iguazio Systems Ltd.
|
|
13
|
+
|
|
14
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
15
|
+
an addition restriction as set forth herein. You may not use this
|
|
16
|
+
file except in compliance with the License. You may obtain a copy of
|
|
17
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
18
|
+
|
|
19
|
+
Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
22
|
+
implied. See the License for the specific language governing
|
|
23
|
+
permissions and limitations under the License.
|
|
24
|
+
|
|
25
|
+
In addition, you may not use the software for any purposes that are
|
|
26
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
27
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
28
|
+
such restriction.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const useChipCell = (isEditMode, visibleChipsMaxLength) => {
|
|
32
|
+
const [showHiddenChips, setShowHiddenChips] = (0, _react.useState)(false);
|
|
33
|
+
const [chipsSizes, setChipsSizes] = (0, _react.useState)({});
|
|
34
|
+
const [showChips, setShowChips] = (0, _react.useState)(false);
|
|
35
|
+
const [visibleChipsCount, setVisibleChipsCount] = (0, _react.useState)(8);
|
|
36
|
+
const transitionEndEventName = (0, _react.useMemo)(() => (0, _common.getTransitionEndEventName)(), []);
|
|
37
|
+
const chipsCellRef = (0, _react.useRef)();
|
|
38
|
+
const chipsWrapperRef = (0, _react.useRef)();
|
|
39
|
+
const hiddenChipsCounterRef = (0, _react.useRef)();
|
|
40
|
+
const hiddenChipsPopUpRef = (0, _react.useRef)();
|
|
41
|
+
const handleShowElements = (0, _react.useCallback)(event => {
|
|
60
42
|
if (!isEditMode || isEditMode && visibleChipsMaxLength) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
43
|
+
var _hiddenChipsCounterRe;
|
|
44
|
+
if (!((_hiddenChipsCounterRe = hiddenChipsCounterRef.current) !== null && _hiddenChipsCounterRe !== void 0 && _hiddenChipsCounterRe.contains(event.target))) {
|
|
45
|
+
setShowHiddenChips(false);
|
|
46
|
+
} else {
|
|
47
|
+
setShowHiddenChips(true);
|
|
48
|
+
}
|
|
64
49
|
}
|
|
65
50
|
}, [isEditMode, visibleChipsMaxLength]);
|
|
66
|
-
(0, _react.useEffect)(
|
|
51
|
+
(0, _react.useEffect)(() => {
|
|
67
52
|
if (showHiddenChips) {
|
|
68
53
|
window.addEventListener('click', handleShowElements);
|
|
69
|
-
return
|
|
70
|
-
return window.removeEventListener('click', handleShowElements);
|
|
71
|
-
};
|
|
54
|
+
return () => window.removeEventListener('click', handleShowElements);
|
|
72
55
|
}
|
|
73
56
|
}, [showHiddenChips, handleShowElements]);
|
|
74
|
-
|
|
57
|
+
const handleScroll = (0, _react.useCallback)(event => {
|
|
75
58
|
if (event.target.parentElement !== (hiddenChipsPopUpRef === null || hiddenChipsPopUpRef === void 0 ? void 0 : hiddenChipsPopUpRef.current)) {
|
|
76
59
|
setShowHiddenChips(false);
|
|
77
60
|
}
|
|
78
61
|
}, [hiddenChipsPopUpRef]);
|
|
79
|
-
(0, _react.useEffect)(
|
|
62
|
+
(0, _react.useEffect)(() => {
|
|
80
63
|
if (showHiddenChips) {
|
|
81
64
|
window.addEventListener('scroll', handleScroll, true);
|
|
82
65
|
}
|
|
83
|
-
return
|
|
84
|
-
return window.removeEventListener('scroll', handleScroll, true);
|
|
85
|
-
};
|
|
66
|
+
return () => window.removeEventListener('scroll', handleScroll, true);
|
|
86
67
|
}, [handleScroll, showHiddenChips]);
|
|
87
|
-
|
|
68
|
+
const resizeChipCell = (0, _react.useCallback)(() => {
|
|
88
69
|
if (hiddenChipsPopUpRef !== null && hiddenChipsPopUpRef !== void 0 && hiddenChipsPopUpRef.current) {
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
var _hiddenChipsCounterRe2;
|
|
71
|
+
const scrollableParent = (0, _getFirstScrollableParent.getFirstScrollableParent)(hiddenChipsCounterRef.current.offsetParent);
|
|
72
|
+
const scrollableParentRect = scrollableParent.getBoundingClientRect();
|
|
73
|
+
const hiddenChipsCounterRect = (_hiddenChipsCounterRe2 = hiddenChipsCounterRef.current) === null || _hiddenChipsCounterRe2 === void 0 ? void 0 : _hiddenChipsCounterRe2.getBoundingClientRect();
|
|
93
74
|
|
|
94
75
|
// Check if the hiddenChipsCounterRect is outside the boundaries of the scrollableParentRect or the window
|
|
95
76
|
if (hiddenChipsCounterRect.left < scrollableParentRect.left || hiddenChipsCounterRect.top < scrollableParentRect.top || hiddenChipsCounterRect.right > scrollableParentRect.right || hiddenChipsCounterRect.bottom > scrollableParentRect.bottom || hiddenChipsCounterRect.right > window.innerWidth || hiddenChipsCounterRect.bottom > window.innerHeight) {
|
|
@@ -98,11 +79,11 @@ var useChipCell = function useChipCell(isEditMode, visibleChipsMaxLength) {
|
|
|
98
79
|
}
|
|
99
80
|
if (!isEditMode && !(0, _common.isEveryObjectValueEmpty)(chipsSizes)) {
|
|
100
81
|
var _chipsCellRef$current;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Object.values(chipsSizes).every(
|
|
82
|
+
const parentSize = (_chipsCellRef$current = chipsCellRef.current) === null || _chipsCellRef$current === void 0 ? void 0 : _chipsCellRef$current.getBoundingClientRect().width;
|
|
83
|
+
let maxLength = 0;
|
|
84
|
+
let chipIndex = 0;
|
|
85
|
+
const padding = 65;
|
|
86
|
+
Object.values(chipsSizes).every((chipSize, index) => {
|
|
106
87
|
// Check if adding chipSize to maxLength exceeds parentSize
|
|
107
88
|
// or if adding chipSize and padding exceeds parentSize when there are multiple chips
|
|
108
89
|
if (maxLength + chipSize > parentSize || Object.values(chipsSizes).length > 1 && maxLength + chipSize + padding > parentSize) {
|
|
@@ -120,31 +101,31 @@ var useChipCell = function useChipCell(isEditMode, visibleChipsMaxLength) {
|
|
|
120
101
|
setShowChips(true);
|
|
121
102
|
}
|
|
122
103
|
}, [chipsSizes, isEditMode]);
|
|
123
|
-
(0, _react.useEffect)(
|
|
104
|
+
(0, _react.useEffect)(() => {
|
|
124
105
|
resizeChipCell();
|
|
125
106
|
}, [resizeChipCell]);
|
|
126
|
-
(0, _react.useEffect)(
|
|
127
|
-
|
|
107
|
+
(0, _react.useEffect)(() => {
|
|
108
|
+
const resizeChipCellDebounced = (0, _lodash.throttle)(resizeChipCell, 500);
|
|
128
109
|
if (!isEditMode) {
|
|
129
110
|
window.addEventListener('resize', resizeChipCellDebounced);
|
|
130
111
|
window.addEventListener(transitionEndEventName, resizeChipCellDebounced);
|
|
131
|
-
return
|
|
112
|
+
return () => {
|
|
132
113
|
window.removeEventListener('resize', resizeChipCellDebounced);
|
|
133
114
|
window.removeEventListener(transitionEndEventName, resizeChipCellDebounced);
|
|
134
115
|
};
|
|
135
116
|
}
|
|
136
117
|
}, [resizeChipCell, isEditMode, transitionEndEventName]);
|
|
137
118
|
return {
|
|
138
|
-
chipsCellRef
|
|
139
|
-
chipsWrapperRef
|
|
140
|
-
handleShowElements
|
|
141
|
-
hiddenChipsCounterRef
|
|
142
|
-
hiddenChipsPopUpRef
|
|
143
|
-
setChipsSizes
|
|
144
|
-
setShowHiddenChips
|
|
145
|
-
showChips
|
|
146
|
-
showHiddenChips
|
|
147
|
-
visibleChipsCount
|
|
119
|
+
chipsCellRef,
|
|
120
|
+
chipsWrapperRef,
|
|
121
|
+
handleShowElements,
|
|
122
|
+
hiddenChipsCounterRef,
|
|
123
|
+
hiddenChipsPopUpRef,
|
|
124
|
+
setChipsSizes,
|
|
125
|
+
setShowHiddenChips,
|
|
126
|
+
showChips,
|
|
127
|
+
showHiddenChips,
|
|
128
|
+
visibleChipsCount
|
|
148
129
|
};
|
|
149
130
|
};
|
|
150
131
|
exports.useChipCell = useChipCell;
|