@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.
- package/CHANGELOG.md +41 -297
- package/es/Menu/{MenuItem → v1/MenuItem}/index.js +2 -2
- package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.js +1 -1
- package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.js +1 -1
- package/es/Menu/{index.js → v1/index.js} +3 -3
- package/es/Menu/v2/MenuItem/index.js +262 -0
- package/es/Menu/v2/MenuItem/props.js +26 -0
- package/es/Menu/v2/MenuItem/styles.js +146 -0
- package/es/Menu/v2/MenuItemGroup/index.js +175 -0
- package/es/Menu/v2/MenuItemGroup/props.js +26 -0
- package/es/Menu/v2/MenuItemGroup/styles.js +60 -0
- package/es/Menu/v2/MenuItemSeparator/index.js +70 -0
- package/es/Menu/v2/MenuItemSeparator/props.js +29 -0
- package/es/Menu/v2/MenuItemSeparator/styles.js +46 -0
- package/es/Menu/v2/index.js +405 -0
- package/es/Menu/v2/props.js +26 -0
- package/es/Menu/v2/styles.js +61 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/es/exports/b.js +24 -0
- package/es/{MenuContext.js → utils/v1/MenuContext.js} +2 -0
- package/lib/Menu/{MenuItem → v1/MenuItem}/index.js +4 -4
- package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.js +1 -1
- package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.js +1 -1
- package/lib/Menu/v1/index.js +432 -0
- package/lib/Menu/v2/MenuItem/index.js +271 -0
- package/lib/Menu/v2/MenuItem/props.js +31 -0
- package/lib/Menu/v2/MenuItem/styles.js +152 -0
- package/lib/Menu/v2/MenuItemGroup/index.js +183 -0
- package/lib/Menu/v2/MenuItemGroup/props.js +31 -0
- package/lib/Menu/v2/MenuItemGroup/styles.js +66 -0
- package/lib/Menu/v2/MenuItemSeparator/index.js +75 -0
- package/lib/Menu/v2/MenuItemSeparator/props.js +34 -0
- package/lib/Menu/v2/MenuItemSeparator/styles.js +52 -0
- package/lib/Menu/{index.js → v2/index.js} +4 -5
- package/lib/Menu/v2/props.js +31 -0
- package/lib/Menu/v2/styles.js +66 -0
- package/lib/{index.js → exports/a.js} +5 -5
- package/lib/exports/b.js +30 -0
- package/lib/{MenuContext.js → utils/v1/MenuContext.js} +1 -0
- package/package.json +45 -23
- package/src/Menu/{MenuItem → v1/MenuItem}/index.tsx +2 -2
- package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.tsx +1 -1
- package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.tsx +1 -1
- package/src/Menu/{index.tsx → v1/index.tsx} +3 -3
- package/src/Menu/{props.ts → v1/props.ts} +1 -1
- package/src/Menu/v2/MenuItem/index.tsx +318 -0
- package/src/Menu/v2/MenuItem/props.ts +132 -0
- package/src/Menu/v2/MenuItem/styles.ts +172 -0
- package/src/Menu/v2/MenuItemGroup/index.tsx +245 -0
- package/src/Menu/v2/MenuItemGroup/props.ts +105 -0
- package/src/Menu/v2/MenuItemGroup/styles.ts +66 -0
- package/src/Menu/v2/MenuItemSeparator/index.tsx +79 -0
- package/src/Menu/v2/MenuItemSeparator/props.ts +48 -0
- package/src/Menu/v2/MenuItemSeparator/styles.ts +52 -0
- package/src/Menu/v2/README.md +104 -0
- package/src/Menu/v2/index.tsx +514 -0
- package/src/Menu/v2/props.ts +213 -0
- package/src/Menu/v2/styles.ts +68 -0
- package/src/{index.ts → exports/a.ts} +5 -5
- package/src/exports/b.ts +29 -0
- package/src/{MenuContext.ts → utils/v1/MenuContext.ts} +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Menu/{MenuItem → v1/MenuItem}/index.d.ts +3 -3
- package/types/Menu/v1/MenuItem/index.d.ts.map +1 -0
- package/types/Menu/v1/MenuItem/props.d.ts.map +1 -0
- package/types/Menu/v1/MenuItem/styles.d.ts.map +1 -0
- package/types/Menu/v1/MenuItem/theme.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemGroup/index.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemGroup/props.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemGroup/styles.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemGroup/theme.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemSeparator/index.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemSeparator/props.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemSeparator/styles.d.ts.map +1 -0
- package/types/Menu/v1/MenuItemSeparator/theme.d.ts.map +1 -0
- package/types/Menu/{index.d.ts → v1/index.d.ts} +3 -3
- package/types/Menu/v1/index.d.ts.map +1 -0
- package/types/Menu/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Menu/v1/props.d.ts.map +1 -0
- package/types/Menu/v1/styles.d.ts.map +1 -0
- package/types/Menu/v1/theme.d.ts.map +1 -0
- package/types/Menu/v2/MenuItem/index.d.ts +66 -0
- package/types/Menu/v2/MenuItem/index.d.ts.map +1 -0
- package/types/Menu/v2/MenuItem/props.d.ts +73 -0
- package/types/Menu/v2/MenuItem/props.d.ts.map +1 -0
- package/types/Menu/v2/MenuItem/styles.d.ts +15 -0
- package/types/Menu/v2/MenuItem/styles.d.ts.map +1 -0
- package/types/Menu/v2/MenuItemGroup/index.d.ts +52 -0
- package/types/Menu/v2/MenuItemGroup/index.d.ts.map +1 -0
- package/types/Menu/v2/MenuItemGroup/props.d.ts +51 -0
- package/types/Menu/v2/MenuItemGroup/props.d.ts.map +1 -0
- package/types/Menu/v2/MenuItemGroup/styles.d.ts +15 -0
- package/types/Menu/v2/MenuItemGroup/styles.d.ts.map +1 -0
- package/types/Menu/v2/MenuItemSeparator/index.d.ts +21 -0
- package/types/Menu/v2/MenuItemSeparator/index.d.ts.map +1 -0
- package/types/Menu/v2/MenuItemSeparator/props.d.ts +11 -0
- package/types/Menu/v2/MenuItemSeparator/props.d.ts.map +1 -0
- package/types/Menu/v2/MenuItemSeparator/styles.d.ts +15 -0
- package/types/Menu/v2/MenuItemSeparator/styles.d.ts.map +1 -0
- package/types/Menu/v2/index.d.ts +118 -0
- package/types/Menu/v2/index.d.ts.map +1 -0
- package/types/Menu/v2/props.d.ts +138 -0
- package/types/Menu/v2/props.d.ts.map +1 -0
- package/types/Menu/v2/styles.d.ts +15 -0
- package/types/Menu/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +6 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +6 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/utils/v1/MenuContext.d.ts +13 -0
- package/types/utils/v1/MenuContext.d.ts.map +1 -0
- package/types/Menu/MenuItem/index.d.ts.map +0 -1
- package/types/Menu/MenuItem/props.d.ts.map +0 -1
- package/types/Menu/MenuItem/styles.d.ts.map +0 -1
- package/types/Menu/MenuItem/theme.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/index.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/props.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/styles.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/theme.d.ts.map +0 -1
- package/types/Menu/MenuItemSeparator/index.d.ts.map +0 -1
- package/types/Menu/MenuItemSeparator/props.d.ts.map +0 -1
- package/types/Menu/MenuItemSeparator/styles.d.ts.map +0 -1
- package/types/Menu/MenuItemSeparator/theme.d.ts.map +0 -1
- package/types/Menu/index.d.ts.map +0 -1
- package/types/Menu/props.d.ts.map +0 -1
- package/types/Menu/styles.d.ts.map +0 -1
- package/types/Menu/theme.d.ts.map +0 -1
- package/types/MenuContext.d.ts +0 -14
- package/types/MenuContext.d.ts.map +0 -1
- package/types/index.d.ts +0 -6
- package/types/index.d.ts.map +0 -1
- /package/es/Menu/{MenuItem → v1/MenuItem}/props.js +0 -0
- /package/es/Menu/{MenuItem → v1/MenuItem}/styles.js +0 -0
- /package/es/Menu/{MenuItem → v1/MenuItem}/theme.js +0 -0
- /package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.js +0 -0
- /package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.js +0 -0
- /package/es/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.js +0 -0
- /package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.js +0 -0
- /package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.js +0 -0
- /package/es/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.js +0 -0
- /package/es/Menu/{props.js → v1/props.js} +0 -0
- /package/es/Menu/{styles.js → v1/styles.js} +0 -0
- /package/es/Menu/{theme.js → v1/theme.js} +0 -0
- /package/lib/Menu/{MenuItem → v1/MenuItem}/props.js +0 -0
- /package/lib/Menu/{MenuItem → v1/MenuItem}/styles.js +0 -0
- /package/lib/Menu/{MenuItem → v1/MenuItem}/theme.js +0 -0
- /package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.js +0 -0
- /package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.js +0 -0
- /package/lib/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.js +0 -0
- /package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.js +0 -0
- /package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.js +0 -0
- /package/lib/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.js +0 -0
- /package/lib/Menu/{props.js → v1/props.js} +0 -0
- /package/lib/Menu/{styles.js → v1/styles.js} +0 -0
- /package/lib/Menu/{theme.js → v1/theme.js} +0 -0
- /package/src/Menu/{MenuItem → v1/MenuItem}/props.ts +0 -0
- /package/src/Menu/{MenuItem → v1/MenuItem}/styles.ts +0 -0
- /package/src/Menu/{MenuItem → v1/MenuItem}/theme.ts +0 -0
- /package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.ts +0 -0
- /package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.ts +0 -0
- /package/src/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.ts +0 -0
- /package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.ts +0 -0
- /package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.ts +0 -0
- /package/src/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.ts +0 -0
- /package/src/Menu/{README.md → v1/README.md} +0 -0
- /package/src/Menu/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Menu/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Menu/{MenuItem → v1/MenuItem}/props.d.ts +0 -0
- /package/types/Menu/{MenuItem → v1/MenuItem}/styles.d.ts +0 -0
- /package/types/Menu/{MenuItem → v1/MenuItem}/theme.d.ts +0 -0
- /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/index.d.ts +0 -0
- /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/props.d.ts +0 -0
- /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/styles.d.ts +0 -0
- /package/types/Menu/{MenuItemGroup → v1/MenuItemGroup}/theme.d.ts +0 -0
- /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/index.d.ts +0 -0
- /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/props.d.ts +0 -0
- /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/styles.d.ts +0 -0
- /package/types/Menu/{MenuItemSeparator → v1/MenuItemSeparator}/theme.d.ts +0 -0
- /package/types/Menu/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Menu/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.MenuItem = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _keycode = _interopRequireDefault(require("keycode"));
|
|
10
|
+
var _uiIcons = require("@instructure/ui-icons");
|
|
11
|
+
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
12
|
+
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
13
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
14
|
+
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
15
|
+
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
16
|
+
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
17
|
+
var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
|
|
18
|
+
var _emotion = require("@instructure/emotion");
|
|
19
|
+
var _MenuContext = require("../../../utils/v1/MenuContext");
|
|
20
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
21
|
+
var _props = require("./props");
|
|
22
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
23
|
+
var _dec, _dec2, _class, _MenuItem;
|
|
24
|
+
/*
|
|
25
|
+
* The MIT License (MIT)
|
|
26
|
+
*
|
|
27
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
28
|
+
*
|
|
29
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
30
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
31
|
+
* in the Software without restriction, including without limitation the rights
|
|
32
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
33
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
34
|
+
* furnished to do so, subject to the following conditions:
|
|
35
|
+
*
|
|
36
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
37
|
+
* copies or substantial portions of the Software.
|
|
38
|
+
*
|
|
39
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
40
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
41
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
42
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
43
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
44
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
45
|
+
* SOFTWARE.
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
---
|
|
49
|
+
parent: Menu
|
|
50
|
+
id: Menu.Item
|
|
51
|
+
---
|
|
52
|
+
**/
|
|
53
|
+
let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_MenuItem = class MenuItem extends _react.Component {
|
|
54
|
+
constructor(props) {
|
|
55
|
+
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
|
+
const state = {
|
|
146
|
+
isHovered: false,
|
|
147
|
+
isFocused: false
|
|
148
|
+
};
|
|
149
|
+
if (typeof props.selected === 'undefined') {
|
|
150
|
+
state.selected = !!props.defaultSelected;
|
|
151
|
+
}
|
|
152
|
+
this.state = state;
|
|
153
|
+
this.labelId = props.deterministicId('MenuItem__label');
|
|
154
|
+
}
|
|
155
|
+
get _node() {
|
|
156
|
+
return this.ref;
|
|
157
|
+
}
|
|
158
|
+
componentDidMount() {
|
|
159
|
+
var _this$props$makeStyle, _this$props2;
|
|
160
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
161
|
+
const context = this.context;
|
|
162
|
+
if (context && context.registerMenuItem) {
|
|
163
|
+
context.registerMenuItem(this);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
componentDidUpdate() {
|
|
167
|
+
var _this$props$makeStyle2, _this$props3;
|
|
168
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
169
|
+
}
|
|
170
|
+
componentWillUnmount() {
|
|
171
|
+
const context = this.context;
|
|
172
|
+
if (context && context.removeMenuItem) {
|
|
173
|
+
context.removeMenuItem(this);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
get elementType() {
|
|
177
|
+
return (0, _getElementType.getElementType)(MenuItem, this.props);
|
|
178
|
+
}
|
|
179
|
+
get role() {
|
|
180
|
+
switch (this.props.type) {
|
|
181
|
+
case 'checkbox':
|
|
182
|
+
return 'menuitemcheckbox';
|
|
183
|
+
case 'radio':
|
|
184
|
+
return 'menuitemradio';
|
|
185
|
+
default:
|
|
186
|
+
return 'menuitem';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
get selected() {
|
|
190
|
+
return typeof this.props.selected === 'undefined' ? this.state.selected : this.props.selected;
|
|
191
|
+
}
|
|
192
|
+
get focused() {
|
|
193
|
+
return (0, _isActiveElement.isActiveElement)(this.ref);
|
|
194
|
+
}
|
|
195
|
+
focus() {
|
|
196
|
+
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
197
|
+
refNode.focus();
|
|
198
|
+
}
|
|
199
|
+
renderContent() {
|
|
200
|
+
var _this$props$styles, _this$props$styles2, _this$props$styles3, _this$props$styles4;
|
|
201
|
+
const _this$props4 = this.props,
|
|
202
|
+
children = _this$props4.children,
|
|
203
|
+
type = _this$props4.type,
|
|
204
|
+
renderLabelInfo = _this$props4.renderLabelInfo;
|
|
205
|
+
return (0, _jsxRuntime.jsxs)("span", {
|
|
206
|
+
children: [(0, _jsxRuntime.jsx)("span", {
|
|
207
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.label,
|
|
208
|
+
id: this.labelId,
|
|
209
|
+
children: children
|
|
210
|
+
}), (type === 'checkbox' || type === 'radio') && (0, _jsxRuntime.jsx)("span", {
|
|
211
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.icon,
|
|
212
|
+
children: this.selected && (0, _jsxRuntime.jsx)(_uiIcons.CheckInstUIIcon, {
|
|
213
|
+
size: "md",
|
|
214
|
+
color: this.getIconColor()
|
|
215
|
+
})
|
|
216
|
+
}), type === 'flyout' && (0, _jsxRuntime.jsx)("span", {
|
|
217
|
+
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.icon,
|
|
218
|
+
children: (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
|
|
219
|
+
size: "md",
|
|
220
|
+
color: this.getIconColor()
|
|
221
|
+
})
|
|
222
|
+
}), renderLabelInfo && (0, _jsxRuntime.jsx)("span", {
|
|
223
|
+
css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.labelInfo,
|
|
224
|
+
children: (0, _callRenderProp.callRenderProp)(renderLabelInfo)
|
|
225
|
+
})]
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
render() {
|
|
229
|
+
var _this$props$styles5;
|
|
230
|
+
const _this$props5 = this.props,
|
|
231
|
+
disabled = _this$props5.disabled,
|
|
232
|
+
controls = _this$props5.controls,
|
|
233
|
+
onKeyDown = _this$props5.onKeyDown,
|
|
234
|
+
onKeyUp = _this$props5.onKeyUp,
|
|
235
|
+
onFocus = _this$props5.onFocus,
|
|
236
|
+
onBlur = _this$props5.onBlur,
|
|
237
|
+
type = _this$props5.type,
|
|
238
|
+
href = _this$props5.href,
|
|
239
|
+
target = _this$props5.target;
|
|
240
|
+
const props = (0, _omitProps.omitProps)(this.props, MenuItem.allowedProps);
|
|
241
|
+
const ElementType = this.elementType;
|
|
242
|
+
return (0, _jsxRuntime.jsx)(ElementType, {
|
|
243
|
+
tabIndex: -1 // note: tabIndex can be overridden by Menu or MenuItemGroup components
|
|
244
|
+
,
|
|
245
|
+
...props,
|
|
246
|
+
href: href,
|
|
247
|
+
target: target,
|
|
248
|
+
role: this.role,
|
|
249
|
+
"aria-labelledby": this.labelId,
|
|
250
|
+
"aria-disabled": disabled ? 'true' : void 0,
|
|
251
|
+
"aria-controls": controls,
|
|
252
|
+
"aria-checked": type === 'checkbox' || type === 'radio' ? this.selected ? 'true' : 'false' : void 0,
|
|
253
|
+
onClick: this.handleClick,
|
|
254
|
+
onKeyUp: (0, _createChainedFunction.createChainedFunction)(onKeyUp, this.handleKeyUp),
|
|
255
|
+
onKeyDown: (0, _createChainedFunction.createChainedFunction)(onKeyDown, this.handleKeyDown),
|
|
256
|
+
ref: this.handleRef,
|
|
257
|
+
css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.menuItem,
|
|
258
|
+
onMouseOver: this.handleMouseOver,
|
|
259
|
+
onMouseEnter: this.handleMouseEnter,
|
|
260
|
+
onMouseLeave: this.handleMouseLeave,
|
|
261
|
+
onFocus: (0, _createChainedFunction.createChainedFunction)(onFocus, this.handleFocusEvent),
|
|
262
|
+
onBlur: (0, _createChainedFunction.createChainedFunction)(onBlur, this.handleBlurEvent),
|
|
263
|
+
"data-cid": "MenuItem",
|
|
264
|
+
children: this.renderContent()
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}, _MenuItem.displayName = "MenuItem", _MenuItem.componentId = 'Menu.Item', _MenuItem.allowedProps = _props.allowedProps, _MenuItem.defaultProps = {
|
|
268
|
+
type: 'button',
|
|
269
|
+
disabled: false
|
|
270
|
+
}, _MenuItem.contextType = _MenuContext.MenuContext, _MenuItem)) || _class) || _class);
|
|
271
|
+
var _default = exports.default = MenuItem;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const allowedProps = exports.allowedProps = ['children', 'defaultSelected', 'selected', 'onSelect', 'onClick', 'onKeyDown', 'onKeyUp', 'onMouseOver', 'controls', 'disabled', 'as', 'type', 'value', 'href', 'target', 'renderLabelInfo'];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* ---
|
|
33
|
+
* private: true
|
|
34
|
+
* ---
|
|
35
|
+
* Generates the style object from the theme and provided additional information
|
|
36
|
+
* @param {Object} componentTheme The theme variable object.
|
|
37
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
38
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
39
|
+
* @return {Object} The final style object, which will be used in the component
|
|
40
|
+
*/
|
|
41
|
+
const generateStyle = (componentTheme, props) => {
|
|
42
|
+
const type = props.type,
|
|
43
|
+
disabled = props.disabled,
|
|
44
|
+
selected = props.selected;
|
|
45
|
+
const isRadioOrCheckbox = type === 'checkbox' || type === 'radio';
|
|
46
|
+
const flyoutIconStyles = type === 'flyout' ? {
|
|
47
|
+
insetInlineStart: 'auto',
|
|
48
|
+
insetInlineEnd: componentTheme.iconPadding
|
|
49
|
+
} : {};
|
|
50
|
+
const roleStyles = isRadioOrCheckbox ? {
|
|
51
|
+
paddingInlineEnd: componentTheme.labelPadding
|
|
52
|
+
} : {};
|
|
53
|
+
const roleIconStyles = isRadioOrCheckbox ? {
|
|
54
|
+
insetInlineStart: 'auto',
|
|
55
|
+
insetInlineEnd: componentTheme.iconPadding
|
|
56
|
+
} : {};
|
|
57
|
+
const disabledStyles = disabled ? {
|
|
58
|
+
cursor: 'not-allowed',
|
|
59
|
+
pointerEvents: 'none',
|
|
60
|
+
opacity: 0.5
|
|
61
|
+
} : {};
|
|
62
|
+
const selectedStyles = selected ? {
|
|
63
|
+
background: componentTheme.activeBackground,
|
|
64
|
+
'[class*="menuItem__label"]': {
|
|
65
|
+
color: componentTheme.activeLabelColor
|
|
66
|
+
}
|
|
67
|
+
} : {};
|
|
68
|
+
const selectedHighlightedStyles = selected ? {
|
|
69
|
+
background: componentTheme.selectedHighlightedBackground
|
|
70
|
+
} : {
|
|
71
|
+
background: componentTheme.highlightedBackground,
|
|
72
|
+
'[class*="menuItem__label"]': {
|
|
73
|
+
color: componentTheme.highlightedLabelColor
|
|
74
|
+
},
|
|
75
|
+
'[class*="menuItem__labelInfo"]': {
|
|
76
|
+
color: componentTheme.highlightedLabelInfoColor
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const linkStyles = {
|
|
80
|
+
textDecoration: 'none'
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
menuItem: {
|
|
84
|
+
label: 'menuItem',
|
|
85
|
+
position: 'relative',
|
|
86
|
+
border: 'none',
|
|
87
|
+
outline: 'none',
|
|
88
|
+
padding: `${componentTheme.paddingVertical} ${componentTheme.paddingHorizontal}`,
|
|
89
|
+
margin: '0',
|
|
90
|
+
width: '100%',
|
|
91
|
+
borderRadius: 'initial',
|
|
92
|
+
boxSizing: 'border-box',
|
|
93
|
+
textAlign: 'start',
|
|
94
|
+
cursor: 'pointer',
|
|
95
|
+
userSelect: 'none',
|
|
96
|
+
fontFamily: componentTheme.fontFamily,
|
|
97
|
+
fontWeight: componentTheme.fontWeight,
|
|
98
|
+
lineHeight: componentTheme.lineHeight,
|
|
99
|
+
fontSize: componentTheme.fontSize,
|
|
100
|
+
background: componentTheme.background,
|
|
101
|
+
// Changing the following to display: flex; causes a VO
|
|
102
|
+
// bug where items with role menuitem, menuitemcheckbox
|
|
103
|
+
// and menuitemradio are selected twice with control+
|
|
104
|
+
// option+space. So we set the display to block.
|
|
105
|
+
display: 'block',
|
|
106
|
+
textDecoration: 'none',
|
|
107
|
+
...roleStyles,
|
|
108
|
+
'&:focus, &:active, &:hover': {
|
|
109
|
+
...selectedHighlightedStyles
|
|
110
|
+
},
|
|
111
|
+
//removes extra ff button spacing
|
|
112
|
+
'&::-moz-focus-inner': {
|
|
113
|
+
padding: '0',
|
|
114
|
+
margin: '0',
|
|
115
|
+
border: '0'
|
|
116
|
+
},
|
|
117
|
+
...disabledStyles,
|
|
118
|
+
...selectedStyles,
|
|
119
|
+
// NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
|
|
120
|
+
'&:is(a)': {
|
|
121
|
+
'&, &:link, &:visited, &:active, &:hover, &:focus': linkStyles
|
|
122
|
+
},
|
|
123
|
+
'&:-webkit-any(a)': {
|
|
124
|
+
'&, &:link, &:visited, &:active, &:hover, &:focus': linkStyles
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
icon: {
|
|
128
|
+
label: 'menuItem__icon',
|
|
129
|
+
position: 'absolute',
|
|
130
|
+
display: 'flex',
|
|
131
|
+
alignItems: 'center',
|
|
132
|
+
top: '0',
|
|
133
|
+
width: '1em',
|
|
134
|
+
height: '100%',
|
|
135
|
+
...roleIconStyles,
|
|
136
|
+
...flyoutIconStyles
|
|
137
|
+
},
|
|
138
|
+
labelInfo: {
|
|
139
|
+
label: 'menuItem__labelInfo',
|
|
140
|
+
height: '100%',
|
|
141
|
+
float: 'right',
|
|
142
|
+
clear: 'right',
|
|
143
|
+
paddingRight: '1.75rem',
|
|
144
|
+
color: componentTheme.labelInfoColor
|
|
145
|
+
},
|
|
146
|
+
label: {
|
|
147
|
+
label: 'menuItem__label',
|
|
148
|
+
color: componentTheme.labelColor
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
var _default = exports.default = generateStyle;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.MenuItemGroup = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _emotion = require("@instructure/emotion");
|
|
10
|
+
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
11
|
+
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
12
|
+
var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
|
|
13
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
14
|
+
var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
|
|
15
|
+
var _MenuItem = require("../MenuItem");
|
|
16
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
17
|
+
var _props = require("./props");
|
|
18
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
19
|
+
var _dec, _dec2, _class, _MenuItemGroup;
|
|
20
|
+
/*
|
|
21
|
+
* The MIT License (MIT)
|
|
22
|
+
*
|
|
23
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
24
|
+
*
|
|
25
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
26
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
27
|
+
* in the Software without restriction, including without limitation the rights
|
|
28
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
29
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
30
|
+
* furnished to do so, subject to the following conditions:
|
|
31
|
+
*
|
|
32
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
33
|
+
* copies or substantial portions of the Software.
|
|
34
|
+
*
|
|
35
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
36
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
37
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
38
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
39
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
41
|
+
* SOFTWARE.
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
---
|
|
45
|
+
parent: Menu
|
|
46
|
+
id: Menu.Group
|
|
47
|
+
---
|
|
48
|
+
**/
|
|
49
|
+
let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_MenuItemGroup = class MenuItemGroup extends _react.Component {
|
|
50
|
+
constructor(props) {
|
|
51
|
+
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
|
+
if (typeof props.selected === 'undefined') {
|
|
89
|
+
this.state = {
|
|
90
|
+
selected: this.selectedFromChildren(props) || props.defaultSelected
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
componentDidMount() {
|
|
95
|
+
var _this$props$makeStyle, _this$props;
|
|
96
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
97
|
+
}
|
|
98
|
+
componentDidUpdate() {
|
|
99
|
+
var _this$props$makeStyle2, _this$props2;
|
|
100
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
101
|
+
}
|
|
102
|
+
selectedFromChildren(props) {
|
|
103
|
+
const children = props.children,
|
|
104
|
+
allowMultiple = props.allowMultiple;
|
|
105
|
+
const selected = [];
|
|
106
|
+
const items = _react.Children.toArray(children).filter(child => {
|
|
107
|
+
return (0, _matchComponentTypes.matchComponentTypes)(child, [_MenuItem.MenuItem]);
|
|
108
|
+
});
|
|
109
|
+
items.forEach((item, index) => {
|
|
110
|
+
if ((selected.length === 0 || allowMultiple) && (item.props.selected || item.props.defaultSelected)) {
|
|
111
|
+
selected.push(item.props.value || index);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return selected.length > 0 ? selected : null;
|
|
115
|
+
}
|
|
116
|
+
get selected() {
|
|
117
|
+
if (typeof this.props.selected === 'undefined' && typeof this.state.selected === 'undefined') {
|
|
118
|
+
return [];
|
|
119
|
+
} else {
|
|
120
|
+
return typeof this.props.selected === 'undefined' ? [...this.state.selected] : [...this.props.selected];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
renderLabel() {
|
|
124
|
+
var _this$props$styles;
|
|
125
|
+
const label = this.props.label;
|
|
126
|
+
return (0, _hasVisibleChildren.hasVisibleChildren)(label) ? (0, _jsxRuntime.jsx)("span", {
|
|
127
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.label,
|
|
128
|
+
children: label
|
|
129
|
+
}) : label;
|
|
130
|
+
}
|
|
131
|
+
renderChildren() {
|
|
132
|
+
const _this$props3 = this.props,
|
|
133
|
+
disabled = _this$props3.disabled,
|
|
134
|
+
controls = _this$props3.controls,
|
|
135
|
+
allowMultiple = _this$props3.allowMultiple,
|
|
136
|
+
isTabbable = _this$props3.isTabbable,
|
|
137
|
+
onMouseOver = _this$props3.onMouseOver;
|
|
138
|
+
const children = this.props.children;
|
|
139
|
+
let index = -1;
|
|
140
|
+
return _react.Children.map(children, child => {
|
|
141
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, [_MenuItem.MenuItem])) {
|
|
142
|
+
++index;
|
|
143
|
+
const value = child.props.value || index;
|
|
144
|
+
return (0, _safeCloneElement.safeCloneElement)(child, {
|
|
145
|
+
tabIndex: isTabbable && index === 0 ? 0 : -1,
|
|
146
|
+
controls,
|
|
147
|
+
value,
|
|
148
|
+
children: child.props.children,
|
|
149
|
+
type: allowMultiple ? 'checkbox' : 'radio',
|
|
150
|
+
ref: this.props.itemRef,
|
|
151
|
+
disabled: disabled || child.props.disabled,
|
|
152
|
+
selected: this.selected.indexOf(value) > -1,
|
|
153
|
+
onSelect: this.handleSelect,
|
|
154
|
+
onMouseOver
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
return child;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
render() {
|
|
162
|
+
var _this$props$styles2, _this$props$styles3;
|
|
163
|
+
const props = (0, _omitProps.omitProps)(this.props, MenuItemGroup.allowedProps);
|
|
164
|
+
return (0, _jsxRuntime.jsxs)("span", {
|
|
165
|
+
...props,
|
|
166
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.menuItemGroup,
|
|
167
|
+
ref: this.handleRef,
|
|
168
|
+
"data-cid": "MenuItemGroup",
|
|
169
|
+
children: [this.renderLabel(), (0, _jsxRuntime.jsx)("div", {
|
|
170
|
+
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.items,
|
|
171
|
+
"aria-disabled": this.props.disabled ? 'true' : void 0,
|
|
172
|
+
children: this.renderChildren()
|
|
173
|
+
})]
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}, _MenuItemGroup.displayName = "MenuItemGroup", _MenuItemGroup.componentId = 'Menu.Group', _MenuItemGroup.allowedProps = _props.allowedProps, _MenuItemGroup.defaultProps = {
|
|
177
|
+
disabled: false,
|
|
178
|
+
children: null,
|
|
179
|
+
isTabbable: false,
|
|
180
|
+
allowMultiple: false,
|
|
181
|
+
defaultSelected: []
|
|
182
|
+
}, _MenuItemGroup)) || _class) || _class);
|
|
183
|
+
var _default = exports.default = MenuItemGroup;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const allowedProps = exports.allowedProps = ['label', 'allowMultiple', 'children', 'selected', 'defaultSelected', 'onSelect', 'onMouseOver', 'controls', 'itemRef', 'disabled', 'isTabbable'];
|