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 #6646

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
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