@workday/canvas-kit-docs 8.0.0-alpha.166-next.1 → 8.0.0-alpha.170-next.3
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.
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import {Grid, GridItem} from '@workday/canvas-kit-react/layout';
|
|
2
2
|
// examples
|
|
3
3
|
import GridLayout from './examples/Grid/GridLayout';
|
|
4
|
-
import
|
|
4
|
+
import Basic from './examples/Grid/Basic';
|
|
5
5
|
import GridLayoutInteractive from './examples/Grid/GridLayoutInteractive';
|
|
6
|
-
import {GridStyle} from './examples/PropTables.splitprops.tsx';
|
|
7
|
-
import {GridStyleProps} from '../lib/utils/grid';
|
|
8
|
-
import {GridItemStyleProps} from '../lib/utils/gridItem';
|
|
6
|
+
import {GridStyle, GridItemStyle} from './examples/PropTables.splitprops.tsx';
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
# Canvas Kit Grid
|
|
@@ -14,9 +12,6 @@ import {GridItemStyleProps} from '../lib/utils/gridItem';
|
|
|
14
12
|
two-dimensional layouts (rows and columns) with
|
|
15
13
|
[CSS Grid](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids).
|
|
16
14
|
|
|
17
|
-
If you want to see how Flexbox and Grid can
|
|
18
|
-
[work together](https://css-tricks.com/css-grid-replace-flexbox/).
|
|
19
|
-
|
|
20
15
|
## Installation
|
|
21
16
|
|
|
22
17
|
```sh
|
|
@@ -27,66 +22,66 @@ yarn add @workday/canvas-kit-react
|
|
|
27
22
|
|
|
28
23
|
### Basic Example
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
columns.
|
|
25
|
+
> **Note**: We recommend you familiarize yourself with CSS Grid
|
|
26
|
+
> ([MDN](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids),
|
|
27
|
+
> [CSS-Tricks](https://css-tricks.com/snippets/css/complete-guide-grid/)) before diving into our
|
|
28
|
+
> `Grid` component. This example makes use of
|
|
29
|
+
> [Grid Areas](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas).
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
In this example, we set up a basic layout built with `Grid` using four child components: `Header`,
|
|
32
|
+
`SideBar`, `BodyContent` and `Footer`. By assigning the same names to each child's `gridArea` prop,
|
|
33
|
+
we're able to arrange them by referencing their names in the parent `Grid` container. Our example
|
|
34
|
+
uses a 12-column grid with `SideBar` occupying three columns and `BodyContent` occupying the
|
|
35
|
+
remaining nine.
|
|
39
36
|
|
|
40
|
-
<ExampleCodeBlock code={
|
|
37
|
+
<ExampleCodeBlock code={Basic} />
|
|
41
38
|
|
|
42
39
|
### Using Grid Items
|
|
43
40
|
|
|
44
41
|
In the example above we nested `Grid` components to create our layout, and we controlled the layout
|
|
45
|
-
structure from the top-level `Grid` container.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
structure from the top-level `Grid` container. We can also use `Grid.Item` components to allow child
|
|
43
|
+
cells to have more control. While any direct child of a `Grid` component is implicitly a grid item,
|
|
44
|
+
`Grid.Item` provides special CSS Grid Item style props that allow you to have more control over how
|
|
45
|
+
and where each item renders.
|
|
49
46
|
|
|
50
47
|
To demonstrate this behavior, the example below has a `Grid` container with nine cells. The eight
|
|
51
48
|
`soap500` cells are `Grid` components, and the `peach300` cell is a `Grid.Item`. We can use the
|
|
52
49
|
`Grid.Item` style props `gridRowStart` and `gridColumnStart` to manipulate where the cell renders.
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
Use the `Row` and `Column` buttons to manipulate these props and see the `Grid.Item`'s position
|
|
51
|
+
adjust accordingly.
|
|
55
52
|
|
|
56
|
-
> Note
|
|
57
|
-
> considered an accessibility best practice. Visually reordering content does not change the
|
|
58
|
-
> it is read by a screen reader
|
|
59
|
-
> accessibility
|
|
60
|
-
> [here](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid_Layout_and_Accessibility).
|
|
53
|
+
> **Note**: This example is solely intended to demonstrate `Grid.Item`'s functionality and is
|
|
54
|
+
> **not** considered an accessibility best practice. Visually reordering content does not change the
|
|
55
|
+
> tab order or the order it is read in by a screen reader. Learn more about
|
|
56
|
+
> [CSS Grid layout and accessibility](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid_Layout_and_Accessibility).
|
|
61
57
|
|
|
62
58
|
<ExampleCodeBlock code={GridLayoutInteractive} />
|
|
63
59
|
|
|
64
60
|
Let's look at another `Grid.Item` example. Below, we have a `Grid` container with two rows: one with
|
|
65
|
-
seven elements and
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
the 1 & 2 elements since that layout is wrapped by the `Grid.Item` component.
|
|
61
|
+
seven elements and another with two elements. Each row is a `Grid.Item` that wraps a nested `Grid`.
|
|
62
|
+
This allows you to use `Grid.Item` to place a layout where needed. Here, we use `gridRowStart` to
|
|
63
|
+
place the row with elements 3 through 7 before the row with elements 1 and 2.
|
|
69
64
|
|
|
70
65
|
<ExampleCodeBlock code={GridLayout} />
|
|
71
66
|
|
|
72
|
-
###
|
|
67
|
+
### Grid vs. Flex vs. Box
|
|
73
68
|
|
|
74
|
-
`
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
together. They are intended to be
|
|
79
|
-
general
|
|
69
|
+
`Grid` and `Flex` are built on top of `Box`, so they have access to all `BoxProps`. Additionally,
|
|
70
|
+
`Grid` and `Flex` have their own specific style props that map to CSS Grid and Flexbox properties,
|
|
71
|
+
respectively. When using these components to build layouts, it is not a matter of choosing `Grid`
|
|
72
|
+
_or_ `Flex` _or_ `Box`, but rather deciding how to
|
|
73
|
+
[use them together](https://css-tricks.com/css-grid-replace-flexbox/). They are intended to be
|
|
74
|
+
complementary not exclusionary. With that said, here are general guidelines for when to use which:
|
|
80
75
|
|
|
81
|
-
- Use `Grid` for
|
|
82
|
-
- Use `Flex` for
|
|
76
|
+
- Use `Grid` for **two-dimensional** layouts (rows AND columns).
|
|
77
|
+
- Use `Flex` for **one-dimensional** layouts (a row OR a column).
|
|
83
78
|
- Use `Box` for generic containers that don't need CSS Flexbox or Grid.
|
|
84
79
|
|
|
85
80
|
## Components
|
|
86
81
|
|
|
87
82
|
### Grid
|
|
88
83
|
|
|
89
|
-
Grid is a container component for creating two-dimensional layouts with CSS Grid. It has special
|
|
84
|
+
`Grid` is a container component for creating two-dimensional layouts with CSS Grid. It has special
|
|
90
85
|
style props that map to CSS Grid style properties to provide a common, ergonomic API for building
|
|
91
86
|
layouts.
|
|
92
87
|
|
|
@@ -104,14 +99,14 @@ layouts.
|
|
|
104
99
|
|
|
105
100
|
As previously mentioned, `Grid` is built on top of `Box` and has access to all its props, including
|
|
106
101
|
[grid container properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout#the_grid_container)
|
|
107
|
-
through style props as well.
|
|
102
|
+
through style props as well.
|
|
108
103
|
|
|
109
|
-
<ArgsTable of={
|
|
104
|
+
<ArgsTable of={GridStyle} />
|
|
110
105
|
|
|
111
106
|
### Grid.Item
|
|
112
107
|
|
|
113
108
|
`Grid.Item` is a subcomponent of Grid. It has specific grid item style props that map to CSS Grid
|
|
114
|
-
Item properties. This
|
|
109
|
+
Item properties. This provides greater control over how child components render in your layout.
|
|
115
110
|
|
|
116
111
|
#### Usage
|
|
117
112
|
|
|
@@ -127,4 +122,4 @@ Item properties. This allows you greater control over how child components rende
|
|
|
127
122
|
|
|
128
123
|
#### Props
|
|
129
124
|
|
|
130
|
-
<ArgsTable of={
|
|
125
|
+
<ArgsTable of={GridItemStyle} />
|
|
@@ -44,8 +44,7 @@ const Footer = ({children, ...props}: GridProps) => (
|
|
|
44
44
|
|
|
45
45
|
export default () => {
|
|
46
46
|
const parentCont = {
|
|
47
|
-
gridTemplateAreas:
|
|
48
|
-
"'Header Header Header Header' 'SideBar BodyContent BodyContent BodyContent' 'Footer Footer Footer Footer'",
|
|
47
|
+
gridTemplateAreas: "'Header Header' 'SideBar BodyContent' 'Footer Footer'",
|
|
49
48
|
gridGap: fontSizes[16],
|
|
50
49
|
gridTemplateColumns: '3fr 9fr',
|
|
51
50
|
gridTemplateRows: 'auto 300px auto',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {Grid} from '@workday/canvas-kit-react/layout';
|
|
2
|
+
import {Box, Grid} from '@workday/canvas-kit-react/layout';
|
|
3
3
|
|
|
4
4
|
const Cell = (props: {children: React.ReactNode}) => {
|
|
5
5
|
return (
|
|
@@ -37,7 +37,7 @@ const CellItem = (props: {children: React.ReactNode}) => {
|
|
|
37
37
|
|
|
38
38
|
export default () => {
|
|
39
39
|
return (
|
|
40
|
-
<
|
|
40
|
+
<Box padding="xs">
|
|
41
41
|
<Grid
|
|
42
42
|
gridTemplateColumns="repeat(auto-fit, minmax(300px, 1fr))"
|
|
43
43
|
gridGap="10px"
|
|
@@ -60,6 +60,6 @@ export default () => {
|
|
|
60
60
|
</Grid>
|
|
61
61
|
</Grid.Item>
|
|
62
62
|
</Grid>
|
|
63
|
-
</
|
|
63
|
+
</Box>
|
|
64
64
|
);
|
|
65
65
|
};
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
FlexStyleProps,
|
|
5
|
+
StackStyleProps,
|
|
6
|
+
GridStyleProps,
|
|
7
|
+
GridItemStyleProps,
|
|
8
|
+
} from '@workday/canvas-kit-react/layout';
|
|
4
9
|
|
|
5
10
|
export const FlexStyle = (props: FlexStyleProps) => <div />;
|
|
6
11
|
|
|
7
12
|
export const StackStyle = (props: StackStyleProps) => <div />;
|
|
8
13
|
|
|
9
14
|
export const GridStyle = (props: GridStyleProps) => <div />;
|
|
15
|
+
|
|
16
|
+
export const GridItemStyle = (props: GridItemStyleProps) => <div />;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.170-next.3+5a6d1f8b",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@storybook/csf": "0.0.1",
|
|
45
|
-
"@workday/canvas-kit-react": "^8.0.0-alpha.
|
|
45
|
+
"@workday/canvas-kit-react": "^8.0.0-alpha.170-next.3+5a6d1f8b"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"fs-extra": "^10.0.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"mkdirp": "^1.0.3",
|
|
51
51
|
"typescript": "4.1"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5a6d1f8bce5cc7ec386c6e5f78ba8e87a3873592"
|
|
54
54
|
}
|