Skip to content

Commit

Permalink
fix(grids) Scale Placeholder Borders (#6444)
Browse files Browse the repository at this point in the history
- Change `gridPlaceholderBorder` to take a value for scale.
- Change `scaleRef` to be a regular `scale` value in `GridControls` as
it needs to be passed to `gridPlaceholderBorder` all the time.
  • Loading branch information
seanparsons authored Oct 2, 2024
1 parent b8c8dcb commit df09eca
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions editor/src/components/canvas/controls/grid-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,11 @@ export const GridControls = controlForStrategyMemoized<GridControlsProps>(({ tar
const features = useRollYourOwnFeatures()

const canvasOffsetRef = useRefEditorState((store) => store.editor.canvas.roundedCanvasOffset)
const scaleRef = useRefEditorState((store) => store.editor.canvas.scale)
const scale = useEditorState(
Substores.canvas,
(store) => store.editor.canvas.scale,
'GridControls scale',
)
const metadataRef = useRefEditorState((store) => store.editor.jsxMetadata)

const activelyDraggingOrResizingCell = useEditorState(
Expand Down Expand Up @@ -811,7 +815,7 @@ export const GridControls = controlForStrategyMemoized<GridControlsProps>(({ tar
setInitialShadowFrame(params.frame)

const start = windowToCanvasCoordinates(
scaleRef.current,
scale,
canvasOffsetRef.current,
windowPoint({ x: event.nativeEvent.x, y: event.nativeEvent.y }),
)
Expand All @@ -827,7 +831,7 @@ export const GridControls = controlForStrategyMemoized<GridControlsProps>(({ tar
),
])
},
[canvasOffsetRef, dispatch, scaleRef],
[canvasOffsetRef, dispatch, scale],
)

// NOTE: this stuff is meant to be temporary, until we settle on the set of interaction pieces we like.
Expand Down Expand Up @@ -976,19 +980,19 @@ export const GridControls = controlForStrategyMemoized<GridControlsProps>(({ tar
id={id}
data-testid={id}
style={{
borderTop: gridPlaceholderBorder(borderColor),
borderLeft: gridPlaceholderBorder(borderColor),
borderTop: gridPlaceholderBorder(borderColor, scale),
borderLeft: gridPlaceholderBorder(borderColor, scale),
borderBottom:
isActiveCell ||
countedRow >= grid.rows ||
(grid.rowGap != null && grid.rowGap > 0)
? gridPlaceholderBorder(borderColor)
? gridPlaceholderBorder(borderColor, scale)
: undefined,
borderRight:
isActiveCell ||
countedColumn >= grid.columns ||
(grid.columnGap != null && grid.columnGap > 0)
? gridPlaceholderBorder(borderColor)
? gridPlaceholderBorder(borderColor, scale)
: undefined,
position: 'relative',
pointerEvents: 'initial',
Expand Down Expand Up @@ -1797,7 +1801,7 @@ function gridKeyFromPath(path: ElementPath): string {
return `grid-${EP.toString(path)}`
}

const gridPlaceholderBorder = (color: string) => `2px solid ${color}`
const gridPlaceholderBorder = (color: string, scale: number) => `${2 / scale}px solid ${color}`

export function controlsForGridPlaceholders(gridPath: ElementPath): ControlWithProps<any> {
return {
Expand Down

0 comments on commit df09eca

Please sign in to comment.