@carbon/react 1.5.0-rc.0 → 1.6.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 (79) hide show
  1. package/es/components/ComposedModal/ComposedModal.js +2 -1
  2. package/es/components/ComposedModal/next/ComposedModal.js +2 -1
  3. package/es/components/DataTable/TableActionList.js +3 -1
  4. package/es/components/DataTable/TableToolbarContent.js +3 -1
  5. package/es/components/DataTable/TableToolbarSearch.js +10 -2
  6. package/es/components/DatePicker/DatePicker.js +14 -5
  7. package/es/components/FileUploader/FileUploader.js +1 -1
  8. package/es/components/FileUploader/FileUploaderButton.js +1 -1
  9. package/es/components/FileUploader/Filename.js +1 -1
  10. package/es/components/Layer/index.js +13 -1
  11. package/es/components/Link/Link.js +6 -3
  12. package/es/components/ListBox/ListBoxPropTypes.js +1 -2
  13. package/es/components/ListBox/ListBoxSelection.js +3 -4
  14. package/es/components/OverflowMenu/OverflowMenu.js +0 -1
  15. package/es/components/RadioButton/next/RadioButton.js +2 -1
  16. package/es/components/Search/next/Search.js +1 -0
  17. package/es/components/Tabs/next/Tabs.js +42 -4
  18. package/es/components/Toggle/Toggle.js +147 -109
  19. package/es/components/UIShell/HeaderGlobalBar.js +3 -1
  20. package/es/components/UIShell/HeaderMenu.js +1 -1
  21. package/es/components/UIShell/HeaderMenuButton.js +3 -4
  22. package/es/components/UIShell/HeaderName.js +3 -4
  23. package/es/components/UIShell/HeaderNavigation.js +27 -75
  24. package/es/components/UIShell/SideNav.js +3 -3
  25. package/es/components/UIShell/SideNavFooter.js +3 -10
  26. package/es/components/UIShell/SideNavIcon.js +3 -4
  27. package/es/components/UIShell/SideNavItem.js +4 -5
  28. package/es/components/UIShell/SideNavLink.js +0 -6
  29. package/es/components/UIShell/SideNavLinkText.js +3 -4
  30. package/es/components/UIShell/SideNavMenu.js +93 -131
  31. package/es/components/UIShell/SideNavSwitcher.js +4 -2
  32. package/es/components/UIShell/SkipToContent.js +3 -4
  33. package/es/index.js +13 -11
  34. package/es/tools/wrapComponent.js +6 -4
  35. package/lib/components/ComposedModal/ComposedModal.js +2 -1
  36. package/lib/components/ComposedModal/next/ComposedModal.js +2 -1
  37. package/lib/components/DataTable/TableActionList.js +3 -1
  38. package/lib/components/DataTable/TableToolbarContent.js +3 -1
  39. package/lib/components/DataTable/TableToolbarSearch.js +10 -2
  40. package/lib/components/DatePicker/DatePicker.js +14 -5
  41. package/lib/components/FileUploader/FileUploader.js +1 -1
  42. package/lib/components/FileUploader/FileUploaderButton.js +1 -1
  43. package/lib/components/FileUploader/Filename.js +1 -1
  44. package/lib/components/Layer/index.js +13 -0
  45. package/lib/components/Link/Link.js +6 -3
  46. package/lib/components/ListBox/ListBoxPropTypes.js +1 -21
  47. package/lib/components/ListBox/ListBoxSelection.js +3 -4
  48. package/lib/components/OverflowMenu/OverflowMenu.js +0 -1
  49. package/lib/components/RadioButton/next/RadioButton.js +2 -1
  50. package/lib/components/Search/next/Search.js +1 -0
  51. package/lib/components/Tabs/next/Tabs.js +42 -4
  52. package/lib/components/Toggle/Toggle.js +146 -107
  53. package/lib/components/UIShell/HeaderGlobalBar.js +3 -1
  54. package/lib/components/UIShell/HeaderMenu.js +1 -1
  55. package/lib/components/UIShell/HeaderMenuButton.js +3 -4
  56. package/lib/components/UIShell/HeaderName.js +3 -4
  57. package/lib/components/UIShell/HeaderNavigation.js +25 -73
  58. package/lib/components/UIShell/SideNav.js +3 -3
  59. package/lib/components/UIShell/SideNavFooter.js +3 -10
  60. package/lib/components/UIShell/SideNavIcon.js +3 -4
  61. package/lib/components/UIShell/SideNavItem.js +4 -5
  62. package/lib/components/UIShell/SideNavLink.js +0 -6
  63. package/lib/components/UIShell/SideNavLinkText.js +3 -4
  64. package/lib/components/UIShell/SideNavMenu.js +89 -128
  65. package/lib/components/UIShell/SideNavSwitcher.js +4 -2
  66. package/lib/components/UIShell/SkipToContent.js +3 -4
  67. package/lib/index.js +86 -82
  68. package/lib/tools/wrapComponent.js +6 -4
  69. package/package.json +18 -18
  70. package/es/components/Toggle/index.js +0 -19
  71. package/es/components/Toggle/next/Toggle.js +0 -158
  72. package/es/components/UIShell/index.js +0 -17
  73. package/es/components/UIShell/next/HeaderNavigation.js +0 -52
  74. package/es/components/UIShell/next/SideNavMenu.js +0 -160
  75. package/lib/components/Toggle/index.js +0 -23
  76. package/lib/components/Toggle/next/Toggle.js +0 -169
  77. package/lib/components/UIShell/index.js +0 -42
  78. package/lib/components/UIShell/next/HeaderNavigation.js +0 -62
  79. package/lib/components/UIShell/next/SideNavMenu.js +0 -170
@@ -223,7 +223,8 @@ var ComposedModal = /*#__PURE__*/function (_Component) {
223
223
  onClick: this.handleClick,
224
224
  onKeyDown: this.handleKeyDown,
225
225
  onTransitionEnd: open ? this.handleTransitionEnd : undefined,
226
- className: modalClass
226
+ className: modalClass,
227
+ tabIndex: "-1"
227
228
  }), /*#__PURE__*/React__default.createElement("span", {
228
229
  ref: this.startSentinel,
229
230
  tabIndex: "0",
@@ -194,7 +194,8 @@ var ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedModa
194
194
  onBlur: handleBlur,
195
195
  onClick: handleClick,
196
196
  onKeyDown: handleKeyDown,
197
- className: modalClass
197
+ className: modalClass,
198
+ tabIndex: "-1"
198
199
  }), /*#__PURE__*/React__default.createElement("div", {
199
200
  className: containerClass,
200
201
  role: "dialog",
@@ -10,7 +10,9 @@ import wrapComponent from '../../tools/wrapComponent.js';
10
10
  var TableActionList = wrapComponent({
11
11
  name: 'TableActionList',
12
12
  type: 'div',
13
- className: "cds--action-list"
13
+ className: function className(prefix) {
14
+ return "".concat(prefix, "--action-list");
15
+ }
14
16
  });
15
17
  var TableActionList$1 = TableActionList;
16
18
 
@@ -10,7 +10,9 @@ import wrapComponent from '../../tools/wrapComponent.js';
10
10
  var TableToolbarContent = wrapComponent({
11
11
  name: 'TableToolbarContent',
12
12
  type: 'div',
13
- className: "cds--toolbar-content"
13
+ className: function className(prefix) {
14
+ return "".concat(prefix, "--toolbar-content");
15
+ }
14
16
  });
15
17
  var TableToolbarContent$1 = TableToolbarContent;
16
18
 
@@ -13,7 +13,7 @@ import Search from '../Search/index.js';
13
13
  import setupGetInstanceId from './tools/instanceId.js';
14
14
  import { usePrefix } from '../../internal/usePrefix.js';
15
15
 
16
- var _excluded = ["className", "searchContainerClass", "onChange", "onClear", "translateWithId", "placeholder", "labelText", "expanded", "defaultExpanded", "defaultValue", "disabled", "onExpand", "persistent", "id", "onBlur", "onFocus"];
16
+ var _excluded = ["className", "searchContainerClass", "onChange", "onClear", "translateWithId", "placeholder", "labelText", "expanded", "defaultExpanded", "defaultValue", "disabled", "onExpand", "persistent", "id", "onBlur", "onFocus", "size"];
17
17
  var getInstanceId = setupGetInstanceId();
18
18
  var translationKeys = {
19
19
  'carbon.table.toolbar.search.label': 'Filter table',
@@ -43,6 +43,8 @@ var TableToolbarSearch = function TableToolbarSearch(_ref) {
43
43
  id = _ref.id,
44
44
  onBlur = _ref.onBlur,
45
45
  onFocus = _ref.onFocus,
46
+ _ref$size = _ref.size,
47
+ size = _ref$size === void 0 ? 'lg' : _ref$size,
46
48
  rest = _objectWithoutProperties(_ref, _excluded);
47
49
 
48
50
  var _useRef = useRef(expandedProp !== undefined),
@@ -126,7 +128,8 @@ var TableToolbarSearch = function TableToolbarSearch(_ref) {
126
128
  } : handleOnFocus,
127
129
  onBlur: onBlur ? function (event) {
128
130
  return onBlur(event, handleExpand);
129
- } : handleOnBlur
131
+ } : handleOnBlur,
132
+ size: size
130
133
  }, rest));
131
134
  };
132
135
 
@@ -212,6 +215,11 @@ TableToolbarSearch.propTypes = {
212
215
  */
213
216
  searchContainerClass: PropTypes.string,
214
217
 
218
+ /**
219
+ * Specify the size of the Search
220
+ */
221
+ size: PropTypes.oneOf(['sm', 'md', 'lg']),
222
+
215
223
  /**
216
224
  * Optional prop to specify the tabIndex of the <Search> (in expanded state) or the container (in collapsed state)
217
225
  */
@@ -20,7 +20,7 @@ import { useSavedCallback } from '../../internal/useSavedCallback.js';
20
20
  import { match } from '../../internal/keyboard/match.js';
21
21
  import { ArrowDown } from '../../internal/keyboard/keys.js';
22
22
 
23
- var _excluded = ["allowInput", "appendTo", "children", "className", "dateFormat", "datePickerType", "disable", "enable", "inline", "light", "locale", "maxDate", "minDate", "onChange", "onClose", "onOpen", "short", "value"];
23
+ var _excluded = ["allowInput", "appendTo", "children", "className", "closeOnSelect", "dateFormat", "datePickerType", "disable", "enable", "inline", "light", "locale", "maxDate", "minDate", "onChange", "onClose", "onOpen", "short", "value"];
24
24
 
25
25
  l10n.en.weekdays.shorthand.forEach(function (_day, index) {
26
26
  var currentDay = l10n.en.weekdays.shorthand;
@@ -152,6 +152,8 @@ function DatePicker(_ref) {
152
152
  appendTo = _ref.appendTo,
153
153
  children = _ref.children,
154
154
  className = _ref.className,
155
+ _ref$closeOnSelect = _ref.closeOnSelect,
156
+ closeOnSelect = _ref$closeOnSelect === void 0 ? true : _ref$closeOnSelect,
155
157
  _ref$dateFormat = _ref.dateFormat,
156
158
  dateFormat = _ref$dateFormat === void 0 ? 'm/d/Y' : _ref$dateFormat,
157
159
  datePickerType = _ref.datePickerType,
@@ -251,6 +253,7 @@ function DatePicker(_ref) {
251
253
  inline: inline !== null && inline !== void 0 ? inline : false,
252
254
  disableMobile: true,
253
255
  defaultDate: value,
256
+ closeOnSelect: closeOnSelect,
254
257
  mode: datePickerType,
255
258
  allowInput: allowInput !== null && allowInput !== void 0 ? allowInput : true,
256
259
  dateFormat: dateFormat,
@@ -311,7 +314,7 @@ function DatePicker(_ref) {
311
314
  // error with IBM Equal Access Accessibility Checker so we add an aria
312
315
  // role to the container div.
313
316
 
314
- calendar.calendarContainer.setAttribute('role', 'region'); // IBM EAAC requires an aria-label on a role='region'
317
+ calendar.calendarContainer.setAttribute('role', 'application'); // IBM EAAC requires an aria-label on a role='region'
315
318
 
316
319
  calendar.calendarContainer.setAttribute('aria-label', 'calendar-container');
317
320
  }
@@ -375,9 +378,10 @@ function DatePicker(_ref) {
375
378
  }, [inline]);
376
379
  useEffect(function () {
377
380
  if (calendarRef.current) {
378
- calendarRef.current.set({
379
- value: value
380
- });
381
+ if (value !== undefined) {
382
+ calendarRef.current.setDate(value);
383
+ }
384
+
381
385
  updateClassNames(calendarRef.current, prefix); //for simple date picker w/o calendar; initial mount may not have value
382
386
  } else if (!calendarRef.current && value) {
383
387
  startInputField.current.value = value;
@@ -412,6 +416,11 @@ DatePicker.propTypes = {
412
416
  */
413
417
  className: PropTypes.string,
414
418
 
419
+ /**
420
+ * flatpickr prop passthrough. Controls whether the calendar dropdown closes upon selection.
421
+ */
422
+ closeOnSelect: PropTypes.bool,
423
+
415
424
  /**
416
425
  * The date format.
417
426
  */
@@ -224,7 +224,7 @@ _defineProperty(FileUploader, "propTypes", {
224
224
  iconDescription: FeatureFlags.enabled('enable-v11-release') ? PropTypes.string.isRequired : PropTypes.string,
225
225
 
226
226
  /**
227
- * Specify the description text of this <FileUploader>
227
+ * Specify the description text of this `<FileUploader>`
228
228
  */
229
229
  labelDescription: PropTypes.string,
230
230
 
@@ -146,7 +146,7 @@ FileUploaderButton.propTypes = {
146
146
  disabled: PropTypes.bool,
147
147
 
148
148
  /**
149
- * Provide a unique id for the underlying <input> node
149
+ * Provide a unique id for the underlying `<input>` node
150
150
  */
151
151
  id: PropTypes.string,
152
152
 
@@ -69,7 +69,7 @@ Filename.propTypes = {
69
69
  status: PropTypes.oneOf(['edit', 'complete', 'uploading']),
70
70
 
71
71
  /**
72
- * Provide a custom tabIndex value for the <Filename>
72
+ * Provide a custom tabIndex value for the `<Filename>`
73
73
  */
74
74
  tabIndex: PropTypes.string
75
75
  };
@@ -15,6 +15,18 @@ import { LayerContext } from './LayerContext.js';
15
15
  var _excluded = ["as", "className", "children", "level"];
16
16
  var levels = ['one', 'two', 'three'];
17
17
  var MAX_LEVEL = levels.length - 1;
18
+ /**
19
+ * A custom hook that will return information about the current layer. A common
20
+ * field to pull from this is the `level` for the layer that the component that
21
+ * calls this hook is currently in
22
+ */
23
+
24
+ function useLayer() {
25
+ var level = React__default.useContext(LayerContext);
26
+ return {
27
+ level: level
28
+ };
29
+ }
18
30
  function Layer(_ref) {
19
31
  var _ref$as = _ref.as,
20
32
  BaseComponent = _ref$as === void 0 ? 'div' : _ref$as,
@@ -59,4 +71,4 @@ Layer.propTypes = {
59
71
  level: PropTypes.oneOf([0, 1, 2])
60
72
  };
61
73
 
62
- export { Layer };
74
+ export { Layer, useLayer };
@@ -18,9 +18,12 @@ var Link = /*#__PURE__*/React__default.forwardRef(function Link(_ref, ref) {
18
18
  var children = _ref.children,
19
19
  customClassName = _ref.className,
20
20
  href = _ref.href,
21
- disabled = _ref.disabled,
22
- inline = _ref.inline,
23
- visited = _ref.visited,
21
+ _ref$disabled = _ref.disabled,
22
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
23
+ _ref$inline = _ref.inline,
24
+ inline = _ref$inline === void 0 ? false : _ref$inline,
25
+ _ref$visited = _ref.visited,
26
+ visited = _ref$visited === void 0 ? false : _ref$visited,
24
27
  Icon = _ref.renderIcon,
25
28
  size = _ref.size,
26
29
  rest = _objectWithoutProperties(_ref, _excluded);
@@ -6,9 +6,8 @@
6
6
  */
7
7
 
8
8
  import PropTypes from 'prop-types';
9
- import * as FeatureFlags from '@carbon/feature-flags';
10
9
 
11
10
  var ListBoxType = PropTypes.oneOf(['default', 'inline']);
12
- var ListBoxSize = FeatureFlags.enabled('enable-v11-release') ? PropTypes.oneOf(['sm', 'md', 'lg']) : PropTypes.oneOf(['sm', 'md', 'lg', 'xl']);
11
+ var ListBoxSize = PropTypes.oneOf(['sm', 'md', 'lg']);
13
12
 
14
13
  export { ListBoxSize, ListBoxType };
@@ -21,7 +21,7 @@ var _Close, _Close2, _defaultTranslations;
21
21
  * selection.
22
22
  */
23
23
 
24
- var ListBoxSelection = function ListBoxSelection(_ref) {
24
+ function ListBoxSelection(_ref) {
25
25
  var _cx;
26
26
 
27
27
  var clearSelection = _ref.clearSelection,
@@ -88,7 +88,7 @@ var ListBoxSelection = function ListBoxSelection(_ref) {
88
88
  "aria-label": description,
89
89
  title: description
90
90
  }, selectionCount, _Close2 || (_Close2 = /*#__PURE__*/React__default.createElement(Close, null)));
91
- };
91
+ }
92
92
 
93
93
  var translationIds = {
94
94
  'clear.all': 'clear.all',
@@ -143,6 +143,5 @@ ListBoxSelection.defaultProps = {
143
143
  return defaultTranslations[id];
144
144
  }
145
145
  };
146
- var ListBoxSelection$1 = ListBoxSelection;
147
146
 
148
- export { ListBoxSelection$1 as default, translationIds };
147
+ export { ListBoxSelection as default, translationIds };
@@ -509,7 +509,6 @@ _defineProperty(OverflowMenu, "defaultProps", {
509
509
  onOpen: function onOpen() {},
510
510
  menuOffset: getMenuOffset,
511
511
  menuOffsetFlip: getMenuOffset,
512
- light: false,
513
512
  selectorPrimaryFocus: '[data-overflow-menu-primary-focus]'
514
513
  });
515
514
 
@@ -50,7 +50,8 @@ var RadioButton = /*#__PURE__*/React__default.forwardRef(function RadioButton(_r
50
50
  id: uniqueId,
51
51
  ref: ref,
52
52
  disabled: disabled,
53
- value: value
53
+ value: value,
54
+ name: name
54
55
  })), /*#__PURE__*/React__default.createElement("label", {
55
56
  htmlFor: uniqueId,
56
57
  className: "".concat(prefix, "--radio-button__label")
@@ -143,6 +143,7 @@ var Search = /*#__PURE__*/React__default.forwardRef(function Search(_ref, forwar
143
143
  className: clearClasses,
144
144
  disabled: disabled,
145
145
  onClick: clearInput,
146
+ title: closeButtonLabelText,
146
147
  type: "button"
147
148
  }, _Close || (_Close = /*#__PURE__*/React__default.createElement(Close, null))));
148
149
  });
@@ -597,6 +597,11 @@ var TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7, f
597
597
  tabIndex = _useState8[0],
598
598
  setTabIndex = _useState8[1];
599
599
 
600
+ var _useState9 = useState(false),
601
+ _useState10 = _slicedToArray(_useState9, 2),
602
+ interactiveContent = _useState10[0],
603
+ setInteractiveContent = _useState10[1];
604
+
600
605
  var _React$useContext3 = React__default.useContext(TabsContext),
601
606
  selectedIndex = _React$useContext3.selectedIndex,
602
607
  baseId = _React$useContext3.baseId;
@@ -604,14 +609,47 @@ var TabPanel = /*#__PURE__*/React__default.forwardRef(function TabPanel(_ref7, f
604
609
  var index = React__default.useContext(TabPanelContext);
605
610
  var id = "".concat(baseId, "-tabpanel-").concat(index);
606
611
  var tabId = "".concat(baseId, "-tab-").concat(index);
607
- var className = cx("".concat(prefix, "--tab-content"), customClassName); // tabindex should only be 0 if no interactive content in children
612
+ var className = cx("".concat(prefix, "--tab-content"), customClassName, _defineProperty({}, "".concat(prefix, "--tab-content--interactive"), interactiveContent));
613
+ useEffectOnce(function () {
614
+ if (!panel.current) {
615
+ return;
616
+ }
608
617
 
609
- useEffect(function () {
610
- var interactiveContent = getInteractiveContent(panel.current);
618
+ var content = getInteractiveContent(panel.current);
611
619
 
612
- if (interactiveContent) {
620
+ if (content) {
621
+ setInteractiveContent(true);
613
622
  setTabIndex('-1');
614
623
  }
624
+ }); // tabindex should only be 0 if no interactive content in children
625
+
626
+ useEffect(function () {
627
+ if (!panel.current) {
628
+ return;
629
+ }
630
+
631
+ var node = panel.current;
632
+
633
+ function callback() {
634
+ var content = getInteractiveContent(node);
635
+
636
+ if (content) {
637
+ setInteractiveContent(true);
638
+ setTabIndex('-1');
639
+ } else {
640
+ setInteractiveContent(false);
641
+ setTabIndex('0');
642
+ }
643
+ }
644
+
645
+ var observer = new MutationObserver(callback);
646
+ observer.observe(node, {
647
+ childList: true,
648
+ subtree: true
649
+ });
650
+ return function () {
651
+ observer.disconnect(node);
652
+ };
615
653
  }, []);
616
654
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
617
655
  "aria-labelledby": tabId,
@@ -5,116 +5,154 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import PropTypes from 'prop-types';
8
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
10
9
  import React__default from 'react';
10
+ import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
13
- import { PrefixContext } from '../../internal/usePrefix.js';
14
- import { match } from '../../internal/keyboard/match.js';
15
- import { Enter } from '../../internal/keyboard/keys.js';
16
-
17
- var _path, _defineProperty2, _defineProperty3;
18
-
19
- var _excluded = ["className", "defaultToggled", "toggled", "onChange", "onToggle", "id", "labelText", "labelA", "labelB", "size"];
20
- var getInstanceId = setupGetInstanceId();
21
-
22
- var Toggle = /*#__PURE__*/function (_React$Component) {
23
- _inherits(Toggle, _React$Component);
24
-
25
- var _super = _createSuper(Toggle);
26
-
27
- function Toggle() {
28
- _classCallCheck(this, Toggle);
29
-
30
- return _super.apply(this, arguments);
31
- }
32
-
33
- _createClass(Toggle, [{
34
- key: "render",
35
- value: function render() {
36
- var prefix = this.context;
37
-
38
- var _this$props = this.props,
39
- className = _this$props.className,
40
- defaultToggled = _this$props.defaultToggled,
41
- toggled = _this$props.toggled,
42
- _onChange = _this$props.onChange,
43
- onToggle = _this$props.onToggle,
44
- _this$props$id = _this$props.id,
45
- id = _this$props$id === void 0 ? this.inputId = this.inputId || "__carbon-toggle_".concat(getInstanceId()) : _this$props$id,
46
- labelText = _this$props.labelText,
47
- labelA = _this$props.labelA,
48
- labelB = _this$props.labelB,
49
- size = _this$props.size,
50
- other = _objectWithoutProperties(_this$props, _excluded);
51
-
52
- var input;
53
- var wrapperClasses = cx("".concat(prefix, "--form-item"), _defineProperty({}, className, className));
54
- var toggleClasses = cx("".concat(prefix, "--toggle-input"), _defineProperty({}, "".concat(prefix, "--toggle-input--small"), size === 'sm'));
55
- var checkedProps = {};
56
-
57
- if (typeof toggled !== 'undefined') {
58
- checkedProps.checked = toggled;
59
- } else {
60
- checkedProps.defaultChecked = defaultToggled;
61
- }
62
-
63
- return /*#__PURE__*/React__default.createElement("div", {
64
- className: wrapperClasses
65
- }, /*#__PURE__*/React__default.createElement("input", _extends({}, other, checkedProps, {
66
- "aria-label": null,
67
- type: "checkbox",
68
- id: id,
69
- className: toggleClasses,
70
- onChange: function onChange(evt) {
71
- _onChange && _onChange(evt);
72
- onToggle(input.checked, id, evt);
73
- },
74
- ref: function ref(el) {
75
- input = el;
76
- },
77
- onKeyUp: function onKeyUp(evt) {
78
- if (match(evt, Enter)) {
79
- input.checked = !input.checked;
80
- _onChange && _onChange(evt);
81
- onToggle(input.checked, id, evt);
82
- }
83
- }
84
- })), /*#__PURE__*/React__default.createElement("label", {
85
- className: "".concat(prefix, "--toggle-input__label"),
86
- htmlFor: id,
87
- "aria-label": typeof labelText === 'string' ? null : this.props['aria-label']
88
- }, labelText, /*#__PURE__*/React__default.createElement("span", {
89
- className: "".concat(prefix, "--toggle__switch")
90
- }, size && /*#__PURE__*/React__default.createElement("svg", {
91
- className: "".concat(prefix, "--toggle__check"),
92
- width: "6px",
93
- height: "5px",
94
- viewBox: "0 0 6 5"
95
- }, _path || (_path = /*#__PURE__*/React__default.createElement("path", {
96
- d: "M2.2 2.7L5 0 6 1 2.2 5 0 2.7 1 1.5z"
97
- }))), /*#__PURE__*/React__default.createElement("span", {
98
- className: "".concat(prefix, "--toggle__text--off"),
99
- "aria-hidden": "true"
100
- }, labelA), /*#__PURE__*/React__default.createElement("span", {
101
- className: "".concat(prefix, "--toggle__text--on"),
102
- "aria-hidden": "true"
103
- }, labelB))));
12
+ import { useControllableState } from '../../internal/useControllableState.js';
13
+ import { usePrefix } from '../../internal/usePrefix.js';
14
+
15
+ var _path;
16
+
17
+ var _excluded = ["className", "defaultToggled", "disabled", "hideLabel", "id", "labelA", "labelB", "labelText", "onClick", "onToggle", "size", "toggled"];
18
+ function Toggle(_ref) {
19
+ var className = _ref.className,
20
+ _ref$defaultToggled = _ref.defaultToggled,
21
+ defaultToggled = _ref$defaultToggled === void 0 ? false : _ref$defaultToggled,
22
+ _ref$disabled = _ref.disabled,
23
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
24
+ _ref$hideLabel = _ref.hideLabel,
25
+ hideLabel = _ref$hideLabel === void 0 ? false : _ref$hideLabel,
26
+ id = _ref.id,
27
+ _ref$labelA = _ref.labelA,
28
+ labelA = _ref$labelA === void 0 ? 'Off' : _ref$labelA,
29
+ _ref$labelB = _ref.labelB,
30
+ labelB = _ref$labelB === void 0 ? 'On' : _ref$labelB,
31
+ labelText = _ref.labelText,
32
+ onClick = _ref.onClick,
33
+ onToggle = _ref.onToggle,
34
+ _ref$size = _ref.size,
35
+ size = _ref$size === void 0 ? 'md' : _ref$size,
36
+ toggled = _ref.toggled,
37
+ other = _objectWithoutProperties(_ref, _excluded);
38
+
39
+ var prefix = usePrefix();
40
+
41
+ var _useControllableState = useControllableState({
42
+ value: toggled,
43
+ onChange: onToggle,
44
+ defaultValue: defaultToggled
45
+ }),
46
+ _useControllableState2 = _slicedToArray(_useControllableState, 2),
47
+ checked = _useControllableState2[0],
48
+ setChecked = _useControllableState2[1];
49
+
50
+ function handleClick(e) {
51
+ setChecked(!checked);
52
+
53
+ if (onClick) {
54
+ onClick(e);
104
55
  }
105
- }]);
106
-
107
- return Toggle;
108
- }(React__default.Component);
109
-
110
- _defineProperty(Toggle, "propTypes", (_defineProperty2 = {}, _defineProperty(_defineProperty2, 'aria-label', PropTypes.string.isRequired), _defineProperty(_defineProperty2, "className", PropTypes.string), _defineProperty(_defineProperty2, "defaultToggled", PropTypes.bool), _defineProperty(_defineProperty2, "id", PropTypes.string.isRequired), _defineProperty(_defineProperty2, "labelA", PropTypes.node.isRequired), _defineProperty(_defineProperty2, "labelB", PropTypes.node.isRequired), _defineProperty(_defineProperty2, "labelText", PropTypes.node), _defineProperty(_defineProperty2, "onChange", PropTypes.func), _defineProperty(_defineProperty2, "onToggle", PropTypes.func), _defineProperty(_defineProperty2, "size", PropTypes.oneOf(['sm', 'md'])), _defineProperty(_defineProperty2, "toggled", PropTypes.bool), _defineProperty2));
111
-
112
- _defineProperty(Toggle, "contextType", PrefixContext);
113
-
114
- _defineProperty(Toggle, "defaultProps", (_defineProperty3 = {
115
- defaultToggled: false
116
- }, _defineProperty(_defineProperty3, 'aria-label', 'Toggle'), _defineProperty(_defineProperty3, "labelA", 'Off'), _defineProperty(_defineProperty3, "labelB", 'On'), _defineProperty(_defineProperty3, "onToggle", function onToggle() {}), _defineProperty3));
117
-
118
- var ToggleClassic = Toggle;
56
+ }
119
57
 
120
- export { ToggleClassic as default };
58
+ var isSm = size === 'sm';
59
+ var sideLabel = hideLabel ? labelText : checked ? labelB : labelA;
60
+ var wrapperClasses = cx("".concat(prefix, "--toggle"), _defineProperty({}, "".concat(prefix, "--toggle--disabled"), disabled), className);
61
+ var labelTextClasses = cx("".concat(prefix, "--toggle__label-text"), _defineProperty({}, "".concat(prefix, "--visually-hidden"), hideLabel));
62
+ var appearanceClasses = cx("".concat(prefix, "--toggle__appearance"), _defineProperty({}, "".concat(prefix, "--toggle__appearance--sm"), isSm));
63
+ var switchClasses = cx("".concat(prefix, "--toggle__switch"), _defineProperty({}, "".concat(prefix, "--toggle__switch--checked"), checked));
64
+ return /*#__PURE__*/React__default.createElement("div", {
65
+ className: wrapperClasses
66
+ }, /*#__PURE__*/React__default.createElement("button", _extends({}, other, {
67
+ id: id,
68
+ className: "".concat(prefix, "--toggle__button"),
69
+ role: "switch",
70
+ type: "button",
71
+ "aria-checked": checked,
72
+ disabled: disabled,
73
+ onClick: handleClick
74
+ })), /*#__PURE__*/React__default.createElement("label", {
75
+ htmlFor: id,
76
+ className: "".concat(prefix, "--toggle__label")
77
+ }, /*#__PURE__*/React__default.createElement("span", {
78
+ className: labelTextClasses
79
+ }, labelText), /*#__PURE__*/React__default.createElement("div", {
80
+ className: appearanceClasses
81
+ }, /*#__PURE__*/React__default.createElement("div", {
82
+ className: switchClasses
83
+ }, isSm && /*#__PURE__*/React__default.createElement("svg", {
84
+ className: "".concat(prefix, "--toggle__check"),
85
+ width: "6px",
86
+ height: "5px",
87
+ viewBox: "0 0 6 5"
88
+ }, _path || (_path = /*#__PURE__*/React__default.createElement("path", {
89
+ d: "M2.2 2.7L5 0 6 1 2.2 5 0 2.7 1 1.5z"
90
+ })))), /*#__PURE__*/React__default.createElement("span", {
91
+ className: "".concat(prefix, "--toggle__text"),
92
+ "aria-hidden": "true"
93
+ }, sideLabel))));
94
+ }
95
+ Toggle.propTypes = {
96
+ /**
97
+ * Specify a custom className to apply to the form-item node
98
+ */
99
+ className: PropTypes.string,
100
+
101
+ /**
102
+ * Specify whether the toggle should be on by default
103
+ */
104
+ defaultToggled: PropTypes.bool,
105
+
106
+ /**
107
+ * Whether this control should be disabled
108
+ */
109
+ disabled: PropTypes.bool,
110
+
111
+ /**
112
+ * Specify whether the label should be hidden, or not
113
+ */
114
+ hideLabel: PropTypes.bool,
115
+
116
+ /**
117
+ * Provide an id that unique represents the underlying `<button>`
118
+ */
119
+ id: PropTypes.string.isRequired,
120
+
121
+ /**
122
+ * Specify the label for the "off" position
123
+ */
124
+ labelA: PropTypes.node,
125
+
126
+ /**
127
+ * Specify the label for the "on" position
128
+ */
129
+ labelB: PropTypes.node,
130
+
131
+ /**
132
+ * Provide the text that will be read by a screen reader when visiting this
133
+ * control
134
+ */
135
+ labelText: PropTypes.node.isRequired,
136
+
137
+ /**
138
+ * Provide an event listener that is called when the control is clicked
139
+ */
140
+ onClick: PropTypes.func,
141
+
142
+ /**
143
+ * Provide an event listener that is called when the control is toggled
144
+ */
145
+ onToggle: PropTypes.func,
146
+
147
+ /**
148
+ * Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
149
+ */
150
+ size: PropTypes.oneOf(['sm', 'md']),
151
+
152
+ /**
153
+ * Specify whether the control is toggled
154
+ */
155
+ toggled: PropTypes.bool
156
+ };
157
+
158
+ export { Toggle, Toggle as default };
@@ -13,7 +13,9 @@ import wrapComponent from '../../tools/wrapComponent.js';
13
13
 
14
14
  var HeaderGlobalBar = wrapComponent({
15
15
  name: 'HeaderGlobalBar',
16
- className: "cds--header__global",
16
+ className: function className(prefix) {
17
+ return "".concat(prefix, "--header__global");
18
+ },
17
19
  type: 'div'
18
20
  });
19
21
 
@@ -163,7 +163,7 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
163
163
  'aria-label': ariaLabel,
164
164
  'aria-labelledby': ariaLabelledBy
165
165
  };
166
- var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--header__submenu"), true), _defineProperty(_cx, customClassName, true), _defineProperty(_cx, "".concat(prefix, "--header__submenu--current"), isCurrentPage), _cx)); // Notes on eslint comments and based on the examples in:
166
+ var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--header__submenu"), true), _defineProperty(_cx, "".concat(prefix, "--header__submenu--current"), isCurrentPage), _defineProperty(_cx, customClassName, !!customClassName), _cx)); // Notes on eslint comments and based on the examples in:
167
167
  // https://www.w3.org/TR/wai-aria-practices/examples/menubar/menubar-1/menubar-1.html#
168
168
  // - The focus is handled by the <a> menuitem, onMouseOver is for mouse
169
169
  // users