@carbon/react 1.25.0 → 1.26.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/Button/Button.js +2 -2
- package/es/components/DataTable/Table.d.ts +74 -0
- package/es/components/DataTable/Table.js +4 -2
- package/es/components/DataTable/TableCell.d.ts +10 -0
- package/es/components/DataTable/TableContext.d.ts +13 -0
- package/es/components/DataTable/TableContext.js +2 -2
- package/es/components/DataTable/TableExpandRow.d.ts +67 -0
- package/es/components/DataTable/TableExpandedRow.d.ts +32 -0
- package/es/components/DataTable/TableHead.d.ts +10 -0
- package/es/components/DataTable/TableHeader.d.ts +64 -0
- package/es/components/DataTable/TableHeader.js +23 -28
- package/es/components/DataTable/TableRow.d.ts +32 -0
- package/es/components/DataTable/TableSelectAll.js +1 -1
- package/es/components/DataTable/TableSelectRow.js +1 -3
- package/es/components/DataTable/TableToolbarContent.d.ts +4 -6
- package/es/components/DataTable/TableToolbarSearch.js +1 -0
- package/es/components/ExpandableSearch/ExpandableSearch.js +1 -0
- package/es/components/FileUploader/FileUploaderButton.js +2 -0
- package/es/components/InlineCheckbox/InlineCheckbox.js +7 -53
- package/es/components/MultiSelect/FilterableMultiSelect.js +15 -7
- package/es/components/MultiSelect/MultiSelect.js +0 -2
- package/es/components/NumberInput/NumberInput.js +9 -1
- package/es/components/RadioButton/RadioButton.Skeleton.d.ts +25 -0
- package/es/components/RadioButton/RadioButton.Skeleton.js +3 -3
- package/es/components/RadioButton/RadioButton.d.ts +64 -0
- package/es/components/RadioButton/RadioButton.js +19 -17
- package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +80 -0
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +84 -25
- package/es/components/Search/Search.Skeleton.d.ts +36 -0
- package/es/components/Search/Search.js +3 -2
- package/es/components/Search/index.js +1 -0
- package/es/components/StructuredList/StructuredList.js +1 -1
- package/es/components/Tabs/Tabs.js +26 -5
- package/es/components/TextInput/TextInput.Skeleton.d.ts +33 -0
- package/es/components/TextInput/index.js +1 -0
- package/es/components/Tile/Tile.js +15 -8
- package/es/components/UIShell/HeaderMenu.js +13 -4
- package/es/components/UIShell/HeaderMenuItem.js +17 -4
- package/es/tools/wrapComponent.js +9 -0
- package/lib/components/Button/Button.js +2 -2
- package/lib/components/DataTable/Table.d.ts +74 -0
- package/lib/components/DataTable/Table.js +4 -2
- package/lib/components/DataTable/TableCell.d.ts +10 -0
- package/lib/components/DataTable/TableContext.d.ts +13 -0
- package/lib/components/DataTable/TableContext.js +2 -2
- package/lib/components/DataTable/TableExpandRow.d.ts +67 -0
- package/lib/components/DataTable/TableExpandedRow.d.ts +32 -0
- package/lib/components/DataTable/TableHead.d.ts +10 -0
- package/lib/components/DataTable/TableHeader.d.ts +64 -0
- package/lib/components/DataTable/TableHeader.js +23 -28
- package/lib/components/DataTable/TableRow.d.ts +32 -0
- package/lib/components/DataTable/TableSelectAll.js +1 -1
- package/lib/components/DataTable/TableSelectRow.js +1 -3
- package/lib/components/DataTable/TableToolbarContent.d.ts +4 -6
- package/lib/components/DataTable/TableToolbarSearch.js +1 -0
- package/lib/components/ExpandableSearch/ExpandableSearch.js +1 -0
- package/lib/components/FileUploader/FileUploaderButton.js +2 -0
- package/lib/components/InlineCheckbox/InlineCheckbox.js +7 -53
- package/lib/components/MultiSelect/FilterableMultiSelect.js +14 -6
- package/lib/components/MultiSelect/MultiSelect.js +0 -2
- package/lib/components/NumberInput/NumberInput.js +9 -1
- package/lib/components/RadioButton/RadioButton.Skeleton.d.ts +25 -0
- package/lib/components/RadioButton/RadioButton.Skeleton.js +3 -3
- package/lib/components/RadioButton/RadioButton.d.ts +64 -0
- package/lib/components/RadioButton/RadioButton.js +18 -16
- package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +80 -0
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +83 -24
- package/lib/components/Search/Search.Skeleton.d.ts +36 -0
- package/lib/components/Search/Search.js +3 -2
- package/lib/components/Search/index.js +2 -0
- package/lib/components/StructuredList/StructuredList.js +1 -1
- package/lib/components/Tabs/Tabs.js +26 -5
- package/lib/components/TextInput/TextInput.Skeleton.d.ts +33 -0
- package/lib/components/TextInput/index.js +2 -0
- package/lib/components/Tile/Tile.js +15 -8
- package/lib/components/UIShell/HeaderMenu.js +13 -4
- package/lib/components/UIShell/HeaderMenuItem.js +17 -4
- package/lib/tools/wrapComponent.js +9 -0
- package/package.json +3 -3
|
@@ -7,13 +7,11 @@
|
|
|
7
7
|
declare const TableToolbarContent: {
|
|
8
8
|
({ className: baseClassName, ...other }: {
|
|
9
9
|
[x: string]: any;
|
|
10
|
-
className
|
|
11
|
-
}): import("react").
|
|
10
|
+
className?: string | undefined;
|
|
11
|
+
}): import("react").ReactElement<{
|
|
12
12
|
className: string | undefined;
|
|
13
|
-
}, import("react").
|
|
14
|
-
|
|
15
|
-
}, any, any>>;
|
|
16
|
-
displayName: any;
|
|
13
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
14
|
+
displayName: string;
|
|
17
15
|
propTypes: {
|
|
18
16
|
className: import("prop-types").Requireable<string>;
|
|
19
17
|
};
|
|
@@ -14,6 +14,7 @@ var cx = require('classnames');
|
|
|
14
14
|
var PropTypes = require('prop-types');
|
|
15
15
|
var React = require('react');
|
|
16
16
|
var Search = require('../Search/Search.js');
|
|
17
|
+
require('../Search/Search.Skeleton.js');
|
|
17
18
|
var instanceId = require('./tools/instanceId.js');
|
|
18
19
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
19
20
|
|
|
@@ -13,6 +13,7 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
|
|
|
13
13
|
var React = require('react');
|
|
14
14
|
var cx = require('classnames');
|
|
15
15
|
var Search = require('../Search/Search.js');
|
|
16
|
+
require('../Search/Search.Skeleton.js');
|
|
16
17
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
17
18
|
var events = require('../../tools/events.js');
|
|
18
19
|
|
|
@@ -99,11 +99,13 @@ function FileUploaderButton(_ref) {
|
|
|
99
99
|
|
|
100
100
|
function onClick(event) {
|
|
101
101
|
event.target.value = null;
|
|
102
|
+
inputNode.current.value = '';
|
|
102
103
|
inputNode.current.click();
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
function onKeyDown(event) {
|
|
106
107
|
if (match.matches(event, [keys.Enter, keys.Space])) {
|
|
108
|
+
inputNode.current.value = '';
|
|
107
109
|
inputNode.current.click();
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
11
|
|
|
12
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
12
13
|
var PropTypes = require('prop-types');
|
|
13
14
|
var React = require('react');
|
|
15
|
+
var deprecate = require('../../prop-types/deprecate.js');
|
|
14
16
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
15
17
|
var useMergedRefs = require('../../internal/useMergedRefs.js');
|
|
16
18
|
|
|
@@ -19,10 +21,12 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
19
21
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
20
22
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
21
23
|
|
|
24
|
+
var _InlineCheckbox$propT;
|
|
22
25
|
/** @type any */
|
|
23
26
|
|
|
24
27
|
var InlineCheckbox = /*#__PURE__*/React__default["default"].forwardRef(function InlineCheckbox(props, forwardRef) {
|
|
25
|
-
var ariaLabel = props
|
|
28
|
+
var ariaLabel = props['aria-label'],
|
|
29
|
+
deprecatedAriaLabel = props.ariaLabel,
|
|
26
30
|
_props$checked = props.checked,
|
|
27
31
|
checked = _props$checked === void 0 ? false : _props$checked,
|
|
28
32
|
disabled = props.disabled,
|
|
@@ -69,64 +73,14 @@ var InlineCheckbox = /*#__PURE__*/React__default["default"].forwardRef(function
|
|
|
69
73
|
React__default["default"].createElement("label", {
|
|
70
74
|
htmlFor: id,
|
|
71
75
|
className: "".concat(prefix, "--checkbox-label"),
|
|
72
|
-
"aria-label": ariaLabel,
|
|
76
|
+
"aria-label": deprecatedAriaLabel || ariaLabel,
|
|
73
77
|
title: title,
|
|
74
78
|
onClick: function onClick(evt) {
|
|
75
79
|
evt.stopPropagation();
|
|
76
80
|
}
|
|
77
81
|
}));
|
|
78
82
|
});
|
|
79
|
-
InlineCheckbox.propTypes = {
|
|
80
|
-
/**
|
|
81
|
-
* Specify the label for the control
|
|
82
|
-
*/
|
|
83
|
-
ariaLabel: PropTypes__default["default"].string.isRequired,
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Specify whether the underlying control is checked, or not
|
|
87
|
-
*/
|
|
88
|
-
checked: PropTypes__default["default"].bool,
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Specify whether the underlying input control should be disabled
|
|
92
|
-
*/
|
|
93
|
-
disabled: PropTypes__default["default"].bool,
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Provide an `id` for the underlying input control
|
|
97
|
-
*/
|
|
98
|
-
id: PropTypes__default["default"].string.isRequired,
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Specify whether the control is in an indterminate state
|
|
102
|
-
*/
|
|
103
|
-
indeterminate: PropTypes__default["default"].bool,
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Provide a `name` for the underlying input control
|
|
107
|
-
*/
|
|
108
|
-
name: PropTypes__default["default"].string.isRequired,
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Provide an optional hook that is called each time the input is updated
|
|
112
|
-
*/
|
|
113
|
-
onChange: PropTypes__default["default"].func,
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Provide a handler that is invoked when a user clicks on the control
|
|
117
|
-
*/
|
|
118
|
-
onClick: PropTypes__default["default"].func,
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Provide a handler that is invoked on the key down event for the control
|
|
122
|
-
*/
|
|
123
|
-
onKeyDown: PropTypes__default["default"].func,
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Provide an optional tooltip for the InlineCheckbox
|
|
127
|
-
*/
|
|
128
|
-
title: PropTypes__default["default"].string
|
|
129
|
-
};
|
|
83
|
+
InlineCheckbox.propTypes = (_InlineCheckbox$propT = {}, _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, 'aria-label', PropTypes__default["default"].string.isRequired), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "ariaLabel", deprecate["default"](PropTypes__default["default"].string.isRequired, 'The `ariaLabel` prop has been deprecated in favor of `aria-label`. This prop will be removed in the next major release.')), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "checked", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "disabled", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "id", PropTypes__default["default"].string.isRequired), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "indeterminate", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "name", PropTypes__default["default"].string.isRequired), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "onChange", PropTypes__default["default"].func), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "onClick", PropTypes__default["default"].func), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "onKeyDown", PropTypes__default["default"].func), _rollupPluginBabelHelpers.defineProperty(_InlineCheckbox$propT, "title", PropTypes__default["default"].string), _InlineCheckbox$propT);
|
|
130
84
|
var InlineCheckbox$1 = InlineCheckbox;
|
|
131
85
|
|
|
132
86
|
exports["default"] = InlineCheckbox$1;
|
|
@@ -104,7 +104,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(fu
|
|
|
104
104
|
inputValue = _useState8[0],
|
|
105
105
|
setInputValue = _useState8[1];
|
|
106
106
|
|
|
107
|
-
var _useState9 = React.useState([]),
|
|
107
|
+
var _useState9 = React.useState(initialSelectedItems !== null && initialSelectedItems !== void 0 ? initialSelectedItems : []),
|
|
108
108
|
_useState10 = _rollupPluginBabelHelpers.slicedToArray(_useState9, 2),
|
|
109
109
|
topItems = _useState10[0],
|
|
110
110
|
setTopItems = _useState10[1];
|
|
@@ -119,6 +119,11 @@ var FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(fu
|
|
|
119
119
|
highlightedIndex = _useState14[0],
|
|
120
120
|
setHighlightedIndex = _useState14[1];
|
|
121
121
|
|
|
122
|
+
var _useState15 = React.useState(initialSelectedItems !== null && initialSelectedItems !== void 0 ? initialSelectedItems : []),
|
|
123
|
+
_useState16 = _rollupPluginBabelHelpers.slicedToArray(_useState15, 2),
|
|
124
|
+
currentSelectedItems = _useState16[0],
|
|
125
|
+
setCurrentSelectedItems = _useState16[1];
|
|
126
|
+
|
|
122
127
|
var textInput = React.useRef();
|
|
123
128
|
var filterableMultiSelectInstanceId = useId.useId();
|
|
124
129
|
var enabled = index.useFeatureFlag('enable-v11-release');
|
|
@@ -143,8 +148,15 @@ var FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(fu
|
|
|
143
148
|
}, helperText) : null;
|
|
144
149
|
var menuId = "".concat(id, "__menu");
|
|
145
150
|
var inputId = "".concat(id, "-input");
|
|
151
|
+
React.useEffect(function () {
|
|
152
|
+
if (!isOpen) {
|
|
153
|
+
setTopItems(currentSelectedItems);
|
|
154
|
+
}
|
|
155
|
+
}, [currentSelectedItems, isOpen, setTopItems]);
|
|
146
156
|
|
|
147
157
|
function handleOnChange(changes) {
|
|
158
|
+
setCurrentSelectedItems(changes.selectedItems);
|
|
159
|
+
|
|
148
160
|
if (onChange) {
|
|
149
161
|
onChange(changes);
|
|
150
162
|
}
|
|
@@ -163,11 +175,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(fu
|
|
|
163
175
|
handleOnMenuChange(false);
|
|
164
176
|
}
|
|
165
177
|
|
|
166
|
-
function handleOnStateChange(changes
|
|
167
|
-
if (changes.isOpen && !isOpen) {
|
|
168
|
-
setTopItems(downshift.selectedItem);
|
|
169
|
-
}
|
|
170
|
-
|
|
178
|
+
function handleOnStateChange(changes) {
|
|
171
179
|
var type = changes.type;
|
|
172
180
|
var stateChangeTypes = Downshift__default["default"].stateChangeTypes;
|
|
173
181
|
|
|
@@ -47,7 +47,6 @@ var _ref = Downshift.useSelect.stateChangeTypes,
|
|
|
47
47
|
MenuBlur = _ref.MenuBlur,
|
|
48
48
|
MenuKeyDownArrowDown = _ref.MenuKeyDownArrowDown,
|
|
49
49
|
MenuKeyDownArrowUp = _ref.MenuKeyDownArrowUp,
|
|
50
|
-
MenuKeyDownEnter = _ref.MenuKeyDownEnter,
|
|
51
50
|
MenuKeyDownEscape = _ref.MenuKeyDownEscape,
|
|
52
51
|
MenuKeyDownSpaceButton = _ref.MenuKeyDownSpaceButton,
|
|
53
52
|
ToggleButtonClick = _ref.ToggleButtonClick;
|
|
@@ -247,7 +246,6 @@ var MultiSelect = /*#__PURE__*/React__default["default"].forwardRef(function Mul
|
|
|
247
246
|
switch (type) {
|
|
248
247
|
case ItemClick:
|
|
249
248
|
case MenuKeyDownSpaceButton:
|
|
250
|
-
case MenuKeyDownEnter:
|
|
251
249
|
if (changes.selectedItem === undefined) {
|
|
252
250
|
break;
|
|
253
251
|
}
|
|
@@ -525,13 +525,21 @@ function disableWheel(e) {
|
|
|
525
525
|
}
|
|
526
526
|
/**
|
|
527
527
|
* Clamp the given value between the upper bound `max` and the lower bound `min`
|
|
528
|
+
*
|
|
529
|
+
* 16 digit min/max more precise than Infinity. Somewhere in 9 quadrillion,
|
|
530
|
+
* there will be integer display issues at runtime. 9quad is a safe cutoff.
|
|
528
531
|
* @param {number} max
|
|
529
532
|
* @param {number} min
|
|
530
533
|
* @param {number} value
|
|
531
534
|
*/
|
|
532
535
|
|
|
533
536
|
|
|
534
|
-
|
|
537
|
+
var boundLimit = 9000000000000000; // 16 digit, 9 quadrillion
|
|
538
|
+
|
|
539
|
+
function clamp() {
|
|
540
|
+
var max = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : boundLimit;
|
|
541
|
+
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -boundLimit;
|
|
542
|
+
var value = arguments.length > 2 ? arguments[2] : undefined;
|
|
535
543
|
return Math.min(max, Math.max(min, value));
|
|
536
544
|
}
|
|
537
545
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
export interface RadioButtonSkeletonProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
10
|
+
/**
|
|
11
|
+
* Specify an optional className to add.
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function RadioButtonSkeleton(props: RadioButtonSkeletonProps): JSX.Element;
|
|
16
|
+
declare namespace RadioButtonSkeleton {
|
|
17
|
+
var propTypes: {
|
|
18
|
+
/**
|
|
19
|
+
* Specify an optional className to add.
|
|
20
|
+
*/
|
|
21
|
+
className: PropTypes.Requireable<string>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export default RadioButtonSkeleton;
|
|
25
|
+
export { RadioButtonSkeleton };
|
|
@@ -23,9 +23,9 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
|
23
23
|
|
|
24
24
|
var _excluded = ["className"];
|
|
25
25
|
|
|
26
|
-
function RadioButtonSkeleton(
|
|
27
|
-
var className =
|
|
28
|
-
rest = _rollupPluginBabelHelpers.objectWithoutProperties(
|
|
26
|
+
function RadioButtonSkeleton(props) {
|
|
27
|
+
var className = props.className,
|
|
28
|
+
rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
|
|
29
29
|
|
|
30
30
|
var prefix = usePrefix.usePrefix();
|
|
31
31
|
return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { ReactNodeLike } from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
type ExcludedAttributes = 'onChange';
|
|
10
|
+
export interface RadioButtonProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify whether the `<RadioButton>` is currently checked
|
|
13
|
+
*/
|
|
14
|
+
checked?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Provide an optional className to be applied to the containing node
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Specify whether the `<RadioButton>` should be checked by default
|
|
21
|
+
*/
|
|
22
|
+
defaultChecked?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Specify whether the control is disabled
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Specify whether the label should be hidden, or not
|
|
29
|
+
*/
|
|
30
|
+
hideLabel?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Provide a unique id for the underlying `<input>` node
|
|
33
|
+
*/
|
|
34
|
+
id?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Provide where label text should be placed
|
|
37
|
+
* NOTE: `top`/`bottom` are deprecated
|
|
38
|
+
*/
|
|
39
|
+
labelPosition?: 'left' | 'right';
|
|
40
|
+
/**
|
|
41
|
+
* Provide label text to be read by screen readers when interacting with the
|
|
42
|
+
* control
|
|
43
|
+
*/
|
|
44
|
+
labelText: ReactNodeLike;
|
|
45
|
+
/**
|
|
46
|
+
* Provide a name for the underlying `<input>` node
|
|
47
|
+
*/
|
|
48
|
+
name?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Provide an optional `onChange` hook that is called each time the value of
|
|
51
|
+
* the underlying `<input>` changes
|
|
52
|
+
*/
|
|
53
|
+
onChange?: (value: string | number, name: string | undefined, event: any) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Provide a handler that is invoked when a user clicks on the control
|
|
56
|
+
*/
|
|
57
|
+
onClick?: (evt: React.MouseEvent<HTMLInputElement>) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Specify the value of the `<RadioButton>`
|
|
60
|
+
*/
|
|
61
|
+
value?: string | number;
|
|
62
|
+
}
|
|
63
|
+
declare const RadioButton: React.ForwardRefExoticComponent<RadioButtonProps & React.RefAttributes<unknown>>;
|
|
64
|
+
export default RadioButton;
|
|
@@ -16,6 +16,7 @@ var cx = require('classnames');
|
|
|
16
16
|
require('../Text/index.js');
|
|
17
17
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
18
18
|
var useId = require('../../internal/useId.js');
|
|
19
|
+
var mergeRefs = require('../../tools/mergeRefs.js');
|
|
19
20
|
var Text = require('../Text/Text.js');
|
|
20
21
|
|
|
21
22
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -25,21 +26,21 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
25
26
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
26
27
|
|
|
27
28
|
var _excluded = ["className", "disabled", "hideLabel", "id", "labelPosition", "labelText", "name", "onChange", "value"];
|
|
28
|
-
var RadioButton = /*#__PURE__*/React__default["default"].forwardRef(function
|
|
29
|
-
var className =
|
|
30
|
-
disabled =
|
|
31
|
-
hideLabel =
|
|
32
|
-
id =
|
|
33
|
-
|
|
34
|
-
labelPosition =
|
|
35
|
-
|
|
36
|
-
labelText =
|
|
37
|
-
name =
|
|
38
|
-
|
|
39
|
-
onChange =
|
|
40
|
-
|
|
41
|
-
value =
|
|
42
|
-
rest = _rollupPluginBabelHelpers.objectWithoutProperties(
|
|
29
|
+
var RadioButton = /*#__PURE__*/React__default["default"].forwardRef(function (props, ref) {
|
|
30
|
+
var className = props.className,
|
|
31
|
+
disabled = props.disabled,
|
|
32
|
+
hideLabel = props.hideLabel,
|
|
33
|
+
id = props.id,
|
|
34
|
+
_props$labelPosition = props.labelPosition,
|
|
35
|
+
labelPosition = _props$labelPosition === void 0 ? 'right' : _props$labelPosition,
|
|
36
|
+
_props$labelText = props.labelText,
|
|
37
|
+
labelText = _props$labelText === void 0 ? '' : _props$labelText,
|
|
38
|
+
name = props.name,
|
|
39
|
+
_props$onChange = props.onChange,
|
|
40
|
+
onChange = _props$onChange === void 0 ? function () {} : _props$onChange,
|
|
41
|
+
_props$value = props.value,
|
|
42
|
+
value = _props$value === void 0 ? '' : _props$value,
|
|
43
|
+
rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
|
|
43
44
|
|
|
44
45
|
var prefix = usePrefix.usePrefix();
|
|
45
46
|
var uid = useId.useId('radio-button');
|
|
@@ -51,6 +52,7 @@ var RadioButton = /*#__PURE__*/React__default["default"].forwardRef(function Rad
|
|
|
51
52
|
|
|
52
53
|
var innerLabelClasses = cx__default["default"]("".concat(prefix, "--radio-button__label-text"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--visually-hidden"), hideLabel));
|
|
53
54
|
var wrapperClasses = cx__default["default"](className, "".concat(prefix, "--radio-button-wrapper"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--radio-button-wrapper--label-").concat(labelPosition), labelPosition !== 'right'));
|
|
55
|
+
var inputRef = React.useRef(null);
|
|
54
56
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
55
57
|
className: wrapperClasses
|
|
56
58
|
}, /*#__PURE__*/React__default["default"].createElement("input", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
@@ -58,7 +60,7 @@ var RadioButton = /*#__PURE__*/React__default["default"].forwardRef(function Rad
|
|
|
58
60
|
className: "".concat(prefix, "--radio-button"),
|
|
59
61
|
onChange: handleOnChange,
|
|
60
62
|
id: uniqueId,
|
|
61
|
-
ref: ref,
|
|
63
|
+
ref: mergeRefs["default"](inputRef, ref),
|
|
62
64
|
disabled: disabled,
|
|
63
65
|
value: value,
|
|
64
66
|
name: name
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { ReactNodeLike } from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
export declare const RadioButtonGroupContext: React.Context<null>;
|
|
10
|
+
type ExcludedAttributes = 'onChange';
|
|
11
|
+
export interface RadioButtonGroupProps extends Omit<React.InputHTMLAttributes<HTMLFieldSetElement>, ExcludedAttributes> {
|
|
12
|
+
/**
|
|
13
|
+
* Provide a collection of `<RadioButton>` components to render in the group
|
|
14
|
+
*/
|
|
15
|
+
children?: ReactNodeLike;
|
|
16
|
+
/**
|
|
17
|
+
* Provide an optional className to be applied to the container node
|
|
18
|
+
*/
|
|
19
|
+
className?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Specify the `<RadioButton>` to be selected by default
|
|
22
|
+
*/
|
|
23
|
+
defaultSelected?: string | number;
|
|
24
|
+
/**
|
|
25
|
+
* Specify whether the group is disabled
|
|
26
|
+
*/
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Provide text that is used alongside the control label for additional help
|
|
30
|
+
*/
|
|
31
|
+
helperText?: ReactNodeLike;
|
|
32
|
+
/**
|
|
33
|
+
* Specify whether the control is currently invalid
|
|
34
|
+
*/
|
|
35
|
+
invalid?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Provide the text that is displayed when the control is in an invalid state
|
|
38
|
+
*/
|
|
39
|
+
invalidText?: ReactNodeLike;
|
|
40
|
+
/**
|
|
41
|
+
* Provide where label text should be placed
|
|
42
|
+
*/
|
|
43
|
+
labelPosition?: 'left' | 'right';
|
|
44
|
+
/**
|
|
45
|
+
* Provide a legend to the RadioButtonGroup input that you are
|
|
46
|
+
* exposing to the user
|
|
47
|
+
*/
|
|
48
|
+
legendText?: ReactNodeLike;
|
|
49
|
+
/**
|
|
50
|
+
* Specify the name of the underlying `<input>` nodes
|
|
51
|
+
*/
|
|
52
|
+
name: string;
|
|
53
|
+
/**
|
|
54
|
+
* Provide an optional `onChange` hook that is called whenever the value of
|
|
55
|
+
* the group changes
|
|
56
|
+
*/
|
|
57
|
+
onChange?: (selection: unknown, name: string, evt: unknown) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Provide where radio buttons should be placed
|
|
60
|
+
*/
|
|
61
|
+
orientation?: 'horizontal' | 'vertical';
|
|
62
|
+
/**
|
|
63
|
+
* Whether the RadioButtonGroup should be read-only
|
|
64
|
+
*/
|
|
65
|
+
readOnly?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Specify whether the control is currently in warning state
|
|
68
|
+
*/
|
|
69
|
+
warn?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Provide the text that is displayed when the control is in warning state
|
|
72
|
+
*/
|
|
73
|
+
warnText?: ReactNodeLike;
|
|
74
|
+
/**
|
|
75
|
+
* Specify the value that is currently selected in the group
|
|
76
|
+
*/
|
|
77
|
+
valueSelected?: string | number;
|
|
78
|
+
}
|
|
79
|
+
declare const RadioButtonGroup: React.ForwardRefExoticComponent<RadioButtonGroupProps & React.RefAttributes<unknown>>;
|
|
80
|
+
export default RadioButtonGroup;
|
|
@@ -15,6 +15,8 @@ var React = require('react');
|
|
|
15
15
|
var cx = require('classnames');
|
|
16
16
|
var index = require('../Text/index.js');
|
|
17
17
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
18
|
+
var iconsReact = require('@carbon/icons-react');
|
|
19
|
+
var mergeRefs = require('../../tools/mergeRefs.js');
|
|
18
20
|
|
|
19
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
22
|
|
|
@@ -22,25 +24,32 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
|
22
24
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
23
25
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
24
26
|
|
|
25
|
-
var _excluded = ["children", "className", "defaultSelected", "disabled", "labelPosition", "legendText", "name", "onChange", "orientation", "readOnly", "valueSelected"];
|
|
26
|
-
var RadioButtonGroup = /*#__PURE__*/React__default["default"].forwardRef(function
|
|
27
|
+
var _excluded = ["children", "className", "defaultSelected", "disabled", "helperText", "invalid", "invalidText", "labelPosition", "legendText", "name", "onChange", "orientation", "readOnly", "valueSelected", "warn", "warnText"];
|
|
28
|
+
var RadioButtonGroup = /*#__PURE__*/React__default["default"].forwardRef(function (props, ref) {
|
|
27
29
|
var _classNames;
|
|
28
30
|
|
|
29
|
-
var children =
|
|
30
|
-
className =
|
|
31
|
-
defaultSelected =
|
|
32
|
-
disabled =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
var children = props.children,
|
|
32
|
+
className = props.className,
|
|
33
|
+
defaultSelected = props.defaultSelected,
|
|
34
|
+
disabled = props.disabled,
|
|
35
|
+
helperText = props.helperText,
|
|
36
|
+
_props$invalid = props.invalid,
|
|
37
|
+
invalid = _props$invalid === void 0 ? false : _props$invalid,
|
|
38
|
+
invalidText = props.invalidText,
|
|
39
|
+
_props$labelPosition = props.labelPosition,
|
|
40
|
+
labelPosition = _props$labelPosition === void 0 ? 'right' : _props$labelPosition,
|
|
41
|
+
legendText = props.legendText,
|
|
42
|
+
name = props.name,
|
|
43
|
+
_props$onChange = props.onChange,
|
|
44
|
+
onChange = _props$onChange === void 0 ? function () {} : _props$onChange,
|
|
45
|
+
_props$orientation = props.orientation,
|
|
46
|
+
orientation = _props$orientation === void 0 ? 'horizontal' : _props$orientation,
|
|
47
|
+
readOnly = props.readOnly,
|
|
48
|
+
valueSelected = props.valueSelected,
|
|
49
|
+
_props$warn = props.warn,
|
|
50
|
+
warn = _props$warn === void 0 ? false : _props$warn,
|
|
51
|
+
warnText = props.warnText,
|
|
52
|
+
rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
|
|
44
53
|
|
|
45
54
|
var prefix = usePrefix.usePrefix();
|
|
46
55
|
|
|
@@ -66,7 +75,11 @@ var RadioButtonGroup = /*#__PURE__*/React__default["default"].forwardRef(functio
|
|
|
66
75
|
|
|
67
76
|
function getRadioButtons() {
|
|
68
77
|
var mappedChildren = React__default["default"].Children.map(children, function (radioButton) {
|
|
69
|
-
var
|
|
78
|
+
var _props;
|
|
79
|
+
|
|
80
|
+
var _ref = (_props = radioButton === null || radioButton === void 0 ? void 0 : radioButton.props) !== null && _props !== void 0 ? _props : undefined,
|
|
81
|
+
value = _ref.value;
|
|
82
|
+
|
|
70
83
|
var newProps = {
|
|
71
84
|
name: name,
|
|
72
85
|
key: value,
|
|
@@ -75,11 +88,13 @@ var RadioButtonGroup = /*#__PURE__*/React__default["default"].forwardRef(functio
|
|
|
75
88
|
checked: value === selected
|
|
76
89
|
};
|
|
77
90
|
|
|
78
|
-
if (!selected && radioButton.props.checked) {
|
|
91
|
+
if (!selected && radioButton !== null && radioButton !== void 0 && radioButton.props.checked) {
|
|
79
92
|
newProps.checked = true;
|
|
80
93
|
}
|
|
81
94
|
|
|
82
|
-
|
|
95
|
+
if (radioButton) {
|
|
96
|
+
return /*#__PURE__*/React__default["default"].cloneElement(radioButton, newProps);
|
|
97
|
+
}
|
|
83
98
|
});
|
|
84
99
|
return mappedChildren;
|
|
85
100
|
}
|
|
@@ -93,18 +108,36 @@ var RadioButtonGroup = /*#__PURE__*/React__default["default"].forwardRef(functio
|
|
|
93
108
|
}
|
|
94
109
|
}
|
|
95
110
|
|
|
96
|
-
var
|
|
111
|
+
var showWarning = !readOnly && !invalid && warn;
|
|
112
|
+
var showHelper = !invalid && !disabled && !warn;
|
|
97
113
|
var wrapperClasses = cx__default["default"]("".concat(prefix, "--form-item"), className);
|
|
114
|
+
var fieldsetClasses = cx__default["default"]("".concat(prefix, "--radio-button-group"), (_classNames = {}, _rollupPluginBabelHelpers.defineProperty(_classNames, "".concat(prefix, "--radio-button-group--").concat(orientation), orientation === 'vertical'), _rollupPluginBabelHelpers.defineProperty(_classNames, "".concat(prefix, "--radio-button-group--label-").concat(labelPosition), labelPosition), _rollupPluginBabelHelpers.defineProperty(_classNames, "".concat(prefix, "--radio-button-group--readonly"), readOnly), _rollupPluginBabelHelpers.defineProperty(_classNames, "".concat(prefix, "--radio-button-group--invalid"), !readOnly && invalid), _rollupPluginBabelHelpers.defineProperty(_classNames, "".concat(prefix, "--radio-button-group--warning"), showWarning), _classNames));
|
|
115
|
+
var helperClasses = cx__default["default"]("".concat(prefix, "--form__helper-text"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--form__helper-text--disabled"), disabled));
|
|
116
|
+
var helper = helperText ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
117
|
+
className: helperClasses
|
|
118
|
+
}, helperText) : null;
|
|
119
|
+
var divRef = React.useRef(null);
|
|
98
120
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
99
121
|
className: wrapperClasses,
|
|
100
|
-
ref: ref
|
|
122
|
+
ref: mergeRefs["default"](divRef, ref)
|
|
101
123
|
}, /*#__PURE__*/React__default["default"].createElement("fieldset", _rollupPluginBabelHelpers["extends"]({
|
|
102
124
|
className: fieldsetClasses,
|
|
103
125
|
disabled: disabled,
|
|
126
|
+
"data-invalid": invalid ? true : undefined,
|
|
104
127
|
"aria-readonly": readOnly
|
|
105
128
|
}, rest), legendText && /*#__PURE__*/React__default["default"].createElement(index.Legend, {
|
|
106
129
|
className: "".concat(prefix, "--label")
|
|
107
|
-
}, legendText), getRadioButtons())
|
|
130
|
+
}, legendText), getRadioButtons()), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
131
|
+
className: "".concat(prefix, "--radio-button__validation-msg")
|
|
132
|
+
}, !readOnly && invalid && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, {
|
|
133
|
+
className: "".concat(prefix, "--radio-button__invalid-icon")
|
|
134
|
+
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
135
|
+
className: "".concat(prefix, "--form-requirement")
|
|
136
|
+
}, invalidText)), showWarning && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningAltFilled, {
|
|
137
|
+
className: "".concat(prefix, "--radio-button__invalid-icon ").concat(prefix, "--radio-button__invalid-icon--warning")
|
|
138
|
+
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
139
|
+
className: "".concat(prefix, "--form-requirement")
|
|
140
|
+
}, warnText)), showHelper && helper));
|
|
108
141
|
});
|
|
109
142
|
RadioButtonGroup.propTypes = {
|
|
110
143
|
/**
|
|
@@ -127,6 +160,21 @@ RadioButtonGroup.propTypes = {
|
|
|
127
160
|
*/
|
|
128
161
|
disabled: PropTypes__default["default"].bool,
|
|
129
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Provide text that is used alongside the control label for additional help
|
|
165
|
+
*/
|
|
166
|
+
helperText: PropTypes__default["default"].node,
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Specify whether the control is currently invalid
|
|
170
|
+
*/
|
|
171
|
+
invalid: PropTypes__default["default"].bool,
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Provide the text that is displayed when the control is in an invalid state
|
|
175
|
+
*/
|
|
176
|
+
invalidText: PropTypes__default["default"].node,
|
|
177
|
+
|
|
130
178
|
/**
|
|
131
179
|
* Provide where label text should be placed
|
|
132
180
|
*/
|
|
@@ -162,8 +210,19 @@ RadioButtonGroup.propTypes = {
|
|
|
162
210
|
/**
|
|
163
211
|
* Specify the value that is currently selected in the group
|
|
164
212
|
*/
|
|
165
|
-
valueSelected: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number])
|
|
213
|
+
valueSelected: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]),
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Specify whether the control is currently in warning state
|
|
217
|
+
*/
|
|
218
|
+
warn: PropTypes__default["default"].bool,
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Provide the text that is displayed when the control is in warning state
|
|
222
|
+
*/
|
|
223
|
+
warnText: PropTypes__default["default"].node
|
|
166
224
|
};
|
|
225
|
+
RadioButtonGroup.displayName = 'RadioButtonGroup';
|
|
167
226
|
var RadioButtonGroup$1 = RadioButtonGroup;
|
|
168
227
|
|
|
169
228
|
exports["default"] = RadioButtonGroup$1;
|