From 4141a1e19b02267b74b9d0358c1682e8f80ff981 Mon Sep 17 00:00:00 2001 From: Felix Habib Date: Wed, 18 Dec 2024 15:38:55 +1100 Subject: [PATCH] Ensure left slot spacing is consistent --- .../components/MenuItem/useMenuItem.css.ts | 4 + .../lib/components/MenuItem/useMenuItem.tsx | 75 +++++++++++++------ .../MenuItemCheckbox/MenuItemCheckbox.tsx | 41 +++++----- 3 files changed, 74 insertions(+), 46 deletions(-) diff --git a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.css.ts b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.css.ts index b9d84156ee4..bebbe9e06ea 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.css.ts +++ b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.css.ts @@ -7,3 +7,7 @@ export const menuItem = style({ }, }, }); + +export const menuItemLeftSlot = style({ + height: '0px', +}); 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..ca99079a7d8 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx +++ b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx @@ -160,7 +160,7 @@ export function useMenuItem({ display: 'flex', alignItems: 'center', width: 'full', - paddingX: size === 'standard' ? 'small' : 'small', // todo - with 'small' size - small or xsmall? + paddingX: size === 'standard' ? 'small' : 'small', paddingY: size === 'standard' ? undefined : 'xsmall', height: size === 'standard' ? 'touchable' : undefined, cursor: 'pointer', @@ -173,6 +173,46 @@ 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 +228,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 +243,17 @@ function MenuItemChildren({ const { size, reserveIconSpace } = menuRendererContext; - const leftSlot = - !formElement && (icon || reserveIconSpace) ? ( - - {icon || ( - -   - - )} - - ) : null; - return ( - {leftSlot ? ( - - {leftSlot} - + {!formElement && (icon || reserveIconSpace) ? ( + + + {icon} + + ) : null} - + - + + + - +