Skip to content

Commit 2c3c923

Browse files
committed
[docs] document new items.renderItem objet property
1 parent 6feb94f commit 2c3c923

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

src-docs/src/views/context_menu/context_menu_example.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
EuiContextMenu,
1010
EuiContextMenuItem,
1111
EuiContextMenuPanel,
12+
EuiTitle,
1213
} from '../../../../src/components';
1314
import { EuiContextMenuPanelDescriptor } from '!!prop-loader!../../../../src/components/context_menu/context_menu';
1415

@@ -173,6 +174,9 @@ export const ContextMenuExample = {
173174
],
174175
text: (
175176
<>
177+
<EuiTitle>
178+
<h3>Custom panels</h3>
179+
</EuiTitle>
176180
<p>
177181
Context menu panels can be passed React elements through the{' '}
178182
<EuiCode>content</EuiCode> prop instead of <EuiCode>items</EuiCode>.
@@ -184,16 +188,24 @@ export const ContextMenuExample = {
184188
<EuiCode language="ts">width: [number of pixels]</EuiCode> to the
185189
panel tree.
186190
</p>
191+
<EuiTitle>
192+
<h3>Custom items</h3>
193+
</EuiTitle>
187194
<p>
188195
You can add separator lines in the <EuiCode>items</EuiCode> prop if
189196
you define an item as{' '}
190197
<EuiCode language="ts">{'{isSeparator: true}'}</EuiCode>. This will
191-
pass the rest of its fields as props to a{' '}
198+
pass the rest of the object properties to an{' '}
192199
<Link to="/layout/horizontal-rule">
193200
<strong>EuiHorizontalRule</strong>
194201
</Link>{' '}
195202
component.
196203
</p>
204+
<p>
205+
For completely custom rendered items, you can use the{' '}
206+
<EuiCode>{'{renderItem}'}</EuiCode> property to pass a component or
207+
any function that returns a JSX node.
208+
</p>
197209
</>
198210
),
199211
demo: <ContextMenuWithContent />,

src-docs/src/views/context_menu/context_menu_with_content.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
EuiContextMenu,
66
EuiIcon,
77
EuiPopover,
8+
EuiPopoverFooter,
89
EuiSpacer,
910
EuiText,
1011
} from '../../../../src/components';
@@ -64,10 +65,6 @@ export default () => {
6465
icon: <EuiIcon type="search" size="m" />,
6566
onClick: closePopover,
6667
},
67-
{
68-
isSeparator: true,
69-
key: 'sep',
70-
},
7168
{
7269
name: 'See more',
7370
icon: 'plusInCircle',
@@ -78,6 +75,19 @@ export default () => {
7875
content: <Content />,
7976
},
8077
},
78+
{
79+
isSeparator: true,
80+
key: 'sep',
81+
},
82+
{
83+
renderItem: () => (
84+
<EuiPopoverFooter paddingSize="s">
85+
<EuiButton size="s" style={{ marginInlineStart: 'auto' }}>
86+
I'm a custom item!
87+
</EuiButton>
88+
</EuiPopoverFooter>
89+
),
90+
},
8191
],
8292
});
8393
};
@@ -116,7 +126,7 @@ export default () => {
116126
);
117127

118128
return (
119-
<React.Fragment>
129+
<>
120130
<EuiPopover
121131
id={normalContextMenuPopoverId}
122132
button={button}
@@ -140,6 +150,6 @@ export default () => {
140150
>
141151
<EuiContextMenu initialPanelId={0} panels={dynamicPanels} />
142152
</EuiPopover>
143-
</React.Fragment>
153+
</>
144154
);
145155
};

0 commit comments

Comments
 (0)