@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.
- package/CHANGELOG.md +5 -2
- package/es/Menu/v1/MenuItem/index.js +99 -95
- package/es/Menu/v1/MenuItem/styles.js +4 -2
- package/es/Menu/v1/MenuItem/theme.js +20 -19
- package/es/Menu/v1/MenuItemGroup/index.js +71 -64
- package/es/Menu/v1/MenuItemGroup/theme.js +12 -11
- package/es/Menu/v1/MenuItemSeparator/index.js +13 -16
- package/es/Menu/v1/MenuItemSeparator/theme.js +8 -7
- package/es/Menu/v1/index.js +189 -183
- package/es/Menu/v1/theme.js +13 -12
- package/es/Menu/v2/MenuItem/index.js +128 -122
- package/es/Menu/v2/MenuItem/styles.js +5 -3
- package/es/Menu/v2/MenuItemGroup/index.js +71 -64
- package/es/Menu/v2/MenuItemSeparator/index.js +13 -16
- package/es/Menu/v2/index.js +189 -183
- package/lib/Menu/v1/MenuItem/index.js +100 -96
- package/lib/Menu/v1/MenuItem/styles.js +4 -2
- package/lib/Menu/v1/MenuItem/theme.js +20 -19
- package/lib/Menu/v1/MenuItemGroup/index.js +71 -64
- package/lib/Menu/v1/MenuItemGroup/theme.js +12 -11
- package/lib/Menu/v1/MenuItemSeparator/index.js +13 -16
- package/lib/Menu/v1/MenuItemSeparator/theme.js +8 -7
- package/lib/Menu/v1/index.js +189 -183
- package/lib/Menu/v1/theme.js +13 -12
- package/lib/Menu/v2/MenuItem/index.js +128 -122
- package/lib/Menu/v2/MenuItem/styles.js +5 -3
- package/lib/Menu/v2/MenuItemGroup/index.js +71 -64
- package/lib/Menu/v2/MenuItemSeparator/index.js +13 -16
- package/lib/Menu/v2/index.js +189 -183
- package/package.json +17 -17
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -20,7 +20,7 @@ var _MenuContext = require("../../../utils/v1/MenuContext");
|
|
|
20
20
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
21
21
|
var _props = require("./props");
|
|
22
22
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
23
|
-
var _dec, _dec2, _class
|
|
23
|
+
var _dec, _dec2, _class;
|
|
24
24
|
/*
|
|
25
25
|
* The MIT License (MIT)
|
|
26
26
|
*
|
|
@@ -50,98 +50,17 @@ parent: Menu
|
|
|
50
50
|
id: Menu.Item
|
|
51
51
|
---
|
|
52
52
|
**/
|
|
53
|
-
let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class =
|
|
53
|
+
let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = class MenuItem extends _react.Component {
|
|
54
|
+
static displayName = "MenuItem";
|
|
55
|
+
static componentId = 'Menu.Item';
|
|
56
|
+
static allowedProps = _props.allowedProps;
|
|
57
|
+
static defaultProps = {
|
|
58
|
+
type: 'button',
|
|
59
|
+
disabled: false
|
|
60
|
+
};
|
|
61
|
+
static contextType = _MenuContext.MenuContext;
|
|
54
62
|
constructor(props) {
|
|
55
63
|
super(props);
|
|
56
|
-
this.labelId = void 0;
|
|
57
|
-
this.ref = null;
|
|
58
|
-
this.handleRef = el => {
|
|
59
|
-
this.ref = el;
|
|
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
|
-
if (disabled) {
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (typeof this.props.selected === 'undefined') {
|
|
73
|
-
this.setState({
|
|
74
|
-
selected
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (typeof onSelect === 'function') {
|
|
78
|
-
e.persist();
|
|
79
|
-
onSelect(e, value, selected, this);
|
|
80
|
-
}
|
|
81
|
-
if (typeof onClick === 'function') {
|
|
82
|
-
onClick(e);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
this.handleKeyDown = e => {
|
|
86
|
-
const spaceKey = e.keyCode === _keycode.default.codes.space;
|
|
87
|
-
const enterKey = e.keyCode === _keycode.default.codes.enter;
|
|
88
|
-
if (spaceKey || enterKey) {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
e.stopPropagation();
|
|
91
|
-
if (enterKey) {
|
|
92
|
-
// handle space key on keyUp for FF
|
|
93
|
-
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
94
|
-
refNode.click();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
this.handleKeyUp = e => {
|
|
99
|
-
const spaceKey = e.keyCode === _keycode.default.codes.space;
|
|
100
|
-
const enterKey = e.keyCode === _keycode.default.codes.enter;
|
|
101
|
-
if (spaceKey || enterKey) {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
e.stopPropagation();
|
|
104
|
-
if (spaceKey) {
|
|
105
|
-
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
106
|
-
refNode.click();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
this.handleMouseOver = event => {
|
|
111
|
-
if (!this.focused) {
|
|
112
|
-
this.focus();
|
|
113
|
-
}
|
|
114
|
-
if (typeof this.props.onMouseOver === 'function') {
|
|
115
|
-
this.props.onMouseOver(event, this);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
this.handleMouseEnter = () => {
|
|
119
|
-
this.setState({
|
|
120
|
-
isHovered: true
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
this.handleMouseLeave = () => {
|
|
124
|
-
this.setState({
|
|
125
|
-
isHovered: false
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
this.handleFocusEvent = () => {
|
|
129
|
-
this.setState({
|
|
130
|
-
isFocused: true
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
this.handleBlurEvent = () => {
|
|
134
|
-
this.setState({
|
|
135
|
-
isFocused: false
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
this.getIconColor = () => {
|
|
139
|
-
const type = this.props.type;
|
|
140
|
-
if (type === 'flyout') {
|
|
141
|
-
return 'baseColor';
|
|
142
|
-
}
|
|
143
|
-
return this.selected ? 'inverseColor' : 'baseColor';
|
|
144
|
-
};
|
|
145
64
|
const state = {
|
|
146
65
|
isHovered: false,
|
|
147
66
|
isFocused: false
|
|
@@ -155,17 +74,20 @@ let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
155
74
|
get _node() {
|
|
156
75
|
return this.ref;
|
|
157
76
|
}
|
|
77
|
+
labelId;
|
|
78
|
+
ref = null;
|
|
79
|
+
handleRef = el => {
|
|
80
|
+
this.ref = el;
|
|
81
|
+
};
|
|
158
82
|
componentDidMount() {
|
|
159
|
-
|
|
160
|
-
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
83
|
+
this.props.makeStyles?.();
|
|
161
84
|
const context = this.context;
|
|
162
85
|
if (context && context.registerMenuItem) {
|
|
163
86
|
context.registerMenuItem(this);
|
|
164
87
|
}
|
|
165
88
|
}
|
|
166
89
|
componentDidUpdate() {
|
|
167
|
-
|
|
168
|
-
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
90
|
+
this.props.makeStyles?.();
|
|
169
91
|
}
|
|
170
92
|
componentWillUnmount() {
|
|
171
93
|
const context = this.context;
|
|
@@ -173,6 +95,93 @@ let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
173
95
|
context.removeMenuItem(this);
|
|
174
96
|
}
|
|
175
97
|
}
|
|
98
|
+
handleClick = e => {
|
|
99
|
+
const {
|
|
100
|
+
onSelect,
|
|
101
|
+
onClick,
|
|
102
|
+
disabled,
|
|
103
|
+
value
|
|
104
|
+
} = this.props;
|
|
105
|
+
const selected = !this.selected;
|
|
106
|
+
if (disabled) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (typeof this.props.selected === 'undefined') {
|
|
111
|
+
this.setState({
|
|
112
|
+
selected
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (typeof onSelect === 'function') {
|
|
116
|
+
e.persist();
|
|
117
|
+
onSelect(e, value, selected, this);
|
|
118
|
+
}
|
|
119
|
+
if (typeof onClick === 'function') {
|
|
120
|
+
onClick(e);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
handleKeyDown = e => {
|
|
124
|
+
const spaceKey = e.keyCode === _keycode.default.codes.space;
|
|
125
|
+
const enterKey = e.keyCode === _keycode.default.codes.enter;
|
|
126
|
+
if (spaceKey || enterKey) {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
if (enterKey) {
|
|
130
|
+
// handle space key on keyUp for FF
|
|
131
|
+
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
132
|
+
refNode.click();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
handleKeyUp = e => {
|
|
137
|
+
const spaceKey = e.keyCode === _keycode.default.codes.space;
|
|
138
|
+
const enterKey = e.keyCode === _keycode.default.codes.enter;
|
|
139
|
+
if (spaceKey || enterKey) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
e.stopPropagation();
|
|
142
|
+
if (spaceKey) {
|
|
143
|
+
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
144
|
+
refNode.click();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
handleMouseOver = event => {
|
|
149
|
+
if (!this.focused) {
|
|
150
|
+
this.focus();
|
|
151
|
+
}
|
|
152
|
+
if (typeof this.props.onMouseOver === 'function') {
|
|
153
|
+
this.props.onMouseOver(event, this);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
handleMouseEnter = () => {
|
|
157
|
+
this.setState({
|
|
158
|
+
isHovered: true
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
handleMouseLeave = () => {
|
|
162
|
+
this.setState({
|
|
163
|
+
isHovered: false
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
handleFocusEvent = () => {
|
|
167
|
+
this.setState({
|
|
168
|
+
isFocused: true
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
handleBlurEvent = () => {
|
|
172
|
+
this.setState({
|
|
173
|
+
isFocused: false
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
getIconColor = () => {
|
|
177
|
+
const {
|
|
178
|
+
type
|
|
179
|
+
} = this.props;
|
|
180
|
+
if (type === 'flyout') {
|
|
181
|
+
return 'baseColor';
|
|
182
|
+
}
|
|
183
|
+
return this.selected ? 'inverseColor' : 'baseColor';
|
|
184
|
+
};
|
|
176
185
|
get elementType() {
|
|
177
186
|
return (0, _getElementType.getElementType)(MenuItem, this.props);
|
|
178
187
|
}
|
|
@@ -197,46 +206,46 @@ let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
197
206
|
refNode.focus();
|
|
198
207
|
}
|
|
199
208
|
renderContent() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
const {
|
|
210
|
+
children,
|
|
211
|
+
type,
|
|
212
|
+
renderLabelInfo
|
|
213
|
+
} = this.props;
|
|
205
214
|
return (0, _jsxRuntime.jsxs)("span", {
|
|
206
215
|
children: [(0, _jsxRuntime.jsx)("span", {
|
|
207
|
-
css:
|
|
216
|
+
css: this.props.styles?.label,
|
|
208
217
|
id: this.labelId,
|
|
209
218
|
children: children
|
|
210
219
|
}), (type === 'checkbox' || type === 'radio') && (0, _jsxRuntime.jsx)("span", {
|
|
211
|
-
css:
|
|
220
|
+
css: this.props.styles?.icon,
|
|
212
221
|
children: this.selected && (0, _jsxRuntime.jsx)(_uiIcons.CheckInstUIIcon, {
|
|
213
222
|
size: "md",
|
|
214
223
|
color: this.getIconColor()
|
|
215
224
|
})
|
|
216
225
|
}), type === 'flyout' && (0, _jsxRuntime.jsx)("span", {
|
|
217
|
-
css:
|
|
226
|
+
css: this.props.styles?.icon,
|
|
218
227
|
children: (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
|
|
219
228
|
size: "md",
|
|
220
229
|
color: this.getIconColor()
|
|
221
230
|
})
|
|
222
231
|
}), renderLabelInfo && (0, _jsxRuntime.jsx)("span", {
|
|
223
|
-
css:
|
|
232
|
+
css: this.props.styles?.labelInfo,
|
|
224
233
|
children: (0, _callRenderProp.callRenderProp)(renderLabelInfo)
|
|
225
234
|
})]
|
|
226
235
|
});
|
|
227
236
|
}
|
|
228
237
|
render() {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const {
|
|
239
|
+
disabled,
|
|
240
|
+
controls,
|
|
241
|
+
onKeyDown,
|
|
242
|
+
onKeyUp,
|
|
243
|
+
onFocus,
|
|
244
|
+
onBlur,
|
|
245
|
+
type,
|
|
246
|
+
href,
|
|
247
|
+
target
|
|
248
|
+
} = this.props;
|
|
240
249
|
const props = (0, _omitProps.omitProps)(this.props, MenuItem.allowedProps);
|
|
241
250
|
const ElementType = this.elementType;
|
|
242
251
|
return (0, _jsxRuntime.jsx)(ElementType, {
|
|
@@ -247,14 +256,14 @@ let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
247
256
|
target: target,
|
|
248
257
|
role: this.role,
|
|
249
258
|
"aria-labelledby": this.labelId,
|
|
250
|
-
"aria-disabled": disabled ? 'true' :
|
|
259
|
+
"aria-disabled": disabled ? 'true' : undefined,
|
|
251
260
|
"aria-controls": controls,
|
|
252
|
-
"aria-checked": type === 'checkbox' || type === 'radio' ? this.selected ? 'true' : 'false' :
|
|
261
|
+
"aria-checked": type === 'checkbox' || type === 'radio' ? this.selected ? 'true' : 'false' : undefined,
|
|
253
262
|
onClick: this.handleClick,
|
|
254
263
|
onKeyUp: (0, _createChainedFunction.createChainedFunction)(onKeyUp, this.handleKeyUp),
|
|
255
264
|
onKeyDown: (0, _createChainedFunction.createChainedFunction)(onKeyDown, this.handleKeyDown),
|
|
256
265
|
ref: this.handleRef,
|
|
257
|
-
css:
|
|
266
|
+
css: this.props.styles?.menuItem,
|
|
258
267
|
onMouseOver: this.handleMouseOver,
|
|
259
268
|
onMouseEnter: this.handleMouseEnter,
|
|
260
269
|
onMouseLeave: this.handleMouseLeave,
|
|
@@ -264,8 +273,5 @@ let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDetermini
|
|
|
264
273
|
children: this.renderContent()
|
|
265
274
|
});
|
|
266
275
|
}
|
|
267
|
-
}
|
|
268
|
-
type: 'button',
|
|
269
|
-
disabled: false
|
|
270
|
-
}, _MenuItem.contextType = _MenuContext.MenuContext, _MenuItem)) || _class) || _class);
|
|
276
|
+
}) || _class) || _class);
|
|
271
277
|
var _default = exports.default = MenuItem;
|
|
@@ -39,9 +39,11 @@ exports.default = void 0;
|
|
|
39
39
|
* @return {Object} The final style object, which will be used in the component
|
|
40
40
|
*/
|
|
41
41
|
const generateStyle = (componentTheme, props) => {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const {
|
|
43
|
+
type,
|
|
44
|
+
disabled,
|
|
45
|
+
selected
|
|
46
|
+
} = props;
|
|
45
47
|
const isRadioOrCheckbox = type === 'checkbox' || type === 'radio';
|
|
46
48
|
const flyoutIconStyles = type === 'flyout' ? {
|
|
47
49
|
insetInlineStart: 'auto',
|
|
@@ -16,7 +16,7 @@ var _MenuItem = require("../MenuItem");
|
|
|
16
16
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
17
17
|
var _props = require("./props");
|
|
18
18
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
19
|
-
var _dec, _dec2, _class
|
|
19
|
+
var _dec, _dec2, _class;
|
|
20
20
|
/*
|
|
21
21
|
* The MIT License (MIT)
|
|
22
22
|
*
|
|
@@ -46,62 +46,74 @@ parent: Menu
|
|
|
46
46
|
id: Menu.Group
|
|
47
47
|
---
|
|
48
48
|
**/
|
|
49
|
-
let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class =
|
|
49
|
+
let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = class MenuItemGroup extends _react.Component {
|
|
50
|
+
static displayName = "MenuItemGroup";
|
|
51
|
+
static componentId = 'Menu.Group';
|
|
52
|
+
static allowedProps = _props.allowedProps;
|
|
53
|
+
static defaultProps = {
|
|
54
|
+
disabled: false,
|
|
55
|
+
children: null,
|
|
56
|
+
isTabbable: false,
|
|
57
|
+
allowMultiple: false,
|
|
58
|
+
defaultSelected: []
|
|
59
|
+
};
|
|
50
60
|
constructor(props) {
|
|
51
61
|
super(props);
|
|
52
|
-
this.ref = null;
|
|
53
|
-
this.handleRef = el => {
|
|
54
|
-
this.ref = el;
|
|
55
|
-
};
|
|
56
|
-
this.handleSelect = (e, value, selected, item) => {
|
|
57
|
-
if (this.props.disabled) {
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (this.props.selected) {
|
|
62
|
-
this.updateSelected(e, value, this.props.selected, selected, item);
|
|
63
|
-
} else {
|
|
64
|
-
this.setState(state => {
|
|
65
|
-
return {
|
|
66
|
-
selected: this.updateSelected(e, value, state.selected, selected, item)
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
this.updateSelected = (e, value, items, selected, item) => {
|
|
72
|
-
const allowMultiple = this.props.allowMultiple;
|
|
73
|
-
let updated = allowMultiple ? [...items] : [];
|
|
74
|
-
const location = updated.indexOf(value);
|
|
75
|
-
if (selected === true && location < 0) {
|
|
76
|
-
updated.push(value);
|
|
77
|
-
} else if (selected === false && location !== -1) {
|
|
78
|
-
updated.splice(location, 1);
|
|
79
|
-
} else if (!allowMultiple && updated.length < 1) {
|
|
80
|
-
// don't allow nothing selected if it's not allowMultiple/checkbox
|
|
81
|
-
updated = [...items];
|
|
82
|
-
}
|
|
83
|
-
if (typeof this.props.onSelect === 'function') {
|
|
84
|
-
this.props.onSelect(e, updated, selected, item);
|
|
85
|
-
}
|
|
86
|
-
return updated;
|
|
87
|
-
};
|
|
88
62
|
if (typeof props.selected === 'undefined') {
|
|
89
63
|
this.state = {
|
|
90
64
|
selected: this.selectedFromChildren(props) || props.defaultSelected
|
|
91
65
|
};
|
|
92
66
|
}
|
|
93
67
|
}
|
|
68
|
+
ref = null;
|
|
69
|
+
handleRef = el => {
|
|
70
|
+
this.ref = el;
|
|
71
|
+
};
|
|
94
72
|
componentDidMount() {
|
|
95
|
-
|
|
96
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
73
|
+
this.props.makeStyles?.();
|
|
97
74
|
}
|
|
98
75
|
componentDidUpdate() {
|
|
99
|
-
|
|
100
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
76
|
+
this.props.makeStyles?.();
|
|
101
77
|
}
|
|
78
|
+
handleSelect = (e, value, selected, item) => {
|
|
79
|
+
if (this.props.disabled) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (this.props.selected) {
|
|
84
|
+
this.updateSelected(e, value, this.props.selected, selected, item);
|
|
85
|
+
} else {
|
|
86
|
+
this.setState(state => {
|
|
87
|
+
return {
|
|
88
|
+
selected: this.updateSelected(e, value, state.selected, selected, item)
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
updateSelected = (e, value, items, selected, item) => {
|
|
94
|
+
const {
|
|
95
|
+
allowMultiple
|
|
96
|
+
} = this.props;
|
|
97
|
+
let updated = allowMultiple ? [...items] : [];
|
|
98
|
+
const location = updated.indexOf(value);
|
|
99
|
+
if (selected === true && location < 0) {
|
|
100
|
+
updated.push(value);
|
|
101
|
+
} else if (selected === false && location !== -1) {
|
|
102
|
+
updated.splice(location, 1);
|
|
103
|
+
} else if (!allowMultiple && updated.length < 1) {
|
|
104
|
+
// don't allow nothing selected if it's not allowMultiple/checkbox
|
|
105
|
+
updated = [...items];
|
|
106
|
+
}
|
|
107
|
+
if (typeof this.props.onSelect === 'function') {
|
|
108
|
+
this.props.onSelect(e, updated, selected, item);
|
|
109
|
+
}
|
|
110
|
+
return updated;
|
|
111
|
+
};
|
|
102
112
|
selectedFromChildren(props) {
|
|
103
|
-
const
|
|
104
|
-
|
|
113
|
+
const {
|
|
114
|
+
children,
|
|
115
|
+
allowMultiple
|
|
116
|
+
} = props;
|
|
105
117
|
const selected = [];
|
|
106
118
|
const items = _react.Children.toArray(children).filter(child => {
|
|
107
119
|
return (0, _matchComponentTypes.matchComponentTypes)(child, [_MenuItem.MenuItem]);
|
|
@@ -121,20 +133,22 @@ let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _withDeterministicId.wit
|
|
|
121
133
|
}
|
|
122
134
|
}
|
|
123
135
|
renderLabel() {
|
|
124
|
-
|
|
125
|
-
|
|
136
|
+
const {
|
|
137
|
+
label
|
|
138
|
+
} = this.props;
|
|
126
139
|
return (0, _hasVisibleChildren.hasVisibleChildren)(label) ? (0, _jsxRuntime.jsx)("span", {
|
|
127
|
-
css:
|
|
140
|
+
css: this.props.styles?.label,
|
|
128
141
|
children: label
|
|
129
142
|
}) : label;
|
|
130
143
|
}
|
|
131
144
|
renderChildren() {
|
|
132
|
-
const
|
|
133
|
-
disabled
|
|
134
|
-
controls
|
|
135
|
-
allowMultiple
|
|
136
|
-
isTabbable
|
|
137
|
-
onMouseOver
|
|
145
|
+
const {
|
|
146
|
+
disabled,
|
|
147
|
+
controls,
|
|
148
|
+
allowMultiple,
|
|
149
|
+
isTabbable,
|
|
150
|
+
onMouseOver
|
|
151
|
+
} = this.props;
|
|
138
152
|
const children = this.props.children;
|
|
139
153
|
let index = -1;
|
|
140
154
|
return _react.Children.map(children, child => {
|
|
@@ -159,25 +173,18 @@ let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _withDeterministicId.wit
|
|
|
159
173
|
});
|
|
160
174
|
}
|
|
161
175
|
render() {
|
|
162
|
-
var _this$props$styles2, _this$props$styles3;
|
|
163
176
|
const props = (0, _omitProps.omitProps)(this.props, MenuItemGroup.allowedProps);
|
|
164
177
|
return (0, _jsxRuntime.jsxs)("span", {
|
|
165
178
|
...props,
|
|
166
|
-
css:
|
|
179
|
+
css: this.props.styles?.menuItemGroup,
|
|
167
180
|
ref: this.handleRef,
|
|
168
181
|
"data-cid": "MenuItemGroup",
|
|
169
182
|
children: [this.renderLabel(), (0, _jsxRuntime.jsx)("div", {
|
|
170
|
-
css:
|
|
171
|
-
"aria-disabled": this.props.disabled ? 'true' :
|
|
183
|
+
css: this.props.styles?.items,
|
|
184
|
+
"aria-disabled": this.props.disabled ? 'true' : undefined,
|
|
172
185
|
children: this.renderChildren()
|
|
173
186
|
})]
|
|
174
187
|
});
|
|
175
188
|
}
|
|
176
|
-
}
|
|
177
|
-
disabled: false,
|
|
178
|
-
children: null,
|
|
179
|
-
isTabbable: false,
|
|
180
|
-
allowMultiple: false,
|
|
181
|
-
defaultSelected: []
|
|
182
|
-
}, _MenuItemGroup)) || _class) || _class);
|
|
189
|
+
}) || _class) || _class);
|
|
183
190
|
var _default = exports.default = MenuItemGroup;
|
|
@@ -11,7 +11,7 @@ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
|
11
11
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
12
12
|
var _props = require("./props");
|
|
13
13
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
14
|
-
var _dec, _class
|
|
14
|
+
var _dec, _class;
|
|
15
15
|
/*
|
|
16
16
|
* The MIT License (MIT)
|
|
17
17
|
*
|
|
@@ -42,34 +42,31 @@ id: Menu.Separator
|
|
|
42
42
|
---
|
|
43
43
|
@module MenuItemSeparator
|
|
44
44
|
**/
|
|
45
|
-
let MenuItemSeparator = exports.MenuItemSeparator = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
45
|
+
let MenuItemSeparator = exports.MenuItemSeparator = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = class MenuItemSeparator extends _react.Component {
|
|
46
|
+
static displayName = "MenuItemSeparator";
|
|
47
|
+
static componentId = 'Menu.Separator';
|
|
48
|
+
static allowedProps = _props.allowedProps;
|
|
49
|
+
ref = null;
|
|
50
|
+
handleRef = el => {
|
|
51
|
+
this.ref = el;
|
|
52
|
+
};
|
|
53
53
|
componentDidMount() {
|
|
54
|
-
|
|
55
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
54
|
+
this.props.makeStyles?.();
|
|
56
55
|
}
|
|
57
56
|
componentDidUpdate() {
|
|
58
|
-
|
|
59
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
57
|
+
this.props.makeStyles?.();
|
|
60
58
|
}
|
|
61
59
|
render() {
|
|
62
|
-
var _this$props$styles;
|
|
63
60
|
const props = (0, _omitProps.omitProps)(this.props, MenuItemSeparator.allowedProps);
|
|
64
61
|
// role="separator" would fit better here, but it causes NVDA to stop the
|
|
65
62
|
// MenuItem count after it
|
|
66
63
|
return (0, _jsxRuntime.jsx)("div", {
|
|
67
64
|
...props,
|
|
68
65
|
role: "presentation",
|
|
69
|
-
css:
|
|
66
|
+
css: this.props.styles?.menuItemSeparator,
|
|
70
67
|
ref: this.handleRef,
|
|
71
68
|
"data-cid": "MenuItemSeparator"
|
|
72
69
|
});
|
|
73
70
|
}
|
|
74
|
-
}
|
|
71
|
+
}) || _class);
|
|
75
72
|
var _default = exports.default = MenuItemSeparator;
|