@carbon/react 1.6.0 → 1.8.0-rc.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/es/components/ComposedModal/ComposedModal.js +1 -1
- package/es/components/ComposedModal/index.js +4 -4
- package/es/components/DataTable/DataTable.js +1 -1
- package/es/components/DataTable/Table.js +10 -2
- package/es/components/DataTable/TableContainer.js +20 -5
- package/es/components/DataTable/TableContext.js +15 -0
- package/es/components/DataTable/TableSelectRow.js +1 -1
- package/es/components/FileUploader/FileUploader.js +8 -1
- package/es/components/FileUploader/FileUploaderButton.js +3 -1
- package/es/components/FileUploader/FileUploaderDropContainer.js +3 -1
- package/es/components/FileUploader/FileUploaderItem.js +3 -1
- package/es/components/Form/Form.js +1 -1
- package/es/components/FormGroup/FormGroup.js +4 -4
- package/es/components/FormItem/FormItem.js +5 -6
- package/es/components/InlineLoading/InlineLoading.js +9 -5
- package/es/components/Loading/Loading.js +7 -18
- package/es/components/MultiSelect/FilterableMultiSelect.js +345 -386
- package/es/components/MultiSelect/index.js +4 -8
- package/es/components/Notification/Notification.js +322 -189
- package/es/components/Popover/index.js +137 -8
- package/es/components/ProgressBar/ProgressBar.js +6 -3
- package/es/components/RadioButton/RadioButton.js +58 -99
- package/es/components/RadioButton/index.js +2 -8
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +72 -121
- package/es/components/RadioButtonGroup/index.js +2 -8
- package/es/components/Select/Select.js +14 -7
- package/es/components/Slider/Slider.js +2 -1
- package/es/components/Switch/Switch.js +0 -1
- package/es/components/TreeView/TreeView.js +19 -11
- package/es/components/UIShell/HeaderMenu.js +1 -1
- package/es/components/UIShell/HeaderMenuButton.js +4 -0
- package/es/components/UIShell/SideNavDetails.js +8 -3
- package/es/components/UIShell/SideNavLink.js +6 -9
- package/es/index.js +7 -6
- package/es/internal/createClassWrapper.js +2 -5
- package/lib/components/ComposedModal/index.js +7 -7
- package/lib/components/DataTable/DataTable.js +5 -5
- package/lib/components/DataTable/Table.js +9 -1
- package/lib/components/DataTable/TableContainer.js +19 -4
- package/lib/components/DataTable/TableContext.js +19 -0
- package/lib/components/DataTable/TableSelectRow.js +2 -2
- package/lib/components/FileUploader/FileUploader.js +8 -1
- package/lib/components/FileUploader/FileUploaderButton.js +3 -1
- package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -1
- package/lib/components/FileUploader/FileUploaderItem.js +3 -1
- package/lib/components/Form/Form.js +1 -1
- package/lib/components/FormGroup/FormGroup.js +4 -4
- package/lib/components/FormItem/FormItem.js +5 -6
- package/lib/components/InlineLoading/InlineLoading.js +9 -5
- package/lib/components/Loading/Loading.js +6 -17
- package/lib/components/MultiSelect/FilterableMultiSelect.js +341 -382
- package/lib/components/MultiSelect/index.js +5 -28
- package/lib/components/Notification/Notification.js +321 -188
- package/lib/components/Popover/index.js +135 -6
- package/lib/components/ProgressBar/ProgressBar.js +6 -3
- package/lib/components/RadioButton/RadioButton.js +57 -99
- package/lib/components/RadioButton/index.js +2 -25
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +68 -117
- package/lib/components/RadioButtonGroup/index.js +2 -25
- package/lib/components/Select/Select.js +14 -7
- package/lib/components/Slider/Slider.js +2 -1
- package/lib/components/Switch/Switch.js +0 -1
- package/lib/components/TreeView/TreeView.js +18 -10
- package/lib/components/UIShell/HeaderMenu.js +1 -0
- package/lib/components/UIShell/HeaderMenuButton.js +4 -0
- package/lib/components/UIShell/SideNavDetails.js +8 -3
- package/lib/components/UIShell/SideNavLink.js +6 -9
- package/lib/index.js +83 -83
- package/lib/internal/createClassWrapper.js +2 -5
- package/package.json +8 -8
- package/es/components/MultiSelect/next/FilterableMultiSelect.js +0 -542
- package/es/components/Notification/index.js +0 -42
- package/es/components/Notification/next/Notification.js +0 -663
- package/es/components/RadioButton/next/RadioButton.js +0 -130
- package/es/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -141
- package/lib/components/MultiSelect/next/FilterableMultiSelect.js +0 -554
- package/lib/components/Notification/index.js +0 -51
- package/lib/components/Notification/next/Notification.js +0 -677
- package/lib/components/RadioButton/next/RadioButton.js +0 -140
- package/lib/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -151
|
@@ -5,21 +5,30 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
8
|
+
import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import cx from 'classnames';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
|
-
import React__default from 'react';
|
|
11
|
+
import React__default, { useRef, useMemo, useState } from 'react';
|
|
12
|
+
import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
|
|
13
|
+
import { useMergedRefs } from '../../internal/useMergedRefs.js';
|
|
12
14
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
13
15
|
|
|
14
|
-
var _excluded = ["align", "as", "caret", "className", "children", "dropShadow", "highContrast", "open"],
|
|
16
|
+
var _excluded = ["align", "as", "autoAlign", "caret", "className", "children", "dropShadow", "highContrast", "open"],
|
|
15
17
|
_excluded2 = ["className", "children"];
|
|
16
|
-
var
|
|
18
|
+
var PopoverContext = /*#__PURE__*/React__default.createContext({
|
|
19
|
+
floating: {
|
|
20
|
+
current: null
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, forwardRef) {
|
|
17
24
|
var _cx;
|
|
18
25
|
|
|
19
26
|
var _props$align = props.align,
|
|
20
27
|
align = _props$align === void 0 ? 'bottom' : _props$align,
|
|
21
28
|
_props$as = props.as,
|
|
22
29
|
BaseComponent = _props$as === void 0 ? 'span' : _props$as,
|
|
30
|
+
_props$autoAlign = props.autoAlign,
|
|
31
|
+
autoAlign = _props$autoAlign === void 0 ? false : _props$autoAlign,
|
|
23
32
|
_props$caret = props.caret,
|
|
24
33
|
caret = _props$caret === void 0 ? true : _props$caret,
|
|
25
34
|
customClassName = props.className,
|
|
@@ -32,11 +41,121 @@ var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, ref
|
|
|
32
41
|
rest = _objectWithoutProperties(props, _excluded);
|
|
33
42
|
|
|
34
43
|
var prefix = usePrefix();
|
|
35
|
-
var
|
|
36
|
-
|
|
44
|
+
var floating = useRef();
|
|
45
|
+
var popover = useRef();
|
|
46
|
+
var value = useMemo(function () {
|
|
47
|
+
return {
|
|
48
|
+
floating: floating
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
var ref = useMergedRefs([forwardRef, popover]);
|
|
52
|
+
|
|
53
|
+
var _useState = useState(false),
|
|
54
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
55
|
+
autoAligned = _useState2[0],
|
|
56
|
+
setAutoAligned = _useState2[1];
|
|
57
|
+
|
|
58
|
+
var _useState3 = useState(align),
|
|
59
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
60
|
+
autoAlignment = _useState4[0],
|
|
61
|
+
setAutoAlignment = _useState4[1];
|
|
62
|
+
|
|
63
|
+
var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(autoAlignment), autoAligned), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), !autoAligned), _defineProperty(_cx, customClassName, !!customClassName), _cx));
|
|
64
|
+
useIsomorphicEffect(function () {
|
|
65
|
+
if (!autoAlign) {
|
|
66
|
+
setAutoAligned(false);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!floating.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (autoAligned === true) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var rect = floating.current.getBoundingClientRect(); // The conditions, per side, of when the popover is not visible, excluding the popover's internal padding(16)
|
|
79
|
+
|
|
80
|
+
var conditions = {
|
|
81
|
+
left: rect.x < -16,
|
|
82
|
+
top: rect.y < -16,
|
|
83
|
+
right: rect.x + (rect.width - 16) > document.documentElement.clientWidth,
|
|
84
|
+
bottom: rect.y + (rect.height - 16) > document.documentElement.clientHeight
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (!conditions.left && !conditions.top && !conditions.right && !conditions.bottom) {
|
|
88
|
+
setAutoAligned(false);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var alignments = ['top', 'top-left', 'right-bottom', 'right', 'right-top', 'bottom-left', 'bottom', 'bottom-right', 'left-top', 'left', 'left-bottom', 'top-right']; // Creates the prioritized list of options depending on ideal alignment coming from `align`
|
|
93
|
+
|
|
94
|
+
var options = [align];
|
|
95
|
+
var option = alignments[(alignments.indexOf(align) + 1) % alignments.length];
|
|
96
|
+
|
|
97
|
+
while (option) {
|
|
98
|
+
if (options.includes(option)) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
options.push(option);
|
|
103
|
+
option = alignments[(alignments.indexOf(option) + 1) % alignments.length];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isVisible(alignment) {
|
|
107
|
+
popover.current.classList.add("".concat(prefix, "--popover--").concat(alignment));
|
|
108
|
+
var rect = floating.current.getBoundingClientRect(); // Check if popover is not visible to the left of the screen
|
|
109
|
+
|
|
110
|
+
if (rect.x < -16) {
|
|
111
|
+
popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
|
|
112
|
+
return false;
|
|
113
|
+
} // Check if popover is not visible at the top of the screen
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if (rect.y < -16) {
|
|
117
|
+
popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
|
|
118
|
+
return false;
|
|
119
|
+
} // Check if popover is not visible to right of screen
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if (rect.x + (rect.width - 16) > document.documentElement.clientWidth) {
|
|
123
|
+
popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
|
|
124
|
+
return false;
|
|
125
|
+
} // Check if popover is not visible to bottom of screen
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if (rect.y + (rect.height - 16) > document.documentElement.clientHeight) {
|
|
129
|
+
popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var alignment = null;
|
|
138
|
+
|
|
139
|
+
for (var i = 0; i < options.length; i++) {
|
|
140
|
+
var _option = options[i];
|
|
141
|
+
|
|
142
|
+
if (isVisible(_option)) {
|
|
143
|
+
alignment = _option;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (alignment) {
|
|
149
|
+
setAutoAligned(true);
|
|
150
|
+
setAutoAlignment(alignment);
|
|
151
|
+
}
|
|
152
|
+
}, [autoAligned, align, autoAlign, prefix]);
|
|
153
|
+
return /*#__PURE__*/React__default.createElement(PopoverContext.Provider, {
|
|
154
|
+
value: value
|
|
155
|
+
}, /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
|
|
37
156
|
className: className,
|
|
38
157
|
ref: ref
|
|
39
|
-
}), children);
|
|
158
|
+
}), children));
|
|
40
159
|
}); // Note: this displayName is temporarily set so that Storybook ArgTable
|
|
41
160
|
// correctly displays the name of this component
|
|
42
161
|
|
|
@@ -56,6 +175,11 @@ Popover.propTypes = {
|
|
|
56
175
|
*/
|
|
57
176
|
as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
|
|
58
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to futurue changes.
|
|
180
|
+
*/
|
|
181
|
+
autoAlign: PropTypes.bool,
|
|
182
|
+
|
|
59
183
|
/**
|
|
60
184
|
* Specify whether a caret should be rendered
|
|
61
185
|
*/
|
|
@@ -87,12 +211,17 @@ Popover.propTypes = {
|
|
|
87
211
|
*/
|
|
88
212
|
open: PropTypes.bool.isRequired
|
|
89
213
|
};
|
|
90
|
-
var PopoverContent = /*#__PURE__*/React__default.forwardRef(function PopoverContent(_ref,
|
|
214
|
+
var PopoverContent = /*#__PURE__*/React__default.forwardRef(function PopoverContent(_ref, forwardRef) {
|
|
91
215
|
var className = _ref.className,
|
|
92
216
|
children = _ref.children,
|
|
93
217
|
rest = _objectWithoutProperties(_ref, _excluded2);
|
|
94
218
|
|
|
95
219
|
var prefix = usePrefix();
|
|
220
|
+
|
|
221
|
+
var _React$useContext = React__default.useContext(PopoverContext),
|
|
222
|
+
floating = _React$useContext.floating;
|
|
223
|
+
|
|
224
|
+
var ref = useMergedRefs([floating, forwardRef]);
|
|
96
225
|
return /*#__PURE__*/React__default.createElement("span", _extends({}, rest, {
|
|
97
226
|
className: "".concat(prefix, "--popover")
|
|
98
227
|
}), /*#__PURE__*/React__default.createElement("span", {
|
|
@@ -84,9 +84,9 @@ function ProgressBar(_ref) {
|
|
|
84
84
|
})), /*#__PURE__*/React__default.createElement("div", {
|
|
85
85
|
className: "".concat(prefix, "--progress-bar__track"),
|
|
86
86
|
role: "progressbar",
|
|
87
|
+
"aria-busy": !isFinished,
|
|
87
88
|
"aria-invalid": isError,
|
|
88
89
|
"aria-labelledby": labelId,
|
|
89
|
-
"aria-describedby": helperText ? helperId : null,
|
|
90
90
|
"aria-valuemin": !indeterminate ? 0 : null,
|
|
91
91
|
"aria-valuemax": !indeterminate ? max : null,
|
|
92
92
|
"aria-valuenow": !indeterminate ? cappedValue : null
|
|
@@ -96,9 +96,12 @@ function ProgressBar(_ref) {
|
|
|
96
96
|
transform: "scaleX(".concat(percentage, ")")
|
|
97
97
|
} : null
|
|
98
98
|
})), helperText && /*#__PURE__*/React__default.createElement("div", {
|
|
99
|
-
id: helperId,
|
|
100
99
|
className: "".concat(prefix, "--progress-bar__helper-text")
|
|
101
|
-
}, helperText
|
|
100
|
+
}, helperText, /*#__PURE__*/React__default.createElement("div", {
|
|
101
|
+
className: "".concat(prefix, "--visually-hidden"),
|
|
102
|
+
"aria-live": "polite",
|
|
103
|
+
id: helperId
|
|
104
|
+
}, isFinished ? 'Done' : 'Loading')));
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
ProgressBar.propTypes = {
|
|
@@ -5,89 +5,66 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import cx from 'classnames';
|
|
8
|
+
import { objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
10
9
|
import PropTypes from 'prop-types';
|
|
11
10
|
import React__default from 'react';
|
|
12
|
-
import
|
|
13
|
-
import uniqueId from '../../tools/uniqueId.js';
|
|
11
|
+
import cx from 'classnames';
|
|
14
12
|
import '../Text/index.js';
|
|
15
|
-
import {
|
|
13
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
+
import { useId } from '../../internal/useId.js';
|
|
16
15
|
import { Text } from '../Text/Text.js';
|
|
17
16
|
|
|
18
|
-
var _excluded = ["className", "
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_this.props.onChange(_this.props.value, _this.props.name, evt);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return _this;
|
|
17
|
+
var _excluded = ["className", "disabled", "hideLabel", "id", "labelPosition", "labelText", "name", "onChange", "value"];
|
|
18
|
+
var RadioButton = /*#__PURE__*/React__default.forwardRef(function RadioButton(_ref, ref) {
|
|
19
|
+
var className = _ref.className,
|
|
20
|
+
disabled = _ref.disabled,
|
|
21
|
+
hideLabel = _ref.hideLabel,
|
|
22
|
+
id = _ref.id,
|
|
23
|
+
_ref$labelPosition = _ref.labelPosition,
|
|
24
|
+
labelPosition = _ref$labelPosition === void 0 ? 'right' : _ref$labelPosition,
|
|
25
|
+
_ref$labelText = _ref.labelText,
|
|
26
|
+
labelText = _ref$labelText === void 0 ? '' : _ref$labelText,
|
|
27
|
+
name = _ref.name,
|
|
28
|
+
_ref$onChange = _ref.onChange,
|
|
29
|
+
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
30
|
+
_ref$value = _ref.value,
|
|
31
|
+
value = _ref$value === void 0 ? '' : _ref$value,
|
|
32
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
33
|
+
|
|
34
|
+
var prefix = usePrefix();
|
|
35
|
+
var uid = useId('radio-button');
|
|
36
|
+
var uniqueId = id || uid;
|
|
37
|
+
|
|
38
|
+
function handleOnChange(event) {
|
|
39
|
+
onChange(value, name, event);
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
onChange: this.handleChange,
|
|
72
|
-
id: this.uid,
|
|
73
|
-
ref: ref
|
|
74
|
-
})), /*#__PURE__*/React__default.createElement("label", {
|
|
75
|
-
htmlFor: this.uid,
|
|
76
|
-
className: "".concat(prefix, "--radio-button__label")
|
|
77
|
-
}, /*#__PURE__*/React__default.createElement("span", {
|
|
78
|
-
className: "".concat(prefix, "--radio-button__appearance")
|
|
79
|
-
}), labelText && /*#__PURE__*/React__default.createElement(Text, {
|
|
80
|
-
className: innerLabelClasses
|
|
81
|
-
}, labelText)));
|
|
82
|
-
}
|
|
83
|
-
}]);
|
|
84
|
-
|
|
85
|
-
return RadioButton;
|
|
86
|
-
}(React__default.Component);
|
|
87
|
-
|
|
88
|
-
_defineProperty(RadioButton, "propTypes", {
|
|
42
|
+
var innerLabelClasses = cx(_defineProperty({}, "".concat(prefix, "--visually-hidden"), hideLabel));
|
|
43
|
+
var wrapperClasses = cx(className, "".concat(prefix, "--radio-button-wrapper"), _defineProperty({}, "".concat(prefix, "--radio-button-wrapper--label-").concat(labelPosition), labelPosition !== 'right'));
|
|
44
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
45
|
+
className: wrapperClasses
|
|
46
|
+
}, /*#__PURE__*/React__default.createElement("input", _extends({}, rest, {
|
|
47
|
+
type: "radio",
|
|
48
|
+
className: "".concat(prefix, "--radio-button"),
|
|
49
|
+
onChange: handleOnChange,
|
|
50
|
+
id: uniqueId,
|
|
51
|
+
ref: ref,
|
|
52
|
+
disabled: disabled,
|
|
53
|
+
value: value,
|
|
54
|
+
name: name
|
|
55
|
+
})), /*#__PURE__*/React__default.createElement("label", {
|
|
56
|
+
htmlFor: uniqueId,
|
|
57
|
+
className: "".concat(prefix, "--radio-button__label")
|
|
58
|
+
}, /*#__PURE__*/React__default.createElement("span", {
|
|
59
|
+
className: "".concat(prefix, "--radio-button__appearance")
|
|
60
|
+
}), labelText && /*#__PURE__*/React__default.createElement(Text, {
|
|
61
|
+
className: innerLabelClasses
|
|
62
|
+
}, labelText)));
|
|
63
|
+
});
|
|
64
|
+
RadioButton.displayName = 'RadioButton';
|
|
65
|
+
RadioButton.propTypes = {
|
|
89
66
|
/**
|
|
90
|
-
* Specify whether the
|
|
67
|
+
* Specify whether the `<RadioButton>` is currently checked
|
|
91
68
|
*/
|
|
92
69
|
checked: PropTypes.bool,
|
|
93
70
|
|
|
@@ -97,7 +74,7 @@ _defineProperty(RadioButton, "propTypes", {
|
|
|
97
74
|
className: PropTypes.string,
|
|
98
75
|
|
|
99
76
|
/**
|
|
100
|
-
* Specify whether the
|
|
77
|
+
* Specify whether the `<RadioButton>` should be checked by default
|
|
101
78
|
*/
|
|
102
79
|
defaultChecked: PropTypes.bool,
|
|
103
80
|
|
|
@@ -120,7 +97,7 @@ _defineProperty(RadioButton, "propTypes", {
|
|
|
120
97
|
* Provide where label text should be placed
|
|
121
98
|
* NOTE: `top`/`bottom` are deprecated
|
|
122
99
|
*/
|
|
123
|
-
labelPosition: PropTypes.oneOf(['
|
|
100
|
+
labelPosition: PropTypes.oneOf(['right', 'left']),
|
|
124
101
|
|
|
125
102
|
/**
|
|
126
103
|
* Provide label text to be read by screen readers when interacting with the
|
|
@@ -145,28 +122,10 @@ _defineProperty(RadioButton, "propTypes", {
|
|
|
145
122
|
onClick: PropTypes.func,
|
|
146
123
|
|
|
147
124
|
/**
|
|
148
|
-
* Specify the value of the
|
|
125
|
+
* Specify the value of the `<RadioButton>`
|
|
149
126
|
*/
|
|
150
127
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
151
|
-
}
|
|
128
|
+
};
|
|
129
|
+
var RadioButton$1 = RadioButton;
|
|
152
130
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
_defineProperty(RadioButton, "defaultProps", {
|
|
156
|
-
labelText: '',
|
|
157
|
-
labelPosition: 'right',
|
|
158
|
-
onChange: function onChange() {},
|
|
159
|
-
value: ''
|
|
160
|
-
});
|
|
161
|
-
var RadioButtonClassic = (function () {
|
|
162
|
-
var forwardRef = function forwardRef(props, ref) {
|
|
163
|
-
return /*#__PURE__*/React__default.createElement(RadioButton, _extends({}, props, {
|
|
164
|
-
innerRef: ref
|
|
165
|
-
}));
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
forwardRef.displayName = 'RadioButton';
|
|
169
|
-
return /*#__PURE__*/React__default.forwardRef(forwardRef);
|
|
170
|
-
})();
|
|
171
|
-
|
|
172
|
-
export { RadioButton, RadioButtonClassic as default };
|
|
131
|
+
export { RadioButton$1 as default };
|
|
@@ -5,11 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import RadioButtonClassic from './RadioButton.js';
|
|
11
|
-
|
|
12
|
-
var RadioButton = FeatureFlags.enabled('enable-v11-release') ? RadioButtonNext : RadioButtonClassic;
|
|
13
|
-
var RadioButton$1 = RadioButton;
|
|
14
|
-
|
|
15
|
-
export { RadioButton$1 as default };
|
|
8
|
+
import RadioButton from './RadioButton.js';
|
|
9
|
+
export { default } from './RadioButton.js';
|
|
@@ -5,121 +5,87 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { slicedToArray as _slicedToArray, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
|
-
import React__default from 'react';
|
|
10
|
+
import React__default, { useState } from 'react';
|
|
11
11
|
import cx from 'classnames';
|
|
12
|
-
import { warning } from '../../internal/warning.js';
|
|
13
12
|
import { Legend } from '../Text/index.js';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
+
|
|
15
|
+
var RadioButtonGroup = /*#__PURE__*/React__default.forwardRef(function RadioButtonGroup(_ref, ref) {
|
|
16
|
+
var _classNames;
|
|
17
|
+
|
|
18
|
+
var children = _ref.children,
|
|
19
|
+
className = _ref.className,
|
|
20
|
+
defaultSelected = _ref.defaultSelected,
|
|
21
|
+
disabled = _ref.disabled,
|
|
22
|
+
_ref$labelPosition = _ref.labelPosition,
|
|
23
|
+
labelPosition = _ref$labelPosition === void 0 ? 'right' : _ref$labelPosition,
|
|
24
|
+
legendText = _ref.legendText,
|
|
25
|
+
name = _ref.name,
|
|
26
|
+
_ref$onChange = _ref.onChange,
|
|
27
|
+
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
28
|
+
_ref$orientation = _ref.orientation,
|
|
29
|
+
orientation = _ref$orientation === void 0 ? 'horizontal' : _ref$orientation,
|
|
30
|
+
valueSelected = _ref.valueSelected;
|
|
31
|
+
var prefix = usePrefix();
|
|
32
|
+
|
|
33
|
+
var _useState = useState(valueSelected !== null && valueSelected !== void 0 ? valueSelected : defaultSelected),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
selected = _useState2[0],
|
|
36
|
+
setSelected = _useState2[1];
|
|
37
|
+
|
|
38
|
+
var _useState3 = useState(valueSelected),
|
|
39
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
40
|
+
prevValueSelected = _useState4[0],
|
|
41
|
+
setPrevValueSelected = _useState4[1];
|
|
42
|
+
/**
|
|
43
|
+
* prop + state alignment - getDerivedStateFromProps
|
|
44
|
+
* only update if selected prop changes
|
|
45
|
+
*/
|
|
30
46
|
|
|
31
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
if (valueSelected !== prevValueSelected) {
|
|
49
|
+
setSelected(valueSelected);
|
|
50
|
+
setPrevValueSelected(valueSelected);
|
|
51
|
+
}
|
|
36
52
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return /*#__PURE__*/React__default.cloneElement(radioButton, {
|
|
47
|
-
name: _this.props.name,
|
|
48
|
-
key: value,
|
|
49
|
-
value: value,
|
|
50
|
-
onChange: _this.handleChange,
|
|
51
|
-
checked: value === _this.state.selected
|
|
52
|
-
});
|
|
53
|
+
function getRadioButtons() {
|
|
54
|
+
var mappedChildren = React__default.Children.map(children, function (radioButton) {
|
|
55
|
+
var value = radioButton.props.value;
|
|
56
|
+
return /*#__PURE__*/React__default.cloneElement(radioButton, {
|
|
57
|
+
name: name,
|
|
58
|
+
key: value,
|
|
59
|
+
value: value,
|
|
60
|
+
onChange: handleOnChange,
|
|
61
|
+
checked: value === selected
|
|
53
62
|
});
|
|
54
|
-
return children;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
_defineProperty(_assertThisInitialized(_this), "handleChange", function (newSelection, value, evt) {
|
|
58
|
-
if (newSelection !== _this.state.selected) {
|
|
59
|
-
_this.setState({
|
|
60
|
-
selected: newSelection
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
_this.props.onChange(newSelection, _this.props.name, evt);
|
|
64
|
-
}
|
|
65
63
|
});
|
|
66
|
-
|
|
67
|
-
return _this;
|
|
64
|
+
return mappedChildren;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var _this$props = this.props,
|
|
76
|
-
disabled = _this$props.disabled,
|
|
77
|
-
className = _this$props.className,
|
|
78
|
-
hideLegend = _this$props.hideLegend,
|
|
79
|
-
orientation = _this$props.orientation,
|
|
80
|
-
labelPosition = _this$props.labelPosition,
|
|
81
|
-
legendText = _this$props.legendText;
|
|
82
|
-
var scope = this.context;
|
|
83
|
-
var enabled;
|
|
84
|
-
|
|
85
|
-
if (scope.enabled) {
|
|
86
|
-
enabled = scope.enabled('enable-v11-release');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return /*#__PURE__*/React__default.createElement(PrefixContext.Consumer, null, function (prefix) {
|
|
90
|
-
var _classNames;
|
|
91
|
-
|
|
92
|
-
var wrapperClasses = cx("".concat(prefix, "--radio-button-group"), [enabled ? null : className], (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "--radio-button-group--").concat(orientation), orientation === 'vertical'), _defineProperty(_classNames, "".concat(prefix, "--radio-button-group--label-").concat(labelPosition), labelPosition), _classNames));
|
|
93
|
-
var legendClasses = cx("".concat(prefix, "--label"), _defineProperty({}, "".concat(prefix, "--visually-hidden"), hideLegend));
|
|
94
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
95
|
-
className: enabled ? cx("".concat(prefix, "--form-item"), className) : "".concat(prefix, "--form-item")
|
|
96
|
-
}, /*#__PURE__*/React__default.createElement("fieldset", {
|
|
97
|
-
className: wrapperClasses,
|
|
98
|
-
disabled: disabled
|
|
99
|
-
}, legendText && /*#__PURE__*/React__default.createElement(Legend, {
|
|
100
|
-
className: legendClasses
|
|
101
|
-
}, legendText), _this2.getRadioButtons()));
|
|
102
|
-
});
|
|
67
|
+
function handleOnChange(newSelection, value, evt) {
|
|
68
|
+
if (newSelection !== selected) {
|
|
69
|
+
setSelected(newSelection);
|
|
70
|
+
onChange(newSelection, name, evt);
|
|
103
71
|
}
|
|
104
|
-
}
|
|
105
|
-
key: "getDerivedStateFromProps",
|
|
106
|
-
value: function getDerivedStateFromProps(_ref, state) {
|
|
107
|
-
var valueSelected = _ref.valueSelected,
|
|
108
|
-
defaultSelected = _ref.defaultSelected;
|
|
109
|
-
var prevValueSelected = state.prevValueSelected;
|
|
110
|
-
return prevValueSelected === valueSelected ? null : {
|
|
111
|
-
selected: typeof valueSelected !== 'undefined' ? valueSelected : defaultSelected,
|
|
112
|
-
prevValueSelected: valueSelected
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}]);
|
|
116
|
-
|
|
117
|
-
return RadioButtonGroup;
|
|
118
|
-
}(React__default.Component);
|
|
72
|
+
}
|
|
119
73
|
|
|
120
|
-
_defineProperty(
|
|
74
|
+
var fieldsetClasses = cx("".concat(prefix, "--radio-button-group"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "--radio-button-group--").concat(orientation), orientation === 'vertical'), _defineProperty(_classNames, "".concat(prefix, "--radio-button-group--label-").concat(labelPosition), labelPosition), _classNames));
|
|
75
|
+
var wrapperClasses = cx("".concat(prefix, "--form-item"), className);
|
|
76
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
77
|
+
className: wrapperClasses,
|
|
78
|
+
ref: ref
|
|
79
|
+
}, /*#__PURE__*/React__default.createElement("fieldset", {
|
|
80
|
+
className: fieldsetClasses,
|
|
81
|
+
disabled: disabled
|
|
82
|
+
}, legendText && /*#__PURE__*/React__default.createElement(Legend, {
|
|
83
|
+
className: "".concat(prefix, "--label")
|
|
84
|
+
}, legendText), getRadioButtons()));
|
|
85
|
+
});
|
|
86
|
+
RadioButtonGroup.propTypes = {
|
|
121
87
|
/**
|
|
122
|
-
* Provide a collection of
|
|
88
|
+
* Provide a collection of `<RadioButton>` components to render in the group
|
|
123
89
|
*/
|
|
124
90
|
children: PropTypes.node,
|
|
125
91
|
|
|
@@ -129,7 +95,7 @@ _defineProperty(RadioButtonGroup, "propTypes", {
|
|
|
129
95
|
className: PropTypes.string,
|
|
130
96
|
|
|
131
97
|
/**
|
|
132
|
-
* Specify the
|
|
98
|
+
* Specify the `<RadioButton>` to be selected by default
|
|
133
99
|
*/
|
|
134
100
|
defaultSelected: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
135
101
|
|
|
@@ -138,11 +104,6 @@ _defineProperty(RadioButtonGroup, "propTypes", {
|
|
|
138
104
|
*/
|
|
139
105
|
disabled: PropTypes.bool,
|
|
140
106
|
|
|
141
|
-
/**
|
|
142
|
-
* Specify whether the legend should be hidden, or not
|
|
143
|
-
*/
|
|
144
|
-
hideLegend: PropTypes.bool,
|
|
145
|
-
|
|
146
107
|
/**
|
|
147
108
|
* Provide where label text should be placed
|
|
148
109
|
*/
|
|
@@ -174,17 +135,7 @@ _defineProperty(RadioButtonGroup, "propTypes", {
|
|
|
174
135
|
* Specify the value that is currently selected in the group
|
|
175
136
|
*/
|
|
176
137
|
valueSelected: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
_defineProperty(RadioButtonGroup, "defaultProps", {
|
|
180
|
-
orientation: 'horizontal',
|
|
181
|
-
labelPosition: 'right',
|
|
182
|
-
hideLegend: false,
|
|
183
|
-
onChange:
|
|
184
|
-
/* istanbul ignore next */
|
|
185
|
-
function onChange() {}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
_defineProperty(RadioButtonGroup, "contextType", FeatureFlagContext);
|
|
138
|
+
};
|
|
139
|
+
var RadioButtonGroup$1 = RadioButtonGroup;
|
|
189
140
|
|
|
190
|
-
export { RadioButtonGroup as default };
|
|
141
|
+
export { RadioButtonGroup$1 as default };
|