Skip to content

Commit fd600a4

Browse files
authored
Merge pull request #836 from buildo/DS-350
Fix Columns layout to respect space between columns
2 parents 7615198 + b187b01 commit fd600a4

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

packages/bento-design-system/src/Layout/Column.css.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import { StyleRule, styleVariants } from "@vanilla-extract/css";
1+
import { StyleRule, createVar, style, styleVariants } from "@vanilla-extract/css";
22
import { bentoSprinkles } from "../internal/sprinkles.css";
33
import { Breakpoint, breakpoints } from "../util/breakpoints";
44

5+
export const columnsSpace = createVar("columns-space");
6+
7+
export const columns = style({
8+
marginLeft: `calc(${columnsSpace} * -1)`,
9+
rowGap: columnsSpace,
10+
});
11+
12+
export const columnContent = style({
13+
marginLeft: columnsSpace,
14+
height: "100%",
15+
});
16+
517
const styleForScale = (scale: number): StyleRule => ({
618
flex: `0 0 ${scale * 100}%`,
719
width: "100%",

packages/bento-design-system/src/Layout/Columns.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ import {
1010
CollapsibleAlignmentProps,
1111
responsiveCollapsibleAlignmentProps,
1212
} from "../util/collapsible";
13-
import { wideWidths, desktopWidths, tabletWidths, mobileWidths, fullWidth } from "./Column.css";
13+
import {
14+
wideWidths,
15+
desktopWidths,
16+
tabletWidths,
17+
mobileWidths,
18+
fullWidth,
19+
columnsSpace,
20+
columns,
21+
columnContent,
22+
} from "./Column.css";
23+
import { assignInlineVars } from "@vanilla-extract/dynamic";
1424

1525
type ColumnProps = {
1626
children: Children;
@@ -39,7 +49,7 @@ export function Column({ children, width, sticky }: ColumnProps) {
3949

4050
return (
4151
<Box className={className} {...stickyProps}>
42-
{children}
52+
<Box className={columnContent}>{children}</Box>
4353
</Box>
4454
);
4555
}
@@ -53,8 +63,9 @@ export function Columns({ space, children, align, alignY, collapseBelow, reverse
5363
return (
5464
<Box
5565
display="flex"
56-
gap={space}
5766
{...responsiveCollapsibleAlignmentProps({ align, alignY, collapseBelow, reverse })}
67+
style={assignInlineVars({ [columnsSpace]: `${space}px` })}
68+
className={columns}
5869
>
5970
{flattenChildren(children).map((child, index) => {
6071
if (isColumn(child)) {

packages/bento-design-system/stories/Layout/Columns.stories.tsx

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Card, Column, Columns, Display, Placeholder } from "..";
1+
import { Card, Column, Columns, Display, Placeholder, Stack } from "..";
22
import { alignArgType, alignYArgType, disableControlArgType, spaceArgType } from "../util";
33
import { Meta, StoryObj } from "@storybook/react";
44

@@ -51,7 +51,7 @@ export const ThreeColumn = {
5151
<Column width="1/5">
5252
<Placeholder height={200} label="1/5" />
5353
</Column>,
54-
<Column>
54+
<Column width="3/5">
5555
<Placeholder height={200} />
5656
</Column>,
5757
<Column width="1/5">
@@ -164,3 +164,40 @@ export const Sticky = {
164164
},
165165
parameters: { viewport: { defaultViewport: "mobile1" } },
166166
} satisfies Story;
167+
168+
export const MultipleRowsLayout = () => {
169+
return (
170+
<Stack space={16}>
171+
<Columns space={16}>
172+
<Column width="1/3">
173+
<Placeholder height={200} label="1/3" />
174+
</Column>
175+
<Column width="2/3">
176+
<Placeholder height={200} label="2/3" />
177+
</Column>
178+
</Columns>
179+
<Columns space={16}>
180+
<Column width="1/3">
181+
<Placeholder height={200} label="1/3" />
182+
</Column>
183+
<Column width="1/3">
184+
<Placeholder height={200} label="1/3" />
185+
</Column>
186+
</Columns>
187+
<Columns space={16}>
188+
<Column width="1/3">
189+
<Placeholder height={200} label="1/3" />
190+
</Column>
191+
<Placeholder height={200} label="auto" />
192+
</Columns>
193+
<Columns space={16}>
194+
<Column width="1/3">
195+
<Placeholder height={200} label="1/3" />
196+
</Column>
197+
<Column width="content">
198+
<Placeholder height={200} width={150} label="150px" />
199+
</Column>
200+
</Columns>
201+
</Stack>
202+
);
203+
};

0 commit comments

Comments
 (0)