From f5cd65359b569a6745f62255051ab52793dd52f8 Mon Sep 17 00:00:00 2001 From: Felix Habib Date: Wed, 18 Dec 2024 14:59:51 +1100 Subject: [PATCH] Ensure left slot spacing is consistent --- .../lib/components/MenuItem/useMenuItem.tsx | 70 +++++++++++++------ .../MenuItemCheckbox/MenuItemCheckbox.tsx | 41 +++++------ 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx index 320c6309fc2..f26c47e81f1 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx +++ b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx @@ -173,6 +173,43 @@ export function useMenuItem({ } as const; } +export function MenuItemLeftSlot({ children }: { children?: ReactNode }) { + const menuRendererContext = useContext(MenuRendererContext); + + assert( + menuRendererContext !== null, + `MenuItem must be rendered as an immediate child of a menu. See the documentation for correct usage: https://seek-oss.github.io/braid-design-system/components/MenuItem`, + ); + + const { size } = menuRendererContext; + const iconSpace = useBraidTheme().legacy ? 'small' : iconSlotSpace; + return ( + + +   + + {children ? ( + + {children} + + ) : null} + + ); +} + export interface MenuItemChildrenProps { children: ReactNode; tone: MenuItemTone; @@ -188,9 +225,7 @@ function MenuItemChildren({ formElement = false, }: MenuItemChildrenProps) { const menuRendererContext = useContext(MenuRendererContext); - const legacy = useBraidTheme().legacy; - const iconSpace = legacy ? 'small' : iconSlotSpace; - const badgeSpace = legacy ? 'small' : badgeSlotSpace; + const badgeSpace = useBraidTheme().legacy ? 'small' : badgeSlotSpace; assert( menuRendererContext !== null, @@ -205,28 +240,17 @@ function MenuItemChildren({ const { size, reserveIconSpace } = menuRendererContext; - const leftSlot = - !formElement && (icon || reserveIconSpace) ? ( - - {icon || ( - -   - - )} - - ) : null; - return ( - {leftSlot ? ( - - {leftSlot} - + {!formElement && (icon || reserveIconSpace) ? ( + + + {icon} + + ) : null} - + - + + + - +