@instructure/ui-menu 8.25.1-snapshot-10 → 8.25.1-snapshot-13

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;
1
+ var _dec, _dec2, _dec3, _class, _class2;
2
2
 
3
3
  /*
4
4
  * The MIT License (MIT)
@@ -47,56 +47,162 @@ 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 = 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
-
50
+ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class Menu extends Component {
98
51
  constructor(props) {
99
52
  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
+
100
206
  this._id = this.props.id || props.deterministicId();
101
207
  }
102
208
 
@@ -112,123 +218,10 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
112
218
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
113
219
  }
114
220
 
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
-
128
221
  get menuItems() {
129
222
  return this._menuItems;
130
223
  }
131
224
 
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
-
232
225
  focus() {
233
226
  if (this.shown) {
234
227
  var _this$_menu;
@@ -449,6 +442,19 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
449
442
  }, this.renderMenu()) : this.renderMenu();
450
443
  }
451
444
 
452
- }) || _class) || _class) || _class);
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);
453
459
  export default Menu;
454
460
  export { Menu, MenuItem, MenuItemGroup, MenuItemSeparator };
@@ -41,7 +41,7 @@ var _theme = _interopRequireDefault(require("./theme"));
41
41
 
42
42
  var _props = require("./props");
43
43
 
44
- var _dec, _dec2, _dec3, _class, _IconCheckSolid, _IconArrowOpenEndSoli;
44
+ var _dec, _dec2, _dec3, _class, _class2, _IconCheckSolid, _IconArrowOpenEndSoli;
45
45
 
46
46
  /**
47
47
  ---
@@ -50,19 +50,83 @@ id: Menu.Item
50
50
  ---
51
51
  @tsProps
52
52
  **/
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
-
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 = (_class2 = class MenuItem extends _react.Component {
64
54
  constructor(props) {
65
55
  super(props);
56
+ this.labelId = void 0;
57
+ this.ref = null;
58
+
59
+ this.handleRef = el => {
60
+ this.ref = el;
61
+ };
62
+
63
+ this.handleClick = e => {
64
+ const _this$props = this.props,
65
+ onSelect = _this$props.onSelect,
66
+ onClick = _this$props.onClick,
67
+ disabled = _this$props.disabled,
68
+ value = _this$props.value;
69
+ const selected = !this.selected;
70
+
71
+ if (disabled) {
72
+ e.preventDefault();
73
+ return;
74
+ }
75
+
76
+ if (typeof this.props.selected === 'undefined') {
77
+ this.setState({
78
+ selected
79
+ });
80
+ }
81
+
82
+ if (typeof onSelect === 'function') {
83
+ e.persist();
84
+ onSelect(e, value, selected, this);
85
+ }
86
+
87
+ if (typeof onClick === 'function') {
88
+ onClick(e);
89
+ }
90
+ };
91
+
92
+ this.handleKeyDown = e => {
93
+ const spaceKey = e.keyCode === _keycode.default.codes.space;
94
+ const enterKey = e.keyCode === _keycode.default.codes.enter;
95
+
96
+ if (spaceKey || enterKey) {
97
+ e.preventDefault();
98
+ e.stopPropagation();
99
+
100
+ if (enterKey) {
101
+ // handle space key on keyUp for FF
102
+ const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
103
+ refNode.click();
104
+ }
105
+ }
106
+ };
107
+
108
+ this.handleKeyUp = e => {
109
+ const spaceKey = e.keyCode === _keycode.default.codes.space;
110
+ const enterKey = e.keyCode === _keycode.default.codes.enter;
111
+
112
+ if (spaceKey || enterKey) {
113
+ e.preventDefault();
114
+ e.stopPropagation();
115
+
116
+ if (spaceKey) {
117
+ const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
118
+ refNode.click();
119
+ }
120
+ }
121
+ };
122
+
123
+ this.handleMouseOver = event => {
124
+ this.focus();
125
+
126
+ if (typeof this.props.onMouseOver === 'function') {
127
+ this.props.onMouseOver(event, this);
128
+ }
129
+ };
66
130
 
67
131
  if (typeof props.selected === 'undefined') {
68
132
  this.state = {
@@ -77,16 +141,10 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
77
141
  return this.ref;
78
142
  }
79
143
 
80
- labelId;
81
- ref = null;
82
- handleRef = el => {
83
- this.ref = el;
84
- };
85
-
86
144
  componentDidMount() {
87
- var _this$props$makeStyle, _this$props;
145
+ var _this$props$makeStyle, _this$props2;
88
146
 
89
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
147
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
90
148
  const context = this.context;
91
149
 
92
150
  if (context && context.registerMenuItem) {
@@ -95,9 +153,9 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
95
153
  }
96
154
 
97
155
  componentDidUpdate() {
98
- var _this$props$makeStyle2, _this$props2;
156
+ var _this$props$makeStyle2, _this$props3;
99
157
 
100
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
158
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
101
159
  }
102
160
 
103
161
  componentWillUnmount() {
@@ -108,71 +166,6 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
108
166
  }
109
167
  }
110
168
 
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
-
176
169
  get elementType() {
177
170
  return (0, _getElementType.getElementType)(MenuItem, this.props);
178
171
  }
@@ -253,7 +246,10 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
253
246
  }), this.renderContent());
254
247
  }
255
248
 
256
- }) || _class) || _class) || _class);
249
+ }, _class2.displayName = "MenuItem", _class2.componentId = 'Menu.Item', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
250
+ type: 'button',
251
+ disabled: false
252
+ }, _class2.contextType = _MenuContext.MenuContext, _class2)) || _class) || _class) || _class);
257
253
  exports.MenuItem = MenuItem;
258
254
  var _default = MenuItem;
259
255
  exports.default = _default;