From 45b0ff0f1d4a00e300f8fdef99cbd65bc955c246 Mon Sep 17 00:00:00 2001 From: Vincenzo Guerrisi Date: Fri, 15 Mar 2024 11:24:13 +0100 Subject: [PATCH] Fix Columns layout to respect space between columns --- .../src/Layout/Column.css.ts | 12 +++++- .../src/Layout/Columns.tsx | 17 ++++++-- .../stories/Layout/Columns.stories.tsx | 43 +++++++++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/packages/bento-design-system/src/Layout/Column.css.ts b/packages/bento-design-system/src/Layout/Column.css.ts index 265cc7026..27a54f93d 100644 --- a/packages/bento-design-system/src/Layout/Column.css.ts +++ b/packages/bento-design-system/src/Layout/Column.css.ts @@ -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%", diff --git a/packages/bento-design-system/src/Layout/Columns.tsx b/packages/bento-design-system/src/Layout/Columns.tsx index 525034ac5..d58bdf929 100644 --- a/packages/bento-design-system/src/Layout/Columns.tsx +++ b/packages/bento-design-system/src/Layout/Columns.tsx @@ -9,7 +9,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; @@ -38,7 +48,7 @@ export function Column({ children, width, sticky }: ColumnProps) { return ( - {children} + {children} ); } @@ -52,8 +62,9 @@ export function Columns({ space, children, align, alignY, collapseBelow, reverse return ( {flattenChildren(children).map((child, index) => { if (isColumn(child)) { diff --git a/packages/bento-design-system/stories/Layout/Columns.stories.tsx b/packages/bento-design-system/stories/Layout/Columns.stories.tsx index 9b1890dad..0d825c3d5 100644 --- a/packages/bento-design-system/stories/Layout/Columns.stories.tsx +++ b/packages/bento-design-system/stories/Layout/Columns.stories.tsx @@ -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"; @@ -37,7 +37,7 @@ export const TwoColumn1_3 = { - + @@ -51,7 +51,7 @@ export const ThreeColumn = { , - + , @@ -164,3 +164,40 @@ export const Sticky = { }, parameters: { viewport: { defaultViewport: "mobile1" } }, } satisfies Story; + +export const MultipleRowsLayout = () => { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +};