From b2687f25b8acc129b6563fd78ffb60199ccef9bf Mon Sep 17 00:00:00 2001
From: Cee Chen <549407+cee-chen@users.noreply.github.com>
Date: Wed, 7 Feb 2024 09:23:29 -0800
Subject: [PATCH] [EuiContextMenu] Support new `renderItem` custom content in
`items` arrays (#7510)
---
changelogs/upcoming/7510.md | 1 +
.../context_menu/context_menu_example.js | 14 +++++++-
.../context_menu/context_menu_with_content.js | 22 ++++++++----
.../context_menu/context_menu.stories.tsx | 18 ++++++++++
.../context_menu/context_menu.test.tsx | 36 +++++++++++++++++++
src/components/context_menu/context_menu.tsx | 21 +++++++++--
6 files changed, 103 insertions(+), 9 deletions(-)
create mode 100644 changelogs/upcoming/7510.md
diff --git a/changelogs/upcoming/7510.md b/changelogs/upcoming/7510.md
new file mode 100644
index 00000000000..aa4670142b8
--- /dev/null
+++ b/changelogs/upcoming/7510.md
@@ -0,0 +1 @@
+- Updated `EuiContextMenu` with a new `panels.items.renderItem` property, which allows rendering completely custom items next to standard `EuiContextMenuItem` objects
diff --git a/src-docs/src/views/context_menu/context_menu_example.js b/src-docs/src/views/context_menu/context_menu_example.js
index 0694c88222d..63ce541d310 100644
--- a/src-docs/src/views/context_menu/context_menu_example.js
+++ b/src-docs/src/views/context_menu/context_menu_example.js
@@ -9,6 +9,7 @@ import {
EuiContextMenu,
EuiContextMenuItem,
EuiContextMenuPanel,
+ EuiTitle,
} from '../../../../src/components';
import { EuiContextMenuPanelDescriptor } from '!!prop-loader!../../../../src/components/context_menu/context_menu';
@@ -173,6 +174,9 @@ export const ContextMenuExample = {
],
text: (
<>
+
+
Custom panels
+
Context menu panels can be passed React elements through the{' '}
content prop instead of items.
@@ -184,16 +188,24 @@ export const ContextMenuExample = {
width: [number of pixels] to the
panel tree.
+
+
Custom items
+
You can add separator lines in the items prop if
you define an item as{' '}
{'{isSeparator: true}'}. This will
- pass the rest of its fields as props to a{' '}
+ pass the rest of the object properties to an{' '}
EuiHorizontalRule
{' '}
component.
+
+ For completely custom rendered items, you can use the{' '}
+ {'{renderItem}'} property to pass a component or
+ any function that returns a JSX node.
+