fix: dropdownMenu item badge position (#10682)

This commit is contained in:
David Luzar
2026-01-21 14:07:36 +01:00
committed by GitHub
parent 84a309d669
commit acf54c6f38
5 changed files with 20 additions and 8 deletions
+1 -1
View File
@@ -1263,9 +1263,9 @@ export const ShapesSwitcher = ({
onSelect={() => app.onMagicframeToolSelect()} onSelect={() => app.onMagicframeToolSelect()}
icon={MagicIcon} icon={MagicIcon}
data-testid="toolbar-magicframe" data-testid="toolbar-magicframe"
badge={<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>}
> >
{t("toolBar.magicframe")} {t("toolBar.magicframe")}
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
</DropdownMenu.Item> </DropdownMenu.Item>
)} )}
</DropdownMenu.Content> </DropdownMenu.Content>
@@ -290,13 +290,15 @@ export const FontPickerList = React.memo(
onHover(font.value); onHover(font.value);
} }
}} }}
badge={
font.badge && (
<DropDownMenuItemBadge type={font.badge.type}>
{font.badge.placeholder}
</DropDownMenuItemBadge>
)
}
> >
{font.text} {font.text}
{font.badge && (
<DropDownMenuItemBadge type={font.badge.type}>
{font.badge.placeholder}
</DropDownMenuItemBadge>
)}
</DropdownMenuItem> </DropdownMenuItem>
); );
@@ -26,9 +26,9 @@ export const TTDDialogTrigger = ({
setAppState({ openDialog: { name: "ttd", tab: "text-to-diagram" } }); setAppState({ openDialog: { name: "ttd", tab: "text-to-diagram" } });
}} }}
icon={icon ?? brainIcon} icon={icon ?? brainIcon}
badge={<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>}
> >
{children ?? t("labels.textToDiagram")} {children ?? t("labels.textToDiagram")}
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
</DropdownMenu.Item> </DropdownMenu.Item>
</TTDDialogTriggerTunnel.In> </TTDDialogTriggerTunnel.In>
); );
@@ -26,6 +26,7 @@ const DropdownMenuItem = ({
textStyle, textStyle,
onSelect, onSelect,
onClick, onClick,
badge,
...rest ...rest
}: { }: {
icon?: JSX.Element; icon?: JSX.Element;
@@ -38,6 +39,7 @@ const DropdownMenuItem = ({
selected?: boolean; selected?: boolean;
textStyle?: React.CSSProperties; textStyle?: React.CSSProperties;
className?: string; className?: string;
badge?: React.ReactNode;
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => { } & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
const handleClick = useHandleDropdownMenuItemClick(onClick, onSelect); const handleClick = useHandleDropdownMenuItemClick(onClick, onSelect);
const ref = useRef<HTMLButtonElement>(null); const ref = useRef<HTMLButtonElement>(null);
@@ -62,7 +64,12 @@ const DropdownMenuItem = ({
className={getDropdownMenuItemClassName(className, selected, hovered)} className={getDropdownMenuItemClassName(className, selected, hovered)}
title={rest.title ?? rest["aria-label"]} title={rest.title ?? rest["aria-label"]}
> >
<MenuItemContent textStyle={textStyle} icon={icon} shortcut={shortcut}> <MenuItemContent
textStyle={textStyle}
icon={icon}
shortcut={shortcut}
badge={badge}
>
{children} {children}
</MenuItemContent> </MenuItemContent>
</button> </button>
@@ -9,11 +9,13 @@ const MenuItemContent = ({
icon, icon,
shortcut, shortcut,
children, children,
badge,
}: { }: {
icon?: JSX.Element; icon?: JSX.Element;
shortcut?: string; shortcut?: string;
textStyle?: React.CSSProperties; textStyle?: React.CSSProperties;
children: React.ReactNode; children: React.ReactNode;
badge?: React.ReactNode;
}) => { }) => {
const editorInterface = useEditorInterface(); const editorInterface = useEditorInterface();
return ( return (
@@ -22,6 +24,7 @@ const MenuItemContent = ({
<div style={textStyle} className="dropdown-menu-item__text"> <div style={textStyle} className="dropdown-menu-item__text">
<Ellipsify>{children}</Ellipsify> <Ellipsify>{children}</Ellipsify>
</div> </div>
{badge && <div className="dropdown-menu-item__badge">{badge}</div>}
{shortcut && editorInterface.formFactor !== "phone" && ( {shortcut && editorInterface.formFactor !== "phone" && (
<div className="dropdown-menu-item__shortcut">{shortcut}</div> <div className="dropdown-menu-item__shortcut">{shortcut}</div>
)} )}