@instructure/ui-menu 8.25.1-snapshot-7 → 8.25.1-snapshot-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.
package/es/Menu/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var _dec, _dec2, _dec3, _class, _class2;
1
+ var _dec, _dec2, _dec3, _class;
2
2
 
3
3
  /*
4
4
  * The MIT License (MIT)
@@ -47,162 +47,56 @@ category: components
47
47
  ---
48
48
  @tsProps
49
49
  **/
50
- let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class Menu extends Component {
50
+ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = class Menu extends Component {
51
+ static displayName = "Menu";
52
+ static componentId = 'Menu';
53
+ static propTypes = propTypes;
54
+ static allowedProps = allowedProps;
55
+ static defaultProps = {
56
+ label: null,
57
+ disabled: false,
58
+ trigger: null,
59
+ placement: 'bottom center',
60
+ defaultShow: false,
61
+ mountNode: null,
62
+ constrain: 'window',
63
+ shouldHideOnSelect: true,
64
+ shouldFocusTriggerOnClose: true,
65
+ withArrow: true,
66
+ offsetX: 0,
67
+ offsetY: 0
68
+ };
69
+ static Item = MenuItem;
70
+ static Group = MenuItemGroup;
71
+ static Separator = MenuItemSeparator;
72
+ state = {
73
+ hasFocus: false
74
+ };
75
+ _rootNode = null;
76
+ _menuItems = [];
77
+ _popover = null;
78
+ _trigger = null;
79
+ _menu = null;
80
+ _labelId = this.props.deterministicId('Menu__label');
81
+ _activeSubMenu;
82
+ _id;
83
+ ref = null;
84
+ handleRef = el => {
85
+ const menuRef = this.props.menuRef;
86
+ this._menu = el;
87
+
88
+ if (typeof menuRef === 'function') {
89
+ menuRef(el);
90
+ } // If there is no trigger `<ul>` is the ref, otherwise the trigger
91
+
92
+
93
+ if (!this.props.trigger) {
94
+ this.ref = el;
95
+ }
96
+ };
97
+
51
98
  constructor(props) {
52
99
  super(props);
53
- this.state = {
54
- hasFocus: false
55
- };
56
- this._rootNode = null;
57
- this._menuItems = [];
58
- this._popover = null;
59
- this._trigger = null;
60
- this._menu = null;
61
- this._labelId = this.props.deterministicId('Menu__label');
62
- this._activeSubMenu = void 0;
63
- this._id = void 0;
64
- this.ref = null;
65
-
66
- this.handleRef = el => {
67
- const menuRef = this.props.menuRef;
68
- this._menu = el;
69
-
70
- if (typeof menuRef === 'function') {
71
- menuRef(el);
72
- } // If there is no trigger `<ul>` is the ref, otherwise the trigger
73
-
74
-
75
- if (!this.props.trigger) {
76
- this.ref = el;
77
- }
78
- };
79
-
80
- this.registerMenuItem = item => {
81
- this._menuItems.push(item);
82
- };
83
-
84
- this.removeMenuItem = item => {
85
- const index = this.getMenuItemIndex(item);
86
- error(index >= 0, '[Menu] Could not find registered menu item.');
87
-
88
- if (index >= 0) {
89
- this._menuItems.splice(index, 1);
90
- }
91
- };
92
-
93
- this.getMenuItemIndex = item => {
94
- return this._menuItems.findIndex(i => i === item);
95
- };
96
-
97
- this.handleTriggerKeyDown = event => {
98
- if (this.props.type === 'flyout' && event.keyCode === keycode.codes.right) {
99
- event.persist();
100
- this.show(event);
101
- }
102
- };
103
-
104
- this.handleTriggerMouseOver = event => {
105
- if (this.props.type === 'flyout') {
106
- this.show(event);
107
- }
108
- };
109
-
110
- this.handleToggle = shown => {
111
- if (typeof this.props.onToggle === 'function') {
112
- this.props.onToggle(shown, this);
113
- }
114
- };
115
-
116
- this.handleMenuKeyDown = event => {
117
- const key = event && event.keyCode;
118
- const _keycode$codes = keycode.codes,
119
- down = _keycode$codes.down,
120
- up = _keycode$codes.up,
121
- tab = _keycode$codes.tab,
122
- left = _keycode$codes.left;
123
- const pgdn = keycode.codes['page down'];
124
- const pgup = keycode.codes['page up'];
125
-
126
- if (key === down || key === pgdn) {
127
- event.preventDefault();
128
- event.stopPropagation();
129
- this.moveFocus(1);
130
- this.hideActiveSubMenu(event);
131
- } else if (key === up || key === pgup) {
132
- event.preventDefault();
133
- event.stopPropagation();
134
- this.moveFocus(-1);
135
- this.hideActiveSubMenu(event);
136
- } else if (key === tab || key === left) {
137
- event.persist();
138
- this.hide(event);
139
- }
140
-
141
- if (typeof this.props.onKeyDown === 'function') {
142
- this.props.onKeyDown(event);
143
- }
144
- };
145
-
146
- this.handleMenuItemSelect = (event, value, selected, item) => {
147
- if (this.props.shouldHideOnSelect) {
148
- this.hide(event);
149
- }
150
-
151
- if (typeof this.props.onSelect === 'function') {
152
- this.props.onSelect(event, value, selected, item);
153
- }
154
- };
155
-
156
- this.handleMenuItemFocus = () => {
157
- this.setState({
158
- hasFocus: true
159
- });
160
- };
161
-
162
- this.handleMenuItemBlur = () => {
163
- this.setState({
164
- hasFocus: this.focusedIndex >= 0
165
- });
166
- };
167
-
168
- this.handleMenuItemMouseOver = (event, menuItem) => {
169
- if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
170
- this.hideActiveSubMenu(event);
171
- }
172
- };
173
-
174
- this.hideActiveSubMenu = event => {
175
- if (this._activeSubMenu) {
176
- this._activeSubMenu.hide(event);
177
-
178
- this._activeSubMenu = null;
179
- }
180
- };
181
-
182
- this.handleSubMenuToggle = (shown, subMenu) => {
183
- if (shown) {
184
- this._activeSubMenu = subMenu;
185
- }
186
- };
187
-
188
- this.handleSubMenuDismiss = (event, documentClick) => {
189
- if (event && event.keyCode === keycode.codes.tab || documentClick) {
190
- this.hide(event);
191
- }
192
- };
193
-
194
- this.hide = event => {
195
- if (this._popover) {
196
- this._popover.hide(event);
197
- }
198
- };
199
-
200
- this.show = event => {
201
- if (this._popover) {
202
- this._popover.show(event);
203
- }
204
- };
205
-
206
100
  this._id = this.props.id || props.deterministicId();
207
101
  }
208
102
 
@@ -218,10 +112,123 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
218
112
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
219
113
  }
220
114
 
115
+ static contextType = MenuContext;
116
+ registerMenuItem = item => {
117
+ this._menuItems.push(item);
118
+ };
119
+ removeMenuItem = item => {
120
+ const index = this.getMenuItemIndex(item);
121
+ error(index >= 0, '[Menu] Could not find registered menu item.');
122
+
123
+ if (index >= 0) {
124
+ this._menuItems.splice(index, 1);
125
+ }
126
+ };
127
+
221
128
  get menuItems() {
222
129
  return this._menuItems;
223
130
  }
224
131
 
132
+ getMenuItemIndex = item => {
133
+ return this._menuItems.findIndex(i => i === item);
134
+ };
135
+ handleTriggerKeyDown = event => {
136
+ if (this.props.type === 'flyout' && event.keyCode === keycode.codes.right) {
137
+ event.persist();
138
+ this.show(event);
139
+ }
140
+ };
141
+ handleTriggerMouseOver = event => {
142
+ if (this.props.type === 'flyout') {
143
+ this.show(event);
144
+ }
145
+ };
146
+ handleToggle = shown => {
147
+ if (typeof this.props.onToggle === 'function') {
148
+ this.props.onToggle(shown, this);
149
+ }
150
+ };
151
+ handleMenuKeyDown = event => {
152
+ const key = event && event.keyCode;
153
+ const _keycode$codes = keycode.codes,
154
+ down = _keycode$codes.down,
155
+ up = _keycode$codes.up,
156
+ tab = _keycode$codes.tab,
157
+ left = _keycode$codes.left;
158
+ const pgdn = keycode.codes['page down'];
159
+ const pgup = keycode.codes['page up'];
160
+
161
+ if (key === down || key === pgdn) {
162
+ event.preventDefault();
163
+ event.stopPropagation();
164
+ this.moveFocus(1);
165
+ this.hideActiveSubMenu(event);
166
+ } else if (key === up || key === pgup) {
167
+ event.preventDefault();
168
+ event.stopPropagation();
169
+ this.moveFocus(-1);
170
+ this.hideActiveSubMenu(event);
171
+ } else if (key === tab || key === left) {
172
+ event.persist();
173
+ this.hide(event);
174
+ }
175
+
176
+ if (typeof this.props.onKeyDown === 'function') {
177
+ this.props.onKeyDown(event);
178
+ }
179
+ };
180
+ handleMenuItemSelect = (event, value, selected, item) => {
181
+ if (this.props.shouldHideOnSelect) {
182
+ this.hide(event);
183
+ }
184
+
185
+ if (typeof this.props.onSelect === 'function') {
186
+ this.props.onSelect(event, value, selected, item);
187
+ }
188
+ };
189
+ handleMenuItemFocus = () => {
190
+ this.setState({
191
+ hasFocus: true
192
+ });
193
+ };
194
+ handleMenuItemBlur = () => {
195
+ this.setState({
196
+ hasFocus: this.focusedIndex >= 0
197
+ });
198
+ };
199
+ handleMenuItemMouseOver = (event, menuItem) => {
200
+ if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
201
+ this.hideActiveSubMenu(event);
202
+ }
203
+ };
204
+ hideActiveSubMenu = event => {
205
+ if (this._activeSubMenu) {
206
+ this._activeSubMenu.hide(event);
207
+
208
+ this._activeSubMenu = null;
209
+ }
210
+ };
211
+ handleSubMenuToggle = (shown, subMenu) => {
212
+ if (shown) {
213
+ this._activeSubMenu = subMenu;
214
+ }
215
+ };
216
+ handleSubMenuDismiss = (event, documentClick) => {
217
+ if (event && event.keyCode === keycode.codes.tab || documentClick) {
218
+ this.hide(event);
219
+ }
220
+ };
221
+ hide = event => {
222
+ if (this._popover) {
223
+ this._popover.hide(event);
224
+ }
225
+ };
226
+ show = event => {
227
+ if (this._popover) {
228
+ this._popover.show(event);
229
+ }
230
+ };
231
+
225
232
  focus() {
226
233
  if (this.shown) {
227
234
  var _this$_menu;
@@ -442,19 +449,6 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
442
449
  }, this.renderMenu()) : this.renderMenu();
443
450
  }
444
451
 
445
- }, _class2.displayName = "Menu", _class2.componentId = 'Menu', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
446
- label: null,
447
- disabled: false,
448
- trigger: null,
449
- placement: 'bottom center',
450
- defaultShow: false,
451
- mountNode: null,
452
- constrain: 'window',
453
- shouldHideOnSelect: true,
454
- shouldFocusTriggerOnClose: true,
455
- withArrow: true,
456
- offsetX: 0,
457
- offsetY: 0
458
- }, _class2.Item = MenuItem, _class2.Group = MenuItemGroup, _class2.Separator = MenuItemSeparator, _class2.contextType = MenuContext, _class2)) || _class) || _class) || _class);
452
+ }) || _class) || _class) || _class);
459
453
  export default Menu;
460
454
  export { Menu, MenuItem, MenuItemGroup, MenuItemSeparator };
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
3
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -7,7 +9,7 @@ Object.defineProperty(exports, "__esModule", {
7
9
  });
8
10
  exports.default = exports.MenuItem = void 0;
9
11
 
10
- var _react = require("react");
12
+ var _react = _interopRequireWildcard(require("react"));
11
13
 
12
14
  var _keycode = _interopRequireDefault(require("keycode"));
13
15
 
@@ -39,7 +41,7 @@ var _theme = _interopRequireDefault(require("./theme"));
39
41
 
40
42
  var _props = require("./props");
41
43
 
42
- var _dec, _dec2, _dec3, _class, _class2, _IconCheckSolid, _IconArrowOpenEndSoli;
44
+ var _dec, _dec2, _dec3, _class, _IconCheckSolid, _IconArrowOpenEndSoli;
43
45
 
44
46
  /**
45
47
  ---
@@ -48,83 +50,19 @@ id: Menu.Item
48
50
  ---
49
51
  @tsProps
50
52
  **/
51
- let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec3 = (0, _testable.testable)(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class MenuItem extends _react.Component {
53
+ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec3 = (0, _testable.testable)(), _dec(_class = _dec2(_class = _dec3(_class = class MenuItem extends _react.Component {
54
+ static displayName = "MenuItem";
55
+ static componentId = 'Menu.Item';
56
+ static propTypes = _props.propTypes;
57
+ static allowedProps = _props.allowedProps;
58
+ static defaultProps = {
59
+ type: 'button',
60
+ disabled: false
61
+ };
62
+ static contextType = _MenuContext.MenuContext;
63
+
52
64
  constructor(props) {
53
65
  super(props);
54
- this.labelId = void 0;
55
- this.ref = null;
56
-
57
- this.handleRef = el => {
58
- this.ref = el;
59
- };
60
-
61
- this.handleClick = e => {
62
- const _this$props = this.props,
63
- onSelect = _this$props.onSelect,
64
- onClick = _this$props.onClick,
65
- disabled = _this$props.disabled,
66
- value = _this$props.value;
67
- const selected = !this.selected;
68
-
69
- if (disabled) {
70
- e.preventDefault();
71
- return;
72
- }
73
-
74
- if (typeof this.props.selected === 'undefined') {
75
- this.setState({
76
- selected
77
- });
78
- }
79
-
80
- if (typeof onSelect === 'function') {
81
- e.persist();
82
- onSelect(e, value, selected, this);
83
- }
84
-
85
- if (typeof onClick === 'function') {
86
- onClick(e);
87
- }
88
- };
89
-
90
- this.handleKeyDown = e => {
91
- const spaceKey = e.keyCode === _keycode.default.codes.space;
92
- const enterKey = e.keyCode === _keycode.default.codes.enter;
93
-
94
- if (spaceKey || enterKey) {
95
- e.preventDefault();
96
- e.stopPropagation();
97
-
98
- if (enterKey) {
99
- // handle space key on keyUp for FF
100
- const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
101
- refNode.click();
102
- }
103
- }
104
- };
105
-
106
- this.handleKeyUp = e => {
107
- const spaceKey = e.keyCode === _keycode.default.codes.space;
108
- const enterKey = e.keyCode === _keycode.default.codes.enter;
109
-
110
- if (spaceKey || enterKey) {
111
- e.preventDefault();
112
- e.stopPropagation();
113
-
114
- if (spaceKey) {
115
- const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
116
- refNode.click();
117
- }
118
- }
119
- };
120
-
121
- this.handleMouseOver = event => {
122
- this.focus();
123
-
124
- if (typeof this.props.onMouseOver === 'function') {
125
- this.props.onMouseOver(event, this);
126
- }
127
- };
128
66
 
129
67
  if (typeof props.selected === 'undefined') {
130
68
  this.state = {
@@ -139,10 +77,16 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
139
77
  return this.ref;
140
78
  }
141
79
 
80
+ labelId;
81
+ ref = null;
82
+ handleRef = el => {
83
+ this.ref = el;
84
+ };
85
+
142
86
  componentDidMount() {
143
- var _this$props$makeStyle, _this$props2;
87
+ var _this$props$makeStyle, _this$props;
144
88
 
145
- (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
89
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
146
90
  const context = this.context;
147
91
 
148
92
  if (context && context.registerMenuItem) {
@@ -151,9 +95,9 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
151
95
  }
152
96
 
153
97
  componentDidUpdate() {
154
- var _this$props$makeStyle2, _this$props3;
98
+ var _this$props$makeStyle2, _this$props2;
155
99
 
156
- (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
100
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
157
101
  }
158
102
 
159
103
  componentWillUnmount() {
@@ -164,6 +108,71 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
164
108
  }
165
109
  }
166
110
 
111
+ handleClick = e => {
112
+ const _this$props3 = this.props,
113
+ onSelect = _this$props3.onSelect,
114
+ onClick = _this$props3.onClick,
115
+ disabled = _this$props3.disabled,
116
+ value = _this$props3.value;
117
+ const selected = !this.selected;
118
+
119
+ if (disabled) {
120
+ e.preventDefault();
121
+ return;
122
+ }
123
+
124
+ if (typeof this.props.selected === 'undefined') {
125
+ this.setState({
126
+ selected
127
+ });
128
+ }
129
+
130
+ if (typeof onSelect === 'function') {
131
+ e.persist();
132
+ onSelect(e, value, selected, this);
133
+ }
134
+
135
+ if (typeof onClick === 'function') {
136
+ onClick(e);
137
+ }
138
+ };
139
+ handleKeyDown = e => {
140
+ const spaceKey = e.keyCode === _keycode.default.codes.space;
141
+ const enterKey = e.keyCode === _keycode.default.codes.enter;
142
+
143
+ if (spaceKey || enterKey) {
144
+ e.preventDefault();
145
+ e.stopPropagation();
146
+
147
+ if (enterKey) {
148
+ // handle space key on keyUp for FF
149
+ const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
150
+ refNode.click();
151
+ }
152
+ }
153
+ };
154
+ handleKeyUp = e => {
155
+ const spaceKey = e.keyCode === _keycode.default.codes.space;
156
+ const enterKey = e.keyCode === _keycode.default.codes.enter;
157
+
158
+ if (spaceKey || enterKey) {
159
+ e.preventDefault();
160
+ e.stopPropagation();
161
+
162
+ if (spaceKey) {
163
+ const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
164
+ refNode.click();
165
+ }
166
+ }
167
+ };
168
+ handleMouseOver = event => {
169
+ this.focus();
170
+
171
+ if (typeof this.props.onMouseOver === 'function') {
172
+ this.props.onMouseOver(event, this);
173
+ }
174
+ };
175
+
167
176
  get elementType() {
168
177
  return (0, _getElementType.getElementType)(MenuItem, this.props);
169
178
  }
@@ -244,10 +253,7 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
244
253
  }), this.renderContent());
245
254
  }
246
255
 
247
- }, _class2.displayName = "MenuItem", _class2.componentId = 'Menu.Item', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
248
- type: 'button',
249
- disabled: false
250
- }, _class2.contextType = _MenuContext.MenuContext, _class2)) || _class) || _class) || _class);
256
+ }) || _class) || _class) || _class);
251
257
  exports.MenuItem = MenuItem;
252
258
  var _default = MenuItem;
253
259
  exports.default = _default;