Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Columns layout to respect space between columns #836

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/bento-design-system/src/Layout/Column.css.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { StyleRule, styleVariants } from "@vanilla-extract/css";
import { StyleRule, createVar, style, styleVariants } from "@vanilla-extract/css";
import { bentoSprinkles } from "../internal/sprinkles.css";
import { Breakpoint, breakpoints } from "../util/breakpoints";

export const columnsSpace = createVar("columns-space");

export const columns = style({
marginLeft: `calc(${columnsSpace} * -1)`,
});

export const columnContent = style({
marginLeft: columnsSpace,
});

const styleForScale = (scale: number): StyleRule => ({
flex: `0 0 ${scale * 100}%`,
width: "100%",
Expand Down
17 changes: 14 additions & 3 deletions packages/bento-design-system/src/Layout/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ import {
CollapsibleAlignmentProps,
responsiveCollapsibleAlignmentProps,
} from "../util/collapsible";
import { wideWidths, desktopWidths, tabletWidths, mobileWidths, fullWidth } from "./Column.css";
import {
wideWidths,
desktopWidths,
tabletWidths,
mobileWidths,
fullWidth,
columnsSpace,
columns,
columnContent,
} from "./Column.css";
import { assignInlineVars } from "@vanilla-extract/dynamic";

type ColumnProps = {
children: Children;
Expand Down Expand Up @@ -39,7 +49,7 @@ export function Column({ children, width, sticky }: ColumnProps) {

return (
<Box className={className} {...stickyProps}>
{children}
<Box className={columnContent}>{children}</Box>
</Box>
);
}
Expand All @@ -53,8 +63,9 @@ export function Columns({ space, children, align, alignY, collapseBelow, reverse
return (
<Box
display="flex"
gap={space}
{...responsiveCollapsibleAlignmentProps({ align, alignY, collapseBelow, reverse })}
style={assignInlineVars({ [columnsSpace]: `${space}px` })}
className={columns}
>
{flattenChildren(children).map((child, index) => {
if (isColumn(child)) {
Expand Down
43 changes: 40 additions & 3 deletions packages/bento-design-system/stories/Layout/Columns.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, Column, Columns, Display, Placeholder } from "..";
import { Card, Column, Columns, Display, Placeholder, Stack } from "..";
import { alignArgType, alignYArgType, disableControlArgType, spaceArgType } from "../util";
import { Meta, StoryObj } from "@storybook/react";

Expand Down Expand Up @@ -37,7 +37,7 @@ export const TwoColumn1_3 = {
<Column width="1/3">
<Placeholder height={200} label="1/3" />
</Column>
<Column>
<Column width="1/3">
<Placeholder height={200} />
</Column>
</>
Expand All @@ -51,7 +51,7 @@ export const ThreeColumn = {
<Column width="1/5">
<Placeholder height={200} label="1/5" />
</Column>,
<Column>
<Column width="3/5">
<Placeholder height={200} />
</Column>,
<Column width="1/5">
Expand Down Expand Up @@ -164,3 +164,40 @@ export const Sticky = {
},
parameters: { viewport: { defaultViewport: "mobile1" } },
} satisfies Story;

export const MultipleRowsLayout = () => {
return (
<Stack space={16}>
<Columns space={16}>
<Column width="1/3">
<Placeholder height={200} label="1/3" />
</Column>
<Column width="2/3">
<Placeholder height={200} label="2/3" />
</Column>
</Columns>
<Columns space={16}>
<Column width="1/3">
<Placeholder height={200} label="1/3" />
</Column>
<Column width="1/3">
<Placeholder height={200} label="1/3" />
</Column>
</Columns>
<Columns space={16}>
<Column width="1/3">
<Placeholder height={200} label="1/3" />
</Column>
<Placeholder height={200} label="auto" />
</Columns>
<Columns space={16}>
<Column width="1/3">
<Placeholder height={200} label="1/3" />
</Column>
<Column width="content">
<Placeholder height={200} width={150} label="150px" />
</Column>
</Columns>
</Stack>
);
};
Loading