@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.
Files changed (61) hide show
  1. package/es/Menu/MenuItem/index.js +14 -60
  2. package/es/Menu/MenuItem/props.js +67 -0
  3. package/es/Menu/MenuItemGroup/index.js +10 -57
  4. package/es/Menu/MenuItemGroup/props.js +71 -0
  5. package/es/Menu/MenuItemSeparator/index.js +5 -8
  6. package/{src/Menu/MenuItemSeparator/types.ts → es/Menu/MenuItemSeparator/props.js} +5 -5
  7. package/es/Menu/index.js +5 -151
  8. package/es/Menu/props.js +167 -0
  9. package/lib/Menu/MenuItem/index.js +15 -62
  10. package/lib/Menu/MenuItem/props.js +79 -0
  11. package/lib/Menu/MenuItemGroup/index.js +11 -62
  12. package/lib/Menu/MenuItemGroup/props.js +87 -0
  13. package/lib/Menu/MenuItemSeparator/index.js +6 -9
  14. package/{src/Menu/MenuItemGroup/types.ts → lib/Menu/MenuItemSeparator/props.js} +13 -16
  15. package/lib/Menu/index.js +6 -156
  16. package/lib/Menu/props.js +182 -0
  17. package/package.json +21 -21
  18. package/src/Menu/MenuItem/index.tsx +14 -56
  19. package/src/Menu/MenuItem/props.ts +109 -0
  20. package/src/Menu/MenuItem/styles.ts +1 -1
  21. package/src/Menu/MenuItemGroup/index.tsx +9 -56
  22. package/src/Menu/MenuItemGroup/props.ts +110 -0
  23. package/src/Menu/MenuItemSeparator/index.tsx +6 -9
  24. package/src/Menu/{MenuItem/types.ts → MenuItemSeparator/props.ts} +19 -19
  25. package/src/Menu/index.tsx +6 -139
  26. package/src/Menu/props.ts +235 -0
  27. package/src/index.ts +4 -4
  28. package/types/Menu/MenuItem/index.d.ts +37 -45
  29. package/types/Menu/MenuItem/index.d.ts.map +1 -1
  30. package/types/Menu/MenuItem/props.d.ts +27 -0
  31. package/types/Menu/MenuItem/props.d.ts.map +1 -0
  32. package/types/Menu/MenuItem/styles.d.ts +1 -1
  33. package/types/Menu/MenuItemGroup/index.d.ts +29 -46
  34. package/types/Menu/MenuItemGroup/index.d.ts.map +1 -1
  35. package/types/Menu/MenuItemGroup/props.d.ts +25 -0
  36. package/types/Menu/MenuItemGroup/props.d.ts.map +1 -0
  37. package/types/Menu/MenuItemSeparator/index.d.ts +3 -6
  38. package/types/Menu/MenuItemSeparator/index.d.ts.map +1 -1
  39. package/types/Menu/MenuItemSeparator/props.d.ts +11 -0
  40. package/types/Menu/MenuItemSeparator/props.d.ts.map +1 -0
  41. package/types/Menu/index.d.ts +60 -122
  42. package/types/Menu/index.d.ts.map +1 -1
  43. package/types/Menu/{types.d.ts → props.d.ts} +12 -4
  44. package/types/Menu/props.d.ts.map +1 -0
  45. package/types/index.d.ts +4 -4
  46. package/es/Menu/MenuItem/types.js +0 -1
  47. package/es/Menu/MenuItemGroup/types.js +0 -1
  48. package/es/Menu/MenuItemSeparator/types.js +0 -1
  49. package/es/Menu/types.js +0 -1
  50. package/lib/Menu/MenuItem/types.js +0 -1
  51. package/lib/Menu/MenuItemGroup/types.js +0 -1
  52. package/lib/Menu/MenuItemSeparator/types.js +0 -1
  53. package/lib/Menu/types.js +0 -1
  54. package/src/Menu/types.ts +0 -63
  55. package/types/Menu/MenuItem/types.d.ts +0 -19
  56. package/types/Menu/MenuItem/types.d.ts.map +0 -1
  57. package/types/Menu/MenuItemGroup/types.d.ts +0 -17
  58. package/types/Menu/MenuItemGroup/types.d.ts.map +0 -1
  59. package/types/Menu/MenuItemSeparator/types.d.ts +0 -5
  60. package/types/Menu/MenuItemSeparator/types.d.ts.map +0 -1
  61. package/types/Menu/types.d.ts.map +0 -1
@@ -24,7 +24,6 @@
24
24
 
25
25
  /** @jsx jsx */
26
26
  import { Component } from 'react'
27
- import PropTypes from 'prop-types'
28
27
 
29
28
  import { withStyle, jsx } from '@instructure/emotion'
30
29
  import { testable } from '@instructure/ui-testable'
@@ -32,7 +31,9 @@ import { omitProps } from '@instructure/ui-react-utils'
32
31
 
33
32
  import generateStyle from './styles'
34
33
  import generateComponentTheme from './theme'
35
- import { MenuSeparatorProps } from './types'
34
+
35
+ import { propTypes, allowedProps } from './props'
36
+ import type { MenuSeparatorProps } from './props'
36
37
 
37
38
  /**
38
39
  ---
@@ -46,12 +47,8 @@ id: Menu.Separator
46
47
  class MenuItemSeparator extends Component<MenuSeparatorProps> {
47
48
  static readonly componentId = 'Menu.Separator'
48
49
 
49
- static propTypes = {
50
- // eslint-disable-next-line react/require-default-props
51
- makeStyles: PropTypes.func,
52
- // eslint-disable-next-line react/require-default-props
53
- styles: PropTypes.object
54
- }
50
+ static propTypes = propTypes
51
+ static allowedProps = allowedProps
55
52
 
56
53
  componentDidMount() {
57
54
  // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
@@ -69,7 +66,7 @@ class MenuItemSeparator extends Component<MenuSeparatorProps> {
69
66
  <div
70
67
  {...props}
71
68
  role="presentation"
72
- css={this.props.styles.menuItemSeparator}
69
+ css={this.props.styles?.menuItemSeparator}
73
70
  />
74
71
  )
75
72
  }
@@ -22,22 +22,22 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import { AsElementType } from '@instructure/shared-types'
26
-
27
- export type MenuItemProps = {
28
- makeStyles?: (...args: any[]) => any
29
- styles?: any
30
- defaultSelected?: boolean
31
- selected?: any // TODO: controllable(PropTypes.bool, 'onSelect', 'defaultSelected')
32
- onSelect?: (...args: any[]) => any
33
- onClick?: (...args: any[]) => any
34
- onKeyDown?: (...args: any[]) => any
35
- onKeyUp?: (...args: any[]) => any
36
- onMouseOver?: (...args: any[]) => any
37
- controls?: string
38
- disabled?: boolean
39
- as?: AsElementType
40
- type?: 'button' | 'checkbox' | 'radio' | 'flyout'
41
- value?: string | number
42
- href?: string
43
- }
25
+ import type { WithStyleProps } from '@instructure/emotion'
26
+ import type { PropValidators } from '@instructure/shared-types'
27
+
28
+ // keeping here to keep the structure of props.ts
29
+ // eslint-disable-next-line
30
+ type MenuSeparatorOwnProps = {}
31
+
32
+ type PropKeys = keyof MenuSeparatorOwnProps
33
+
34
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
35
+
36
+ type MenuSeparatorProps = MenuSeparatorOwnProps & WithStyleProps
37
+
38
+ const propTypes: PropValidators<PropKeys> = {}
39
+
40
+ const allowedProps: AllowedPropKeys = []
41
+
42
+ export type { MenuSeparatorProps }
43
+ export { propTypes, allowedProps }
@@ -23,16 +23,10 @@
23
23
  */
24
24
  /** @jsx jsx */
25
25
  import { Children, Component, ReactElement } from 'react'
26
- import PropTypes from 'prop-types'
27
26
  import keycode from 'keycode'
28
27
 
29
28
  import { Popover } from '@instructure/ui-popover'
30
29
  import { uid } from '@instructure/uid'
31
- import {
32
- controllable,
33
- Children as ChildrenPropTypes
34
- } from '@instructure/ui-prop-types'
35
- import { PositionPropTypes } from '@instructure/ui-position'
36
30
  import {
37
31
  safeCloneElement,
38
32
  matchComponentTypes
@@ -49,7 +43,9 @@ import { withStyle, jsx } from '@instructure/emotion'
49
43
 
50
44
  import generateStyle from './styles'
51
45
  import generateComponentTheme from './theme'
52
- import { MenuProps } from './types'
46
+
47
+ import { propTypes, allowedProps } from './props'
48
+ import type { MenuProps } from './props'
53
49
 
54
50
  /**
55
51
  ---
@@ -61,134 +57,8 @@ category: components
61
57
  class Menu extends Component<MenuProps> {
62
58
  static readonly componentId = 'Menu'
63
59
 
64
- static propTypes = {
65
- // eslint-disable-next-line react/require-default-props
66
- makeStyles: PropTypes.func,
67
- // eslint-disable-next-line react/require-default-props
68
- styles: PropTypes.object,
69
- /**
70
- * Children of type `Menu.Item`, `Menu.Group`, `Menu.Separator`, or `Menu`
71
- */
72
- children: ChildrenPropTypes.oneOf([
73
- 'MenuItem',
74
- 'MenuItemGroup',
75
- 'MenuItemSeparator',
76
- 'Menu'
77
- ]),
78
- /**
79
- * Description of the `<Menu />`
80
- */
81
- label: PropTypes.string,
82
- /**
83
- * Is the `<Menu />` disabled
84
- */
85
- disabled: PropTypes.bool,
86
- /**
87
- * The trigger element, if the `<Menu />` is to render as a popover
88
- */
89
- trigger: PropTypes.node,
90
- /**
91
- * If a trigger is supplied, where should the `<Menu />` be placed (relative to the trigger)
92
- */
93
- placement: PositionPropTypes.placement,
94
- /**
95
- * Should the `<Menu />` be open for the initial render
96
- */
97
- defaultShow: PropTypes.bool,
98
- /**
99
- * Is the `<Menu />` open (should be accompanied by `onToggle`)
100
- */
101
- show: controllable(PropTypes.bool, 'onToggle', 'defaultShow'),
102
- /**
103
- * Callback fired when the `<Menu />` is toggled open/closed. When used with `show`,
104
- * the component will not control its own state.
105
- */
106
- onToggle: PropTypes.func,
107
- /**
108
- * Callback fired when an item within the `<Menu />` is selected
109
- */
110
- onSelect: PropTypes.func,
111
- /**
112
- * If a trigger is supplied, callback fired when the `<Menu />` is closed
113
- */
114
- onDismiss: PropTypes.func,
115
- /**
116
- * If a trigger is supplied, callback fired when the `<Menu />` trigger is blurred
117
- */
118
- onBlur: PropTypes.func,
119
- /**
120
- * If a trigger is supplied, callback fired when the `<Menu />` trigger is focused
121
- */
122
- onFocus: PropTypes.func,
123
- /**
124
- * If a trigger is supplied, callback fired onMouseOver for the `<Menu />` trigger
125
- */
126
- onMouseOver: PropTypes.func,
127
- /**
128
- * Callback fired on the onKeyDown of the `<Menu />`
129
- */
130
- onKeyDown: PropTypes.func,
131
- /**
132
- * Callback fired on the onKeyUp of the `<Menu />`
133
- */
134
- onKeyUp: PropTypes.func,
135
- /*
136
- * A function that returns a reference to the `<Menu />`
137
- */
138
- menuRef: PropTypes.func,
139
- /**
140
- * A function that returns a reference to the `<Popover />`
141
- */
142
- popoverRef: PropTypes.func,
143
- /**
144
- * If a trigger is supplied, an element or a function returning an element to use as the mount node
145
- * for the `<Menu />` (defaults to `document.body`)
146
- */
147
- mountNode: PositionPropTypes.mountNode,
148
- /**
149
- * The parent in which to constrain the menu.
150
- * One of: 'window', 'scroll-parent', 'parent', 'none', an element,
151
- * or a function returning an element
152
- */
153
- constrain: PositionPropTypes.constrain,
154
- /**
155
- * If a trigger is supplied, an element, function returning an element, or array of elements that will not
156
- * be hidden from the screen reader when the `<Menu />` is open
157
- */
158
- liveRegion: PropTypes.oneOfType([
159
- PropTypes.arrayOf(PropTypes.element),
160
- PropTypes.element,
161
- PropTypes.func
162
- ]),
163
- /**
164
- * If a trigger is supplied, should the `<Menu />` hide when an item is selected
165
- */
166
- shouldHideOnSelect: PropTypes.bool,
167
- /**
168
- * If a trigger is supplied, should the `<Menu />` focus the trigger on after closing
169
- */
170
- shouldFocusTriggerOnClose: PropTypes.bool,
171
- /**
172
- * The type of `<Menu />`
173
- */
174
- type: PropTypes.oneOf(['flyout']),
175
- id: PropTypes.string,
176
- /**
177
- * Whether or not an arrow pointing to the trigger should be rendered
178
- */
179
- withArrow: PropTypes.bool,
180
- /**
181
- * The horizontal offset for the positioned content.
182
- * Works only if `trigger` is provided.
183
- */
184
- offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
185
- /**
186
- * The vertical offset for the positioned content.
187
- * Works only if `trigger` is provided.
188
- */
189
- offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
190
- }
191
-
60
+ static propTypes = propTypes
61
+ static allowedProps = allowedProps
192
62
  static defaultProps = {
193
63
  children: null,
194
64
  label: null,
@@ -221,9 +91,6 @@ class Menu extends Component<MenuProps> {
221
91
  liveRegion: null,
222
92
  shouldHideOnSelect: true,
223
93
  shouldFocusTriggerOnClose: true,
224
- show: undefined,
225
- id: undefined,
226
- type: undefined,
227
94
  withArrow: true,
228
95
  offsetX: 0,
229
96
  offsetY: 0
@@ -595,7 +462,7 @@ class Menu extends Component<MenuProps> {
595
462
  aria-label={label}
596
463
  // @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'number | ... Remove this comment to see the full error message
597
464
  tabIndex="0"
598
- css={this.props.styles.menu}
465
+ css={this.props.styles?.menu}
599
466
  aria-labelledby={labelledBy || (trigger && this._labelId)}
600
467
  aria-controls={controls}
601
468
  // @ts-expect-error ts-migrate(2322) FIXME: Type '"true" | null' is not assignable to type 'bo... Remove this comment to see the full error message
@@ -0,0 +1,235 @@
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 { PositionPropTypes } from '@instructure/ui-position'
28
+ import {
29
+ controllable,
30
+ Children as ChildrenPropTypes
31
+ } from '@instructure/ui-prop-types'
32
+
33
+ import type { PropValidators } from '@instructure/shared-types'
34
+ import type { WithStyleProps } from '@instructure/emotion'
35
+ import type {
36
+ PlacementPropValues,
37
+ PositionConstraint,
38
+ PositionMountNode
39
+ } from '@instructure/ui-position'
40
+
41
+ type MenuOwnProps = {
42
+ children?: React.ReactNode // TODO: oneOf(['MenuItem', 'MenuItemGroup', 'MenuItemSeparator', 'Menu'])
43
+ label?: string
44
+ disabled?: boolean
45
+ trigger?: React.ReactNode
46
+ placement?: PlacementPropValues
47
+ defaultShow?: boolean
48
+ show?: any // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultShow')
49
+ onToggle?: (...args: any[]) => any
50
+ onSelect?: (...args: any[]) => any
51
+ onDismiss?: (...args: any[]) => any
52
+ onBlur?: (...args: any[]) => any
53
+ onFocus?: (...args: any[]) => any
54
+ onMouseOver?: (...args: any[]) => any
55
+ onKeyDown?: (...args: any[]) => any
56
+ onKeyUp?: (...args: any[]) => any
57
+ menuRef?: (...args: any[]) => any
58
+ popoverRef?: (...args: any[]) => any
59
+ mountNode?: PositionMountNode
60
+ constrain?: PositionConstraint
61
+ liveRegion?:
62
+ | React.ReactElement[]
63
+ | React.ReactElement
64
+ | ((...args: any[]) => any)
65
+ shouldHideOnSelect?: boolean
66
+ shouldFocusTriggerOnClose?: boolean
67
+ type?: 'flyout'
68
+ id?: string
69
+ withArrow?: boolean
70
+ offsetX?: string | number
71
+ offsetY?: string | number
72
+ }
73
+
74
+ type PropKeys = keyof MenuOwnProps
75
+
76
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
77
+
78
+ type MenuProps = MenuOwnProps & WithStyleProps
79
+
80
+ const propTypes: PropValidators<PropKeys> = {
81
+ /**
82
+ * Children of type `Menu.Item`, `Menu.Group`, `Menu.Separator`, or `Menu`
83
+ */
84
+ children: ChildrenPropTypes.oneOf([
85
+ 'MenuItem',
86
+ 'MenuItemGroup',
87
+ 'MenuItemSeparator',
88
+ 'Menu'
89
+ ]),
90
+ /**
91
+ * Description of the `<Menu />`
92
+ */
93
+ label: PropTypes.string,
94
+ /**
95
+ * Is the `<Menu />` disabled
96
+ */
97
+ disabled: PropTypes.bool,
98
+ /**
99
+ * The trigger element, if the `<Menu />` is to render as a popover
100
+ */
101
+ trigger: PropTypes.node,
102
+ /**
103
+ * If a trigger is supplied, where should the `<Menu />` be placed (relative to the trigger)
104
+ */
105
+ placement: PositionPropTypes.placement,
106
+ /**
107
+ * Should the `<Menu />` be open for the initial render
108
+ */
109
+ defaultShow: PropTypes.bool,
110
+ /**
111
+ * Is the `<Menu />` open (should be accompanied by `onToggle`)
112
+ */
113
+ show: controllable(PropTypes.bool, 'onToggle', 'defaultShow'),
114
+ /**
115
+ * Callback fired when the `<Menu />` is toggled open/closed. When used with `show`,
116
+ * the component will not control its own state.
117
+ */
118
+ onToggle: PropTypes.func,
119
+ /**
120
+ * Callback fired when an item within the `<Menu />` is selected
121
+ */
122
+ onSelect: PropTypes.func,
123
+ /**
124
+ * If a trigger is supplied, callback fired when the `<Menu />` is closed
125
+ */
126
+ onDismiss: PropTypes.func,
127
+ /**
128
+ * If a trigger is supplied, callback fired when the `<Menu />` trigger is blurred
129
+ */
130
+ onBlur: PropTypes.func,
131
+ /**
132
+ * If a trigger is supplied, callback fired when the `<Menu />` trigger is focused
133
+ */
134
+ onFocus: PropTypes.func,
135
+ /**
136
+ * If a trigger is supplied, callback fired onMouseOver for the `<Menu />` trigger
137
+ */
138
+ onMouseOver: PropTypes.func,
139
+ /**
140
+ * Callback fired on the onKeyDown of the `<Menu />`
141
+ */
142
+ onKeyDown: PropTypes.func,
143
+ /**
144
+ * Callback fired on the onKeyUp of the `<Menu />`
145
+ */
146
+ onKeyUp: PropTypes.func,
147
+ /**
148
+ * A function that returns a reference to the `<Menu />`
149
+ */
150
+ menuRef: PropTypes.func,
151
+ /**
152
+ * A function that returns a reference to the `<Popover />`
153
+ */
154
+ popoverRef: PropTypes.func,
155
+ /**
156
+ * If a trigger is supplied, an element or a function returning an element to use as the mount node
157
+ * for the `<Menu />` (defaults to `document.body`)
158
+ */
159
+ mountNode: PositionPropTypes.mountNode,
160
+ /**
161
+ * The parent in which to constrain the menu.
162
+ * One of: 'window', 'scroll-parent', 'parent', 'none', an element,
163
+ * or a function returning an element
164
+ */
165
+ constrain: PositionPropTypes.constrain,
166
+ /**
167
+ * If a trigger is supplied, an element, function returning an element, or array of elements that will not
168
+ * be hidden from the screen reader when the `<Menu />` is open
169
+ */
170
+ liveRegion: PropTypes.oneOfType([
171
+ PropTypes.arrayOf(PropTypes.element),
172
+ PropTypes.element,
173
+ PropTypes.func
174
+ ]),
175
+ /**
176
+ * If a trigger is supplied, should the `<Menu />` hide when an item is selected
177
+ */
178
+ shouldHideOnSelect: PropTypes.bool,
179
+ /**
180
+ * If a trigger is supplied, should the `<Menu />` focus the trigger on after closing
181
+ */
182
+ shouldFocusTriggerOnClose: PropTypes.bool,
183
+ /**
184
+ * The type of `<Menu />`
185
+ */
186
+ type: PropTypes.oneOf(['flyout']),
187
+ id: PropTypes.string,
188
+ /**
189
+ * Whether or not an arrow pointing to the trigger should be rendered
190
+ */
191
+ withArrow: PropTypes.bool,
192
+ /**
193
+ * The horizontal offset for the positioned content.
194
+ * Works only if `trigger` is provided.
195
+ */
196
+ offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
197
+ /**
198
+ * The vertical offset for the positioned content.
199
+ * Works only if `trigger` is provided.
200
+ */
201
+ offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
202
+ }
203
+
204
+ const allowedProps: AllowedPropKeys = [
205
+ 'children',
206
+ 'label',
207
+ 'disabled',
208
+ 'trigger',
209
+ 'placement',
210
+ 'defaultShow',
211
+ 'show',
212
+ 'onToggle',
213
+ 'onSelect',
214
+ 'onDismiss',
215
+ 'onBlur',
216
+ 'onFocus',
217
+ 'onMouseOver',
218
+ 'onKeyDown',
219
+ 'onKeyUp',
220
+ 'menuRef',
221
+ 'popoverRef',
222
+ 'mountNode',
223
+ 'constrain',
224
+ 'liveRegion',
225
+ 'shouldHideOnSelect',
226
+ 'shouldFocusTriggerOnClose',
227
+ 'type',
228
+ 'id',
229
+ 'withArrow',
230
+ 'offsetX',
231
+ 'offsetY'
232
+ ]
233
+
234
+ export type { MenuProps }
235
+ export { propTypes, allowedProps }