UNPKG

tldraw

Version:

A tiny little drawing editor.

8 lines (7 loc) 3.35 kB
{ "version": 3, "sources": ["../../../../../../src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx"], "sourcesContent": ["import { ContextMenuGroup } from '@radix-ui/react-context-menu'\nimport { ReactNode } from 'react'\nimport { unwrapLabel } from '../../../context/actions'\nimport { TLUiTranslationKey } from '../../../hooks/useTranslation/TLUiTranslationKey'\nimport { useTranslation } from '../../../hooks/useTranslation/useTranslation'\nimport { TldrawUiDropdownMenuGroup } from '../TldrawUiDropdownMenu'\nimport { useTldrawUiMenuContext } from './TldrawUiMenuContext'\n\n/** @public */\nexport interface TLUiMenuGroupProps<TranslationKey extends string = string> {\n\tid: string\n\t/**\n\t * 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.\n\t */\n\tlabel?: TranslationKey | { [key: string]: TranslationKey }\n\tchildren?: ReactNode\n}\n\n/** @public @react */\nexport function TldrawUiMenuGroup({ id, label, children }: TLUiMenuGroupProps) {\n\tconst { type: menuType, sourceId } = useTldrawUiMenuContext()\n\tconst msg = useTranslation()\n\tconst labelToUse = unwrapLabel(label, menuType)\n\tconst labelStr = labelToUse ? msg(labelToUse as TLUiTranslationKey) : undefined\n\n\tswitch (menuType) {\n\t\tcase 'panel': {\n\t\t\treturn (\n\t\t\t\t<div className=\"tlui-menu__group\" data-testid={`${sourceId}-group.${id}`}>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\t\tcase 'menu': {\n\t\t\treturn (\n\t\t\t\t<TldrawUiDropdownMenuGroup data-testid={`${sourceId}-group.${id}`}>\n\t\t\t\t\t{children}\n\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t)\n\t\t}\n\t\tcase 'context-menu': {\n\t\t\treturn (\n\t\t\t\t<ContextMenuGroup\n\t\t\t\t\tdir=\"ltr\"\n\t\t\t\t\tclassName=\"tlui-menu__group\"\n\t\t\t\t\tdata-testid={`${sourceId}-group.${id}`}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</ContextMenuGroup>\n\t\t\t)\n\t\t}\n\t\tcase 'keyboard-shortcuts': {\n\t\t\t// todo: if groups need a label, let's give em a label\n\t\t\treturn (\n\t\t\t\t<div className=\"tlui-shortcuts-dialog__group\" data-testid={`${sourceId}-group.${id}`}>\n\t\t\t\t\t<h2 className=\"tlui-shortcuts-dialog__group__title\">{labelStr}</h2>\n\t\t\t\t\t<div className=\"tlui-shortcuts-dialog__group__content\">{children}</div>\n\t\t\t\t</div>\n\t\t\t)\n\t\t}\n\t\tdefault: {\n\t\t\treturn children\n\t\t}\n\t}\n}\n"], "mappings": "AA4BI,cA0BA,YA1BA;AA5BJ,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB;AAE5B,SAAS,sBAAsB;AAC/B,SAAS,iCAAiC;AAC1C,SAAS,8BAA8B;AAahC,SAAS,kBAAkB,EAAE,IAAI,OAAO,SAAS,GAAuB;AAC9E,QAAM,EAAE,MAAM,UAAU,SAAS,IAAI,uBAAuB;AAC5D,QAAM,MAAM,eAAe;AAC3B,QAAM,aAAa,YAAY,OAAO,QAAQ;AAC9C,QAAM,WAAW,aAAa,IAAI,UAAgC,IAAI;AAEtE,UAAQ,UAAU;AAAA,IACjB,KAAK,SAAS;AACb,aACC,oBAAC,SAAI,WAAU,oBAAmB,eAAa,GAAG,QAAQ,UAAU,EAAE,IACpE,UACF;AAAA,IAEF;AAAA,IACA,KAAK,QAAQ;AACZ,aACC,oBAAC,6BAA0B,eAAa,GAAG,QAAQ,UAAU,EAAE,IAC7D,UACF;AAAA,IAEF;AAAA,IACA,KAAK,gBAAgB;AACpB,aACC;AAAA,QAAC;AAAA;AAAA,UACA,KAAI;AAAA,UACJ,WAAU;AAAA,UACV,eAAa,GAAG,QAAQ,UAAU,EAAE;AAAA,UAEnC;AAAA;AAAA,MACF;AAAA,IAEF;AAAA,IACA,KAAK,sBAAsB;AAE1B,aACC,qBAAC,SAAI,WAAU,gCAA+B,eAAa,GAAG,QAAQ,UAAU,EAAE,IACjF;AAAA,4BAAC,QAAG,WAAU,uCAAuC,oBAAS;AAAA,QAC9D,oBAAC,SAAI,WAAU,yCAAyC,UAAS;AAAA,SAClE;AAAA,IAEF;AAAA,IACA,SAAS;AACR,aAAO;AAAA,IACR;AAAA,EACD;AACD;", "names": [] }