@instructure/ui-menu 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -41,7 +41,7 @@ var _styles = _interopRequireDefault(require("./styles"));
41
41
  var _theme = _interopRequireDefault(require("./theme"));
42
42
  var _props = require("./props");
43
43
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
44
- var _dec, _dec2, _class, _Menu;
44
+ var _dec, _dec2, _class;
45
45
  /*
46
46
  * The MIT License (MIT)
47
47
  *
@@ -70,158 +70,178 @@ var _dec, _dec2, _class, _Menu;
70
70
  category: components
71
71
  ---
72
72
  **/
73
- let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_Menu = class Menu extends _react.Component {
73
+ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = class Menu extends _react.Component {
74
+ static displayName = "Menu";
75
+ static componentId = 'Menu';
76
+ static allowedProps = _props.allowedProps;
77
+ static defaultProps = {
78
+ label: null,
79
+ disabled: false,
80
+ trigger: null,
81
+ placement: 'bottom center',
82
+ defaultShow: false,
83
+ mountNode: null,
84
+ constrain: 'window',
85
+ shouldHideOnSelect: true,
86
+ shouldFocusTriggerOnClose: true,
87
+ withArrow: true,
88
+ offsetX: 0,
89
+ offsetY: 0
90
+ };
91
+ static Item = _MenuItem.MenuItem;
92
+ static Group = _MenuItemGroup.MenuItemGroup;
93
+ static Separator = _MenuItemSeparator.MenuItemSeparator;
94
+ state = {
95
+ hasFocus: false
96
+ };
97
+ _rootNode = null;
98
+ _menuItems = [];
99
+ _popover = null;
100
+ _trigger = null;
101
+ _menu = null;
102
+ _labelId = this.props.deterministicId('Menu__label');
103
+ _activeSubMenu;
104
+ _id;
105
+ ref = null;
106
+ handleRef = el => {
107
+ const {
108
+ menuRef
109
+ } = this.props;
110
+ this._menu = el;
111
+ if (typeof menuRef === 'function') {
112
+ menuRef(el);
113
+ }
114
+ // If there is no trigger `<ul>` is the ref, otherwise the trigger
115
+ if (!this.props.trigger) {
116
+ this.ref = el;
117
+ }
118
+ };
74
119
  constructor(props) {
75
120
  super(props);
76
- this.state = {
77
- hasFocus: false
78
- };
79
- this._rootNode = null;
80
- this._menuItems = [];
81
- this._popover = null;
82
- this._trigger = null;
83
- this._menu = null;
84
- this._labelId = this.props.deterministicId('Menu__label');
85
- this._activeSubMenu = void 0;
86
- this._id = void 0;
87
- this.ref = null;
88
- this.handleRef = el => {
89
- const menuRef = this.props.menuRef;
90
- this._menu = el;
91
- if (typeof menuRef === 'function') {
92
- menuRef(el);
93
- }
94
- // If there is no trigger `<ul>` is the ref, otherwise the trigger
95
- if (!this.props.trigger) {
96
- this.ref = el;
97
- }
98
- };
99
- this.registerMenuItem = item => {
100
- this._menuItems.push(item);
101
- };
102
- this.removeMenuItem = item => {
103
- const index = this.getMenuItemIndex(item);
104
- (0, _console.logError)(index >= 0, '[Menu] Could not find registered menu item.');
105
- if (index >= 0) {
106
- this._menuItems.splice(index, 1);
107
- }
108
- };
109
- this.getMenuItemIndex = item => {
110
- return this._menuItems.findIndex(i => i === item);
111
- };
112
- this.handleTriggerKeyDown = event => {
113
- if (this.props.type === 'flyout' && event.keyCode === _keycode.default.codes.right) {
114
- event.persist();
115
- this.show(event);
116
- }
117
- };
118
- this.handleTriggerMouseOver = event => {
119
- if (this.props.type === 'flyout') {
120
- this.show(event);
121
- }
122
- };
123
- this.handleToggle = shown => {
124
- if (typeof this.props.onToggle === 'function') {
125
- this.props.onToggle(shown, this);
126
- }
127
- };
128
- this.handleMenuKeyDown = event => {
129
- const key = event && event.keyCode;
130
- const _keycode$codes = _keycode.default.codes,
131
- down = _keycode$codes.down,
132
- up = _keycode$codes.up,
133
- tab = _keycode$codes.tab,
134
- left = _keycode$codes.left;
135
- const pgdn = _keycode.default.codes['page down'];
136
- const pgup = _keycode.default.codes['page up'];
137
- if (key === down || key === pgdn) {
138
- event.preventDefault();
139
- event.stopPropagation();
140
- this.moveFocus(1);
141
- this.hideActiveSubMenu(event);
142
- } else if (key === up || key === pgup) {
143
- event.preventDefault();
144
- event.stopPropagation();
145
- this.moveFocus(-1);
146
- this.hideActiveSubMenu(event);
147
- } else if (key === tab || key === left) {
148
- event.persist();
149
- this.hide(event);
150
- }
151
- if (typeof this.props.onKeyDown === 'function') {
152
- this.props.onKeyDown(event);
153
- }
154
- };
155
- this.handleMenuItemSelect = (event, value, selected, item) => {
156
- if (this.props.shouldHideOnSelect) {
157
- this.hide(event);
158
- }
159
- if (typeof this.props.onSelect === 'function') {
160
- this.props.onSelect(event, value, selected, item);
161
- }
162
- };
163
- this.handleMenuItemFocus = () => {
164
- this.setState({
165
- hasFocus: true
166
- });
167
- };
168
- this.handleMenuItemBlur = () => {
169
- this.setState({
170
- hasFocus: this.focusedIndex >= 0
171
- });
172
- };
173
- this.handleMenuItemMouseOver = (event, menuItem) => {
174
- if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
175
- this.hideActiveSubMenu(event);
176
- }
177
- };
178
- this.hideActiveSubMenu = event => {
179
- if (this._activeSubMenu) {
180
- this._activeSubMenu.hide(event);
181
- this._activeSubMenu = null;
182
- }
183
- };
184
- this.handleSubMenuToggle = (shown, subMenu) => {
185
- if (shown) {
186
- this._activeSubMenu = subMenu;
187
- }
188
- };
189
- this.handleSubMenuDismiss = (event, documentClick) => {
190
- if (event && event.keyCode === _keycode.default.codes.tab || documentClick) {
191
- this.hide(event);
192
- }
193
- };
194
- this.hide = event => {
195
- if (this._popover) {
196
- this._popover.hide(event);
197
- }
198
- };
199
- this.show = event => {
200
- if (this._popover) {
201
- this._popover.show(event);
202
- }
203
- };
204
121
  this._id = this.props.id || props.deterministicId();
205
122
  }
206
123
  componentDidMount() {
207
- var _this$props$makeStyle, _this$props;
208
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
124
+ this.props.makeStyles?.();
209
125
  }
210
126
  componentDidUpdate() {
211
- var _this$props$makeStyle2, _this$props2;
212
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
127
+ this.props.makeStyles?.();
213
128
  }
129
+ static contextType = _MenuContext.MenuContext;
130
+ registerMenuItem = item => {
131
+ this._menuItems.push(item);
132
+ };
133
+ removeMenuItem = item => {
134
+ const index = this.getMenuItemIndex(item);
135
+ (0, _console.logError)(index >= 0, '[Menu] Could not find registered menu item.');
136
+ if (index >= 0) {
137
+ this._menuItems.splice(index, 1);
138
+ }
139
+ };
214
140
  get menuItems() {
215
141
  return this._menuItems;
216
142
  }
143
+ getMenuItemIndex = item => {
144
+ return this._menuItems.findIndex(i => i === item);
145
+ };
146
+ handleTriggerKeyDown = event => {
147
+ if (this.props.type === 'flyout' && event.keyCode === _keycode.default.codes.right) {
148
+ event.persist();
149
+ this.show(event);
150
+ }
151
+ };
152
+ handleTriggerMouseOver = event => {
153
+ if (this.props.type === 'flyout') {
154
+ this.show(event);
155
+ }
156
+ };
157
+ handleToggle = shown => {
158
+ if (typeof this.props.onToggle === 'function') {
159
+ this.props.onToggle(shown, this);
160
+ }
161
+ };
162
+ handleMenuKeyDown = event => {
163
+ const key = event && event.keyCode;
164
+ const {
165
+ down,
166
+ up,
167
+ tab,
168
+ left
169
+ } = _keycode.default.codes;
170
+ const pgdn = _keycode.default.codes['page down'];
171
+ const pgup = _keycode.default.codes['page up'];
172
+ if (key === down || key === pgdn) {
173
+ event.preventDefault();
174
+ event.stopPropagation();
175
+ this.moveFocus(1);
176
+ this.hideActiveSubMenu(event);
177
+ } else if (key === up || key === pgup) {
178
+ event.preventDefault();
179
+ event.stopPropagation();
180
+ this.moveFocus(-1);
181
+ this.hideActiveSubMenu(event);
182
+ } else if (key === tab || key === left) {
183
+ event.persist();
184
+ this.hide(event);
185
+ }
186
+ if (typeof this.props.onKeyDown === 'function') {
187
+ this.props.onKeyDown(event);
188
+ }
189
+ };
190
+ handleMenuItemSelect = (event, value, selected, item) => {
191
+ if (this.props.shouldHideOnSelect) {
192
+ this.hide(event);
193
+ }
194
+ if (typeof this.props.onSelect === 'function') {
195
+ this.props.onSelect(event, value, selected, item);
196
+ }
197
+ };
198
+ handleMenuItemFocus = () => {
199
+ this.setState({
200
+ hasFocus: true
201
+ });
202
+ };
203
+ handleMenuItemBlur = () => {
204
+ this.setState({
205
+ hasFocus: this.focusedIndex >= 0
206
+ });
207
+ };
208
+ handleMenuItemMouseOver = (event, menuItem) => {
209
+ if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
210
+ this.hideActiveSubMenu(event);
211
+ }
212
+ };
213
+ hideActiveSubMenu = event => {
214
+ if (this._activeSubMenu) {
215
+ this._activeSubMenu.hide(event);
216
+ this._activeSubMenu = null;
217
+ }
218
+ };
219
+ handleSubMenuToggle = (shown, subMenu) => {
220
+ if (shown) {
221
+ this._activeSubMenu = subMenu;
222
+ }
223
+ };
224
+ handleSubMenuDismiss = (event, documentClick) => {
225
+ if (event && event.keyCode === _keycode.default.codes.tab || documentClick) {
226
+ this.hide(event);
227
+ }
228
+ };
229
+ hide = event => {
230
+ if (this._popover) {
231
+ this._popover.hide(event);
232
+ }
233
+ };
234
+ show = event => {
235
+ if (this._popover) {
236
+ this._popover.show(event);
237
+ }
238
+ };
217
239
  focus() {
218
240
  if (this.shown) {
219
- var _this$_menu;
220
- (0, _console.logError)(!!((_this$_menu = this._menu) !== null && _this$_menu !== void 0 && _this$_menu.focus), '[Menu] Could not focus the menu.');
241
+ (0, _console.logError)(!!this._menu?.focus, '[Menu] Could not focus the menu.');
221
242
  this._menu.focus();
222
243
  } else {
223
- var _this$_trigger;
224
- (0, _console.logError)(!!((_this$_trigger = this._trigger) !== null && _this$_trigger !== void 0 && _this$_trigger.focus), '[Menu] Could not focus the trigger.');
244
+ (0, _console.logError)(!!this._trigger?.focus, '[Menu] Could not focus the trigger.');
225
245
  this._trigger.focus();
226
246
  }
227
247
  }
@@ -251,9 +271,10 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
251
271
  return this._popover ? this._popover.shown : true;
252
272
  }
253
273
  renderChildren() {
254
- const _this$props3 = this.props,
255
- children = _this$props3.children,
256
- disabled = _this$props3.disabled;
274
+ const {
275
+ children,
276
+ disabled
277
+ } = this.props;
257
278
  let count = 0;
258
279
  return _react.Children.map(children, child => {
259
280
  if (!(0, _matchComponentTypes.matchComponentTypes)(child, ['MenuItemSeparator', 'MenuItem', 'MenuItemGroup', 'Menu'])) {
@@ -319,12 +340,12 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
319
340
  });
320
341
  }
321
342
  renderMenu() {
322
- var _this$props$styles;
323
- const _this$props4 = this.props,
324
- disabled = _this$props4.disabled,
325
- label = _this$props4.label,
326
- trigger = _this$props4.trigger,
327
- onKeyUp = _this$props4.onKeyUp;
343
+ const {
344
+ disabled,
345
+ label,
346
+ trigger,
347
+ onKeyUp
348
+ } = this.props;
328
349
  const labelledBy = this.props['aria-labelledby'];
329
350
  const controls = this.props['aria-controls'];
330
351
  return (0, _jsxRuntime.jsx)(_MenuContext.MenuContext.Provider, {
@@ -336,10 +357,10 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
336
357
  role: "menu",
337
358
  "aria-label": label,
338
359
  tabIndex: 0,
339
- css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.menu,
340
- "aria-labelledby": labelledBy || (trigger ? this._labelId : void 0),
360
+ css: this.props.styles?.menu,
361
+ "aria-labelledby": labelledBy || (trigger ? this._labelId : undefined),
341
362
  "aria-controls": controls,
342
- "aria-disabled": disabled ? 'true' : void 0,
363
+ "aria-disabled": disabled ? 'true' : undefined,
343
364
  onKeyDown: this.handleMenuKeyDown,
344
365
  onKeyUp: onKeyUp,
345
366
  ref: this.handleRef,
@@ -349,21 +370,22 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
349
370
  });
350
371
  }
351
372
  render() {
352
- const _this$props5 = this.props,
353
- show = _this$props5.show,
354
- defaultShow = _this$props5.defaultShow,
355
- placement = _this$props5.placement,
356
- withArrow = _this$props5.withArrow,
357
- trigger = _this$props5.trigger,
358
- mountNode = _this$props5.mountNode,
359
- popoverRef = _this$props5.popoverRef,
360
- disabled = _this$props5.disabled,
361
- onDismiss = _this$props5.onDismiss,
362
- onFocus = _this$props5.onFocus,
363
- onMouseOver = _this$props5.onMouseOver,
364
- positionContainerDisplay = _this$props5.positionContainerDisplay,
365
- offsetX = _this$props5.offsetX,
366
- offsetY = _this$props5.offsetY;
373
+ const {
374
+ show,
375
+ defaultShow,
376
+ placement,
377
+ withArrow,
378
+ trigger,
379
+ mountNode,
380
+ popoverRef,
381
+ disabled,
382
+ onDismiss,
383
+ onFocus,
384
+ onMouseOver,
385
+ positionContainerDisplay,
386
+ offsetX,
387
+ offsetY
388
+ } = this.props;
367
389
  return trigger ? (0, _jsxRuntime.jsx)(_v11_.Popover, {
368
390
  "data-cid": "Menu",
369
391
  isShowingContent: show,
@@ -408,25 +430,9 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
408
430
  onKeyDown: this.handleTriggerKeyDown,
409
431
  disabled: trigger.props.disabled || disabled
410
432
  }),
411
- defaultFocusElement: () => {
412
- var _this$_popover, _this$_popover$_conte;
413
- 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"]');
414
- },
433
+ defaultFocusElement: () => this._popover?._contentElement?.querySelector('[class$="menuItem"]'),
415
434
  children: this.renderMenu()
416
435
  }) : this.renderMenu();
417
436
  }
418
- }, _Menu.displayName = "Menu", _Menu.componentId = 'Menu', _Menu.allowedProps = _props.allowedProps, _Menu.defaultProps = {
419
- label: null,
420
- disabled: false,
421
- trigger: null,
422
- placement: 'bottom center',
423
- defaultShow: false,
424
- mountNode: null,
425
- constrain: 'window',
426
- shouldHideOnSelect: true,
427
- shouldFocusTriggerOnClose: true,
428
- withArrow: true,
429
- offsetX: 0,
430
- offsetY: 0
431
- }, _Menu.Item = _MenuItem.MenuItem, _Menu.Group = _MenuItemGroup.MenuItemGroup, _Menu.Separator = _MenuItemSeparator.MenuItemSeparator, _Menu.contextType = _MenuContext.MenuContext, _Menu)) || _class) || _class);
437
+ }) || _class) || _class);
432
438
  var _default = exports.default = Menu;
@@ -34,19 +34,20 @@ exports.default = void 0;
34
34
  * @return {Object} The final theme object with the overrides and component variables
35
35
  */
36
36
  const generateComponentTheme = theme => {
37
- var _colors$contrasts, _colors$contrasts2;
38
- const colors = theme.colors,
39
- breakpoints = theme.breakpoints,
40
- borders = theme.borders;
37
+ const {
38
+ colors,
39
+ breakpoints,
40
+ borders
41
+ } = theme;
41
42
  const componentVariables = {
42
- minWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.xxSmall,
43
- maxWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.xSmall,
44
- background: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.white1010,
45
- borderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusMedium,
46
- focusBorderStyle: borders === null || borders === void 0 ? void 0 : borders.style,
47
- focusBorderWidth: borders === null || borders === void 0 ? void 0 : borders.widthMedium,
48
- focusBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.blue4570,
49
- focusBorderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusMedium
43
+ minWidth: breakpoints?.xxSmall,
44
+ maxWidth: breakpoints?.xSmall,
45
+ background: colors?.contrasts?.white1010,
46
+ borderRadius: borders?.radiusMedium,
47
+ focusBorderStyle: borders?.style,
48
+ focusBorderWidth: borders?.widthMedium,
49
+ focusBorderColor: colors?.contrasts?.blue4570,
50
+ focusBorderRadius: borders?.radiusMedium
50
51
  };
51
52
  return {
52
53
  ...componentVariables