@carbon/ibm-products 2.30.0 → 2.31.0-alpha.5

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 (75) hide show
  1. package/css/index-full-carbon.css +242 -23
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +4 -4
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +242 -23
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +1 -1
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +238 -19
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +1 -1
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/ComboButton/ComboButton.d.ts +38 -18
  18. package/es/components/ComboButton/ComboButton.js +25 -21
  19. package/es/components/ComboButton/ComboButtonItem/index.d.ts +22 -13
  20. package/es/components/Datagrid/Datagrid/addons/stateReducer.js +7 -0
  21. package/es/components/EditInPlace/EditInPlace.js +4 -5
  22. package/es/components/Nav/Nav.d.ts +3 -0
  23. package/es/components/Nav/Nav.js +154 -0
  24. package/es/components/Nav/NavItem.d.ts +35 -0
  25. package/es/components/Nav/NavItem.js +149 -0
  26. package/es/components/Nav/NavItemLink.d.ts +3 -0
  27. package/es/components/Nav/NavItemLink.js +30 -0
  28. package/es/components/Nav/NavList.d.ts +4 -0
  29. package/es/components/Nav/NavList.js +168 -0
  30. package/es/components/Nav/index.d.ts +3 -0
  31. package/es/components/Tearsheet/TearsheetShell.js +22 -7
  32. package/es/components/index.d.ts +1 -0
  33. package/es/global/js/package-settings.d.ts +1 -0
  34. package/es/global/js/package-settings.js +1 -0
  35. package/es/index.js +1 -0
  36. package/es/node_modules/@carbon/icon-helpers/es/index.js +140 -0
  37. package/es/node_modules/@carbon/icons-react/es/Icon.js +73 -0
  38. package/es/node_modules/@carbon/icons-react/es/generated/bucket-2.js +3091 -0
  39. package/es/node_modules/@carbon/icons-react/es/generated/bucket-8.js +3004 -0
  40. package/es/node_modules/@carbon/icons-react/es/iconPropTypes-4cbeb95d.js +14 -0
  41. package/es/settings.d.ts +1 -0
  42. package/lib/components/ComboButton/ComboButton.d.ts +38 -18
  43. package/lib/components/ComboButton/ComboButton.js +24 -20
  44. package/lib/components/ComboButton/ComboButtonItem/index.d.ts +22 -13
  45. package/lib/components/Datagrid/Datagrid/addons/stateReducer.js +7 -0
  46. package/lib/components/EditInPlace/EditInPlace.js +4 -5
  47. package/lib/components/Nav/Nav.d.ts +3 -0
  48. package/lib/components/Nav/Nav.js +161 -0
  49. package/lib/components/Nav/NavItem.d.ts +35 -0
  50. package/lib/components/Nav/NavItem.js +160 -0
  51. package/lib/components/Nav/NavItemLink.d.ts +3 -0
  52. package/lib/components/Nav/NavItemLink.js +38 -0
  53. package/lib/components/Nav/NavList.d.ts +4 -0
  54. package/lib/components/Nav/NavList.js +179 -0
  55. package/lib/components/Nav/index.d.ts +3 -0
  56. package/lib/components/Tearsheet/TearsheetShell.js +22 -7
  57. package/lib/components/index.d.ts +1 -0
  58. package/lib/global/js/package-settings.d.ts +1 -0
  59. package/lib/global/js/package-settings.js +1 -0
  60. package/lib/index.js +5 -0
  61. package/lib/node_modules/@carbon/icon-helpers/es/index.js +145 -0
  62. package/lib/node_modules/@carbon/icons-react/es/Icon.js +81 -0
  63. package/lib/node_modules/@carbon/icons-react/es/generated/bucket-2.js +3223 -0
  64. package/lib/node_modules/@carbon/icons-react/es/generated/bucket-8.js +3136 -0
  65. package/lib/node_modules/@carbon/icons-react/es/iconPropTypes-4cbeb95d.js +18 -0
  66. package/lib/settings.d.ts +1 -0
  67. package/package.json +3 -3
  68. package/scss/components/ComboButton/_combo-button.scss +19 -21
  69. package/scss/components/Nav/_carbon-imports.scss +9 -0
  70. package/scss/components/Nav/_index-with-carbon.scss +9 -0
  71. package/scss/components/Nav/_index.scss +8 -0
  72. package/scss/components/Nav/_nav.scss +259 -0
  73. package/scss/components/Tearsheet/_tearsheet.scss +24 -6
  74. package/scss/components/_index-with-carbon.scss +1 -0
  75. package/scss/components/_index.scss +1 -0
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020, 2024
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 { slicedToArray as _slicedToArray, extends as _extends, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default, { useState, useEffect, useImperativeHandle } from 'react';
10
+ import cx from 'classnames';
11
+ import { p as propTypesExports } from '../../node_modules/prop-types/index.js';
12
+ import NavItem, { blockClass as blockClass$1 } from './NavItem.js';
13
+ import { pkg } from '../../settings.js';
14
+ import { ChevronDown } from '../../node_modules/@carbon/icons-react/es/generated/bucket-2.js';
15
+
16
+ var componentName = 'NavList';
17
+ var blockClass = "".concat(pkg.prefix, "--nav-list");
18
+
19
+ // Default values for props
20
+ var defaults = {
21
+ activeHref: '#',
22
+ className: '',
23
+ children: null,
24
+ id: '',
25
+ isExpandedOnPageload: false,
26
+ onItemClick: function onItemClick() {},
27
+ onListClick: function onListClick() {},
28
+ tabIndex: 0,
29
+ title: '',
30
+ icon: '',
31
+ navigationItemTitle: ''
32
+ };
33
+ var NavList = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
34
+ var _ref$activeHref = _ref.activeHref,
35
+ activeHref = _ref$activeHref === void 0 ? defaults.activeHref : _ref$activeHref,
36
+ _ref$children = _ref.children,
37
+ children = _ref$children === void 0 ? defaults.children : _ref$children,
38
+ _ref$className = _ref.className,
39
+ className = _ref$className === void 0 ? defaults.className : _ref$className,
40
+ _ref$icon = _ref.icon,
41
+ icon = _ref$icon === void 0 ? defaults.icon : _ref$icon,
42
+ _ref$id = _ref.id,
43
+ id = _ref$id === void 0 ? defaults.id : _ref$id,
44
+ _ref$isExpandedOnPage = _ref.isExpandedOnPageload,
45
+ isExpandedOnPageload = _ref$isExpandedOnPage === void 0 ? defaults.isExpandedOnPageload : _ref$isExpandedOnPage,
46
+ _ref$navigationItemTi = _ref.navigationItemTitle,
47
+ navigationItemTitle = _ref$navigationItemTi === void 0 ? defaults.navigationItemTitle : _ref$navigationItemTi,
48
+ _ref$onItemClick = _ref.onItemClick,
49
+ onItemClick = _ref$onItemClick === void 0 ? defaults.onItemClick : _ref$onItemClick,
50
+ _ref$onListClick = _ref.onListClick,
51
+ onListClick = _ref$onListClick === void 0 ? defaults.onListClick : _ref$onListClick,
52
+ _ref$tabIndex = _ref.tabIndex,
53
+ tabIndex = _ref$tabIndex === void 0 ? defaults.tabIndex : _ref$tabIndex,
54
+ _ref$title = _ref.title,
55
+ title = _ref$title === void 0 ? defaults.title : _ref$title;
56
+ var _useState = useState(isExpandedOnPageload),
57
+ _useState2 = _slicedToArray(_useState, 2),
58
+ open = _useState2[0],
59
+ setOpen = _useState2[1];
60
+ useEffect(function () {
61
+ var hrefs = React__default.Children.toArray(children).filter(function (_ref2) {
62
+ var childProps = _ref2.props;
63
+ return childProps.href && childProps.href.length > 0;
64
+ }).map(function (_ref3) {
65
+ var childProps = _ref3.props;
66
+ return childProps.href;
67
+ });
68
+ setOpen(hrefs.includes(activeHref) || isExpandedOnPageload);
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ }, []);
71
+
72
+ /**
73
+ * Closes the list.
74
+ */
75
+ var close = function close() {
76
+ if (open) {
77
+ setOpen(false);
78
+ }
79
+ };
80
+
81
+ /**
82
+ * Handles toggling the list.
83
+ * @param {SyntheticEvent} event The event fired when the list is toggled.
84
+ */
85
+ var toggle = function toggle(event) {
86
+ var which = event.which,
87
+ type = event.type;
88
+
89
+ // Enter (13) and spacebar (32).
90
+ if (which === 13 || which === 32 || type === 'click') {
91
+ if (!open) {
92
+ onListClick(id);
93
+ }
94
+ setOpen(!open);
95
+ }
96
+ };
97
+
98
+ // Expose external function calls to the parent component
99
+ useImperativeHandle(ref, function () {
100
+ return {
101
+ close: close,
102
+ isExpandedOnPageload: isExpandedOnPageload
103
+ };
104
+ });
105
+ var newChildren = React__default.Children.map(children, function (child, index) {
106
+ return /*#__PURE__*/React__default.createElement(NavItem, _extends({}, child.props, {
107
+ key: "".concat(blockClass$1, "--").concat(index),
108
+ onClick: function onClick(event, href) {
109
+ var _child$props$onClick, _child$props;
110
+ onItemClick(event, href);
111
+ (_child$props$onClick = (_child$props = child.props).onClick) === null || _child$props$onClick === void 0 || _child$props$onClick.call(_child$props, event);
112
+ },
113
+ activeHref: activeHref,
114
+ tabIndex: open ? 0 : -1
115
+ }));
116
+ });
117
+ return /*#__PURE__*/React__default.createElement("li", {
118
+ ref: ref,
119
+ className: cx(blockClass, className, _defineProperty({}, "".concat(blockClass$1, "--expanded"), open)),
120
+ tabIndex: tabIndex,
121
+ onClick: toggle,
122
+ onKeyDown: toggle,
123
+ role: "menuitem"
124
+ }, /*#__PURE__*/React__default.createElement("div", {
125
+ className: "".concat(blockClass$1, "__link")
126
+ }, icon && /*#__PURE__*/React__default.createElement("img", {
127
+ alt: navigationItemTitle,
128
+ className: "".concat(blockClass$1, "__img"),
129
+ src: icon
130
+ }), /*#__PURE__*/React__default.createElement("div", {
131
+ className: "".concat(blockClass$1, "__content")
132
+ }, title), /*#__PURE__*/React__default.createElement(ChevronDown, {
133
+ className: "".concat(blockClass, "__icon")
134
+ })), /*#__PURE__*/React__default.createElement("ul", {
135
+ "aria-label": title,
136
+ "aria-hidden": !open,
137
+ className: "".concat(blockClass, " ").concat(blockClass, "--nested"),
138
+ role: "menu"
139
+ }, newChildren));
140
+ });
141
+ NavList.propTypes = {
142
+ /** @type {string} Hypertext reference for active page. */
143
+ activeHref: propTypesExports.string,
144
+ /** @type {Node} Child elements. */
145
+ children: propTypesExports.node,
146
+ /** @type {string} Extra classes to add. */
147
+ className: propTypesExports.string,
148
+ /** @type {string} Icon of a list. */
149
+ icon: propTypesExports.string,
150
+ /** @type {string} ID of a list. */
151
+ id: propTypesExports.string,
152
+ /** @type {boolean} State of a list. */
153
+ isExpandedOnPageload: propTypesExports.bool,
154
+ /** @type {boolean} Title of nav. */
155
+ navigationItemTitle: propTypesExports.string,
156
+ /** @type {Function} Click handler for an item. */
157
+ onItemClick: propTypesExports.func,
158
+ /** @type {Function} Click handler for a list. */
159
+ onListClick: propTypesExports.func,
160
+ /** @type {number} `tabindex` of an item. */
161
+ tabIndex: propTypesExports.number,
162
+ /** @type {string} Label of the list. */
163
+ title: propTypesExports.string
164
+ };
165
+ NavList.displayName = componentName;
166
+ var NavList$1 = NavList;
167
+
168
+ export { NavList, blockClass, NavList$1 as default };
@@ -0,0 +1,3 @@
1
+ export { Nav } from "./Nav";
2
+ export { NavList } from "./NavList";
3
+ export { NavItem } from "./NavItem";
@@ -34,9 +34,13 @@ var maxDepth = 3;
34
34
  // happens when a tearsheet opens or closes. The 'open' array contains one
35
35
  // handler per OPEN tearsheet ordered from lowest to highest in visual z-order.
36
36
  // The 'all' array contains all the handlers for open and closed tearsheets.
37
+ // The 'sizes' array contains an array of the sizes for every stacked tearsheet.
38
+ // This is so we can opt-out of including the stacking scale effect when there
39
+ // are stacked tearsheets with mixed sizes (ie, using wide and narrow together)
37
40
  var stack = {
38
41
  open: [],
39
- all: []
42
+ all: [],
43
+ sizes: []
40
44
  };
41
45
 
42
46
  // these props are only applicable when size='wide'
@@ -147,6 +151,7 @@ var TearsheetShell = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
147
151
 
148
152
  // Register this tearsheet's stack change callback/listener.
149
153
  stack.all.push(handleStackChange);
154
+ stack.sizes.push(size);
150
155
 
151
156
  // If the tearsheet is mounting with open=true or open is changing from
152
157
  // false to true to open it then append its notification callback to
@@ -163,6 +168,7 @@ var TearsheetShell = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
163
168
  return function cleanup() {
164
169
  // Remove the notification callback from the all handlers array.
165
170
  stack.all.splice(stack.all.indexOf(handleStackChange), 1);
171
+ stack.sizes.splice(stack.sizes.indexOf(size), 1);
166
172
 
167
173
  // Remove the notification callback from the open handlers array, if
168
174
  // it's there, and notify all open tearsheets that the stacking has
@@ -173,7 +179,7 @@ var TearsheetShell = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
173
179
  notify();
174
180
  }
175
181
  };
176
- }, [open]);
182
+ }, [open, size]);
177
183
  function handleFocus() {
178
184
  // If something within us is receiving focus but we are not the topmost
179
185
  // stacked tearsheet, transfer focus to the topmost tearsheet instead
@@ -189,14 +195,23 @@ var TearsheetShell = /*#__PURE__*/React__default.forwardRef(function (_ref, ref)
189
195
 
190
196
  // Include an ActionSet if and only if one or more actions is given.
191
197
  var includeActions = actions && (actions === null || actions === void 0 ? void 0 : actions.length) > 0;
198
+ var areAllSameSizeVariant = function areAllSameSizeVariant() {
199
+ return new Set(stack.sizes).size === 1;
200
+ };
201
+ var setScaleValues = function setScaleValues() {
202
+ if (!areAllSameSizeVariant()) {
203
+ return _defineProperty(_defineProperty({}, "--".concat(bc, "--stacking-scale-factor-single"), 1), "--".concat(bc, "--stacking-scale-factor-double"), 1);
204
+ }
205
+ return _defineProperty(_defineProperty({}, "--".concat(bc, "--stacking-scale-factor-single"), (width - 32) / width), "--".concat(bc, "--stacking-scale-factor-double"), (width - 64) / width);
206
+ };
192
207
  return renderPortalUse( /*#__PURE__*/React__default.createElement(ComposedModal, _extends({}, rest, {
193
208
  "aria-label": ariaLabel || getNodeTextContent(title),
194
209
  className: cx(bc, className, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(bc, "--stacked-").concat(position, "-of-").concat(depth),
195
210
  // Don't apply this on the initial open of a single tearsheet.
196
211
  depth > 1 || depth === 1 && prevDepth.current > 1), "".concat(bc, "--wide"), wide), "".concat(bc, "--narrow"), !wide), "".concat(bc, "--has-slug"), slug), "".concat(bc, "--has-close"), effectiveHasCloseIcon)),
197
212
  slug: slug,
198
- style: _defineProperty(_defineProperty({}, "--".concat(bc, "--stacking-scale-factor-single"), (width - 32) / width), "--".concat(bc, "--stacking-scale-factor-double"), (width - 64) / width),
199
- containerClassName: cx("".concat(bc, "__container"), _defineProperty({}, "".concat(bc, "__container--lower"), verticalPosition === 'lower')),
213
+ style: setScaleValues(),
214
+ containerClassName: cx("".concat(bc, "__container"), _defineProperty(_defineProperty({}, "".concat(bc, "__container--lower"), verticalPosition === 'lower'), "".concat(bc, "__container--mixed-size-stacking"), !areAllSameSizeVariant())),
200
215
  onClose: onClose,
201
216
  open: open,
202
217
  selectorPrimaryFocus: selectorPrimaryFocus,
@@ -324,9 +339,9 @@ TearsheetShell.propTypes = _objectSpread2({
324
339
  * **Note:** This prop is only required if a close icon is shown, i.e. if
325
340
  * there are a no navigation actions and/or hasCloseIcon is true.
326
341
  */
327
- closeIconDescription: PropTypes.string.isRequired.if(function (_ref3) {
328
- var actions = _ref3.actions,
329
- hasCloseIcon = _ref3.hasCloseIcon;
342
+ closeIconDescription: PropTypes.string.isRequired.if(function (_ref4) {
343
+ var actions = _ref4.actions,
344
+ hasCloseIcon = _ref4.hasCloseIcon;
330
345
  return tearsheetHasCloseIcon(actions, hasCloseIcon);
331
346
  }),
332
347
  /**
@@ -44,6 +44,7 @@ export { Decorator } from "./Decorator";
44
44
  export { DescriptionList } from "./DescriptionList";
45
45
  export { FullPageError } from "./FullPageError";
46
46
  export { SearchBar } from "./SearchBar";
47
+ export { Nav } from "./Nav";
47
48
  export { StringFormatter } from "./StringFormatter";
48
49
  export { UserAvatar } from "./UserAvatar";
49
50
  export { StatusIndicator } from "./StatusIndicator";
@@ -75,6 +75,7 @@ declare namespace defaults {
75
75
  let EditTearsheetNarrow: boolean;
76
76
  let EditFullPage: boolean;
77
77
  let EditUpdateCards: boolean;
78
+ let Nav: boolean;
78
79
  let BigNumbers: boolean;
79
80
  let TruncatedList: boolean;
80
81
  let DelimitedList: boolean;
@@ -74,6 +74,7 @@ var defaults = {
74
74
  EditTearsheetNarrow: false,
75
75
  EditFullPage: false,
76
76
  EditUpdateCards: false,
77
+ Nav: false,
77
78
  BigNumbers: false,
78
79
  TruncatedList: false,
79
80
  DelimitedList: false,
package/es/index.js CHANGED
@@ -109,6 +109,7 @@ export { Decorator } from './components/Decorator/Decorator.js';
109
109
  export { DescriptionList } from './components/DescriptionList/DescriptionList.js';
110
110
  export { FullPageError } from './components/FullPageError/FullPageError.js';
111
111
  export { SearchBar } from './components/SearchBar/SearchBar.js';
112
+ export { Nav } from './components/Nav/Nav.js';
112
113
  export { StringFormatter } from './components/StringFormatter/StringFormatter.js';
113
114
  export { UserAvatar } from './components/UserAvatar/UserAvatar.js';
114
115
  export { StatusIndicator } from './components/StatusIndicator/StatusIndicator.js';
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020, 2024
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 { typeof as _typeof } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
9
+
10
+ function ownKeys(object, enumerableOnly) {
11
+ var keys = Object.keys(object);
12
+ if (Object.getOwnPropertySymbols) {
13
+ var symbols = Object.getOwnPropertySymbols(object);
14
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
15
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
16
+ })), keys.push.apply(keys, symbols);
17
+ }
18
+ return keys;
19
+ }
20
+ function _objectSpread2(target) {
21
+ for (var i = 1; i < arguments.length; i++) {
22
+ var source = null != arguments[i] ? arguments[i] : {};
23
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
24
+ _defineProperty(target, key, source[key]);
25
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
26
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
27
+ });
28
+ }
29
+ return target;
30
+ }
31
+ function _defineProperty(obj, key, value) {
32
+ key = _toPropertyKey(key);
33
+ if (key in obj) {
34
+ Object.defineProperty(obj, key, {
35
+ value: value,
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true
39
+ });
40
+ } else {
41
+ obj[key] = value;
42
+ }
43
+ return obj;
44
+ }
45
+ function _objectWithoutPropertiesLoose(source, excluded) {
46
+ if (source == null) return {};
47
+ var target = {};
48
+ var sourceKeys = Object.keys(source);
49
+ var key, i;
50
+ for (i = 0; i < sourceKeys.length; i++) {
51
+ key = sourceKeys[i];
52
+ if (excluded.indexOf(key) >= 0) continue;
53
+ target[key] = source[key];
54
+ }
55
+ return target;
56
+ }
57
+ function _objectWithoutProperties(source, excluded) {
58
+ if (source == null) return {};
59
+ var target = _objectWithoutPropertiesLoose(source, excluded);
60
+ var key, i;
61
+ if (Object.getOwnPropertySymbols) {
62
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
63
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
64
+ key = sourceSymbolKeys[i];
65
+ if (excluded.indexOf(key) >= 0) continue;
66
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
67
+ target[key] = source[key];
68
+ }
69
+ }
70
+ return target;
71
+ }
72
+ function _toPrimitive(input, hint) {
73
+ if (_typeof(input) !== "object" || input === null) return input;
74
+ var prim = input[Symbol.toPrimitive];
75
+ if (prim !== undefined) {
76
+ var res = prim.call(input, hint || "default");
77
+ if (_typeof(res) !== "object") return res;
78
+ throw new TypeError("@@toPrimitive must return a primitive value.");
79
+ }
80
+ return (hint === "string" ? String : Number)(input);
81
+ }
82
+ function _toPropertyKey(arg) {
83
+ var key = _toPrimitive(arg, "string");
84
+ return _typeof(key) === "symbol" ? key : String(key);
85
+ }
86
+ var _excluded = ["width", "height", "viewBox"],
87
+ _excluded2 = ["tabindex"];
88
+ /**
89
+ * Copyright IBM Corp. 2018, 2024
90
+ *
91
+ * This source code is licensed under the Apache-2.0 license found in the
92
+ * LICENSE file in the root directory of this source tree.
93
+ */
94
+
95
+ var defaultAttributes = {
96
+ // Reference:
97
+ // https://github.com/IBM/carbon-components-react/issues/1392
98
+ // https://github.com/PolymerElements/iron-iconset-svg/pull/47
99
+ // `focusable` is a string attribute which is why we do not use a boolean here
100
+ focusable: 'false',
101
+ preserveAspectRatio: 'xMidYMid meet'
102
+ };
103
+
104
+ /**
105
+ * Get supplementary HTML attributes for a given <svg> element based on existing
106
+ * attributes.
107
+ */
108
+ function getAttributes() {
109
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
110
+ width = _ref.width,
111
+ height = _ref.height,
112
+ _ref$viewBox = _ref.viewBox,
113
+ viewBox = _ref$viewBox === void 0 ? "0 0 ".concat(width, " ").concat(height) : _ref$viewBox,
114
+ attributes = _objectWithoutProperties(_ref, _excluded);
115
+ var tabindex = attributes.tabindex,
116
+ rest = _objectWithoutProperties(attributes, _excluded2);
117
+ var iconAttributes = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultAttributes), rest), {}, {
118
+ width: width,
119
+ height: height,
120
+ viewBox: viewBox
121
+ });
122
+
123
+ // TODO: attributes.title assumes that the consumer will implement <title> and
124
+ // correctly set `aria-labelledby`.
125
+ if (iconAttributes['aria-label'] || iconAttributes['aria-labelledby'] || iconAttributes.title) {
126
+ iconAttributes.role = 'img';
127
+
128
+ // Reference:
129
+ // https://allyjs.io/tutorials/focusing-in-svg.html
130
+ if (tabindex !== undefined && tabindex !== null) {
131
+ iconAttributes.focusable = 'true';
132
+ iconAttributes.tabindex = tabindex;
133
+ }
134
+ } else {
135
+ iconAttributes['aria-hidden'] = true;
136
+ }
137
+ return iconAttributes;
138
+ }
139
+
140
+ export { defaultAttributes, getAttributes };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020, 2024
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 { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import { getAttributes } from '../../icon-helpers/es/index.js';
10
+ import PropTypes from '../../../prop-types/index.js';
11
+ import React__default from 'react';
12
+
13
+ var _excluded = ["className", "children", "tabIndex", "xmlns", "preserveAspectRatio"],
14
+ _excluded2 = ["tabindex"];
15
+
16
+ /**
17
+ * Copyright IBM Corp. 2019, 2023
18
+ *
19
+ * This source code is licensed under the Apache-2.0 license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+ var Icon = /*#__PURE__*/React__default.forwardRef(function Icon(_ref, ref) {
23
+ var className = _ref.className,
24
+ children = _ref.children,
25
+ tabIndex = _ref.tabIndex,
26
+ _ref$xmlns = _ref.xmlns,
27
+ xmlns = _ref$xmlns === void 0 ? 'http://www.w3.org/2000/svg' : _ref$xmlns,
28
+ _ref$preserveAspectRa = _ref.preserveAspectRatio,
29
+ preserveAspectRatio = _ref$preserveAspectRa === void 0 ? 'xMidYMid meet' : _ref$preserveAspectRa,
30
+ rest = _objectWithoutProperties(_ref, _excluded);
31
+ var _getAttributes = getAttributes(_objectSpread2(_objectSpread2({}, rest), {}, {
32
+ tabindex: tabIndex
33
+ })),
34
+ tabindex = _getAttributes.tabindex,
35
+ attrs = _objectWithoutProperties(_getAttributes, _excluded2);
36
+ var props = attrs;
37
+ if (className) {
38
+ props.className = className;
39
+ }
40
+ if (tabindex !== undefined && tabindex !== null) {
41
+ if (typeof tabindex === 'number') {
42
+ props.tabIndex = tabindex;
43
+ } else {
44
+ props.tabIndex = Number(tabIndex);
45
+ }
46
+ }
47
+ if (ref) {
48
+ props.ref = ref;
49
+ }
50
+ if (xmlns) {
51
+ props.xmlns = xmlns;
52
+ }
53
+ if (preserveAspectRatio) {
54
+ props.preserveAspectRatio = preserveAspectRatio;
55
+ }
56
+ return /*#__PURE__*/React__default.createElement('svg', props, children);
57
+ });
58
+ Icon.displayName = 'Icon';
59
+ Icon.propTypes = {
60
+ 'aria-hidden': PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['true', 'false'])]),
61
+ 'aria-label': PropTypes.string,
62
+ 'aria-labelledby': PropTypes.string,
63
+ children: PropTypes.node,
64
+ className: PropTypes.string,
65
+ height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
66
+ preserveAspectRatio: PropTypes.string,
67
+ tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
68
+ viewBox: PropTypes.string,
69
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
70
+ xmlns: PropTypes.string
71
+ };
72
+
73
+ export { Icon as default };