@carbon/react 1.22.0 → 1.23.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 (49) hide show
  1. package/es/components/CodeSnippet/CodeSnippet.js +2 -2
  2. package/es/components/ComboBox/ComboBox.d.ts +151 -0
  3. package/es/components/ComboBox/ComboBox.js +28 -21
  4. package/es/components/ComposedModal/ComposedModal.js +2 -2
  5. package/es/components/DataTable/TableSelectRow.d.ts +88 -0
  6. package/es/components/DataTable/TableSelectRow.js +3 -5
  7. package/es/components/DatePicker/DatePicker.js +1 -1
  8. package/es/components/DatePicker/plugins/fixEventsPlugin.js +10 -1
  9. package/es/components/DatePicker/plugins/rangePlugin.js +1 -1
  10. package/es/components/FileUploader/FileUploaderButton.js +14 -16
  11. package/es/components/NumberInput/NumberInput.d.ts +132 -0
  12. package/es/components/NumberInput/NumberInput.js +9 -7
  13. package/es/components/TextArea/TextArea.js +1 -0
  14. package/es/components/Toggle/Toggle.js +54 -33
  15. package/es/components/Toggletip/index.js +26 -1
  16. package/es/internal/useNormalizedInputProps.js +3 -3
  17. package/lib/components/CodeSnippet/CodeSnippet.js +4 -3
  18. package/lib/components/ComboBox/ComboBox.d.ts +151 -0
  19. package/lib/components/ComboBox/ComboBox.js +28 -21
  20. package/lib/components/ComposedModal/ComposedModal.js +2 -2
  21. package/lib/components/DataTable/TableSelectRow.d.ts +88 -0
  22. package/lib/components/DataTable/TableSelectRow.js +2 -4
  23. package/lib/components/DatePicker/DatePicker.js +9 -8
  24. package/lib/components/DatePicker/plugins/fixEventsPlugin.js +10 -1
  25. package/lib/components/DatePicker/plugins/rangePlugin.js +6 -2
  26. package/lib/components/FileUploader/FileUploaderButton.js +14 -16
  27. package/lib/components/NumberInput/NumberInput.d.ts +132 -0
  28. package/lib/components/NumberInput/NumberInput.js +9 -7
  29. package/lib/components/TextArea/TextArea.js +1 -0
  30. package/lib/components/Toggle/Toggle.js +53 -32
  31. package/lib/components/Toggletip/index.js +26 -1
  32. package/lib/internal/useNormalizedInputProps.js +3 -3
  33. package/package.json +3 -5
  34. package/es/_virtual/ResizeObserver.es.js +0 -13
  35. package/es/_virtual/_commonjsHelpers.js +0 -42
  36. package/es/_virtual/index.js +0 -14
  37. package/es/_virtual/rangePlugin.js +0 -14
  38. package/es/node_modules/flatpickr/dist/l10n/index.js +0 -1423
  39. package/es/node_modules/flatpickr/dist/plugins/rangePlugin.js +0 -196
  40. package/es/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -1112
  41. package/es/node_modules/use-resize-observer/polyfilled.js +0 -111
  42. package/lib/_virtual/ResizeObserver.es.js +0 -17
  43. package/lib/_virtual/_commonjsHelpers.js +0 -48
  44. package/lib/_virtual/index.js +0 -18
  45. package/lib/_virtual/rangePlugin.js +0 -18
  46. package/lib/node_modules/flatpickr/dist/l10n/index.js +0 -1427
  47. package/lib/node_modules/flatpickr/dist/plugins/rangePlugin.js +0 -200
  48. package/lib/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -1116
  49. package/lib/node_modules/use-resize-observer/polyfilled.js +0 -119
@@ -137,11 +137,12 @@ var NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function Num
137
137
  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), _cx3));
138
138
 
139
139
  if (controlledValue !== prevControlledValue) {
140
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
140
141
  setValue(controlledValue);
141
142
  setPrevControlledValue(controlledValue);
142
143
  }
143
144
 
144
- var ariaDescribedBy = null;
145
+ var ariaDescribedBy = undefined;
145
146
 
146
147
  if (normalizedProps.invalid) {
147
148
  ariaDescribedBy = normalizedProps.invalidId;
@@ -168,7 +169,7 @@ var NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function Num
168
169
  }
169
170
 
170
171
  var handleFocus = function handleFocus(evt) {
171
- if (evt.target.type === 'button') {
172
+ if ('type' in evt.target && evt.target.type === 'button') {
172
173
  setIsFocused(false);
173
174
  } else {
174
175
  setIsFocused(evt.type === 'focus' ? true : false);
@@ -176,10 +177,11 @@ var NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function Num
176
177
  };
177
178
 
178
179
  var outerElementClasses = cx__default["default"]("".concat(prefix, "--form-item"), (_cx4 = {}, _rollupPluginBabelHelpers.defineProperty(_cx4, customClassName, !!customClassName), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--number-input--fluid--invalid"), isFluid && normalizedProps.invalid), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--number-input--fluid--focus"), isFluid && isFocused), _rollupPluginBabelHelpers.defineProperty(_cx4, "".concat(prefix, "--number-input--fluid--disabled"), isFluid && disabled), _cx4));
180
+ var Icon = normalizedProps.icon;
179
181
  return /*#__PURE__*/React__default["default"].createElement("div", {
180
182
  className: outerElementClasses,
181
- onFocus: isFluid ? handleFocus : null,
182
- onBlur: isFluid ? handleFocus : null
183
+ onFocus: isFluid ? handleFocus : undefined,
184
+ onBlur: isFluid ? handleFocus : undefined
183
185
  }, /*#__PURE__*/React__default["default"].createElement("div", {
184
186
  className: numberInputClasses,
185
187
  "data-invalid": normalizedProps.invalid ? true : undefined
@@ -225,7 +227,7 @@ var NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function Num
225
227
  step: step,
226
228
  type: "number",
227
229
  value: value
228
- })), normalizedProps.icon ? /*#__PURE__*/React__default["default"].createElement(normalizedProps.icon, {
230
+ })), Icon ? /*#__PURE__*/React__default["default"].createElement(Icon, {
229
231
  className: iconClasses
230
232
  }) : null, !hideSteppers && /*#__PURE__*/React__default["default"].createElement("div", {
231
233
  className: "".concat(prefix, "--number__controls")
@@ -248,7 +250,7 @@ var NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function Num
248
250
  _onClick(event, state);
249
251
  }
250
252
  },
251
- tabIndex: "-1",
253
+ tabIndex: -1,
252
254
  title: decrementNumLabel || iconDescription,
253
255
  type: "button"
254
256
  }, _Subtract || (_Subtract = /*#__PURE__*/React__default["default"].createElement(iconsReact.Subtract, {
@@ -274,7 +276,7 @@ var NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function Num
274
276
  _onClick(event, state);
275
277
  }
276
278
  },
277
- tabIndex: "-1",
279
+ tabIndex: -1,
278
280
  title: incrementNumLabel || iconDescription,
279
281
  type: "button"
280
282
  }, _Add || (_Add = /*#__PURE__*/React__default["default"].createElement(iconsReact.Add, {
@@ -114,6 +114,7 @@ var TextArea = /*#__PURE__*/React__default["default"].forwardRef(function TextAr
114
114
  useIsomorphicEffect["default"](function () {
115
115
  if (other.cols) {
116
116
  textareaRef.current.style.width = null;
117
+ textareaRef.current.style.resize = 'none';
117
118
  } else {
118
119
  textareaRef.current.style.width = "100%";
119
120
  }
@@ -51,6 +51,7 @@ function Toggle(_ref) {
51
51
  other = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
52
52
 
53
53
  var prefix = usePrefix.usePrefix();
54
+ var buttonElement = React.useRef(null);
54
55
 
55
56
  var _useControllableState = useControllableState.useControllableState({
56
57
  value: toggled,
@@ -79,37 +80,53 @@ function Toggle(_ref) {
79
80
  var labelTextClasses = cx__default["default"]("".concat(prefix, "--toggle__label-text"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--visually-hidden"), hideLabel));
80
81
  var appearanceClasses = cx__default["default"]("".concat(prefix, "--toggle__appearance"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--toggle__appearance--sm"), isSm));
81
82
  var switchClasses = cx__default["default"]("".concat(prefix, "--toggle__switch"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--toggle__switch--checked"), checked));
82
- return /*#__PURE__*/React__default["default"].createElement("div", {
83
- className: wrapperClasses
84
- }, /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, other, {
85
- id: id,
86
- className: "".concat(prefix, "--toggle__button"),
87
- role: "switch",
88
- type: "button",
89
- "aria-checked": checked,
90
- "aria-labelledby": ariaLabelledby,
91
- disabled: disabled,
92
- onClick: handleClick
93
- })), /*#__PURE__*/React__default["default"].createElement(LabelComponent, {
94
- htmlFor: ariaLabelledby ? null : id,
95
- className: "".concat(prefix, "--toggle__label")
96
- }, labelText && /*#__PURE__*/React__default["default"].createElement("span", {
97
- className: labelTextClasses
98
- }, labelText), /*#__PURE__*/React__default["default"].createElement("div", {
99
- className: appearanceClasses
100
- }, /*#__PURE__*/React__default["default"].createElement("div", {
101
- className: switchClasses
102
- }, isSm && /*#__PURE__*/React__default["default"].createElement("svg", {
103
- className: "".concat(prefix, "--toggle__check"),
104
- width: "6px",
105
- height: "5px",
106
- viewBox: "0 0 6 5"
107
- }, _path || (_path = /*#__PURE__*/React__default["default"].createElement("path", {
108
- d: "M2.2 2.7L5 0 6 1 2.2 5 0 2.7 1 1.5z"
109
- })))), renderSideLabel && /*#__PURE__*/React__default["default"].createElement("span", {
110
- className: "".concat(prefix, "--toggle__text"),
111
- "aria-hidden": "true"
112
- }, sideLabel))));
83
+ return (
84
+ /*#__PURE__*/
85
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
86
+ React__default["default"].createElement("div", {
87
+ className: wrapperClasses,
88
+ onClick: ariaLabelledby ? function (e) {
89
+ // the underlying <button> can only be activated by keyboard as it is visually hidden;
90
+ // therefore, if this event's target is the <button>, it had to be triggered by
91
+ // the keyboard event which already calls handleClick. if we wouldn't catch this, the
92
+ // onClick and onToggle functions would be called twice whenever the user activates the
93
+ // toggle by keyboard and props['aria-labelledby'] is passed.
94
+ if (buttonElement.current && e.target !== buttonElement.current) {
95
+ handleClick(e);
96
+ buttonElement.current.focus();
97
+ }
98
+ } : null
99
+ }, /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, other, {
100
+ ref: buttonElement,
101
+ id: id,
102
+ className: "".concat(prefix, "--toggle__button"),
103
+ role: "switch",
104
+ type: "button",
105
+ "aria-checked": checked,
106
+ "aria-labelledby": ariaLabelledby,
107
+ disabled: disabled,
108
+ onClick: handleClick
109
+ })), /*#__PURE__*/React__default["default"].createElement(LabelComponent, {
110
+ htmlFor: ariaLabelledby ? null : id,
111
+ className: "".concat(prefix, "--toggle__label")
112
+ }, labelText && /*#__PURE__*/React__default["default"].createElement("span", {
113
+ className: labelTextClasses
114
+ }, labelText), /*#__PURE__*/React__default["default"].createElement("div", {
115
+ className: appearanceClasses
116
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
117
+ className: switchClasses
118
+ }, isSm && /*#__PURE__*/React__default["default"].createElement("svg", {
119
+ className: "".concat(prefix, "--toggle__check"),
120
+ width: "6px",
121
+ height: "5px",
122
+ viewBox: "0 0 6 5"
123
+ }, _path || (_path = /*#__PURE__*/React__default["default"].createElement("path", {
124
+ d: "M2.2 2.7L5 0 6 1 2.2 5 0 2.7 1 1.5z"
125
+ })))), renderSideLabel && /*#__PURE__*/React__default["default"].createElement("span", {
126
+ className: "".concat(prefix, "--toggle__text"),
127
+ "aria-hidden": "true"
128
+ }, sideLabel))))
129
+ );
113
130
  }
114
131
  Toggle.propTypes = {
115
132
  /**
@@ -133,7 +150,11 @@ Toggle.propTypes = {
133
150
  disabled: PropTypes__default["default"].bool,
134
151
 
135
152
  /**
136
- * Specify whether the label should be hidden, or not
153
+ * If true, the side labels (props.labelA and props.labelB) will be replaced by
154
+ * props.labelText, so that the toggle doesn't render a top label. In order to fully
155
+ * hide any labels, you can use props['aria-labelledby'] to refer to another element
156
+ * that labels the toggle. props.labelText would no longer be required in that case
157
+ * and can therefore be omitted.
137
158
  */
138
159
  hideLabel: PropTypes__default["default"].bool,
139
160
 
@@ -112,10 +112,34 @@ function Toggletip(_ref2) {
112
112
 
113
113
  function onKeyDown(event) {
114
114
  if (open && match.match(event, keys.Escape)) {
115
- actions.close();
115
+ actions.close(); // If the menu is closed while focus is still inside the menu, it should return to the trigger button (#12922)
116
+
117
+ var button = ref.current.children[0];
118
+
119
+ if (button && button.type === 'button') {
120
+ button.focus();
121
+ }
116
122
  }
117
123
  }
118
124
 
125
+ function handleBlur(event) {
126
+ // Do not close if the menu itself is clicked, should only close on focus out
127
+ if (open && event.relatedTarget === null) {
128
+ return;
129
+ }
130
+
131
+ if (!event.currentTarget.contains(event.relatedTarget)) {
132
+ // The menu should be closed when focus leaves the `Toggletip` (#12922)
133
+ actions.close();
134
+ }
135
+ } // If the `Toggletip` is the last focusable item in the tab order, it shoudl also close when the browser window loses focus (#12922)
136
+
137
+
138
+ useEvent.useWindowEvent('blur', function () {
139
+ if (open) {
140
+ actions.close();
141
+ }
142
+ });
119
143
  useEvent.useWindowEvent('click', function (event) {
120
144
  if (open && !ref.current.contains(event.target)) {
121
145
  actions.close();
@@ -132,6 +156,7 @@ function Toggletip(_ref2) {
132
156
  highContrast: true,
133
157
  open: open,
134
158
  onKeyDown: onKeyDown,
159
+ onBlur: handleBlur,
135
160
  ref: ref
136
161
  }, children));
137
162
  }
@@ -20,12 +20,12 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
20
  /**
21
21
  * @typedef {object} InputProps
22
22
  * @property {string} id - The input's id
23
- * @property {boolean} readOnly - Whether the input should be readonly
23
+ * @property {boolean | undefined} readOnly - Whether the input should be readonly
24
24
  * @property {boolean} disabled - Whether the input should be disabled
25
25
  * @property {boolean} invalid - Whether the input should be marked as invalid
26
- * @property {string} invalidText - The validation message displayed in case the input is considered invalid
26
+ * @property {React.ReactNode | undefined} invalidText - The validation message displayed in case the input is considered invalid
27
27
  * @property {boolean} warn - Whether the input should be in warning state
28
- * @property {string} warnText - The validation message displayed in case the input is in warning state
28
+ * @property {React.ReactNode | undefined} warnText - The validation message displayed in case the input is in warning state
29
29
  */
30
30
 
31
31
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/react",
3
3
  "description": "React components for the Carbon Design System",
4
- "version": "1.22.0",
4
+ "version": "1.23.0-rc.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -46,7 +46,7 @@
46
46
  "@carbon/feature-flags": "^0.12.0",
47
47
  "@carbon/icons-react": "^11.16.0",
48
48
  "@carbon/layout": "^11.11.0",
49
- "@carbon/styles": "^1.22.0",
49
+ "@carbon/styles": "^1.23.0-rc.0",
50
50
  "@carbon/telemetry": "0.1.0",
51
51
  "classnames": "2.3.2",
52
52
  "copy-to-clipboard": "^3.3.1",
@@ -89,8 +89,6 @@
89
89
  "@storybook/manager-webpack5": "^6.5.6",
90
90
  "@storybook/react": "^6.5.6",
91
91
  "@storybook/theming": "^6.5.6",
92
- "@typescript-eslint/eslint-plugin": "^5.38.1",
93
- "@typescript-eslint/parser": "^5.38.1",
94
92
  "autoprefixer": "^10.4.0",
95
93
  "babel-loader": "^9.0.0",
96
94
  "babel-plugin-dev-expression": "^0.2.3",
@@ -135,5 +133,5 @@
135
133
  "**/*.scss",
136
134
  "**/*.css"
137
135
  ],
138
- "gitHead": "f4c904ce641392046ad21e6c77394a53f6cf0f30"
136
+ "gitHead": "61937768ed4c69f8ec98c7c193d3c30b12c03b46"
139
137
  }
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
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
-
8
- import { getAugmentedNamespace } from './_commonjsHelpers.js';
9
- import * as ResizeObserver_es from '../node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js';
10
-
11
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(ResizeObserver_es);
12
-
13
- export { require$$0 as default };
@@ -1,42 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
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
-
8
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9
-
10
- function getDefaultExportFromCjs (x) {
11
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
12
- }
13
-
14
- function getAugmentedNamespace(n) {
15
- if (n.__esModule) return n;
16
- var f = n.default;
17
- if (typeof f == "function") {
18
- var a = function a () {
19
- if (this instanceof a) {
20
- var args = [null];
21
- args.push.apply(args, arguments);
22
- var Ctor = Function.bind.apply(f, args);
23
- return new Ctor();
24
- }
25
- return f.apply(this, arguments);
26
- };
27
- a.prototype = f.prototype;
28
- } else a = {};
29
- Object.defineProperty(a, '__esModule', {value: true});
30
- Object.keys(n).forEach(function (k) {
31
- var d = Object.getOwnPropertyDescriptor(n, k);
32
- Object.defineProperty(a, k, d.get ? d : {
33
- enumerable: true,
34
- get: function () {
35
- return n[k];
36
- }
37
- });
38
- });
39
- return a;
40
- }
41
-
42
- export { commonjsGlobal, getAugmentedNamespace, getDefaultExportFromCjs };
@@ -1,14 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
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
-
8
- var l10nExports = {};
9
- var l10n = {
10
- get exports(){ return l10nExports; },
11
- set exports(v){ l10nExports = v; },
12
- };
13
-
14
- export { l10n as __module, l10nExports as exports };
@@ -1,14 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
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
-
8
- var rangePluginExports = {};
9
- var rangePlugin = {
10
- get exports(){ return rangePluginExports; },
11
- set exports(v){ rangePluginExports = v; },
12
- };
13
-
14
- export { rangePlugin as __module, rangePluginExports as exports };