Skip to content

Commit d3c2fff

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
improvement(ui): share canvas toolbar controls
1 parent ea31ca7 commit d3c2fff

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use client'
2+
3+
import { type ComponentProps, forwardRef } from 'react'
4+
import { Button, chipHoverSurfaceClass, cn } from '@sim/emcn'
5+
6+
type CanvasControlButtonProps = Omit<
7+
ComponentProps<typeof Button>,
8+
'variant' | 'size' | 'iconSize' | 'iconPadding' | 'className'
9+
> & { active?: boolean; 'aria-label': string }
10+
11+
/** Fixed-size action in the canvas navigation toolbar. */
12+
export const CanvasControlButton = forwardRef<HTMLButtonElement, CanvasControlButtonProps>(
13+
({ active = false, ...props }, ref) => (
14+
<Button
15+
{...props}
16+
ref={ref}
17+
variant={active ? 'active' : 'ghost'}
18+
className={cn('size-[28px] rounded-sm p-0', !active && chipHoverSurfaceClass)}
19+
/>
20+
)
21+
)
22+
23+
CanvasControlButton.displayName = 'CanvasControlButton'

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-controls/workflow-controls.tsx‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { useShallow } from 'zustand/react/shallow'
2525
import { useSession } from '@/lib/auth/auth-client'
2626
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
2727
import { createCommand } from '@/app/workspace/[workspaceId]/utils/commands-utils'
28+
import { CanvasControlButton } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-controls/canvas-control-button'
2829
import { useShowActionBar, useUpdateGeneralSetting } from '@/hooks/queries/general-settings'
2930
import { useCanvasViewport } from '@/hooks/use-canvas-viewport'
3031
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
@@ -109,17 +110,13 @@ export const WorkflowControls = memo(function WorkflowControls() {
109110
<PopoverTrigger asChild>
110111
<div className='flex cursor-pointer items-center gap-1'>
111112
<Tooltip.Trigger asChild>
112-
<Button
113-
aria-label={mode === 'hand' ? 'Mover' : 'Pointer'}
114-
className='size-[28px] rounded-sm p-0'
115-
variant='active'
116-
>
113+
<CanvasControlButton aria-label={mode === 'hand' ? 'Mover' : 'Pointer'} active>
117114
{mode === 'hand' ? (
118115
<Hand className='size-[14px]' />
119116
) : (
120117
<Cursor className='size-[14px]' />
121118
)}
122-
</Button>
119+
</CanvasControlButton>
123120
</Tooltip.Trigger>
124121
<Button
125122
aria-label='Change canvas mode'
@@ -160,15 +157,9 @@ export const WorkflowControls = memo(function WorkflowControls() {
160157

161158
<Tooltip.Root>
162159
<Tooltip.Trigger asChild>
163-
<Button
164-
aria-label='Undo'
165-
variant='ghost'
166-
className={cn('size-[28px] rounded-sm p-0', chipHoverSurfaceClass)}
167-
onClick={undo}
168-
disabled={!canUndo}
169-
>
160+
<CanvasControlButton aria-label='Undo' onClick={undo} disabled={!canUndo}>
170161
<Undo className='size-[14px]' />
171-
</Button>
162+
</CanvasControlButton>
172163
</Tooltip.Trigger>
173164
<Tooltip.Content side='top'>
174165
<Tooltip.Shortcut keys='⌘Z'>Undo</Tooltip.Shortcut>
@@ -177,15 +168,9 @@ export const WorkflowControls = memo(function WorkflowControls() {
177168

178169
<Tooltip.Root>
179170
<Tooltip.Trigger asChild>
180-
<Button
181-
aria-label='Redo'
182-
variant='ghost'
183-
className={cn('size-[28px] rounded-sm p-0', chipHoverSurfaceClass)}
184-
onClick={redo}
185-
disabled={!canRedo}
186-
>
171+
<CanvasControlButton aria-label='Redo' onClick={redo} disabled={!canRedo}>
187172
<Redo className='size-[14px]' />
188-
</Button>
173+
</CanvasControlButton>
189174
</Tooltip.Trigger>
190175
<Tooltip.Content side='top'>
191176
<Tooltip.Shortcut keys='⌘⇧Z'>Redo</Tooltip.Shortcut>
@@ -196,14 +181,9 @@ export const WorkflowControls = memo(function WorkflowControls() {
196181

197182
<Tooltip.Root>
198183
<Tooltip.Trigger asChild>
199-
<Button
200-
aria-label='Fit to View'
201-
variant='ghost'
202-
className={cn('size-[28px] rounded-sm p-0', chipHoverSurfaceClass)}
203-
onClick={handleFitToView}
204-
>
184+
<CanvasControlButton aria-label='Fit to View' onClick={handleFitToView}>
205185
<SelectAll className='size-[14px]' />
206-
</Button>
186+
</CanvasControlButton>
207187
</Tooltip.Trigger>
208188
<Tooltip.Content side='top'>
209189
<Tooltip.Shortcut keys='⌘⇧F'>Fit to View</Tooltip.Shortcut>

0 commit comments

Comments
 (0)