iglooform 2.5.48 → 2.5.49
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/es/checkbox/index.d.ts +1 -0
- package/es/checkbox/index.js +43 -21
- package/es/utils/option-utils.js +1 -0
- package/lib/checkbox/index.d.ts +1 -0
- package/lib/checkbox/index.js +43 -20
- package/lib/utils/option-utils.js +1 -0
- package/package.json +1 -1
package/es/checkbox/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface IProps extends IglooComponentProps, Omit<CheckboxGroupProps, 'o
|
|
|
16
16
|
radioType?: string;
|
|
17
17
|
options: Option[];
|
|
18
18
|
preview?: boolean;
|
|
19
|
+
mutuallyExclusions?: Record<string, string[]>;
|
|
19
20
|
}
|
|
20
21
|
declare const IglooCheckbox: FC<Props>;
|
|
21
22
|
export default IglooCheckbox;
|
package/es/checkbox/index.js
CHANGED
|
@@ -4,8 +4,9 @@ import "antd/es/row/style";
|
|
|
4
4
|
import _Row from "antd/es/row";
|
|
5
5
|
import "antd/es/checkbox/style";
|
|
6
6
|
import _Checkbox from "antd/es/checkbox";
|
|
7
|
-
var _excluded = ["
|
|
8
|
-
_excluded2 = ["
|
|
7
|
+
var _excluded = ["value"],
|
|
8
|
+
_excluded2 = ["className", "options", "value", "clearWhenOptionsUpdated", "preview", "mutuallyExclusions"],
|
|
9
|
+
_excluded3 = ["label", "value", "extraInfo"];
|
|
9
10
|
|
|
10
11
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
12
|
|
|
@@ -19,16 +20,16 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
19
20
|
|
|
20
21
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
22
|
|
|
22
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
23
|
-
|
|
24
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
25
|
-
|
|
26
23
|
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; }
|
|
27
24
|
|
|
28
25
|
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; }
|
|
29
26
|
|
|
30
27
|
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; }
|
|
31
28
|
|
|
29
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
30
|
+
|
|
31
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
32
|
+
|
|
32
33
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
33
34
|
import { useState, useEffect, useRef, useContext } from 'react';
|
|
34
35
|
import Typography from '../typography';
|
|
@@ -38,7 +39,27 @@ import classnames from 'classnames';
|
|
|
38
39
|
import { compareOptions, optionsHOC, previewSelectedOptions } from '../utils/option-utils';
|
|
39
40
|
import LocaleContext from '../locale/locale-context';
|
|
40
41
|
import emptyIcon from '../radio/style/empty.svg';
|
|
41
|
-
import './style/index.less';
|
|
42
|
+
import './style/index.less'; // add disabled attributes to checkbox options based on mutually exclusion config
|
|
43
|
+
|
|
44
|
+
var addDisabledAttr = function addDisabledAttr(options, mutuallyExclusions, checkedValues) {
|
|
45
|
+
if (!mutuallyExclusions || !checkedValues) return options;
|
|
46
|
+
checkedValues = Array.isArray(checkedValues) ? checkedValues : [checkedValues];
|
|
47
|
+
return options.map(function (_ref) {
|
|
48
|
+
var _checkedValues;
|
|
49
|
+
|
|
50
|
+
var value = _ref.value,
|
|
51
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
52
|
+
|
|
53
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
54
|
+
value: value,
|
|
55
|
+
disabled: !!value && !!((_checkedValues = checkedValues) === null || _checkedValues === void 0 ? void 0 : _checkedValues.some(function (v) {
|
|
56
|
+
var _mutuallyExclusions$S, _mutuallyExclusions$v;
|
|
57
|
+
|
|
58
|
+
return ((_mutuallyExclusions$S = mutuallyExclusions[String(v)]) === null || _mutuallyExclusions$S === void 0 ? void 0 : _mutuallyExclusions$S.includes(String(value))) || ((_mutuallyExclusions$v = mutuallyExclusions[value]) === null || _mutuallyExclusions$v === void 0 ? void 0 : _mutuallyExclusions$v.includes(String(v)));
|
|
59
|
+
}))
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
42
63
|
|
|
43
64
|
var IglooCheckbox = function IglooCheckbox(props) {
|
|
44
65
|
return _jsx(_Checkbox, _objectSpread({}, omit(props, formMethods)));
|
|
@@ -55,15 +76,16 @@ IglooCheckbox.formItemPropsHandler = function (config) {
|
|
|
55
76
|
|
|
56
77
|
export default IglooCheckbox;
|
|
57
78
|
|
|
58
|
-
var InnerCheckboxGroup = function InnerCheckboxGroup(
|
|
59
|
-
var className =
|
|
60
|
-
|
|
61
|
-
options =
|
|
62
|
-
value =
|
|
63
|
-
|
|
64
|
-
clearWhenOptionsUpdated =
|
|
65
|
-
preview =
|
|
66
|
-
|
|
79
|
+
var InnerCheckboxGroup = function InnerCheckboxGroup(_ref2) {
|
|
80
|
+
var className = _ref2.className,
|
|
81
|
+
_ref2$options = _ref2.options,
|
|
82
|
+
options = _ref2$options === void 0 ? [] : _ref2$options,
|
|
83
|
+
value = _ref2.value,
|
|
84
|
+
_ref2$clearWhenOption = _ref2.clearWhenOptionsUpdated,
|
|
85
|
+
clearWhenOptionsUpdated = _ref2$clearWhenOption === void 0 ? false : _ref2$clearWhenOption,
|
|
86
|
+
preview = _ref2.preview,
|
|
87
|
+
mutuallyExclusions = _ref2.mutuallyExclusions,
|
|
88
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
67
89
|
|
|
68
90
|
var _useState = useState(value),
|
|
69
91
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -106,11 +128,11 @@ var InnerCheckboxGroup = function InnerCheckboxGroup(_ref) {
|
|
|
106
128
|
value: value,
|
|
107
129
|
children: [_jsx(_Row, {
|
|
108
130
|
gutter: [8, 8],
|
|
109
|
-
children: options.map(function (
|
|
110
|
-
var label =
|
|
111
|
-
key =
|
|
112
|
-
extraInfo =
|
|
113
|
-
rest = _objectWithoutProperties(
|
|
131
|
+
children: addDisabledAttr(options, mutuallyExclusions, value).map(function (_ref3) {
|
|
132
|
+
var label = _ref3.label,
|
|
133
|
+
key = _ref3.value,
|
|
134
|
+
extraInfo = _ref3.extraInfo,
|
|
135
|
+
rest = _objectWithoutProperties(_ref3, _excluded3);
|
|
114
136
|
|
|
115
137
|
return _jsxs(_Col, {
|
|
116
138
|
span: 24,
|
package/es/utils/option-utils.js
CHANGED
package/lib/checkbox/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface IProps extends IglooComponentProps, Omit<CheckboxGroupProps, 'o
|
|
|
16
16
|
radioType?: string;
|
|
17
17
|
options: Option[];
|
|
18
18
|
preview?: boolean;
|
|
19
|
+
mutuallyExclusions?: Record<string, string[]>;
|
|
19
20
|
}
|
|
20
21
|
declare const IglooCheckbox: FC<Props>;
|
|
21
22
|
export default IglooCheckbox;
|
package/lib/checkbox/index.js
CHANGED
|
@@ -37,8 +37,9 @@ var _empty = _interopRequireDefault(require("../radio/style/empty.svg"));
|
|
|
37
37
|
|
|
38
38
|
require("./style/index.less");
|
|
39
39
|
|
|
40
|
-
var _excluded = ["
|
|
41
|
-
_excluded2 = ["
|
|
40
|
+
var _excluded = ["value"],
|
|
41
|
+
_excluded2 = ["className", "options", "value", "clearWhenOptionsUpdated", "preview", "mutuallyExclusions"],
|
|
42
|
+
_excluded3 = ["label", "value", "extraInfo"];
|
|
42
43
|
|
|
43
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
44
45
|
|
|
@@ -54,16 +55,37 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
54
55
|
|
|
55
56
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
56
57
|
|
|
57
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
58
|
-
|
|
59
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
60
|
-
|
|
61
58
|
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; }
|
|
62
59
|
|
|
63
60
|
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; }
|
|
64
61
|
|
|
65
62
|
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; }
|
|
66
63
|
|
|
64
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
65
|
+
|
|
66
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
67
|
+
|
|
68
|
+
// add disabled attributes to checkbox options based on mutually exclusion config
|
|
69
|
+
var addDisabledAttr = function addDisabledAttr(options, mutuallyExclusions, checkedValues) {
|
|
70
|
+
if (!mutuallyExclusions || !checkedValues) return options;
|
|
71
|
+
checkedValues = Array.isArray(checkedValues) ? checkedValues : [checkedValues];
|
|
72
|
+
return options.map(function (_ref) {
|
|
73
|
+
var _checkedValues;
|
|
74
|
+
|
|
75
|
+
var value = _ref.value,
|
|
76
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
77
|
+
|
|
78
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
79
|
+
value: value,
|
|
80
|
+
disabled: !!value && !!((_checkedValues = checkedValues) === null || _checkedValues === void 0 ? void 0 : _checkedValues.some(function (v) {
|
|
81
|
+
var _mutuallyExclusions$S, _mutuallyExclusions$v;
|
|
82
|
+
|
|
83
|
+
return ((_mutuallyExclusions$S = mutuallyExclusions[String(v)]) === null || _mutuallyExclusions$S === void 0 ? void 0 : _mutuallyExclusions$S.includes(String(value))) || ((_mutuallyExclusions$v = mutuallyExclusions[value]) === null || _mutuallyExclusions$v === void 0 ? void 0 : _mutuallyExclusions$v.includes(String(v)));
|
|
84
|
+
}))
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
67
89
|
var IglooCheckbox = function IglooCheckbox(props) {
|
|
68
90
|
return (0, _jsxRuntime.jsx)(_checkbox.default, _objectSpread({}, (0, _omit.default)(props, _formMethods.default)));
|
|
69
91
|
};
|
|
@@ -80,15 +102,16 @@ IglooCheckbox.formItemPropsHandler = function (config) {
|
|
|
80
102
|
var _default = IglooCheckbox;
|
|
81
103
|
exports.default = _default;
|
|
82
104
|
|
|
83
|
-
var InnerCheckboxGroup = function InnerCheckboxGroup(
|
|
84
|
-
var className =
|
|
85
|
-
|
|
86
|
-
options =
|
|
87
|
-
value =
|
|
88
|
-
|
|
89
|
-
clearWhenOptionsUpdated =
|
|
90
|
-
preview =
|
|
91
|
-
|
|
105
|
+
var InnerCheckboxGroup = function InnerCheckboxGroup(_ref2) {
|
|
106
|
+
var className = _ref2.className,
|
|
107
|
+
_ref2$options = _ref2.options,
|
|
108
|
+
options = _ref2$options === void 0 ? [] : _ref2$options,
|
|
109
|
+
value = _ref2.value,
|
|
110
|
+
_ref2$clearWhenOption = _ref2.clearWhenOptionsUpdated,
|
|
111
|
+
clearWhenOptionsUpdated = _ref2$clearWhenOption === void 0 ? false : _ref2$clearWhenOption,
|
|
112
|
+
preview = _ref2.preview,
|
|
113
|
+
mutuallyExclusions = _ref2.mutuallyExclusions,
|
|
114
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
92
115
|
|
|
93
116
|
var _useState = (0, _react.useState)(value),
|
|
94
117
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -131,11 +154,11 @@ var InnerCheckboxGroup = function InnerCheckboxGroup(_ref) {
|
|
|
131
154
|
value: value,
|
|
132
155
|
children: [(0, _jsxRuntime.jsx)(_row.default, {
|
|
133
156
|
gutter: [8, 8],
|
|
134
|
-
children: options.map(function (
|
|
135
|
-
var label =
|
|
136
|
-
key =
|
|
137
|
-
extraInfo =
|
|
138
|
-
rest = _objectWithoutProperties(
|
|
157
|
+
children: addDisabledAttr(options, mutuallyExclusions, value).map(function (_ref3) {
|
|
158
|
+
var label = _ref3.label,
|
|
159
|
+
key = _ref3.value,
|
|
160
|
+
extraInfo = _ref3.extraInfo,
|
|
161
|
+
rest = _objectWithoutProperties(_ref3, _excluded3);
|
|
139
162
|
|
|
140
163
|
return (0, _jsxRuntime.jsxs)(_col.default, {
|
|
141
164
|
span: 24,
|