@carbon/react 1.7.0 → 1.9.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/ComposedModal/next/ComposedModal.js +1 -1
- 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/InlineLoading/InlineLoading.js +9 -5
- package/es/components/Loading/Loading.js +7 -18
- package/es/components/Menu/Menu.js +1 -1
- package/es/components/Modal/Modal.js +204 -273
- package/es/components/Modal/index.js +2 -8
- package/es/components/ModalWrapper/ModalWrapper.js +1 -1
- 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/NumberInput/NumberInput.Skeleton.js +3 -4
- package/es/components/NumberInput/NumberInput.js +308 -359
- 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/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/SideNavLink.js +6 -9
- package/es/index.js +10 -9
- package/es/internal/createClassWrapper.js +2 -5
- package/lib/components/ComposedModal/index.js +7 -7
- package/lib/components/ComposedModal/next/ComposedModal.js +1 -1
- 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/InlineLoading/InlineLoading.js +9 -5
- package/lib/components/Loading/Loading.js +6 -17
- package/lib/components/Menu/Menu.js +1 -1
- package/lib/components/Modal/Modal.js +201 -270
- package/lib/components/Modal/index.js +2 -25
- package/lib/components/ModalWrapper/ModalWrapper.js +2 -2
- 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/NumberInput/NumberInput.Skeleton.js +3 -4
- package/lib/components/NumberInput/NumberInput.js +305 -376
- 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/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/SideNavLink.js +6 -9
- package/lib/index.js +95 -95
- package/lib/internal/createClassWrapper.js +2 -5
- package/package.json +7 -7
- package/scss/utilities/_hide-at-breakpoint.scss +9 -0
- package/es/components/Modal/next/Modal.js +0 -274
- package/es/components/MultiSelect/next/FilterableMultiSelect.js +0 -544
- 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/es/internal/FeatureFlags.js +0 -52
- package/es/prop-types/requiredIfValueExists.js +0 -32
- package/lib/components/Modal/next/Modal.js +0 -284
- package/lib/components/MultiSelect/next/FilterableMultiSelect.js +0 -556
- 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
- package/lib/internal/FeatureFlags.js +0 -56
- package/lib/prop-types/requiredIfValueExists.js +0 -36
|
@@ -5,21 +5,18 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { defineProperty as _defineProperty,
|
|
9
|
-
import PropTypes from 'prop-types';
|
|
10
|
-
import React__default, { Component } from 'react';
|
|
11
|
-
import cx from 'classnames';
|
|
8
|
+
import { defineProperty as _defineProperty, objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
12
9
|
import { Subtract, Add } from '@carbon/icons-react';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
10
|
+
import cx from 'classnames';
|
|
11
|
+
import PropTypes from 'prop-types';
|
|
12
|
+
import React__default, { useState, useRef } from 'react';
|
|
13
|
+
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
14
|
+
import { useMergedRefs } from '../../internal/useMergedRefs.js';
|
|
16
15
|
import { useNormalizedInputProps } from '../../internal/useNormalizedInputProps.js';
|
|
17
|
-
import {
|
|
18
|
-
import { PrefixContext } from '../../internal/usePrefix.js';
|
|
16
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
19
17
|
import deprecate from '../../prop-types/deprecate.js';
|
|
20
|
-
import { FeatureFlagContext } from '../FeatureFlags/index.js';
|
|
21
18
|
|
|
22
|
-
var _excluded = ["className", "disabled", "
|
|
19
|
+
var _excluded = ["allowEmpty", "className", "disabled", "defaultValue", "helperText", "hideLabel", "hideSteppers", "iconDescription", "id", "label", "invalid", "invalidText", "light", "max", "min", "onChange", "onClick", "onKeyUp", "readOnly", "size", "step", "translateWithId", "warn", "warnText", "value"];
|
|
23
20
|
|
|
24
21
|
var _defaultTranslations, _Subtract, _Add;
|
|
25
22
|
var translationIds = {
|
|
@@ -27,331 +24,226 @@ var translationIds = {
|
|
|
27
24
|
'decrement.number': 'decrement.number'
|
|
28
25
|
};
|
|
29
26
|
var defaultTranslations = (_defaultTranslations = {}, _defineProperty(_defaultTranslations, translationIds['increment.number'], 'Increment number'), _defineProperty(_defaultTranslations, translationIds['decrement.number'], 'Decrement number'), _defaultTranslations);
|
|
27
|
+
var NumberInput = /*#__PURE__*/React__default.forwardRef(function NumberInput(props, forwardRef) {
|
|
28
|
+
var _cx, _cx3;
|
|
29
|
+
|
|
30
|
+
var enabled = useFeatureFlag('enable-v11-release');
|
|
31
|
+
|
|
32
|
+
var _props$allowEmpty = props.allowEmpty,
|
|
33
|
+
allowEmpty = _props$allowEmpty === void 0 ? false : _props$allowEmpty,
|
|
34
|
+
customClassName = props.className,
|
|
35
|
+
_props$disabled = props.disabled,
|
|
36
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
37
|
+
defaultValue = props.defaultValue,
|
|
38
|
+
_props$helperText = props.helperText,
|
|
39
|
+
helperText = _props$helperText === void 0 ? '' : _props$helperText,
|
|
40
|
+
_props$hideLabel = props.hideLabel,
|
|
41
|
+
hideLabel = _props$hideLabel === void 0 ? false : _props$hideLabel,
|
|
42
|
+
hideSteppers = props.hideSteppers,
|
|
43
|
+
_props$iconDescriptio = props.iconDescription,
|
|
44
|
+
iconDescription = _props$iconDescriptio === void 0 ? enabled ? undefined : 'choose a number' : _props$iconDescriptio,
|
|
45
|
+
id = props.id,
|
|
46
|
+
label = props.label,
|
|
47
|
+
_props$invalid = props.invalid,
|
|
48
|
+
invalid = _props$invalid === void 0 ? false : _props$invalid,
|
|
49
|
+
_props$invalidText = props.invalidText,
|
|
50
|
+
invalidText = _props$invalidText === void 0 ? enabled ? undefined : 'Provide invalidText' : _props$invalidText,
|
|
51
|
+
light = props.light,
|
|
52
|
+
max = props.max,
|
|
53
|
+
min = props.min,
|
|
54
|
+
onChange = props.onChange,
|
|
55
|
+
_onClick = props.onClick,
|
|
56
|
+
onKeyUp = props.onKeyUp,
|
|
57
|
+
readOnly = props.readOnly,
|
|
58
|
+
_props$size = props.size,
|
|
59
|
+
size = _props$size === void 0 ? 'md' : _props$size,
|
|
60
|
+
_props$step = props.step,
|
|
61
|
+
step = _props$step === void 0 ? 1 : _props$step,
|
|
62
|
+
_props$translateWithI = props.translateWithId,
|
|
63
|
+
t = _props$translateWithI === void 0 ? function (id) {
|
|
64
|
+
return defaultTranslations[id];
|
|
65
|
+
} : _props$translateWithI,
|
|
66
|
+
_props$warn = props.warn,
|
|
67
|
+
warn = _props$warn === void 0 ? false : _props$warn,
|
|
68
|
+
_props$warnText = props.warnText,
|
|
69
|
+
warnText = _props$warnText === void 0 ? '' : _props$warnText,
|
|
70
|
+
controlledValue = props.value,
|
|
71
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
72
|
+
|
|
73
|
+
var prefix = usePrefix();
|
|
74
|
+
|
|
75
|
+
var _useState = useState(function () {
|
|
76
|
+
if (controlledValue !== undefined) {
|
|
77
|
+
return controlledValue;
|
|
78
|
+
}
|
|
30
79
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
80
|
+
if (defaultValue !== undefined) {
|
|
81
|
+
return defaultValue;
|
|
82
|
+
}
|
|
34
83
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
84
|
+
return 0;
|
|
85
|
+
}),
|
|
86
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
87
|
+
value = _useState2[0],
|
|
88
|
+
setValue = _useState2[1];
|
|
89
|
+
|
|
90
|
+
var _useState3 = useState(controlledValue),
|
|
91
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
92
|
+
prevControlledValue = _useState4[0],
|
|
93
|
+
setPrevControlledValue = _useState4[1];
|
|
94
|
+
|
|
95
|
+
var inputRef = useRef(null);
|
|
96
|
+
var ref = useMergedRefs([forwardRef, inputRef]);
|
|
97
|
+
var numberInputClasses = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--number"), true), _defineProperty(_cx, "".concat(prefix, "--number--helpertext"), true), _defineProperty(_cx, "".concat(prefix, "--number--readonly"), readOnly), _defineProperty(_cx, "".concat(prefix, "--number--light"), light), _defineProperty(_cx, "".concat(prefix, "--number--nolabel"), hideLabel), _defineProperty(_cx, "".concat(prefix, "--number--nosteppers"), hideSteppers), _defineProperty(_cx, "".concat(prefix, "--number--").concat(size), size), _defineProperty(_cx, customClassName, !enabled), _cx));
|
|
98
|
+
var isInputValid = getInputValidity({
|
|
99
|
+
allowEmpty: allowEmpty,
|
|
100
|
+
invalid: invalid,
|
|
101
|
+
value: value,
|
|
102
|
+
max: max,
|
|
103
|
+
min: min
|
|
104
|
+
});
|
|
105
|
+
var normalizedProps = useNormalizedInputProps({
|
|
106
|
+
id: id,
|
|
107
|
+
readOnly: readOnly,
|
|
108
|
+
disabled: disabled,
|
|
109
|
+
invalid: !isInputValid,
|
|
110
|
+
invalidText: invalidText,
|
|
111
|
+
warn: warn,
|
|
112
|
+
warnText: warnText
|
|
113
|
+
});
|
|
114
|
+
var _ref = [t('increment.number'), t('decrement.number')],
|
|
115
|
+
incrementNumLabel = _ref[0],
|
|
116
|
+
decrementNumLabel = _ref[1];
|
|
117
|
+
var wrapperClasses = cx("".concat(prefix, "--number__input-wrapper"), _defineProperty({}, "".concat(prefix, "--number__input-wrapper--warning"), normalizedProps.warn));
|
|
118
|
+
var iconClasses = cx((_cx3 = {}, _defineProperty(_cx3, "".concat(prefix, "--number__invalid"), normalizedProps.invalid || normalizedProps.warn), _defineProperty(_cx3, "".concat(prefix, "--number__invalid--warning"), normalizedProps.warn), _defineProperty(_cx3, "".concat(prefix, "--number__readonly-icon"), readOnly), _cx3));
|
|
119
|
+
|
|
120
|
+
if (controlledValue !== prevControlledValue) {
|
|
121
|
+
setValue(controlledValue);
|
|
122
|
+
setPrevControlledValue(controlledValue);
|
|
123
|
+
}
|
|
38
124
|
|
|
39
|
-
var
|
|
40
|
-
_inherits(NumberInput, _Component);
|
|
41
|
-
|
|
42
|
-
var _super = _createSuper(NumberInput);
|
|
43
|
-
|
|
44
|
-
function NumberInput(props) {
|
|
45
|
-
var _this;
|
|
46
|
-
|
|
47
|
-
_classCallCheck(this, NumberInput);
|
|
48
|
-
|
|
49
|
-
_this = _super.call(this, props);
|
|
50
|
-
|
|
51
|
-
_defineProperty(_assertThisInitialized(_this), "_inputRef", null);
|
|
52
|
-
|
|
53
|
-
_defineProperty(_assertThisInitialized(_this), "handleChange", function (evt) {
|
|
54
|
-
var _this$props = _this.props,
|
|
55
|
-
disabled = _this$props.disabled,
|
|
56
|
-
onChange = _this$props.onChange;
|
|
57
|
-
|
|
58
|
-
if (!disabled) {
|
|
59
|
-
evt.persist();
|
|
60
|
-
evt.imaginaryTarget = _this._inputRef;
|
|
61
|
-
var prevValue = _this.state.value;
|
|
62
|
-
var value = evt.target.value;
|
|
63
|
-
var direction = prevValue < value ? 'up' : 'down';
|
|
64
|
-
|
|
65
|
-
_this.setState({
|
|
66
|
-
value: value
|
|
67
|
-
}, function () {
|
|
68
|
-
if (useControlledStateWithValue) {
|
|
69
|
-
onChange(evt, {
|
|
70
|
-
value: value,
|
|
71
|
-
direction: direction
|
|
72
|
-
});
|
|
73
|
-
} else if (onChange) {
|
|
74
|
-
onChange(evt, {
|
|
75
|
-
value: value,
|
|
76
|
-
direction: direction
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
_defineProperty(_assertThisInitialized(_this), "handleArrowClick", function (evt, direction) {
|
|
84
|
-
var value = typeof _this.state.value === 'string' ? Number(_this.state.value) : _this.state.value;
|
|
85
|
-
var _this$props2 = _this.props,
|
|
86
|
-
disabled = _this$props2.disabled,
|
|
87
|
-
min = _this$props2.min,
|
|
88
|
-
max = _this$props2.max,
|
|
89
|
-
step = _this$props2.step,
|
|
90
|
-
onChange = _this$props2.onChange,
|
|
91
|
-
onClick = _this$props2.onClick;
|
|
92
|
-
var conditional = direction === 'down' ? min !== undefined && value > min || min === undefined : max !== undefined && value < max || max === undefined;
|
|
93
|
-
|
|
94
|
-
if (!disabled && conditional) {
|
|
95
|
-
value = direction === 'down' ? value - step : value + step;
|
|
96
|
-
value = capMax(max, capMin(min, value));
|
|
97
|
-
evt.persist();
|
|
98
|
-
evt.imaginaryTarget = _this._inputRef;
|
|
99
|
-
|
|
100
|
-
_this.setState({
|
|
101
|
-
value: value
|
|
102
|
-
}, function () {
|
|
103
|
-
//TO-DO v11: update these events to return the same things --> evt, {value, direction}
|
|
104
|
-
if (useControlledStateWithValue) {
|
|
105
|
-
onClick && onClick(evt, {
|
|
106
|
-
value: value,
|
|
107
|
-
direction: direction
|
|
108
|
-
});
|
|
109
|
-
onChange && onChange(evt, {
|
|
110
|
-
value: value,
|
|
111
|
-
direction: direction
|
|
112
|
-
});
|
|
113
|
-
} else {
|
|
114
|
-
// value added as a 3rd argument rather than in same obj so it doesn't break in v10
|
|
115
|
-
onClick && onClick(evt, direction, value);
|
|
116
|
-
onChange && onChange(evt, direction, value);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
});
|
|
125
|
+
var ariaDescribedBy = null;
|
|
121
126
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
if (normalizedProps.invalid) {
|
|
128
|
+
ariaDescribedBy = normalizedProps.invalidId;
|
|
129
|
+
}
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
if (normalizedProps.warn) {
|
|
132
|
+
ariaDescribedBy = normalizedProps.warnId;
|
|
133
|
+
}
|
|
127
134
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return _possibleConstructorReturn(_this);
|
|
135
|
+
function handleOnChange(event) {
|
|
136
|
+
if (disabled) {
|
|
137
|
+
return;
|
|
132
138
|
}
|
|
133
139
|
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
var state = {
|
|
141
|
+
value: event.target.value,
|
|
142
|
+
direction: value < event.target.value ? 'up' : 'down'
|
|
143
|
+
};
|
|
144
|
+
setValue(state.value);
|
|
137
145
|
|
|
138
|
-
if (
|
|
139
|
-
|
|
146
|
+
if (onChange) {
|
|
147
|
+
onChange(event, state);
|
|
140
148
|
}
|
|
141
|
-
|
|
142
|
-
_this.state = {
|
|
143
|
-
value: _value
|
|
144
|
-
};
|
|
145
|
-
return _this;
|
|
146
149
|
}
|
|
147
150
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
151
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
152
|
+
className: cx("".concat(prefix, "--form-item"), _defineProperty({}, customClassName, enabled))
|
|
153
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
154
|
+
className: numberInputClasses,
|
|
155
|
+
"data-invalid": normalizedProps.invalid ? true : undefined
|
|
156
|
+
}, /*#__PURE__*/React__default.createElement(Label, {
|
|
157
|
+
disabled: normalizedProps.disabled,
|
|
158
|
+
hideLabel: hideLabel,
|
|
159
|
+
id: id,
|
|
160
|
+
label: label
|
|
161
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
162
|
+
className: wrapperClasses
|
|
163
|
+
}, /*#__PURE__*/React__default.createElement("input", _extends({}, rest, {
|
|
164
|
+
"data-invalid": normalizedProps.invalid ? true : undefined,
|
|
165
|
+
"aria-invalid": normalizedProps.invalid,
|
|
166
|
+
"aria-describedby": ariaDescribedBy,
|
|
167
|
+
disabled: normalizedProps.disabled,
|
|
168
|
+
ref: ref,
|
|
169
|
+
id: id,
|
|
170
|
+
max: max,
|
|
171
|
+
min: min,
|
|
172
|
+
onClick: _onClick,
|
|
173
|
+
onChange: handleOnChange,
|
|
174
|
+
onKeyUp: onKeyUp,
|
|
175
|
+
pattern: "[0-9]*",
|
|
176
|
+
readOnly: readOnly,
|
|
177
|
+
step: step,
|
|
178
|
+
type: "number",
|
|
179
|
+
value: value
|
|
180
|
+
})), normalizedProps.icon ? /*#__PURE__*/React__default.createElement(normalizedProps.icon, {
|
|
181
|
+
className: iconClasses
|
|
182
|
+
}) : null, !hideSteppers && /*#__PURE__*/React__default.createElement("div", {
|
|
183
|
+
className: "".concat(prefix, "--number__controls")
|
|
184
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
185
|
+
"aria-label": decrementNumLabel || iconDescription,
|
|
186
|
+
className: "".concat(prefix, "--number__control-btn down-icon"),
|
|
187
|
+
disabled: disabled,
|
|
188
|
+
onClick: function onClick(event) {
|
|
189
|
+
var state = {
|
|
190
|
+
value: clamp(max, min, value - step),
|
|
191
|
+
direction: 'down'
|
|
192
|
+
};
|
|
193
|
+
setValue(state.value);
|
|
194
|
+
|
|
195
|
+
if (onChange) {
|
|
196
|
+
onChange(event, state);
|
|
186
197
|
}
|
|
187
198
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var normalizedProps = useNormalizedInputProps({
|
|
209
|
-
id: id,
|
|
210
|
-
readOnly: readOnly,
|
|
211
|
-
disabled: disabled,
|
|
212
|
-
invalid: isInputInvalid,
|
|
213
|
-
invalidText: invalidText,
|
|
214
|
-
warn: warn,
|
|
215
|
-
warnText: warnText
|
|
216
|
-
});
|
|
217
|
-
var props = {
|
|
218
|
-
disabled: normalizedProps.disabled,
|
|
219
|
-
id: id,
|
|
220
|
-
max: max,
|
|
221
|
-
min: min,
|
|
222
|
-
step: step,
|
|
223
|
-
onChange: _this2.handleChange,
|
|
224
|
-
value: useControlledStateWithValue && _this2.isControlled ? value : _this2.state.value,
|
|
225
|
-
readOnly: readOnly,
|
|
226
|
-
'aria-label': label ? null : ariaLabel
|
|
227
|
-
};
|
|
228
|
-
var buttonProps = {
|
|
229
|
-
disabled: disabled
|
|
230
|
-
};
|
|
231
|
-
var inputWrapperProps = {};
|
|
232
|
-
|
|
233
|
-
if (normalizedProps.invalid) {
|
|
234
|
-
inputWrapperProps['data-invalid'] = true;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
var helperTextClasses = cx("".concat(prefix, "--form__helper-text"), _defineProperty({}, "".concat(prefix, "--form__helper-text--disabled"), normalizedProps.disabled));
|
|
238
|
-
var helper = helperText ? /*#__PURE__*/React__default.createElement("div", {
|
|
239
|
-
className: helperTextClasses
|
|
240
|
-
}, helperText) : null;
|
|
241
|
-
var labelClasses = cx("".concat(prefix, "--label"), (_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefix, "--label--disabled"), normalizedProps.disabled), _defineProperty(_classNames3, "".concat(prefix, "--visually-hidden"), hideLabel), _classNames3));
|
|
242
|
-
var labelText = label ? /*#__PURE__*/React__default.createElement("label", {
|
|
243
|
-
htmlFor: id,
|
|
244
|
-
className: labelClasses
|
|
245
|
-
}, label) : null;
|
|
246
|
-
var _ref = [t('increment.number'), t('decrement.number')],
|
|
247
|
-
incrementNumLabel = _ref[0],
|
|
248
|
-
decrementNumLabel = _ref[1];
|
|
249
|
-
var wrapperClasses = cx("".concat(prefix, "--number__input-wrapper"), _defineProperty({}, "".concat(prefix, "--number__input-wrapper--warning"), normalizedProps.warn));
|
|
250
|
-
var iconClasses = cx((_classNames5 = {}, _defineProperty(_classNames5, "".concat(prefix, "--number__invalid"), normalizedProps.invalid || normalizedProps.warn), _defineProperty(_classNames5, "".concat(prefix, "--number__invalid--warning"), normalizedProps.warn), _defineProperty(_classNames5, "".concat(prefix, "--number__readonly-icon"), readOnly), _classNames5));
|
|
251
|
-
var ariaDescribedBy = null;
|
|
252
|
-
|
|
253
|
-
if (normalizedProps.invalid) {
|
|
254
|
-
ariaDescribedBy = normalizedProps.invalidId;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (normalizedProps.warn) {
|
|
258
|
-
ariaDescribedBy = normalizedProps.warnId;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
262
|
-
className: enabled ? cx("".concat(prefix, "--form-item"), className) : "".concat(prefix, "--form-item")
|
|
263
|
-
}, /*#__PURE__*/React__default.createElement("div", _extends({
|
|
264
|
-
className: numberInputClasses
|
|
265
|
-
}, inputWrapperProps), function () {
|
|
266
|
-
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, labelText, /*#__PURE__*/React__default.createElement("div", {
|
|
267
|
-
className: wrapperClasses
|
|
268
|
-
}, /*#__PURE__*/React__default.createElement("input", _extends({
|
|
269
|
-
"data-invalid": normalizedProps.invalid,
|
|
270
|
-
"aria-invalid": normalizedProps.invalid,
|
|
271
|
-
"aria-describedby": ariaDescribedBy,
|
|
272
|
-
type: "number",
|
|
273
|
-
pattern: "[0-9]*"
|
|
274
|
-
}, other, props, {
|
|
275
|
-
ref: mergeRefs(ref, _this2._handleInputRef)
|
|
276
|
-
})), normalizedProps.icon && (_normalizedProps$icon || (_normalizedProps$icon = /*#__PURE__*/React__default.createElement(normalizedProps.icon, {
|
|
277
|
-
className: iconClasses
|
|
278
|
-
}))), !hideSteppers && /*#__PURE__*/React__default.createElement("div", {
|
|
279
|
-
className: "".concat(prefix, "--number__controls")
|
|
280
|
-
}, /*#__PURE__*/React__default.createElement("button", _extends({
|
|
281
|
-
type: "button",
|
|
282
|
-
className: "".concat(prefix, "--number__control-btn down-icon")
|
|
283
|
-
}, buttonProps, {
|
|
284
|
-
onClick: function onClick(evt) {
|
|
285
|
-
return _this2.handleArrowClick(evt, 'down');
|
|
286
|
-
},
|
|
287
|
-
title: decrementNumLabel || iconDescription,
|
|
288
|
-
"aria-label": decrementNumLabel || iconDescription,
|
|
289
|
-
tabIndex: "-1"
|
|
290
|
-
}), _Subtract || (_Subtract = /*#__PURE__*/React__default.createElement(Subtract, {
|
|
291
|
-
className: "down-icon"
|
|
292
|
-
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
293
|
-
className: "".concat(prefix, "--number__rule-divider")
|
|
294
|
-
}), /*#__PURE__*/React__default.createElement("button", _extends({
|
|
295
|
-
type: "button",
|
|
296
|
-
className: "".concat(prefix, "--number__control-btn up-icon")
|
|
297
|
-
}, buttonProps, {
|
|
298
|
-
onClick: function onClick(evt) {
|
|
299
|
-
return _this2.handleArrowClick(evt, 'up');
|
|
300
|
-
},
|
|
301
|
-
title: incrementNumLabel || iconDescription,
|
|
302
|
-
"aria-label": incrementNumLabel || iconDescription,
|
|
303
|
-
tabIndex: "-1"
|
|
304
|
-
}), _Add || (_Add = /*#__PURE__*/React__default.createElement(Add, {
|
|
305
|
-
className: "up-icon"
|
|
306
|
-
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
307
|
-
className: "".concat(prefix, "--number__rule-divider")
|
|
308
|
-
}))), normalizedProps.validation ? null : helper);
|
|
309
|
-
}(), normalizedProps.validation));
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
}], [{
|
|
313
|
-
key: "getDerivedStateFromProps",
|
|
314
|
-
value: function getDerivedStateFromProps(_ref2, state) {
|
|
315
|
-
var value = _ref2.value;
|
|
316
|
-
var prevValue = state.prevValue;
|
|
317
|
-
|
|
318
|
-
if (useControlledStateWithValue && value === '' && prevValue !== '') {
|
|
319
|
-
return {
|
|
320
|
-
value: '',
|
|
321
|
-
prevValue: ''
|
|
322
|
-
};
|
|
323
|
-
} // If `useControlledStateWithValue` feature flag is on, do nothing here.
|
|
324
|
-
// Otherwise, do prop -> state sync with "value capping".
|
|
325
|
-
//// Value capping removed in #8965
|
|
326
|
-
//// value: capMax(max, capMin(min, value)), (L223)
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return useControlledStateWithValue || prevValue === value ? null : {
|
|
330
|
-
value: value,
|
|
331
|
-
prevValue: value
|
|
199
|
+
if (_onClick) {
|
|
200
|
+
_onClick(event, state);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
tabIndex: "-1",
|
|
204
|
+
title: decrementNumLabel || iconDescription,
|
|
205
|
+
type: "button"
|
|
206
|
+
}, _Subtract || (_Subtract = /*#__PURE__*/React__default.createElement(Subtract, {
|
|
207
|
+
className: "down-icon"
|
|
208
|
+
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
209
|
+
className: "".concat(prefix, "--number__rule-divider")
|
|
210
|
+
}), /*#__PURE__*/React__default.createElement("button", {
|
|
211
|
+
"aria-label": incrementNumLabel || iconDescription,
|
|
212
|
+
className: "".concat(prefix, "--number__control-btn up-icon"),
|
|
213
|
+
disabled: disabled,
|
|
214
|
+
onClick: function onClick(event) {
|
|
215
|
+
var state = {
|
|
216
|
+
value: clamp(max, min, value + step),
|
|
217
|
+
direction: 'up'
|
|
332
218
|
};
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* The DOM node reference to the `<input>`.
|
|
336
|
-
* @type {HTMLInputElement}
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
}]);
|
|
219
|
+
setValue(state.value);
|
|
340
220
|
|
|
341
|
-
|
|
342
|
-
|
|
221
|
+
if (onChange) {
|
|
222
|
+
onChange(event, state);
|
|
223
|
+
}
|
|
343
224
|
|
|
344
|
-
|
|
225
|
+
if (_onClick) {
|
|
226
|
+
_onClick(event, state);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
tabIndex: "-1",
|
|
230
|
+
title: incrementNumLabel || iconDescription,
|
|
231
|
+
type: "button"
|
|
232
|
+
}, _Add || (_Add = /*#__PURE__*/React__default.createElement(Add, {
|
|
233
|
+
className: "up-icon"
|
|
234
|
+
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
235
|
+
className: "".concat(prefix, "--number__rule-divider")
|
|
236
|
+
}))), normalizedProps.validation ? normalizedProps.validation : /*#__PURE__*/React__default.createElement(HelperText, {
|
|
237
|
+
disabled: disabled,
|
|
238
|
+
description: helperText
|
|
239
|
+
})));
|
|
240
|
+
});
|
|
241
|
+
NumberInput.propTypes = {
|
|
345
242
|
/**
|
|
346
243
|
* `true` to allow empty string.
|
|
347
244
|
*/
|
|
348
245
|
allowEmpty: PropTypes.bool,
|
|
349
246
|
|
|
350
|
-
/**
|
|
351
|
-
* Provide a description that would be used to best describe the use case of the NumberInput component
|
|
352
|
-
*/
|
|
353
|
-
ariaLabel: PropTypes.string,
|
|
354
|
-
|
|
355
247
|
/**
|
|
356
248
|
* Specify an optional className to be applied to the wrapper node
|
|
357
249
|
*/
|
|
@@ -385,7 +277,7 @@ _defineProperty(NumberInput, "propTypes", {
|
|
|
385
277
|
/**
|
|
386
278
|
* Provide a description for up/down icons that can be read by screen readers
|
|
387
279
|
*/
|
|
388
|
-
iconDescription: PropTypes.string
|
|
280
|
+
iconDescription: PropTypes.string,
|
|
389
281
|
|
|
390
282
|
/**
|
|
391
283
|
* Specify a custom `id` for the input
|
|
@@ -402,11 +294,6 @@ _defineProperty(NumberInput, "propTypes", {
|
|
|
402
294
|
*/
|
|
403
295
|
invalidText: PropTypes.node,
|
|
404
296
|
|
|
405
|
-
/**
|
|
406
|
-
* `true` to use the mobile variant.
|
|
407
|
-
*/
|
|
408
|
-
isMobile: deprecate(PropTypes.bool, "The `isMobile` prop no longer needed as the default NumberInput styles are now identical to the mobile variant styles. This prop will be removed in the next major version of `carbon-components-react`"),
|
|
409
|
-
|
|
410
297
|
/**
|
|
411
298
|
* Generic `label` that will be used as the textual representation of what
|
|
412
299
|
* this field is for
|
|
@@ -416,7 +303,7 @@ _defineProperty(NumberInput, "propTypes", {
|
|
|
416
303
|
/**
|
|
417
304
|
* `true` to use the light version.
|
|
418
305
|
*/
|
|
419
|
-
light: PropTypes.bool,
|
|
306
|
+
light: deprecate(PropTypes.bool, 'The `light` prop for `NumberInput` is no longer needed and has ' + 'been deprecated in v11 in favor of the new `Layer` component. It will be moved in the next major release.'),
|
|
420
307
|
|
|
421
308
|
/**
|
|
422
309
|
* The maximum value.
|
|
@@ -432,29 +319,28 @@ _defineProperty(NumberInput, "propTypes", {
|
|
|
432
319
|
* The new value is available in 'imaginaryTarget.value'
|
|
433
320
|
* i.e. to get the value: evt.imaginaryTarget.value
|
|
434
321
|
*
|
|
435
|
-
* * _With_ `useControlledStateWithValue` feature flag, the signature of the event handler will be altered to provide additional context in the second parameter: `onChange(event, { value, direction })` where:
|
|
436
|
-
* * `event` is the (React) raw event
|
|
437
|
-
* * `value` is the new value
|
|
438
|
-
* * `direction` tells you the button you hit is up button or down button
|
|
439
|
-
* * _Without_ this feature flag the event handler has `onChange(event, direction)` signature.
|
|
440
322
|
*/
|
|
441
|
-
onChange:
|
|
323
|
+
onChange: PropTypes.func,
|
|
442
324
|
|
|
443
325
|
/**
|
|
444
326
|
* Provide an optional function to be called when the up/down button is clicked
|
|
445
327
|
*/
|
|
446
328
|
onClick: PropTypes.func,
|
|
447
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Provide an optional function to be called when a key is pressed in the number input
|
|
332
|
+
*/
|
|
333
|
+
onKeyUp: PropTypes.func,
|
|
334
|
+
|
|
448
335
|
/**
|
|
449
336
|
* Specify if the component should be read-only
|
|
450
337
|
*/
|
|
451
338
|
readOnly: PropTypes.bool,
|
|
452
339
|
|
|
453
340
|
/**
|
|
454
|
-
* Specify the size of the Number Input.
|
|
455
|
-
* TODO V11: remove `xl` (replaced with lg)
|
|
341
|
+
* Specify the size of the Number Input.
|
|
456
342
|
*/
|
|
457
|
-
size: PropTypes.oneOf(['sm', 'md', 'lg'
|
|
343
|
+
size: PropTypes.oneOf(['sm', 'md', 'lg']),
|
|
458
344
|
|
|
459
345
|
/**
|
|
460
346
|
* Specify how much the values should increase/decrease upon clicking on up/down button
|
|
@@ -464,7 +350,7 @@ _defineProperty(NumberInput, "propTypes", {
|
|
|
464
350
|
/**
|
|
465
351
|
* Provide custom text for the component for each translation id
|
|
466
352
|
*/
|
|
467
|
-
translateWithId: PropTypes.func
|
|
353
|
+
translateWithId: PropTypes.func,
|
|
468
354
|
|
|
469
355
|
/**
|
|
470
356
|
* Specify the value of the input
|
|
@@ -480,36 +366,99 @@ _defineProperty(NumberInput, "propTypes", {
|
|
|
480
366
|
* Provide the text that is displayed when the control is in warning state
|
|
481
367
|
*/
|
|
482
368
|
warnText: PropTypes.node
|
|
483
|
-
}
|
|
369
|
+
};
|
|
484
370
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
371
|
+
function Label(_ref2) {
|
|
372
|
+
var _cx5;
|
|
373
|
+
|
|
374
|
+
var disabled = _ref2.disabled,
|
|
375
|
+
id = _ref2.id,
|
|
376
|
+
hideLabel = _ref2.hideLabel,
|
|
377
|
+
label = _ref2.label;
|
|
378
|
+
var prefix = usePrefix();
|
|
379
|
+
var className = cx((_cx5 = {}, _defineProperty(_cx5, "".concat(prefix, "--label"), true), _defineProperty(_cx5, "".concat(prefix, "--label--disabled"), disabled), _defineProperty(_cx5, "".concat(prefix, "--visually-hidden"), hideLabel), _cx5));
|
|
380
|
+
|
|
381
|
+
if (label) {
|
|
382
|
+
return /*#__PURE__*/React__default.createElement("label", {
|
|
383
|
+
htmlFor: id,
|
|
384
|
+
className: className
|
|
385
|
+
}, label);
|
|
500
386
|
}
|
|
501
|
-
});
|
|
502
387
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
Label.propTypes = {
|
|
392
|
+
disabled: PropTypes.bool,
|
|
393
|
+
hideLabel: PropTypes.bool,
|
|
394
|
+
id: PropTypes.string,
|
|
395
|
+
label: PropTypes.node
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
function HelperText(_ref3) {
|
|
399
|
+
var disabled = _ref3.disabled,
|
|
400
|
+
description = _ref3.description;
|
|
401
|
+
var prefix = usePrefix();
|
|
402
|
+
var className = cx("".concat(prefix, "--form__helper-text"), _defineProperty({}, "".concat(prefix, "--form__helper-text--disabled"), disabled));
|
|
403
|
+
|
|
404
|
+
if (description) {
|
|
405
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
406
|
+
className: className
|
|
407
|
+
}, description);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
HelperText.propTypes = {
|
|
414
|
+
description: PropTypes.node,
|
|
415
|
+
disabled: PropTypes.bool
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* Determine if the given value is invalid based on the given max, min and
|
|
419
|
+
* conditions like `allowEmpty`. If `invalid` is passed through, it will default
|
|
420
|
+
* to false.
|
|
421
|
+
*
|
|
422
|
+
* @param {object} config
|
|
423
|
+
* @param {boolean} config.allowEmpty
|
|
424
|
+
* @param {boolean} config.invalid
|
|
425
|
+
* @param {number} config.value
|
|
426
|
+
* @param {number} config.max
|
|
427
|
+
* @param {number} config.min
|
|
428
|
+
* @returns {boolean}
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
function getInputValidity(_ref4) {
|
|
432
|
+
var allowEmpty = _ref4.allowEmpty,
|
|
433
|
+
invalid = _ref4.invalid,
|
|
434
|
+
value = _ref4.value,
|
|
435
|
+
max = _ref4.max,
|
|
436
|
+
min = _ref4.min;
|
|
437
|
+
|
|
438
|
+
if (invalid) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (value === '') {
|
|
443
|
+
return allowEmpty;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (value > max || value < min) {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Clamp the given value between the upper bound `max` and the lower bound `min`
|
|
454
|
+
* @param {number} max
|
|
455
|
+
* @param {number} min
|
|
456
|
+
* @param {number} value
|
|
457
|
+
*/
|
|
458
|
+
|
|
510
459
|
|
|
511
|
-
|
|
512
|
-
return
|
|
513
|
-
}
|
|
460
|
+
function clamp(max, min, value) {
|
|
461
|
+
return Math.min(max, Math.max(min, value));
|
|
462
|
+
}
|
|
514
463
|
|
|
515
|
-
export { NumberInput,
|
|
464
|
+
export { NumberInput, translationIds };
|