Skip to content

Commit

Permalink
factor out style
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggi committed Oct 10, 2024
1 parent c25c954 commit 8279ecf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
13 changes: 2 additions & 11 deletions editor/src/components/editor/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
simpleAttribute,
} from '../../core/shared/element-template'
import type { NormalisedFrame } from 'utopia-api/core'
import { defaultImageAttributes } from '../shared/project-components'
import { defaultImageAttributes, insertableGridStyle } from '../shared/project-components'

export function defaultSceneElement(
uid: string,
Expand Down Expand Up @@ -177,16 +177,7 @@ export function defaultGridElement(uid: string): JSXElement {
uid,
jsxAttributesFromMap({
'data-uid': jsExpressionValue(uid, emptyComments),
style: jsExpressionValue(
{
position: 'absolute',
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
gridTemplateRows: '1fr 1fr 1fr',
gap: 10,
},
emptyComments,
),
style: jsExpressionValue(insertableGridStyle(), emptyComments),
}),
[],
)
Expand Down
21 changes: 14 additions & 7 deletions editor/src/components/shared/project-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { intrinsicHTMLElementNamesThatSupportChildren } from '../../core/shared/
import { getTopLevelElementByExportsDetail } from '../../core/model/project-file-utils'
import { type Icon } from 'utopia-api'
import type { FileRootPath } from '../canvas/ui-jsx-canvas'
import type { CSSProperties } from 'react'

export type StylePropOption = 'do-not-add' | 'add-size'

Expand Down Expand Up @@ -474,6 +475,16 @@ const divComponentGroup = {
),
}

export function insertableGridStyle(): CSSProperties {
return {
position: 'absolute',
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
gridTemplateRows: '1fr 1fr 1fr',
gap: 10,
}
}

const gridComponentGroup: ComponentDescriptorsForFile = {
grid: {
properties: {},
Expand All @@ -489,13 +500,9 @@ const gridComponentGroup: ComponentDescriptorsForFile = {
jsxAttributesFromMap({
style: jsExpressionValue(
{
display: 'grid',
gridTemplateRows: '1fr 1fr 1fr',
gridTemplateColumns: '1fr 1fr 1fr',
gap: 10,
position: 'absolute',
width: 200,
height: 200,
...insertableGridStyle(),
width: 150,
height: 150,
},
emptyComments,
),
Expand Down

0 comments on commit 8279ecf

Please sign in to comment.