@workday/canvas-kit-docs 14.0.0-alpha.1149-next.0 → 14.0.0-alpha.1151-next.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.
@@ -0,0 +1,111 @@
1
+ import React from 'react';
2
+ import styled from '@emotion/styled';
3
+
4
+ interface ButtonProps {
5
+ variant: 'primary' | 'secondary' | 'danger';
6
+ size: 'large' | 'medium' | 'small';
7
+ backgroundColor?: string;
8
+ children?: React.ReactNode;
9
+ }
10
+
11
+ const StyledButton = styled('button')<ButtonProps>(
12
+ {
13
+ // base styles
14
+ fontSize: '1rem',
15
+ display: 'flex',
16
+ borderRadius: '1rem',
17
+ },
18
+ // variant styles
19
+ ({variant, backgroundColor}) => {
20
+ switch (variant) {
21
+ case 'primary':
22
+ return {
23
+ background: backgroundColor || 'blue',
24
+ color: 'white',
25
+ };
26
+ case 'secondary':
27
+ return {
28
+ background: backgroundColor || 'gray',
29
+ };
30
+ case 'danger':
31
+ return {
32
+ background: backgroundColor || 'red',
33
+ };
34
+ default:
35
+ return {};
36
+ }
37
+ },
38
+ // size styles
39
+ ({size}) => {
40
+ switch (size) {
41
+ case 'large':
42
+ return {
43
+ fontSize: '1.4rem',
44
+ height: '2rem',
45
+ };
46
+ case 'medium':
47
+ return {
48
+ fontSize: '1rem',
49
+ height: '1.5rem',
50
+ };
51
+ case 'small':
52
+ return {
53
+ fontSize: '0.8rem',
54
+ height: '1.2rem',
55
+ };
56
+ default:
57
+ return {};
58
+ }
59
+ }
60
+ );
61
+
62
+ export default () => {
63
+ return (
64
+ <div style={{display: 'flex', flexDirection: 'column', gap: '1rem'}}>
65
+ <div style={{display: 'flex', gap: '1rem'}}>
66
+ <StyledButton variant="primary" size="large">
67
+ Primary Large
68
+ </StyledButton>
69
+ <StyledButton variant="primary" size="medium">
70
+ Primary Medium
71
+ </StyledButton>
72
+ <StyledButton variant="primary" size="small">
73
+ Primary Small
74
+ </StyledButton>
75
+ </div>
76
+ <div style={{display: 'flex', gap: '1rem'}}>
77
+ <StyledButton variant="secondary" size="large">
78
+ Secondary Large
79
+ </StyledButton>
80
+ <StyledButton variant="secondary" size="medium">
81
+ Secondary Medium
82
+ </StyledButton>
83
+ <StyledButton variant="secondary" size="small">
84
+ Secondary Small
85
+ </StyledButton>
86
+ </div>
87
+ <div style={{display: 'flex', gap: '1rem'}}>
88
+ <StyledButton variant="danger" size="large">
89
+ Danger Large
90
+ </StyledButton>
91
+ <StyledButton variant="danger" size="medium">
92
+ Danger Medium
93
+ </StyledButton>
94
+ <StyledButton variant="danger" size="small">
95
+ Danger Small
96
+ </StyledButton>
97
+ </div>
98
+ <div style={{display: 'flex', gap: '1rem'}}>
99
+ <StyledButton variant="danger" size="large" backgroundColor="orange">
100
+ Custom Large
101
+ </StyledButton>
102
+ <StyledButton variant="danger" size="medium" backgroundColor="orange">
103
+ Custom Medium
104
+ </StyledButton>
105
+ <StyledButton variant="danger" size="small" backgroundColor="orange">
106
+ Custom Small
107
+ </StyledButton>
108
+ </div>
109
+ </div>
110
+ );
111
+ };
@@ -0,0 +1,107 @@
1
+ import React from 'react';
2
+ import {createStyles} from '@workday/canvas-kit-styling';
3
+
4
+ interface ButtonProps {
5
+ variant: 'primary' | 'secondary' | 'danger';
6
+ size: 'large' | 'medium' | 'small';
7
+ backgroundColor?: string;
8
+ children?: React.ReactNode;
9
+ }
10
+
11
+ const baseStyles = createStyles({
12
+ fontSize: '1rem',
13
+ display: 'flex',
14
+ borderRadius: '1rem',
15
+ });
16
+
17
+ const modifierStyles = {
18
+ variant: {
19
+ primary: createStyles({
20
+ background: `var(--button-background-color, blue)`,
21
+ color: 'white',
22
+ }),
23
+ secondary: createStyles({
24
+ background: `var(--button-background-color, gray)`,
25
+ }),
26
+ danger: createStyles({
27
+ background: `var(--button-background-color, red)`,
28
+ }),
29
+ },
30
+ size: {
31
+ large: createStyles({
32
+ fontSize: '1.4rem',
33
+ height: '2rem',
34
+ }),
35
+ medium: createStyles({
36
+ fontSize: '1rem',
37
+ height: '1.5rem',
38
+ }),
39
+ small: createStyles({
40
+ fontSize: '0.8rem',
41
+ height: '1.2rem',
42
+ }),
43
+ },
44
+ };
45
+
46
+ const Button = ({variant, size, backgroundColor, children}: ButtonProps) => {
47
+ const className = [baseStyles, modifierStyles.variant[variant], modifierStyles.size[size]].join(
48
+ ' '
49
+ );
50
+ const style = {'--button-background-color': backgroundColor} as React.CSSProperties;
51
+ return (
52
+ <button className={className} style={style}>
53
+ {children}
54
+ </button>
55
+ );
56
+ };
57
+
58
+ export default () => {
59
+ return (
60
+ <div style={{display: 'flex', flexDirection: 'column', gap: '1rem'}}>
61
+ <div style={{display: 'flex', gap: '1rem'}}>
62
+ <Button variant="primary" size="large">
63
+ Primary Large
64
+ </Button>
65
+ <Button variant="primary" size="medium">
66
+ Primary Medium
67
+ </Button>
68
+ <Button variant="primary" size="small">
69
+ Primary Small
70
+ </Button>
71
+ </div>
72
+ <div style={{display: 'flex', gap: '1rem'}}>
73
+ <Button variant="secondary" size="large">
74
+ Secondary Large
75
+ </Button>
76
+ <Button variant="secondary" size="medium">
77
+ Secondary Medium
78
+ </Button>
79
+ <Button variant="secondary" size="small">
80
+ Secondary Small
81
+ </Button>
82
+ </div>
83
+ <div style={{display: 'flex', gap: '1rem'}}>
84
+ <Button variant="danger" size="large">
85
+ Danger Large
86
+ </Button>
87
+ <Button variant="danger" size="medium">
88
+ Danger Medium
89
+ </Button>
90
+ <Button variant="danger" size="small">
91
+ Danger Small
92
+ </Button>
93
+ </div>
94
+ <div style={{display: 'flex', gap: '1rem'}}>
95
+ <Button variant="danger" size="large" backgroundColor="orange">
96
+ Custom Large
97
+ </Button>
98
+ <Button variant="danger" size="medium" backgroundColor="orange">
99
+ Custom Medium
100
+ </Button>
101
+ <Button variant="danger" size="small" backgroundColor="orange">
102
+ Custom Small
103
+ </Button>
104
+ </div>
105
+ </div>
106
+ );
107
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+
3
+ import {system} from '@workday/canvas-tokens-web';
4
+ import {caretDownIcon} from '@workday/canvas-system-icons-web';
5
+ import {createStyles} from '@workday/canvas-kit-styling';
6
+ import {buttonStencil, PrimaryButton} from '@workday/canvas-kit-react/button';
7
+ import {systemIconStencil} from '@workday/canvas-kit-react/icon';
8
+
9
+ const varStyles = createStyles({
10
+ [buttonStencil.vars.background]: system.color.static.gray.soft,
11
+ [buttonStencil.vars.label]: system.color.static.blue.strong,
12
+ // Because PrimaryButton uses SystemIcon under the hood,
13
+ // we also can change system icon variable for color
14
+ [systemIconStencil.vars.color]: system.color.static.blue.strong,
15
+ '&:hover': {
16
+ [buttonStencil.vars.background]: system.color.static.amber.default,
17
+ [buttonStencil.vars.label]: system.color.static.white,
18
+ [systemIconStencil.vars.color]: system.color.static.white,
19
+ },
20
+ '&:focus-visible': {
21
+ [buttonStencil.vars.background]: system.color.static.green.default,
22
+ [buttonStencil.vars.boxShadowOuter]: system.color.static.green.strong,
23
+ [buttonStencil.vars.boxShadowInner]: system.color.static.white,
24
+ },
25
+ });
26
+
27
+ export default () => (
28
+ <PrimaryButton cs={varStyles} icon={caretDownIcon} iconPosition="end">
29
+ Overwrite styles by setting variables
30
+ </PrimaryButton>
31
+ );
@@ -0,0 +1,107 @@
1
+ import React from 'react';
2
+ import {createStyles, createModifiers, createVars, cssVar} from '@workday/canvas-kit-styling';
3
+
4
+ interface ButtonProps {
5
+ variant: 'primary' | 'secondary' | 'danger';
6
+ size: 'large' | 'medium' | 'small';
7
+ backgroundColor?: string;
8
+ children?: React.ReactNode;
9
+ }
10
+
11
+ const variables = createVars('backgroundColor');
12
+
13
+ const baseStyles = createStyles({
14
+ fontSize: '1rem',
15
+ display: 'flex',
16
+ borderRadius: '1rem',
17
+ });
18
+
19
+ const modifierStyles = createModifiers({
20
+ variant: {
21
+ primary: createStyles({
22
+ background: cssVar(variables.backgroundColor, 'blue'),
23
+ color: 'white',
24
+ }),
25
+ secondary: createStyles({
26
+ background: cssVar(variables.backgroundColor, 'gray'),
27
+ }),
28
+ danger: createStyles({
29
+ background: cssVar(variables.backgroundColor, 'red'),
30
+ }),
31
+ },
32
+ size: {
33
+ large: createStyles({
34
+ fontSize: '1.4rem',
35
+ height: '2rem',
36
+ }),
37
+ medium: createStyles({
38
+ fontSize: '1rem',
39
+ height: '1.5rem',
40
+ }),
41
+ small: createStyles({
42
+ fontSize: '0.8rem',
43
+ height: '1.2rem',
44
+ }),
45
+ },
46
+ });
47
+
48
+ const Button = ({variant, size, backgroundColor, children}: ButtonProps) => {
49
+ const className = [baseStyles, modifierStyles({variant, size})].join(' ');
50
+ const style = variables({backgroundColor});
51
+ return (
52
+ <button className={className} style={style}>
53
+ {children}
54
+ </button>
55
+ );
56
+ };
57
+
58
+ export default () => {
59
+ return (
60
+ <div style={{display: 'flex', flexDirection: 'column', gap: '1rem'}}>
61
+ <div style={{display: 'flex', gap: '1rem'}}>
62
+ <Button variant="primary" size="large">
63
+ Primary Large
64
+ </Button>
65
+ <Button variant="primary" size="medium">
66
+ Primary Medium
67
+ </Button>
68
+ <Button variant="primary" size="small">
69
+ Primary Small
70
+ </Button>
71
+ </div>
72
+ <div style={{display: 'flex', gap: '1rem'}}>
73
+ <Button variant="secondary" size="large">
74
+ Secondary Large
75
+ </Button>
76
+ <Button variant="secondary" size="medium">
77
+ Secondary Medium
78
+ </Button>
79
+ <Button variant="secondary" size="small">
80
+ Secondary Small
81
+ </Button>
82
+ </div>
83
+ <div style={{display: 'flex', gap: '1rem'}}>
84
+ <Button variant="danger" size="large">
85
+ Danger Large
86
+ </Button>
87
+ <Button variant="danger" size="medium">
88
+ Danger Medium
89
+ </Button>
90
+ <Button variant="danger" size="small">
91
+ Danger Small
92
+ </Button>
93
+ </div>
94
+ <div style={{display: 'flex', gap: '1rem'}}>
95
+ <Button variant="danger" size="large" backgroundColor="orange">
96
+ Custom Large
97
+ </Button>
98
+ <Button variant="danger" size="medium" backgroundColor="orange">
99
+ Custom Medium
100
+ </Button>
101
+ <Button variant="danger" size="small" backgroundColor="orange">
102
+ Custom Small
103
+ </Button>
104
+ </div>
105
+ </div>
106
+ );
107
+ };
@@ -0,0 +1,158 @@
1
+ import * as React from 'react';
2
+ import styled from '@emotion/styled';
3
+ import {jsx} from '@emotion/react';
4
+
5
+ import {Flex} from '@workday/canvas-kit-react/layout';
6
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
7
+ import {base} from '@workday/canvas-tokens-web';
8
+ import {createStyles, cssVar} from '@workday/canvas-kit-styling';
9
+
10
+ const backgroundColors = {
11
+ cssProp: cssVar(base.orange500),
12
+ styledComponent: cssVar(base.green500),
13
+ styleProps: cssVar(base.pink500),
14
+ createStyles: cssVar(base.purple500),
15
+ };
16
+
17
+ const StyledPrimaryButton = styled(PrimaryButton)({
18
+ backgroundColor: backgroundColors.styledComponent,
19
+ });
20
+
21
+ const styles = createStyles({
22
+ backgroundColor: backgroundColors.createStyles,
23
+ });
24
+
25
+ const CSSProp = () => (
26
+ <div
27
+ style={{
28
+ color: 'white',
29
+ padding: '0 4px',
30
+ height: 40,
31
+ width: 100,
32
+ backgroundColor: backgroundColors.cssProp,
33
+ }}
34
+ >
35
+ CSS Prop
36
+ </div>
37
+ );
38
+ const StyledComponent = () => (
39
+ <div
40
+ style={{
41
+ color: 'white',
42
+ padding: '0 4px',
43
+ height: 40,
44
+ width: 100,
45
+ backgroundColor: backgroundColors.styledComponent,
46
+ }}
47
+ >
48
+ Styled Component
49
+ </div>
50
+ );
51
+ const CreateStyles = () => (
52
+ <div
53
+ style={{
54
+ color: 'white',
55
+ padding: '0 4px',
56
+ height: 40,
57
+ width: 100,
58
+ backgroundColor: backgroundColors.createStyles,
59
+ }}
60
+ >
61
+ createStyles
62
+ </div>
63
+ );
64
+ const StyleProps = () => (
65
+ <div
66
+ style={{
67
+ color: 'white',
68
+ padding: '0 4px',
69
+ height: 40,
70
+ width: 100,
71
+ backgroundColor: backgroundColors.styleProps,
72
+ }}
73
+ >
74
+ Style Props
75
+ </div>
76
+ );
77
+
78
+ // We use this object and cast to `{}` to keep TypeScript happy. Emotion extends the JSX interface
79
+ // to include the `css` prop, but the `jsx` function type doesn't accept the `css` prop. Casting to
80
+ // an empty object keeps TypeScript happy and the `css` prop is valid at runtime.
81
+ const cssProp = {css: {backgroundColor: backgroundColors.cssProp}} as {};
82
+
83
+ export default () => {
84
+ return (
85
+ <Flex flexDirection="column" minHeight="100vh" gap="s">
86
+ <Flex flexDirection="column" gap="s">
87
+ <h2>Buttons</h2>
88
+ <Flex flexDirection="row" gap="s">
89
+ <PrimaryButton cs={styles}>createStyles</PrimaryButton>
90
+ {jsx(PrimaryButton, {...cssProp}, 'CSS Prop')}
91
+ <StyledPrimaryButton>Styled Component</StyledPrimaryButton>
92
+ <PrimaryButton backgroundColor={backgroundColors.styleProps}>Style Props</PrimaryButton>
93
+ </Flex>
94
+ <div>
95
+ {jsx(
96
+ PrimaryButton,
97
+ {
98
+ ...cssProp,
99
+ cs: styles,
100
+ },
101
+ 'createStyles + CSS Prop'
102
+ )}
103
+ </div>
104
+ <div>
105
+ <StyledPrimaryButton cs={styles}>createStyles + Styled Component</StyledPrimaryButton>
106
+ </div>
107
+ <div>
108
+ <PrimaryButton cs={styles} backgroundColor={backgroundColors.styleProps}>
109
+ createStyles + Style Props
110
+ </PrimaryButton>
111
+ </div>
112
+ <div>
113
+ <StyledPrimaryButton backgroundColor={backgroundColors.styleProps} cs={styles}>
114
+ createStyles + Styled Component + Style Props
115
+ </StyledPrimaryButton>
116
+ </div>
117
+ <div>
118
+ {jsx(
119
+ StyledPrimaryButton,
120
+ {
121
+ ...cssProp,
122
+ backgroundColor: backgroundColors.styleProps,
123
+ cs: styles,
124
+ },
125
+ 'createStyles + CSS Prop + Styled Component + Style Props'
126
+ )}
127
+ </div>
128
+ <div>{jsx(StyledPrimaryButton, {...cssProp}, 'CSS Prop + Styled Component')}</div>
129
+ <div>
130
+ {jsx(
131
+ PrimaryButton,
132
+ {
133
+ ...cssProp,
134
+ backgroundColor: backgroundColors.styleProps,
135
+ },
136
+ 'CSS Prop + Style Props'
137
+ )}
138
+ </div>
139
+ <div>
140
+ <StyledPrimaryButton backgroundColor={backgroundColors.styleProps}>
141
+ Styled Component + Style Props
142
+ </StyledPrimaryButton>
143
+ </div>
144
+ </Flex>
145
+ <div>
146
+ <p>Legend:</p>
147
+ <CreateStyles />
148
+ <CSSProp />
149
+ <StyledComponent />
150
+ <StyleProps />
151
+ </div>
152
+ <p>
153
+ Style Precedence: <strong>createStyles</strong> &gt; <strong>CSS Props</strong> &gt;{' '}
154
+ <strong>Styled Component</strong> &gt; <strong>Style Props</strong>
155
+ </p>
156
+ </Flex>
157
+ );
158
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "14.0.0-alpha.1149-next.0",
3
+ "version": "14.0.0-alpha.1151-next.0",
4
4
  "description": "Documentation components of Canvas Kit components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -45,10 +45,10 @@
45
45
  "@emotion/styled": "^11.6.0",
46
46
  "@stackblitz/sdk": "^1.11.0",
47
47
  "@storybook/csf": "0.0.1",
48
- "@workday/canvas-kit-labs-react": "^14.0.0-alpha.1149-next.0",
49
- "@workday/canvas-kit-preview-react": "^14.0.0-alpha.1149-next.0",
50
- "@workday/canvas-kit-react": "^14.0.0-alpha.1149-next.0",
51
- "@workday/canvas-kit-styling": "^14.0.0-alpha.1149-next.0",
48
+ "@workday/canvas-kit-labs-react": "^14.0.0-alpha.1151-next.0",
49
+ "@workday/canvas-kit-preview-react": "^14.0.0-alpha.1151-next.0",
50
+ "@workday/canvas-kit-react": "^14.0.0-alpha.1151-next.0",
51
+ "@workday/canvas-kit-styling": "^14.0.0-alpha.1151-next.0",
52
52
  "@workday/canvas-system-icons-web": "^3.0.0",
53
53
  "@workday/canvas-tokens-web": "3.0.0-alpha.5",
54
54
  "markdown-to-jsx": "^7.2.0",
@@ -61,5 +61,5 @@
61
61
  "mkdirp": "^1.0.3",
62
62
  "typescript": "5.0"
63
63
  },
64
- "gitHead": "ef6d229e302c293a16da98a7b36b1409877a1ac8"
64
+ "gitHead": "891b0d79a8054c5cd3799eb8dd2e0c3b0f15a47b"
65
65
  }