@carbon/react 1.22.0 → 1.23.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 (85) 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/DataTable/tools/sorting.js +3 -0
  8. package/es/components/DatePicker/DatePicker.js +1 -1
  9. package/es/components/DatePicker/plugins/fixEventsPlugin.js +10 -1
  10. package/es/components/DatePicker/plugins/rangePlugin.js +1 -1
  11. package/es/components/FileUploader/FileUploaderButton.js +14 -16
  12. package/es/components/Grid/CSSGrid.d.ts +9 -0
  13. package/es/components/Grid/CSSGrid.js +8 -5
  14. package/es/components/Grid/Column.d.ts +73 -0
  15. package/es/components/Grid/Column.js +40 -34
  16. package/es/components/Grid/ColumnHang.d.ts +24 -0
  17. package/es/components/Grid/ColumnHang.js +7 -4
  18. package/es/components/Grid/FlexGrid.d.ts +9 -0
  19. package/es/components/Grid/FlexGrid.js +6 -3
  20. package/es/components/Grid/Grid.d.ts +9 -0
  21. package/es/components/Grid/Grid.js +6 -5
  22. package/es/components/Grid/GridContext.d.ts +38 -0
  23. package/es/components/Grid/GridContext.js +6 -6
  24. package/es/components/Grid/GridTypes.d.ts +37 -0
  25. package/es/components/Grid/Row.d.ts +34 -0
  26. package/es/components/Grid/Row.js +4 -2
  27. package/es/components/Grid/index.d.ts +11 -0
  28. package/es/components/NumberInput/NumberInput.d.ts +132 -0
  29. package/es/components/NumberInput/NumberInput.js +9 -7
  30. package/es/components/TextArea/TextArea.js +1 -0
  31. package/es/components/Toggle/Toggle.js +54 -33
  32. package/es/components/Toggletip/index.js +26 -1
  33. package/es/index.js +5 -5
  34. package/es/internal/useNormalizedInputProps.js +3 -3
  35. package/lib/components/CodeSnippet/CodeSnippet.js +4 -3
  36. package/lib/components/ComboBox/ComboBox.d.ts +151 -0
  37. package/lib/components/ComboBox/ComboBox.js +28 -21
  38. package/lib/components/ComposedModal/ComposedModal.js +2 -2
  39. package/lib/components/DataTable/TableSelectRow.d.ts +88 -0
  40. package/lib/components/DataTable/TableSelectRow.js +2 -4
  41. package/lib/components/DataTable/tools/sorting.js +3 -0
  42. package/lib/components/DatePicker/DatePicker.js +9 -8
  43. package/lib/components/DatePicker/plugins/fixEventsPlugin.js +10 -1
  44. package/lib/components/DatePicker/plugins/rangePlugin.js +6 -2
  45. package/lib/components/FileUploader/FileUploaderButton.js +14 -16
  46. package/lib/components/Grid/CSSGrid.d.ts +9 -0
  47. package/lib/components/Grid/CSSGrid.js +8 -5
  48. package/lib/components/Grid/Column.d.ts +73 -0
  49. package/lib/components/Grid/Column.js +36 -30
  50. package/lib/components/Grid/ColumnHang.d.ts +24 -0
  51. package/lib/components/Grid/ColumnHang.js +7 -4
  52. package/lib/components/Grid/FlexGrid.d.ts +9 -0
  53. package/lib/components/Grid/FlexGrid.js +6 -3
  54. package/lib/components/Grid/Grid.d.ts +9 -0
  55. package/lib/components/Grid/Grid.js +2 -1
  56. package/lib/components/Grid/GridContext.d.ts +38 -0
  57. package/lib/components/Grid/GridContext.js +6 -6
  58. package/lib/components/Grid/GridTypes.d.ts +37 -0
  59. package/lib/components/Grid/Row.d.ts +34 -0
  60. package/lib/components/Grid/Row.js +4 -2
  61. package/lib/components/Grid/index.d.ts +11 -0
  62. package/lib/components/NumberInput/NumberInput.d.ts +132 -0
  63. package/lib/components/NumberInput/NumberInput.js +9 -7
  64. package/lib/components/TextArea/TextArea.js +1 -0
  65. package/lib/components/Toggle/Toggle.js +53 -32
  66. package/lib/components/Toggletip/index.js +26 -1
  67. package/lib/index.js +10 -10
  68. package/lib/internal/useNormalizedInputProps.js +3 -3
  69. package/package.json +3 -5
  70. package/es/_virtual/ResizeObserver.es.js +0 -13
  71. package/es/_virtual/_commonjsHelpers.js +0 -42
  72. package/es/_virtual/index.js +0 -14
  73. package/es/_virtual/rangePlugin.js +0 -14
  74. package/es/node_modules/flatpickr/dist/l10n/index.js +0 -1423
  75. package/es/node_modules/flatpickr/dist/plugins/rangePlugin.js +0 -196
  76. package/es/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -1112
  77. package/es/node_modules/use-resize-observer/polyfilled.js +0 -111
  78. package/lib/_virtual/ResizeObserver.es.js +0 -17
  79. package/lib/_virtual/_commonjsHelpers.js +0 -48
  80. package/lib/_virtual/index.js +0 -18
  81. package/lib/_virtual/rangePlugin.js +0 -18
  82. package/lib/node_modules/flatpickr/dist/l10n/index.js +0 -1427
  83. package/lib/node_modules/flatpickr/dist/plugins/rangePlugin.js +0 -200
  84. package/lib/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -1116
  85. package/lib/node_modules/use-resize-observer/polyfilled.js +0 -119
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import * as React from 'react';
8
+ export type GridMode = 'flexbox' | 'css-grid';
9
+ export interface GridSettingContext {
10
+ /**
11
+ * The grid mode for the GridContext
12
+ */
13
+ mode: GridMode;
14
+ /**
15
+ * Specifies whether subgrid should be enabled
16
+ */
17
+ subgrid?: boolean;
18
+ }
19
+ export interface GridSettingsProps {
20
+ /**
21
+ * Pass in components which will be rendered within the `GridSettings`
22
+ * component
23
+ */
24
+ children?: React.ReactNode;
25
+ /**
26
+ * Specify the grid mode for the GridContext
27
+ */
28
+ mode: GridMode;
29
+ /**
30
+ * Specify whether subgrid should be enabled
31
+ */
32
+ subgrid?: boolean;
33
+ }
34
+ export declare const GridSettings: React.FC<GridSettingsProps>;
35
+ /**
36
+ * Helper function for accessing the GridContext value
37
+ */
38
+ export declare const useGridSettings: () => GridSettingContext;
@@ -39,12 +39,11 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
39
  * Provides a grid context for communication the grid "mode" (flexbox or
40
40
  * css-grid) along with subgrid information.
41
41
  */
42
-
43
42
  var GridSettingsContext = /*#__PURE__*/React__namespace.createContext({
44
43
  mode: 'flexbox',
45
44
  subgrid: false
46
45
  });
47
- function GridSettings(_ref) {
46
+ var GridSettings = function GridSettings(_ref) {
48
47
  var children = _ref.children,
49
48
  mode = _ref.mode,
50
49
  _ref$subgrid = _ref.subgrid,
@@ -58,7 +57,8 @@ function GridSettings(_ref) {
58
57
  return /*#__PURE__*/React__namespace.createElement(GridSettingsContext.Provider, {
59
58
  value: value
60
59
  }, children);
61
- }
60
+ };
61
+ var gridModes = ['flexbox', 'css-grid'];
62
62
  GridSettings.propTypes = {
63
63
  /**
64
64
  * Pass in components which will be rendered within the `GridSettings`
@@ -69,7 +69,7 @@ GridSettings.propTypes = {
69
69
  /**
70
70
  * Specify the grid mode for the GridContext
71
71
  */
72
- mode: PropTypes__default["default"].oneOf(['flexbox', 'css-grid']).isRequired,
72
+ mode: PropTypes__default["default"].oneOf(gridModes).isRequired,
73
73
 
74
74
  /**
75
75
  * Specify whether subgrid should be enabled
@@ -80,9 +80,9 @@ GridSettings.propTypes = {
80
80
  * Helper function for accessing the GridContext value
81
81
  */
82
82
 
83
- function useGridSettings() {
83
+ var useGridSettings = function useGridSettings() {
84
84
  return React__namespace.useContext(GridSettingsContext);
85
- }
85
+ };
86
86
 
87
87
  exports.GridSettings = GridSettings;
88
88
  exports.useGridSettings = useGridSettings;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright IBM Corp. 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ /// <reference types="react" />
8
+ import { PolymorphicProps } from '../../types/common';
9
+ interface GridBaseProps {
10
+ /**
11
+ * Pass in content that will be rendered within the `Grid`
12
+ */
13
+ children?: React.ReactNode;
14
+ /**
15
+ * Specify a custom className to be applied to the `Grid`
16
+ */
17
+ className?: string;
18
+ /**
19
+ * Collapse the gutter to 1px. Useful for fluid layouts.
20
+ * Rows have 1px of margin between them to match gutter.
21
+ */
22
+ condensed?: boolean;
23
+ /**
24
+ * Remove the default max width that the grid has set
25
+ */
26
+ fullWidth?: boolean;
27
+ /**
28
+ * Container hangs 16px into the gutter. Useful for
29
+ * typographic alignment with and without containers.
30
+ */
31
+ narrow?: boolean;
32
+ }
33
+ export type GridProps<T extends React.ElementType> = PolymorphicProps<T, GridBaseProps>;
34
+ export interface GridComponent {
35
+ <T extends React.ElementType>(props: GridProps<T>, context?: any): React.ReactElement<any, any> | null;
36
+ }
37
+ export {};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import { PolymorphicProps } from '../../types/common';
9
+ export interface RowBaseProps {
10
+ /**
11
+ * Pass in content that will be rendered within the `Row`
12
+ */
13
+ children?: React.ReactNode;
14
+ /**
15
+ * Specify a custom className to be applied to the `Row`
16
+ */
17
+ className?: string;
18
+ /**
19
+ * Specify a single row as condensed.Rows that are adjacent
20
+ * and are condensed will have 2px of margin between them to match gutter.
21
+ */
22
+ condensed?: boolean;
23
+ /**
24
+ * Specify a single row as narrow. The container will hang
25
+ * 16px into the gutter.
26
+ */
27
+ narrow?: boolean;
28
+ }
29
+ export type RowProps<T extends React.ElementType> = PolymorphicProps<T, RowBaseProps>;
30
+ export interface RowComponent {
31
+ <T extends React.ElementType>(props: RowProps<T>, context?: any): React.ReactElement<any, any> | null;
32
+ }
33
+ declare const _default: RowComponent;
34
+ export default _default;
@@ -37,8 +37,10 @@ function Row(_ref) {
37
37
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
38
38
 
39
39
  var prefix = usePrefix.usePrefix();
40
- var className = cx__default["default"](containerClassName, (_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--row"), true), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--row--condensed"), condensed), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--row--narrow"), narrow), _cx));
41
- return /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({
40
+ var className = cx__default["default"](containerClassName, (_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--row"), true), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--row--condensed"), condensed), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--row--narrow"), narrow), _cx)); // TypeScript type validation reports conflicts on different instances of keyof JSX.IntrinsicElements
41
+
42
+ var BaseComponentAsAny = BaseComponent;
43
+ return /*#__PURE__*/React__default["default"].createElement(BaseComponentAsAny, _rollupPluginBabelHelpers["extends"]({
42
44
  className: className
43
45
  }, rest), children);
44
46
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export { FlexGrid } from './FlexGrid';
8
+ export { Grid } from './Grid';
9
+ export { default as Row } from './Row';
10
+ export { default as Column } from './Column';
11
+ export { ColumnHang } from './ColumnHang';
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2018
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React, { ReactNode } from 'react';
8
+ export declare const translationIds: {
9
+ 'increment.number': string;
10
+ 'decrement.number': string;
11
+ };
12
+ type ExcludedAttributes = 'defaultValue' | 'id' | 'min' | 'max' | 'onChange' | 'onClick' | 'size' | 'step' | 'value';
13
+ export interface NumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
14
+ /**
15
+ * `true` to allow empty string.
16
+ */
17
+ allowEmpty?: boolean;
18
+ /**
19
+ * Specify an optional className to be applied to the wrapper node
20
+ */
21
+ className?: string;
22
+ /**
23
+ * Optional starting value for uncontrolled state
24
+ */
25
+ defaultValue?: number | string;
26
+ /**
27
+ * Specify if the wheel functionality for the input should be disabled, or not
28
+ */
29
+ disableWheel?: boolean;
30
+ /**
31
+ * Specify if the control should be disabled, or not
32
+ */
33
+ disabled?: boolean;
34
+ /**
35
+ * Provide text that is used alongside the control label for additional help
36
+ */
37
+ helperText?: ReactNode;
38
+ /**
39
+ * Specify whether you want the underlying label to be visually hidden
40
+ */
41
+ hideLabel?: boolean;
42
+ /**
43
+ * Specify whether you want the steppers to be hidden
44
+ */
45
+ hideSteppers?: boolean;
46
+ /**
47
+ * Provide a description for up/down icons that can be read by screen readers
48
+ */
49
+ iconDescription?: string;
50
+ /**
51
+ * Specify a custom `id` for the input
52
+ */
53
+ id: string;
54
+ /**
55
+ * Specify if the currently value is invalid.
56
+ */
57
+ invalid?: boolean;
58
+ /**
59
+ * Message which is displayed if the value is invalid.
60
+ */
61
+ invalidText?: ReactNode;
62
+ /**
63
+ * Generic `label` that will be used as the textual representation of what
64
+ * this field is for
65
+ */
66
+ label?: ReactNode;
67
+ /**
68
+ * `true` to use the light version.
69
+ *
70
+ * @deprecated The `light` prop for `NumberInput` is no longer needed and has
71
+ * been deprecated in v11 in favor of the new `Layer` component. It will be moved in the next major release.
72
+ */
73
+ light?: boolean;
74
+ /**
75
+ * The maximum value.
76
+ */
77
+ max?: number;
78
+ /**
79
+ * The minimum value.
80
+ */
81
+ min?: number;
82
+ /**
83
+ * Provide an optional handler that is called when the internal state of
84
+ * NumberInput changes. This handler is called with event and state info.
85
+ * `(event, { value, direction }) => void`
86
+ */
87
+ onChange?: (event: React.MouseEvent<HTMLButtonElement>, state: {
88
+ value: number | string;
89
+ direction: string;
90
+ }) => void;
91
+ /**
92
+ * Provide an optional function to be called when the up/down button is clicked
93
+ */
94
+ onClick?: (event: React.MouseEvent<HTMLElement>, state?: {
95
+ value: number | string;
96
+ direction: string;
97
+ }) => void;
98
+ /**
99
+ * Provide an optional function to be called when a key is pressed in the number input
100
+ */
101
+ onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
102
+ /**
103
+ * Specify if the component should be read-only
104
+ */
105
+ readOnly?: boolean;
106
+ /**
107
+ * Specify the size of the Number Input.
108
+ */
109
+ size?: 'sm' | 'md' | 'lg';
110
+ /**
111
+ * Specify how much the values should increase/decrease upon clicking on up/down button
112
+ */
113
+ step?: number;
114
+ /**
115
+ * Provide custom text for the component for each translation id
116
+ */
117
+ translateWithId?: (id: string) => string;
118
+ /**
119
+ * Specify the value of the input
120
+ */
121
+ value?: number | string;
122
+ /**
123
+ * Specify whether the control is currently in warning state
124
+ */
125
+ warn?: boolean;
126
+ /**
127
+ * Provide the text that is displayed when the control is in warning state
128
+ */
129
+ warnText?: ReactNode;
130
+ }
131
+ declare const NumberInput: React.ForwardRefExoticComponent<NumberInputProps & React.RefAttributes<unknown>>;
132
+ export { NumberInput };
@@ -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
  }
package/lib/index.js CHANGED
@@ -18,6 +18,11 @@ var Dropdown = require('./components/Dropdown/Dropdown.js');
18
18
  var Dropdown_Skeleton = require('./components/Dropdown/Dropdown.Skeleton.js');
19
19
  var FluidForm = require('./components/FluidForm/FluidForm.js');
20
20
  var FormContext = require('./components/FluidForm/FormContext.js');
21
+ var FlexGrid = require('./components/Grid/FlexGrid.js');
22
+ var Grid = require('./components/Grid/Grid.js');
23
+ var Row = require('./components/Grid/Row.js');
24
+ var Column = require('./components/Grid/Column.js');
25
+ var ColumnHang = require('./components/Grid/ColumnHang.js');
21
26
  var index$4 = require('./components/IdPrefix/index.js');
22
27
  var index$5 = require('./components/OverflowMenu/index.js');
23
28
  var index$6 = require('./components/Slider/index.js');
@@ -74,8 +79,6 @@ var FileUploaderDropContainer = require('./components/FileUploader/FileUploaderD
74
79
  var FileUploaderItem = require('./components/FileUploader/FileUploaderItem.js');
75
80
  var FormItem = require('./components/FormItem/FormItem.js');
76
81
  var FormLabel = require('./components/FormLabel/FormLabel.js');
77
- var Row = require('./components/Grid/Row.js');
78
- var Column = require('./components/Grid/Column.js');
79
82
  var InlineLoading = require('./components/InlineLoading/InlineLoading.js');
80
83
  var Loading = require('./components/Loading/Loading.js');
81
84
  var NumberInput_Skeleton = require('./components/NumberInput/NumberInput.Skeleton.js');
@@ -154,9 +157,6 @@ var FileUploader = require('./components/FileUploader/FileUploader.js');
154
157
  var FilterableMultiSelect = require('./components/MultiSelect/FilterableMultiSelect.js');
155
158
  var Form = require('./components/Form/Form.js');
156
159
  var FormGroup = require('./components/FormGroup/FormGroup.js');
157
- var FlexGrid = require('./components/Grid/FlexGrid.js');
158
- var Grid = require('./components/Grid/Grid.js');
159
- var ColumnHang = require('./components/Grid/ColumnHang.js');
160
160
  var Link = require('./components/Link/Link.js');
161
161
  var ListItem = require('./components/ListItem/ListItem.js');
162
162
  var Modal = require('./components/Modal/Modal.js');
@@ -232,6 +232,11 @@ exports.Dropdown = Dropdown["default"];
232
232
  exports.DropdownSkeleton = Dropdown_Skeleton["default"];
233
233
  exports.FluidForm = FluidForm["default"];
234
234
  exports.FormContext = FormContext.FormContext;
235
+ exports.FlexGrid = FlexGrid.FlexGrid;
236
+ exports.Grid = Grid.Grid;
237
+ exports.Row = Row["default"];
238
+ exports.Column = Column["default"];
239
+ exports.ColumnHang = ColumnHang.ColumnHang;
235
240
  exports.IdPrefix = index$4.IdPrefix;
236
241
  exports.OverflowMenu = index$5["default"];
237
242
  exports.Slider = index$6["default"];
@@ -301,8 +306,6 @@ exports.FileUploaderDropContainer = FileUploaderDropContainer["default"];
301
306
  exports.FileUploaderItem = FileUploaderItem["default"];
302
307
  exports.FormItem = FormItem["default"];
303
308
  exports.FormLabel = FormLabel["default"];
304
- exports.Row = Row["default"];
305
- exports.Column = Column["default"];
306
309
  exports.InlineLoading = InlineLoading["default"];
307
310
  exports.Loading = Loading["default"];
308
311
  exports.NumberInputSkeleton = NumberInput_Skeleton["default"];
@@ -382,9 +385,6 @@ exports.FileUploader = FileUploader["default"];
382
385
  exports.FilterableMultiSelect = FilterableMultiSelect["default"];
383
386
  exports.Form = Form["default"];
384
387
  exports.FormGroup = FormGroup["default"];
385
- exports.FlexGrid = FlexGrid.FlexGrid;
386
- exports.Grid = Grid.Grid;
387
- exports.ColumnHang = ColumnHang.ColumnHang;
388
388
  exports.Link = Link["default"];
389
389
  exports.ListItem = ListItem["default"];
390
390
  exports.Modal = Modal["default"];
@@ -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",
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",
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": "6234f2b1304e340345fff3935342f80a1e36e08e"
139
137
  }