@workday/canvas-kit-docs 8.0.0-alpha.138-next.6 → 8.0.0-alpha.150-next.2

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.
@@ -431,7 +431,9 @@ The APIs for these promoted components remain unchanged.
431
431
 
432
432
  ### Action Bar
433
433
 
434
- The ActionBar API changed to model API to support more generic behaviors to allow for other
434
+ #### Model
435
+
436
+ The `ActionBar` API changed to model API to support more generic behaviors to allow for other
435
437
  components to support responsive layouts using the same models and behaviors. It also allows to
436
438
  implement a responsive layout based on a container width
437
439
  ([#1585](https://github.com/Workday/canvas-kit/pull/1585)).
@@ -449,7 +451,9 @@ const model = useActionBarModel({
449
451
  <ActionBar model={model} />;
450
452
  ```
451
453
 
452
- The ActionBar component can now handle responsive containers, but the support is not automatic. You
454
+ #### Responsive Container Support
455
+
456
+ The `ActionBar` component can now handle responsive containers, but the support is not automatic. You
453
457
  must use the dynamic API and provide an overflow menu subcomponent. The dynamic API doesn't know the
454
458
  shape of your object, so render props must be used to instruct React how to render each item.
455
459
 
@@ -497,6 +501,11 @@ const model = useActionBarModel({items});
497
501
  </ActionBar>;
498
502
  ```
499
503
 
504
+ #### Fixed Position Prop
505
+
506
+ `ActionBar`'s boolean `fixed` prop has been removed. It has been replaced by a new `position` style
507
+ prop in the `ActionBar.List` component and is set to `fixed` by default.
508
+
500
509
  🤖 The codemod will remove uses of the `fixed` prop from `ActionBar` and restructure component by
501
510
  creating `ActionBar.List` subcomponent and replacing all `ActionBar` children to it.
502
511
 
@@ -0,0 +1,130 @@
1
+ import {Grid, GridItem} from '@workday/canvas-kit-react/layout';
2
+ // examples
3
+ import GridLayout from './examples/Grid/GridLayout';
4
+ import UIExample from './examples/Grid/UIExample';
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';
9
+
10
+
11
+ # Canvas Kit Grid
12
+
13
+ `Grid` is a low-level layout component that provides a common, ergonomic API for building
14
+ two-dimensional layouts (rows and columns) with
15
+ [CSS Grid](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids).
16
+
17
+ If you want to see how Flexbox and Grid can
18
+ [work together](https://css-tricks.com/css-grid-replace-flexbox/).
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ yarn add @workday/canvas-kit-react
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Basic Example
29
+
30
+ Below is a basic layout built with `Grid`. We created four components: `Header`, `SideBar`,
31
+ `BodyContent` and `Footer`. We also used those names for their respective `gridArea` props. Then we
32
+ can use those names in the parent component, `UIExample`, to organize the UI however we want. This
33
+ allows the parent container to control how its children render. For page layouts, Workday typically
34
+ uses a 12 column grid. In the example below, the Sidebar is 3 columns and the Body Content is 9
35
+ columns.
36
+
37
+ > Note: You can learn more about CSS Grid's `gridArea` and `gridTemplateAreas`
38
+ > [here](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas).
39
+
40
+ <ExampleCodeBlock code={UIExample} />
41
+
42
+ ### Using Grid Items
43
+
44
+ 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. That's a perfectly valid approach. However, we can
46
+ also use `Grid.Item` components to allow child cells to have more control. While any direct child of
47
+ a `Grid` component is implicitly a grid item, `Grid.Item` provides special CSS Grid Item style props
48
+ that allow you to have more control over how and where each item renders.
49
+
50
+ To demonstrate this behavior, the example below has a `Grid` container with nine cells. The eight
51
+ `soap500` cells are `Grid` components, and the `peach300` cell is a `Grid.Item`. We can use the
52
+ `Grid.Item` style props `gridRowStart` and `gridColumnStart` to manipulate where the cell renders.
53
+ You can use the `Row` and `Column` buttons to manipulate these props and see the `Grid.Item`'s
54
+ position adjust accordingly.
55
+
56
+ > Note: This example is solely intended to demonstrate the `Grid.Item`'s functionality and is NOT
57
+ > considered an accessibility best practice. Visually reordering content does not change the order
58
+ > it is read by a screen reader or the tab order. You can learn more about CSS Grid layout and
59
+ > accessibility
60
+ > [here](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid_Layout_and_Accessibility).
61
+
62
+ <ExampleCodeBlock code={GridLayoutInteractive} />
63
+
64
+ Let's look at another `Grid.Item` example. Below, we have a `Grid` container with two rows: one with
65
+ seven elements and the other with two elements. This example is to show how a user can use the
66
+ `<Grid.Item/>` component to wrap a `Grid` component. This would allow a user to have access to the
67
+ child props of `Grid.Item` to place a layout where needed. The row with elements 3 - 7 is put before
68
+ the 1 & 2 elements since that layout is wrapped by the `Grid.Item` component.
69
+
70
+ <ExampleCodeBlock code={GridLayout} />
71
+
72
+ ### Using Grid vs. Flex vs. Box
73
+
74
+ `Box` is the underlying layout component that `Grid` and `Flex` are built upon. So `Grid` and `Flex`
75
+ have access to all `BoxProps`. But `Grid` and `Flex` have their own specific style props that map to
76
+ CSS Grid and Flexbox properties, respectively. When using these components to build layouts, it is
77
+ not a matter of choosing `Grid` _or_ `Flex` _or_ `Box`, but rather deciding how to use them
78
+ together. They are intended to be complementary not exclusionary. With that said, here are some
79
+ general rules for when to use which:
80
+
81
+ - Use `Grid` for building **two-dimensional** layouts (rows AND columns).
82
+ - Use `Flex` for building **one-dimensional** layouts (a row OR a column).
83
+ - Use `Box` for generic containers that don't need CSS Flexbox or Grid.
84
+
85
+ ## Components
86
+
87
+ ### Grid
88
+
89
+ Grid is a container component for creating two-dimensional layouts with CSS Grid. It has special
90
+ style props that map to CSS Grid style properties to provide a common, ergonomic API for building
91
+ layouts.
92
+
93
+ #### Usage
94
+
95
+ ```tsx
96
+ <Grid grid gridTemplateColumns="1fr 2fr 1fr" gridGap={space.s}>
97
+ <div>Implicit grid item 1</div>
98
+ <div>Implicit grid item 2</div>
99
+ <div>Implicit grid item 3</div>
100
+ </Grid>
101
+ ```
102
+
103
+ #### Props
104
+
105
+ As previously mentioned, `Grid` is built on top of `Box` and has access to all its props, including
106
+ [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. Here are the grid container props:
108
+
109
+ <ArgsTable of={GridStyleProps} />
110
+
111
+ ### Grid.Item
112
+
113
+ `Grid.Item` is a subcomponent of Grid. It has specific grid item style props that map to CSS Grid
114
+ Item properties. This allows you greater control over how child components render in your layout.
115
+
116
+ #### Usage
117
+
118
+ ```tsx
119
+ <Grid gridGap={space.s}>
120
+ <Grid.Item gridColumn="1 / span 2">First item</Grid.Item>
121
+ <Grid.Item gridRow="1 / span 2">Second item</Grid.Item>
122
+ <Grid.Item gridColumn="1 / span 2" gridRow="2">
123
+ Third item
124
+ </Grid.Item>
125
+ </Grid>
126
+ ```
127
+
128
+ #### Props
129
+
130
+ <ArgsTable of={GridItemStyleProps} />
@@ -0,0 +1,44 @@
1
+ import * as React from 'react';
2
+ import {Grid, Box} from '@workday/canvas-kit-react/layout';
3
+ import {PrimaryButton, SecondaryButton} from '@workday/canvas-kit-react/button';
4
+ import {type} from '@workday/canvas-kit-react/tokens';
5
+
6
+ // temporary placeholder until type components are added to canvas-kit
7
+ const H3 = props => (
8
+ <h3
9
+ style={{
10
+ ...type.levels.body.large,
11
+ margin: 0,
12
+ fontWeight: type.properties.fontWeights.bold,
13
+ }}
14
+ {...props}
15
+ />
16
+ );
17
+
18
+ const Body = props => <p style={{...type.levels.body.small, margin: 0}} {...props} />;
19
+
20
+ export default () => {
21
+ const [isComplete, setIsComplete] = React.useState(false);
22
+ return (
23
+ <Grid
24
+ padding="m"
25
+ depth={1}
26
+ borderRadius="l"
27
+ border="solid 1px"
28
+ borderColor="soap400"
29
+ maxWidth={600}
30
+ gridTemplate="auto / auto"
31
+ >
32
+ <H3>Learn about Grid {isComplete && '🥳'}</H3>
33
+ <Box paddingY="s">
34
+ <Body>Complete this task when you have a functional understanding of Grid.</Body>
35
+ </Box>
36
+ <Grid gridTemplate="auto / 1fr auto" justifyItems="end">
37
+ <Box marginRight="xxs">
38
+ <PrimaryButton onClick={() => setIsComplete(true)}>Complete</PrimaryButton>
39
+ </Box>
40
+ <SecondaryButton onClick={() => setIsComplete(false)}>Cancel</SecondaryButton>
41
+ </Grid>
42
+ </Grid>
43
+ );
44
+ };
@@ -0,0 +1,65 @@
1
+ import * as React from 'react';
2
+ import {Grid} from '@workday/canvas-kit-react/layout';
3
+
4
+ const Cell = (props: {children: React.ReactNode}) => {
5
+ return (
6
+ <Grid
7
+ alignContent="center"
8
+ padding="xs"
9
+ justifyContent="center"
10
+ backgroundColor="soap500"
11
+ color="blackPepper500"
12
+ borderRadius="m"
13
+ >
14
+ {props.children}
15
+ </Grid>
16
+ );
17
+ };
18
+
19
+ const CellItem = (props: {children: React.ReactNode}) => {
20
+ return (
21
+ <Grid
22
+ alignContent="center"
23
+ gridAutoColumns="max-content"
24
+ gridGap="0 16px"
25
+ height="100%"
26
+ gridAutoFlow="column"
27
+ padding="xs"
28
+ justifyContent="center"
29
+ backgroundColor="peach300"
30
+ color="blackPepper500"
31
+ borderRadius="m"
32
+ >
33
+ {props.children}
34
+ </Grid>
35
+ );
36
+ };
37
+
38
+ export default () => {
39
+ return (
40
+ <Grid gridAutoFlow="row" padding="xs" gridGap="10px 0">
41
+ <Grid
42
+ gridTemplateColumns="repeat(auto-fit, minmax(300px, 1fr))"
43
+ gridGap="10px"
44
+ padding="xxs"
45
+ border="5px solid #c860d1"
46
+ >
47
+ <Grid.Item gridRowStart="2">
48
+ <Grid gridTemplateColumns="repeat(auto-fit, minmax(300px, 1fr))" gridGap="10px">
49
+ <Cell>1</Cell>
50
+ <Cell>2</Cell>
51
+ </Grid>
52
+ </Grid.Item>
53
+ <Grid.Item gridRowStart="1">
54
+ <Grid gridTemplateColumns="repeat(auto-fit, minmax(100px, 1fr))" gridGap="10px">
55
+ <CellItem>3</CellItem>
56
+ <CellItem>4</CellItem>
57
+ <CellItem>5</CellItem>
58
+ <CellItem>6</CellItem>
59
+ <CellItem>7</CellItem>
60
+ </Grid>
61
+ </Grid.Item>
62
+ </Grid>
63
+ </Grid>
64
+ );
65
+ };
@@ -0,0 +1,114 @@
1
+ import React, {useState, useEffect, useRef} from 'react';
2
+ import {Grid} from '@workday/canvas-kit-react/layout';
3
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
4
+ // eslint-disable-next-line no-duplicate-imports
5
+ import {
6
+ arrowDownIcon,
7
+ arrowLeftIcon,
8
+ arrowRightIcon,
9
+ arrowUpIcon,
10
+ } from '@workday/canvas-system-icons-web';
11
+
12
+ const Cell = (props: {children: React.ReactNode}) => {
13
+ return (
14
+ <Grid
15
+ alignContent="center"
16
+ padding="xs"
17
+ justifyContent="center"
18
+ backgroundColor="soap500"
19
+ color="blackPepper500"
20
+ borderRadius="m"
21
+ >
22
+ {props.children}
23
+ </Grid>
24
+ );
25
+ };
26
+
27
+ const CellItem = (props: {children: React.ReactNode}) => {
28
+ return (
29
+ <Grid
30
+ alignContent="center"
31
+ gridAutoColumns="max-content"
32
+ gridGap="0 16px"
33
+ height="100%"
34
+ gridAutoFlow="column"
35
+ padding="xs"
36
+ justifyContent="center"
37
+ backgroundColor="peach300"
38
+ color="frenchVanilla100"
39
+ borderRadius="m"
40
+ >
41
+ {props.children}
42
+ </Grid>
43
+ );
44
+ };
45
+
46
+ export default () => {
47
+ const [rowCount, setRowCount] = useState(1);
48
+ const [colCount, setColCount] = useState(1);
49
+
50
+ const Prev = val => {
51
+ const ref = useRef();
52
+ useEffect(() => {
53
+ ref.current = val;
54
+ }, [val]);
55
+ return ref.current;
56
+ };
57
+
58
+ const prevRowCount = Prev(rowCount);
59
+ const prevColCount = Prev(colCount);
60
+
61
+ const plusMinus = (curr, prev) => {
62
+ if (curr <= 2 && (!prev || prev <= 2)) {
63
+ return true;
64
+ }
65
+ };
66
+
67
+ const incDec = (curr, prev, func) => {
68
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
69
+ plusMinus(curr, prev) ? func(curr + 1) : func(curr - 1);
70
+ };
71
+
72
+ return (
73
+ <Grid gridAutoFlow="row" padding="xs" gridGap="10px 0">
74
+ <Grid
75
+ gridTemplateColumns="repeat(3, 1fr)"
76
+ gridTemplateRows="repeat(3, 1fr)"
77
+ gridGap="10px"
78
+ padding="xs"
79
+ border="5px solid #c860d1"
80
+ >
81
+ <Grid.Item gridRowStart={rowCount} gridColumnStart={colCount}>
82
+ <CellItem>
83
+ <PrimaryButton
84
+ size="extraSmall"
85
+ icon={plusMinus(rowCount, prevRowCount) ? arrowDownIcon : arrowUpIcon}
86
+ onClick={() => {
87
+ incDec(rowCount, prevRowCount, setRowCount);
88
+ }}
89
+ >
90
+ Row: {rowCount}
91
+ </PrimaryButton>
92
+ <PrimaryButton
93
+ size="extraSmall"
94
+ icon={plusMinus(colCount, prevColCount) ? arrowRightIcon : arrowLeftIcon}
95
+ onClick={() => {
96
+ incDec(colCount, prevColCount, setColCount);
97
+ }}
98
+ >
99
+ Col: {colCount}
100
+ </PrimaryButton>
101
+ </CellItem>
102
+ </Grid.Item>
103
+ <Cell>2</Cell>
104
+ <Cell>3</Cell>
105
+ <Cell>4</Cell>
106
+ <Cell>5</Cell>
107
+ <Cell>6</Cell>
108
+ <Cell>7</Cell>
109
+ <Cell>8</Cell>
110
+ <Cell>9</Cell>
111
+ </Grid>
112
+ </Grid>
113
+ );
114
+ };
@@ -0,0 +1,71 @@
1
+ import * as React from 'react';
2
+ import {Grid, GridProps, Box} from '@workday/canvas-kit-react/layout';
3
+ import {type} from '@workday/canvas-kit-react/tokens';
4
+ import {fontSizes} from '../../../../tokens/lib/type/fontSizes';
5
+ import styled from '@emotion/styled';
6
+
7
+ // temporary placeholder until type components are added to canvas-kit
8
+
9
+ const StyledHeading = styled(Box.as('h3'))({
10
+ ...type.levels.body.large,
11
+ ...type.variants.inverse,
12
+ margin: 0,
13
+ fontWeight: type.properties.fontWeights.bold,
14
+ });
15
+
16
+ const borderPadProps = {
17
+ borderRadius: 'm',
18
+ padding: 's',
19
+ };
20
+
21
+ const Header = ({children, ...props}: GridProps) => (
22
+ <Grid gridArea="Header" depth={1} {...props} {...borderPadProps}>
23
+ {children}
24
+ </Grid>
25
+ );
26
+
27
+ const BodyContent = ({children, ...props}: GridProps) => (
28
+ <Grid gridArea="BodyContent" depth={1} {...props} {...borderPadProps}>
29
+ {children}
30
+ </Grid>
31
+ );
32
+
33
+ const SideBar = ({children, ...props}: GridProps) => (
34
+ <Grid gridArea="SideBar" depth={1} {...props} {...borderPadProps}>
35
+ {children}
36
+ </Grid>
37
+ );
38
+
39
+ const Footer = ({children, ...props}: GridProps) => (
40
+ <Grid gridArea="Footer" depth={1} {...props} {...borderPadProps}>
41
+ {children}
42
+ </Grid>
43
+ );
44
+
45
+ export default () => {
46
+ const parentCont = {
47
+ gridTemplateAreas:
48
+ "'Header Header Header Header' 'SideBar BodyContent BodyContent BodyContent' 'Footer Footer Footer Footer'",
49
+ gridGap: fontSizes[16],
50
+ gridTemplateColumns: '3fr 9fr',
51
+ gridTemplateRows: 'auto 300px auto',
52
+ };
53
+ return (
54
+ <Grid as="section" padding="s">
55
+ <Grid {...parentCont}>
56
+ <Header backgroundColor="blueberry400">
57
+ <StyledHeading>Header</StyledHeading>
58
+ </Header>
59
+ <SideBar backgroundColor="blueberry300">
60
+ <StyledHeading>SideBar</StyledHeading>
61
+ </SideBar>
62
+ <BodyContent backgroundColor="plum300">
63
+ <StyledHeading>Body Content</StyledHeading>
64
+ </BodyContent>
65
+ <Footer backgroundColor="berrySmoothie300">
66
+ <StyledHeading>Footer</StyledHeading>
67
+ </Footer>
68
+ </Grid>
69
+ </Grid>
70
+ );
71
+ };
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import {FlexStyleProps, StackStyleProps} from '@workday/canvas-kit-react/layout';
3
+ import {FlexStyleProps, StackStyleProps, GridStyleProps} from '@workday/canvas-kit-react/layout';
4
4
 
5
5
  export const FlexStyle = (props: FlexStyleProps) => <div />;
6
6
 
7
7
  export const StackStyle = (props: StackStyleProps) => <div />;
8
+
9
+ export const GridStyle = (props: GridStyleProps) => <div />;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "8.0.0-alpha.138-next.6+7e99b1d8",
3
+ "version": "8.0.0-alpha.150-next.2+b0c3f340",
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.138-next.6+7e99b1d8"
45
+ "@workday/canvas-kit-react": "^8.0.0-alpha.150-next.2+b0c3f340"
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": "7e99b1d8e866a65d922bad07765622457b8712f6"
53
+ "gitHead": "b0c3f340ec8e06d39bed5d992b23a1b36892106f"
54
54
  }