Skip to content

Commit

Permalink
[docs] document new items.renderItem objet property
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Feb 5, 2024
1 parent 6feb94f commit 2c3c923
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src-docs/src/views/context_menu/context_menu_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EuiContextMenu,
EuiContextMenuItem,
EuiContextMenuPanel,
EuiTitle,
} from '../../../../src/components';
import { EuiContextMenuPanelDescriptor } from '!!prop-loader!../../../../src/components/context_menu/context_menu';

Expand Down Expand Up @@ -173,6 +174,9 @@ export const ContextMenuExample = {
],
text: (
<>
<EuiTitle>
<h3>Custom panels</h3>
</EuiTitle>
<p>
Context menu panels can be passed React elements through the{' '}
<EuiCode>content</EuiCode> prop instead of <EuiCode>items</EuiCode>.
Expand All @@ -184,16 +188,24 @@ export const ContextMenuExample = {
<EuiCode language="ts">width: [number of pixels]</EuiCode> to the
panel tree.
</p>
<EuiTitle>
<h3>Custom items</h3>
</EuiTitle>
<p>
You can add separator lines in the <EuiCode>items</EuiCode> prop if
you define an item as{' '}
<EuiCode language="ts">{'{isSeparator: true}'}</EuiCode>. This will
pass the rest of its fields as props to a{' '}
pass the rest of the object properties to an{' '}
<Link to="/layout/horizontal-rule">
<strong>EuiHorizontalRule</strong>
</Link>{' '}
component.
</p>
<p>
For completely custom rendered items, you can use the{' '}
<EuiCode>{'{renderItem}'}</EuiCode> property to pass a component or
any function that returns a JSX node.
</p>
</>
),
demo: <ContextMenuWithContent />,
Expand Down
22 changes: 16 additions & 6 deletions src-docs/src/views/context_menu/context_menu_with_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EuiContextMenu,
EuiIcon,
EuiPopover,
EuiPopoverFooter,
EuiSpacer,
EuiText,
} from '../../../../src/components';
Expand Down Expand Up @@ -64,10 +65,6 @@ export default () => {
icon: <EuiIcon type="search" size="m" />,
onClick: closePopover,
},
{
isSeparator: true,
key: 'sep',
},
{
name: 'See more',
icon: 'plusInCircle',
Expand All @@ -78,6 +75,19 @@ export default () => {
content: <Content />,
},
},
{
isSeparator: true,
key: 'sep',
},
{
renderItem: () => (
<EuiPopoverFooter paddingSize="s">
<EuiButton size="s" style={{ marginInlineStart: 'auto' }}>
I'm a custom item!
</EuiButton>
</EuiPopoverFooter>
),
},
],
});
};
Expand Down Expand Up @@ -116,7 +126,7 @@ export default () => {
);

return (
<React.Fragment>
<>
<EuiPopover
id={normalContextMenuPopoverId}
button={button}
Expand All @@ -140,6 +150,6 @@ export default () => {
>
<EuiContextMenu initialPanelId={0} panels={dynamicPanels} />
</EuiPopover>
</React.Fragment>
</>
);
};

0 comments on commit 2c3c923

Please sign in to comment.