@spaced-out/ui-design-system 0.1.15 → 0.1.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/CHANGELOG.md +8 -0
- package/lib/components/Avatar/Avatar.module.css +8 -2
- package/lib/components/AvatarGroup/AvatarGroup.js +21 -11
- package/lib/components/AvatarGroup/AvatarGroup.js.flow +9 -3
- package/lib/components/Checkbox/Checkbox.js +15 -10
- package/lib/components/Checkbox/Checkbox.js.flow +121 -100
- package/lib/components/Checkbox/Checkbox.module.css +4 -1
- package/lib/components/Checkbox/CheckboxGroup.js +4 -3
- package/lib/components/Checkbox/CheckboxGroup.js.flow +76 -65
- package/lib/components/RadioButton/RadioButton.js +15 -9
- package/lib/components/RadioButton/RadioButton.js.flow +91 -70
- package/lib/components/RadioButton/RadioButton.module.css +4 -1
- package/lib/components/RadioButton/RadioGroup.js +4 -3
- package/lib/components/RadioButton/RadioGroup.js.flow +56 -47
- package/lib/components/Toast/Toast.js +8 -10
- package/lib/components/Toast/Toast.js.flow +19 -27
- package/lib/components/Toast/Toast.module.css +8 -0
- package/lib/components/Toggle/Toggle.js +11 -7
- package/lib/components/Toggle/Toggle.js.flow +16 -12
- package/lib/components/Toggle/Toggle.module.css +2 -0
- package/lib/utils/click-away.js.flow +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.16](https://github.com/spaced-out/ui-design-system/compare/v0.1.15...v0.1.16) (2023-04-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* avatar img aspect ratio and Checkbox ref forwarding ([#101](https://github.com/spaced-out/ui-design-system/issues/101)) ([f756a98](https://github.com/spaced-out/ui-design-system/commit/f756a9812a7327c04a99d056b36f479425662153))
|
|
11
|
+
* typography component removed from children wrap ([#104](https://github.com/spaced-out/ui-design-system/issues/104)) ([24887c8](https://github.com/spaced-out/ui-design-system/commit/24887c8a505917738e161ae1208dea533cecfab5))
|
|
12
|
+
|
|
5
13
|
### [0.1.15](https://github.com/spaced-out/ui-design-system/compare/v0.1.14...v0.1.15) (2023-04-18)
|
|
6
14
|
|
|
7
15
|
|
|
@@ -13,16 +13,22 @@
|
|
|
13
13
|
.container.largeSize {
|
|
14
14
|
width: size60;
|
|
15
15
|
height: size60;
|
|
16
|
+
min-width: size60;
|
|
17
|
+
min-height: size60;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
.container.mediumSize {
|
|
19
21
|
width: size42;
|
|
20
22
|
height: size42;
|
|
23
|
+
min-width: size42;
|
|
24
|
+
min-height: size42;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
.container.smallSize {
|
|
24
28
|
width: size34;
|
|
25
29
|
height: size34;
|
|
30
|
+
min-width: size34;
|
|
31
|
+
min-height: size34;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
.container.baseLargeSize {
|
|
@@ -48,8 +54,8 @@
|
|
|
48
54
|
|
|
49
55
|
.avatar {
|
|
50
56
|
vertical-align: middle;
|
|
51
|
-
width: sizeFluid;
|
|
52
|
-
height: sizeFluid;
|
|
57
|
+
max-width: sizeFluid;
|
|
58
|
+
max-height: sizeFluid;
|
|
53
59
|
border-radius: borderRadiusCircle;
|
|
54
60
|
display: flex;
|
|
55
61
|
align-items: center;
|
|
@@ -33,17 +33,27 @@ const AvatarGroup = _ref => {
|
|
|
33
33
|
large: _space.spaceXSmall
|
|
34
34
|
};
|
|
35
35
|
let colorIndex = -1;
|
|
36
|
-
const avatarInGroup = (child, index, color) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
const avatarInGroup = (child, index, color) => {
|
|
37
|
+
const {
|
|
38
|
+
classNames
|
|
39
|
+
} = child.props;
|
|
40
|
+
const {
|
|
41
|
+
wrapper,
|
|
42
|
+
...restClassNames
|
|
43
|
+
} = classNames || {};
|
|
44
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
|
45
|
+
size,
|
|
46
|
+
classNames: {
|
|
47
|
+
wrapper: (0, _classify.default)(_AvatarGroupModule.default.avatarInGroup, wrapper),
|
|
48
|
+
...restClassNames
|
|
49
|
+
},
|
|
50
|
+
style: {
|
|
51
|
+
borderColor,
|
|
52
|
+
marginLeft: `-${index !== 0 ? leftOverlap[size] : 0}`
|
|
53
|
+
},
|
|
54
|
+
color
|
|
55
|
+
});
|
|
56
|
+
};
|
|
47
57
|
const childrenArray = React.Children.toArray(children);
|
|
48
58
|
const totalAvatarCount = childrenArray.length;
|
|
49
59
|
const plusAvatar = () => {
|
|
@@ -48,16 +48,22 @@ export const AvatarGroup = ({
|
|
|
48
48
|
|
|
49
49
|
let colorIndex = -1;
|
|
50
50
|
|
|
51
|
-
const avatarInGroup = (child, index, color) =>
|
|
52
|
-
|
|
51
|
+
const avatarInGroup = (child, index, color) => {
|
|
52
|
+
const {classNames} = child.props;
|
|
53
|
+
const {wrapper, ...restClassNames} = classNames || {};
|
|
54
|
+
return React.cloneElement(child, {
|
|
53
55
|
size,
|
|
54
|
-
classNames: {
|
|
56
|
+
classNames: {
|
|
57
|
+
wrapper: classify(css.avatarInGroup, wrapper),
|
|
58
|
+
...restClassNames,
|
|
59
|
+
},
|
|
55
60
|
style: {
|
|
56
61
|
borderColor,
|
|
57
62
|
marginLeft: `-${index !== 0 ? leftOverlap[size] : 0}`,
|
|
58
63
|
},
|
|
59
64
|
color,
|
|
60
65
|
});
|
|
66
|
+
};
|
|
61
67
|
|
|
62
68
|
const childrenArray = React.Children.toArray(children);
|
|
63
69
|
const totalAvatarCount = childrenArray.length;
|
|
@@ -7,13 +7,12 @@ exports.Checkbox = void 0;
|
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
9
9
|
var _Icon = require("../Icon");
|
|
10
|
-
var _Text = require("../Text/Text");
|
|
11
10
|
var _CheckboxModule = _interopRequireDefault(require("./Checkbox.module.css"));
|
|
12
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
13
|
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; }
|
|
15
14
|
|
|
16
|
-
const Checkbox = _ref => {
|
|
15
|
+
const Checkbox = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
17
16
|
let {
|
|
18
17
|
name = 'checkbox',
|
|
19
18
|
value = '',
|
|
@@ -26,9 +25,11 @@ const Checkbox = _ref => {
|
|
|
26
25
|
onChange,
|
|
27
26
|
align,
|
|
28
27
|
classNames,
|
|
29
|
-
tabIndex = 0
|
|
28
|
+
tabIndex = 0,
|
|
29
|
+
ariaLabel = ''
|
|
30
30
|
} = _ref;
|
|
31
31
|
const checkboxInput = /*#__PURE__*/React.createRef();
|
|
32
|
+
React.useImperativeHandle(forwardRef, () => checkboxInput.current);
|
|
32
33
|
const handleOnChange = () => {
|
|
33
34
|
if (!disabled) {
|
|
34
35
|
onChange && onChange({
|
|
@@ -50,17 +51,21 @@ const Checkbox = _ref => {
|
|
|
50
51
|
checkboxInput.current.indeterminate = false;
|
|
51
52
|
}
|
|
52
53
|
}, [indeterminate]);
|
|
53
|
-
|
|
54
|
+
const onClickHandler = () => {
|
|
55
|
+
checkboxInput.current?.click();
|
|
56
|
+
};
|
|
57
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
54
58
|
"data-testid": "checkbox",
|
|
55
59
|
className: (0, _classify.default)(_CheckboxModule.default.checkboxContainer, {
|
|
56
60
|
[_CheckboxModule.default.disabled]: disabled,
|
|
57
61
|
[_CheckboxModule.default.horizontalCheckbox]: align === 'horizontal-fixed',
|
|
58
62
|
[_CheckboxModule.default.fluidCheckbox]: align === 'horizontal-fluid'
|
|
59
|
-
}, classNames?.wrapper)
|
|
63
|
+
}, classNames?.wrapper),
|
|
64
|
+
onClick: onClickHandler
|
|
60
65
|
}, /*#__PURE__*/React.createElement("span", {
|
|
61
66
|
className: (0, _classify.default)(_CheckboxModule.default.checkboxSquare, {
|
|
62
67
|
[_CheckboxModule.default.disabled]: disabled
|
|
63
|
-
})
|
|
68
|
+
}, classNames?.checkboxSquare)
|
|
64
69
|
}, /*#__PURE__*/React.createElement("input", {
|
|
65
70
|
tabIndex: disabled ? -1 : tabIndex,
|
|
66
71
|
type: "checkbox",
|
|
@@ -70,7 +75,8 @@ const Checkbox = _ref => {
|
|
|
70
75
|
onChange: handleOnChange,
|
|
71
76
|
className: (0, _classify.default)(_CheckboxModule.default.inputCheckbox),
|
|
72
77
|
disabled: disabled,
|
|
73
|
-
name: name
|
|
78
|
+
name: name,
|
|
79
|
+
"aria-label": ariaLabel || children
|
|
74
80
|
}), /*#__PURE__*/React.createElement("span", {
|
|
75
81
|
className: (0, _classify.default)(_CheckboxModule.default.checkboxSquareInner, {
|
|
76
82
|
[_CheckboxModule.default.enabled]: !disabled && !error,
|
|
@@ -87,9 +93,8 @@ const Checkbox = _ref => {
|
|
|
87
93
|
name: "check",
|
|
88
94
|
size: "small",
|
|
89
95
|
type: "regular"
|
|
90
|
-
}))), React.Children.count(children) > 0 && /*#__PURE__*/React.createElement(
|
|
91
|
-
color: "secondary",
|
|
96
|
+
}))), React.Children.count(children) > 0 && /*#__PURE__*/React.createElement("div", {
|
|
92
97
|
className: (0, _classify.default)(_CheckboxModule.default.checkboxLabel, classNames?.label)
|
|
93
98
|
}, children));
|
|
94
|
-
};
|
|
99
|
+
});
|
|
95
100
|
exports.Checkbox = Checkbox;
|
|
@@ -5,12 +5,15 @@ import * as React from 'react';
|
|
|
5
5
|
import type {GroupAlign} from '../../types/common';
|
|
6
6
|
import classify from '../../utils/classify';
|
|
7
7
|
import {Icon} from '../Icon';
|
|
8
|
-
import {FormLabelMedium} from '../Text/Text';
|
|
9
8
|
|
|
10
9
|
import css from './Checkbox.module.css';
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
type ClassNames = $ReadOnly<{
|
|
12
|
+
type ClassNames = $ReadOnly<{
|
|
13
|
+
wrapper?: string,
|
|
14
|
+
checkboxSquare?: string,
|
|
15
|
+
label?: string,
|
|
16
|
+
}>;
|
|
14
17
|
|
|
15
18
|
/*
|
|
16
19
|
Note: An indeterminate state has a higher priority.
|
|
@@ -30,111 +33,129 @@ export type CheckboxProps = {
|
|
|
30
33
|
align?: GroupAlign,
|
|
31
34
|
classNames?: ClassNames,
|
|
32
35
|
tabIndex?: number,
|
|
36
|
+
ariaLabel?: string,
|
|
33
37
|
};
|
|
34
38
|
|
|
35
|
-
export const Checkbox
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
export const Checkbox: React$AbstractComponent<
|
|
40
|
+
CheckboxProps,
|
|
41
|
+
HTMLInputElement,
|
|
42
|
+
> = React.forwardRef<CheckboxProps, HTMLInputElement>(
|
|
43
|
+
(
|
|
44
|
+
{
|
|
45
|
+
name = 'checkbox',
|
|
46
|
+
value = '',
|
|
47
|
+
children,
|
|
48
|
+
checked = false,
|
|
49
|
+
indeterminate = false,
|
|
50
|
+
focused = false,
|
|
51
|
+
disabled = false,
|
|
52
|
+
error = false,
|
|
53
|
+
onChange,
|
|
54
|
+
align,
|
|
55
|
+
classNames,
|
|
56
|
+
tabIndex = 0,
|
|
57
|
+
ariaLabel = '',
|
|
58
|
+
}: CheckboxProps,
|
|
59
|
+
forwardRef,
|
|
60
|
+
): React.Node => {
|
|
61
|
+
const checkboxInput = React.createRef<HTMLInputElement>();
|
|
62
|
+
React.useImperativeHandle(forwardRef, () => checkboxInput.current);
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
const handleOnChange = () => {
|
|
65
|
+
if (!disabled) {
|
|
66
|
+
onChange &&
|
|
67
|
+
onChange({
|
|
68
|
+
value,
|
|
69
|
+
checked: !checked,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
60
73
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
if (checkboxInput.current && focused) {
|
|
76
|
+
checkboxInput.current.focus();
|
|
77
|
+
}
|
|
78
|
+
}, [focused]);
|
|
66
79
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (checkboxInput.current && indeterminate) {
|
|
82
|
+
checkboxInput.current.indeterminate = true;
|
|
83
|
+
}
|
|
84
|
+
if (checkboxInput.current && !indeterminate) {
|
|
85
|
+
checkboxInput.current.indeterminate = false;
|
|
86
|
+
}
|
|
87
|
+
}, [indeterminate]);
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
89
|
+
const onClickHandler = () => {
|
|
90
|
+
checkboxInput.current?.click();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div
|
|
95
|
+
data-testid="checkbox"
|
|
96
|
+
className={classify(
|
|
97
|
+
css.checkboxContainer,
|
|
98
|
+
{
|
|
99
|
+
[css.disabled]: disabled,
|
|
100
|
+
[css.horizontalCheckbox]: align === 'horizontal-fixed',
|
|
101
|
+
[css.fluidCheckbox]: align === 'horizontal-fluid',
|
|
102
|
+
},
|
|
103
|
+
classNames?.wrapper,
|
|
104
|
+
)}
|
|
105
|
+
onClick={onClickHandler}
|
|
93
106
|
>
|
|
94
|
-
<input
|
|
95
|
-
tabIndex={disabled ? -1 : tabIndex}
|
|
96
|
-
type="checkbox"
|
|
97
|
-
value={value}
|
|
98
|
-
checked={checked}
|
|
99
|
-
ref={checkboxInput}
|
|
100
|
-
onChange={handleOnChange}
|
|
101
|
-
className={classify(css.inputCheckbox)}
|
|
102
|
-
disabled={disabled}
|
|
103
|
-
name={name}
|
|
104
|
-
/>
|
|
105
107
|
<span
|
|
106
|
-
className={classify(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
{indeterminate && (
|
|
113
|
-
<Icon
|
|
114
|
-
color={disabled ? 'disabled' : 'inversePrimary'}
|
|
115
|
-
name="hyphen"
|
|
116
|
-
size="small"
|
|
117
|
-
type="regular"
|
|
118
|
-
/>
|
|
108
|
+
className={classify(
|
|
109
|
+
css.checkboxSquare,
|
|
110
|
+
{
|
|
111
|
+
[css.disabled]: disabled,
|
|
112
|
+
},
|
|
113
|
+
classNames?.checkboxSquare,
|
|
119
114
|
)}
|
|
120
|
-
{checked && !indeterminate && (
|
|
121
|
-
<Icon
|
|
122
|
-
color={disabled ? 'disabled' : 'inversePrimary'}
|
|
123
|
-
name="check"
|
|
124
|
-
size="small"
|
|
125
|
-
type="regular"
|
|
126
|
-
/>
|
|
127
|
-
)}
|
|
128
|
-
</span>
|
|
129
|
-
</span>
|
|
130
|
-
{React.Children.count(children) > 0 && (
|
|
131
|
-
<FormLabelMedium
|
|
132
|
-
color="secondary"
|
|
133
|
-
className={classify(css.checkboxLabel, classNames?.label)}
|
|
134
115
|
>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
116
|
+
<input
|
|
117
|
+
tabIndex={disabled ? -1 : tabIndex}
|
|
118
|
+
type="checkbox"
|
|
119
|
+
value={value}
|
|
120
|
+
checked={checked}
|
|
121
|
+
ref={checkboxInput}
|
|
122
|
+
onChange={handleOnChange}
|
|
123
|
+
className={classify(css.inputCheckbox)}
|
|
124
|
+
disabled={disabled}
|
|
125
|
+
name={name}
|
|
126
|
+
aria-label={ariaLabel || children}
|
|
127
|
+
/>
|
|
128
|
+
<span
|
|
129
|
+
className={classify(css.checkboxSquareInner, {
|
|
130
|
+
[css.enabled]: !disabled && !error,
|
|
131
|
+
[css.disabled]: disabled,
|
|
132
|
+
[css.error]: error && !disabled,
|
|
133
|
+
})}
|
|
134
|
+
>
|
|
135
|
+
{indeterminate && (
|
|
136
|
+
<Icon
|
|
137
|
+
color={disabled ? 'disabled' : 'inversePrimary'}
|
|
138
|
+
name="hyphen"
|
|
139
|
+
size="small"
|
|
140
|
+
type="regular"
|
|
141
|
+
/>
|
|
142
|
+
)}
|
|
143
|
+
{checked && !indeterminate && (
|
|
144
|
+
<Icon
|
|
145
|
+
color={disabled ? 'disabled' : 'inversePrimary'}
|
|
146
|
+
name="check"
|
|
147
|
+
size="small"
|
|
148
|
+
type="regular"
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
</span>
|
|
152
|
+
</span>
|
|
153
|
+
{React.Children.count(children) > 0 && (
|
|
154
|
+
<div className={classify(css.checkboxLabel, classNames?.label)}>
|
|
155
|
+
{children}
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
);
|
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
.checkboxSquare {
|
|
59
59
|
width: size24;
|
|
60
60
|
height: size24;
|
|
61
|
+
min-width: size24;
|
|
62
|
+
min-height: size24;
|
|
61
63
|
box-sizing: border-box;
|
|
62
64
|
display: flex;
|
|
63
65
|
align-items: center;
|
|
@@ -158,5 +160,6 @@ input[type='checkbox']:checked + .error {
|
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
.checkboxLabel {
|
|
161
|
-
composes:
|
|
163
|
+
composes: formLabelMedium from '../../styles/typography.module.css';
|
|
164
|
+
composes: secondary from '../../styles/typography.module.css';
|
|
162
165
|
}
|
|
@@ -12,7 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
13
|
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; }
|
|
14
14
|
|
|
15
|
-
const CheckboxGroup = _ref => {
|
|
15
|
+
const CheckboxGroup = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
16
16
|
let {
|
|
17
17
|
align = 'vertical',
|
|
18
18
|
disabled = false,
|
|
@@ -72,10 +72,11 @@ const CheckboxGroup = _ref => {
|
|
|
72
72
|
[_CheckboxGroupModule.default.vertical]: align === 'vertical',
|
|
73
73
|
[_CheckboxGroupModule.default.horizontal]: align === 'horizontal-fixed',
|
|
74
74
|
[_CheckboxGroupModule.default.horizontalFluid]: align === 'horizontal-fluid'
|
|
75
|
-
}, classNames?.checkboxGroup)
|
|
75
|
+
}, classNames?.checkboxGroup),
|
|
76
|
+
ref: forwardRef
|
|
76
77
|
}, childrenWithProps), error && /*#__PURE__*/React.createElement(_Text.BodySmall, {
|
|
77
78
|
className: (0, _classify.default)(classNames?.errorText),
|
|
78
79
|
color: "danger"
|
|
79
80
|
}, errorText));
|
|
80
|
-
};
|
|
81
|
+
});
|
|
81
82
|
exports.CheckboxGroup = CheckboxGroup;
|
|
@@ -31,75 +31,86 @@ export type CheckboxGroupProps = {
|
|
|
31
31
|
children?: React.Node,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export const CheckboxGroup
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
export const CheckboxGroup: React$AbstractComponent<
|
|
35
|
+
CheckboxGroupProps,
|
|
36
|
+
HTMLDivElement,
|
|
37
|
+
> = React.forwardRef<CheckboxGroupProps, HTMLDivElement>(
|
|
38
|
+
(
|
|
39
|
+
{
|
|
40
|
+
align = 'vertical',
|
|
41
|
+
disabled = false,
|
|
42
|
+
name,
|
|
43
|
+
value: checkedList,
|
|
44
|
+
onChange,
|
|
45
|
+
classNames,
|
|
46
|
+
error = false,
|
|
47
|
+
errorText = '',
|
|
48
|
+
children,
|
|
49
|
+
}: CheckboxGroupProps,
|
|
50
|
+
forwardRef,
|
|
51
|
+
): React.Node => {
|
|
52
|
+
const onChangeHandler = ({value, checked}) => {
|
|
53
|
+
const checkedListTemp = checkedList ? [...checkedList] : [];
|
|
54
|
+
if (checked && !checkedListTemp.includes(value)) {
|
|
55
|
+
checkedListTemp.push(value);
|
|
56
|
+
} else if (!checked && checkedListTemp.includes(value)) {
|
|
57
|
+
for (let i = 0; i < checkedListTemp.length; i++) {
|
|
58
|
+
if (checkedListTemp[i] === value) {
|
|
59
|
+
checkedListTemp.splice(i, 1);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
64
|
+
onChange && onChange(checkedListTemp);
|
|
65
|
+
};
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
const childrenWithProps = React.Children.map(children, (child) => {
|
|
68
|
+
if (React.isValidElement(child)) {
|
|
69
|
+
const {
|
|
70
|
+
value,
|
|
71
|
+
disabled: disabledChild,
|
|
72
|
+
error: errorChild,
|
|
73
|
+
onChange,
|
|
74
|
+
} = child.props;
|
|
75
|
+
const childOnChange = (...params) => {
|
|
76
|
+
onChangeHandler(...params);
|
|
77
|
+
onChange && onChange(...params);
|
|
78
|
+
};
|
|
79
|
+
return React.cloneElement(child, {
|
|
80
|
+
name,
|
|
81
|
+
checked: !!checkedList?.includes(value),
|
|
82
|
+
onChange: childOnChange,
|
|
83
|
+
align,
|
|
84
|
+
error: errorChild || error,
|
|
85
|
+
disabled: disabledChild || disabled,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return child;
|
|
89
|
+
});
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
<div className={classify(css.checkboxGroupContainer, classNames?.wrapper)}>
|
|
91
|
+
return (
|
|
86
92
|
<div
|
|
87
|
-
className={classify(
|
|
88
|
-
{
|
|
89
|
-
[css.vertical]: align === 'vertical',
|
|
90
|
-
[css.horizontal]: align === 'horizontal-fixed',
|
|
91
|
-
[css.horizontalFluid]: align === 'horizontal-fluid',
|
|
92
|
-
},
|
|
93
|
-
classNames?.checkboxGroup,
|
|
94
|
-
)}
|
|
93
|
+
className={classify(css.checkboxGroupContainer, classNames?.wrapper)}
|
|
95
94
|
>
|
|
96
|
-
|
|
95
|
+
<div
|
|
96
|
+
className={classify(
|
|
97
|
+
{
|
|
98
|
+
[css.vertical]: align === 'vertical',
|
|
99
|
+
[css.horizontal]: align === 'horizontal-fixed',
|
|
100
|
+
[css.horizontalFluid]: align === 'horizontal-fluid',
|
|
101
|
+
},
|
|
102
|
+
classNames?.checkboxGroup,
|
|
103
|
+
)}
|
|
104
|
+
ref={forwardRef}
|
|
105
|
+
>
|
|
106
|
+
{childrenWithProps}
|
|
107
|
+
</div>
|
|
108
|
+
{error && (
|
|
109
|
+
<BodySmall className={classify(classNames?.errorText)} color="danger">
|
|
110
|
+
{errorText}
|
|
111
|
+
</BodySmall>
|
|
112
|
+
)}
|
|
97
113
|
</div>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
</BodySmall>
|
|
102
|
-
)}
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
);
|