@instructure/ui-menu 11.6.0 → 11.6.1-snapshot-129

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 (180) hide show
  1. package/CHANGELOG.md +41 -297
  2. package/es/Menu/{MenuItem → v1/MenuItem}/index.js +2 -2
  3. package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.js +1 -1
  4. package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.js +1 -1
  5. package/es/Menu/{index.js → v1/index.js} +3 -3
  6. package/es/Menu/v2/MenuItem/index.js +262 -0
  7. package/es/Menu/v2/MenuItem/props.js +26 -0
  8. package/es/Menu/v2/MenuItem/styles.js +146 -0
  9. package/es/Menu/v2/MenuItemGroup/index.js +175 -0
  10. package/es/Menu/v2/MenuItemGroup/props.js +26 -0
  11. package/es/Menu/v2/MenuItemGroup/styles.js +60 -0
  12. package/es/Menu/v2/MenuItemSeparator/index.js +70 -0
  13. package/es/Menu/v2/MenuItemSeparator/props.js +29 -0
  14. package/es/Menu/v2/MenuItemSeparator/styles.js +46 -0
  15. package/es/Menu/v2/index.js +405 -0
  16. package/es/Menu/v2/props.js +26 -0
  17. package/es/Menu/v2/styles.js +61 -0
  18. package/es/{index.js → exports/a.js} +1 -1
  19. package/es/exports/b.js +24 -0
  20. package/es/{MenuContext.js → utils/v1/MenuContext.js} +2 -0
  21. package/lib/Menu/{MenuItem → v1/MenuItem}/index.js +4 -4
  22. package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.js +1 -1
  23. package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.js +1 -1
  24. package/lib/Menu/v1/index.js +432 -0
  25. package/lib/Menu/v2/MenuItem/index.js +271 -0
  26. package/lib/Menu/v2/MenuItem/props.js +31 -0
  27. package/lib/Menu/v2/MenuItem/styles.js +152 -0
  28. package/lib/Menu/v2/MenuItemGroup/index.js +183 -0
  29. package/lib/Menu/v2/MenuItemGroup/props.js +31 -0
  30. package/lib/Menu/v2/MenuItemGroup/styles.js +66 -0
  31. package/lib/Menu/v2/MenuItemSeparator/index.js +75 -0
  32. package/lib/Menu/v2/MenuItemSeparator/props.js +34 -0
  33. package/lib/Menu/v2/MenuItemSeparator/styles.js +52 -0
  34. package/lib/Menu/{index.js → v2/index.js} +4 -5
  35. package/lib/Menu/v2/props.js +31 -0
  36. package/lib/Menu/v2/styles.js +66 -0
  37. package/lib/{index.js → exports/a.js} +5 -5
  38. package/lib/exports/b.js +30 -0
  39. package/lib/{MenuContext.js → utils/v1/MenuContext.js} +1 -0
  40. package/package.json +45 -23
  41. package/src/Menu/{MenuItem → v1/MenuItem}/index.tsx +2 -2
  42. package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.tsx +1 -1
  43. package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.tsx +1 -1
  44. package/src/Menu/{index.tsx → v1/index.tsx} +3 -3
  45. package/src/Menu/{props.ts → v1/props.ts} +1 -1
  46. package/src/Menu/v2/MenuItem/index.tsx +318 -0
  47. package/src/Menu/v2/MenuItem/props.ts +132 -0
  48. package/src/Menu/v2/MenuItem/styles.ts +172 -0
  49. package/src/Menu/v2/MenuItemGroup/index.tsx +245 -0
  50. package/src/Menu/v2/MenuItemGroup/props.ts +105 -0
  51. package/src/Menu/v2/MenuItemGroup/styles.ts +66 -0
  52. package/src/Menu/v2/MenuItemSeparator/index.tsx +79 -0
  53. package/src/Menu/v2/MenuItemSeparator/props.ts +48 -0
  54. package/src/Menu/v2/MenuItemSeparator/styles.ts +52 -0
  55. package/src/Menu/v2/README.md +104 -0
  56. package/src/Menu/v2/index.tsx +514 -0
  57. package/src/Menu/v2/props.ts +213 -0
  58. package/src/Menu/v2/styles.ts +68 -0
  59. package/src/{index.ts → exports/a.ts} +5 -5
  60. package/src/exports/b.ts +29 -0
  61. package/src/{MenuContext.ts → utils/v1/MenuContext.ts} +3 -3
  62. package/tsconfig.build.tsbuildinfo +1 -1
  63. package/types/Menu/{MenuItem → v1/MenuItem}/index.d.ts +3 -3
  64. package/types/Menu/v1/MenuItem/index.d.ts.map +1 -0
  65. package/types/Menu/v1/MenuItem/props.d.ts.map +1 -0
  66. package/types/Menu/v1/MenuItem/styles.d.ts.map +1 -0
  67. package/types/Menu/v1/MenuItem/theme.d.ts.map +1 -0
  68. package/types/Menu/v1/MenuItemGroup/index.d.ts.map +1 -0
  69. package/types/Menu/v1/MenuItemGroup/props.d.ts.map +1 -0
  70. package/types/Menu/v1/MenuItemGroup/styles.d.ts.map +1 -0
  71. package/types/Menu/v1/MenuItemGroup/theme.d.ts.map +1 -0
  72. package/types/Menu/v1/MenuItemSeparator/index.d.ts.map +1 -0
  73. package/types/Menu/v1/MenuItemSeparator/props.d.ts.map +1 -0
  74. package/types/Menu/v1/MenuItemSeparator/styles.d.ts.map +1 -0
  75. package/types/Menu/v1/MenuItemSeparator/theme.d.ts.map +1 -0
  76. package/types/Menu/{index.d.ts → v1/index.d.ts} +3 -3
  77. package/types/Menu/v1/index.d.ts.map +1 -0
  78. package/types/Menu/{props.d.ts → v1/props.d.ts} +1 -1
  79. package/types/Menu/v1/props.d.ts.map +1 -0
  80. package/types/Menu/v1/styles.d.ts.map +1 -0
  81. package/types/Menu/v1/theme.d.ts.map +1 -0
  82. package/types/Menu/v2/MenuItem/index.d.ts +66 -0
  83. package/types/Menu/v2/MenuItem/index.d.ts.map +1 -0
  84. package/types/Menu/v2/MenuItem/props.d.ts +73 -0
  85. package/types/Menu/v2/MenuItem/props.d.ts.map +1 -0
  86. package/types/Menu/v2/MenuItem/styles.d.ts +15 -0
  87. package/types/Menu/v2/MenuItem/styles.d.ts.map +1 -0
  88. package/types/Menu/v2/MenuItemGroup/index.d.ts +52 -0
  89. package/types/Menu/v2/MenuItemGroup/index.d.ts.map +1 -0
  90. package/types/Menu/v2/MenuItemGroup/props.d.ts +51 -0
  91. package/types/Menu/v2/MenuItemGroup/props.d.ts.map +1 -0
  92. package/types/Menu/v2/MenuItemGroup/styles.d.ts +15 -0
  93. package/types/Menu/v2/MenuItemGroup/styles.d.ts.map +1 -0
  94. package/types/Menu/v2/MenuItemSeparator/index.d.ts +21 -0
  95. package/types/Menu/v2/MenuItemSeparator/index.d.ts.map +1 -0
  96. package/types/Menu/v2/MenuItemSeparator/props.d.ts +11 -0
  97. package/types/Menu/v2/MenuItemSeparator/props.d.ts.map +1 -0
  98. package/types/Menu/v2/MenuItemSeparator/styles.d.ts +15 -0
  99. package/types/Menu/v2/MenuItemSeparator/styles.d.ts.map +1 -0
  100. package/types/Menu/v2/index.d.ts +118 -0
  101. package/types/Menu/v2/index.d.ts.map +1 -0
  102. package/types/Menu/v2/props.d.ts +138 -0
  103. package/types/Menu/v2/props.d.ts.map +1 -0
  104. package/types/Menu/v2/styles.d.ts +15 -0
  105. package/types/Menu/v2/styles.d.ts.map +1 -0
  106. package/types/exports/a.d.ts +6 -0
  107. package/types/exports/a.d.ts.map +1 -0
  108. package/types/exports/b.d.ts +6 -0
  109. package/types/exports/b.d.ts.map +1 -0
  110. package/types/utils/v1/MenuContext.d.ts +13 -0
  111. package/types/utils/v1/MenuContext.d.ts.map +1 -0
  112. package/types/Menu/MenuItem/index.d.ts.map +0 -1
  113. package/types/Menu/MenuItem/props.d.ts.map +0 -1
  114. package/types/Menu/MenuItem/styles.d.ts.map +0 -1
  115. package/types/Menu/MenuItem/theme.d.ts.map +0 -1
  116. package/types/Menu/MenuItemGroup/index.d.ts.map +0 -1
  117. package/types/Menu/MenuItemGroup/props.d.ts.map +0 -1
  118. package/types/Menu/MenuItemGroup/styles.d.ts.map +0 -1
  119. package/types/Menu/MenuItemGroup/theme.d.ts.map +0 -1
  120. package/types/Menu/MenuItemSeparator/index.d.ts.map +0 -1
  121. package/types/Menu/MenuItemSeparator/props.d.ts.map +0 -1
  122. package/types/Menu/MenuItemSeparator/styles.d.ts.map +0 -1
  123. package/types/Menu/MenuItemSeparator/theme.d.ts.map +0 -1
  124. package/types/Menu/index.d.ts.map +0 -1
  125. package/types/Menu/props.d.ts.map +0 -1
  126. package/types/Menu/styles.d.ts.map +0 -1
  127. package/types/Menu/theme.d.ts.map +0 -1
  128. package/types/MenuContext.d.ts +0 -14
  129. package/types/MenuContext.d.ts.map +0 -1
  130. package/types/index.d.ts +0 -6
  131. package/types/index.d.ts.map +0 -1
  132. /package/es/Menu/{MenuItem → v1/MenuItem}/props.js +0 -0
  133. /package/es/Menu/{MenuItem → v1/MenuItem}/styles.js +0 -0
  134. /package/es/Menu/{MenuItem → v1/MenuItem}/theme.js +0 -0
  135. /package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.js +0 -0
  136. /package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.js +0 -0
  137. /package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.js +0 -0
  138. /package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.js +0 -0
  139. /package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.js +0 -0
  140. /package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.js +0 -0
  141. /package/es/Menu/{props.js → v1/props.js} +0 -0
  142. /package/es/Menu/{styles.js → v1/styles.js} +0 -0
  143. /package/es/Menu/{theme.js → v1/theme.js} +0 -0
  144. /package/lib/Menu/{MenuItem → v1/MenuItem}/props.js +0 -0
  145. /package/lib/Menu/{MenuItem → v1/MenuItem}/styles.js +0 -0
  146. /package/lib/Menu/{MenuItem → v1/MenuItem}/theme.js +0 -0
  147. /package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.js +0 -0
  148. /package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.js +0 -0
  149. /package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.js +0 -0
  150. /package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.js +0 -0
  151. /package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.js +0 -0
  152. /package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.js +0 -0
  153. /package/lib/Menu/{props.js → v1/props.js} +0 -0
  154. /package/lib/Menu/{styles.js → v1/styles.js} +0 -0
  155. /package/lib/Menu/{theme.js → v1/theme.js} +0 -0
  156. /package/src/Menu/{MenuItem → v1/MenuItem}/props.ts +0 -0
  157. /package/src/Menu/{MenuItem → v1/MenuItem}/styles.ts +0 -0
  158. /package/src/Menu/{MenuItem → v1/MenuItem}/theme.ts +0 -0
  159. /package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.ts +0 -0
  160. /package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.ts +0 -0
  161. /package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.ts +0 -0
  162. /package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.ts +0 -0
  163. /package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.ts +0 -0
  164. /package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.ts +0 -0
  165. /package/src/Menu/{README.md → v1/README.md} +0 -0
  166. /package/src/Menu/{styles.ts → v1/styles.ts} +0 -0
  167. /package/src/Menu/{theme.ts → v1/theme.ts} +0 -0
  168. /package/types/Menu/{MenuItem → v1/MenuItem}/props.d.ts +0 -0
  169. /package/types/Menu/{MenuItem → v1/MenuItem}/styles.d.ts +0 -0
  170. /package/types/Menu/{MenuItem → v1/MenuItem}/theme.d.ts +0 -0
  171. /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.d.ts +0 -0
  172. /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.d.ts +0 -0
  173. /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.d.ts +0 -0
  174. /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.d.ts +0 -0
  175. /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.d.ts +0 -0
  176. /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.d.ts +0 -0
  177. /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.d.ts +0 -0
  178. /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.d.ts +0 -0
  179. /package/types/Menu/{styles.d.ts → v1/styles.d.ts} +0 -0
  180. /package/types/Menu/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,60 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = componentTheme => {
36
+ return {
37
+ menuItemGroup: {
38
+ label: 'menuItemGroup',
39
+ display: 'block'
40
+ },
41
+ label: {
42
+ label: 'menuItemGroup__label',
43
+ background: componentTheme.background,
44
+ padding: `${componentTheme.paddingVertical} ${componentTheme.paddingHorizontal}`,
45
+ display: 'block',
46
+ fontSize: componentTheme.fontSize,
47
+ fontFamily: componentTheme.fontFamily,
48
+ fontWeight: componentTheme.fontWeight,
49
+ color: componentTheme.color,
50
+ textAlign: 'start'
51
+ },
52
+ items: {
53
+ label: 'menuItemGroup__items',
54
+ padding: '0',
55
+ margin: '0 0 0 0',
56
+ listStyleType: 'none'
57
+ }
58
+ };
59
+ };
60
+ export default generateStyle;
@@ -0,0 +1,70 @@
1
+ var _dec, _class, _MenuItemSeparator;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Component } from 'react';
27
+ import { withStyle } from '@instructure/emotion';
28
+ import { omitProps } from '@instructure/ui-react-utils';
29
+ import generateStyle from "./styles.js";
30
+ import { allowedProps } from "./props.js";
31
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
32
+ /**
33
+ ---
34
+ parent: Menu
35
+ id: Menu.Separator
36
+ ---
37
+ @module MenuItemSeparator
38
+ **/
39
+ let MenuItemSeparator = (_dec = withStyle(generateStyle), _dec(_class = (_MenuItemSeparator = class MenuItemSeparator extends Component {
40
+ constructor(...args) {
41
+ super(...args);
42
+ this.ref = null;
43
+ this.handleRef = el => {
44
+ this.ref = el;
45
+ };
46
+ }
47
+ componentDidMount() {
48
+ var _this$props$makeStyle, _this$props;
49
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
50
+ }
51
+ componentDidUpdate() {
52
+ var _this$props$makeStyle2, _this$props2;
53
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
54
+ }
55
+ render() {
56
+ var _this$props$styles;
57
+ const props = omitProps(this.props, MenuItemSeparator.allowedProps);
58
+ // role="separator" would fit better here, but it causes NVDA to stop the
59
+ // MenuItem count after it
60
+ return _jsx("div", {
61
+ ...props,
62
+ role: "presentation",
63
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.menuItemSeparator,
64
+ ref: this.handleRef,
65
+ "data-cid": "MenuItemSeparator"
66
+ });
67
+ }
68
+ }, _MenuItemSeparator.displayName = "MenuItemSeparator", _MenuItemSeparator.componentId = 'Menu.Separator', _MenuItemSeparator.allowedProps = allowedProps, _MenuItemSeparator)) || _class);
69
+ export default MenuItemSeparator;
70
+ export { MenuItemSeparator };
@@ -0,0 +1,29 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ // keeping here to keep the structure of props.ts
26
+ // eslint-disable-next-line
27
+
28
+ const allowedProps = [];
29
+ export { allowedProps };
@@ -0,0 +1,46 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = componentTheme => {
36
+ return {
37
+ menuItemSeparator: {
38
+ label: 'menuItemSeparator',
39
+ height: componentTheme.height,
40
+ margin: `${componentTheme.marginVertical} ${componentTheme.marginHorizontal}`,
41
+ overflow: 'hidden',
42
+ background: componentTheme.background
43
+ }
44
+ };
45
+ };
46
+ export default generateStyle;
@@ -0,0 +1,405 @@
1
+ var _dec, _dec2, _class, _Menu;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Children, Component } from 'react';
27
+ import keycode from 'keycode';
28
+ import { Popover } from '@instructure/ui-popover/latest';
29
+ import { safeCloneElement, matchComponentTypes, withDeterministicId } from '@instructure/ui-react-utils';
30
+ import { logError as error } from '@instructure/console';
31
+ import { containsActiveElement } from '@instructure/ui-dom-utils';
32
+ import { MenuContext } from "../../utils/v1/MenuContext.js";
33
+ import { MenuItem } from "./MenuItem/index.js";
34
+ import { MenuItemGroup } from "./MenuItemGroup/index.js";
35
+ import { MenuItemSeparator } from "./MenuItemSeparator/index.js";
36
+ import { withStyle } from '@instructure/emotion';
37
+ import generateStyle from "./styles.js";
38
+ import { allowedProps } from "./props.js";
39
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
40
+ /**
41
+ ---
42
+ category: components
43
+ ---
44
+ **/
45
+ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_Menu = class Menu extends Component {
46
+ constructor(props) {
47
+ super(props);
48
+ this.state = {
49
+ hasFocus: false
50
+ };
51
+ this._rootNode = null;
52
+ this._menuItems = [];
53
+ this._popover = null;
54
+ this._trigger = null;
55
+ this._menu = null;
56
+ this._labelId = this.props.deterministicId('Menu__label');
57
+ this._activeSubMenu = void 0;
58
+ this._id = void 0;
59
+ this.ref = null;
60
+ this.handleRef = el => {
61
+ const menuRef = this.props.menuRef;
62
+ this._menu = el;
63
+ if (typeof menuRef === 'function') {
64
+ menuRef(el);
65
+ }
66
+ // If there is no trigger `<ul>` is the ref, otherwise the trigger
67
+ if (!this.props.trigger) {
68
+ this.ref = el;
69
+ }
70
+ };
71
+ this.registerMenuItem = item => {
72
+ this._menuItems.push(item);
73
+ };
74
+ this.removeMenuItem = item => {
75
+ const index = this.getMenuItemIndex(item);
76
+ error(index >= 0, '[Menu] Could not find registered menu item.');
77
+ if (index >= 0) {
78
+ this._menuItems.splice(index, 1);
79
+ }
80
+ };
81
+ this.getMenuItemIndex = item => {
82
+ return this._menuItems.findIndex(i => i === item);
83
+ };
84
+ this.handleTriggerKeyDown = event => {
85
+ if (this.props.type === 'flyout' && event.keyCode === keycode.codes.right) {
86
+ event.persist();
87
+ this.show(event);
88
+ }
89
+ };
90
+ this.handleTriggerMouseOver = event => {
91
+ if (this.props.type === 'flyout') {
92
+ this.show(event);
93
+ }
94
+ };
95
+ this.handleToggle = shown => {
96
+ if (typeof this.props.onToggle === 'function') {
97
+ this.props.onToggle(shown, this);
98
+ }
99
+ };
100
+ this.handleMenuKeyDown = event => {
101
+ const key = event && event.keyCode;
102
+ const _keycode$codes = keycode.codes,
103
+ down = _keycode$codes.down,
104
+ up = _keycode$codes.up,
105
+ tab = _keycode$codes.tab,
106
+ left = _keycode$codes.left;
107
+ const pgdn = keycode.codes['page down'];
108
+ const pgup = keycode.codes['page up'];
109
+ if (key === down || key === pgdn) {
110
+ event.preventDefault();
111
+ event.stopPropagation();
112
+ this.moveFocus(1);
113
+ this.hideActiveSubMenu(event);
114
+ } else if (key === up || key === pgup) {
115
+ event.preventDefault();
116
+ event.stopPropagation();
117
+ this.moveFocus(-1);
118
+ this.hideActiveSubMenu(event);
119
+ } else if (key === tab || key === left) {
120
+ event.persist();
121
+ this.hide(event);
122
+ }
123
+ if (typeof this.props.onKeyDown === 'function') {
124
+ this.props.onKeyDown(event);
125
+ }
126
+ };
127
+ this.handleMenuItemSelect = (event, value, selected, item) => {
128
+ if (this.props.shouldHideOnSelect) {
129
+ this.hide(event);
130
+ }
131
+ if (typeof this.props.onSelect === 'function') {
132
+ this.props.onSelect(event, value, selected, item);
133
+ }
134
+ };
135
+ this.handleMenuItemFocus = () => {
136
+ this.setState({
137
+ hasFocus: true
138
+ });
139
+ };
140
+ this.handleMenuItemBlur = () => {
141
+ this.setState({
142
+ hasFocus: this.focusedIndex >= 0
143
+ });
144
+ };
145
+ this.handleMenuItemMouseOver = (event, menuItem) => {
146
+ if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
147
+ this.hideActiveSubMenu(event);
148
+ }
149
+ };
150
+ this.hideActiveSubMenu = event => {
151
+ if (this._activeSubMenu) {
152
+ this._activeSubMenu.hide(event);
153
+ this._activeSubMenu = null;
154
+ }
155
+ };
156
+ this.handleSubMenuToggle = (shown, subMenu) => {
157
+ if (shown) {
158
+ this._activeSubMenu = subMenu;
159
+ }
160
+ };
161
+ this.handleSubMenuDismiss = (event, documentClick) => {
162
+ if (event && event.keyCode === keycode.codes.tab || documentClick) {
163
+ this.hide(event);
164
+ }
165
+ };
166
+ this.hide = event => {
167
+ if (this._popover) {
168
+ this._popover.hide(event);
169
+ }
170
+ };
171
+ this.show = event => {
172
+ if (this._popover) {
173
+ this._popover.show(event);
174
+ }
175
+ };
176
+ this._id = this.props.id || props.deterministicId();
177
+ }
178
+ componentDidMount() {
179
+ var _this$props$makeStyle, _this$props;
180
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
181
+ }
182
+ componentDidUpdate() {
183
+ var _this$props$makeStyle2, _this$props2;
184
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
185
+ }
186
+ get menuItems() {
187
+ return this._menuItems;
188
+ }
189
+ focus() {
190
+ if (this.shown) {
191
+ var _this$_menu;
192
+ error(!!((_this$_menu = this._menu) !== null && _this$_menu !== void 0 && _this$_menu.focus), '[Menu] Could not focus the menu.');
193
+ this._menu.focus();
194
+ } else {
195
+ var _this$_trigger;
196
+ error(!!((_this$_trigger = this._trigger) !== null && _this$_trigger !== void 0 && _this$_trigger.focus), '[Menu] Could not focus the trigger.');
197
+ this._trigger.focus();
198
+ }
199
+ }
200
+ focused() {
201
+ if (this.shown) {
202
+ return containsActiveElement(this._menu) || this.state.hasFocus;
203
+ } else {
204
+ return containsActiveElement(this._trigger);
205
+ }
206
+ }
207
+ get focusedIndex() {
208
+ return this.menuItems.findIndex(item => {
209
+ return item && item.focused === true;
210
+ });
211
+ }
212
+ moveFocus(step) {
213
+ const count = this.menuItems ? this.menuItems.length : 0;
214
+ if (count <= 0) {
215
+ return;
216
+ }
217
+ const current = this.focusedIndex < 0 && step < 0 ? 0 : this.focusedIndex;
218
+ const nextItem = this.menuItems[(current + count + step) % count];
219
+ error(typeof nextItem !== 'undefined' && typeof nextItem.focus !== 'undefined', '[Menu] Could not focus next menu item.');
220
+ nextItem.focus();
221
+ }
222
+ get shown() {
223
+ return this._popover ? this._popover.shown : true;
224
+ }
225
+ renderChildren() {
226
+ const _this$props3 = this.props,
227
+ children = _this$props3.children,
228
+ disabled = _this$props3.disabled;
229
+ let count = 0;
230
+ return Children.map(children, child => {
231
+ if (!matchComponentTypes(child, ['MenuItemSeparator', 'MenuItem', 'MenuItemGroup', 'Menu'])) {
232
+ return;
233
+ }
234
+ count += 1;
235
+ const isTabbable = !this.state.hasFocus && count === 1;
236
+ if (matchComponentTypes(child, ['MenuItemSeparator'])) {
237
+ return child;
238
+ }
239
+ const menuItemChild = child;
240
+ const controls = menuItemChild.props['aria-controls'] || menuItemChild.props.controls || this.props['aria-controls'] || this.props.controls;
241
+ if (matchComponentTypes(child, ['MenuItem'])) {
242
+ return safeCloneElement(child, {
243
+ controls,
244
+ children: child.props.children,
245
+ disabled: disabled || child.props.disabled,
246
+ onFocus: this.handleMenuItemFocus,
247
+ onBlur: this.handleMenuItemBlur,
248
+ onSelect: this.handleMenuItemSelect,
249
+ onMouseOver: this.handleMenuItemMouseOver,
250
+ tabIndex: isTabbable ? 0 : -1
251
+ });
252
+ }
253
+ if (matchComponentTypes(child, ['MenuItemGroup'])) {
254
+ return safeCloneElement(child, {
255
+ label: child.props.label,
256
+ controls,
257
+ disabled: disabled || child.props.disabled,
258
+ onFocus: this.handleMenuItemFocus,
259
+ onBlur: this.handleMenuItemBlur,
260
+ onSelect: this.handleMenuItemSelect,
261
+ onMouseOver: this.handleMenuItemMouseOver,
262
+ isTabbable
263
+ });
264
+ }
265
+ if (matchComponentTypes(child, ['Menu'])) {
266
+ const submenuDisabled = disabled || child.props.disabled;
267
+ return safeCloneElement(child, {
268
+ type: 'flyout',
269
+ controls,
270
+ disabled: submenuDisabled,
271
+ onSelect: this.handleMenuItemSelect,
272
+ placement: 'end top',
273
+ offsetX: -5,
274
+ offsetY: 5,
275
+ withArrow: false,
276
+ onToggle: this.handleSubMenuToggle,
277
+ onDismiss: this.handleSubMenuDismiss,
278
+ trigger: _jsx(MenuItem, {
279
+ onMouseOver: this.handleMenuItemMouseOver,
280
+ onFocus: this.handleMenuItemFocus,
281
+ onBlur: this.handleMenuItemBlur,
282
+ tabIndex: isTabbable ? 0 : -1,
283
+ type: "flyout",
284
+ disabled: submenuDisabled,
285
+ renderLabelInfo: child.props.renderLabelInfo,
286
+ children: child.props.title || child.props.label
287
+ })
288
+ });
289
+ }
290
+ return;
291
+ });
292
+ }
293
+ renderMenu() {
294
+ var _this$props$styles;
295
+ const _this$props4 = this.props,
296
+ disabled = _this$props4.disabled,
297
+ label = _this$props4.label,
298
+ trigger = _this$props4.trigger,
299
+ onKeyUp = _this$props4.onKeyUp;
300
+ const labelledBy = this.props['aria-labelledby'];
301
+ const controls = this.props['aria-controls'];
302
+ return _jsx(MenuContext.Provider, {
303
+ value: {
304
+ removeMenuItem: this.removeMenuItem,
305
+ registerMenuItem: this.registerMenuItem
306
+ },
307
+ children: _jsx("div", {
308
+ role: "menu",
309
+ "aria-label": label,
310
+ tabIndex: 0,
311
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.menu,
312
+ "aria-labelledby": labelledBy || (trigger ? this._labelId : void 0),
313
+ "aria-controls": controls,
314
+ "aria-disabled": disabled ? 'true' : void 0,
315
+ onKeyDown: this.handleMenuKeyDown,
316
+ onKeyUp: onKeyUp,
317
+ ref: this.handleRef,
318
+ "data-cid": "Menu",
319
+ children: this.renderChildren()
320
+ })
321
+ });
322
+ }
323
+ render() {
324
+ const _this$props5 = this.props,
325
+ show = _this$props5.show,
326
+ defaultShow = _this$props5.defaultShow,
327
+ placement = _this$props5.placement,
328
+ withArrow = _this$props5.withArrow,
329
+ trigger = _this$props5.trigger,
330
+ mountNode = _this$props5.mountNode,
331
+ popoverRef = _this$props5.popoverRef,
332
+ disabled = _this$props5.disabled,
333
+ onDismiss = _this$props5.onDismiss,
334
+ onFocus = _this$props5.onFocus,
335
+ onMouseOver = _this$props5.onMouseOver,
336
+ positionContainerDisplay = _this$props5.positionContainerDisplay,
337
+ offsetX = _this$props5.offsetX,
338
+ offsetY = _this$props5.offsetY;
339
+ return trigger ? _jsx(Popover, {
340
+ "data-cid": "Menu",
341
+ isShowingContent: show,
342
+ defaultIsShowingContent: defaultShow,
343
+ onHideContent: (event, {
344
+ documentClick
345
+ }) => {
346
+ if (typeof onDismiss === 'function') {
347
+ onDismiss(event, documentClick);
348
+ }
349
+ this.handleToggle(false);
350
+ },
351
+ onShowContent: () => this.handleToggle(true),
352
+ mountNode: mountNode,
353
+ placement: placement,
354
+ withArrow: withArrow,
355
+ id: this._id,
356
+ on: ['click'],
357
+ shouldContainFocus: true,
358
+ shouldReturnFocus: true,
359
+ onFocus: onFocus,
360
+ onMouseOver: onMouseOver,
361
+ positionContainerDisplay: positionContainerDisplay,
362
+ offsetX: offsetX,
363
+ offsetY: offsetY,
364
+ elementRef: element => {
365
+ this.ref = element;
366
+ },
367
+ ref: el => {
368
+ this._popover = el;
369
+ if (typeof popoverRef === 'function') {
370
+ popoverRef(el);
371
+ }
372
+ },
373
+ renderTrigger: safeCloneElement(trigger, {
374
+ ref: el => {
375
+ this._trigger = el;
376
+ },
377
+ 'aria-haspopup': true,
378
+ id: this._labelId,
379
+ onMouseOver: this.handleTriggerMouseOver,
380
+ onKeyDown: this.handleTriggerKeyDown,
381
+ disabled: trigger.props.disabled || disabled
382
+ }),
383
+ defaultFocusElement: () => {
384
+ var _this$_popover, _this$_popover$_conte;
385
+ return (_this$_popover = this._popover) === null || _this$_popover === void 0 ? void 0 : (_this$_popover$_conte = _this$_popover._contentElement) === null || _this$_popover$_conte === void 0 ? void 0 : _this$_popover$_conte.querySelector('[class$="menuItem"]');
386
+ },
387
+ children: this.renderMenu()
388
+ }) : this.renderMenu();
389
+ }
390
+ }, _Menu.displayName = "Menu", _Menu.componentId = 'Menu', _Menu.allowedProps = allowedProps, _Menu.defaultProps = {
391
+ label: null,
392
+ disabled: false,
393
+ trigger: null,
394
+ placement: 'bottom center',
395
+ defaultShow: false,
396
+ mountNode: null,
397
+ constrain: 'window',
398
+ shouldHideOnSelect: true,
399
+ shouldFocusTriggerOnClose: true,
400
+ withArrow: true,
401
+ offsetX: 0,
402
+ offsetY: 0
403
+ }, _Menu.Item = MenuItem, _Menu.Group = MenuItemGroup, _Menu.Separator = MenuItemSeparator, _Menu.contextType = MenuContext, _Menu)) || _class) || _class);
404
+ export default Menu;
405
+ export { Menu, MenuItem, MenuItemGroup, MenuItemSeparator };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const allowedProps = ['children', 'label', 'disabled', 'trigger', 'placement', 'defaultShow', 'show', 'onToggle', 'onSelect', 'onDismiss', 'onFocus', 'onMouseOver', 'onKeyDown', 'onKeyUp', 'menuRef', 'popoverRef', 'mountNode', 'constrain', 'shouldHideOnSelect', 'shouldFocusTriggerOnClose', 'positionContainerDisplay', 'type', 'id', 'withArrow', 'offsetX', 'offsetY', 'maxHeight', 'renderLabelInfo'];
26
+ export { allowedProps };