Skip to content

Commit 3809637

Browse files
authored
Add gap param to st.columns (#4887)
* Add gap param to st.columns * Modify gap spacing/default and add BE tests * Fix Block test prop for new pattern * Fix FE test snapshots & add e2e tests
1 parent 81db95c commit 3809637

File tree

16 files changed

+158
-18
lines changed

16 files changed

+158
-18
lines changed

e2e/scripts/st_columns.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@
2929
# Variable-width columns
3030
for c in st.columns((1, 2, 3, 4)):
3131
c.image(CAT_IMAGE)
32+
33+
# Various column gaps
34+
c4, c5, c6 = st.columns(3, gap="small")
35+
c4.image(CAT_IMAGE)
36+
c5.image(CAT_IMAGE)
37+
c6.image(CAT_IMAGE)
38+
39+
c7, c8, c9 = st.columns(3, gap="medium")
40+
c7.image(CAT_IMAGE)
41+
c8.image(CAT_IMAGE)
42+
c9.image(CAT_IMAGE)
43+
44+
c10, c11, c12 = st.columns(3, gap="large")
45+
c10.image(CAT_IMAGE)
46+
c11.image(CAT_IMAGE)
47+
c12.image(CAT_IMAGE)

e2e/specs/st_columns.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("st.column", () => {
6161
// This assertion ensures that the report rerun completes first
6262
cy.get("[data-testid='stHorizontalBlock'] [data-testid='column']").should(
6363
"have.length",
64-
7
64+
16
6565
);
6666

6767
// When layout was shifting, there was an old "flex: 8" block here.
@@ -70,4 +70,20 @@ describe("st.column", () => {
7070
3
7171
).should("have.css", "flex", "1 1 calc(10% - 16px)");
7272
});
73+
74+
it("creates small gap between columns", () => {
75+
cy.getIndexed("[data-testid='stHorizontalBlock']",
76+
2).matchThemedSnapshots("columns-small-gap");
77+
});
78+
79+
it("creates medium gap between columns", () => {
80+
cy.getIndexed("[data-testid='stHorizontalBlock']",
81+
3).matchThemedSnapshots("columns-medium-gap");
82+
});
83+
84+
it("creates large gap between columns", () => {
85+
cy.getIndexed("[data-testid='stHorizontalBlock']",
86+
4).matchThemedSnapshots("columns-large-gap");
87+
});
88+
7389
});
92.8 KB
Loading
92.7 KB
Loading
110 KB
Loading
110 KB
Loading
119 KB
Loading
118 KB
Loading

frontend/src/components/core/Block/Block.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function makeHorizontalBlock(numColumns: number): BlockNode {
3535

3636
return new BlockNode(
3737
Array.from({ length: numColumns }, () => makeColumn(weight)),
38-
new BlockProto({ allowEmpty: true, horizontal: true })
38+
new BlockProto({ allowEmpty: true, horizontal: { gap: "small" } })
3939
)
4040
}
4141

frontend/src/components/core/Block/Block.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const BlockNodeRenderer = (props: BlockPropsWithWidth): ReactElement => {
106106
return (
107107
<StyledColumn
108108
weight={node.deltaBlock.column.weight ?? 0}
109+
gap={node.deltaBlock.column.gap ?? ""}
109110
data-testid="column"
110111
>
111112
{child}
@@ -179,8 +180,10 @@ const HorizontalBlock = (props: BlockPropsWithWidth): ReactElement => {
179180
// Create a horizontal block as the parent for columns.
180181
// The children are always columns, but this is not checked. We just trust the Python side to
181182
// do the right thing, then we ask ChildRenderer to handle it.
183+
const gap = props.node.deltaBlock.horizontal?.gap ?? ""
184+
182185
return (
183-
<StyledHorizontalBlock data-testid="stHorizontalBlock">
186+
<StyledHorizontalBlock gap={gap} data-testid="stHorizontalBlock">
184187
<ChildRenderer {...props} />
185188
</StyledHorizontalBlock>
186189
)

0 commit comments

Comments
 (0)