Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show grid lines when selecting grid or during child interaction #6647

Merged
merged 11 commits into from
Nov 18, 2024
44 changes: 39 additions & 5 deletions editor/src/components/canvas/controls/grid-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,26 @@ export const GridControlsComponent = ({ targets }: GridControlsProps) => {
}),
)

const isItemInteractionActive = useEditorState(
Substores.canvas,
(store) => {
if (store.editor.canvas.interactionSession == null) {
return false
}
return (
// movement
store.editor.canvas.interactionSession.activeControl.type === 'GRID_CELL_HANDLE' ||
// resize (cell)
store.editor.canvas.interactionSession.activeControl.type === 'GRID_RESIZE_HANDLE' ||
// resize (abs)
store.editor.canvas.interactionSession.activeControl.type === 'RESIZE_HANDLE'
)
},
'GridControlsComponent isItemInteractionActive',
)

const selectedViewsRef = useRefEditorState((store) => store.editor.selectedViews)

if (grids.length === 0) {
return null
}
Expand All @@ -1144,20 +1164,34 @@ export const GridControlsComponent = ({ targets }: GridControlsProps) => {
<div id={'grid-controls'}>
<CanvasOffsetWrapper>
{grids.map((grid) => {
const gridItemSelected = selectedViewsRef.current.some((path) =>
EP.isDescendantOf(path, grid.identifier.path),
)

const gridPath =
grid.identifier.type === 'GRID_CONTAINER'
? grid.identifier.path
: EP.parentPath(grid.identifier.path)
const shouldHaveVisibleControls = gridsWithVisibleControls.some((g) => {
const visibleControlPath = g.type === 'GRID_CONTAINER' ? g.path : EP.parentPath(g.path)
return EP.pathsEqual(gridPath, visibleControlPath)
})

function shouldHaveVisibleControls(): boolean {
const isGridChildSelectedWihtoutInteraction =
gridItemSelected && !isItemInteractionActive
if (isGridChildSelectedWihtoutInteraction) {
ruggi marked this conversation as resolved.
Show resolved Hide resolved
return false
}

return gridsWithVisibleControls.some((g) => {
const visibleControlPath =
g.type === 'GRID_CONTAINER' ? g.path : EP.parentPath(g.path)
return EP.pathsEqual(gridPath, visibleControlPath)
})
}

return (
<GridControl
key={GridControlKey(grid.identifier.path)}
grid={grid}
controlsVisible={shouldHaveVisibleControls ? 'visible' : 'not-visible'}
controlsVisible={shouldHaveVisibleControls() ? 'visible' : 'not-visible'}
/>
)
})}
Expand Down
Loading