@instructure/ui-menu 8.13.1-snapshot.9 → 8.14.0

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 (47) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/es/Menu/MenuItem/index.js +28 -21
  3. package/es/Menu/MenuItem/props.js +0 -23
  4. package/es/Menu/MenuItemGroup/index.js +17 -13
  5. package/es/Menu/MenuItemGroup/props.js +1 -30
  6. package/es/Menu/MenuItemSeparator/index.js +6 -2
  7. package/es/Menu/index.js +59 -56
  8. package/es/Menu/props.js +1 -113
  9. package/es/MenuContext.js +3 -3
  10. package/lib/Menu/MenuItem/index.js +28 -21
  11. package/lib/Menu/MenuItem/props.js +0 -23
  12. package/lib/Menu/MenuItemGroup/index.js +17 -13
  13. package/lib/Menu/MenuItemGroup/props.js +1 -30
  14. package/lib/Menu/MenuItemSeparator/index.js +6 -2
  15. package/lib/Menu/index.js +61 -56
  16. package/lib/Menu/props.js +1 -113
  17. package/lib/MenuContext.js +2 -2
  18. package/package.json +21 -22
  19. package/src/Menu/MenuItem/index.tsx +24 -34
  20. package/src/Menu/MenuItem/props.ts +36 -27
  21. package/src/Menu/MenuItemGroup/index.tsx +28 -48
  22. package/src/Menu/MenuItemGroup/props.ts +37 -30
  23. package/src/Menu/MenuItemSeparator/index.tsx +2 -4
  24. package/src/Menu/index.tsx +81 -135
  25. package/src/Menu/props.ts +79 -84
  26. package/src/MenuContext.ts +3 -2
  27. package/tsconfig.build.json +25 -2
  28. package/tsconfig.build.tsbuildinfo +1 -0
  29. package/types/Menu/MenuItem/MenuItemLocator.d.ts +52 -52
  30. package/types/Menu/MenuItem/index.d.ts +24 -23
  31. package/types/Menu/MenuItem/index.d.ts.map +1 -1
  32. package/types/Menu/MenuItem/props.d.ts +30 -7
  33. package/types/Menu/MenuItem/props.d.ts.map +1 -1
  34. package/types/Menu/MenuItemGroup/MenuItemGroupLocator.d.ts +182 -182
  35. package/types/Menu/MenuItemGroup/index.d.ts +22 -22
  36. package/types/Menu/MenuItemGroup/index.d.ts.map +1 -1
  37. package/types/Menu/MenuItemGroup/props.d.ts +33 -8
  38. package/types/Menu/MenuItemGroup/props.d.ts.map +1 -1
  39. package/types/Menu/MenuItemSeparator/index.d.ts.map +1 -1
  40. package/types/Menu/MenuLocator.d.ts +576 -576
  41. package/types/Menu/index.d.ts +58 -68
  42. package/types/Menu/index.d.ts.map +1 -1
  43. package/types/Menu/props.d.ts +94 -16
  44. package/types/Menu/props.d.ts.map +1 -1
  45. package/types/MenuContext.d.ts +3 -2
  46. package/types/MenuContext.d.ts.map +1 -1
  47. package/LICENSE.md +0 -27
package/src/Menu/props.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
+ import React from 'react'
25
26
  import PropTypes from 'prop-types'
26
27
 
27
28
  import { PositionPropTypes } from '@instructure/ui-position'
@@ -29,175 +30,171 @@ import {
29
30
  controllable,
30
31
  Children as ChildrenPropTypes
31
32
  } from '@instructure/ui-prop-types'
33
+ import type { Menu } from './index'
32
34
 
33
- import type { PropValidators, MenuTheme } from '@instructure/shared-types'
35
+ import type {
36
+ PropValidators,
37
+ MenuTheme,
38
+ OtherHTMLAttributes
39
+ } from '@instructure/shared-types'
34
40
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
35
41
  import type {
36
42
  PlacementPropValues,
37
43
  PositionConstraint,
38
44
  PositionMountNode
39
45
  } from '@instructure/ui-position'
46
+ import type { OnMenuItemSelect } from './MenuItem/props'
47
+ import type { Popover } from '@instructure/ui-popover'
40
48
 
41
49
  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?: // TODO check whether this is used
62
- React.ReactElement[] | React.ReactElement | ((...args: any[]) => any)
63
- shouldHideOnSelect?: boolean
64
- shouldFocusTriggerOnClose?: boolean
65
- type?: 'flyout'
66
- id?: string
67
- withArrow?: boolean
68
- offsetX?: string | number
69
- offsetY?: string | number
70
- }
71
-
72
- type PropKeys = keyof MenuOwnProps
73
-
74
- type AllowedPropKeys = Readonly<Array<PropKeys>>
75
-
76
- type MenuProps = MenuOwnProps & WithStyleProps<MenuTheme, MenuStyle>
77
-
78
- type MenuStyle = ComponentStyle<'menu'>
79
-
80
- const propTypes: PropValidators<PropKeys> = {
81
50
  /**
82
51
  * Children of type `Menu.Item`, `Menu.Group`, `Menu.Separator`, or `Menu`
83
52
  */
84
- children: ChildrenPropTypes.oneOf([
85
- 'MenuItem',
86
- 'MenuItemGroup',
87
- 'MenuItemSeparator',
88
- 'Menu'
89
- ]),
53
+ children?: React.ReactNode // TODO: oneOf(['MenuItem', 'MenuItemGroup', 'MenuItemSeparator', 'Menu'])
90
54
  /**
91
55
  * Description of the `<Menu />`
92
56
  */
93
- label: PropTypes.string,
57
+ label?: string
94
58
  /**
95
59
  * Is the `<Menu />` disabled
96
60
  */
97
- disabled: PropTypes.bool,
61
+ disabled?: boolean
98
62
  /**
99
63
  * The trigger element, if the `<Menu />` is to render as a popover
100
64
  */
101
- trigger: PropTypes.node,
65
+ trigger?: React.ReactNode
102
66
  /**
103
67
  * If a trigger is supplied, where should the `<Menu />` be placed (relative to the trigger)
104
68
  */
105
- placement: PositionPropTypes.placement,
69
+ placement?: PlacementPropValues
106
70
  /**
107
71
  * Should the `<Menu />` be open for the initial render
108
72
  */
109
- defaultShow: PropTypes.bool,
73
+ defaultShow?: boolean
110
74
  /**
111
75
  * Is the `<Menu />` open (should be accompanied by `onToggle`)
112
76
  */
113
- show: controllable(PropTypes.bool, 'onToggle', 'defaultShow'),
77
+ show?: boolean // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultShow')
114
78
  /**
115
79
  * Callback fired when the `<Menu />` is toggled open/closed. When used with `show`,
116
80
  * the component will not control its own state.
117
81
  */
118
- onToggle: PropTypes.func,
82
+ onToggle?: (show: boolean, menu: Menu) => void
119
83
  /**
120
84
  * Callback fired when an item within the `<Menu />` is selected
121
85
  */
122
- onSelect: PropTypes.func,
86
+ onSelect?: OnMenuItemSelect
123
87
  /**
124
88
  * If a trigger is supplied, callback fired when the `<Menu />` is closed
125
89
  */
126
- onDismiss: PropTypes.func,
127
- /**
128
- * If a trigger is supplied, callback fired when the `<Menu />` trigger is blurred
129
- */
130
- onBlur: PropTypes.func,
90
+ onDismiss?: (
91
+ event: React.UIEvent | React.FocusEvent,
92
+ documentClick: boolean
93
+ ) => void
131
94
  /**
132
95
  * If a trigger is supplied, callback fired when the `<Menu />` trigger is focused
133
96
  */
134
- onFocus: PropTypes.func,
97
+ onFocus?: (event: React.FocusEvent) => void
135
98
  /**
136
99
  * If a trigger is supplied, callback fired onMouseOver for the `<Menu />` trigger
137
100
  */
138
- onMouseOver: PropTypes.func,
101
+ onMouseOver?: (event: React.MouseEvent) => void
139
102
  /**
140
103
  * Callback fired on the onKeyDown of the `<Menu />`
141
104
  */
142
- onKeyDown: PropTypes.func,
105
+ onKeyDown?: (event: React.KeyboardEvent<HTMLUListElement>) => void
143
106
  /**
144
107
  * Callback fired on the onKeyUp of the `<Menu />`
145
108
  */
146
- onKeyUp: PropTypes.func,
109
+ onKeyUp?: (event: React.KeyboardEvent<HTMLUListElement>) => void
147
110
  /**
148
111
  * A function that returns a reference to the `<Menu />`
149
112
  */
150
- menuRef: PropTypes.func,
113
+ menuRef?: (el: HTMLUListElement | null) => void
151
114
  /**
152
115
  * A function that returns a reference to the `<Popover />`
153
116
  */
154
- popoverRef: PropTypes.func,
117
+ popoverRef?: (el: Popover | null) => void
155
118
  /**
156
119
  * If a trigger is supplied, an element or a function returning an element to use as the mount node
157
120
  * for the `<Menu />` (defaults to `document.body`)
158
121
  */
159
- mountNode: PositionPropTypes.mountNode,
122
+ mountNode?: PositionMountNode
160
123
  /**
161
124
  * The parent in which to constrain the menu.
162
125
  * One of: 'window', 'scroll-parent', 'parent', 'none', an element,
163
126
  * or a function returning an element
164
127
  */
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
- ]),
128
+ constrain?: PositionConstraint
175
129
  /**
176
130
  * If a trigger is supplied, should the `<Menu />` hide when an item is selected
177
131
  */
178
- shouldHideOnSelect: PropTypes.bool,
132
+ shouldHideOnSelect?: boolean
179
133
  /**
180
134
  * If a trigger is supplied, should the `<Menu />` focus the trigger on after closing
181
135
  */
182
- shouldFocusTriggerOnClose: PropTypes.bool,
136
+ shouldFocusTriggerOnClose?: boolean
183
137
  /**
184
138
  * The type of `<Menu />`
185
139
  */
186
- type: PropTypes.oneOf(['flyout']),
187
- id: PropTypes.string,
140
+ type?: 'flyout'
141
+ id?: string
188
142
  /**
189
143
  * Whether or not an arrow pointing to the trigger should be rendered
190
144
  */
191
- withArrow: PropTypes.bool,
145
+ withArrow?: boolean
192
146
  /**
193
147
  * The horizontal offset for the positioned content.
194
148
  * Works only if `trigger` is provided.
195
149
  */
196
- offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
150
+ offsetX?: string | number
197
151
  /**
198
152
  * The vertical offset for the positioned content.
199
153
  * Works only if `trigger` is provided.
200
154
  */
155
+ offsetY?: string | number
156
+ }
157
+
158
+ type PropKeys = keyof MenuOwnProps
159
+
160
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
161
+
162
+ type MenuProps = MenuOwnProps &
163
+ WithStyleProps<MenuTheme, MenuStyle> &
164
+ OtherHTMLAttributes<MenuOwnProps>
165
+
166
+ type MenuStyle = ComponentStyle<'menu'>
167
+
168
+ const propTypes: PropValidators<PropKeys> = {
169
+ children: ChildrenPropTypes.oneOf([
170
+ 'MenuItem',
171
+ 'MenuItemGroup',
172
+ 'MenuItemSeparator',
173
+ 'Menu'
174
+ ]),
175
+ label: PropTypes.string,
176
+ disabled: PropTypes.bool,
177
+ trigger: PropTypes.node,
178
+ placement: PositionPropTypes.placement,
179
+ defaultShow: PropTypes.bool,
180
+ show: controllable(PropTypes.bool, 'onToggle', 'defaultShow'),
181
+ onToggle: PropTypes.func,
182
+ onSelect: PropTypes.func,
183
+ onDismiss: PropTypes.func,
184
+ onFocus: PropTypes.func,
185
+ onMouseOver: PropTypes.func,
186
+ onKeyDown: PropTypes.func,
187
+ onKeyUp: PropTypes.func,
188
+ menuRef: PropTypes.func,
189
+ popoverRef: PropTypes.func,
190
+ mountNode: PositionPropTypes.mountNode,
191
+ constrain: PositionPropTypes.constrain,
192
+ shouldHideOnSelect: PropTypes.bool,
193
+ shouldFocusTriggerOnClose: PropTypes.bool,
194
+ type: PropTypes.oneOf(['flyout']),
195
+ id: PropTypes.string,
196
+ withArrow: PropTypes.bool,
197
+ offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
201
198
  offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
202
199
  }
203
200
 
@@ -212,7 +209,6 @@ const allowedProps: AllowedPropKeys = [
212
209
  'onToggle',
213
210
  'onSelect',
214
211
  'onDismiss',
215
- 'onBlur',
216
212
  'onFocus',
217
213
  'onMouseOver',
218
214
  'onKeyDown',
@@ -221,7 +217,6 @@ const allowedProps: AllowedPropKeys = [
221
217
  'popoverRef',
222
218
  'mountNode',
223
219
  'constrain',
224
- 'liveRegion',
225
220
  'shouldHideOnSelect',
226
221
  'shouldFocusTriggerOnClose',
227
222
  'type',
@@ -23,6 +23,7 @@
23
23
  */
24
24
 
25
25
  import { createContext } from 'react'
26
+ import { MenuItem } from './Menu/MenuItem'
26
27
 
27
28
  /**
28
29
  ---
@@ -31,8 +32,8 @@ private: true
31
32
  @module MenuContext
32
33
  **/
33
34
  const MenuContext = createContext({
34
- registerMenuItem: () => {},
35
- removeMenuItem: () => {}
35
+ registerMenuItem: (_value: MenuItem) => {},
36
+ removeMenuItem: (_value: MenuItem) => {}
36
37
  })
37
38
 
38
39
  export default MenuContext
@@ -1,7 +1,30 @@
1
1
  {
2
2
  "extends": "../../tsconfig.build.json",
3
3
  "compilerOptions": {
4
- "outDir": "./types"
4
+ "outDir": "./types",
5
+ "rootDir": "./src",
6
+ "composite": true
5
7
  },
6
- "include": ["src/**/*"]
8
+ "include": ["src"],
9
+ "references": [
10
+ { "path": "../ui-babel-preset/tsconfig.build.json" },
11
+ { "path": "../ui-color-utils/tsconfig.build.json" },
12
+ { "path": "../ui-test-locator/tsconfig.build.json" },
13
+ { "path": "../ui-test-queries/tsconfig.build.json" },
14
+ { "path": "../ui-test-utils/tsconfig.build.json" },
15
+ { "path": "../ui-themes/tsconfig.build.json" },
16
+ { "path": "../console/tsconfig.build.json" },
17
+ { "path": "../emotion/tsconfig.build.json" },
18
+ { "path": "../shared-types/tsconfig.build.json" },
19
+ { "path": "../ui-a11y-utils/tsconfig.build.json" },
20
+ { "path": "../ui-dom-utils/tsconfig.build.json" },
21
+ { "path": "../ui-icons/tsconfig.build.json" },
22
+ { "path": "../ui-popover/tsconfig.build.json" },
23
+ { "path": "../ui-position/tsconfig.build.json" },
24
+ { "path": "../ui-prop-types/tsconfig.build.json" },
25
+ { "path": "../ui-react-utils/tsconfig.build.json" },
26
+ { "path": "../ui-testable/tsconfig.build.json" },
27
+ { "path": "../ui-utils/tsconfig.build.json" },
28
+ { "path": "../uid/tsconfig.build.json" }
29
+ ]
7
30
  }