iguazio.dashboard-react-controls 1.4.0 → 1.4.1

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.
@@ -11,7 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
  var _reactFinalForm = require("react-final-form");
12
12
  require("./formToggle.scss");
13
13
  var _jsxRuntime = require("react/jsx-runtime");
14
- var _excluded = ["className", "density", "label", "name", "onChange", "readOnly"];
14
+ var _excluded = ["className", "density", "label", "name", "onChange"];
15
15
  /*
16
16
  Copyright 2022 Iguazio Systems Ltd.
17
17
  Licensed under the Apache License, Version 2.0 (the "License") with
@@ -42,19 +42,20 @@ var FormToggle = function FormToggle(_ref) {
42
42
  label = _ref.label,
43
43
  name = _ref.name,
44
44
  _onChange = _ref.onChange,
45
- readOnly = _ref.readOnly,
46
45
  inputProps = _objectWithoutProperties(_ref, _excluded);
47
- var toggleWrapperClassNames = (0, _classnames.default)('form-field__wrapper', "form-field__wrapper-".concat(density));
46
+ var toggleWrapperClassNames = (0, _classnames.default)('form-field__wrapper', density && "form-field__wrapper-".concat(density));
48
47
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
49
48
  name: name,
50
49
  value: inputProps.value,
51
50
  type: "checkbox",
52
51
  children: function children(_ref2) {
53
52
  var input = _ref2.input;
54
- var toggleClassName = (0, _classnames.default)('form-field-toggle', className, readOnly && 'form-field_readonly', input.checked && 'form-field_checked');
55
53
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
56
- className: toggleClassName,
57
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
54
+ className: "form-field-toggle",
55
+ children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
56
+ className: "form-field__label",
57
+ children: label
58
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
58
59
  "data-testid": "toggle",
59
60
  id: name
60
61
  }, _objectSpread(_objectSpread({}, input), inputProps)), {}, {
@@ -63,16 +64,10 @@ var FormToggle = function FormToggle(_ref) {
63
64
  input.onChange(event);
64
65
  },
65
66
  type: "checkbox"
66
- })), label && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
67
- className: "form-field__label",
68
- children: label
69
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
67
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
70
68
  className: toggleWrapperClassNames,
71
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
72
- className: "form-field-toggle__switch",
73
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
74
- className: "form-field-toggle__switch-button"
75
- })
69
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
70
+ className: "form-field-toggle__switch"
76
71
  })
77
72
  })]
78
73
  });
@@ -82,16 +77,14 @@ var FormToggle = function FormToggle(_ref) {
82
77
  FormToggle.defaultProps = {
83
78
  className: '',
84
79
  label: '',
85
- onChange: function onChange() {},
86
- readOnly: false
80
+ onChange: function onChange() {}
87
81
  };
88
82
  FormToggle.propTypes = {
89
83
  className: _propTypes.default.string,
90
84
  density: _propTypes.default.string,
91
85
  label: _propTypes.default.string,
92
86
  name: _propTypes.default.string.isRequired,
93
- onChange: _propTypes.default.func,
94
- readOnly: _propTypes.default.bool
87
+ onChange: _propTypes.default.func
95
88
  };
96
89
  var _default = FormToggle;
97
90
  exports.default = _default;
@@ -4,12 +4,6 @@
4
4
  .form-field-toggle {
5
5
  position: relative;
6
6
 
7
- input[type='checkbox'] {
8
- display: none;
9
- width: 0;
10
- height: 0;
11
- }
12
-
13
7
  &__switch {
14
8
  height: 24px;
15
9
  width: 48px;
@@ -20,7 +14,8 @@
20
14
  border-radius: 20px;
21
15
  transition: all 0.2s ease;
22
16
 
23
- &-button {
17
+ &:before {
18
+ content: '';
24
19
  width: 20px;
25
20
  height: 20px;
26
21
  background-color: $white;
@@ -36,31 +31,27 @@
36
31
  &__wrapper {
37
32
  border: none;
38
33
  }
34
+ }
39
35
 
40
- &_readonly {
41
- opacity: 0.5;
42
- pointer-events: none;
36
+ input[type='checkbox'] {
37
+ display: none;
38
+ width: 0;
39
+ height: 0;
43
40
 
44
- .form-field-toggle__switch {
41
+ &:disabled {
42
+ & + * .form-field-toggle__switch {
43
+ opacity: 0.5;
44
+ pointer-events: none;
45
45
  cursor: default;
46
46
  }
47
-
48
- &.form-field-toggle_checked {
49
- .form-field-toggle__switch {
50
- &-button {
51
- opacity: 0.5;
52
- }
53
- }
54
- }
55
47
  }
56
- }
57
48
 
58
- &.form-field_checked {
59
- .form-field-toggle__switch {
60
- background-color: $malibu;
61
-
62
- &-button {
63
- transform: translateX(26px);
49
+ &:checked {
50
+ & + * .form-field-toggle__switch {
51
+ background-color: $malibu;
52
+ &:before {
53
+ transform: translateX(26px);
54
+ }
64
55
  }
65
56
  }
66
57
  }
@@ -57,6 +57,7 @@ var Wizard = function Wizard(_ref) {
57
57
  title = _ref.title,
58
58
  stepsConfig = _ref.stepsConfig,
59
59
  submitButtonLabel = _ref.submitButtonLabel;
60
+ var wizardClasses = (0, _classnames.default)('wizard-form', className);
60
61
  var _useState = (0, _react.useState)(0),
61
62
  _useState2 = _slicedToArray(_useState, 2),
62
63
  activeStepNumber = _useState2[0],
@@ -78,11 +79,14 @@ var Wizard = function Wizard(_ref) {
78
79
  }).map(function (step) {
79
80
  return {
80
81
  id: step.id,
81
- label: step.label
82
+ label: step.label,
83
+ disabled: step.disabled
82
84
  };
83
85
  })) || [];
84
86
  }, [stepsConfig]);
85
- var wizardClasses = (0, _classnames.default)('wizard-form', className);
87
+ var nextStepIsInvalid = (0, _react.useMemo)(function () {
88
+ return formState.submitting || formState.invalid && formState.submitFailed;
89
+ }, [formState.invalid, formState.submitFailed, formState.submitting]);
86
90
  var goToNextStep = function goToNextStep() {
87
91
  setActiveStepNumber(function (prevStep) {
88
92
  return Math.min(++prevStep, totalSteps);
@@ -114,7 +118,7 @@ var Wizard = function Wizard(_ref) {
114
118
  type: "button"
115
119
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
116
120
  onClick: handleSubmit,
117
- disabled: formState.submitting || formState.invalid && formState.submitFailed,
121
+ disabled: nextStepIsInvalid,
118
122
  label: isLastStep ? submitButtonLabel : 'Next',
119
123
  type: "button",
120
124
  variant: _constants.SECONDARY_BUTTON
@@ -150,7 +154,9 @@ var Wizard = function Wizard(_ref) {
150
154
  title: title,
151
155
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_WizardSteps.default, {
152
156
  activeStepNumber: activeStepNumber,
157
+ handleSubmit: handleSubmit,
153
158
  jumpToStep: jumpToStep,
159
+ nextStepIsInvalid: nextStepIsInvalid,
154
160
  steps: stepsMenu
155
161
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
156
162
  className: "wizard-form__content-container",
@@ -31,23 +31,31 @@ such restriction.
31
31
 
32
32
  var WizardSteps = function WizardSteps(_ref) {
33
33
  var activeStepNumber = _ref.activeStepNumber,
34
+ handleSubmit = _ref.handleSubmit,
34
35
  jumpToStep = _ref.jumpToStep,
36
+ nextStepIsInvalid = _ref.nextStepIsInvalid,
35
37
  steps = _ref.steps;
36
- var getStepClassNames = function getStepClassNames(idx) {
37
- return (0, _classnames.default)('wizard-steps__item', idx === activeStepNumber && 'active', idx < activeStepNumber && 'valid');
38
+ var getStepClassNames = function getStepClassNames(idx, stepIsInvalid) {
39
+ return (0, _classnames.default)('wizard-steps__item', idx === activeStepNumber && 'active', !stepIsInvalid && 'valid');
38
40
  };
39
41
  var handleJumpToStep = function handleJumpToStep(event, idx) {
40
42
  event.preventDefault();
41
- jumpToStep(idx);
43
+ if (idx === activeStepNumber + 1) {
44
+ handleSubmit();
45
+ } else {
46
+ jumpToStep(idx);
47
+ }
42
48
  };
43
49
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
44
50
  className: "wizard-steps",
45
51
  children: steps.map(function (_ref2, idx) {
46
52
  var id = _ref2.id,
47
- label = _ref2.label;
53
+ label = _ref2.label,
54
+ disabled = _ref2.disabled;
55
+ var stepIsInvalid = idx > activeStepNumber + 1 || idx === activeStepNumber + 1 && (nextStepIsInvalid || disabled);
48
56
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
49
- className: getStepClassNames(idx),
50
- disabled: idx > activeStepNumber,
57
+ className: getStepClassNames(idx, stepIsInvalid),
58
+ disabled: stepIsInvalid,
51
59
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
52
60
  className: "wizard-steps__indicator",
53
61
  children: idx + 1
@@ -62,7 +70,9 @@ var WizardSteps = function WizardSteps(_ref) {
62
70
  };
63
71
  WizardSteps.propTypes = {
64
72
  activeStepNumber: _propTypes.default.number.isRequired,
73
+ handleSubmit: _propTypes.default.func.isRequired,
65
74
  jumpToStep: _propTypes.default.func.isRequired,
75
+ nextStepIsInvalid: _propTypes.default.bool.isRequired,
66
76
  steps: _types.WIZARD_STEPS_CONFIG
67
77
  };
68
78
  var _default = WizardSteps;
@@ -43,6 +43,16 @@
43
43
  }
44
44
  }
45
45
 
46
+ &.valid {
47
+ color: $primary;
48
+
49
+ .wizard-steps__indicator {
50
+ border-color: $malibu;
51
+ color: $malibu;
52
+ background-color: inherit;
53
+ }
54
+ }
55
+
46
56
  &.active {
47
57
  background-color: $malibuTwo;
48
58
  color: $cornflowerBlue;
@@ -54,16 +64,6 @@
54
64
  }
55
65
  }
56
66
 
57
- &.valid {
58
- color: $primary;
59
-
60
- .wizard-steps__indicator {
61
- border-color: $malibu;
62
- color: $malibu;
63
- background-color: inherit;
64
- }
65
- }
66
-
67
67
  &:disabled {
68
68
  border: 0;
69
69
  color: $spunPearl;
@@ -43,10 +43,13 @@ var FormRowActions = function FormRowActions(_ref) {
43
43
  discardOrDelete = _ref.discardOrDelete,
44
44
  editingItem = _ref.editingItem,
45
45
  fieldsPath = _ref.fieldsPath,
46
+ hidden = _ref.hidden,
46
47
  index = _ref.index;
47
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
48
- children: (editingItem === null || editingItem === void 0 ? void 0 : (_editingItem$ui = editingItem.ui) === null || _editingItem$ui === void 0 ? void 0 : _editingItem$ui.index) === index ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
49
- className: "form-table__cell form-table__actions-cell",
48
+ return hidden ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
49
+ className: "form-table__cell form-table__actions-cell"
50
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
51
+ className: "form-table__cell form-table__actions-cell",
52
+ children: (editingItem === null || editingItem === void 0 ? void 0 : (_editingItem$ui = editingItem.ui) === null || _editingItem$ui === void 0 ? void 0 : _editingItem$ui.index) === index ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
50
53
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
51
54
  onClick: function onClick(event) {
52
55
  return applyChanges(event, index);
@@ -62,8 +65,7 @@ var FormRowActions = function FormRowActions(_ref) {
62
65
  disabled: disabled,
63
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, {})
64
67
  })]
65
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
66
- className: "form-table__cell form-table__actions-cell",
68
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
67
69
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
68
70
  onClick: function onClick(event) {
69
71
  event.preventDefault();
@@ -85,7 +87,8 @@ var FormRowActions = function FormRowActions(_ref) {
85
87
  FormRowActions.defaultProps = {
86
88
  deleteIsDisabled: false,
87
89
  disabled: false,
88
- editingItem: null
90
+ editingItem: null,
91
+ hidden: false
89
92
  };
90
93
  FormRowActions.propTypes = {
91
94
  applyChanges: _propTypes.default.func.isRequired,
@@ -95,6 +98,7 @@ FormRowActions.propTypes = {
95
98
  discardOrDelete: _propTypes.default.func.isRequired,
96
99
  editingItem: _types.FORM_TABLE_EDITING_ITEM,
97
100
  fieldsPath: _propTypes.default.string.isRequired,
101
+ hidden: _propTypes.default.bool,
98
102
  index: _propTypes.default.number.isRequired
99
103
  };
100
104
  var _default = FormRowActions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iguazio.dashboard-react-controls",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Collection of resources (such as CSS styles, fonts and images) and ReactJS 17.x components to share among different Iguazio React repos.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",