From 8cbe1b9964c675d6372fa40030ab6cf4d425622c Mon Sep 17 00:00:00 2001 From: Michael Taranto Date: Mon, 23 Dec 2024 16:14:42 +1100 Subject: [PATCH] Refactor: Move MenuItemLeftSlot to MenuItemChildren prop --- .../src/lib/components/MenuItem/MenuItem.tsx | 4 +- .../lib/components/MenuItem/MenuItemLink.tsx | 2 +- .../lib/components/MenuItem/useMenuItem.tsx | 75 +++++++++---------- .../MenuItemCheckbox/MenuItemCheckbox.tsx | 46 ++++++------ 4 files changed, 60 insertions(+), 67 deletions(-) diff --git a/packages/braid-design-system/src/lib/components/MenuItem/MenuItem.tsx b/packages/braid-design-system/src/lib/components/MenuItem/MenuItem.tsx index fc75ac45d1c..a624caa60f3 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/MenuItem.tsx +++ b/packages/braid-design-system/src/lib/components/MenuItem/MenuItem.tsx @@ -10,7 +10,7 @@ export interface MenuItemProps extends Pick { children: ReactNode; badge?: MenuItemChildrenProps['badge']; - icon?: MenuItemChildrenProps['icon']; + icon?: MenuItemChildrenProps['leftSlot']; } export const MenuItem = ({ children, @@ -30,7 +30,7 @@ export const MenuItem = ({ return ( - + {children} diff --git a/packages/braid-design-system/src/lib/components/MenuItem/MenuItemLink.tsx b/packages/braid-design-system/src/lib/components/MenuItem/MenuItemLink.tsx index da5902f5459..26a0472127e 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/MenuItemLink.tsx +++ b/packages/braid-design-system/src/lib/components/MenuItem/MenuItemLink.tsx @@ -36,7 +36,7 @@ export const MenuItemLink = ({ target={target} rel={rel} > - + {children} 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 af5a01c65b5..b34456f86a0 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx +++ b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx @@ -174,51 +174,23 @@ export function useMenuItem({ } as const; } -export function MenuItemLeftSlot({ children }: { children?: ReactNode }) { - const menuRendererContext = useContext(MenuRendererContext); - const size = menuRendererContext?.size; - const iconSpace = useBraidTheme().legacy ? 'small' : iconSlotSpace; - - return ( - - -   - - {children ? ( - - {children} - - ) : null} - - ); -} - export interface MenuItemChildrenProps { children: ReactNode; tone: MenuItemTone; badge: ReactElement | undefined; - icon: ReactNode | undefined; - formElement?: boolean; + leftSlot: ReactNode | undefined; + isCheckbox?: boolean; } function MenuItemChildren({ - icon, + leftSlot, tone, children, badge, - formElement = false, + isCheckbox = false, }: MenuItemChildrenProps) { const menuRendererContext = useContext(MenuRendererContext); const badgeSpace = useBraidTheme().legacy ? 'small' : badgeSlotSpace; + const iconSpace = useBraidTheme().legacy ? 'small' : iconSlotSpace; assert( menuRendererContext !== null, @@ -235,15 +207,36 @@ function MenuItemChildren({ return ( - {!formElement && (icon || reserveIconSpace) ? ( - - + - {icon} - - +   + + {leftSlot ? ( + + {isCheckbox ? ( + leftSlot + ) : ( + + {leftSlot} + + )} + + ) : null} + ) : null} - - + - + + + - - - {children}