Skip to content

Commit e6dc007

Browse files
edonehoothatblindgeyenicolethoen
authored
Adds content to menu react examples (#8018)
* Starts menu content edits. * Content updates and rewording. * Update packages/react-core/src/components/Menu/examples/Menu.md Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> * Adds submenu context and makes a few edits. * Adds content to with drilldown breadcumbs example and reorganizes. * Adds danger item content and adds in missing back ticks. * Content edits. Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> Co-authored-by: Nicole Thoen <nthoen@redhat.com>
1 parent 7b3cf4f commit e6dc007

File tree

1 file changed

+96
-37
lines changed
  • packages/react-core/src/components/Menu/examples

1 file changed

+96
-37
lines changed

packages/react-core/src/components/Menu/examples/Menu.md

Lines changed: 96 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,114 +18,173 @@ import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-ico
1818

1919
## Examples
2020

21-
### Basic
21+
### Basic menus
22+
23+
A menu may contain multiple variations of `<MenuItem>` components. The following example shows a few different states of menu items, where they may:
24+
25+
- Use the `itemId` property to link to callbacks. In this example, the `onSelect` property logs information to the console when a menu item is selected. In practice, specific actions can be linked to `onSelect` callbacks.
26+
- Use the `to` property to direct users to other resources or webpages after selecting a menu item, and the `onClick` property to pass in a callback for specific menu items.
27+
- Use the `isDisabled` property to disable a menu item.
28+
- Use the `isPlain` property to remove the outer box shadow and style the menu plainly instead.
2229

2330
```ts file="MenuBasic.tsx"
2431
```
2532

2633
### Danger menu item
2734

35+
To indicate that a `<MenuItem>` is connected to a potentially destructive action, use the `isDanger` property. The "Delete" item in the following example demonstrates how danger items look.
36+
2837
```ts file="MenuDangerMenuItem.tsx"
2938
```
3039

3140
### With icons
3241

42+
Use the `icon` property to add a familiar icon before a `<MenuItem>` to accelerate text label recognition.
43+
3344
```ts file="MenuWithIcons.tsx"
3445
```
3546

36-
### With checkbox
47+
### With actions
48+
49+
To connect a menu item to an action icon, add a `<MenuItemAction>` to a `<MenuItem>`, and use the `icon` property to load an easily recognizable icon.
3750

38-
```ts file="./MenuWithCheckbox.tsx"
39-
```
51+
To trigger an action when any menu action icon is selected, pass a callback to the `onActionClick` property of the `<Menu>`. The following example logs to the console any time any action icon is selected.
4052

41-
### Filtering with search input
53+
To trigger an action when a specific item's action icon is selected, pass in the `onClick` property to that `<MenuItemAction>`. The following example logs "clicked on code icon" to the console when the "code" icon is selected.
4254

43-
```ts file="MenuFilteringWithSearchInput.tsx"
55+
```ts file="MenuWithActions.tsx"
4456
```
4557

4658
### With links
4759

60+
Use the `to` property to add a link to a `<MenuItem>` that directs users to a new page when the item is selected. Use the `isExternalLink` property when linking to external resources. This will annotate a menu item link with an external link icon when they navigate to the link or hover over it.
61+
4862
```ts file="MenuWithLinks.tsx"
4963
```
5064

51-
### With separator(s)
65+
### With descriptions
5266

53-
```ts file="MenuWithSeparators.tsx"
67+
Use the `description` property to add short descriptive text below any menu item that needs additional context.
68+
69+
```ts file="MenuWithDescription.tsx"
5470
```
5571

56-
### With titled groups
72+
### Item checkbox
5773

58-
```ts file="MenuWithTitledGroups.tsx"
74+
Use the `hasCheck` property to add a checkbox to a `<MenuItem>`. Use the `isSelected` property to indicate when a `<MenuItem>` is selected.
75+
76+
```ts file="./MenuWithCheckbox.tsx" isBeta
5977
```
6078

61-
### With description
79+
### Menu footer
6280

63-
```ts file="MenuWithDescription.tsx"
81+
Add a `<MenuFooter>` that contains separate, but related actions at the bottom of a menu.
82+
83+
```ts file="MenuWithFooter.tsx"
6484
```
6585

66-
### With actions
86+
### Separated items
6787

68-
```ts file="MenuWithActions.tsx"
88+
Use a [divider](/components/divider) to visually separate `<MenuContent>`. Use the `component` property to specify the type of divider component to use.
89+
90+
```ts file="MenuWithSeparators.tsx"
91+
```
92+
93+
### Titled groups of items
94+
95+
Add a `<MenuGroup>` to organize `<MenuContent>` and use the `label` property to title a group of menu items. Use the `labelHeadingLevel` property to assign a heading level to the menu group label.
96+
97+
```ts file="MenuWithTitledGroups.tsx"
6998
```
7099

71100
### With favorites
72101

102+
The following menu example allows users to favorite menu items, an action that duplicates a menu item and places it in a separate group at the top of the menu. The `isFavorited` property identifies items that a user has favorited.
103+
73104
```ts file="MenuWithFavorites.tsx"
74105
```
75106

76-
### Option single select
107+
### Filtering with search input
108+
109+
A [search input](/components/search-input) component can be placed within `<MenuInput>` to render a search input at the top of the menu. In the following example, the `onChange` property of the text input is passed a callback that filters menu items as a user types.
110+
111+
```ts file="MenuFilteringWithSearchInput.tsx"
112+
```
113+
114+
### Option single select menu
115+
116+
The following example demonstrates a single option select menu that persists a selected menu item. Use the `selected` property on the `<Menu>` to label a selected item with a checkmark. You can also use the `isSelected` property on a `<MenuItem>` to indicate that it is selected.
77117

78118
```ts file="MenuOptionSingleSelect.tsx"
79119
```
80120

81-
### Option multi select
121+
### Option multi select menu
122+
123+
To persist multiple selections that a user makes, use a multiple option select menu. To enable multi select, pass an array containing each selected `itemId` to the `selected` property.
82124

83125
```ts file="MenuOptionMultiSelect.tsx"
84126
```
85127

86-
### With drilldown
128+
### Scrollable menus
87129

88-
```ts file="./MenuWithDrilldown.tsx" isBeta
130+
Use the `isScrollable` property to make a long `<Menu>` scrollable and visually condensed.
131+
132+
```ts file="MenuScrollable.tsx"
89133
```
90134

91-
### With drilldown - initial drill in state
135+
### Scrollable menu with custom height
92136

93-
To render an initially drilled in menu, the `menuDrilledIn`, `drilldownPath`, and `activeMenu` states must be set to an initial state. The `menuHeights` state must also be set, defining the height of the root menu. The `setHeight` function passed into the `onGetMenuHeight` property must also account for updating heights, other than the root menu, as menus drill in and out of view.
137+
Adjust the visual size of a scrollable menu by using the `menuHeight` property within `<MenuContent>`. This example adjusts the height to 200px.
94138

95-
```ts file="./MenuWithDrilldownInitialState.tsx" isBeta
139+
```ts file="MenuScrollableCustomMenuHeight.tsx"
96140
```
97141

98-
### With drilldown - submenu functions
142+
### With view more
99143

100-
```ts file="./MenuWithDrilldownSubmenuFunctions.tsx" isBeta
101-
```
144+
If you want to initially render only a certain number of menu items within a large menu, you can add a "view more" menu item with a callback passed into its `onClick` property that will render additional menu items.
102145

103-
### With drilldown breadcrumbs
146+
In this example, 3 additional menu items are revealed each time the "view more" option is selected, with a loading icon simulating a network call to fetch more items. After all items are visible, the "view more" link disappears.
104147

105-
```ts file="MenuWithDrilldownBreadcrumbs.tsx" isBeta
148+
```ts file="MenuWithViewMore.tsx"
106149
```
107150

108-
### With drilldown and inline filter
151+
### With drilldown
109152

110-
```ts file="MenuFilterDrilldown.tsx"
111-
```
153+
Use a drilldown menu to contain different levels of menu items. When a parent menu item (an item that has a submenu of children) is selected, the menu is replaced with the children items.
112154

113-
### Scrollable
155+
- To indicate that a menu contains a drilldown, use the `containsDrilldown` property.
156+
- To indicate the path of drilled-in menu item ids, use the `drilldownItemPath` property.
157+
- Pass in an array of drilled-in menus with the `drilledInMenus` property.
158+
- Use the `onDrillIn` and `onDrillOut` properties to contain callbacks for drilling into and drilling out of a submenu, respectively.
159+
- To account for updated heights as menus drill in and out of use, use the `onGetMenuHeight` property. When starting from a drilled-in state, the `onGetMenuHeight` property must define the height of the root menu.
114160

115-
```ts file="MenuScrollable.tsx"
161+
```ts file="./MenuWithDrilldown.tsx" isBeta
116162
```
117163

118-
### Scrollable with custom menu height
164+
### Initially drilled-in menu
119165

120-
```ts file="MenuScrollableCustomMenuHeight.tsx"
166+
To render an initially drilled-in menu, the `drilldownItemPath`, `drilledInMenus`, and `activeMenu` properties must be set to default values.
167+
168+
```ts file="./MenuWithDrilldownInitialState.tsx" isBeta
121169
```
122170

123-
### With footer
171+
### With drilldown - submenu functions
124172

125-
```ts file="MenuWithFooter.tsx"
173+
For added flexibility with large menus, you may create a menu by passing a function to `drilldownMenu`. This approach allows you to create menu items dynamically, rather than creating everything up front.
174+
175+
```ts file="./MenuWithDrilldownSubmenuFunctions.tsx" isBeta
126176
```
127177

128-
### With view more
178+
### With drilldown breadcrumbs
129179

130-
```ts file="MenuWithViewMore.tsx"
180+
Use [breadcrumbs](/components/breadcrumb) when a drilldown menu has more than 2 levels to offer users better navigation.
181+
182+
To control the height of a menu, use the `maxMenuHeight` property. Selecting the "Set max menu height" checkbox in the following example sets the menu height to "100px" and makes the menu scrollable.
183+
184+
```ts file="MenuWithDrilldownBreadcrumbs.tsx" isBeta
131185
```
186+
187+
### With drilldown and inline filter
188+
189+
```ts file="MenuFilterDrilldown.tsx"
190+
```

0 commit comments

Comments
 (0)