import classNames from 'classnames' import { ReactNode } from 'react' import { unwrapLabel } from '../../../context/actions' import { TLUiTranslationKey } from '../../../hooks/useTranslation/TLUiTranslationKey' import { useDirection, useTranslation } from '../../../hooks/useTranslation/useTranslation' import { TldrawUiColumn, TldrawUiGrid, TldrawUiRow, useTldrawUiOrientation } from '../layout' import { TldrawUiDropdownMenuGroup } from '../TldrawUiDropdownMenu' import { useTldrawUiMenuContext } from './TldrawUiMenuContext' /** @public */ export interface TLUiMenuGroupProps { id: string /** * The label to display on the item. If it's a string, it will be translated. If it's an object, the keys will be used as the language keys and the values will be translated. */ label?: TranslationKey | { [key: string]: TranslationKey } className?: string children?: ReactNode } /** @public @react */ export function TldrawUiMenuGroup({ id, label, className, children }: TLUiMenuGroupProps) { const menu = useTldrawUiMenuContext() const { orientation } = useTldrawUiOrientation() const msg = useTranslation() const dir = useDirection() const labelToUse = unwrapLabel(label, menu.type) const labelStr = labelToUse ? msg(labelToUse as TLUiTranslationKey) : undefined switch (menu.type) { case 'menu': { return ( {children} ) } case 'context-menu': { return (
{children}
) } case 'keyboard-shortcuts': { // todo: if groups need a label, let's give em a label return (

{labelStr}

{children}
) } case 'toolbar': { const Layout = orientation === 'horizontal' ? TldrawUiRow : TldrawUiColumn return ( {children} ) } case 'toolbar-overflow': { return ( {children} ) } default: { return children } } }