From c1e053fb1188e89be4fd706bb887566b75041c29 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Tue, 16 Nov 2021 21:21:02 +0000 Subject: [PATCH] Fix toggle prop --- .../src/components/ToolButton/ToolButton.tsx | 5 ++++ .../components/ToolsPanel/ActionButton.tsx | 23 ++++++++++--------- .../toggleShapesProp/toggleShapesProp.ts | 20 ++++++++-------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/tldraw/src/components/ToolButton/ToolButton.tsx b/packages/tldraw/src/components/ToolButton/ToolButton.tsx index ae4d2ca24..7a9baa91f 100644 --- a/packages/tldraw/src/components/ToolButton/ToolButton.tsx +++ b/packages/tldraw/src/components/ToolButton/ToolButton.tsx @@ -117,6 +117,11 @@ export const StyledToolButton = styled('button', { border: 'none', height: '40px', width: '40px', + + [`&:disabled ${StyledToolButtonInner}`]: { + opacity: 0.618, + }, + variants: { variant: { primary: { diff --git a/packages/tldraw/src/components/ToolsPanel/ActionButton.tsx b/packages/tldraw/src/components/ToolsPanel/ActionButton.tsx index 81933c59b..b7746bd8a 100644 --- a/packages/tldraw/src/components/ToolsPanel/ActionButton.tsx +++ b/packages/tldraw/src/components/ToolsPanel/ActionButton.tsx @@ -26,12 +26,12 @@ import { SpaceEvenlyVerticallyIcon, StretchHorizontallyIcon, StretchVerticallyIcon, + BoxIcon, } from '@radix-ui/react-icons' import { DMContent } from '~components/DropdownMenu' import { Divider } from '~components/Divider' import { TrashIcon } from '~components/icons' import { ToolButton } from '~components/ToolButton' -import { GHOSTED_OPACITY } from '~constants' const selectedShapesCountSelector = (s: TDSnapshot) => s.document.pageStates[s.appState.currentPageId].selectedIds.length @@ -85,6 +85,12 @@ export function ActionButton(): JSX.Element { const hasMultipleSelection = app.useStore(hasMultipleSelectionClickor) + const selectedShapesCount = app.useStore(selectedShapesCountSelector) + + const hasTwoOrMore = selectedShapesCount > 1 + + const hasThreeOrMore = selectedShapesCount > 2 + const handleRotate = React.useCallback(() => { app.rotate() }, [app]) @@ -165,16 +171,11 @@ export function ActionButton(): JSX.Element { app.distribute(DistributeType.Horizontal) }, [app]) - const selectedShapesCount = app.useStore(selectedShapesCountSelector) - - const hasTwoOrMore = selectedShapesCount > 1 - const hasThreeOrMore = selectedShapesCount > 2 - return ( - + - + @@ -192,12 +193,12 @@ export function ActionButton(): JSX.Element { - {isAllLocked ? : } + {isAllLocked ? : } - + {isAllAspectLocked ? : } - + diff --git a/packages/tldraw/src/state/commands/toggleShapesProp/toggleShapesProp.ts b/packages/tldraw/src/state/commands/toggleShapesProp/toggleShapesProp.ts index 7f12288dd..fc440cf2e 100644 --- a/packages/tldraw/src/state/commands/toggleShapesProp/toggleShapesProp.ts +++ b/packages/tldraw/src/state/commands/toggleShapesProp/toggleShapesProp.ts @@ -1,22 +1,22 @@ import type { TDShape, TldrawCommand } from '~types' -import { TLDR } from '~state/TLDR' import type { TldrawApp } from '~state' export function toggleShapeProp(app: TldrawApp, ids: string[], prop: keyof TDShape): TldrawCommand { const { currentPageId } = app - const initialShapes = ids.map((id) => app.getShape(id)) + const initialShapes = ids + .map((id) => app.getShape(id)) + .filter((shape) => (prop === 'isLocked' ? true : !shape.isLocked)) const isAllToggled = initialShapes.every((shape) => shape[prop]) - const { before, after } = TLDR.mutateShapes( - app.state, - ids.filter((id) => (prop === 'isLocked' ? true : !app.getShape(id).isLocked)), - () => ({ - [prop]: !isAllToggled, - }), - currentPageId - ) + const before: Record> = {} + const after: Record> = {} + + initialShapes.forEach((shape) => { + before[shape.id] = { [prop]: shape[prop] } + after[shape.id] = { [prop]: !isAllToggled } + }) return { id: 'toggle',