@pingux/astro 2.84.0-alpha.1 → 2.84.0-alpha.10

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 (115) hide show
  1. package/lib/cjs/components/Avatar/Avatar.js +43 -8
  2. package/lib/cjs/components/Avatar/Avatar.test.js +10 -1
  3. package/lib/cjs/components/CheckboxField/CheckboxField.stories.js +5 -3
  4. package/lib/cjs/components/CodeView/CodeView.js +5 -2
  5. package/lib/cjs/components/CodeView/CodeView.styles.d.ts +2 -1
  6. package/lib/cjs/components/CodeView/CodeView.styles.js +4 -3
  7. package/lib/cjs/components/Link/Link.js +3 -1
  8. package/lib/cjs/components/LinkSelectField/LinkSelectField.stories.js +3 -6
  9. package/lib/cjs/components/ListBox/ListBox.styles.js +6 -3
  10. package/lib/cjs/components/Menu/Menu.js +15 -3
  11. package/lib/cjs/components/Menu/Menu.test.js +23 -0
  12. package/lib/cjs/components/MenuItem/MenuItem.styles.d.ts +1 -0
  13. package/lib/cjs/components/MenuItem/MenuItem.styles.js +2 -1
  14. package/lib/cjs/components/MenuSection/MenuSection.d.ts +9 -0
  15. package/lib/cjs/components/MenuSection/MenuSection.js +76 -0
  16. package/lib/cjs/components/MenuSection/MenuSection.styles.d.ts +21 -0
  17. package/lib/cjs/components/MenuSection/MenuSection.styles.js +35 -0
  18. package/lib/cjs/components/MenuSection/MenuSection.test.d.ts +1 -0
  19. package/lib/cjs/components/MenuSection/MenuSection.test.js +100 -0
  20. package/lib/cjs/components/MenuSection/index.d.ts +1 -0
  21. package/lib/cjs/components/MenuSection/index.js +14 -0
  22. package/lib/cjs/components/PopoverMenu/PopoverMenu.stories.d.ts +2 -0
  23. package/lib/cjs/components/PopoverMenu/PopoverMenu.stories.js +73 -5
  24. package/lib/cjs/components/SelectField/SelectField.stories.js +3 -6
  25. package/lib/cjs/components/SwitchField/SwitchField.d.ts +4 -0
  26. package/lib/cjs/components/SwitchField/SwitchField.js +12 -32
  27. package/lib/cjs/components/SwitchField/SwitchField.stories.d.ts +11 -0
  28. package/lib/cjs/components/SwitchField/SwitchField.stories.js +4 -2
  29. package/lib/cjs/components/SwitchField/SwitchField.test.d.ts +1 -0
  30. package/lib/cjs/components/SwitchField/index.d.ts +1 -0
  31. package/lib/cjs/components/SwitchField/switchFieldAttributes.d.ts +94 -0
  32. package/lib/cjs/components/SwitchField/switchFieldAttributes.js +2 -30
  33. package/lib/cjs/components/Tabs/Tabs.js +0 -1
  34. package/lib/cjs/components/Tabs/Tabs.style.d.ts +1 -0
  35. package/lib/cjs/components/Tabs/Tabs.style.js +2 -1
  36. package/lib/cjs/components/TimeField/TimeField.stories.js +2 -2
  37. package/lib/cjs/styles/theme.js +5 -1
  38. package/lib/cjs/styles/themes/next-gen/codeView/codeView.d.ts +105 -0
  39. package/lib/cjs/styles/themes/next-gen/codeView/codeView.js +134 -0
  40. package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +1 -1
  41. package/lib/cjs/styles/themes/next-gen/next-gen.d.ts +344 -36
  42. package/lib/cjs/styles/themes/next-gen/next-gen.js +24 -4
  43. package/lib/cjs/styles/themes/next-gen/sizes.d.ts +18 -0
  44. package/lib/cjs/styles/themes/next-gen/sizes.js +27 -0
  45. package/lib/cjs/styles/themes/next-gen/spacing.d.ts +9 -0
  46. package/lib/cjs/styles/themes/next-gen/spacing.js +17 -0
  47. package/lib/cjs/styles/themes/next-gen/text.d.ts +8 -2
  48. package/lib/cjs/styles/themes/next-gen/text.js +16 -13
  49. package/lib/cjs/styles/themes/next-gen/variants/button.d.ts +36 -3
  50. package/lib/cjs/styles/themes/next-gen/variants/button.js +25 -5
  51. package/lib/cjs/styles/themes/next-gen/variants/cards.d.ts +20 -0
  52. package/lib/cjs/styles/themes/next-gen/variants/cards.js +28 -0
  53. package/lib/cjs/styles/themes/next-gen/variants/images.d.ts +4 -0
  54. package/lib/cjs/styles/themes/next-gen/variants/images.js +12 -0
  55. package/lib/cjs/styles/themes/next-gen/variants/links.d.ts +56 -0
  56. package/lib/cjs/styles/themes/next-gen/variants/links.js +62 -0
  57. package/lib/cjs/styles/themes/next-gen/variants/text.d.ts +7 -0
  58. package/lib/cjs/styles/themes/next-gen/variants/text.js +9 -2
  59. package/lib/cjs/styles/themes/next-gen/variants/variants.d.ts +82 -31
  60. package/lib/cjs/styles/themes/next-gen/variants/variants.js +91 -30
  61. package/lib/cjs/styles/variants/variants.js +2 -0
  62. package/lib/cjs/types/avatar.d.ts +5 -1
  63. package/lib/cjs/types/checkboxField.d.ts +3 -1
  64. package/lib/cjs/types/codeView.d.ts +1 -0
  65. package/lib/cjs/types/index.d.ts +2 -0
  66. package/lib/cjs/types/index.js +43 -21
  67. package/lib/cjs/types/link.d.ts +1 -0
  68. package/lib/cjs/types/menuSection.d.ts +24 -0
  69. package/lib/cjs/types/menuSection.js +6 -0
  70. package/lib/cjs/types/switchField.d.ts +29 -0
  71. package/lib/cjs/types/switchField.js +6 -0
  72. package/lib/components/Avatar/Avatar.js +44 -7
  73. package/lib/components/Avatar/Avatar.test.js +10 -1
  74. package/lib/components/CheckboxField/CheckboxField.stories.js +5 -3
  75. package/lib/components/CodeView/CodeView.js +5 -2
  76. package/lib/components/CodeView/CodeView.styles.js +4 -3
  77. package/lib/components/Link/Link.js +3 -1
  78. package/lib/components/LinkSelectField/LinkSelectField.stories.js +4 -7
  79. package/lib/components/ListBox/ListBox.styles.js +6 -3
  80. package/lib/components/Menu/Menu.js +15 -3
  81. package/lib/components/Menu/Menu.test.js +24 -1
  82. package/lib/components/MenuItem/MenuItem.styles.js +2 -1
  83. package/lib/components/MenuSection/MenuSection.js +64 -0
  84. package/lib/components/MenuSection/MenuSection.styles.js +27 -0
  85. package/lib/components/MenuSection/MenuSection.test.js +97 -0
  86. package/lib/components/MenuSection/index.js +1 -0
  87. package/lib/components/PopoverMenu/PopoverMenu.stories.js +70 -4
  88. package/lib/components/SelectField/SelectField.stories.js +4 -7
  89. package/lib/components/SwitchField/SwitchField.js +14 -34
  90. package/lib/components/SwitchField/SwitchField.stories.js +4 -2
  91. package/lib/components/SwitchField/switchFieldAttributes.js +1 -28
  92. package/lib/components/Tabs/Tabs.js +0 -1
  93. package/lib/components/Tabs/Tabs.style.js +2 -1
  94. package/lib/components/TimeField/TimeField.stories.js +2 -2
  95. package/lib/styles/theme.js +5 -1
  96. package/lib/styles/themes/next-gen/codeView/codeView.js +126 -0
  97. package/lib/styles/themes/next-gen/convertedComponentList.js +1 -1
  98. package/lib/styles/themes/next-gen/next-gen.js +24 -4
  99. package/lib/styles/themes/next-gen/sizes.js +19 -0
  100. package/lib/styles/themes/next-gen/spacing.js +9 -0
  101. package/lib/styles/themes/next-gen/text.js +16 -13
  102. package/lib/styles/themes/next-gen/variants/button.js +25 -5
  103. package/lib/styles/themes/next-gen/variants/cards.js +20 -0
  104. package/lib/styles/themes/next-gen/variants/images.js +4 -0
  105. package/lib/styles/themes/next-gen/variants/links.js +54 -0
  106. package/lib/styles/themes/next-gen/variants/text.js +9 -2
  107. package/lib/styles/themes/next-gen/variants/variants.js +91 -30
  108. package/lib/styles/variants/variants.js +2 -0
  109. package/lib/types/index.js +2 -0
  110. package/lib/types/menuSection.js +1 -0
  111. package/lib/types/switchField.js +1 -0
  112. package/package.json +1 -1
  113. package/lib/cjs/recipes/NextGen/DefaultAvatar.stories.d.ts +0 -6
  114. package/lib/cjs/recipes/NextGen/DefaultAvatar.stories.js +0 -41
  115. package/lib/recipes/NextGen/DefaultAvatar.stories.js +0 -31
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
@@ -1,14 +1,51 @@
1
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
2
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
4
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
6
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
8
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
1
9
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
10
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
11
+ import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
12
+ var _excluded = ["alt", "defaultText", "color", "className", "size", "src", "sx"];
13
+ 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; }
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
2
15
  import React, { forwardRef } from 'react';
3
- import { Avatar as ThemeUIAvatar } from 'theme-ui';
16
+ import { Avatar as ThemeUIAvatar, Box } from 'theme-ui';
17
+ import { useStatusClasses } from '../../hooks';
4
18
  import { jsx as ___EmotionJSX } from "@emotion/react";
5
19
  var Avatar = /*#__PURE__*/forwardRef(function (props, ref) {
6
- return ___EmotionJSX(ThemeUIAvatar, _extends({
7
- ref: ref
8
- }, props));
20
+ var _props$alt = props.alt,
21
+ alt = _props$alt === void 0 ? 'Avatar' : _props$alt,
22
+ defaultText = props.defaultText,
23
+ color = props.color,
24
+ className = props.className,
25
+ size = props.size,
26
+ src = props.src,
27
+ sx = props.sx,
28
+ others = _objectWithoutProperties(props, _excluded);
29
+ var _useStatusClasses = useStatusClasses(className, _defineProperty({}, "is-".concat(color), true)),
30
+ classNames = _useStatusClasses.classNames;
31
+ if (src) {
32
+ return ___EmotionJSX(ThemeUIAvatar, _extends({
33
+ ref: ref,
34
+ alt: alt,
35
+ src: src,
36
+ sx: _objectSpread({
37
+ size: size
38
+ }, sx)
39
+ }, others));
40
+ }
41
+ return ___EmotionJSX(Box, _extends({
42
+ variant: "avatar",
43
+ className: classNames,
44
+ sx: _objectSpread({
45
+ size: size,
46
+ fontSize: size
47
+ }, sx)
48
+ }, others), defaultText);
9
49
  });
10
- Avatar.defaultProps = {
11
- alt: 'Avatar'
12
- };
13
50
  Avatar.displayName = 'Avatar';
14
51
  export default Avatar;
@@ -5,8 +5,9 @@ import { render, screen } from '../../utils/testUtils/testWrapper';
5
5
  import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
6
6
  import Avatar from '.';
7
7
  import { jsx as ___EmotionJSX } from "@emotion/react";
8
+ var src = faker.image.lorempicsum.imageUrl(150, 150, false, undefined, '1');
8
9
  var defaultProps = {
9
- src: faker.image.lorempicsum.imageUrl(150, 150, false, undefined, '1')
10
+ src: src
10
11
  };
11
12
  var getComponent = function getComponent() {
12
13
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -31,4 +32,12 @@ test('an avatar is rendered with custom alt', function () {
31
32
  });
32
33
  var img = screen.getByRole('img');
33
34
  expect(img).toHaveAttribute('alt', 'Custom Alt');
35
+ });
36
+ test('an avatar is rendered with custom alt', function () {
37
+ getComponent({
38
+ src: undefined,
39
+ defaultText: 'KL'
40
+ });
41
+ var avatar = screen.getByText('KL');
42
+ expect(avatar).toBeInTheDocument();
34
43
  });
@@ -87,8 +87,8 @@ export var Controlled = function Controlled() {
87
87
  setSelected = _React$useState2[1];
88
88
  return ___EmotionJSX(CheckboxField, {
89
89
  isSelected: isSelected,
90
- onChange: function onChange(e) {
91
- return setSelected;
90
+ onChange: function onChange(selected) {
91
+ return setSelected(selected);
92
92
  },
93
93
  label: "Click me"
94
94
  });
@@ -183,7 +183,9 @@ export var ExpandableAndToggleableIndeterminate = function ExpandableAndToggleab
183
183
  return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(SwitchField, {
184
184
  isSelected: isReadOnly,
185
185
  label: "Is Read Only",
186
- onChange: setIsReadOnly,
186
+ onChange: function onChange() {
187
+ return setIsReadOnly(!isReadOnly);
188
+ },
187
189
  value: "my-switch"
188
190
  }), ___EmotionJSX("br", null), ___EmotionJSX(Box, {
189
191
  isRow: true,
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
2
2
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
3
3
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
4
- var _excluded = ["children", "className", "hasLineNumbers", "hasNoCopyButton", "language", "Prism"];
4
+ var _excluded = ["children", "className", "hasLineNumbers", "hasNoCopyButton", "language", "Prism", "stylesProp"];
5
5
  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; }
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
7
7
  import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
@@ -30,6 +30,8 @@ var CodeView = /*#__PURE__*/forwardRef(function (props, ref) {
30
30
  hasNoCopyButton = props.hasNoCopyButton,
31
31
  language = props.language,
32
32
  customPrism = props.Prism,
33
+ _props$stylesProp = props.stylesProp,
34
+ stylesProp = _props$stylesProp === void 0 ? styles : _props$stylesProp,
33
35
  others = _objectWithoutProperties(props, _excluded);
34
36
  var _useFocusRing = useFocusRing(),
35
37
  isFocusVisible = _useFocusRing.isFocusVisible,
@@ -46,12 +48,13 @@ var CodeView = /*#__PURE__*/forwardRef(function (props, ref) {
46
48
  classNames = _useStatusClasses.classNames;
47
49
 
48
50
  // Get the width for the line number element depending on the total amount of lines
51
+
49
52
  var getLineNoWidth = function getLineNoWidth(tokens) {
50
53
  return tokens.length.toString().length * 12;
51
54
  };
52
55
  var code = (children === null || children === void 0 ? void 0 : _trimInstanceProperty(children).call(children)) || '';
53
56
  var content = ___EmotionJSX(Highlight, _extends({}, defaultProps, {
54
- theme: styles.theme,
57
+ theme: stylesProp.theme,
55
58
  code: code,
56
59
  language: language,
57
60
  Prism: customPrism || Prism
@@ -105,14 +105,15 @@ var wrapper = {
105
105
  pre: {
106
106
  backgroundColor: 'transparent',
107
107
  m: 0,
108
- p: 10,
108
+ p: 'sm',
109
109
  pr: 0,
110
110
  height: '100%',
111
111
  width: '100%',
112
112
  overflowX: 'hidden',
113
113
  overflowY: 'auto',
114
- fontFamily: 'standard',
115
- fontSize: 'sm',
114
+ fontFamily: 'codeView',
115
+ fontSize: '13px',
116
+ lineHeight: 'md',
116
117
  '& .token-line': {
117
118
  display: 'block',
118
119
  alignItems: 'center',
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["className", "isDisabled", "onPress", "isSafariCompatible"];
3
+ var _excluded = ["className", "isDisabled", "onPress", "isSelected", "isSafariCompatible"];
4
4
  import React, { forwardRef, useImperativeHandle, useRef } from 'react';
5
5
  import { mergeProps, useFocusRing, useLink } from 'react-aria';
6
6
  import { useHover, usePress } from '@react-aria/interactions';
@@ -11,6 +11,7 @@ var Link = /*#__PURE__*/forwardRef(function (props, ref) {
11
11
  var className = props.className,
12
12
  isDisabled = props.isDisabled,
13
13
  onPress = props.onPress,
14
+ isSelected = props.isSelected,
14
15
  isSafariCompatible = props.isSafariCompatible,
15
16
  others = _objectWithoutProperties(props, _excluded);
16
17
  var linkRef = useRef(null);
@@ -33,6 +34,7 @@ var Link = /*#__PURE__*/forwardRef(function (props, ref) {
33
34
  pressProps = _usePress.pressProps,
34
35
  isPressed = _usePress.isPressed;
35
36
  var _useStatusClasses = useStatusClasses(className, {
37
+ isSelected: isSelected,
36
38
  isDisabled: isDisabled,
37
39
  isFocused: isFocusVisible,
38
40
  isHovered: isHovered,
@@ -29,7 +29,7 @@ import React, { useState } from 'react';
29
29
  import { OverlayProvider } from 'react-aria';
30
30
  import { useAsyncList } from 'react-stately';
31
31
  import DocsLayout from '../../../.storybook/storybookDocsLayout';
32
- import { Box, Item, LinkSelectField, Separator } from '../../index';
32
+ import { Box, Item, LinkSelectField, Section } from '../../index';
33
33
  import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
34
34
  import { inputFieldAttributeBaseArgTypes } from '../../utils/docUtils/fieldAttributes';
35
35
  import { statusArgTypes } from '../../utils/docUtils/statusProp';
@@ -166,18 +166,15 @@ export var Controlled = function Controlled() {
166
166
  export var WithNoneOption = function WithNoneOption() {
167
167
  return ___EmotionJSX(LinkSelectField, {
168
168
  label: "What's your favorite color?"
169
- }, ___EmotionJSX(Item, {
169
+ }, ___EmotionJSX(Section, null, ___EmotionJSX(Item, {
170
170
  key: "none"
171
- }, "None"), ___EmotionJSX(Item, {
172
- isSeparator: true,
173
- textValue: "-"
174
- }, ___EmotionJSX(Separator, null)), ___EmotionJSX(Item, {
171
+ }, "None")), ___EmotionJSX(Section, null, ___EmotionJSX(Item, {
175
172
  key: "red"
176
173
  }, "Red"), ___EmotionJSX(Item, {
177
174
  key: "blue"
178
175
  }, "Blue"), ___EmotionJSX(Item, {
179
176
  key: "yellow"
180
- }, "Yellow"));
177
+ }, "Yellow")));
181
178
  };
182
179
  export var DisabledField = function DisabledField() {
183
180
  return ___EmotionJSX(LinkSelectField, {
@@ -20,13 +20,16 @@ listBox.option = _objectSpread(_objectSpread({}, text.base), {}, {
20
20
  outline: 'none',
21
21
  wordBreak: 'break-word',
22
22
  cursor: 'pointer',
23
- '&.is-selected': _objectSpread(_objectSpread({}, text.inputValue), {}, {
24
- pl: 0
25
- }),
26
23
  '&.is-focused': {
27
24
  color: 'white',
28
25
  bg: 'active'
29
26
  },
27
+ '&.is-selected': _objectSpread(_objectSpread({}, text.inputValue), {}, {
28
+ pl: 0,
29
+ '&.is-focused': {
30
+ color: 'white'
31
+ }
32
+ }),
30
33
  '&.is-condensed': {
31
34
  '&.is-selected': {
32
35
  pl: 'md',
@@ -24,6 +24,7 @@ import { useLocalOrForwardRef, usePropWarning } from '../../hooks';
24
24
  import ORIENTATION from '../../utils/devUtils/constants/orientation';
25
25
  import Box from '../Box';
26
26
  import MenuItem from '../MenuItem';
27
+ import MenuSection from '../MenuSection';
27
28
  import { jsx as ___EmotionJSX } from "@emotion/react";
28
29
  var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
29
30
  var _context;
@@ -66,10 +67,21 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
66
67
  "aria-orientation": ORIENTATION.VERTICAL
67
68
  }, others, mergeProps(focusProps, menuProps, hoverProps), {
68
69
  role: "menu"
69
- }), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (item) {
70
+ }), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (element) {
71
+ if (element.type === 'section') {
72
+ return ___EmotionJSX(MenuSection, {
73
+ key: element.key,
74
+ section: element,
75
+ state: state,
76
+ onAction: onAction,
77
+ isDisabled: isDisabled,
78
+ isFocusVisible: isFocusVisible,
79
+ isNotFocusedOnHover: isNotFocusedOnHover
80
+ });
81
+ }
70
82
  return ___EmotionJSX(MenuItem, {
71
- key: item.key,
72
- item: item,
83
+ key: element.key,
84
+ item: element,
73
85
  state: state,
74
86
  onAction: onAction,
75
87
  isDisabled: isDisabled,
@@ -4,7 +4,7 @@ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
4
4
  import _Set from "@babel/runtime-corejs3/core-js-stable/set";
5
5
  import React from 'react';
6
6
  import userEvent from '@testing-library/user-event';
7
- import { Item, Menu } from '../../index';
7
+ import { Item, Menu, Section } from '../../index';
8
8
  import ORIENTATION from '../../utils/devUtils/constants/orientation';
9
9
  import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
10
10
  import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
@@ -51,6 +51,29 @@ test('should render basic menu with children', function () {
51
51
  expect(menuItems).toHaveLength(3);
52
52
  expect(menu).toHaveAttribute('aria-orientation', ORIENTATION.VERTICAL);
53
53
  });
54
+ test('should render sections when sections are passed as Children', function () {
55
+ var menuSections = [{
56
+ key: 'menuSection 1',
57
+ children: defaultItems
58
+ }, {
59
+ key: 'menuSection 2',
60
+ children: defaultItems
61
+ }];
62
+ render(___EmotionJSX(Menu, defaultProps, _mapInstanceProperty(menuSections).call(menuSections, function (section) {
63
+ var _context;
64
+ return ___EmotionJSX(Section, section, _mapInstanceProperty(_context = section.children).call(_context, function (item) {
65
+ return ___EmotionJSX(Item, _extends({
66
+ key: item.id
67
+ }, item));
68
+ }));
69
+ })));
70
+ var menu = screen.queryByRole('menu');
71
+ expect(menu).toBeInTheDocument();
72
+ var menuSection = screen.queryAllByRole('group');
73
+ expect(menuSection).toHaveLength(2);
74
+ var menuItems = screen.getAllByRole('menuitem');
75
+ expect(menuItems).toHaveLength(6);
76
+ });
54
77
  test('should render items when selectionMode is set to single', function () {
55
78
  getComponent({
56
79
  selectionMode: 'single'
@@ -18,7 +18,8 @@ var separator = {
18
18
  padding: '0px',
19
19
  '& > [role="separator"]': {
20
20
  margin: '0px'
21
- }
21
+ },
22
+ outline: 'none'
22
23
  };
23
24
  export default {
24
25
  item: item,
@@ -0,0 +1,64 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
3
+ import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
4
+ import React, { forwardRef } from 'react';
5
+ import { useMenuSection } from 'react-aria';
6
+ import { useLocalOrForwardRef } from '../../hooks';
7
+ import Box from '../Box';
8
+ import MenuItem from '../MenuItem';
9
+ import Separator from '../Separator';
10
+
11
+ /**
12
+ * Menu Section component intended to be used within Menu or PopupMenu.
13
+ * This component is not intented to be used outside of Menu or independently.
14
+ * Utilizes [React Aria](https://react-spectrum.adobe.com/react-aria/useMenu.html)
15
+ */
16
+ import { jsx as ___EmotionJSX } from "@emotion/react";
17
+ var MenuSection = /*#__PURE__*/forwardRef(function (props, ref) {
18
+ var _context;
19
+ var section = props.section,
20
+ state = props.state,
21
+ onAction = props.onAction,
22
+ isDisabled = props.isDisabled,
23
+ isFocusVisible = props.isFocusVisible,
24
+ isNotFocusedOnHover = props.isNotFocusedOnHover;
25
+ var menuSectionRef = useLocalOrForwardRef(ref);
26
+ var _useMenuSection = useMenuSection({
27
+ heading: section.rendered,
28
+ 'aria-label': section['aria-label']
29
+ }),
30
+ itemProps = _useMenuSection.itemProps,
31
+ groupProps = _useMenuSection.groupProps,
32
+ headingProps = _useMenuSection.headingProps;
33
+ return ___EmotionJSX(React.Fragment, null, section.key !== state.collection.getFirstKey() && ___EmotionJSX(Separator, {
34
+ as: "li",
35
+ p: 0,
36
+ m: 0
37
+ }), ___EmotionJSX(Box, _extends({
38
+ as: "li"
39
+ }, itemProps, {
40
+ ref: menuSectionRef,
41
+ role: "presentation"
42
+ }), section.rendered && ___EmotionJSX(Box, _extends({
43
+ as: "span",
44
+ variant: "menuSection.sectionTitle"
45
+ }, headingProps, {
46
+ role: "presentation"
47
+ }), section.rendered), ___EmotionJSX(Box, _extends({
48
+ as: "ul",
49
+ variant: "menuSection.section"
50
+ }, groupProps, {
51
+ role: "group"
52
+ }), _mapInstanceProperty(_context = _Array$from(section.childNodes)).call(_context, function (node) {
53
+ return ___EmotionJSX(MenuItem, {
54
+ key: node.key,
55
+ item: node,
56
+ state: state,
57
+ onAction: onAction,
58
+ isDisabled: isDisabled,
59
+ isFocusVisible: isFocusVisible,
60
+ isNotFocusedOnHover: isNotFocusedOnHover
61
+ });
62
+ }))));
63
+ });
64
+ export default MenuSection;
@@ -0,0 +1,27 @@
1
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
2
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
4
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
6
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
8
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
9
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
10
+ 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; }
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+ import menu from '../Menu/Menu.styles';
13
+ var section = _objectSpread(_objectSpread({}, menu), {}, {
14
+ borderRadius: 0
15
+ });
16
+ var sectionTitle = {
17
+ fontSize: 'sm',
18
+ fontWeight: '3',
19
+ color: 'text.secondary',
20
+ height: '36px',
21
+ ml: 'sm',
22
+ justifyContent: 'center'
23
+ };
24
+ export default {
25
+ section: section,
26
+ sectionTitle: sectionTitle
27
+ };
@@ -0,0 +1,97 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
3
+ import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
4
+ import React from 'react';
5
+ import { Item, Menu, Section } from '../../index';
6
+ import { render, screen } from '../../utils/testUtils/testWrapper';
7
+ import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
8
+ import { jsx as ___EmotionJSX } from "@emotion/react";
9
+ var testId = 'testId';
10
+ var defaultMenuSections = [{
11
+ key: 'menuSection 1',
12
+ 'data-id': 'menuSection1',
13
+ title: 'Section 1',
14
+ children: [{
15
+ key: 'menuItem1',
16
+ children: 'MenuItem 1',
17
+ 'data-id': 'menuItem1',
18
+ isPressed: false,
19
+ backgroundColor: 'orange'
20
+ }]
21
+ }, {
22
+ key: 'menuSection 2',
23
+ 'data-id': 'menuSection2',
24
+ children: [{
25
+ key: 'menuItem2',
26
+ children: 'MenuItem 2',
27
+ 'data-id': 'menuItem1',
28
+ isPressed: false
29
+ }, {
30
+ key: 'menuItem3',
31
+ children: 'MenuItem 3',
32
+ 'data-id': 'menuItem1',
33
+ isPressed: false
34
+ }]
35
+ }];
36
+ var defaultProps = {
37
+ 'data-testid': testId,
38
+ defaultSelectedKey: 'menuItem1',
39
+ 'aria-label': 'testLabel'
40
+ };
41
+ var getComponent = function getComponent() {
42
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
43
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
44
+ _ref$items = _ref.items,
45
+ items = _ref$items === void 0 ? defaultMenuSections : _ref$items,
46
+ _ref$renderFn = _ref.renderFn,
47
+ renderFn = _ref$renderFn === void 0 ? render : _ref$renderFn;
48
+ return renderFn(___EmotionJSX(Menu, _extends({}, defaultProps, props), _mapInstanceProperty(items).call(items, function (section) {
49
+ var _context;
50
+ return ___EmotionJSX(Section, section, _mapInstanceProperty(_context = section.children).call(_context, function (li) {
51
+ return ___EmotionJSX(Item, li);
52
+ }));
53
+ })));
54
+ };
55
+
56
+ // Needs to be added to each components test file
57
+ universalComponentTests({
58
+ renderComponent: function renderComponent(props) {
59
+ return ___EmotionJSX(Menu, _extends({}, defaultProps, props), _mapInstanceProperty(defaultMenuSections).call(defaultMenuSections, function (section) {
60
+ var _context2;
61
+ return ___EmotionJSX(Section, section, _mapInstanceProperty(_context2 = section.children).call(_context2, function (li) {
62
+ return ___EmotionJSX(Item, _extends({}, li, {
63
+ sx: {
64
+ backgroundColor: 'orange'
65
+ }
66
+ }));
67
+ }));
68
+ }));
69
+ }
70
+ });
71
+ test('renders menu with menu sections and titles', function () {
72
+ getComponent();
73
+ var menu = screen.getByRole('menu');
74
+ var menuSections = screen.getAllByRole('group');
75
+ var menuTitle = screen.getByText('Section 1');
76
+ expect(menu).toBeInTheDocument();
77
+ expect(menuTitle).toBeInTheDocument();
78
+ expect(menuSections).toHaveLength(defaultMenuSections.length);
79
+ });
80
+ test('renders sections with menu items', function () {
81
+ getComponent();
82
+ var menuItems = screen.getAllByRole('menuitem');
83
+ expect(menuItems).toHaveLength(_reduceInstanceProperty(defaultMenuSections).call(defaultMenuSections, function (acc, section) {
84
+ return acc + section.children.length;
85
+ }, 0));
86
+ });
87
+ test('custom props are passed into menuItem', function () {
88
+ getComponent();
89
+ var itemText1 = defaultMenuSections[0].children[0].children;
90
+ var menuItem1 = screen.getByText(itemText1);
91
+ expect(menuItem1).toHaveStyleRule('background-color', 'orange');
92
+ });
93
+ test('renders separator before menu section if it is not the first section', function () {
94
+ getComponent();
95
+ var separators = screen.getByRole('separator');
96
+ expect(separators).toBeInTheDocument();
97
+ });
@@ -0,0 +1 @@
1
+ export { default } from './MenuSection';
@@ -4,7 +4,7 @@ import DotsVerticalIcon from '@pingux/mdi-react/DotsVerticalIcon';
4
4
  import { action } from '@storybook/addon-actions';
5
5
  import { withDesign } from 'storybook-addon-designs';
6
6
  import DocsLayout from '../../../.storybook/storybookDocsLayout';
7
- import { Icon, IconButton, Item, Menu, OverlayProvider, PopoverMenu, Text } from '../../index';
7
+ import { Icon, IconButton, Item, Menu, OverlayProvider, PopoverMenu, Section, Text } from '../../index';
8
8
  import { FIGMA_LINKS } from '../../utils/designUtils/figmaLinks';
9
9
  import PopoverMenuReadme from './PopoverMenu.mdx';
10
10
  import { jsx as ___EmotionJSX } from "@emotion/react";
@@ -88,12 +88,12 @@ export var DefaultOpen = function DefaultOpen() {
88
88
  }
89
89
  })), ___EmotionJSX(Menu, {
90
90
  onAction: action('onAction'),
91
- disabledKeys: ['duplicate']
91
+ disabledKeys: ['disabledItem']
92
92
  }, ___EmotionJSX(Item, {
93
93
  key: "edit"
94
94
  }, "Edit"), ___EmotionJSX(Item, {
95
- key: "duplicate"
96
- }, "Duplicate"), ___EmotionJSX(Item, {
95
+ key: "disabledItem"
96
+ }, "Disabled Item"), ___EmotionJSX(Item, {
97
97
  key: "delete",
98
98
  textValue: "delete"
99
99
  }, ___EmotionJSX(Text, {
@@ -222,4 +222,70 @@ export var NotClosedOnSelect = function NotClosedOnSelect() {
222
222
  color: "critical.bright"
223
223
  }, "Delete")))))
224
224
  );
225
+ };
226
+ export var WithSeparator = function WithSeparator(args) {
227
+ return (
228
+ // Application must be wrapped in an OverlayProvider so that it can be hidden from screen
229
+ // readers when an overlay opens.
230
+ ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(PopoverMenu, args, ___EmotionJSX(IconButton, {
231
+ "aria-label": "more options",
232
+ variant: "inverted"
233
+ }, ___EmotionJSX(Icon, {
234
+ icon: DotsVerticalIcon,
235
+ size: "md",
236
+ title: {
237
+ name: 'Dots Vertical Icon'
238
+ }
239
+ })), ___EmotionJSX(Menu, {
240
+ onAction: action('onAction'),
241
+ disabledKeys: ['disabledItem']
242
+ }, ___EmotionJSX(Section, null, ___EmotionJSX(Item, {
243
+ key: "edit"
244
+ }, "Edit")), ___EmotionJSX(Section, null, ___EmotionJSX(Item, {
245
+ key: "disabledItem"
246
+ }, "Disabled Item"), ___EmotionJSX(Item, {
247
+ key: "delete",
248
+ textValue: "delete"
249
+ }, ___EmotionJSX(Text, {
250
+ color: "critical.bright"
251
+ }, "Delete"))))))
252
+ );
253
+ };
254
+ export var WithSections = function WithSections(args) {
255
+ return (
256
+ // Application must be wrapped in an OverlayProvider so that it can be hidden from screen
257
+ // readers when an overlay opens.
258
+ ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(PopoverMenu, args, ___EmotionJSX(IconButton, {
259
+ "aria-label": "more options",
260
+ variant: "inverted"
261
+ }, ___EmotionJSX(Icon, {
262
+ icon: DotsVerticalIcon,
263
+ size: "md",
264
+ title: {
265
+ name: 'Dots Vertical Icon'
266
+ }
267
+ })), ___EmotionJSX(Menu, {
268
+ onAction: action('onAction'),
269
+ disabledKeys: ['disabledItem']
270
+ }, ___EmotionJSX(Section, {
271
+ key: "section 1",
272
+ title: "Section 1"
273
+ }, ___EmotionJSX(Item, {
274
+ key: "edit"
275
+ }, "Edit"), ___EmotionJSX(Item, {
276
+ key: "disabledItem"
277
+ }, "Disabled Item"), ___EmotionJSX(Item, {
278
+ key: "copy"
279
+ }, "Copy")), ___EmotionJSX(Section, {
280
+ key: "section 2",
281
+ title: "Section 2"
282
+ }, ___EmotionJSX(Item, {
283
+ key: "duplicate"
284
+ }, "Duplicate"), ___EmotionJSX(Item, {
285
+ key: "delete",
286
+ textValue: "delete"
287
+ }, ___EmotionJSX(Text, {
288
+ color: "critical.bright"
289
+ }, "Delete"))))))
290
+ );
225
291
  };
@@ -31,7 +31,7 @@ import { OverlayProvider } from 'react-aria';
31
31
  import { useAsyncList } from 'react-stately';
32
32
  import CalendarRangeIcon from '@pingux/mdi-react/CalendarRangeIcon';
33
33
  import DocsLayout from '../../../.storybook/storybookDocsLayout';
34
- import { Icon, Item, Section, SelectField, Separator } from '../../index';
34
+ import { Icon, Item, Section, SelectField } from '../../index';
35
35
  import { modes as labelModes } from '../../utils/devUtils/constants/labelModes';
36
36
  import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
37
37
  import { inputFieldAttributeBaseArgTypes } from '../../utils/docUtils/fieldAttributes';
@@ -247,18 +247,15 @@ export var Controlled = function Controlled() {
247
247
  export var WithNoneOption = function WithNoneOption() {
248
248
  return ___EmotionJSX(SelectField, {
249
249
  label: "What's your favorite color?"
250
- }, ___EmotionJSX(Item, {
250
+ }, ___EmotionJSX(Section, null, ___EmotionJSX(Item, {
251
251
  key: "none"
252
- }, "None"), ___EmotionJSX(Item, {
253
- isSeparator: true,
254
- textValue: "-"
255
- }, ___EmotionJSX(Separator, null)), ___EmotionJSX(Item, {
252
+ }, "None")), ___EmotionJSX(Section, null, ___EmotionJSX(Item, {
256
253
  key: "red"
257
254
  }, "Red"), ___EmotionJSX(Item, {
258
255
  key: "blue"
259
256
  }, "Blue"), ___EmotionJSX(Item, {
260
257
  key: "yellow"
261
- }, "Yellow"));
258
+ }, "Yellow")));
262
259
  };
263
260
  export var WithSlots = function WithSlots() {
264
261
  return ___EmotionJSX(SelectField, {