@purpurds/grid 4.6.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/grid.cjs.js +2 -2
- package/dist/grid.cjs.js.map +1 -1
- package/dist/grid.d.ts +14 -8
- package/dist/grid.d.ts.map +1 -1
- package/dist/grid.es.js +94 -94
- package/dist/grid.es.js.map +1 -1
- package/dist/grid.item.d.ts +16 -0
- package/dist/grid.item.d.ts.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +3 -2
- package/readme.mdx +67 -19
- package/src/grid.item.module.scss +43 -0
- package/src/grid.item.stories.tsx +47 -0
- package/src/grid.item.tsx +68 -0
- package/src/grid.module.scss +68 -8
- package/src/grid.stories.tsx +92 -33
- package/src/grid.tsx +39 -15
- package/dist/col.d.ts +0 -13
- package/dist/col.d.ts.map +0 -1
- package/dist/row.d.ts +0 -18
- package/dist/row.d.ts.map +0 -1
- package/src/col.module.scss +0 -62
- package/src/col.tsx +0 -43
- package/src/grid.col.stories.tsx +0 -79
- package/src/grid.row.stories.tsx +0 -67
- package/src/row.module.scss +0 -58
- package/src/row.tsx +0 -47
package/readme.mdx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Meta, Stories, ArgTypes, Primary, Subtitle } from "@storybook/blocks";
|
|
2
2
|
|
|
3
3
|
import * as GridStories from "./src/grid.stories";
|
|
4
|
-
import * as
|
|
5
|
-
import * as GridRowStories from "./src/grid.row.stories";
|
|
4
|
+
import * as GridItemStories from "./src/grid.item.stories";
|
|
6
5
|
import packageInfo from "./package.json";
|
|
7
6
|
|
|
8
7
|
<Meta name="Docs" title="Components/Grid" of={GridStories} />
|
|
@@ -21,13 +20,9 @@ import packageInfo from "./package.json";
|
|
|
21
20
|
|
|
22
21
|
<ArgTypes of={GridStories} />
|
|
23
22
|
|
|
24
|
-
#### Grid.
|
|
23
|
+
#### Grid.Item
|
|
25
24
|
|
|
26
|
-
<ArgTypes of={
|
|
27
|
-
|
|
28
|
-
#### Grid.Col
|
|
29
|
-
|
|
30
|
-
<ArgTypes of={GridColStories} />
|
|
25
|
+
<ArgTypes of={GridItemStories} />
|
|
31
26
|
|
|
32
27
|
### Installation
|
|
33
28
|
|
|
@@ -35,6 +30,10 @@ import packageInfo from "./package.json";
|
|
|
35
30
|
|
|
36
31
|
Add the dependency to your consumer app like `"@purpurds/purpur": "^x.y.z"`
|
|
37
32
|
|
|
33
|
+
### Usage
|
|
34
|
+
|
|
35
|
+
The standard usage is to have multiple elements directly as children of the `Grid` component. It's also possible to only have one, to get the standard page padding, max width and prevent getting gaps between elements.
|
|
36
|
+
|
|
38
37
|
In MyApp.tsx
|
|
39
38
|
|
|
40
39
|
```tsx
|
|
@@ -43,23 +42,72 @@ import "@purpurds/purpur/styles";
|
|
|
43
42
|
|
|
44
43
|
In MyComponent.tsx
|
|
45
44
|
|
|
45
|
+
#### Basic grid with same-width columns
|
|
46
|
+
|
|
46
47
|
```tsx
|
|
47
48
|
import { Grid } from "@purpurds/purpur";
|
|
48
49
|
|
|
49
50
|
export const MyComponent = () => {
|
|
50
51
|
return (
|
|
51
|
-
<
|
|
52
|
-
<Grid
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
<Grid colsSm={2} colsMd={4} colsLg={6}>
|
|
53
|
+
<div>Grid item 1</div>
|
|
54
|
+
<div>Grid item 2</div>
|
|
55
|
+
<div>Grid item 3</div>
|
|
56
|
+
<div>Grid item 4</div>
|
|
57
|
+
<div>Grid item 5</div>
|
|
58
|
+
<div>Grid item 6</div>
|
|
59
|
+
</Grid>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Advanced grid using nested grids
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { Grid } from "@purpurds/purpur";
|
|
68
|
+
|
|
69
|
+
export const MyComponent = () => {
|
|
70
|
+
return (
|
|
71
|
+
<Grid>
|
|
72
|
+
<Grid colsSm={1} colsMd={3} colsLg={3}>
|
|
73
|
+
<div>Grid item 1</div>
|
|
74
|
+
<div>Grid item 2</div>
|
|
75
|
+
<div>Grid item 3</div>
|
|
76
|
+
</Grid>
|
|
77
|
+
<Grid colsSm={1} colsMd={2} colsLg={2}>
|
|
78
|
+
<div>Grid item 4</div>
|
|
79
|
+
<div>Grid item 5</div>
|
|
61
80
|
</Grid>
|
|
62
|
-
|
|
81
|
+
<Grid colsSm={1} colsMd={2} colsLg={2}>
|
|
82
|
+
<div>Grid item 6</div>
|
|
83
|
+
<div>Grid item 7</div>
|
|
84
|
+
</Grid>
|
|
85
|
+
</Grid>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Advanced grid using Grid.Item
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { Grid } from "@purpurds/purpur";
|
|
94
|
+
|
|
95
|
+
export const MyComponent = () => {
|
|
96
|
+
return (
|
|
97
|
+
<Grid>
|
|
98
|
+
<Grid.Item colSpanSm={2} colSpanMd={5} colSpanLg={3}>
|
|
99
|
+
Grid item 1
|
|
100
|
+
</Grid.Item>
|
|
101
|
+
<Grid.Item colSpanSm={2} colSpanMd={3} colSpanLg={9}>
|
|
102
|
+
Grid item 2
|
|
103
|
+
</Grid.Item>
|
|
104
|
+
<Grid.Item colSpanSm={4} colSpanMd={2} colSpanLg={6}>
|
|
105
|
+
Grid item 3
|
|
106
|
+
</Grid.Item>
|
|
107
|
+
<Grid.Item colSpanSm={4} colSpanMd={6} colSpanLg={6}>
|
|
108
|
+
Grid item 4
|
|
109
|
+
</Grid.Item>
|
|
110
|
+
</Grid>
|
|
63
111
|
);
|
|
64
112
|
};
|
|
65
113
|
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
@import "@purpurds/tokens/breakpoint/variables";
|
|
2
|
+
|
|
3
|
+
.purpur-grid-item {
|
|
4
|
+
$root: &;
|
|
5
|
+
--padding: calc(var(--purpur-spacing-gutter-sm) / 2);
|
|
6
|
+
|
|
7
|
+
padding: 0 var(--padding);
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
|
|
10
|
+
@media screen and (min-width: $purpur-breakpoint-md) {
|
|
11
|
+
--padding: calc(var(--purpur-spacing-gutter-md) / 2);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@media screen and (min-width: $purpur-breakpoint-lg) {
|
|
15
|
+
--padding: calc(var(--purpur-spacing-gutter-lg) / 2);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@media screen and (min-width: $purpur-breakpoint-xl) {
|
|
19
|
+
--padding: calc(var(--purpur-spacing-gutter-xl) / 2);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@for $i from 4 through 1 {
|
|
23
|
+
&#{$root}-colspan-sm-#{$i} {
|
|
24
|
+
width: calc($i / 4 * 100%);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@for $i from 8 through 1 {
|
|
29
|
+
@media screen and (min-width: $purpur-breakpoint-md) {
|
|
30
|
+
&#{$root}-colspan-md-#{$i} {
|
|
31
|
+
width: calc($i / 8 * 100%);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@for $i from 12 through 1 {
|
|
37
|
+
@media screen and (min-width: $purpur-breakpoint-lg) {
|
|
38
|
+
&#{$root}-colspan-lg-#{$i} {
|
|
39
|
+
width: calc($i / 12 * 100%);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
|
+
|
|
5
|
+
import { Grid } from "./grid";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Grid.Item> = {
|
|
8
|
+
title: "Components/Grid",
|
|
9
|
+
component: Grid.Item,
|
|
10
|
+
parameters: {
|
|
11
|
+
design: [
|
|
12
|
+
{
|
|
13
|
+
name: "Grid",
|
|
14
|
+
type: "figma",
|
|
15
|
+
url: "https://www.figma.com/file/2QIcZVqP99ZKY4rNW7VuSx/Purpur-DS---Foundations-Library?type=design&node-id=5704%3A10669&mode=design&t=lPtp9KR80NhTNx9u-1",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
argTypes: {
|
|
20
|
+
["data-testid"]: { control: { type: "text" } },
|
|
21
|
+
className: { control: { type: "text" } },
|
|
22
|
+
children: { control: { type: "text" } },
|
|
23
|
+
colSpanSm: { control: { type: "range", min: 1, max: 4, step: 1 } },
|
|
24
|
+
colSpanMd: { control: { type: "range", min: 1, max: 8, step: 1 } },
|
|
25
|
+
colSpanLg: { control: { type: "range", min: 1, max: 12, step: 1 } },
|
|
26
|
+
},
|
|
27
|
+
args: {
|
|
28
|
+
colSpanSm: 4,
|
|
29
|
+
colSpanMd: 8,
|
|
30
|
+
colSpanLg: 12,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default meta;
|
|
35
|
+
|
|
36
|
+
type Story = StoryObj<typeof Grid.Item>;
|
|
37
|
+
|
|
38
|
+
export const Item: Story = {
|
|
39
|
+
render: ({ children, ...args }) => (
|
|
40
|
+
<Grid.Item {...args}>
|
|
41
|
+
<div style={{ border: "1px solid lightgray", padding: ".5rem" }}>
|
|
42
|
+
<p>Column</p>
|
|
43
|
+
{children}
|
|
44
|
+
</div>
|
|
45
|
+
</Grid.Item>
|
|
46
|
+
),
|
|
47
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
isValidElement,
|
|
3
|
+
ReactChild,
|
|
4
|
+
ReactElement,
|
|
5
|
+
ReactFragment,
|
|
6
|
+
ReactNode,
|
|
7
|
+
ReactPortal,
|
|
8
|
+
} from "react";
|
|
9
|
+
import c from "classnames/bind";
|
|
10
|
+
|
|
11
|
+
import styles from "./grid.item.module.scss";
|
|
12
|
+
|
|
13
|
+
const cx = c.bind(styles);
|
|
14
|
+
|
|
15
|
+
export type ItemProps = {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
["data-testid"]?: string;
|
|
18
|
+
className?: string;
|
|
19
|
+
/** The number of columns that the item spans on small screens. */
|
|
20
|
+
colSpanSm?: 1 | 2 | 3 | 4;
|
|
21
|
+
/** The number of columns that the item spans on medium screens. */
|
|
22
|
+
colSpanMd?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
23
|
+
/** The number of columns that the item spans on large screens. */
|
|
24
|
+
colSpanLg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const rootClassName = "purpur-grid-item";
|
|
28
|
+
|
|
29
|
+
export const Item = ({
|
|
30
|
+
children,
|
|
31
|
+
className,
|
|
32
|
+
["data-testid"]: dataTestId,
|
|
33
|
+
colSpanSm = 4,
|
|
34
|
+
colSpanMd = 8,
|
|
35
|
+
colSpanLg = 12,
|
|
36
|
+
}: ItemProps) => {
|
|
37
|
+
const classes = cx([
|
|
38
|
+
className,
|
|
39
|
+
rootClassName,
|
|
40
|
+
{
|
|
41
|
+
[`${rootClassName}-colspan-sm-${colSpanSm}`]: colSpanSm,
|
|
42
|
+
[`${rootClassName}-colspan-md-${colSpanMd}`]: colSpanMd,
|
|
43
|
+
[`${rootClassName}-colspan-lg-${colSpanLg}`]: colSpanLg,
|
|
44
|
+
},
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className={classes} data-testid={dataTestId}>
|
|
49
|
+
{children}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const isItem = (
|
|
55
|
+
child:
|
|
56
|
+
| ReactChild
|
|
57
|
+
| ReactElement
|
|
58
|
+
| ReactFragment
|
|
59
|
+
| ReactPortal
|
|
60
|
+
| string
|
|
61
|
+
| number
|
|
62
|
+
| boolean
|
|
63
|
+
| null
|
|
64
|
+
| undefined
|
|
65
|
+
): child is ReactElement<ItemProps> =>
|
|
66
|
+
!!child &&
|
|
67
|
+
isValidElement<ItemProps>(child) &&
|
|
68
|
+
(!!child.props.colSpanSm || !!child.props.colSpanMd || !!child.props.colSpanLg);
|
package/src/grid.module.scss
CHANGED
|
@@ -1,23 +1,83 @@
|
|
|
1
1
|
@import "@purpurds/tokens/breakpoint/variables";
|
|
2
2
|
|
|
3
3
|
.purpur-grid {
|
|
4
|
+
$root: &;
|
|
5
|
+
|
|
6
|
+
--gap: var(--purpur-spacing-gutter-sm);
|
|
4
7
|
--padding: var(--purpur-spacing-page-padding-sm);
|
|
5
8
|
|
|
6
9
|
box-sizing: border-box;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
margin-right: auto;
|
|
10
|
+
row-gap: var(--gap);
|
|
11
|
+
width: 100%;
|
|
10
12
|
max-width: var(--purpur-breakpoint-xl);
|
|
13
|
+
margin: 0 auto;
|
|
11
14
|
padding: 0 var(--padding);
|
|
12
|
-
width: 100%;
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
/* Remove padding for nested grids */
|
|
17
|
+
#{$root} {
|
|
18
|
+
padding: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@media screen and (min-width: $purpur-breakpoint-md) {
|
|
22
|
+
--gap: var(--purpur-spacing-gutter-md);
|
|
15
23
|
--padding: var(--purpur-spacing-page-padding-md);
|
|
16
24
|
}
|
|
17
|
-
|
|
25
|
+
|
|
26
|
+
@media screen and (min-width: $purpur-breakpoint-lg) {
|
|
27
|
+
--gap: var(--purpur-spacing-gutter-lg);
|
|
18
28
|
--padding: var(--purpur-spacing-page-padding-lg);
|
|
19
29
|
}
|
|
20
|
-
|
|
30
|
+
|
|
31
|
+
@media screen and (min-width: $purpur-breakpoint-xl) {
|
|
32
|
+
--gap: var(--purpur-spacing-gutter-xl);
|
|
21
33
|
--padding: var(--purpur-spacing-page-padding-xl);
|
|
22
34
|
}
|
|
23
|
-
|
|
35
|
+
|
|
36
|
+
&--grid {
|
|
37
|
+
display: grid;
|
|
38
|
+
column-gap: var(--gap);
|
|
39
|
+
|
|
40
|
+
@for $i from 4 through 2 {
|
|
41
|
+
&#{$root}-col-sm-#{$i} {
|
|
42
|
+
grid-template-columns: repeat($i, 1fr);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@for $i from 8 through 2 {
|
|
47
|
+
@media screen and (min-width: $purpur-breakpoint-md) {
|
|
48
|
+
&#{$root}-col-md-#{$i} {
|
|
49
|
+
grid-template-columns: repeat($i, 1fr);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@for $i from 12 through 2 {
|
|
55
|
+
@media screen and (min-width: $purpur-breakpoint-lg) {
|
|
56
|
+
&#{$root}-col-lg-#{$i} {
|
|
57
|
+
grid-template-columns: repeat($i, 1fr);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&--flex {
|
|
64
|
+
--gutter: var(--purpur-spacing-gutter-sm);
|
|
65
|
+
|
|
66
|
+
display: flex;
|
|
67
|
+
flex-wrap: wrap;
|
|
68
|
+
width: calc(100% + var(--gutter));
|
|
69
|
+
margin: 0 calc(-1 * (var(--gutter) / 2));
|
|
70
|
+
|
|
71
|
+
@media screen and (min-width: $purpur-breakpoint-md) {
|
|
72
|
+
--gutter: var(--purpur-spacing-gutter-md);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@media screen and (min-width: $purpur-breakpoint-lg) {
|
|
76
|
+
--gutter: var(--purpur-spacing-gutter-lg);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@media screen and (min-width: $purpur-breakpoint-xl) {
|
|
80
|
+
--gutter: var(--purpur-spacing-gutter-xl);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/grid.stories.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
|
+
import type { ReactNode } from "react";
|
|
2
3
|
import React from "react";
|
|
4
|
+
import { Link } from "@purpurds/link";
|
|
3
5
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
6
|
|
|
5
7
|
import { Grid } from "./grid";
|
|
@@ -20,6 +22,14 @@ const meta: Meta<typeof Grid> = {
|
|
|
20
22
|
["data-testid"]: { control: { type: "text" } },
|
|
21
23
|
className: { control: { type: "text" } },
|
|
22
24
|
children: { control: { type: "text" } },
|
|
25
|
+
colsSm: { control: { type: "range", min: 1, max: 4, step: 1 } },
|
|
26
|
+
colsMd: { control: { type: "range", min: 1, max: 8, step: 1 } },
|
|
27
|
+
colsLg: { control: { type: "range", min: 1, max: 12, step: 1 } },
|
|
28
|
+
},
|
|
29
|
+
args: {
|
|
30
|
+
colsSm: 2,
|
|
31
|
+
colsMd: 4,
|
|
32
|
+
colsLg: 6,
|
|
23
33
|
},
|
|
24
34
|
};
|
|
25
35
|
|
|
@@ -27,43 +37,92 @@ export default meta;
|
|
|
27
37
|
|
|
28
38
|
type Story = StoryObj<typeof Grid>;
|
|
29
39
|
|
|
40
|
+
const Column = ({ number, children }: { number: number; children?: ReactNode }) => {
|
|
41
|
+
return (
|
|
42
|
+
<div style={{ border: "1px solid lightgray", padding: ".5rem" }}>
|
|
43
|
+
<p>Column {number}</p>
|
|
44
|
+
{children}
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
30
49
|
export const Showcase: Story = {
|
|
31
50
|
render: ({ children, ...args }) => (
|
|
32
51
|
<Grid {...args}>
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
<p>Column 1</p>
|
|
36
|
-
{children}
|
|
37
|
-
</Grid.Col>
|
|
38
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
39
|
-
<p>Column 2</p>
|
|
40
|
-
{children}
|
|
41
|
-
</Grid.Col>
|
|
42
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
43
|
-
<p>Column 3</p>
|
|
44
|
-
{children}
|
|
45
|
-
</Grid.Col>
|
|
46
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
47
|
-
<p>Column 4</p>
|
|
48
|
-
{children}
|
|
49
|
-
</Grid.Col>
|
|
50
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
51
|
-
<p>Column 5</p>
|
|
52
|
-
{children}
|
|
53
|
-
</Grid.Col>
|
|
54
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
55
|
-
<p>Column 6</p>
|
|
56
|
-
{children}
|
|
57
|
-
</Grid.Col>
|
|
58
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
59
|
-
<p>Column 7</p>
|
|
60
|
-
{children}
|
|
61
|
-
</Grid.Col>
|
|
62
|
-
<Grid.Col width={6} widthMd={4} widthLg={3}>
|
|
63
|
-
<p>Column 8</p>
|
|
52
|
+
{Array.from(Array(12).keys()).map((x) => (
|
|
53
|
+
<Column key={x} number={x + 1}>
|
|
64
54
|
{children}
|
|
65
|
-
</
|
|
66
|
-
|
|
55
|
+
</Column>
|
|
56
|
+
))}
|
|
67
57
|
</Grid>
|
|
68
58
|
),
|
|
69
59
|
};
|
|
60
|
+
|
|
61
|
+
export const AdvancedWithNestedGrids: Story = {
|
|
62
|
+
parameters: {
|
|
63
|
+
controls: {
|
|
64
|
+
exclude: ["colsSm", "colsMd", "colsLg"],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
render: ({ children }) => (
|
|
68
|
+
<>
|
|
69
|
+
<Grid>
|
|
70
|
+
<Grid colsSm={1} colsMd={3} colsLg={3}>
|
|
71
|
+
<Column number={1}>{children}</Column>
|
|
72
|
+
<Column number={2}>{children}</Column>
|
|
73
|
+
<Column number={3}>{children}</Column>
|
|
74
|
+
</Grid>
|
|
75
|
+
<Grid colsSm={1} colsMd={2} colsLg={2}>
|
|
76
|
+
<Column number={4}>{children}</Column>
|
|
77
|
+
<Column number={5}>{children}</Column>
|
|
78
|
+
</Grid>
|
|
79
|
+
<Grid colsSm={1} colsMd={2} colsLg={2}>
|
|
80
|
+
<Column number={6}>{children}</Column>
|
|
81
|
+
<Column number={7}>{children}</Column>
|
|
82
|
+
</Grid>
|
|
83
|
+
</Grid>
|
|
84
|
+
<div style={{ marginTop: "3rem" }}>
|
|
85
|
+
<Link
|
|
86
|
+
variant="standalone"
|
|
87
|
+
href="/?path=/docs/components-grid--docs#advanced-grid-using-nested-grids"
|
|
88
|
+
>
|
|
89
|
+
See the example code in Docs
|
|
90
|
+
</Link>
|
|
91
|
+
</div>
|
|
92
|
+
</>
|
|
93
|
+
),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const AdvancedWithGridItems: Story = {
|
|
97
|
+
parameters: {
|
|
98
|
+
controls: {
|
|
99
|
+
exclude: ["colsSm", "colsMd", "colsLg"],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
render: ({ children }) => (
|
|
103
|
+
<>
|
|
104
|
+
<Grid>
|
|
105
|
+
<Grid.Item colSpanSm={2} colSpanMd={5} colSpanLg={3}>
|
|
106
|
+
<Column number={1}>{children}</Column>
|
|
107
|
+
</Grid.Item>
|
|
108
|
+
<Grid.Item colSpanSm={2} colSpanMd={3} colSpanLg={9}>
|
|
109
|
+
<Column number={2}>{children}</Column>
|
|
110
|
+
</Grid.Item>
|
|
111
|
+
<Grid.Item colSpanSm={4} colSpanMd={2} colSpanLg={6}>
|
|
112
|
+
<Column number={3}>{children}</Column>
|
|
113
|
+
</Grid.Item>
|
|
114
|
+
<Grid.Item colSpanSm={4} colSpanMd={6} colSpanLg={6}>
|
|
115
|
+
<Column number={4}>{children}</Column>
|
|
116
|
+
</Grid.Item>
|
|
117
|
+
</Grid>
|
|
118
|
+
<div style={{ marginTop: "3rem" }}>
|
|
119
|
+
<Link
|
|
120
|
+
variant="standalone"
|
|
121
|
+
href="/?path=/docs/components-grid--docs#advanced-grid-using-griditem"
|
|
122
|
+
>
|
|
123
|
+
See the example code in Docs
|
|
124
|
+
</Link>
|
|
125
|
+
</div>
|
|
126
|
+
</>
|
|
127
|
+
),
|
|
128
|
+
};
|
package/src/grid.tsx
CHANGED
|
@@ -1,38 +1,62 @@
|
|
|
1
|
-
import React, { ReactNode } from "react";
|
|
2
|
-
import c from "classnames";
|
|
1
|
+
import React, { Children, ReactNode } from "react";
|
|
2
|
+
import c from "classnames/bind";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { isItem, Item } from "./grid.item";
|
|
5
5
|
import styles from "./grid.module.scss";
|
|
6
|
-
import { Row } from "./row";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
Row: typeof Row;
|
|
10
|
-
Col: typeof Col;
|
|
11
|
-
};
|
|
7
|
+
const cx = c.bind(styles);
|
|
12
8
|
|
|
13
9
|
export type GridProps = {
|
|
14
10
|
children: ReactNode;
|
|
15
11
|
["data-testid"]?: string;
|
|
16
12
|
className?: string;
|
|
13
|
+
/** The number of columns on small screens. */
|
|
14
|
+
colsSm?: 1 | 2 | 3 | 4;
|
|
15
|
+
/** The number of columns on medium screens. */
|
|
16
|
+
colsMd?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
17
|
+
/** The number of columns on large screens. */
|
|
18
|
+
colsLg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
|
-
export type
|
|
21
|
+
export type GridCmp<P> = React.FunctionComponent<P> & {
|
|
22
|
+
Item: typeof Item;
|
|
23
|
+
};
|
|
20
24
|
|
|
21
25
|
const rootClassName = "purpur-grid";
|
|
22
26
|
|
|
23
|
-
export const Grid
|
|
27
|
+
export const Grid = ({
|
|
24
28
|
children,
|
|
25
29
|
className,
|
|
26
30
|
["data-testid"]: dataTestId,
|
|
31
|
+
colsSm = 1,
|
|
32
|
+
colsMd = 1,
|
|
33
|
+
colsLg = 1,
|
|
27
34
|
...props
|
|
28
|
-
}) => {
|
|
29
|
-
const
|
|
35
|
+
}: GridProps) => {
|
|
36
|
+
const gridItemChildren = Children.toArray(children).filter(isItem);
|
|
37
|
+
const hasItemChildren = gridItemChildren.length;
|
|
38
|
+
|
|
39
|
+
const classes = cx([
|
|
40
|
+
className,
|
|
41
|
+
rootClassName,
|
|
42
|
+
{
|
|
43
|
+
[`${rootClassName}--grid`]: !hasItemChildren,
|
|
44
|
+
[`${rootClassName}--flex`]: hasItemChildren,
|
|
45
|
+
[`${rootClassName}-col-sm-${colsSm}`]: colsSm > 1 && !hasItemChildren,
|
|
46
|
+
[`${rootClassName}-col-md-${colsMd}`]: colsMd > 1 && !hasItemChildren,
|
|
47
|
+
[`${rootClassName}-col-lg-${colsLg}`]: colsLg > 1 && !hasItemChildren,
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
|
|
30
51
|
return (
|
|
31
52
|
<div className={classes} data-testid={dataTestId} {...props}>
|
|
32
|
-
{
|
|
53
|
+
{hasItemChildren
|
|
54
|
+
? Children.map(gridItemChildren, ({ props: { children, ...colProps } }) => (
|
|
55
|
+
<Item {...colProps}>{children}</Item>
|
|
56
|
+
))
|
|
57
|
+
: children}
|
|
33
58
|
</div>
|
|
34
59
|
);
|
|
35
60
|
};
|
|
36
61
|
|
|
37
|
-
Grid.
|
|
38
|
-
Grid.Row = Row;
|
|
62
|
+
Grid.Item = Item;
|
package/dist/col.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { default as React, ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
export type ColumnWidthType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
4
|
-
export type ColProps = {
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
className?: string;
|
|
7
|
-
["data-testid"]?: string;
|
|
8
|
-
width?: ColumnWidthType;
|
|
9
|
-
widthMd?: ColumnWidthType;
|
|
10
|
-
widthLg?: ColumnWidthType;
|
|
11
|
-
};
|
|
12
|
-
export declare const Col: ({ children, ["data-testid"]: dataTestId, width, className, widthMd, widthLg, ...props }: ColProps) => React.JSX.Element;
|
|
13
|
-
//# sourceMappingURL=col.d.ts.map
|
package/dist/col.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"col.d.ts","sourceRoot":"","sources":["../src/col.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKzC,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAE/E,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B,CAAC;AAIF,eAAO,MAAM,GAAG,4FAQb,QAAQ,sBAgBV,CAAC"}
|
package/dist/row.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { default as React, ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
export declare const RowSpacings: {
|
|
4
|
-
readonly SM: "sm";
|
|
5
|
-
readonly MD: "md";
|
|
6
|
-
readonly LG: "lg";
|
|
7
|
-
};
|
|
8
|
-
export declare const RowSpacingSizes: ("sm" | "md" | "lg")[];
|
|
9
|
-
export type RowSpacingsType = (typeof RowSpacings)[keyof typeof RowSpacings];
|
|
10
|
-
export type RowProps = {
|
|
11
|
-
className?: string;
|
|
12
|
-
colGap?: boolean;
|
|
13
|
-
["data-testid"]?: string;
|
|
14
|
-
children: ReactNode;
|
|
15
|
-
spacing?: RowSpacingsType;
|
|
16
|
-
};
|
|
17
|
-
export declare const Row: ({ children, ["data-testid"]: dataTestId, spacing, className, colGap, ...props }: RowProps) => React.JSX.Element;
|
|
18
|
-
//# sourceMappingURL=row.d.ts.map
|
package/dist/row.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"row.d.ts","sourceRoot":"","sources":["../src/row.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKzC,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,eAAO,MAAM,eAAe,wBAA6B,CAAC;AAC1D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAE7E,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B,CAAC;AAIF,eAAO,MAAM,GAAG,oFAOb,QAAQ,sBAeV,CAAC"}
|