@contentful/f36-menu 4.0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2018-present Contentful GmbH
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.mdx ADDED
@@ -0,0 +1,159 @@
1
+ ---
2
+ title: 'Menu'
3
+ slug: /components/menu/
4
+ github: 'https://github.com/contentful/forma-36/tree/forma-v4/packages/components/menu'
5
+ typescript: ./src/Menu.tsx,./src/MenuItem/MenuItem.tsx,./src/MenuList/MenuList.tsx
6
+ ---
7
+
8
+ Menu is a component that offers a list of choices to the user, such as a set of actions or links.
9
+ Menu uses Popover component as a base.
10
+
11
+ ## Import
12
+
13
+ ```jsx static=true
14
+ import { Menu } from '@contentful/f36-components';
15
+ ```
16
+
17
+ ## Examples
18
+
19
+ You can use following components to build a menu:
20
+
21
+ 1. `<Menu>`: The main wrapper that provides nested components with all the context and state.
22
+ 1. `<Menu.Trigger>` The wrapper for the menu list trigger. Must be a direct child of `<Menu>`.
23
+ NOTE: 🚨 Ensure that the component that you pass accepts `ref`. Consider using `forwardRef` for functional components.
24
+ 1. `<Menu.List>`: The wrapper for the menu items. Must be a direct child of `<Menu>`.
25
+ 1. `<Menu.Item>` The trigger that handles menu selection. Must be a direct child of `<Menu.List>`.
26
+ 1. `<Menu.Divider>` A visual separator for menu items.
27
+ 1. `<Menu.SectionTitle>` A title that you can use in the menu list.
28
+ 1. `<Menu.ListHeader>` The wrapper for one menu item that will be sticked to the top of the menu list. `<Menu.Item>` must be provided as a child.
29
+ 1. `<Menu.ListFooter>` The wrapper for one menu item that will be sticked to the bottom of the menu list. `<Menu.Item>` must be provided as a child.
30
+ 1. `<Menu.Submenu>` The wrapper for for submenu components. Structure of the children remains the same like in `<Menu>`, except you should use `<Menu.SubmenuTrigger>` instead of `<Menu.Trigger>`.
31
+ 1. `<Menu.SubmenuTrigger>` The wrapper for the submenu list trigger. Must be a direct child of `<Menu.Submenu>`.
32
+
33
+ ### Basic usage
34
+
35
+ ```tsx file=examples/BasicMenu.tsx
36
+
37
+ ```
38
+
39
+ ### With simple Button as a trigger
40
+
41
+ ```tsx file=examples/MenuWithButtonAsTrigger.tsx
42
+
43
+ ```
44
+
45
+ ### With Menu.SectionTitle and Menu.Divider
46
+
47
+ ```jsx file=examples/MenuWithTitle.tsx
48
+
49
+ ```
50
+
51
+ ### Controlled Menu
52
+
53
+ By default the Menu component is uncontrolled. So when user clicks on the trigger, the menu opens/closes.
54
+ But you can control it by passing `isOpen` prop and `onClose`, `onOpen` callbacks.
55
+
56
+ ```jsx file=examples/ControlledMenu.tsx
57
+ function ControlledMenu() {
58
+ const [isOpen, setIsOpen] = React.useState(false);
59
+ return (
60
+ <Menu
61
+ isOpen={isOpen}
62
+ onOpen={() => setIsOpen(true)}
63
+ onClose={() => setIsOpen(false)}
64
+ >
65
+ <Menu.Trigger>
66
+ <IconButton
67
+ variant="secondary"
68
+ icon={<MenuIcon />}
69
+ aria-label="toggle menu"
70
+ />
71
+ </Menu.Trigger>
72
+ <Menu.List>
73
+ <Menu.Item>Create an entry</Menu.Item>
74
+ <Menu.Item>Remove an entry</Menu.Item>
75
+ <Menu.Item>Embed existing entry</Menu.Item>
76
+ </Menu.List>
77
+ </Menu>
78
+ );
79
+ }
80
+ ```
81
+
82
+ ### Controlled Menu with custom trigger onClick callback
83
+
84
+ In most cases, you will use the [controlled approach](#controlled-menu).
85
+ But if you have to provide your own toggle menu logic on the trigger component, you can do this by providing `onClick` callback on trigger component and omitting `onOpen` callback on the Menu component.
86
+
87
+ ```jsx file=examples/ControlledMenuWithCustomTriggerLogic.tsx
88
+
89
+ ```
90
+
91
+ ### With Menu list maximum height
92
+
93
+ ```jsx file=examples/MenuWithMaxHeight.tsx
94
+
95
+ ```
96
+
97
+ ### With disabled items
98
+
99
+ ```jsx file=examples/MenuWithDisabledItems.tsx
100
+
101
+ ```
102
+
103
+ ### With menu open by default
104
+
105
+ ```jsx static=true file=examples/MenuOpenByDefault.tsx
106
+
107
+ ```
108
+
109
+ ### With sticky header and footer
110
+
111
+ ```jsx file=examples/MenuWithStickyHeaderFooter.tsx
112
+
113
+ ```
114
+
115
+ ### With React Router links
116
+
117
+ ```jsx static=true file=examples/MenuWithReactRouterLinks.tsx
118
+
119
+ ```
120
+
121
+ ### With predefined focused menu item
122
+
123
+ ```jsx file=examples/MenuWithPredefinedFocusedMenuItem.tsx
124
+
125
+ ```
126
+
127
+ ### With submenu
128
+
129
+ By default props like `closeOnSelect`, `closeOnBlur`, `closeOnEsc` that you pass to `Menu` will be shared to all submenus
130
+ But you can redefine them on any submenu by passing those props directly to that `Submenu`.
131
+
132
+ ```jsx file=examples/MenuWithSubmenu.tsx
133
+
134
+ ```
135
+
136
+ ### Menu
137
+
138
+ <Props of="Menu" storybookPath="/story/components-menu--basic" />
139
+
140
+ ### Menu.Item
141
+
142
+ <Props of="MenuItem" />
143
+
144
+ ### Menu.List
145
+
146
+ <Props of="MenuList" />
147
+
148
+ ## Content guidelines
149
+
150
+ - Use an interactive element such as `button` for `Menu.Trigger`
151
+
152
+ ## Accessibility
153
+
154
+ - When the menu is opened, focus is moved to the first menu item. If you set `autoFocus`to `false`, it will not move the focus.
155
+ - When the menu is closed, focus returned back to the trigger element.
156
+ - You can use arrow keys (`ArrowUp` and `ArrowDown`) to navigate through menu items.
157
+ - When the menu is open, click on `Esc` key will close the popover. If you set `closeOnEsc` to `false`, it will not close.
158
+ - When the menu is open, click outside menu or blurring out will close the menu. If you set `closeOnBlur` to `false`, it will not close.
159
+ - All the necessary a11y attributes for `Menu.List`, `Menu.Trigger` and `Menu.Item` are provided.