@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,262 @@
1
+ var _dec, _dec2, _class, _MenuItem;
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 keycode from 'keycode';
28
+ import { CheckInstUIIcon, ChevronRightInstUIIcon } from '@instructure/ui-icons';
29
+ import { omitProps, getElementType, withDeterministicId, callRenderProp } from '@instructure/ui-react-utils';
30
+ import { createChainedFunction } from '@instructure/ui-utils';
31
+ import { isActiveElement, findDOMNode } from '@instructure/ui-dom-utils';
32
+ import { withStyle } from '@instructure/emotion';
33
+ import { MenuContext } from "../../../utils/v1/MenuContext.js";
34
+ import generateStyle from "./styles.js";
35
+ import { allowedProps } from "./props.js";
36
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
37
+ /**
38
+ ---
39
+ parent: Menu
40
+ id: Menu.Item
41
+ ---
42
+ **/
43
+ let MenuItem = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_MenuItem = class MenuItem extends Component {
44
+ constructor(props) {
45
+ super(props);
46
+ this.labelId = void 0;
47
+ this.ref = null;
48
+ this.handleRef = el => {
49
+ this.ref = el;
50
+ };
51
+ this.handleClick = e => {
52
+ const _this$props = this.props,
53
+ onSelect = _this$props.onSelect,
54
+ onClick = _this$props.onClick,
55
+ disabled = _this$props.disabled,
56
+ value = _this$props.value;
57
+ const selected = !this.selected;
58
+ if (disabled) {
59
+ e.preventDefault();
60
+ return;
61
+ }
62
+ if (typeof this.props.selected === 'undefined') {
63
+ this.setState({
64
+ selected
65
+ });
66
+ }
67
+ if (typeof onSelect === 'function') {
68
+ e.persist();
69
+ onSelect(e, value, selected, this);
70
+ }
71
+ if (typeof onClick === 'function') {
72
+ onClick(e);
73
+ }
74
+ };
75
+ this.handleKeyDown = e => {
76
+ const spaceKey = e.keyCode === keycode.codes.space;
77
+ const enterKey = e.keyCode === keycode.codes.enter;
78
+ if (spaceKey || enterKey) {
79
+ e.preventDefault();
80
+ e.stopPropagation();
81
+ if (enterKey) {
82
+ // handle space key on keyUp for FF
83
+ const refNode = findDOMNode(this.ref);
84
+ refNode.click();
85
+ }
86
+ }
87
+ };
88
+ this.handleKeyUp = e => {
89
+ const spaceKey = e.keyCode === keycode.codes.space;
90
+ const enterKey = e.keyCode === keycode.codes.enter;
91
+ if (spaceKey || enterKey) {
92
+ e.preventDefault();
93
+ e.stopPropagation();
94
+ if (spaceKey) {
95
+ const refNode = findDOMNode(this.ref);
96
+ refNode.click();
97
+ }
98
+ }
99
+ };
100
+ this.handleMouseOver = event => {
101
+ if (!this.focused) {
102
+ this.focus();
103
+ }
104
+ if (typeof this.props.onMouseOver === 'function') {
105
+ this.props.onMouseOver(event, this);
106
+ }
107
+ };
108
+ this.handleMouseEnter = () => {
109
+ this.setState({
110
+ isHovered: true
111
+ });
112
+ };
113
+ this.handleMouseLeave = () => {
114
+ this.setState({
115
+ isHovered: false
116
+ });
117
+ };
118
+ this.handleFocusEvent = () => {
119
+ this.setState({
120
+ isFocused: true
121
+ });
122
+ };
123
+ this.handleBlurEvent = () => {
124
+ this.setState({
125
+ isFocused: false
126
+ });
127
+ };
128
+ this.getIconColor = () => {
129
+ const type = this.props.type;
130
+ if (type === 'flyout') {
131
+ return 'baseColor';
132
+ }
133
+ return this.selected ? 'inverseColor' : 'baseColor';
134
+ };
135
+ const state = {
136
+ isHovered: false,
137
+ isFocused: false
138
+ };
139
+ if (typeof props.selected === 'undefined') {
140
+ state.selected = !!props.defaultSelected;
141
+ }
142
+ this.state = state;
143
+ this.labelId = props.deterministicId('MenuItem__label');
144
+ }
145
+ get _node() {
146
+ return this.ref;
147
+ }
148
+ componentDidMount() {
149
+ var _this$props$makeStyle, _this$props2;
150
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
151
+ const context = this.context;
152
+ if (context && context.registerMenuItem) {
153
+ context.registerMenuItem(this);
154
+ }
155
+ }
156
+ componentDidUpdate() {
157
+ var _this$props$makeStyle2, _this$props3;
158
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
159
+ }
160
+ componentWillUnmount() {
161
+ const context = this.context;
162
+ if (context && context.removeMenuItem) {
163
+ context.removeMenuItem(this);
164
+ }
165
+ }
166
+ get elementType() {
167
+ return getElementType(MenuItem, this.props);
168
+ }
169
+ get role() {
170
+ switch (this.props.type) {
171
+ case 'checkbox':
172
+ return 'menuitemcheckbox';
173
+ case 'radio':
174
+ return 'menuitemradio';
175
+ default:
176
+ return 'menuitem';
177
+ }
178
+ }
179
+ get selected() {
180
+ return typeof this.props.selected === 'undefined' ? this.state.selected : this.props.selected;
181
+ }
182
+ get focused() {
183
+ return isActiveElement(this.ref);
184
+ }
185
+ focus() {
186
+ const refNode = findDOMNode(this.ref);
187
+ refNode.focus();
188
+ }
189
+ renderContent() {
190
+ var _this$props$styles, _this$props$styles2, _this$props$styles3, _this$props$styles4;
191
+ const _this$props4 = this.props,
192
+ children = _this$props4.children,
193
+ type = _this$props4.type,
194
+ renderLabelInfo = _this$props4.renderLabelInfo;
195
+ return _jsxs("span", {
196
+ children: [_jsx("span", {
197
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.label,
198
+ id: this.labelId,
199
+ children: children
200
+ }), (type === 'checkbox' || type === 'radio') && _jsx("span", {
201
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.icon,
202
+ children: this.selected && _jsx(CheckInstUIIcon, {
203
+ size: "md",
204
+ color: this.getIconColor()
205
+ })
206
+ }), type === 'flyout' && _jsx("span", {
207
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.icon,
208
+ children: _jsx(ChevronRightInstUIIcon, {
209
+ size: "md",
210
+ color: this.getIconColor()
211
+ })
212
+ }), renderLabelInfo && _jsx("span", {
213
+ css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.labelInfo,
214
+ children: callRenderProp(renderLabelInfo)
215
+ })]
216
+ });
217
+ }
218
+ render() {
219
+ var _this$props$styles5;
220
+ const _this$props5 = this.props,
221
+ disabled = _this$props5.disabled,
222
+ controls = _this$props5.controls,
223
+ onKeyDown = _this$props5.onKeyDown,
224
+ onKeyUp = _this$props5.onKeyUp,
225
+ onFocus = _this$props5.onFocus,
226
+ onBlur = _this$props5.onBlur,
227
+ type = _this$props5.type,
228
+ href = _this$props5.href,
229
+ target = _this$props5.target;
230
+ const props = omitProps(this.props, MenuItem.allowedProps);
231
+ const ElementType = this.elementType;
232
+ return _jsx(ElementType, {
233
+ tabIndex: -1 // note: tabIndex can be overridden by Menu or MenuItemGroup components
234
+ ,
235
+ ...props,
236
+ href: href,
237
+ target: target,
238
+ role: this.role,
239
+ "aria-labelledby": this.labelId,
240
+ "aria-disabled": disabled ? 'true' : void 0,
241
+ "aria-controls": controls,
242
+ "aria-checked": type === 'checkbox' || type === 'radio' ? this.selected ? 'true' : 'false' : void 0,
243
+ onClick: this.handleClick,
244
+ onKeyUp: createChainedFunction(onKeyUp, this.handleKeyUp),
245
+ onKeyDown: createChainedFunction(onKeyDown, this.handleKeyDown),
246
+ ref: this.handleRef,
247
+ css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.menuItem,
248
+ onMouseOver: this.handleMouseOver,
249
+ onMouseEnter: this.handleMouseEnter,
250
+ onMouseLeave: this.handleMouseLeave,
251
+ onFocus: createChainedFunction(onFocus, this.handleFocusEvent),
252
+ onBlur: createChainedFunction(onBlur, this.handleBlurEvent),
253
+ "data-cid": "MenuItem",
254
+ children: this.renderContent()
255
+ });
256
+ }
257
+ }, _MenuItem.displayName = "MenuItem", _MenuItem.componentId = 'Menu.Item', _MenuItem.allowedProps = allowedProps, _MenuItem.defaultProps = {
258
+ type: 'button',
259
+ disabled: false
260
+ }, _MenuItem.contextType = MenuContext, _MenuItem)) || _class) || _class);
261
+ export default MenuItem;
262
+ export { MenuItem };
@@ -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', 'defaultSelected', 'selected', 'onSelect', 'onClick', 'onKeyDown', 'onKeyUp', 'onMouseOver', 'controls', 'disabled', 'as', 'type', 'value', 'href', 'target', 'renderLabelInfo'];
26
+ export { allowedProps };
@@ -0,0 +1,146 @@
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, props) => {
36
+ const type = props.type,
37
+ disabled = props.disabled,
38
+ selected = props.selected;
39
+ const isRadioOrCheckbox = type === 'checkbox' || type === 'radio';
40
+ const flyoutIconStyles = type === 'flyout' ? {
41
+ insetInlineStart: 'auto',
42
+ insetInlineEnd: componentTheme.iconPadding
43
+ } : {};
44
+ const roleStyles = isRadioOrCheckbox ? {
45
+ paddingInlineEnd: componentTheme.labelPadding
46
+ } : {};
47
+ const roleIconStyles = isRadioOrCheckbox ? {
48
+ insetInlineStart: 'auto',
49
+ insetInlineEnd: componentTheme.iconPadding
50
+ } : {};
51
+ const disabledStyles = disabled ? {
52
+ cursor: 'not-allowed',
53
+ pointerEvents: 'none',
54
+ opacity: 0.5
55
+ } : {};
56
+ const selectedStyles = selected ? {
57
+ background: componentTheme.activeBackground,
58
+ '[class*="menuItem__label"]': {
59
+ color: componentTheme.activeLabelColor
60
+ }
61
+ } : {};
62
+ const selectedHighlightedStyles = selected ? {
63
+ background: componentTheme.selectedHighlightedBackground
64
+ } : {
65
+ background: componentTheme.highlightedBackground,
66
+ '[class*="menuItem__label"]': {
67
+ color: componentTheme.highlightedLabelColor
68
+ },
69
+ '[class*="menuItem__labelInfo"]': {
70
+ color: componentTheme.highlightedLabelInfoColor
71
+ }
72
+ };
73
+ const linkStyles = {
74
+ textDecoration: 'none'
75
+ };
76
+ return {
77
+ menuItem: {
78
+ label: 'menuItem',
79
+ position: 'relative',
80
+ border: 'none',
81
+ outline: 'none',
82
+ padding: `${componentTheme.paddingVertical} ${componentTheme.paddingHorizontal}`,
83
+ margin: '0',
84
+ width: '100%',
85
+ borderRadius: 'initial',
86
+ boxSizing: 'border-box',
87
+ textAlign: 'start',
88
+ cursor: 'pointer',
89
+ userSelect: 'none',
90
+ fontFamily: componentTheme.fontFamily,
91
+ fontWeight: componentTheme.fontWeight,
92
+ lineHeight: componentTheme.lineHeight,
93
+ fontSize: componentTheme.fontSize,
94
+ background: componentTheme.background,
95
+ // Changing the following to display: flex; causes a VO
96
+ // bug where items with role menuitem, menuitemcheckbox
97
+ // and menuitemradio are selected twice with control+
98
+ // option+space. So we set the display to block.
99
+ display: 'block',
100
+ textDecoration: 'none',
101
+ ...roleStyles,
102
+ '&:focus, &:active, &:hover': {
103
+ ...selectedHighlightedStyles
104
+ },
105
+ //removes extra ff button spacing
106
+ '&::-moz-focus-inner': {
107
+ padding: '0',
108
+ margin: '0',
109
+ border: '0'
110
+ },
111
+ ...disabledStyles,
112
+ ...selectedStyles,
113
+ // NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
114
+ '&:is(a)': {
115
+ '&, &:link, &:visited, &:active, &:hover, &:focus': linkStyles
116
+ },
117
+ '&:-webkit-any(a)': {
118
+ '&, &:link, &:visited, &:active, &:hover, &:focus': linkStyles
119
+ }
120
+ },
121
+ icon: {
122
+ label: 'menuItem__icon',
123
+ position: 'absolute',
124
+ display: 'flex',
125
+ alignItems: 'center',
126
+ top: '0',
127
+ width: '1em',
128
+ height: '100%',
129
+ ...roleIconStyles,
130
+ ...flyoutIconStyles
131
+ },
132
+ labelInfo: {
133
+ label: 'menuItem__labelInfo',
134
+ height: '100%',
135
+ float: 'right',
136
+ clear: 'right',
137
+ paddingRight: '1.75rem',
138
+ color: componentTheme.labelInfoColor
139
+ },
140
+ label: {
141
+ label: 'menuItem__label',
142
+ color: componentTheme.labelColor
143
+ }
144
+ };
145
+ };
146
+ export default generateStyle;
@@ -0,0 +1,175 @@
1
+ var _dec, _dec2, _class, _MenuItemGroup;
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 { withStyle } from '@instructure/emotion';
28
+ import { omitProps, safeCloneElement, matchComponentTypes, withDeterministicId } from '@instructure/ui-react-utils';
29
+ import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
30
+ import { MenuItem } from "../MenuItem/index.js";
31
+ import generateStyle from "./styles.js";
32
+ import { allowedProps } from "./props.js";
33
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
34
+ /**
35
+ ---
36
+ parent: Menu
37
+ id: Menu.Group
38
+ ---
39
+ **/
40
+ let MenuItemGroup = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_MenuItemGroup = class MenuItemGroup extends Component {
41
+ constructor(props) {
42
+ super(props);
43
+ this.ref = null;
44
+ this.handleRef = el => {
45
+ this.ref = el;
46
+ };
47
+ this.handleSelect = (e, value, selected, item) => {
48
+ if (this.props.disabled) {
49
+ e.preventDefault();
50
+ return;
51
+ }
52
+ if (this.props.selected) {
53
+ this.updateSelected(e, value, this.props.selected, selected, item);
54
+ } else {
55
+ this.setState(state => {
56
+ return {
57
+ selected: this.updateSelected(e, value, state.selected, selected, item)
58
+ };
59
+ });
60
+ }
61
+ };
62
+ this.updateSelected = (e, value, items, selected, item) => {
63
+ const allowMultiple = this.props.allowMultiple;
64
+ let updated = allowMultiple ? [...items] : [];
65
+ const location = updated.indexOf(value);
66
+ if (selected === true && location < 0) {
67
+ updated.push(value);
68
+ } else if (selected === false && location !== -1) {
69
+ updated.splice(location, 1);
70
+ } else if (!allowMultiple && updated.length < 1) {
71
+ // don't allow nothing selected if it's not allowMultiple/checkbox
72
+ updated = [...items];
73
+ }
74
+ if (typeof this.props.onSelect === 'function') {
75
+ this.props.onSelect(e, updated, selected, item);
76
+ }
77
+ return updated;
78
+ };
79
+ if (typeof props.selected === 'undefined') {
80
+ this.state = {
81
+ selected: this.selectedFromChildren(props) || props.defaultSelected
82
+ };
83
+ }
84
+ }
85
+ componentDidMount() {
86
+ var _this$props$makeStyle, _this$props;
87
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
88
+ }
89
+ componentDidUpdate() {
90
+ var _this$props$makeStyle2, _this$props2;
91
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
92
+ }
93
+ selectedFromChildren(props) {
94
+ const children = props.children,
95
+ allowMultiple = props.allowMultiple;
96
+ const selected = [];
97
+ const items = Children.toArray(children).filter(child => {
98
+ return matchComponentTypes(child, [MenuItem]);
99
+ });
100
+ items.forEach((item, index) => {
101
+ if ((selected.length === 0 || allowMultiple) && (item.props.selected || item.props.defaultSelected)) {
102
+ selected.push(item.props.value || index);
103
+ }
104
+ });
105
+ return selected.length > 0 ? selected : null;
106
+ }
107
+ get selected() {
108
+ if (typeof this.props.selected === 'undefined' && typeof this.state.selected === 'undefined') {
109
+ return [];
110
+ } else {
111
+ return typeof this.props.selected === 'undefined' ? [...this.state.selected] : [...this.props.selected];
112
+ }
113
+ }
114
+ renderLabel() {
115
+ var _this$props$styles;
116
+ const label = this.props.label;
117
+ return hasVisibleChildren(label) ? _jsx("span", {
118
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.label,
119
+ children: label
120
+ }) : label;
121
+ }
122
+ renderChildren() {
123
+ const _this$props3 = this.props,
124
+ disabled = _this$props3.disabled,
125
+ controls = _this$props3.controls,
126
+ allowMultiple = _this$props3.allowMultiple,
127
+ isTabbable = _this$props3.isTabbable,
128
+ onMouseOver = _this$props3.onMouseOver;
129
+ const children = this.props.children;
130
+ let index = -1;
131
+ return Children.map(children, child => {
132
+ if (matchComponentTypes(child, [MenuItem])) {
133
+ ++index;
134
+ const value = child.props.value || index;
135
+ return safeCloneElement(child, {
136
+ tabIndex: isTabbable && index === 0 ? 0 : -1,
137
+ controls,
138
+ value,
139
+ children: child.props.children,
140
+ type: allowMultiple ? 'checkbox' : 'radio',
141
+ ref: this.props.itemRef,
142
+ disabled: disabled || child.props.disabled,
143
+ selected: this.selected.indexOf(value) > -1,
144
+ onSelect: this.handleSelect,
145
+ onMouseOver
146
+ });
147
+ } else {
148
+ return child;
149
+ }
150
+ });
151
+ }
152
+ render() {
153
+ var _this$props$styles2, _this$props$styles3;
154
+ const props = omitProps(this.props, MenuItemGroup.allowedProps);
155
+ return _jsxs("span", {
156
+ ...props,
157
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.menuItemGroup,
158
+ ref: this.handleRef,
159
+ "data-cid": "MenuItemGroup",
160
+ children: [this.renderLabel(), _jsx("div", {
161
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.items,
162
+ "aria-disabled": this.props.disabled ? 'true' : void 0,
163
+ children: this.renderChildren()
164
+ })]
165
+ });
166
+ }
167
+ }, _MenuItemGroup.displayName = "MenuItemGroup", _MenuItemGroup.componentId = 'Menu.Group', _MenuItemGroup.allowedProps = allowedProps, _MenuItemGroup.defaultProps = {
168
+ disabled: false,
169
+ children: null,
170
+ isTabbable: false,
171
+ allowMultiple: false,
172
+ defaultSelected: []
173
+ }, _MenuItemGroup)) || _class) || _class);
174
+ export default MenuItemGroup;
175
+ export { MenuItemGroup };
@@ -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 = ['label', 'allowMultiple', 'children', 'selected', 'defaultSelected', 'onSelect', 'onMouseOver', 'controls', 'itemRef', 'disabled', 'isTabbable'];
26
+ export { allowedProps };