diff --git a/components/canvas/canvas.tsx b/components/canvas/canvas.tsx index 0e8c5875b..8c071e56c 100644 --- a/components/canvas/canvas.tsx +++ b/components/canvas/canvas.tsx @@ -11,7 +11,7 @@ import BoundsBg from './bounds/bounds-bg' import Selected from './selected' import Handles from './bounds/handles' import useCanvasEvents from 'hooks/useCanvasEvents' -import ContextMenu from 'components/context-menu' +import ContextMenu from './context-menu/context-menu' export default function Canvas() { const rCanvas = useRef(null) diff --git a/components/context-menu.tsx b/components/canvas/context-menu/context-menu.tsx similarity index 65% rename from components/context-menu.tsx rename to components/canvas/context-menu/context-menu.tsx index f11e3cb76..2b17d29f7 100644 --- a/components/context-menu.tsx +++ b/components/canvas/context-menu/context-menu.tsx @@ -1,7 +1,11 @@ import * as _ContextMenu from '@radix-ui/react-context-menu' import * as _Dropdown from '@radix-ui/react-dropdown-menu' import styled from 'styles' -import { IconWrapper, RowButton } from './shared' +import { + IconWrapper, + IconButton as _IconButton, + RowButton, +} from 'components/shared' import { commandKey, deepCompareArrays, @@ -9,9 +13,67 @@ import { isMobile, } from 'utils/utils' import state, { useSelector } from 'state' -import { MoveType, ShapeType } from 'types' +import { + AlignType, + DistributeType, + MoveType, + ShapeType, + StretchType, +} from 'types' import React, { useRef } from 'react' -import { ChevronRightIcon } from '@radix-ui/react-icons' +import { + ChevronRightIcon, + AlignBottomIcon, + AlignCenterHorizontallyIcon, + AlignCenterVerticallyIcon, + AlignLeftIcon, + AlignRightIcon, + AlignTopIcon, + SpaceEvenlyHorizontallyIcon, + SpaceEvenlyVerticallyIcon, + StretchHorizontallyIcon, + StretchVerticallyIcon, +} from '@radix-ui/react-icons' + +function alignTop() { + state.send('ALIGNED', { type: AlignType.Top }) +} + +function alignCenterVertical() { + state.send('ALIGNED', { type: AlignType.CenterVertical }) +} + +function alignBottom() { + state.send('ALIGNED', { type: AlignType.Bottom }) +} + +function stretchVertically() { + state.send('STRETCHED', { type: StretchType.Vertical }) +} + +function distributeVertically() { + state.send('DISTRIBUTED', { type: DistributeType.Vertical }) +} + +function alignLeft() { + state.send('ALIGNED', { type: AlignType.Left }) +} + +function alignCenterHorizontal() { + state.send('ALIGNED', { type: AlignType.CenterHorizontal }) +} + +function alignRight() { + state.send('ALIGNED', { type: AlignType.Right }) +} + +function stretchHorizontally() { + state.send('STRETCHED', { type: StretchType.Horizontal }) +} + +function distributeHorizontally() { + state.send('DISTRIBUTED', { type: DistributeType.Horizontal }) +} export default function ContextMenu({ children, @@ -26,7 +88,8 @@ export default function ContextMenu({ const rContent = useRef(null) const hasGroupSelectd = selectedShapes.some((s) => s.type === ShapeType.Group) - const hasMultipleSelected = selectedShapes.length > 1 + const hasTwoOrMore = selectedShapes.length > 1 + const hasThreeOrMore = selectedShapes.length > 2 return ( <_ContextMenu.Root> @@ -58,7 +121,7 @@ export default function ContextMenu({ {hasGroupSelectd || - (hasMultipleSelected && ( + (hasTwoOrMore && ( <> {hasGroupSelectd && ( )} - {hasMultipleSelected && ( + {hasTwoOrMore && ( + {hasTwoOrMore && ( + + )}