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

Fix misaligned gap controls when justifyContent or alignContent is set #6565

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from './grid-controls'
import { isEdgePositionOnSide } from '../canvas-utils'
import { findOriginalGrid } from '../canvas-strategies/strategies/grid-helpers'
import type { AlignContent, FlexJustifyContent } from '../../inspector/inspector-common'

export const GridCellTestId = (elementPath: ElementPath) => `grid-cell-${EP.toString(elementPath)}`

Expand Down Expand Up @@ -70,8 +71,8 @@ export type GridMeasurementHelperData = {
gap: number | null
rowGap: number | null
columnGap: number | null
justifyContent: string | null
alignContent: string | null
justifyContent: FlexJustifyContent | null
alignContent: AlignContent | null
padding: Sides
columns: number
cells: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@ import type { CSSProperties } from 'react'
import React from 'react'
import { createArrayWithLength, interleaveArray } from '../../../../core/shared/array-utils'
import type { GridAutoOrTemplateBase } from '../../../../core/shared/element-template'
import type { CanvasVector, Size } from '../../../../core/shared/math-utils'
import { size, windowPoint } from '../../../../core/shared/math-utils'
import type { Size } from '../../../../core/shared/math-utils'
import { size } from '../../../../core/shared/math-utils'
import type { ElementPath } from '../../../../core/shared/project-file-types'
import { assertNever } from '../../../../core/shared/utils'
import { Modifier } from '../../../../utils/modifiers'
import { when } from '../../../../utils/react-conditionals'
import { useColorTheme, UtopiaStyles } from '../../../../uuiui'
import { CSSCursor } from '../../../../uuiui-deps'
import type { EditorDispatch } from '../../../editor/action-types'
import { useDispatch } from '../../../editor/store/dispatch-context'
import { Substores, useEditorState, useRefEditorState } from '../../../editor/store/store-hook'
import {
cssNumber,
printCSSNumber,
stringifyGridDimension,
} from '../../../inspector/common/css-utils'
import CanvasActions from '../../canvas-actions'
import { createInteractionViaMouse, gridGapHandle } from '../../canvas-strategies/interaction-state'
import { windowToCanvasCoordinates } from '../../dom-lookup'
import type { Axis } from '../../gap-utils'
import { maybeGridGapData } from '../../gap-utils'
import { CanvasOffsetWrapper } from '../canvas-offset-wrapper'
Expand All @@ -30,6 +25,7 @@ import { getGridHelperStyleMatchingTargetGrid } from '../grid-controls-helpers'
import type { CSSNumberWithRenderedValue } from './controls-common'
import { CanvasLabel, PillHandle, useHoverWithDelay } from './controls-common'
import { startGapControlInteraction } from './grid-gap-control-helpers'
import type { AlignContent, FlexJustifyContent } from '../../../inspector/inspector-common'

export interface GridGapControlProps {
selectedElement: ElementPath
Expand Down Expand Up @@ -184,7 +180,7 @@ const GridPaddingOutlineForDimension = (props: {
{createArrayWithLength(length, (index) => {
const hide = index === 0 || index === length - 1 || index % 2 === 0
return (
<GridRowHighlight
<GridRowOrColumnHighlight
key={index}
hide={hide} // we only want to show the divs that fall in where the gaps are in the original grid
gapId={`${dimension}-${index}`}
Expand All @@ -199,14 +195,16 @@ const GridPaddingOutlineForDimension = (props: {
beingDragged={beingDragged}
onMouseOver={onMouseOver}
elementHovered={elementHovered}
gridJustifyContent={grid.justifyContent}
gridAlignContent={grid.alignContent}
/>
)
})}
</div>
)
}

const GridRowHighlight = (props: {
const GridRowOrColumnHighlight = (props: {
gapId: string
onMouseDown: React.MouseEventHandler
hide: boolean
Expand All @@ -218,6 +216,8 @@ const GridRowHighlight = (props: {
beingDragged: boolean
onMouseOver: () => void
elementHovered: boolean
gridJustifyContent: FlexJustifyContent | null
gridAlignContent: AlignContent | null
}) => {
const {
gapId,
Expand All @@ -231,6 +231,8 @@ const GridRowHighlight = (props: {
beingDragged,
onMouseOver,
elementHovered,
gridJustifyContent,
gridAlignContent,
} = props

const colorTheme = useColorTheme()
Expand Down Expand Up @@ -294,8 +296,8 @@ const GridRowHighlight = (props: {
boxShadow: `inset 0 0 0 ${lineWidth}px ${outlineColor}`,
opacity: hide ? 0 : 1,

alignItems: 'center',
justifyContent: 'center',
alignContent: axis === 'row' ? undefined : gridAlignContent ?? undefined,
justifyContent: axis === 'row' ? gridJustifyContent ?? undefined : undefined,
placeItems: 'center',

gap: gap ?? 0,
Expand Down
Loading