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