Skip to content

Commit 9b9b8f0

Browse files
committed
Fix Columns layout to respect space between columns
1 parent ba85e0b commit 9b9b8f0

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
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 column = style({});
8+
9+
export const columnContent = style({
10+
marginLeft: columnsSpace,
11+
selectors: {
12+
[`${column}:first-child &`]: {
13+
marginLeft: 0,
14+
},
15+
},
16+
});
17+
518
const styleForScale = (scale: number): StyleRule => ({
619
flex: `0 0 ${scale * 100}%`,
720
width: "100%",

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ import {
99
CollapsibleAlignmentProps,
1010
responsiveCollapsibleAlignmentProps,
1111
} from "../util/collapsible";
12-
import { wideWidths, desktopWidths, tabletWidths, mobileWidths, fullWidth } from "./Column.css";
12+
import {
13+
wideWidths,
14+
desktopWidths,
15+
tabletWidths,
16+
mobileWidths,
17+
fullWidth,
18+
columnsSpace,
19+
column,
20+
columnContent,
21+
} from "./Column.css";
22+
import { assignInlineVars } from "@vanilla-extract/dynamic";
1323

1424
type ColumnProps = {
1525
children: Children;
@@ -26,8 +36,9 @@ export function Column({ children, width, sticky }: ColumnProps) {
2636

2737
const className =
2838
width == null
29-
? fullWidth
39+
? [column, fullWidth]
3040
: [
41+
column,
3142
wide && wideWidths[wide],
3243
desktop && desktopWidths[desktop],
3344
tablet && tabletWidths[tablet],
@@ -38,7 +49,7 @@ export function Column({ children, width, sticky }: ColumnProps) {
3849

3950
return (
4051
<Box className={className} {...stickyProps}>
41-
{children}
52+
<Box className={columnContent}>{children}</Box>
4253
</Box>
4354
);
4455
}
@@ -52,8 +63,8 @@ export function Columns({ space, children, align, alignY, collapseBelow, reverse
5263
return (
5364
<Box
5465
display="flex"
55-
gap={space}
5666
{...responsiveCollapsibleAlignmentProps({ align, alignY, collapseBelow, reverse })}
67+
style={assignInlineVars({ [columnsSpace]: `${space}px` })}
5768
>
5869
{flattenChildren(children).map((child, index) => {
5970
if (isColumn(child)) {

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

+40-3
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

@@ -37,7 +37,7 @@ export const TwoColumn1_3 = {
3737
<Column width="1/3">
3838
<Placeholder height={200} label="1/3" />
3939
</Column>
40-
<Column>
40+
<Column width="1/3">
4141
<Placeholder height={200} />
4242
</Column>
4343
</>
@@ -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)