-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Problem The basic hug contents strategy doesn't really make sense for grids. ## Fix Create a hug contents strategy tailored to grids. When setting a grid to hug along an axis, if the grid doesn't use any `fr` units in `gridTemplate{Row | Column}` along that axis, the width/height prop is removed from that axis, so the grid is sized by its template rows or columns. If there's an `fr` unit in`gridTemplate{Row | Column}`, the strategy is not applicable because the `fr` only works if the grid is sized
- Loading branch information
Showing
5 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3124,6 +3124,96 @@ describe('Double click on resize edge', () => { | |
expect(div.style.width).toEqual(MaxContent) | ||
expect(div.style.height).toEqual('445px') | ||
}) | ||
|
||
describe('grids', () => { | ||
const project = ({ | ||
rows: rows, | ||
columns: columns, | ||
}: { | ||
rows: string | ||
columns: string | ||
}) => `import * as React from 'react' | ||
import { Scene, Storyboard } from 'utopia-api' | ||
export var storyboard = ( | ||
<Storyboard data-uid='sb'> | ||
<Scene | ||
id='playground-scene' | ||
commentId='playground-scene' | ||
style={{ | ||
width: 700, | ||
height: 759, | ||
position: 'absolute', | ||
left: 212, | ||
top: 128, | ||
}} | ||
data-label='Playground' | ||
data-uid='sc' | ||
> | ||
<div | ||
style={{ | ||
display: 'grid', | ||
gridTemplateRows: '${rows}', | ||
gridTemplateColumns: '${columns}', | ||
backgroundColor: '#0074ff', | ||
position: 'absolute', | ||
left: 135, | ||
top: 55, | ||
width: 400, | ||
height: 400, | ||
opacity: '30%', | ||
}} | ||
data-uid='grid' | ||
data-testid='mydiv' | ||
> | ||
<img | ||
src='https://github.com/concrete-utopia/utopia/blob/master/editor/resources/editor/[email protected]?raw=true' | ||
alt='Utopia logo' | ||
style={{ | ||
objectFit: 'contain', | ||
display: 'inline-block', | ||
width: 100, | ||
height: 100, | ||
gridColumnStart: 2, | ||
gridColumnEnd: 2, | ||
gridRowStart: 2, | ||
gridRowEnd: 2, | ||
}} | ||
data-uid='smyramid' | ||
/> | ||
</div> | ||
</Scene> | ||
</Storyboard> | ||
) | ||
` | ||
it('removes width when right edge is clicked', async () => { | ||
const editor = await renderTestEditorWithCode( | ||
project({ rows: '66px 66px 66px 66px', columns: '50px 81px 96px 85px' }), | ||
'await-first-dom-report', | ||
) | ||
const div = await doDblClickTest(editor, edgeResizeControlTestId(EdgePositionRight)) | ||
expect(div.style.width).toEqual('') // width is removed | ||
expect(div.style.height).toEqual('400px') | ||
}) | ||
it('removes height when bottom edge is clicked', async () => { | ||
const editor = await renderTestEditorWithCode( | ||
project({ rows: '66px 66px 66px 66px', columns: '50px 81px 96px 85px' }), | ||
'await-first-dom-report', | ||
) | ||
const div = await doDblClickTest(editor, edgeResizeControlTestId(EdgePositionBottom)) | ||
expect(div.style.width).toEqual('400px') | ||
expect(div.style.height).toEqual('') // height is removed | ||
}) | ||
it("isn't applicable when the selected grid uses fr along the affected axis", async () => { | ||
const editor = await renderTestEditorWithCode( | ||
project({ rows: '66px 1fr 66px 66px', columns: '50px 81px 96px 85px' }), | ||
'await-first-dom-report', | ||
) | ||
const div = await doDblClickTest(editor, edgeResizeControlTestId(EdgePositionBottom)) | ||
expect(div.style.width).toEqual('400px') | ||
expect(div.style.height).toEqual('400px') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('double click on resize corner', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters