@fluentui-react-native/menu 0.16.0 → 1.0.2

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 (48) hide show
  1. package/CHANGELOG.json +46 -1
  2. package/CHANGELOG.md +26 -2
  3. package/MIGRATION.md +323 -0
  4. package/SPEC.md +405 -0
  5. package/assets/Menu.png +0 -0
  6. package/assets/Submenu.png +0 -0
  7. package/assets/checkbox.png +0 -0
  8. package/lib/MenuItem/useMenuItem.d.ts +2 -0
  9. package/lib/MenuItem/useMenuItem.d.ts.map +1 -1
  10. package/lib/MenuItem/useMenuItem.js +17 -28
  11. package/lib/MenuItem/useMenuItem.js.map +1 -1
  12. package/lib/MenuItemCheckbox/useMenuItemCheckbox.d.ts.map +1 -1
  13. package/lib/MenuItemCheckbox/useMenuItemCheckbox.js +23 -9
  14. package/lib/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
  15. package/lib/MenuList/MenuList.types.d.ts +1 -0
  16. package/lib/MenuList/MenuList.types.d.ts.map +1 -1
  17. package/lib/MenuList/useMenuList.d.ts.map +1 -1
  18. package/lib/MenuList/useMenuList.js +13 -1
  19. package/lib/MenuList/useMenuList.js.map +1 -1
  20. package/lib/MenuTrigger/MenuTrigger.js +1 -1
  21. package/lib/MenuTrigger/MenuTrigger.js.map +1 -1
  22. package/lib/context/menuListContext.d.ts.map +1 -1
  23. package/lib/context/menuListContext.js +1 -0
  24. package/lib/context/menuListContext.js.map +1 -1
  25. package/lib-commonjs/MenuItem/useMenuItem.d.ts +2 -0
  26. package/lib-commonjs/MenuItem/useMenuItem.d.ts.map +1 -1
  27. package/lib-commonjs/MenuItem/useMenuItem.js +19 -30
  28. package/lib-commonjs/MenuItem/useMenuItem.js.map +1 -1
  29. package/lib-commonjs/MenuItemCheckbox/useMenuItemCheckbox.d.ts.map +1 -1
  30. package/lib-commonjs/MenuItemCheckbox/useMenuItemCheckbox.js +20 -6
  31. package/lib-commonjs/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
  32. package/lib-commonjs/MenuList/MenuList.types.d.ts +1 -0
  33. package/lib-commonjs/MenuList/MenuList.types.d.ts.map +1 -1
  34. package/lib-commonjs/MenuList/useMenuList.d.ts.map +1 -1
  35. package/lib-commonjs/MenuList/useMenuList.js +13 -1
  36. package/lib-commonjs/MenuList/useMenuList.js.map +1 -1
  37. package/lib-commonjs/MenuTrigger/MenuTrigger.js +1 -1
  38. package/lib-commonjs/MenuTrigger/MenuTrigger.js.map +1 -1
  39. package/lib-commonjs/context/menuListContext.d.ts.map +1 -1
  40. package/lib-commonjs/context/menuListContext.js +1 -0
  41. package/lib-commonjs/context/menuListContext.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/MenuItem/useMenuItem.ts +21 -34
  44. package/src/MenuItemCheckbox/useMenuItemCheckbox.ts +32 -7
  45. package/src/MenuList/MenuList.types.ts +1 -0
  46. package/src/MenuList/useMenuList.ts +18 -1
  47. package/src/MenuTrigger/MenuTrigger.tsx +1 -1
  48. package/src/context/menuListContext.ts +1 -0
package/CHANGELOG.json CHANGED
@@ -2,7 +2,52 @@
2
2
  "name": "@fluentui-react-native/menu",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 27 Jun 2022 15:59:42 GMT",
5
+ "date": "Wed, 29 Jun 2022 21:06:35 GMT",
6
+ "tag": "@fluentui-react-native/menu_v1.0.2",
7
+ "version": "1.0.2",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "ruaraki@microsoft.com",
12
+ "package": "@fluentui-react-native/menu",
13
+ "commit": "c606f6deb5e1be500fc4183e6537dbf523c84194",
14
+ "comment": "Some refactoring"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 28 Jun 2022 22:01:06 GMT",
21
+ "tag": "@fluentui-react-native/menu_v1.0.1",
22
+ "version": "1.0.1",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "ruaraki@microsoft.com",
27
+ "package": "@fluentui-react-native/menu",
28
+ "commit": "46767277f2408687a94a808360affee37683673e",
29
+ "comment": "Update package.json version"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Tue, 28 Jun 2022 18:04:00 GMT",
36
+ "tag": "@fluentui-react-native/menu_v0.16.1",
37
+ "version": "0.16.1",
38
+ "comments": {
39
+ "patch": [
40
+ {
41
+ "author": "ruaraki@microsoft.com",
42
+ "package": "@fluentui-react-native/menu",
43
+ "commit": "bb8994fb90ff02dab0270e4005558b21d7be50e1",
44
+ "comment": "Fix arrow close not working"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Mon, 27 Jun 2022 15:59:57 GMT",
6
51
  "tag": "@fluentui-react-native/menu_v0.16.0",
7
52
  "version": "0.16.0",
8
53
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,36 @@
1
1
  # Change Log - @fluentui-react-native/menu
2
2
 
3
- This log was last generated on Mon, 27 Jun 2022 15:59:42 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 29 Jun 2022 21:06:35 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.0.2
8
+
9
+ Wed, 29 Jun 2022 21:06:35 GMT
10
+
11
+ ### Patches
12
+
13
+ - Some refactoring (ruaraki@microsoft.com)
14
+
15
+ ## 1.0.1
16
+
17
+ Tue, 28 Jun 2022 22:01:06 GMT
18
+
19
+ ### Patches
20
+
21
+ - Update package.json version (ruaraki@microsoft.com)
22
+
23
+ ## 0.16.1
24
+
25
+ Tue, 28 Jun 2022 18:04:00 GMT
26
+
27
+ ### Patches
28
+
29
+ - Fix arrow close not working (ruaraki@microsoft.com)
30
+
7
31
  ## 0.16.0
8
32
 
9
- Mon, 27 Jun 2022 15:59:42 GMT
33
+ Mon, 27 Jun 2022 15:59:57 GMT
10
34
 
11
35
  ### Minor changes
12
36
 
package/MIGRATION.md ADDED
@@ -0,0 +1,323 @@
1
+ # Menu Migration
2
+
3
+ ## Migration from ContextualMenu
4
+
5
+ ### Component rename
6
+
7
+ `ContextalMenu` and `Submenu` are now named `Menu`. `ContextualMenuItem` and `SubmenuItem` are now named `MenuItem`.
8
+
9
+ ### Structural difference
10
+
11
+ The v1 `Menu` differs from the v0 `ContextualMenu` by wrapping the anchor component. With this, the `Menu` component takes care of several aspects of managing the menu, including the ref of the target and anchoring the popover (or callout) to the correct component, and open and close behavior.
12
+
13
+ Additionally there is no difference between the root menu and submenus in terms of how they are written. Both controls use the same components with the V1 `Menu`.
14
+
15
+ In v0 a `ContextualMenu` looked like:
16
+
17
+ ```tsx
18
+ const stdBtnRef = React.useRef(null);
19
+ const [showContextualMenu, setShowContextualMenu] = React.useState(false);
20
+ const toggleShowContextualMenu = React.useCallback(() => {
21
+ setShowContextualMenu(!showContextualMenu);
22
+ }, [showContextualMenu, setShowContextualMenu]);
23
+ const onDismissContextualMenu = React.useCallback(() => {
24
+ setShowContextualMenu(false);
25
+ }, [setShowContextualMenu]);
26
+ const onItemClick = React.useCallback(
27
+ (key) => {
28
+ // Do something
29
+ },
30
+ [],
31
+ );
32
+
33
+ <>
34
+ <Button onClick={toggleShowContextualMenu} componentRef={stdBtnRef}>
35
+ Press for ContextualMenu
36
+ </Button>;
37
+ {
38
+ showContextualMenu && (
39
+ <ContextualMenu
40
+ target={stdBtnRef}
41
+ onDismiss={onDismissContextualMenu}
42
+ onItemClick={onItemClick}
43
+ setShowMenu={toggleShowContextualMenu}
44
+ >
45
+ <ContextualMenuItem text="MenuItem 1" itemKey="1" />
46
+ <ContextualMenuItem text="MenuItem 2" itemKey="2" />
47
+ <ContextualMenuItem text="Disabled Menu Item" itemKey="3" disabled />
48
+ <ContextualMenuItem text="MenuItem 4" itemKey="4" />
49
+ <ContextualMenuItem text="MenuItem 5" itemKey="5" />
50
+ </ContextualMenu>
51
+ );
52
+ }
53
+ </>
54
+ ```
55
+
56
+ While a similar setup with the V1 `Menu` looks like:
57
+
58
+ ```tsx
59
+ const onOption1Click = React.useCallback(
60
+ () => {
61
+ // Do something
62
+ },
63
+ [],
64
+ );
65
+
66
+ <Menu>
67
+ <MenuTrigger>
68
+ <Button>Press for Menu</Button>
69
+ </MenuTrigger>
70
+ <MenuPopover>
71
+ <MenuList>
72
+ <MenuItem onClick={onOption1Click}>Option 1</MenuItem>
73
+ <MenuItem>Option 2</MenuItem>
74
+ <MenuItem disabled>Disabled Menu Item</MenuItem>
75
+ <MenuItem>Option 4</MenuItem>
76
+ <MenuItem>Option 5</MenuItem>
77
+ </MenuList>
78
+ </MenuPopover>
79
+ <Menu>
80
+ ```
81
+
82
+ Mapping the `ContextualMenu` to the `Menu`:
83
+
84
+ 1. The `Menu` component wraps both the trigger or the anchor and the popover, while the `ContextualMenu` only represented the popover. This allows the `Menu` to share state between the anchor and the popover.
85
+ 2. The `MenuTrigger` component wraps the anchor. This allows for the anchor to be configured to open and close the popover and have the correct ref while providing flexibility for what the anchor component could be. There is no equivalent in the `ContextualMenu`.
86
+ 3. The `MenuPopover` wraps the popover or callout component which hosts the options of the menu. This can be thought of as equivalent to `ContextualMenu`.
87
+ 4. The `MenuList` wraps the menu options so that they can share state between each other and sets up the menu to be able to be a standalone component in the future. This can be thought of as handling some of the logic of the `ContextualMenu`.
88
+ 5. The `MenuItem`, `MenuItemCheckbox`, and `MenuItemRadio` represent options in a menu. These can be thought of as equivalent to `ContextualMenuItem`.
89
+
90
+ #### Submenu
91
+
92
+ In v0 a `ContextualMenu` with a `Submenu` looked like:
93
+
94
+ ```tsx
95
+ const stdBtnRef = React.useRef(null);
96
+ const [showContextualMenu, setShowContextualMenu] = React.useState(false);
97
+ const toggleShowContextualMenu = React.useCallback(() => {
98
+ setShowContextualMenu(!showContextualMenu);
99
+ }, [showContextualMenu, setShowContextualMenu]);
100
+ const onDismissContextualMenu = React.useCallback(() => {
101
+ setShowContextualMenu(false);
102
+ }, [setShowContextualMenu]);
103
+ const onItemClick = React.useCallback((key) => {
104
+ // Do something
105
+ }, []);
106
+
107
+ const stdMenuItemRef = React.useRef(null);
108
+
109
+ const [showSubmenu, setShowSubmenu] = React.useState(false);
110
+
111
+ const toggleShowSubmenu = React.useCallback(() => {
112
+ setShowSubmenu(!showSubmenu);
113
+ }, [showSubmenu, isSubmenuVisible, setShowSubmenu, setIsSubmenuVisible]);
114
+ const onDismissSubmenu = React.useCallback(() => {
115
+ setShowSubmenu(false);
116
+ }, [setShowSubmenu]);
117
+ const onClick = React.useCallback(() => {
118
+ console.log('submenu item clicked');
119
+ }, []);
120
+
121
+ <>
122
+ <Button onClick={toggleShowContextualMenu} componentRef={stdBtnRef}>
123
+ Press for ContextualMenu
124
+ </Button>
125
+ {showContextualMenu && (
126
+ <ContextualMenu target={stdBtnRef} onDismiss={onDismissContextualMenu} setShowMenu={toggleShowContextualMenu}>
127
+ <ContextualMenuItem text="Menu item 1" itemKey="1" />
128
+ <ContextualMenuItem text="Menu item 2" itemKey="2" />
129
+ <ContextualMenuItem text="Disabled Menu Item" itemKey="3" disabled />
130
+ <SubmenuItem text="Nested Menu" itemKey="4" onHoverIn={toggleShowSubmenu} componentRef={stdMenuItemRef} />
131
+ {showSubmenu && (
132
+ <Submenu target={stdMenuItemRef} onDismiss={onDismissSubmenu} setShowMenu={toggleShowSubmenu}>
133
+ <ContextualMenuItem text="SubmenuItem 1" itemKey="1" onClick={onClick} />
134
+ <ContextualMenuItem text="SubmenuItem 2" itemKey="2" />
135
+ <ContextualMenuItem text="Disabled Menu Item" itemKey="3" disabled />
136
+ </Submenu>
137
+ )}
138
+ <ContextualMenuItem text="Menuitem 5" itemKey="5" />
139
+ </ContextualMenu>
140
+ )}
141
+ </>;
142
+ ```
143
+
144
+ While a similar setup with the V1 `Menu` looks like:
145
+
146
+ ```tsx
147
+ const onSubmenuItemClick = React.useCallback(
148
+ () => {
149
+ // Do something
150
+ },
151
+ [],
152
+ );
153
+
154
+ <Menu>
155
+ <MenuTrigger>
156
+ <Button>Press for Menu</Button>
157
+ </MenuTrigger>
158
+ <MenuPopover>
159
+ <MenuList>
160
+ <MenuItem>Menu item 1</MenuItem>
161
+ <MenuItem>Menu item 2</MenuItem>
162
+ <MenuItem disabled>Disabled Menu Item</MenuItem>
163
+ <Menu>
164
+ <MenuTrigger>
165
+ <MenuItem>Nested Menu</MenuItem>
166
+ </MenuTrigger>
167
+ <MenuPopover>
168
+ <MenuList>
169
+ <MenuItem onClick={onSubmenuItemClick}>SubmenuItem 1</MenuItem>
170
+ <MenuItem >SubmenuItem 2</MenuItem>
171
+ <MenuItem disabled>Disabled Menu Item</MenuItem>
172
+ </MenuList>
173
+ </MenuPopover>
174
+ <MenuItem>Menu item 5</MenuItem>
175
+ </MenuList>
176
+ </MenuPopover>
177
+ <Menu>
178
+ ```
179
+
180
+ There is no separate `SubmenuItem` or `Submenu` component. You can wrap a `MenuItem` in a `Menu` component, and it will take care of showing an indicator for the submenu and opening the menu in a reasonable direction.
181
+
182
+ ### Prop and token mapping from ContextualMenu to Menu
183
+
184
+ #### Props no longer supported in ContextualMenu with an equivalent functionality in v1 Menu
185
+
186
+ - `shouldFocusOnMount` => Use `setInitialFocus` on `MenuPopover` instead. Defaults to `true`.
187
+ - `onItemClick` => Use `onClick` on the individual `MenuItem` instead.
188
+ - `setShowMenu` => Use `onOpenChange` on `Menu` instead. This is not required to toggle showing the `MenuPopover`, the `Menu` component will take care of it unless you want to control the component's `open` state.
189
+
190
+ #### Props no longer supported in ContextualMenu without an equivalent functionality in v1 Menu
191
+
192
+ - `shouldFocusOnContainer` - Default behavior is taken care of by `Menu`
193
+
194
+ #### Tokens with an equivalent functionality in v1 Menu
195
+
196
+ - `backgroundColor` => Use `backgroundColor` token on `MenuList`
197
+ - All other tokens can be passed as props to `MenuPopover`
198
+
199
+ ### Prop and token mapping from ContextualMenuItem to MenuItem
200
+
201
+ #### Props no longer supported in ContextualMenuItem with an equivalent functionality in v1 MenuItem
202
+
203
+ - `itemKey` => Use `name` instead.
204
+ - `text` => Pass text as child to component instead.
205
+
206
+ #### Props no longer supported in ContextualMenuItem without an equivalent functionality in v1 MenuItem
207
+
208
+ - `icon` - Not yet supported
209
+ - `title` - Not yet supported
210
+ - `dismissMenu`
211
+
212
+ #### Tokens with an equivalent functionality in v1 MenuItem
213
+
214
+ - `FontTokens`, `IColorTokens`, `IBorderTokens`
215
+
216
+ ### Updating ThemeProvider
217
+
218
+ If you are using the older theme provider `ThemeProvider` from `@uifabricshared/theming-react-native`, you will need to update the `ThemeProvider` to pull from `@fluentui-react-native/theme` to have the control work properly with themes. Please see [this page](../../../docs/pages/Guides/UpdateThemeProvider.md) for guidance.
219
+
220
+ ### Migrating customized ContextualMenus
221
+
222
+ Please see [this page](../../../docs/pages/Guides/UpdatingCustomize.md) for guidance on how to move from the old `customize` API to the new one.
223
+
224
+ ### Migrating composed ContextualMenus
225
+
226
+ Please see [this page](../../../docs/pages/Guides/UpdatingCustomize.md) for guidance on how to move from the old `customize` API to the new one.
227
+
228
+ ## Porting from FluentUI v9 Menu
229
+
230
+ The FURN menu cannot be used in place of a FluentUI menu - these componentss are intended to be used on their respective platforms. See [this porting guide](../../../docs/pages/Guides/PortingFromFluentUI.md) for general guidance on coming from FluentUI to FURN.
231
+
232
+ ### Not yet implemented
233
+
234
+ - Icons on MenuItems
235
+ - Secondary labels on MenuItems
236
+ - Split buttons for MenuItems
237
+ - MenuGroups (including headings)
238
+ - Scrollable menus
239
+ - Custom triggers for Menus (i.e. have a Menu trigger be a component that is not under MenuTrigger)
240
+ - Standalone MenuList
241
+
242
+ ### Menu
243
+
244
+ #### Menu Props that remain as is
245
+
246
+ - `children`
247
+ - `defaultOpen`
248
+ - `hoverDelay`
249
+ - `open`
250
+ - `openOnHover`
251
+
252
+ #### Menu Prop differences due to technical differences and limitations
253
+
254
+ - `onOpenChange` has a different event type and a bool for `isOpen` instead of `data` for its call signature.
255
+
256
+ #### Not implemented on Menu
257
+
258
+ - `inline`
259
+ - `openOnContext`
260
+ - `positioning` (`directionalHint` can be passed into `MenuPopover` instead)
261
+ - `closeOnScroll`
262
+
263
+ ### MenuTrigger
264
+
265
+ `MenuTrigger` should not need any changes.
266
+
267
+ ### MenuPopover
268
+
269
+ `MenuPopover` should not need any changes.
270
+
271
+ ### MenuList
272
+
273
+ #### MenuList Props that remain as is
274
+
275
+ - `hasCheckmarks`
276
+ - `children`
277
+
278
+ #### MenuList Prop differences due to technical differences and limitations
279
+
280
+ `MenuItem*` only uses `name` and not `value` since it is not based on an `input` HTML element. This changes the following props:
281
+
282
+ - `checkedValues` takes in `string[]` of names to be checked instead of `Record<string, string[]>`
283
+ - `defaultCheckedValues` takes in `string[]` of names to be checked instead of `Record<string, string[]>`
284
+ - `onCheckedValueChange` returns a `string[]` of names of items that are checked instead of `Record<string, string[]>`
285
+
286
+ #### Not implemented on MenuList
287
+
288
+ - `hasIcons`
289
+
290
+ ### MenuItem
291
+
292
+ #### MenuItem Props that remain as is
293
+
294
+ - `children`
295
+ - `disabled`
296
+
297
+ #### MenuItem Prop differences due to technical differences and limitations
298
+
299
+ - `componentRef` instead of `ref`
300
+
301
+ #### Not implemented on MenuItem
302
+
303
+ - `hasSubmenu` - currently automatically handled
304
+
305
+ ### MenuItemCheckbox and MenuItemRadio
306
+
307
+ #### MenuItemCheckbox Props that remain as is
308
+
309
+ - `children`
310
+ - `disabled`
311
+ - `name`
312
+
313
+ #### MenuItemCheckbox Prop differences due to technical differences and limitations
314
+
315
+ - `componentRef` instead of `ref`
316
+
317
+ #### Not implemented on MenuItemCheckbox
318
+
319
+ - `value`
320
+
321
+ ### MenuDivider
322
+
323
+ `MenuDivider` should not need any changes.