@instructure/ui-menu 8.8.1-snapshot.3 → 8.8.1-snapshot.63
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/MenuItem/index.js +14 -60
- package/es/Menu/MenuItem/props.js +67 -0
- package/es/Menu/MenuItemGroup/index.js +10 -57
- package/es/Menu/MenuItemGroup/props.js +71 -0
- package/es/Menu/MenuItemSeparator/index.js +5 -8
- package/{src/Menu/MenuItemSeparator/types.ts → es/Menu/MenuItemSeparator/props.js} +5 -5
- package/es/Menu/index.js +5 -151
- package/es/Menu/props.js +167 -0
- package/lib/Menu/MenuItem/index.js +15 -62
- package/lib/Menu/MenuItem/props.js +79 -0
- package/lib/Menu/MenuItemGroup/index.js +11 -62
- package/lib/Menu/MenuItemGroup/props.js +87 -0
- package/lib/Menu/MenuItemSeparator/index.js +6 -9
- package/{src/Menu/MenuItemGroup/types.ts → lib/Menu/MenuItemSeparator/props.js} +13 -16
- package/lib/Menu/index.js +6 -156
- package/lib/Menu/props.js +182 -0
- package/package.json +21 -21
- package/src/Menu/MenuItem/index.tsx +14 -56
- package/src/Menu/MenuItem/props.ts +109 -0
- package/src/Menu/MenuItem/styles.ts +1 -1
- package/src/Menu/MenuItemGroup/index.tsx +9 -56
- package/src/Menu/MenuItemGroup/props.ts +110 -0
- package/src/Menu/MenuItemSeparator/index.tsx +6 -9
- package/src/Menu/{MenuItem/types.ts → MenuItemSeparator/props.ts} +19 -19
- package/src/Menu/index.tsx +6 -139
- package/src/Menu/props.ts +235 -0
- package/src/index.ts +4 -4
- package/types/Menu/MenuItem/index.d.ts +37 -45
- package/types/Menu/MenuItem/index.d.ts.map +1 -1
- package/types/Menu/MenuItem/props.d.ts +27 -0
- package/types/Menu/MenuItem/props.d.ts.map +1 -0
- package/types/Menu/MenuItem/styles.d.ts +1 -1
- package/types/Menu/MenuItemGroup/index.d.ts +29 -46
- package/types/Menu/MenuItemGroup/index.d.ts.map +1 -1
- package/types/Menu/MenuItemGroup/props.d.ts +25 -0
- package/types/Menu/MenuItemGroup/props.d.ts.map +1 -0
- package/types/Menu/MenuItemSeparator/index.d.ts +3 -6
- package/types/Menu/MenuItemSeparator/index.d.ts.map +1 -1
- package/types/Menu/MenuItemSeparator/props.d.ts +11 -0
- package/types/Menu/MenuItemSeparator/props.d.ts.map +1 -0
- package/types/Menu/index.d.ts +60 -122
- package/types/Menu/index.d.ts.map +1 -1
- package/types/Menu/{types.d.ts → props.d.ts} +12 -4
- package/types/Menu/props.d.ts.map +1 -0
- package/types/index.d.ts +4 -4
- package/es/Menu/MenuItem/types.js +0 -1
- package/es/Menu/MenuItemGroup/types.js +0 -1
- package/es/Menu/MenuItemSeparator/types.js +0 -1
- package/es/Menu/types.js +0 -1
- package/lib/Menu/MenuItem/types.js +0 -1
- package/lib/Menu/MenuItemGroup/types.js +0 -1
- package/lib/Menu/MenuItemSeparator/types.js +0 -1
- package/lib/Menu/types.js +0 -1
- package/src/Menu/types.ts +0 -63
- package/types/Menu/MenuItem/types.d.ts +0 -19
- package/types/Menu/MenuItem/types.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/types.d.ts +0 -17
- package/types/Menu/MenuItemGroup/types.d.ts.map +0 -1
- package/types/Menu/MenuItemSeparator/types.d.ts +0 -5
- package/types/Menu/MenuItemSeparator/types.d.ts.map +0 -1
- package/types/Menu/types.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-menu",
|
|
3
|
-
"version": "8.8.1-snapshot.
|
|
3
|
+
"version": "8.8.1-snapshot.63+ec21bbc1d",
|
|
4
4
|
"description": "A dropdown menu component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,28 +24,28 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@instructure/
|
|
28
|
-
"@instructure/ui-
|
|
29
|
-
"@instructure/ui-
|
|
30
|
-
"@instructure/ui-test-
|
|
31
|
-
"@instructure/ui-test-
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-themes": "8.8.1-snapshot.3+d5d6d4cd8"
|
|
27
|
+
"@instructure/ui-babel-preset": "8.8.1-snapshot.63+ec21bbc1d",
|
|
28
|
+
"@instructure/ui-color-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
29
|
+
"@instructure/ui-test-locator": "8.8.1-snapshot.63+ec21bbc1d",
|
|
30
|
+
"@instructure/ui-test-queries": "8.8.1-snapshot.63+ec21bbc1d",
|
|
31
|
+
"@instructure/ui-test-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
32
|
+
"@instructure/ui-themes": "8.8.1-snapshot.63+ec21bbc1d"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"@babel/runtime": "^7.13.10",
|
|
37
|
-
"@instructure/console": "8.8.1-snapshot.
|
|
38
|
-
"@instructure/emotion": "8.8.1-snapshot.
|
|
39
|
-
"@instructure/
|
|
40
|
-
"@instructure/ui-
|
|
41
|
-
"@instructure/ui-
|
|
42
|
-
"@instructure/ui-
|
|
43
|
-
"@instructure/ui-
|
|
44
|
-
"@instructure/ui-
|
|
45
|
-
"@instructure/ui-
|
|
46
|
-
"@instructure/ui-
|
|
47
|
-
"@instructure/ui-
|
|
48
|
-
"@instructure/
|
|
36
|
+
"@instructure/console": "8.8.1-snapshot.63+ec21bbc1d",
|
|
37
|
+
"@instructure/emotion": "8.8.1-snapshot.63+ec21bbc1d",
|
|
38
|
+
"@instructure/shared-types": "8.8.1-snapshot.63+ec21bbc1d",
|
|
39
|
+
"@instructure/ui-a11y-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
40
|
+
"@instructure/ui-dom-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
41
|
+
"@instructure/ui-icons": "8.8.1-snapshot.63+ec21bbc1d",
|
|
42
|
+
"@instructure/ui-popover": "8.8.1-snapshot.63+ec21bbc1d",
|
|
43
|
+
"@instructure/ui-position": "8.8.1-snapshot.63+ec21bbc1d",
|
|
44
|
+
"@instructure/ui-prop-types": "8.8.1-snapshot.63+ec21bbc1d",
|
|
45
|
+
"@instructure/ui-react-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
46
|
+
"@instructure/ui-testable": "8.8.1-snapshot.63+ec21bbc1d",
|
|
47
|
+
"@instructure/ui-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
48
|
+
"@instructure/uid": "8.8.1-snapshot.63+ec21bbc1d",
|
|
49
49
|
"keycode": "^2",
|
|
50
50
|
"prop-types": "^15"
|
|
51
51
|
},
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ec21bbc1dcdd8567b11f2c15f5fadd16709d7e3d"
|
|
60
60
|
}
|
|
@@ -23,12 +23,10 @@
|
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
25
|
import { Component } from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
26
|
import keycode from 'keycode'
|
|
28
27
|
|
|
29
28
|
import { IconCheckSolid, IconArrowOpenEndSolid } from '@instructure/ui-icons'
|
|
30
29
|
import { uid } from '@instructure/uid'
|
|
31
|
-
import { controllable } from '@instructure/ui-prop-types'
|
|
32
30
|
import { omitProps, getElementType } from '@instructure/ui-react-utils'
|
|
33
31
|
import { createChainedFunction } from '@instructure/ui-utils'
|
|
34
32
|
import { isActiveElement, findDOMNode } from '@instructure/ui-dom-utils'
|
|
@@ -39,7 +37,9 @@ import { MenuContext } from '../../MenuContext'
|
|
|
39
37
|
|
|
40
38
|
import generateStyle from './styles'
|
|
41
39
|
import generateComponentTheme from './theme'
|
|
42
|
-
|
|
40
|
+
|
|
41
|
+
import { propTypes, allowedProps } from './props'
|
|
42
|
+
import type { MenuItemProps } from './props'
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
---
|
|
@@ -52,56 +52,14 @@ id: Menu.Item
|
|
|
52
52
|
class MenuItem extends Component<MenuItemProps> {
|
|
53
53
|
static readonly componentId = 'Menu.Item'
|
|
54
54
|
|
|
55
|
-
static propTypes =
|
|
56
|
-
|
|
57
|
-
makeStyles: PropTypes.func,
|
|
58
|
-
// eslint-disable-next-line react/require-default-props
|
|
59
|
-
styles: PropTypes.object,
|
|
60
|
-
/* the menu item label */
|
|
61
|
-
children: PropTypes.node.isRequired,
|
|
62
|
-
/* whether to set the menu item state to selected or not on initial render */
|
|
63
|
-
defaultSelected: PropTypes.bool,
|
|
64
|
-
/**
|
|
65
|
-
* whether the menu item is selected or not (must be accompanied by an `onSelect` prop)
|
|
66
|
-
*/
|
|
67
|
-
selected: controllable(PropTypes.bool, 'onSelect', 'defaultSelected'),
|
|
68
|
-
/**
|
|
69
|
-
* when used with the `selected` prop, the component will not control its own state
|
|
70
|
-
*/
|
|
71
|
-
onSelect: PropTypes.func,
|
|
72
|
-
onClick: PropTypes.func,
|
|
73
|
-
onKeyDown: PropTypes.func,
|
|
74
|
-
onKeyUp: PropTypes.func,
|
|
75
|
-
onMouseOver: PropTypes.func,
|
|
76
|
-
/**
|
|
77
|
-
* the id of the element that the menu item will act upon
|
|
78
|
-
*/
|
|
79
|
-
controls: PropTypes.string,
|
|
80
|
-
disabled: PropTypes.bool,
|
|
81
|
-
/**
|
|
82
|
-
* the element type to render as (will default to `<a>` if href is provided)
|
|
83
|
-
*/
|
|
84
|
-
as: PropTypes.elementType, // eslint-disable-line react/require-default-props
|
|
85
|
-
type: PropTypes.oneOf(['button', 'checkbox', 'radio', 'flyout']),
|
|
86
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
87
|
-
href: PropTypes.string
|
|
88
|
-
}
|
|
89
|
-
|
|
55
|
+
static propTypes = propTypes
|
|
56
|
+
static allowedProps = allowedProps
|
|
90
57
|
static defaultProps = {
|
|
91
58
|
type: 'button',
|
|
92
59
|
disabled: false,
|
|
93
60
|
// @ts-expect-error ts-migrate(6133) FIXME: 'e' is declared but its value is never read.
|
|
94
|
-
onSelect: function (e, value, selected, item) {}
|
|
95
|
-
|
|
96
|
-
selected: undefined,
|
|
97
|
-
onClick: undefined,
|
|
98
|
-
onKeyDown: undefined,
|
|
99
|
-
onKeyUp: undefined,
|
|
100
|
-
onMouseOver: undefined,
|
|
101
|
-
controls: undefined,
|
|
102
|
-
value: undefined,
|
|
103
|
-
href: undefined
|
|
104
|
-
}
|
|
61
|
+
onSelect: function (e, value, selected, item) {}
|
|
62
|
+
} as const
|
|
105
63
|
|
|
106
64
|
static contextType = MenuContext
|
|
107
65
|
|
|
@@ -249,16 +207,16 @@ class MenuItem extends Component<MenuItemProps> {
|
|
|
249
207
|
return (
|
|
250
208
|
<span>
|
|
251
209
|
{(type === 'checkbox' || type === 'radio') && (
|
|
252
|
-
<span css={this.props.styles
|
|
210
|
+
<span css={this.props.styles?.icon}>
|
|
253
211
|
{this.selected && <IconCheckSolid />}
|
|
254
212
|
</span>
|
|
255
213
|
)}
|
|
256
214
|
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'labelId' does not exist on type 'MenuIte... Remove this comment to see the full error message */}
|
|
257
|
-
<span css={this.props.styles
|
|
215
|
+
<span css={this.props.styles?.label} id={this.labelId}>
|
|
258
216
|
{children}
|
|
259
217
|
</span>
|
|
260
218
|
{type === 'flyout' && (
|
|
261
|
-
<span css={this.props.styles
|
|
219
|
+
<span css={this.props.styles?.icon}>
|
|
262
220
|
<IconArrowOpenEndSolid />
|
|
263
221
|
</span>
|
|
264
222
|
)}
|
|
@@ -274,20 +232,20 @@ class MenuItem extends Component<MenuItemProps> {
|
|
|
274
232
|
|
|
275
233
|
return (
|
|
276
234
|
<ElementType // eslint-disable-line jsx-a11y/mouse-events-have-key-events
|
|
277
|
-
tabIndex=
|
|
235
|
+
tabIndex={-1} // note: tabIndex can be overridden by Menu or MenuItemGroup components
|
|
278
236
|
{...props}
|
|
279
237
|
href={href}
|
|
280
238
|
role={this.role}
|
|
281
239
|
// @ts-expect-error ts-migrate(2339) FIXME: Property 'labelId' does not exist on type 'MenuIte... Remove this comment to see the full error message
|
|
282
240
|
aria-labelledby={this.labelId}
|
|
283
|
-
aria-disabled={disabled ? 'true' :
|
|
241
|
+
aria-disabled={disabled ? 'true' : undefined}
|
|
284
242
|
aria-controls={controls}
|
|
285
243
|
aria-checked={
|
|
286
244
|
type === 'checkbox' || type === 'radio'
|
|
287
245
|
? this.selected
|
|
288
246
|
? 'true'
|
|
289
247
|
: 'false'
|
|
290
|
-
:
|
|
248
|
+
: undefined
|
|
291
249
|
}
|
|
292
250
|
onClick={this.handleClick}
|
|
293
251
|
onKeyUp={createChainedFunction(onKeyUp, this.handleKeyUp)}
|
|
@@ -297,7 +255,7 @@ class MenuItem extends Component<MenuItemProps> {
|
|
|
297
255
|
// @ts-expect-error ts-migrate(2339) FIXME: Property '_node' does not exist on type 'MenuItem'... Remove this comment to see the full error message
|
|
298
256
|
this._node = c
|
|
299
257
|
}}
|
|
300
|
-
css={this.props.styles
|
|
258
|
+
css={this.props.styles?.menuItem}
|
|
301
259
|
onMouseOver={this.handleMouseOver}
|
|
302
260
|
>
|
|
303
261
|
{this.renderContent()}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import PropTypes from 'prop-types'
|
|
27
|
+
|
|
28
|
+
import { controllable } from '@instructure/ui-prop-types'
|
|
29
|
+
|
|
30
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
31
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
|
32
|
+
|
|
33
|
+
type MenuItemOwnProps = {
|
|
34
|
+
children: React.ReactNode
|
|
35
|
+
defaultSelected?: boolean
|
|
36
|
+
selected?: any // TODO: controllable(PropTypes.bool, 'onSelect', 'defaultSelected')
|
|
37
|
+
onSelect?: (...args: any[]) => any
|
|
38
|
+
onClick?: (...args: any[]) => any
|
|
39
|
+
onKeyDown?: (...args: any[]) => any
|
|
40
|
+
onKeyUp?: (...args: any[]) => any
|
|
41
|
+
onMouseOver?: (...args: any[]) => any
|
|
42
|
+
controls?: string
|
|
43
|
+
disabled?: boolean
|
|
44
|
+
as?: AsElementType
|
|
45
|
+
type?: 'button' | 'checkbox' | 'radio' | 'flyout'
|
|
46
|
+
value?: string | number
|
|
47
|
+
href?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type PropKeys = keyof MenuItemOwnProps
|
|
51
|
+
|
|
52
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
53
|
+
|
|
54
|
+
type MenuItemProps = MenuItemOwnProps & WithStyleProps
|
|
55
|
+
|
|
56
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
57
|
+
/**
|
|
58
|
+
* the menu item label
|
|
59
|
+
*/
|
|
60
|
+
children: PropTypes.node.isRequired,
|
|
61
|
+
/**
|
|
62
|
+
* whether to set the menu item state to selected or not on initial render
|
|
63
|
+
*/
|
|
64
|
+
defaultSelected: PropTypes.bool,
|
|
65
|
+
/**
|
|
66
|
+
* whether the menu item is selected or not (must be accompanied by an `onSelect` prop)
|
|
67
|
+
*/
|
|
68
|
+
selected: controllable(PropTypes.bool, 'onSelect', 'defaultSelected'),
|
|
69
|
+
/**
|
|
70
|
+
* when used with the `selected` prop, the component will not control its own state
|
|
71
|
+
*/
|
|
72
|
+
onSelect: PropTypes.func,
|
|
73
|
+
onClick: PropTypes.func,
|
|
74
|
+
onKeyDown: PropTypes.func,
|
|
75
|
+
onKeyUp: PropTypes.func,
|
|
76
|
+
onMouseOver: PropTypes.func,
|
|
77
|
+
/**
|
|
78
|
+
* the id of the element that the menu item will act upon
|
|
79
|
+
*/
|
|
80
|
+
controls: PropTypes.string,
|
|
81
|
+
disabled: PropTypes.bool,
|
|
82
|
+
/**
|
|
83
|
+
* the element type to render as (will default to `<a>` if href is provided)
|
|
84
|
+
*/
|
|
85
|
+
as: PropTypes.elementType, // eslint-disable-line react/require-default-props
|
|
86
|
+
type: PropTypes.oneOf(['button', 'checkbox', 'radio', 'flyout']),
|
|
87
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
88
|
+
href: PropTypes.string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const allowedProps: AllowedPropKeys = [
|
|
92
|
+
'children',
|
|
93
|
+
'defaultSelected',
|
|
94
|
+
'selected',
|
|
95
|
+
'onSelect',
|
|
96
|
+
'onClick',
|
|
97
|
+
'onKeyDown',
|
|
98
|
+
'onKeyUp',
|
|
99
|
+
'onMouseOver',
|
|
100
|
+
'controls',
|
|
101
|
+
'disabled',
|
|
102
|
+
'as',
|
|
103
|
+
'type',
|
|
104
|
+
'value',
|
|
105
|
+
'href'
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
export type { MenuItemProps }
|
|
109
|
+
export { propTypes, allowedProps }
|
|
@@ -24,13 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
26
|
import { Children, Component, ReactElement } from 'react'
|
|
27
|
-
import PropTypes from 'prop-types'
|
|
28
27
|
|
|
29
28
|
import { withStyle, jsx } from '@instructure/emotion'
|
|
30
|
-
import {
|
|
31
|
-
controllable,
|
|
32
|
-
Children as ChildrenPropTypes
|
|
33
|
-
} from '@instructure/ui-prop-types'
|
|
34
29
|
import {
|
|
35
30
|
omitProps,
|
|
36
31
|
safeCloneElement,
|
|
@@ -41,11 +36,12 @@ import { hasVisibleChildren } from '@instructure/ui-a11y-utils'
|
|
|
41
36
|
import { testable } from '@instructure/ui-testable'
|
|
42
37
|
|
|
43
38
|
import { MenuItem } from '../MenuItem'
|
|
44
|
-
import { MenuItemSeparator } from '../MenuItemSeparator'
|
|
45
39
|
|
|
46
40
|
import generateStyle from './styles'
|
|
47
41
|
import generateComponentTheme from './theme'
|
|
48
|
-
|
|
42
|
+
|
|
43
|
+
import { propTypes, allowedProps } from './props'
|
|
44
|
+
import type { MenuGroupProps } from './props'
|
|
49
45
|
|
|
50
46
|
/**
|
|
51
47
|
---
|
|
@@ -58,52 +54,10 @@ id: Menu.Group
|
|
|
58
54
|
class MenuItemGroup extends Component<MenuGroupProps> {
|
|
59
55
|
static readonly componentId = 'Menu.Group'
|
|
60
56
|
|
|
61
|
-
static propTypes =
|
|
62
|
-
|
|
63
|
-
makeStyles: PropTypes.func,
|
|
64
|
-
// eslint-disable-next-line react/require-default-props
|
|
65
|
-
styles: PropTypes.object,
|
|
66
|
-
label: PropTypes.node.isRequired,
|
|
67
|
-
allowMultiple: PropTypes.bool,
|
|
68
|
-
/**
|
|
69
|
-
* children of type `Menu.Item`, `Menu.Separator`
|
|
70
|
-
*/
|
|
71
|
-
children: ChildrenPropTypes.oneOf([MenuItem, MenuItemSeparator]),
|
|
72
|
-
/**
|
|
73
|
-
* an array of the values (or indices by default) for the selected items
|
|
74
|
-
*/
|
|
75
|
-
selected: controllable(PropTypes.array, 'onSelect', 'defaultSelected'),
|
|
76
|
-
/**
|
|
77
|
-
* an array of the values (or indices by default) for the selected items on initial render
|
|
78
|
-
*/
|
|
79
|
-
defaultSelected: PropTypes.array,
|
|
80
|
-
/**
|
|
81
|
-
* call this function when a menu item is selected
|
|
82
|
-
*/
|
|
83
|
-
onSelect: PropTypes.func,
|
|
84
|
-
onMouseOver: PropTypes.func,
|
|
85
|
-
onKeyDown: PropTypes.func,
|
|
86
|
-
/**
|
|
87
|
-
* the id of the element that the menu items will act upon
|
|
88
|
-
*/
|
|
89
|
-
controls: PropTypes.string,
|
|
90
|
-
/**
|
|
91
|
-
* returns a reference to the `MenuItem`
|
|
92
|
-
*/
|
|
93
|
-
itemRef: PropTypes.func,
|
|
94
|
-
disabled: PropTypes.bool,
|
|
95
|
-
/**
|
|
96
|
-
* should the group appear in the tab order (the first item will have a tabIndex of 0)
|
|
97
|
-
*/
|
|
98
|
-
isTabbable: PropTypes.bool
|
|
99
|
-
}
|
|
100
|
-
|
|
57
|
+
static propTypes = propTypes
|
|
58
|
+
static allowedProps = allowedProps
|
|
101
59
|
static defaultProps = {
|
|
102
|
-
onMouseOver: undefined,
|
|
103
60
|
disabled: false,
|
|
104
|
-
controls: undefined,
|
|
105
|
-
onKeyDown: undefined,
|
|
106
|
-
selected: undefined,
|
|
107
61
|
children: null,
|
|
108
62
|
isTabbable: false,
|
|
109
63
|
allowMultiple: false,
|
|
@@ -230,7 +184,7 @@ class MenuItemGroup extends Component<MenuGroupProps> {
|
|
|
230
184
|
const { label } = this.props
|
|
231
185
|
|
|
232
186
|
return hasVisibleChildren(label) ? (
|
|
233
|
-
<span css={this.props.styles
|
|
187
|
+
<span css={this.props.styles?.label}>{label}</span>
|
|
234
188
|
) : (
|
|
235
189
|
label
|
|
236
190
|
)
|
|
@@ -282,16 +236,15 @@ class MenuItemGroup extends Component<MenuGroupProps> {
|
|
|
282
236
|
return (
|
|
283
237
|
<span
|
|
284
238
|
{...props}
|
|
285
|
-
css={this.props.styles
|
|
239
|
+
css={this.props.styles?.menuItemGroup}
|
|
286
240
|
role="presentation"
|
|
287
241
|
>
|
|
288
242
|
{/* @ts-expect-error ts-migrate(2339) FIXME: Property '_labelId' does not exist on type 'MenuIt... Remove this comment to see the full error message */}
|
|
289
243
|
<span id={this._labelId}>{this.renderLabel()}</span>
|
|
290
244
|
<ul
|
|
291
245
|
role="menu"
|
|
292
|
-
css={this.props.styles
|
|
293
|
-
|
|
294
|
-
aria-disabled={this.props.disabled ? 'true' : null}
|
|
246
|
+
css={this.props.styles?.items}
|
|
247
|
+
aria-disabled={this.props.disabled ? 'true' : undefined}
|
|
295
248
|
// @ts-expect-error ts-migrate(2339) FIXME: Property '_labelId' does not exist on type 'MenuIt... Remove this comment to see the full error message
|
|
296
249
|
aria-labelledby={this._labelId}
|
|
297
250
|
>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import PropTypes from 'prop-types'
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
controllable,
|
|
29
|
+
Children as ChildrenPropTypes
|
|
30
|
+
} from '@instructure/ui-prop-types'
|
|
31
|
+
import { MenuItem } from '../MenuItem'
|
|
32
|
+
import { MenuItemSeparator } from '../MenuItemSeparator'
|
|
33
|
+
|
|
34
|
+
import type { PropValidators } from '@instructure/shared-types'
|
|
35
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
|
36
|
+
|
|
37
|
+
type MenuGroupOwnProps = {
|
|
38
|
+
label: React.ReactNode
|
|
39
|
+
allowMultiple?: boolean
|
|
40
|
+
children?: React.ReactNode // TODO: oneOf([MenuItem, MenuItemSeparator])
|
|
41
|
+
selected?: any // TODO: controllable(PropTypes.array, 'onSelect', 'defaultSelected')
|
|
42
|
+
defaultSelected?: any[]
|
|
43
|
+
onSelect?: (...args: any[]) => any
|
|
44
|
+
onMouseOver?: (...args: any[]) => any
|
|
45
|
+
onKeyDown?: (...args: any[]) => any
|
|
46
|
+
controls?: string
|
|
47
|
+
itemRef?: (...args: any[]) => any
|
|
48
|
+
disabled?: boolean
|
|
49
|
+
isTabbable?: boolean
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type PropKeys = keyof MenuGroupOwnProps
|
|
53
|
+
|
|
54
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
55
|
+
|
|
56
|
+
type MenuGroupProps = MenuGroupOwnProps & WithStyleProps
|
|
57
|
+
|
|
58
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
59
|
+
label: PropTypes.node.isRequired,
|
|
60
|
+
allowMultiple: PropTypes.bool,
|
|
61
|
+
/**
|
|
62
|
+
* children of type `Menu.Item`, `Menu.Separator`
|
|
63
|
+
*/
|
|
64
|
+
children: ChildrenPropTypes.oneOf([MenuItem, MenuItemSeparator]),
|
|
65
|
+
/**
|
|
66
|
+
* an array of the values (or indices by default) for the selected items
|
|
67
|
+
*/
|
|
68
|
+
selected: controllable(PropTypes.array, 'onSelect', 'defaultSelected'),
|
|
69
|
+
/**
|
|
70
|
+
* an array of the values (or indices by default) for the selected items on initial render
|
|
71
|
+
*/
|
|
72
|
+
defaultSelected: PropTypes.array,
|
|
73
|
+
/**
|
|
74
|
+
* call this function when a menu item is selected
|
|
75
|
+
*/
|
|
76
|
+
onSelect: PropTypes.func,
|
|
77
|
+
onMouseOver: PropTypes.func,
|
|
78
|
+
onKeyDown: PropTypes.func,
|
|
79
|
+
/**
|
|
80
|
+
* the id of the element that the menu items will act upon
|
|
81
|
+
*/
|
|
82
|
+
controls: PropTypes.string,
|
|
83
|
+
/**
|
|
84
|
+
* returns a reference to the `MenuItem`
|
|
85
|
+
*/
|
|
86
|
+
itemRef: PropTypes.func,
|
|
87
|
+
disabled: PropTypes.bool,
|
|
88
|
+
/**
|
|
89
|
+
* should the group appear in the tab order (the first item will have a tabIndex of 0)
|
|
90
|
+
*/
|
|
91
|
+
isTabbable: PropTypes.bool
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const allowedProps: AllowedPropKeys = [
|
|
95
|
+
'label',
|
|
96
|
+
'allowMultiple',
|
|
97
|
+
'children',
|
|
98
|
+
'selected',
|
|
99
|
+
'defaultSelected',
|
|
100
|
+
'onSelect',
|
|
101
|
+
'onMouseOver',
|
|
102
|
+
'onKeyDown',
|
|
103
|
+
'controls',
|
|
104
|
+
'itemRef',
|
|
105
|
+
'disabled',
|
|
106
|
+
'isTabbable'
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
export type { MenuGroupProps }
|
|
110
|
+
export { propTypes, allowedProps }
|