@pingux/astro 2.57.0 → 2.58.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 (37) hide show
  1. package/lib/cjs/components/ListBox/ListBox.d.ts +1 -1
  2. package/lib/cjs/components/ListBox/ListBox.js +5 -5
  3. package/lib/cjs/components/MultivaluesField/MultivaluesField.js +6 -6
  4. package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +30 -0
  5. package/lib/cjs/components/Stepper/Stepper.mdx +20 -14
  6. package/lib/cjs/components/Stepper/Stepper.stories.js +115 -34
  7. package/lib/cjs/components/Stepper/Stepper.styles.js +2 -1
  8. package/lib/cjs/components/Tab/Tab.d.ts +10 -0
  9. package/lib/cjs/components/Tab/Tab.js +18 -58
  10. package/lib/cjs/components/Tab/index.d.ts +2 -0
  11. package/lib/cjs/components/Tabs/Tabs.d.ts +5 -0
  12. package/lib/cjs/components/Tabs/Tabs.js +17 -55
  13. package/lib/cjs/components/Tabs/Tabs.stories.d.ts +14 -0
  14. package/lib/cjs/components/Tabs/Tabs.style.d.ts +52 -0
  15. package/lib/cjs/components/Tabs/Tabs.test.d.ts +1 -0
  16. package/lib/cjs/components/Tabs/Tabs.test.js +38 -20
  17. package/lib/cjs/components/Tabs/index.d.ts +2 -0
  18. package/lib/cjs/types/index.d.ts +2 -0
  19. package/lib/cjs/types/index.js +26 -4
  20. package/lib/cjs/types/item.d.ts +7 -3
  21. package/lib/cjs/types/tab.d.ts +32 -0
  22. package/lib/cjs/types/tab.js +6 -0
  23. package/lib/cjs/types/tabs.d.ts +51 -0
  24. package/lib/cjs/types/tabs.js +6 -0
  25. package/lib/components/ListBox/ListBox.js +2 -2
  26. package/lib/components/MultivaluesField/MultivaluesField.js +6 -6
  27. package/lib/components/MultivaluesField/MultivaluesField.test.js +30 -0
  28. package/lib/components/Stepper/Stepper.mdx +20 -14
  29. package/lib/components/Stepper/Stepper.stories.js +115 -34
  30. package/lib/components/Stepper/Stepper.styles.js +2 -1
  31. package/lib/components/Tab/Tab.js +17 -58
  32. package/lib/components/Tabs/Tabs.js +19 -57
  33. package/lib/components/Tabs/Tabs.test.js +38 -20
  34. package/lib/types/index.js +2 -0
  35. package/lib/types/tab.js +1 -0
  36. package/lib/types/tabs.js +1 -0
  37. package/package.json +4 -2
@@ -1,13 +1,14 @@
1
- import { Meta } from '@storybook/addon-docs';
1
+ import { Meta } from "@storybook/addon-docs";
2
2
 
3
3
  <Meta title="Components/Stepper/Stepper" />
4
4
 
5
5
  # Stepper
6
6
 
7
- The Stepper component acts as a wrapper for individual step components.
7
+ The Stepper component acts as a wrapper for individual step components.
8
8
  It is used to display progress through a sequence of logical and numbered steps, usually within a configuration wizard.
9
9
 
10
10
  This component should be used:
11
+
11
12
  - To reveal or hide sections of content.
12
13
  - For progressive disclosure.
13
14
 
@@ -19,23 +20,28 @@ This component requires the Item originating from [react-stately/collections](ht
19
20
 
20
21
  ### Accessibility
21
22
 
22
- This component should adhere to the [WAI-ARIA Stepper](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/) accessibility guidelines.
23
+ This component should adhere to the [WAI-ARIA Stepper](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/) accessibility guidelines.
23
24
 
24
25
  #### Keyboard Navigation
25
26
 
26
- These keys provide additional functionality to the component.
27
+ These keys provide additional functionality to the component.
27
28
 
28
- | Keys | Function |
29
- | ---- | ---- |
30
- | Tab | The field is focusable using the Tab key and follows the page tab sequence. |
31
- | Arrow keys | When this field is focused, the arrow keys can be used to navigate through the steps. |
32
- | Shift + Tab | Moves focus to the previous focusable component. |
33
- | Home(Fn + Right Arrow Key) Or Control/Command + Home| Shifts the focus to the first step. |
34
- | End(Fn + Left Arrow Key) Or Control/Command + End | Shifts the focus to the last step. |
29
+ | Keys | Function |
30
+ | ---------------------------------------------------- | ------------------------------------------------------------------------------------- |
31
+ | Tab | The field is focusable using the Tab key and follows the page tab sequence. |
32
+ | Arrow keys | When this field is focused, the arrow keys can be used to navigate through the steps. |
33
+ | Shift + Tab | Moves focus to the previous focusable component. |
34
+ | Home(Fn + Right Arrow Key) Or Control/Command + Home | Shifts the focus to the first step. |
35
+ | End(Fn + Left Arrow Key) Or Control/Command + End | Shifts the focus to the last step. |
35
36
 
36
37
  #### Screen Readers
37
38
 
38
39
  This component uses the following attributes to assist screen readers:
39
- - The **`aria-orientation`** attribute indicates whether the orientation is horizontal, vertical, unknown, or ambiguous.
40
- - Each step uses the **`aria-selected`** attribute to indicate the selection status, and the **`aria-control`** attribute is supplied with the associated panel ID that displays the content.
41
- - Each step uses the **`aria-labelledby`** with the label ID to reference it.
40
+
41
+ - The **`aria-orientation`** attribute indicates whether the orientation is horizontal, vertical, unknown, or ambiguous.
42
+ - Each step uses the **`aria-selected`** attribute to indicate the selection status, and the **`aria-control`** attribute is supplied with the associated panel ID that displays the content.
43
+ - Each step uses the **`aria-labelledby`** with the label ID to reference it.
44
+
45
+ #### Usage
46
+
47
+ - The stepper component is always center-aligned in its context, whether it's in a page, a panel, or a popup.
@@ -1,9 +1,11 @@
1
1
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
- import React, { useState } from 'react';
2
+ import React, { useRef, useState } from 'react';
3
3
  import { Item } from 'react-stately';
4
+ import CreationOutlineIcon from '@pingux/mdi-react/CreationOutlineIcon';
4
5
  import { withDesign } from 'storybook-addon-designs';
5
6
  import DocsLayout from '../../../.storybook/storybookDocsLayout';
6
- import { Stepper, Text } from '../../index';
7
+ import { useOverlayPanelState } from '../../hooks';
8
+ import { Box, Button, OverlayPanel, OverlayProvider, PanelHeader, PanelHeaderCloseButton, Stepper, Text } from '../../index';
7
9
  import { FIGMA_LINKS } from '../../utils/designUtils/figmaLinks.ts';
8
10
  import StepperReadme from './Stepper.mdx';
9
11
  import { jsx as ___EmotionJSX } from "@emotion/react";
@@ -56,30 +58,69 @@ export default {
56
58
  }
57
59
  };
58
60
  var steps = [{
59
- label: 'Label 1',
60
- children: 'This is content for step 1',
61
+ label: 'Duis Aute',
62
+ children: 'Quis autem vel eum iure reprehenderit qui in ea voluptate',
63
+ title: 'Duis Aute',
61
64
  name: 'step1'
62
65
  }, {
63
- label: 'Label 2',
64
- children: 'This is content for step 2',
66
+ label: 'Lorem Ipsum',
67
+ children: 'Sed ut perspiciatis unde omnis',
68
+ title: 'Lorem Ipsum',
65
69
  name: 'step2'
66
70
  }, {
67
- label: 'Label 3',
68
- children: 'This is content for step 3',
71
+ label: 'Excepteur Sint',
72
+ children: 'Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam',
73
+ title: 'Excepteur Sint',
69
74
  name: 'step3'
70
75
  }];
76
+ var sx = {
77
+ overlayPanel: {
78
+ padding: '0px',
79
+ transition: 'width 500ms, right 500ms'
80
+ },
81
+ stepperContainer: {
82
+ padding: 'lg'
83
+ },
84
+ contentContainer: {
85
+ marginTop: 'lg',
86
+ gap: 'sm'
87
+ },
88
+ buttonStyle: {
89
+ margin: '50px 0px'
90
+ }
91
+ };
71
92
  export var Default = function Default(args) {
72
93
  return ___EmotionJSX(Stepper, args, ___EmotionJSX(Item, {
73
94
  key: "step1",
74
- textValue: "Step 1"
95
+ textValue: "Duis Aute"
96
+ }, ___EmotionJSX(Box, {
97
+ sx: sx.contentContainer
75
98
  }, ___EmotionJSX(Text, {
76
- pt: "lg"
77
- }, "This is content for step 1")), ___EmotionJSX(Item, {
99
+ fontSize: "md",
100
+ fontWeight: "3"
101
+ }, "Duis Aute"), ___EmotionJSX(Text, {
102
+ fontSize: "md"
103
+ }, "Quis autem vel eum iure reprehenderit qui in ea voluptate"))), ___EmotionJSX(Item, {
78
104
  key: "step2",
79
- textValue: "Step 2"
105
+ textValue: "Lorem Ipsum"
106
+ }, ___EmotionJSX(Box, {
107
+ sx: sx.contentContainer
80
108
  }, ___EmotionJSX(Text, {
81
- pt: "lg"
82
- }, "This is content for step 2")));
109
+ fontSize: "md",
110
+ fontWeight: "3"
111
+ }, "Lorem Ipsum"), ___EmotionJSX(Text, {
112
+ fontSize: "md"
113
+ }, "Sed ut perspiciatis unde omnis"))), ___EmotionJSX(Item, {
114
+ key: "step3",
115
+ textValue: "Excepteur Sint"
116
+ }, ___EmotionJSX(Box, {
117
+ sx: sx.contentContainer
118
+ }, ___EmotionJSX(Text, {
119
+ fontSize: "md",
120
+ fontWeight: "3"
121
+ }, "Excepteur Sint"), ___EmotionJSX(Text, {
122
+ fontSize: "md"
123
+ }, "Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam"))));
83
124
  };
84
125
  Default.parameters = {
85
126
  design: {
@@ -92,12 +133,6 @@ export var ControlledStepper = function ControlledStepper() {
92
133
  _useState2 = _slicedToArray(_useState, 2),
93
134
  activeStep = _useState2[0],
94
135
  setActiveStep = _useState2[1];
95
-
96
- // steps = [
97
- // { label: 'Label 1', children: 'This is content for step 1', name: 'step1' },
98
- // { label: 'Label 2', children: 'This is content for step 2', name: 'step2' },
99
- // { label: 'Label 3', children: 'This is content for step 3', name: 'step3' },
100
- // ];
101
136
  return ___EmotionJSX(Stepper, {
102
137
  items: steps,
103
138
  activeStep: activeStep,
@@ -105,21 +140,67 @@ export var ControlledStepper = function ControlledStepper() {
105
140
  }, function (item) {
106
141
  return ___EmotionJSX(Item, {
107
142
  key: item.name,
108
- textValue: item.name
143
+ textValue: item.title
144
+ }, ___EmotionJSX(Box, {
145
+ sx: sx.contentContainer
109
146
  }, ___EmotionJSX(Text, {
110
- pt: "lg"
111
- }, item.children));
147
+ fontSize: "md",
148
+ fontWeight: "3"
149
+ }, item.title), ___EmotionJSX(Text, {
150
+ fontSize: "md"
151
+ }, item.children)));
112
152
  });
113
153
  };
114
- export var WithoutContent = function WithoutContent() {
115
- return ___EmotionJSX(Stepper, null, ___EmotionJSX(Item, {
116
- key: "step1",
117
- textValue: "Step 1"
118
- }), ___EmotionJSX(Item, {
119
- key: "step2",
120
- textValue: "Step 2"
121
- }), ___EmotionJSX(Item, {
122
- key: "step3",
123
- textValue: "Step 3"
124
- }));
154
+ export var Panel = function Panel() {
155
+ var _useState3 = useState(1),
156
+ _useState4 = _slicedToArray(_useState3, 2),
157
+ activeStep = _useState4[0],
158
+ setActiveStep = _useState4[1];
159
+ var _useOverlayPanelState = useOverlayPanelState(),
160
+ state = _useOverlayPanelState.state,
161
+ onClose = _useOverlayPanelState.onClose;
162
+ var triggerRef = useRef < HTMLButtonElement > null;
163
+ var onCloseHandler = function onCloseHandler() {
164
+ return onClose(state, triggerRef);
165
+ };
166
+ return (
167
+ // Application must be wrapped in an OverlayProvider so that it can be hidden from screen
168
+ // readers when an overlay opens.
169
+ ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(Button, {
170
+ onPress: state.open,
171
+ "aria-expanded": state.isOpen,
172
+ sx: sx.buttonStyle
173
+ }, "Open Panel"), (state.isOpen || state.isTransitioning) && ___EmotionJSX(OverlayPanel, {
174
+ isTransitioning: state.isTransitioning,
175
+ isOpen: state.isOpen,
176
+ state: state,
177
+ triggerRef: triggerRef,
178
+ sx: sx.overlayPanel,
179
+ size: "full"
180
+ }, ___EmotionJSX(PanelHeader, {
181
+ data: {
182
+ icon: CreationOutlineIcon,
183
+ text: 'Sed Ut Perspiciatis'
184
+ }
185
+ }, ___EmotionJSX(PanelHeaderCloseButton, {
186
+ onPress: onCloseHandler
187
+ })), ___EmotionJSX(Stepper, {
188
+ items: steps,
189
+ activeStep: activeStep,
190
+ onStepChange: setActiveStep,
191
+ sx: sx.stepperContainer
192
+ }, function (item) {
193
+ return ___EmotionJSX(Item, {
194
+ key: item.name,
195
+ textValue: item.title
196
+ }, ___EmotionJSX(Box, {
197
+ sx: sx.contentContainer
198
+ }, ___EmotionJSX(Text, {
199
+ fontSize: "md",
200
+ fontWeight: "3"
201
+ }, item.title), ___EmotionJSX(Text, {
202
+ fontSize: "md"
203
+ }, item.children)));
204
+ })))
205
+ );
125
206
  };
@@ -18,7 +18,8 @@ var tabs = {
18
18
  outline: 'none',
19
19
  borderBottom: 'none',
20
20
  mb: 0,
21
- width: '100%'
21
+ width: '100%',
22
+ justifyContent: 'center'
22
23
  };
23
24
  var tab = {
24
25
  mb: 0,
@@ -1,13 +1,10 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
- import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["icon", "isDisabled", "separator", "tabLabelProps", "tabLineProps", "content", "titleAttr", "title"];
4
- import React, { forwardRef, useContext, useImperativeHandle, useRef } from 'react';
2
+ import React, { forwardRef, useContext } from 'react';
5
3
  import { mergeProps, useFocusRing, useTab } from 'react-aria';
6
4
  import { Item as Tab } from 'react-stately';
7
5
  import { Pressable, useHover } from '@react-aria/interactions';
8
- import PropTypes from 'prop-types';
9
6
  import { Box, Text, Tooltip, TooltipTrigger } from '../..';
10
- import { usePropWarning, useStatusClasses } from '../../hooks';
7
+ import { useLocalOrForwardRef, usePropWarning, useStatusClasses } from '../../hooks';
11
8
  import ORIENTATION from '../../utils/devUtils/constants/orientation';
12
9
  import { getPendoID } from '../../utils/devUtils/constants/pendoID';
13
10
  import TabPicker from '../TabPicker';
@@ -29,17 +26,8 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
29
26
  var key = item.key,
30
27
  rendered = item.rendered,
31
28
  itemProps = item.props;
32
- var icon = itemProps.icon,
33
- tabDisabled = itemProps.isDisabled,
34
- separator = itemProps.separator,
35
- tabLabelProps = itemProps.tabLabelProps,
36
- tabLineProps = itemProps.tabLineProps,
37
- content = itemProps.content,
38
- titleAttr = itemProps.titleAttr,
39
- title = itemProps.title,
40
- otherItemProps = _objectWithoutProperties(itemProps, _excluded);
41
29
  var state = useContext(TabsContext);
42
- var isDisabled = tabsDisabled || tabDisabled || state.disabledKeys.has(key);
30
+ var isDisabled = tabsDisabled || (itemProps === null || itemProps === void 0 ? void 0 : itemProps.isDisabled) || state.disabledKeys.has(key);
43
31
  var isSelected = state.selectedKey === key;
44
32
  var _useFocusRing = useFocusRing(),
45
33
  isFocusVisible = _useFocusRing.isFocusVisible,
@@ -56,12 +44,8 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
56
44
  isSelected: isSelected
57
45
  }),
58
46
  classNames = _useStatusClasses.classNames;
59
- var tabRef = useRef();
60
47
  usePropWarning(props, 'disabled', 'isDisabled');
61
- /* istanbul ignore next */
62
- useImperativeHandle(ref, function () {
63
- return tabRef.current;
64
- });
48
+ var tabRef = useLocalOrForwardRef(ref);
65
49
  var _useTab = useTab({
66
50
  key: key,
67
51
  isDisabled: isDisabled
@@ -72,57 +56,32 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
72
56
  }, slots === null || slots === void 0 ? void 0 : slots.beforeTab, ___EmotionJSX(Box, _extends({
73
57
  className: classNames,
74
58
  variant: "tab"
75
- }, mergeProps(focusProps, hoverProps, tabProps), getPendoID('Tab'), otherItemProps, {
76
- ref: tabRef,
77
- title: titleAttr || undefined
78
- }), icon, ___EmotionJSX(Text, _extends({
59
+ // title={itemProps?.titleAttr || undefined}
60
+ }, mergeProps(focusProps, hoverProps, tabProps), getPendoID('Tab'), {
61
+ // {...otherItemProps}
62
+ ref: tabRef
63
+ }, itemProps, {
64
+ role: "tab"
65
+ }), ___EmotionJSX(React.Fragment, null, itemProps === null || itemProps === void 0 ? void 0 : itemProps.icon, ___EmotionJSX(Text, _extends({
79
66
  variant: "tabLabel"
80
- }, tabLabelProps), rendered), isSelected && !isDisabled && ___EmotionJSX(TabLine, tabLineProps)), slots === null || slots === void 0 ? void 0 : slots.afterTab);
81
- if (mode === 'list' && itemProps.list) {
67
+ }, itemProps === null || itemProps === void 0 ? void 0 : itemProps.tabLabelProps), rendered), isSelected && !isDisabled && ___EmotionJSX(TabLine, itemProps === null || itemProps === void 0 ? void 0 : itemProps.tabLineProps))), slots === null || slots === void 0 ? void 0 : slots.afterTab);
68
+ if (mode === 'list' && itemProps !== null && itemProps !== void 0 && itemProps.list) {
82
69
  return ___EmotionJSX(TabPicker, _extends({
83
70
  ref: tabRef,
84
71
  className: classNames,
85
- items: itemProps.list,
72
+ items: itemProps === null || itemProps === void 0 ? void 0 : itemProps.list,
86
73
  state: state,
87
74
  item: item
88
- }, mergeProps(focusProps, hoverProps, tabProps), otherItemProps));
75
+ }, mergeProps(focusProps, hoverProps, tabProps), itemProps));
89
76
  }
90
77
  if (mode === 'tooltip') {
91
- return ___EmotionJSX(React.Fragment, null, separator, ___EmotionJSX(TooltipTrigger, _extends({}, tooltipTriggerProps, {
78
+ return ___EmotionJSX(React.Fragment, null, itemProps === null || itemProps === void 0 ? void 0 : itemProps.separator, ___EmotionJSX(TooltipTrigger, _extends({}, tooltipTriggerProps, {
92
79
  isOpen: isHovered || isFocusVisible
93
- }), ___EmotionJSX(Pressable, null, ___EmotionJSX("span", {
94
- variant: "quiet"
95
- }, tab)), ___EmotionJSX(Tooltip, null, itemProps.textValue || itemProps.title)));
80
+ }), ___EmotionJSX(Pressable, null, ___EmotionJSX("span", null, tab)), ___EmotionJSX(Tooltip, null, (itemProps === null || itemProps === void 0 ? void 0 : itemProps.textValue) || (itemProps === null || itemProps === void 0 ? void 0 : itemProps.title))));
96
81
  }
97
82
  return tab;
98
83
  });
99
84
  CollectionTab.displayName = 'CollectionTab';
100
- CollectionTab.propTypes = {
101
- isDisabled: PropTypes.bool,
102
- item: PropTypes.shape({
103
- key: PropTypes.string,
104
- props: PropTypes.shape({
105
- icon: PropTypes.shape({}),
106
- isDisabled: PropTypes.bool,
107
- textValue: PropTypes.string,
108
- tabLineProps: PropTypes.shape({}),
109
- tabLabelProps: PropTypes.shape({}),
110
- content: PropTypes.shape({}),
111
- titleAttr: PropTypes.string,
112
- title: PropTypes.oneOfType([PropTypes.element, PropTypes.string, PropTypes.object]),
113
- separator: PropTypes.oneOfType([PropTypes.element, PropTypes.bool]),
114
- list: PropTypes.arrayOf(PropTypes.shape({}))
115
- }),
116
- rendered: PropTypes.node
117
- }),
118
- mode: PropTypes.oneOf(['default', 'tooltip', 'list']),
119
- orientation: PropTypes.oneOf(['horizontal', 'vertical']),
120
- tooltipTriggerProps: PropTypes.shape({}),
121
- slots: PropTypes.shape({
122
- beforeTab: PropTypes.node,
123
- afterTab: PropTypes.node
124
- })
125
- };
126
85
  export var TabLine = function TabLine(props) {
127
86
  return ___EmotionJSX(Box, _extends({
128
87
  role: "presentation",
@@ -8,7 +8,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
8
8
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
9
9
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
10
10
  var _excluded = ["state"],
11
- _excluded2 = ["children", "isDisabled", "items", "onSelectionChange", "orientation", "mode", "tabListProps", "tabPanelProps"];
11
+ _excluded2 = ["isDisabled", "items", "onSelectionChange", "orientation", "mode", "tabListProps", "tabPanelProps"];
12
12
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
14
14
  import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
@@ -16,11 +16,10 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
16
16
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
17
17
  import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
18
18
  import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
19
- import React, { forwardRef, useImperativeHandle, useRef } from 'react';
19
+ import React, { forwardRef } from 'react';
20
20
  import { useTabList, useTabPanel } from 'react-aria';
21
21
  import { useTabListState } from 'react-stately';
22
- import PropTypes from 'prop-types';
23
- import { usePropWarning } from '../../hooks';
22
+ import { useLocalOrForwardRef, usePropWarning } from '../../hooks';
24
23
  import ORIENTATION from '../../utils/devUtils/constants/orientation';
25
24
  import Box from '../Box';
26
25
  import { CollectionTab } from '../Tab';
@@ -29,23 +28,19 @@ export var TabsContext = /*#__PURE__*/React.createContext({});
29
28
  var TabPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
30
29
  var state = _ref.state,
31
30
  props = _objectWithoutProperties(_ref, _excluded);
32
- var tabPanelRef = useRef();
33
31
  var children = props.children,
34
32
  tabPanelProps = props.tabPanelProps;
35
- /* istanbul ignore next */
36
- useImperativeHandle(ref, function () {
37
- return tabPanelRef.current;
38
- });
39
- var _useTabPanel = useTabPanel(props, state, tabPanelRef),
40
- raTabPanelProps = _useTabPanel.tabPanelProps;
33
+ var tabPanelRef = useLocalOrForwardRef(ref);
34
+ var _ref2 = useTabPanel(props, state, tabPanelRef),
35
+ raTabPanelProps = _ref2.tabPanelProps;
41
36
  return ___EmotionJSX(Box, _extends({}, tabPanelProps, raTabPanelProps, {
42
- ref: tabPanelRef
37
+ ref: tabPanelRef,
38
+ role: "tabpanel"
43
39
  }), children);
44
40
  });
45
41
  var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
46
42
  var _context4, _context5, _state$selectedItem, _state$selectedItem2, _state$selectedItem3;
47
- var children = props.children,
48
- isDisabled = props.isDisabled,
43
+ var isDisabled = props.isDisabled,
49
44
  items = props.items,
50
45
  onSelectionChange = props.onSelectionChange,
51
46
  orientation = props.orientation,
@@ -53,14 +48,10 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
53
48
  tabListProps = props.tabListProps,
54
49
  tabPanelProps = props.tabPanelProps,
55
50
  others = _objectWithoutProperties(props, _excluded2);
56
- var tabListRef = useRef();
57
51
  usePropWarning(props, 'disabled', 'isDisabled');
58
- /* istanbul ignore next */
59
- useImperativeHandle(ref, function () {
60
- return tabListRef.current;
61
- });
52
+ var tabListRef = useLocalOrForwardRef(ref);
62
53
  var allItems = [];
63
- if (mode === 'list') {
54
+ if (mode === 'list' && items) {
64
55
  _forEachInstanceProperty(items).call(items, function (item) {
65
56
  var _context;
66
57
  allItems = _concatInstanceProperty(_context = []).call(_context, allItems, [item]);
@@ -80,7 +71,8 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
80
71
  items: mode === 'list' ? allItems : items
81
72
  }));
82
73
  var _useTabList = useTabList(props, state, tabListRef),
83
- raTabListProps = _useTabList.tabListProps;
74
+ raTabListProps = _useTabList.tabListProps; //= useTabList(props, state, tabListRef);
75
+
84
76
  return ___EmotionJSX(TabsContext.Provider, {
85
77
  value: state
86
78
  }, ___EmotionJSX(Box, others, ___EmotionJSX(Box, _extends({
@@ -88,19 +80,20 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
88
80
  gap: "25px",
89
81
  isRow: orientation === ORIENTATION.HORIZONTAL
90
82
  }, tabListProps, raTabListProps, {
91
- ref: tabListRef
83
+ ref: tabListRef,
84
+ role: "tablist"
92
85
  }), _mapInstanceProperty(_context4 = _filterInstanceProperty(_context5 = _Array$from(state.collection)).call(_context5, function (item) {
93
- var _item$value;
94
- return !(item !== null && item !== void 0 && (_item$value = item.value) !== null && _item$value !== void 0 && _item$value.isListItem);
95
- })).call(_context4, function (item) {
96
86
  var _item$props;
87
+ return !(item !== null && item !== void 0 && (_item$props = item.props) !== null && _item$props !== void 0 && _item$props.isListItem);
88
+ })).call(_context4, function (item) {
89
+ var _item$props2;
97
90
  return ___EmotionJSX(CollectionTab, {
98
91
  key: item.key,
99
92
  item: item,
100
93
  isDisabled: isDisabled,
101
94
  orientation: orientation,
102
95
  mode: mode,
103
- slots: item === null || item === void 0 || (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.slots
96
+ slots: item === null || item === void 0 || (_item$props2 = item.props) === null || _item$props2 === void 0 ? void 0 : _item$props2.slots
104
97
  });
105
98
  })), ___EmotionJSX(TabPanel, {
106
99
  key: (_state$selectedItem = state.selectedItem) === null || _state$selectedItem === void 0 ? void 0 : _state$selectedItem.key,
@@ -108,42 +101,11 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
108
101
  tabPanelProps: tabPanelProps
109
102
  }, ((_state$selectedItem2 = state.selectedItem) === null || _state$selectedItem2 === void 0 ? void 0 : _state$selectedItem2.props.children) || ((_state$selectedItem3 = state.selectedItem) === null || _state$selectedItem3 === void 0 ? void 0 : _state$selectedItem3.props.content))));
110
103
  });
111
- Tabs.propTypes = {
112
- /** The default tab key to be selected. (uncontrolled) */
113
- defaultSelectedKey: PropTypes.string,
114
- /** Array of keys to disable within the tab list. */
115
- disabledKeys: PropTypes.arrayOf(PropTypes.string),
116
- /** The tab key that is currently selected. (controlled) */
117
- selectedKey: PropTypes.string,
118
- /** Determines the arrangement of the tablist. */
119
- orientation: PropTypes.oneOf(['horizontal', 'vertical']),
120
- /** Determines the behavior model for the tabs. */
121
- mode: PropTypes.oneOf(['default', 'tooltip', 'list']),
122
- /**
123
- * *For performance reasons, use this prop instead of Array.map when iteratively rendering Items*.
124
- * For use with [dynamic collections](https://react-spectrum.adobe.com/react-stately/collections.html#dynamic-collections).
125
- */
126
- items: PropTypes.arrayOf(PropTypes.shape({})),
127
- /** Whether the entire tablist is disabled. */
128
- isDisabled: PropTypes.bool,
129
- /** Handler that is called when the selected tab has changed. */
130
- onSelectionChange: PropTypes.func,
131
- /** A props object that is subsequently spread into the rendered tablist. */
132
- tabListProps: PropTypes.shape({}),
133
- /** Props object that is spread directly into all of the tab panel wrapper elements. */
134
- tabPanelProps: PropTypes.shape({}),
135
- /** Whether tabs are activated automatically on focus or manually¸ */
136
- keyboardActivation: PropTypes.oneOf(['automatic', 'manual'])
137
- };
138
104
  Tabs.defaultProps = {
139
105
  isDisabled: false,
140
106
  orientation: 'horizontal',
141
107
  mode: 'default',
142
108
  keyboardActivation: 'manual'
143
109
  };
144
- TabPanel.propTypes = {
145
- state: PropTypes.shape({}),
146
- tabPanelProps: PropTypes.shape({})
147
- };
148
110
  Tabs.displayName = 'Tabs';
149
111
  export default Tabs;
@@ -37,17 +37,21 @@ emotionCache.compat = true;
37
37
  var testId = 'testId';
38
38
  var defaultTabs = [{
39
39
  name: 'Tab 1',
40
- children: 'Tab 1 body'
40
+ children: 'Tab 1 body',
41
+ props: {}
41
42
  }, {
42
43
  name: 'Tab 2',
43
- children: 'Tab 2 body'
44
+ children: 'Tab 2 body',
45
+ props: {}
44
46
  }, {
45
47
  name: 'Tab 3',
46
- children: 'Tab 3 body'
48
+ children: 'Tab 3 body',
49
+ props: {}
47
50
  }];
48
51
  var tabsWithList = [{
49
52
  name: 'Tab 1',
50
- children: 'Tab 1 body'
53
+ children: 'Tab 1 body',
54
+ props: {}
51
55
  }, {
52
56
  name: 'Tab 2',
53
57
  list: [{
@@ -60,7 +64,8 @@ var tabsWithList = [{
60
64
  name: 'Tab 2 list',
61
65
  children: 'Tab 2 from list',
62
66
  role: 'menuitemradio'
63
- }]
67
+ }],
68
+ props: {}
64
69
  }];
65
70
  var defaultProps = {
66
71
  'data-testid': testId,
@@ -77,8 +82,8 @@ var getComponent = function getComponent() {
77
82
  value: emotionCache
78
83
  }, ___EmotionJSX(Tabs, _extends({}, defaultProps, props), _mapInstanceProperty(tabs).call(tabs, function (_ref2) {
79
84
  var name = _ref2.name,
80
- tabProps = _ref2.props,
81
- children = _ref2.children;
85
+ children = _ref2.children,
86
+ tabProps = _ref2.props;
82
87
  return ___EmotionJSX(Tab, _extends({
83
88
  key: name,
84
89
  title: name
@@ -114,7 +119,10 @@ var getTabs = function getTabs() {
114
119
  var testTabPanel = function testTabPanel(expectedTabIndex) {
115
120
  return _forEachInstanceProperty(defaultTabs).call(defaultTabs, function (_ref4, index) {
116
121
  var children = _ref4.children;
117
- return index === expectedTabIndex ? expect(screen.queryByText(children)).toBeInTheDocument() : expect(screen.queryByText(children)).not.toBeInTheDocument();
122
+ if (typeof children === 'string') {
123
+ return index === expectedTabIndex ? expect(screen.queryByText(children)).toBeInTheDocument() : expect(screen.queryByText(children)).not.toBeInTheDocument();
124
+ }
125
+ return null;
118
126
  });
119
127
  };
120
128
  var testSingleTab = function testSingleTab(tabs, tab, thisTest) {
@@ -264,9 +272,11 @@ test('disabled all tabs', function () {
264
272
 
265
273
  // Tabs cannot be DOM disabled so must check visuals
266
274
  _forEachInstanceProperty(defaultTabs).call(defaultTabs, function (tab) {
267
- var tabText = screen.getByText(tab.name);
268
- var parentElement = tabText.parentElement;
269
- expect(parentElement).toHaveClass('is-disabled');
275
+ if (tab.name) {
276
+ var tabText = screen.getByText(tab.name);
277
+ var parentElement = tabText.parentElement;
278
+ expect(parentElement).toHaveClass('is-disabled');
279
+ }
270
280
  });
271
281
  expect(tabLine).not.toBeInTheDocument();
272
282
 
@@ -413,7 +423,7 @@ test('tabs without selected keys show null tab panel content', function () {
413
423
  getComponent({
414
424
  defaultSelectedKey: undefined
415
425
  });
416
- expect(screen.queryByRole('tabpanel')).not.toHaveTextContent();
426
+ expect(screen.queryByRole('tabpanel')).not.toHaveTextContent('');
417
427
  });
418
428
  test('hover tab style', function () {
419
429
  getComponent();
@@ -468,17 +478,21 @@ test('will render tab with list if provided', /*#__PURE__*/_asyncToGenerator( /*
468
478
  });
469
479
  testTabPanel(0);
470
480
  _getTabs12 = getTabs(), menuBtn = _getTabs12.tab1.parentElement;
471
- userEvent.click(menuBtn);
481
+ if (menuBtn) userEvent.click(menuBtn);
472
482
  expect(screen.queryByRole('menu')).toBeInTheDocument();
473
483
  testTabPanel(0);
474
484
  menuItems = screen.queryAllByRole('menuitemradio');
475
- expect(menuItems).toHaveLength(tabsWithList[1].list.length);
485
+ if (tabsWithList[1].list) {
486
+ expect(menuItems).toHaveLength(tabsWithList[1].list.length);
487
+ }
476
488
  expect(menuItems[0]).not.toHaveFocus();
477
489
  userEvent.click(menuItems[0]);
478
- firstListItemContent = tabsWithList[1].list[0].children;
479
- expect(screen.queryByRole('tabpanel')).toHaveTextContent(firstListItemContent);
490
+ if (tabsWithList[1].list) {
491
+ firstListItemContent = tabsWithList[1].list[0].children;
492
+ expect(screen.queryByRole('tabpanel')).toHaveTextContent(firstListItemContent);
493
+ }
480
494
  expect(screen.queryByRole('menu')).not.toBeInTheDocument();
481
- case 13:
495
+ case 12:
482
496
  case "end":
483
497
  return _context2.stop();
484
498
  }
@@ -510,13 +524,17 @@ test('tab list is accessible via keyboard', function () {
510
524
  expect(screen.queryByRole('menu')).toBeInTheDocument();
511
525
  testTabPanel(0);
512
526
  var menuItems = screen.queryAllByRole('menuitemradio');
513
- expect(menuItems).toHaveLength(tabsWithList[1].list.length);
527
+ if (tabsWithList[1].list) {
528
+ expect(menuItems).toHaveLength(tabsWithList[1].list.length);
529
+ }
514
530
  expect(menuItems[0]).toHaveFocus();
515
531
  fireEvent.keyDown(menuItems[0], {
516
532
  key: 'Enter',
517
533
  code: 'Enter'
518
534
  });
519
- var firstListItemContent = tabsWithList[1].list[0].children;
520
- expect(screen.queryByRole('tabpanel')).toHaveTextContent(firstListItemContent);
535
+ if (tabsWithList[1].list) {
536
+ var firstListItemContent = tabsWithList[1].list[0].children;
537
+ expect(screen.queryByRole('tabpanel')).toHaveTextContent(firstListItemContent);
538
+ }
521
539
  expect(screen.queryByRole('menu')).not.toBeInTheDocument();
522
540
  });