-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
248 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from "react"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { Grid } from "./Grid"; | ||
|
||
const meta: Meta<typeof Grid> = { | ||
title: "Components/Grid", | ||
component: Grid, | ||
tags: ["autodocs"] | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Grid>; | ||
|
||
const StyledColumn = ({ ...props }) => ( | ||
<Grid.Column className="bg-primary text-neutral-light p-2 text-md rounded-sm" {...props} /> | ||
); | ||
|
||
export const Default: Story = { | ||
args: { | ||
className: "bg-neutral-light p-4", | ||
children: ( | ||
<> | ||
<StyledColumn>Col 1</StyledColumn> | ||
<StyledColumn span={3}> | ||
Col 2 (<code>span: 3</code>) | ||
</StyledColumn> | ||
<StyledColumn>Col 3</StyledColumn> | ||
<StyledColumn>Col 4</StyledColumn> | ||
<StyledColumn>Col 5</StyledColumn> | ||
<StyledColumn>Col 6</StyledColumn> | ||
<StyledColumn span={2}> | ||
Col 7 (<code>span: 2</code>) | ||
</StyledColumn> | ||
<StyledColumn>Col 8</StyledColumn> | ||
<StyledColumn>Col 9</StyledColumn> | ||
</> | ||
) | ||
} | ||
}; | ||
|
||
export const SpaciousGap: Story = { | ||
args: { | ||
...Default.args, | ||
gap: "spacious" | ||
} | ||
}; | ||
|
||
export const WithOffset: Story = { | ||
parameters: { | ||
layout: "padded" | ||
}, | ||
decorators: [ | ||
Story => ( | ||
<div className="w-full"> | ||
<Story /> | ||
</div> | ||
) | ||
], | ||
args: { | ||
...Default.args, | ||
children: ( | ||
<> | ||
{/* Row 1 */} | ||
<StyledColumn span={8} offset={2}> | ||
Col (<code>span: 8</code>, <code>offset: 2</code>) | ||
</StyledColumn> | ||
<Grid.Column span={2} /> | ||
|
||
{/* Row 2 */} | ||
<StyledColumn span={8} offset={4}> | ||
Col (<code>span: 8</code>, <code>offset: 4</code>) | ||
</StyledColumn> | ||
|
||
{/* Row 3 */} | ||
<StyledColumn span={10} offset={1}> | ||
Col (<code>span: 10</code>, <code>offset: 1</code>) | ||
</StyledColumn> | ||
<Grid.Column span={1} /> | ||
|
||
{/* Row 4 */} | ||
<StyledColumn span={12}> | ||
Col (<code>span: 12</code>) | ||
</StyledColumn> | ||
</> | ||
) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from "react"; | ||
import { makeDecoratable } from "@webiny/react-composition"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import { cn, withStaticProps } from "~/utils"; | ||
|
||
const columnVariants = cva("", { | ||
variants: { | ||
span: { | ||
auto: "col-auto", | ||
1: "col-span-1", | ||
2: "col-span-2", | ||
3: "col-span-3", | ||
4: "col-span-4", | ||
5: "col-span-5", | ||
6: "col-span-6", | ||
7: "col-span-7", | ||
8: "col-span-8", | ||
9: "col-span-9", | ||
10: "col-span-10", | ||
11: "col-span-11", | ||
12: "col-span-12" | ||
}, | ||
offset: { | ||
1: "col-start-2", | ||
2: "col-start-3", | ||
3: "col-start-4", | ||
4: "col-start-5", | ||
5: "col-start-6", | ||
6: "col-start-7", | ||
7: "col-start-8", | ||
8: "col-start-9", | ||
9: "col-start-10", | ||
10: "col-start-11", | ||
11: "col-start-12" | ||
}, | ||
align: { | ||
top: "self-start", | ||
middle: "self-center", | ||
bottom: "self-end" | ||
} | ||
}, | ||
defaultVariants: { | ||
span: "auto" | ||
} | ||
}); | ||
|
||
interface ColumnProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof columnVariants> { | ||
children?: React.ReactNode; | ||
} | ||
|
||
const ColumnBase = React.forwardRef<HTMLDivElement, ColumnProps>( | ||
({ span, align, children, className, offset, ...props }, ref) => { | ||
return ( | ||
<div | ||
{...props} | ||
className={cn(columnVariants({ span, offset, align, className }))} | ||
ref={ref} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
ColumnBase.displayName = "Column"; | ||
|
||
const Column = makeDecoratable("Column", ColumnBase); | ||
|
||
const gridVariants = cva("grid", { | ||
variants: { | ||
gap: { | ||
comfortable: "gap-lg", | ||
spacious: "gap-xl" | ||
} | ||
}, | ||
defaultVariants: { | ||
gap: "comfortable" | ||
} | ||
}); | ||
|
||
interface GridProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof gridVariants> { | ||
children: | ||
| React.ReactElement<ColumnProps, typeof Column> | ||
| Array<React.ReactElement<ColumnProps, typeof Column>>; | ||
} | ||
|
||
const GridBase = React.forwardRef<HTMLDivElement, GridProps>( | ||
({ gap, children, className, ...props }, ref) => { | ||
return ( | ||
<div | ||
{...props} | ||
className={cn("grid-cols-12", gridVariants({ gap }), className)} | ||
ref={ref} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
GridBase.displayName = "Grid"; | ||
|
||
const DecoratableGrid = makeDecoratable("Grid", GridBase); | ||
|
||
const Grid = withStaticProps(DecoratableGrid, { Column }); | ||
|
||
export { Grid, type GridProps, type ColumnProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./Grid"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters