2021-11-03 16:46:33 +00:00
|
|
|
import * as React from 'react'
|
2021-11-06 11:16:30 +00:00
|
|
|
import { styled } from '~styles'
|
2021-11-03 16:46:33 +00:00
|
|
|
import * as RadixContextMenu from '@radix-ui/react-context-menu'
|
2021-11-16 16:01:29 +00:00
|
|
|
import { useTldrawApp } from '~hooks'
|
|
|
|
import { TDSnapshot, AlignType, DistributeType, StretchType } from '~types'
|
2021-11-03 16:46:33 +00:00
|
|
|
import {
|
|
|
|
AlignBottomIcon,
|
|
|
|
AlignCenterHorizontallyIcon,
|
|
|
|
AlignCenterVerticallyIcon,
|
|
|
|
AlignLeftIcon,
|
|
|
|
AlignRightIcon,
|
|
|
|
AlignTopIcon,
|
|
|
|
SpaceEvenlyHorizontallyIcon,
|
|
|
|
SpaceEvenlyVerticallyIcon,
|
|
|
|
StretchHorizontallyIcon,
|
|
|
|
StretchVerticallyIcon,
|
|
|
|
} from '@radix-ui/react-icons'
|
2021-11-19 10:19:06 +00:00
|
|
|
import { Divider } from '~components/Primitives/Divider'
|
|
|
|
import { MenuContent } from '~components/Primitives/MenuContent'
|
|
|
|
import { RowButton, RowButtonProps } from '~components/Primitives/RowButton'
|
|
|
|
import { ToolButton, ToolButtonProps } from '~components/Primitives/ToolButton'
|
|
|
|
|
|
|
|
const numberOfSelectedIdsSelector = (s: TDSnapshot) => {
|
|
|
|
return s.document.pageStates[s.appState.currentPageId].selectedIds.length
|
2021-11-03 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 16:01:29 +00:00
|
|
|
const isDebugModeSelector = (s: TDSnapshot) => {
|
2021-11-03 16:46:33 +00:00
|
|
|
return s.settings.isDebugMode
|
|
|
|
}
|
|
|
|
|
2021-11-16 16:01:29 +00:00
|
|
|
const hasGroupSelectedSelector = (s: TDSnapshot) => {
|
2021-11-03 16:46:33 +00:00
|
|
|
return s.document.pageStates[s.appState.currentPageId].selectedIds.some(
|
|
|
|
(id) => s.document.pages[s.appState.currentPageId].shapes[id].children !== undefined
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-11-05 14:13:14 +00:00
|
|
|
const preventDefault = (e: Event) => e.stopPropagation()
|
|
|
|
|
2021-11-03 16:46:33 +00:00
|
|
|
interface ContextMenuProps {
|
2022-01-06 14:00:23 +00:00
|
|
|
onBlur?: React.FocusEventHandler
|
2021-11-03 16:46:33 +00:00
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
|
2021-11-11 09:54:58 +00:00
|
|
|
export const ContextMenu = ({ onBlur, children }: ContextMenuProps): JSX.Element => {
|
2022-01-06 14:00:23 +00:00
|
|
|
return (
|
|
|
|
<RadixContextMenu.Root dir="ltr">
|
|
|
|
<RadixContextMenu.Trigger dir="ltr">{children}</RadixContextMenu.Trigger>
|
|
|
|
<InnerMenu onBlur={onBlur} />
|
|
|
|
</RadixContextMenu.Root>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
interface InnerContextMenuProps {
|
|
|
|
onBlur?: React.FocusEventHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
const InnerMenu = React.memo(function InnerMenu({ onBlur }: InnerContextMenuProps) {
|
2021-11-16 16:01:29 +00:00
|
|
|
const app = useTldrawApp()
|
2021-11-19 10:19:06 +00:00
|
|
|
const numberOfSelectedIds = app.useStore(numberOfSelectedIdsSelector)
|
2021-11-16 16:01:29 +00:00
|
|
|
const isDebugMode = app.useStore(isDebugModeSelector)
|
|
|
|
const hasGroupSelected = app.useStore(hasGroupSelectedSelector)
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const rContent = React.useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
const handleFlipHorizontal = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.flipHorizontal()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleFlipVertical = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.flipVertical()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleDuplicate = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.duplicate()
|
|
|
|
}, [app])
|
|
|
|
|
|
|
|
const handleLock = React.useCallback(() => {
|
|
|
|
app.toggleLocked()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleGroup = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.group()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleMoveToBack = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.moveToBack()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleMoveBackward = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.moveBackward()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleMoveForward = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.moveForward()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleMoveToFront = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.moveToFront()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleDelete = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.delete()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleCopyJson = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.copyJson()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
2021-11-27 16:26:15 +00:00
|
|
|
const handleCut = React.useCallback(() => {
|
|
|
|
app.cut()
|
|
|
|
}, [app])
|
|
|
|
|
2021-11-03 16:46:33 +00:00
|
|
|
const handleCopy = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.copy()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handlePaste = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.paste()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleCopySvg = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.copySvg()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleUndo = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.undo()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const handleRedo = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.redo()
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
2021-11-19 10:19:06 +00:00
|
|
|
const hasSelection = numberOfSelectedIds > 0
|
|
|
|
const hasTwoOrMore = numberOfSelectedIds > 1
|
|
|
|
const hasThreeOrMore = numberOfSelectedIds > 2
|
|
|
|
|
2021-11-03 16:46:33 +00:00
|
|
|
return (
|
2022-01-06 14:00:23 +00:00
|
|
|
<RadixContextMenu.Content
|
|
|
|
dir="ltr"
|
|
|
|
ref={rContent}
|
|
|
|
onEscapeKeyDown={preventDefault}
|
|
|
|
asChild
|
|
|
|
tabIndex={-1}
|
|
|
|
onBlur={onBlur}
|
|
|
|
>
|
|
|
|
<MenuContent>
|
|
|
|
{hasSelection ? (
|
|
|
|
<>
|
|
|
|
<CMRowButton onClick={handleDuplicate} kbd="#D">
|
|
|
|
Duplicate
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleFlipHorizontal} kbd="⇧H">
|
|
|
|
Flip Horizontal
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleFlipVertical} kbd="⇧V">
|
|
|
|
Flip Vertical
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleLock} kbd="#⇧L">
|
|
|
|
Lock / Unlock
|
|
|
|
</CMRowButton>
|
|
|
|
{(hasTwoOrMore || hasGroupSelected) && <Divider />}
|
|
|
|
{hasTwoOrMore && (
|
|
|
|
<CMRowButton onClick={handleGroup} kbd="#G">
|
|
|
|
Group
|
2021-11-27 16:26:15 +00:00
|
|
|
</CMRowButton>
|
2022-01-06 14:00:23 +00:00
|
|
|
)}
|
|
|
|
{hasGroupSelected && (
|
|
|
|
<CMRowButton onClick={handleGroup} kbd="#G">
|
|
|
|
Ungroup
|
2021-11-03 16:46:33 +00:00
|
|
|
</CMRowButton>
|
2022-01-06 14:00:23 +00:00
|
|
|
)}
|
|
|
|
<Divider />
|
|
|
|
<ContextMenuSubMenu label="Move">
|
|
|
|
<CMRowButton onClick={handleMoveToFront} kbd="⇧]">
|
|
|
|
To Front
|
2021-11-03 16:46:33 +00:00
|
|
|
</CMRowButton>
|
2022-01-06 14:00:23 +00:00
|
|
|
<CMRowButton onClick={handleMoveForward} kbd="]">
|
|
|
|
Forward
|
2021-11-03 16:46:33 +00:00
|
|
|
</CMRowButton>
|
2022-01-06 14:00:23 +00:00
|
|
|
<CMRowButton onClick={handleMoveBackward} kbd="[">
|
|
|
|
Backward
|
2021-11-03 16:46:33 +00:00
|
|
|
</CMRowButton>
|
2022-01-06 14:00:23 +00:00
|
|
|
<CMRowButton onClick={handleMoveToBack} kbd="⇧[">
|
|
|
|
To Back
|
2021-11-03 16:46:33 +00:00
|
|
|
</CMRowButton>
|
2022-01-06 14:00:23 +00:00
|
|
|
</ContextMenuSubMenu>
|
|
|
|
<MoveToPageMenu />
|
|
|
|
{hasTwoOrMore && (
|
|
|
|
<AlignDistributeSubMenu hasTwoOrMore={hasTwoOrMore} hasThreeOrMore={hasThreeOrMore} />
|
|
|
|
)}
|
|
|
|
<Divider />
|
|
|
|
<CMRowButton onClick={handleCut} kbd="#X">
|
|
|
|
Cut
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleCopy} kbd="#C">
|
|
|
|
Copy
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleCopySvg} kbd="#⇧C">
|
|
|
|
Copy as SVG
|
|
|
|
</CMRowButton>
|
|
|
|
{isDebugMode && <CMRowButton onClick={handleCopyJson}>Copy as JSON</CMRowButton>}
|
|
|
|
<CMRowButton onClick={handlePaste} kbd="#V">
|
|
|
|
Paste
|
|
|
|
</CMRowButton>
|
|
|
|
<Divider />
|
|
|
|
<CMRowButton onClick={handleDelete} kbd="⌫">
|
|
|
|
Delete
|
|
|
|
</CMRowButton>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<CMRowButton onClick={handlePaste} kbd="#V">
|
|
|
|
Paste
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleUndo} kbd="#Z">
|
|
|
|
Undo
|
|
|
|
</CMRowButton>
|
|
|
|
<CMRowButton onClick={handleRedo} kbd="#⇧Z">
|
|
|
|
Redo
|
|
|
|
</CMRowButton>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</MenuContent>
|
|
|
|
</RadixContextMenu.Content>
|
2021-11-03 16:46:33 +00:00
|
|
|
)
|
2022-01-06 14:00:23 +00:00
|
|
|
})
|
2021-11-03 16:46:33 +00:00
|
|
|
|
2021-11-19 10:19:06 +00:00
|
|
|
/* ---------- Align and Distribute Sub Menu --------- */
|
|
|
|
|
2021-11-03 16:46:33 +00:00
|
|
|
function AlignDistributeSubMenu({
|
|
|
|
hasThreeOrMore,
|
|
|
|
}: {
|
|
|
|
hasTwoOrMore: boolean
|
|
|
|
hasThreeOrMore: boolean
|
|
|
|
}) {
|
2021-11-16 16:01:29 +00:00
|
|
|
const app = useTldrawApp()
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const alignTop = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.align(AlignType.Top)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const alignCenterVertical = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.align(AlignType.CenterVertical)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const alignBottom = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.align(AlignType.Bottom)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const stretchVertically = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.stretch(StretchType.Vertical)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const distributeVertically = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.distribute(DistributeType.Vertical)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const alignLeft = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.align(AlignType.Left)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const alignCenterHorizontal = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.align(AlignType.CenterHorizontal)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const alignRight = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.align(AlignType.Right)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const stretchHorizontally = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.stretch(StretchType.Horizontal)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const distributeHorizontally = React.useCallback(() => {
|
2021-11-16 16:01:29 +00:00
|
|
|
app.distribute(DistributeType.Horizontal)
|
|
|
|
}, [app])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
return (
|
2021-11-16 16:01:29 +00:00
|
|
|
<RadixContextMenu.Root dir="ltr">
|
2021-11-03 16:46:33 +00:00
|
|
|
<CMTriggerButton isSubmenu>Align / Distribute</CMTriggerButton>
|
|
|
|
<RadixContextMenu.Content asChild sideOffset={2} alignOffset={-2}>
|
2021-11-19 10:19:06 +00:00
|
|
|
<StyledGridContent numberOfSelected={hasThreeOrMore ? 'threeOrMore' : 'twoOrMore'}>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={alignLeft}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<AlignLeftIcon />
|
|
|
|
</CMIconButton>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={alignCenterHorizontal}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<AlignCenterHorizontallyIcon />
|
|
|
|
</CMIconButton>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={alignRight}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<AlignRightIcon />
|
|
|
|
</CMIconButton>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={stretchHorizontally}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<StretchHorizontallyIcon />
|
|
|
|
</CMIconButton>
|
|
|
|
{hasThreeOrMore && (
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={distributeHorizontally}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<SpaceEvenlyHorizontallyIcon />
|
|
|
|
</CMIconButton>
|
|
|
|
)}
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={alignTop}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<AlignTopIcon />
|
|
|
|
</CMIconButton>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={alignCenterVertical}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<AlignCenterVerticallyIcon />
|
|
|
|
</CMIconButton>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={alignBottom}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<AlignBottomIcon />
|
|
|
|
</CMIconButton>
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={stretchVertically}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<StretchVerticallyIcon />
|
|
|
|
</CMIconButton>
|
|
|
|
{hasThreeOrMore && (
|
2021-11-16 16:01:29 +00:00
|
|
|
<CMIconButton onClick={distributeVertically}>
|
2021-11-03 16:46:33 +00:00
|
|
|
<SpaceEvenlyVerticallyIcon />
|
|
|
|
</CMIconButton>
|
|
|
|
)}
|
|
|
|
<CMArrow offset={13} />
|
|
|
|
</StyledGridContent>
|
|
|
|
</RadixContextMenu.Content>
|
|
|
|
</RadixContextMenu.Root>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const StyledGridContent = styled(MenuContent, {
|
|
|
|
display: 'grid',
|
|
|
|
variants: {
|
2021-11-19 10:19:06 +00:00
|
|
|
numberOfSelected: {
|
2021-11-03 16:46:33 +00:00
|
|
|
threeOrMore: {
|
|
|
|
gridTemplateColumns: 'repeat(5, auto)',
|
|
|
|
},
|
|
|
|
twoOrMore: {
|
|
|
|
gridTemplateColumns: 'repeat(4, auto)',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-11-19 10:19:06 +00:00
|
|
|
/* -------------- Move to Page Sub Menu ------------- */
|
2021-11-03 16:46:33 +00:00
|
|
|
|
2021-11-16 16:01:29 +00:00
|
|
|
const currentPageIdSelector = (s: TDSnapshot) => s.appState.currentPageId
|
|
|
|
const documentPagesSelector = (s: TDSnapshot) => s.document.pages
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
function MoveToPageMenu(): JSX.Element | null {
|
2021-11-16 16:01:29 +00:00
|
|
|
const app = useTldrawApp()
|
|
|
|
const currentPageId = app.useStore(currentPageIdSelector)
|
|
|
|
const documentPages = app.useStore(documentPagesSelector)
|
2021-11-03 16:46:33 +00:00
|
|
|
|
|
|
|
const sorted = Object.values(documentPages)
|
|
|
|
.sort((a, b) => (a.childIndex || 0) - (b.childIndex || 0))
|
|
|
|
.filter((a) => a.id !== currentPageId)
|
|
|
|
|
|
|
|
if (sorted.length === 0) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<RadixContextMenu.Root dir="ltr">
|
|
|
|
<CMTriggerButton isSubmenu>Move To Page</CMTriggerButton>
|
|
|
|
<RadixContextMenu.Content dir="ltr" sideOffset={2} alignOffset={-2} asChild>
|
|
|
|
<MenuContent>
|
|
|
|
{sorted.map(({ id, name }, i) => (
|
|
|
|
<CMRowButton
|
|
|
|
key={id}
|
|
|
|
disabled={id === currentPageId}
|
2021-11-16 16:01:29 +00:00
|
|
|
onClick={() => app.moveToPage(id)}
|
2021-11-03 16:46:33 +00:00
|
|
|
>
|
|
|
|
{name || `Page ${i}`}
|
|
|
|
</CMRowButton>
|
|
|
|
))}
|
|
|
|
<CMArrow offset={13} />
|
|
|
|
</MenuContent>
|
|
|
|
</RadixContextMenu.Content>
|
|
|
|
</RadixContextMenu.Root>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------- Submenu -------------------- */
|
|
|
|
|
|
|
|
export interface ContextMenuSubMenuProps {
|
|
|
|
label: string
|
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ContextMenuSubMenu({ children, label }: ContextMenuSubMenuProps): JSX.Element {
|
|
|
|
return (
|
|
|
|
<RadixContextMenu.Root dir="ltr">
|
|
|
|
<CMTriggerButton isSubmenu>{label}</CMTriggerButton>
|
|
|
|
<RadixContextMenu.Content dir="ltr" sideOffset={2} alignOffset={-2} asChild>
|
|
|
|
<MenuContent>
|
|
|
|
{children}
|
|
|
|
<CMArrow offset={13} />
|
|
|
|
</MenuContent>
|
|
|
|
</RadixContextMenu.Content>
|
|
|
|
</RadixContextMenu.Root>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------- Arrow --------------------- */
|
|
|
|
|
|
|
|
const CMArrow = styled(RadixContextMenu.ContextMenuArrow, {
|
|
|
|
fill: '$panel',
|
|
|
|
})
|
2021-11-19 10:19:06 +00:00
|
|
|
|
|
|
|
/* ------------------- IconButton ------------------- */
|
|
|
|
|
|
|
|
function CMIconButton({ onSelect, ...rest }: ToolButtonProps): JSX.Element {
|
|
|
|
return (
|
|
|
|
<RadixContextMenu.ContextMenuItem dir="ltr" onSelect={onSelect} asChild>
|
|
|
|
<ToolButton {...rest} />
|
|
|
|
</RadixContextMenu.ContextMenuItem>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------- RowButton ------------------- */
|
|
|
|
|
|
|
|
const CMRowButton = ({ ...rest }: RowButtonProps) => {
|
|
|
|
return (
|
|
|
|
<RadixContextMenu.ContextMenuItem asChild>
|
|
|
|
<RowButton {...rest} />
|
|
|
|
</RadixContextMenu.ContextMenuItem>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------- Trigger Button ----------------- */
|
|
|
|
|
|
|
|
interface CMTriggerButtonProps extends RowButtonProps {
|
|
|
|
isSubmenu?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
export const CMTriggerButton = ({ isSubmenu, ...rest }: CMTriggerButtonProps) => {
|
|
|
|
return (
|
|
|
|
<RadixContextMenu.ContextMenuTriggerItem asChild>
|
|
|
|
<RowButton hasArrow={isSubmenu} {...rest} />
|
|
|
|
</RadixContextMenu.ContextMenuTriggerItem>
|
|
|
|
)
|
|
|
|
}
|