@workday/canvas-kit-docs 14.0.0-alpha.1165-next.0 → 14.0.0-alpha.1168-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.
- package/dist/es6/index.d.ts +1 -1
- package/dist/es6/index.d.ts.map +1 -1
- package/dist/es6/index.js +1 -1
- package/dist/es6/lib/StorybookStatusIndicator.d.ts +4 -0
- package/dist/es6/lib/StorybookStatusIndicator.d.ts.map +1 -0
- package/dist/es6/lib/StorybookStatusIndicator.js +39 -0
- package/dist/es6/lib/docs.js +607 -5
- package/dist/es6/lib/stackblitzFiles/packageJSONFile.js +5 -5
- package/dist/es6/lib/stackblitzFiles/packageJSONFile.ts +5 -5
- package/dist/mdx/preview-react/select/Select.mdx +20 -2
- package/dist/mdx/preview-react/text-area/TextArea.mdx +18 -9
- package/dist/mdx/preview-react/text-input/TextInput.mdx +19 -10
- package/dist/mdx/react/status-indicator/StatusIndicator.mdx +13 -12
- package/dist/mdx/react/text/LabelText.mdx +14 -11
- package/dist/mdx/react/tokens/Tokens.mdx +4 -3
- package/dist/mdx/styling/mdx/Overview.mdx +202 -55
- package/dist/mdx/tokens/TokenMigrationOverview.mdx +3 -4
- package/index.ts +1 -1
- package/lib/StorybookStatusIndicator.tsx +49 -0
- package/package.json +6 -6
- package/dist/es6/lib/AIIndicator.d.ts +0 -2
- package/dist/es6/lib/AIIndicator.d.ts.map +0 -1
- package/dist/es6/lib/AIIndicator.js +0 -12
- package/lib/AIIndicator.tsx +0 -22
|
@@ -18,11 +18,11 @@ export const packageJSONFile = `{
|
|
|
18
18
|
"@emotion/react": "11.11.4",
|
|
19
19
|
"@types/react": "18.2.60",
|
|
20
20
|
"@types/react-dom": "18.2.19",
|
|
21
|
-
"@workday/canvas-kit-labs-react": "13.2.
|
|
22
|
-
"@workday/canvas-kit-preview-react": "13.2.
|
|
23
|
-
"@workday/canvas-kit-react": "13.2.
|
|
24
|
-
"@workday/canvas-kit-react-fonts": "^13.2.
|
|
25
|
-
"@workday/canvas-kit-styling": "13.2.
|
|
21
|
+
"@workday/canvas-kit-labs-react": "13.2.2",
|
|
22
|
+
"@workday/canvas-kit-preview-react": "13.2.2",
|
|
23
|
+
"@workday/canvas-kit-react": "13.2.2",
|
|
24
|
+
"@workday/canvas-kit-react-fonts": "^13.2.2",
|
|
25
|
+
"@workday/canvas-kit-styling": "13.2.2",
|
|
26
26
|
"@workday/canvas-system-icons-web": "3.0.22",
|
|
27
27
|
"@workday/canvas-tokens-web": "2.0.0"
|
|
28
28
|
},
|
|
@@ -18,11 +18,11 @@ export const packageJSONFile = `{
|
|
|
18
18
|
"@emotion/react": "11.11.4",
|
|
19
19
|
"@types/react": "18.2.60",
|
|
20
20
|
"@types/react-dom": "18.2.19",
|
|
21
|
-
"@workday/canvas-kit-labs-react": "13.2.
|
|
22
|
-
"@workday/canvas-kit-preview-react": "13.2.
|
|
23
|
-
"@workday/canvas-kit-react": "13.2.
|
|
24
|
-
"@workday/canvas-kit-react-fonts": "^13.2.
|
|
25
|
-
"@workday/canvas-kit-styling": "13.2.
|
|
21
|
+
"@workday/canvas-kit-labs-react": "13.2.2",
|
|
22
|
+
"@workday/canvas-kit-preview-react": "13.2.2",
|
|
23
|
+
"@workday/canvas-kit-react": "13.2.2",
|
|
24
|
+
"@workday/canvas-kit-react-fonts": "^13.2.2",
|
|
25
|
+
"@workday/canvas-kit-styling": "13.2.2",
|
|
26
26
|
"@workday/canvas-system-icons-web": "3.0.22",
|
|
27
27
|
"@workday/canvas-tokens-web": "2.0.0"
|
|
28
28
|
},
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ExampleCodeBlock,
|
|
3
|
+
StorybookStatusIndicator,
|
|
4
|
+
SymbolDoc,
|
|
5
|
+
Specifications,
|
|
6
|
+
} from '@workday/canvas-kit-docs';
|
|
7
|
+
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
2
8
|
import Default from './examples/Top Label/Default';
|
|
3
9
|
import DefaultWithCustomOptions from './examples/Top Label/DefaultWithCustomOptions';
|
|
4
10
|
import DefaultWithSimpleOptions from './examples/Top Label/DefaultWithSimpleOptions';
|
|
@@ -17,8 +23,20 @@ import ErrorLeft from './examples/Left Label/ErrorLeft';
|
|
|
17
23
|
import GrowLeft from './examples/Left Label/GrowLeft';
|
|
18
24
|
|
|
19
25
|
|
|
26
|
+
# Canvas Kit Select <StorybookStatusIndicator type="deprecated" />
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
<InformationHighlight className="sb-unstyled" variant="caution" cs={{p: {marginBlock: 0}}}>
|
|
29
|
+
<InformationHighlight.Icon />
|
|
30
|
+
<InformationHighlight.Body>
|
|
31
|
+
`Select` in Preview has been deprecated and will be removed in a future major version. Please
|
|
32
|
+
use `Select` in Main instead.
|
|
33
|
+
</InformationHighlight.Body>
|
|
34
|
+
<InformationHighlight.Link href="https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs">
|
|
35
|
+
Form Field Docs
|
|
36
|
+
</InformationHighlight.Link>
|
|
37
|
+
</InformationHighlight>
|
|
38
|
+
|
|
39
|
+
<br />
|
|
22
40
|
|
|
23
41
|
## Top Label
|
|
24
42
|
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ExampleCodeBlock,
|
|
3
|
+
StorybookStatusIndicator,
|
|
4
|
+
SymbolDoc,
|
|
5
|
+
Specifications,
|
|
6
|
+
} from '@workday/canvas-kit-docs';
|
|
7
|
+
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
2
8
|
|
|
3
9
|
import Alert from './examples/Alert';
|
|
4
10
|
import Basic from './examples/Basic';
|
|
@@ -14,15 +20,18 @@ import Required from './examples/Required';
|
|
|
14
20
|
import ResizeConstraints from './examples/ResizeConstraints';
|
|
15
21
|
|
|
16
22
|
|
|
17
|
-
# Canvas Kit Text Area
|
|
23
|
+
# Canvas Kit Text Area <StorybookStatusIndicator type="deprecated" />
|
|
18
24
|
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
<InformationHighlight className="sb-unstyled" variant="caution" cs={{p: {marginBlock: 0}}}>
|
|
26
|
+
<InformationHighlight.Icon />
|
|
27
|
+
<InformationHighlight.Body>
|
|
28
|
+
`TextArea` in Preview has been deprecated and will be removed in a future major version. Please
|
|
29
|
+
use `FormField` instead.
|
|
30
|
+
</InformationHighlight.Body>
|
|
31
|
+
<InformationHighlight.Link href="https://workday.github.io/canvas-kit/?path=/story/components-inputs-form-field--docs">
|
|
32
|
+
Form Field Docs
|
|
33
|
+
</InformationHighlight.Link>
|
|
34
|
+
</InformationHighlight>
|
|
26
35
|
|
|
27
36
|
TextArea's allow users to enter and edit multiple lines of text.
|
|
28
37
|
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ExampleCodeBlock,
|
|
3
|
+
StorybookStatusIndicator,
|
|
4
|
+
SymbolDoc,
|
|
5
|
+
Specifications,
|
|
6
|
+
} from '@workday/canvas-kit-docs';
|
|
7
|
+
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
2
8
|
|
|
3
9
|
import Basic from './examples/Basic';
|
|
4
10
|
import Disabled from './examples/Disabled';
|
|
@@ -18,15 +24,18 @@ import Error from './examples/Error';
|
|
|
18
24
|
import Alert from './examples/Alert';
|
|
19
25
|
|
|
20
26
|
|
|
21
|
-
# Canvas Kit Text Input
|
|
27
|
+
# Canvas Kit Text Input <StorybookStatusIndicator type="deprecated" />
|
|
22
28
|
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
<InformationHighlight className="sb-unstyled" variant="caution" cs={{p: {marginBlock: 0}}}>
|
|
30
|
+
<InformationHighlight.Icon />
|
|
31
|
+
<InformationHighlight.Body>
|
|
32
|
+
`TextInput` in Preview has been deprecated and will be removed in a future major version. Please
|
|
33
|
+
use `FormField` instead.
|
|
34
|
+
</InformationHighlight.Body>
|
|
35
|
+
<InformationHighlight.Link href="https://workday.github.io/canvas-kit/?path=/story/components-inputs-form-field--docs">
|
|
36
|
+
Form Field Docs
|
|
37
|
+
</InformationHighlight.Link>
|
|
38
|
+
</InformationHighlight>
|
|
30
39
|
|
|
31
40
|
Text Inputs allow users to enter words or characters without styling.
|
|
32
41
|
|
|
@@ -78,7 +87,7 @@ Set `TextInput.Field`'s `type` prop to `hidden` to completly hide a field while
|
|
|
78
87
|
value, often used for things like security tokens. Note: You will likely need to manually
|
|
79
88
|
set`aria-describedby={undefined}`and`id={undefined}`
|
|
80
89
|
|
|
81
|
-
<ExampleCodeBlock code={
|
|
90
|
+
<ExampleCodeBlock code={Hidden} />
|
|
82
91
|
|
|
83
92
|
### Ref Forwarding
|
|
84
93
|
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {ExampleCodeBlock, SymbolDoc} from '@workday/canvas-kit-docs';
|
|
2
|
-
import {
|
|
1
|
+
import {ExampleCodeBlock, StorybookStatusIndicator, SymbolDoc} from '@workday/canvas-kit-docs';
|
|
2
|
+
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
3
3
|
|
|
4
4
|
import Basic from './examples/Basic';
|
|
5
5
|
import Icon from './examples/Icon';
|
|
6
6
|
import Emphasis from './examples/Emphasis';
|
|
7
7
|
import MaxWidth from './examples/MaxWidth';
|
|
8
8
|
|
|
9
|
-
# Canvas Kit Status Indicator
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
# Canvas Kit Status Indicator <StorybookStatusIndicator type="deprecated" />
|
|
10
|
+
|
|
11
|
+
<InformationHighlight className="sb-unstyled" variant="caution" cs={{p: {marginBlock: 0}}}>
|
|
12
|
+
<InformationHighlight.Icon />
|
|
13
|
+
<InformationHighlight.Body>
|
|
14
|
+
`StatusIndicator` in Main has been deprecated and will be removed in a future major version.
|
|
15
|
+
Please use [Status
|
|
16
|
+
Indicator](https://workday.github.io/canvas-kit/?path=/docs/preview-status-indicator--basic) in
|
|
17
|
+
Preview instead.
|
|
18
|
+
</InformationHighlight.Body>
|
|
19
|
+
</InformationHighlight>
|
|
19
20
|
|
|
20
21
|
Status Indicators help the user quickly identify the status of a task, action, or page element.
|
|
21
22
|
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {ExampleCodeBlock, SymbolDoc} from '@workday/canvas-kit-docs';
|
|
2
|
-
import {
|
|
1
|
+
import {ExampleCodeBlock, StorybookStatusIndicator, SymbolDoc} from '@workday/canvas-kit-docs';
|
|
2
|
+
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
3
3
|
import Basic from './examples/LabelText/Basic';
|
|
4
4
|
import Cursor from './examples/LabelText/Cursor';
|
|
5
5
|
import Disabled from './examples/LabelText/Disabled';
|
|
6
6
|
|
|
7
|
-
# Canvas Kit Label Text
|
|
8
|
-
|
|
9
|
-
<
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
# Canvas Kit Label Text <StorybookStatusIndicator type="deprecated" />
|
|
8
|
+
|
|
9
|
+
<InformationHighlight className="sb-unstyled" variant="caution" cs={{p: {marginBlock: 0}}}>
|
|
10
|
+
<InformationHighlight.Icon />
|
|
11
|
+
<InformationHighlight.Body>
|
|
12
|
+
`LabelText` has been deprecated and will be removed in a future major version. Please use
|
|
13
|
+
`FormField.Label` instead.
|
|
14
|
+
</InformationHighlight.Body>
|
|
15
|
+
<InformationHighlight.Link href="https://workday.github.io/canvas-kit/?path=/story/components-inputs-form-field--docs">
|
|
16
|
+
Form Field Docs
|
|
17
|
+
</InformationHighlight.Link>
|
|
18
|
+
</InformationHighlight>
|
|
16
19
|
|
|
17
20
|
`LabelText` provides a simple way to render a label with built-in support for Canvas type tokens.
|
|
18
21
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {ExampleCodeBlock} from '@workday/canvas-kit-docs';
|
|
1
|
+
import {ExampleCodeBlock, StorybookStatusIndicator} from '@workday/canvas-kit-docs';
|
|
2
2
|
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';import {BorderRadius, Space, Depth, Colors, Type} from './examples/Tokens';
|
|
3
3
|
import Overview from './examples/Overview';
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
# Tokens
|
|
6
|
+
# Tokens <StorybookStatusIndicator type="deprecated" />
|
|
7
7
|
|
|
8
8
|
<InformationHighlight variant="caution" className="sb-unstyled" cs={{p: {margin: 0}}}>
|
|
9
9
|
<InformationHighlight.Icon />
|
|
10
|
-
<InformationHighlight.Heading>React tokens have been deprecated!</InformationHighlight.Heading>
|
|
11
10
|
<InformationHighlight.Body>
|
|
12
11
|
The tokens documented below are deprecated and will be removed in a future release. You must
|
|
13
12
|
migrate to the new Canvas Tokens Web package to ensure continued support and access to the
|
|
@@ -23,6 +22,8 @@ information. They enable building components and patterns with consistency acros
|
|
|
23
22
|
|
|
24
23
|
<ExampleCodeBlock code={Overview} />
|
|
25
24
|
|
|
25
|
+
<br />
|
|
26
|
+
|
|
26
27
|
## Border Radius
|
|
27
28
|
|
|
28
29
|
### Usage
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
2
2
|
import {Hyperlink} from '@workday/canvas-kit-react/button';
|
|
3
|
-
import {system} from '@workday/canvas-tokens-web'
|
|
3
|
+
import {system} from '@workday/canvas-tokens-web';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
# Canvas Kit Styling
|
|
@@ -27,7 +27,8 @@ The Canvas Kit styling system consists of two main packages:
|
|
|
27
27
|
- `@workday/canvas-kit-styling` - Core styling utilities for runtime use
|
|
28
28
|
- `@workday/canvas-kit-styling-transform` - Build-time optimization tools
|
|
29
29
|
|
|
30
|
-
These packages work together to provide a CSS-in-JS experience during development while enabling
|
|
30
|
+
These packages work together to provide a CSS-in-JS experience during development while enabling
|
|
31
|
+
optimized static CSS in production.
|
|
31
32
|
|
|
32
33
|
## Installation
|
|
33
34
|
|
|
@@ -55,74 +56,219 @@ const root = createRoot(domNode);
|
|
|
55
56
|
root.render(<div className={myStyles}>Hello!</div>);
|
|
56
57
|
```
|
|
57
58
|
|
|
59
|
+
## Style Merging
|
|
60
|
+
|
|
61
|
+
The `@workday/canvas-kit-styling` package uses `@emotion/css` to inject styles during JavaScript
|
|
62
|
+
evaluation time rather than `@emotion/react` or `@emotion/styled` injecting when a component is
|
|
63
|
+
rendered. This means the Emotion cache needs to be known before any style is created. In order to
|
|
64
|
+
properly merge styles with components using either dynamic styling package, the Emotion cache must
|
|
65
|
+
be changed on any React application. Without this, styles will not be merged correctly when static
|
|
66
|
+
and dynamic styles are used on the same element.
|
|
67
|
+
|
|
68
|
+
If you're using Canvas Kit React, you should use the `<CanvasProvider>` which includes Emotion's
|
|
69
|
+
`<CacheProvider>` with the proper cache already set. If you're not using Canvas Kit React, you
|
|
70
|
+
should use the `<CacheProvider>`:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// ONLY use if not using the <CanvasProvider>
|
|
74
|
+
import {getCache} from '@workday/canvas-kit-styling';
|
|
75
|
+
|
|
76
|
+
// in your application bootstrap
|
|
77
|
+
const root = React.createRoot(document.getElementById('root'));
|
|
78
|
+
|
|
79
|
+
root.render(
|
|
80
|
+
<CacheProvider value={getCache()}>
|
|
81
|
+
<App />
|
|
82
|
+
</CacheProvider>
|
|
83
|
+
);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Known issues
|
|
87
|
+
|
|
88
|
+
### Hot Reloading
|
|
89
|
+
|
|
90
|
+
Style merging works by using CSS specificity rather than JavaScript runtime. This can cause problems
|
|
91
|
+
during hot reloading. If you specify all styles in the same file, hot reloading shouldn't result in
|
|
92
|
+
any style merging problems. But if you use `extends` in `createStencil` that references another
|
|
93
|
+
file, you may run into style merge issues.
|
|
94
|
+
|
|
95
|
+
For example:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
// base.tsx file
|
|
99
|
+
export const baseStencil = createStencil({
|
|
100
|
+
base: {
|
|
101
|
+
color: 'red',
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// extended.tsx file
|
|
106
|
+
import {baseStencil} from './base';
|
|
107
|
+
|
|
108
|
+
export const extendedStencil = createStencil({
|
|
109
|
+
extends: baseStencil,
|
|
110
|
+
base: {
|
|
111
|
+
color: 'blue',
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
This will render correctly until you change `color` in `base.tsx` and get a hot reload:
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
// base.tsx file
|
|
120
|
+
export const baseStencil = createStencil({
|
|
121
|
+
base: {
|
|
122
|
+
color: 'purple',
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The hot reload will evaluate this update and inject a new style.
|
|
128
|
+
|
|
58
129
|
## Development
|
|
59
130
|
|
|
60
|
-
Canvas Kit Styling comes with a runtime that doesn't need anything special for
|
|
61
|
-
runtime uses `@emotion/css` to include your styles on the page.
|
|
131
|
+
Canvas Kit Styling comes with a runtime that doesn't need anything special for development. The
|
|
132
|
+
runtime uses `@emotion/css` to include your styles on the page. If you plan to use static
|
|
133
|
+
compilation, we recommend enabling in production as well so you can fix static compilation errors as
|
|
134
|
+
you develop rather than get errors only in production builds.
|
|
62
135
|
|
|
63
|
-
##
|
|
136
|
+
## Static compilation
|
|
64
137
|
|
|
65
|
-
|
|
66
|
-
|
|
138
|
+
The `@workday/canvas-kit-styling-transform` package can to pre-build styles. This process takes
|
|
139
|
+
style objects and turns them into CSS strings. This process moves serialization and hashing to build
|
|
140
|
+
time rather than browser runtime when `@emotion/css` is processing styles. This will speed up
|
|
141
|
+
production builds at runtime.
|
|
67
142
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
143
|
+
Static compilation has stricter requirements than when doing runtime styling. The static compiler
|
|
144
|
+
uses the TypeScript type system to statically analyze style values and thus requires value types to
|
|
145
|
+
be known by TypeScript. See [Restrictions](#restrictions).
|
|
146
|
+
|
|
147
|
+
Static compilation may be required for server side rendering (SSR), especially when using React
|
|
148
|
+
Server Components.
|
|
149
|
+
|
|
150
|
+
### Hash generation
|
|
151
|
+
|
|
152
|
+
Emotion generates hashes based on the serialized style object. This means a style should always give
|
|
153
|
+
the same hash. Static styling hashes differently. Every `createStyles` or `createStencil` call will
|
|
154
|
+
generate a unique hash even if the style object is the same. This is required for proper style
|
|
155
|
+
merging because static styling doesn't give single class names, but rather merges styles using CSS
|
|
156
|
+
specificity.
|
|
157
|
+
|
|
158
|
+
For runtime development, the hash is always unique. For static compilation, the hash is based on the
|
|
159
|
+
start and end character count in the source file of the style block. This is required for SSR so
|
|
160
|
+
that the server and client agree on the same value during hydration. This means that while
|
|
161
|
+
debugging, the hash depends on any code before it. If you add a `console.log` for example, the
|
|
162
|
+
character index of a style block could shift which will generate a new hash.
|
|
163
|
+
|
|
164
|
+
### Restrictions
|
|
165
|
+
|
|
166
|
+
The static compiler uses the TypeScript type checker. The easiest way to think of these restrictions
|
|
167
|
+
is if TypeScript knows the exact value, the static compiler will also know. A simple example:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
// won't work - `value` is a type of `string` because `let` allows a value to be mutated
|
|
171
|
+
let value = 'absolute'; // `string`
|
|
172
|
+
|
|
173
|
+
const myStyles = createStyles({
|
|
174
|
+
position: value, // error - `string` isn't specific enough.
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// will work - `value` is a type of `'absolute'` because `const` restricts to a string literal
|
|
178
|
+
const value = 'absolute'; // `'absolute'`
|
|
179
|
+
|
|
180
|
+
const myStyles = createStyles({
|
|
181
|
+
position: value, // works. If you mouse over `value` in your editor, you'll see the type is `'absolute'`
|
|
182
|
+
});
|
|
81
183
|
```
|
|
82
184
|
|
|
83
|
-
|
|
84
|
-
[ts-patch](https://www.npmjs.com/package/ts-patch) projects uses the `plugins` when running
|
|
85
|
-
transforms.
|
|
185
|
+
More complex examples may be objects:
|
|
86
186
|
|
|
87
|
-
|
|
187
|
+
```ts
|
|
188
|
+
// won't work. TypeScript will not understand that the position will only be `'absolute'` and makes it a `string` instead
|
|
189
|
+
const reusableStyles = {
|
|
190
|
+
position: 'absolute',
|
|
191
|
+
}; // `{ position: string }`
|
|
88
192
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
to transform code during compilation.
|
|
193
|
+
const myStyles = createStyles({
|
|
194
|
+
...reusableStyles, // error - `position` is a `string` and not specific enough
|
|
195
|
+
});
|
|
93
196
|
|
|
94
|
-
|
|
197
|
+
// will work. Adding `as const` tells TypeScript the object is readonly and therefore no values can change
|
|
198
|
+
const reusableStyles = {
|
|
199
|
+
position: 'absolute',
|
|
200
|
+
} as const; // `{ readonly position: 'absolute' }`
|
|
201
|
+
|
|
202
|
+
const myStyles = createStyles({
|
|
203
|
+
...reusableStyles, // works. If you mouse over, the position is a string literal `'absolute'`
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Functions are a little more tricky and may require generics.
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
// generic makes the type be statically knowable
|
|
211
|
+
function getPosition<V extends 'relative' | 'absolute'>(value: V): {position: V} {
|
|
212
|
+
return {position: value};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// mouse over `position` in your editor an the type will be `{ position: 'absolute' }`
|
|
216
|
+
const position = getPosition('absolute'); // { position: 'absolute' }
|
|
217
|
+
|
|
218
|
+
const myStyles = createStyles({
|
|
219
|
+
...getPosition('absolute'), // works - `{ position: 'absolute' }`
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Webpack
|
|
224
|
+
|
|
225
|
+
The `@webpack/canvas-kit-styling-transform` package comes with a webpack loader that can be added to
|
|
226
|
+
development and/or production.
|
|
95
227
|
|
|
96
228
|
```js
|
|
229
|
+
// import the transform - CJS and ESM are supported
|
|
230
|
+
import {StylingWebpackPlugin} from '@workday/canvas-kit-styling-transform';
|
|
231
|
+
|
|
232
|
+
// somewhere only once. For static webpack config files, this can be near the top.
|
|
233
|
+
// If inside Storybook, Gatsby, Next.js, etc configs, put inside the function that is called that
|
|
234
|
+
// returns a webpack config
|
|
235
|
+
const tsPlugin = const tsPlugin = new StylingWebpackPlugin({
|
|
236
|
+
tsconfigPath: path.resolve(__dirname, '../tsconfig.json'), // allows your TS config to be used
|
|
237
|
+
// A different tsconfig could be used if you want to use TS to transpile to something like ES2019 and
|
|
238
|
+
// also have Babel process the file.
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// However you need to define rules.
|
|
242
|
+
// This is different for using webpack directly or in Storybook/Gatsby/Next.js/etc
|
|
97
243
|
{
|
|
98
244
|
rules: [
|
|
99
245
|
//...
|
|
100
246
|
{
|
|
101
247
|
test: /.\.tsx?$/,
|
|
102
|
-
|
|
103
|
-
// ts-loader
|
|
248
|
+
use: [
|
|
104
249
|
{
|
|
105
|
-
loader: require.resolve('
|
|
106
|
-
options:
|
|
107
|
-
compiler: 'ts-patch/compiler',
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
// OR awesome-typescript-loader
|
|
111
|
-
{
|
|
112
|
-
loader: require.resolve('awesome-typescript-loader'),
|
|
250
|
+
loader: require.resolve('@workday/canvas-kit-styling-transform/webpack-loader'),
|
|
251
|
+
options: tsPlugin.getLoaderOptions(),
|
|
113
252
|
},
|
|
114
253
|
],
|
|
254
|
+
enforce: 'pre'
|
|
115
255
|
},
|
|
116
256
|
];
|
|
257
|
+
// We need to pass the plugin to Webpack's plugin list. Failure to do this will result in a
|
|
258
|
+
// production build hanging
|
|
259
|
+
plugins: [tsPlugin]
|
|
117
260
|
}
|
|
118
261
|
```
|
|
119
262
|
|
|
120
263
|
## Core Styling Approaches for Static Styling
|
|
264
|
+
|
|
121
265
|
For proper static styling there's two methods that you can use to apply styles.
|
|
266
|
+
|
|
122
267
|
1. Using `createStyles` for simple object base styles.
|
|
123
268
|
2. Using `createStencil` for dynamic styles and reusable components.
|
|
124
269
|
|
|
125
|
-
Both approaches are intended to be used in tandem with the `cs` prop when applying styles to our
|
|
270
|
+
Both approaches are intended to be used in tandem with the `cs` prop when applying styles to our
|
|
271
|
+
components.
|
|
126
272
|
|
|
127
273
|
### `cs` Prop
|
|
128
274
|
|
|
@@ -132,7 +278,8 @@ everything together and applies `className` and `style` attributes to a React el
|
|
|
132
278
|
components extend the `cs` prop so that you can statically apply styles to them.
|
|
133
279
|
|
|
134
280
|
> **Important**: While the `cs` prop accepts a style object, **this will not** be considered
|
|
135
|
-
> statically styling an element and you will lose the performance benefits. We plan on providing a
|
|
281
|
+
> statically styling an element and you will lose the performance benefits. We plan on providing a
|
|
282
|
+
> babel plugin to extract these styles statically in a future version.
|
|
136
283
|
|
|
137
284
|
```tsx
|
|
138
285
|
import {system} from '@workday/canvas-tokens-webs';
|
|
@@ -172,15 +319,15 @@ function MyComponent() {
|
|
|
172
319
|
}
|
|
173
320
|
```
|
|
174
321
|
|
|
175
|
-
Most of our components support using the `cs` prop to apply the static styles. It merges
|
|
176
|
-
|
|
322
|
+
Most of our components support using the `cs` prop to apply the static styles. It merges everything
|
|
323
|
+
together and applies `className` and `style` attributes to a React element.
|
|
177
324
|
|
|
178
|
-
<InformationHighlight className="sb-unstyled" cs={{marginBlock: system.space.x4
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
325
|
+
<InformationHighlight className="sb-unstyled" cs={{marginBlock: system.space.x4}}>
|
|
326
|
+
<InformationHighlight.Icon />
|
|
327
|
+
<InformationHighlight.Heading>Information</InformationHighlight.Heading>
|
|
328
|
+
<InformationHighlight.Body>
|
|
329
|
+
For a more in depth overview, please view our <Hyperlink src="https://workday.github.io/canvas-kit/?path=/docs/styling-getting-started-create-styles--docs"> Create Styles </Hyperlink> docs.
|
|
330
|
+
</InformationHighlight.Body>
|
|
184
331
|
</InformationHighlight>
|
|
185
332
|
|
|
186
333
|
### `createStencil`
|
|
@@ -245,10 +392,10 @@ const ThemedCard = ({isDarkTheme, headerColor, elemProps}) => {
|
|
|
245
392
|
};
|
|
246
393
|
```
|
|
247
394
|
|
|
248
|
-
<InformationHighlight className="sb-unstyled" cs={{marginBlock: system.space.x4
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
395
|
+
<InformationHighlight className="sb-unstyled" cs={{marginBlock: system.space.x4}}>
|
|
396
|
+
<InformationHighlight.Icon />
|
|
397
|
+
<InformationHighlight.Heading>Information</InformationHighlight.Heading>
|
|
398
|
+
<InformationHighlight.Body>
|
|
399
|
+
For a more in depth overview, please view our <Hyperlink src="https://workday.github.io/canvas-kit/?path=/docs/styling-getting-started-stencils--docs">Create Stencil</Hyperlink> docs.
|
|
400
|
+
</InformationHighlight.Body>
|
|
254
401
|
</InformationHighlight>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {StorybookStatusIndicator, DownloadLLMFile} from '@workday/canvas-kit-docs';
|
|
2
2
|
import {StorybookInformationHighlight} from './StorybookInformationHighlight';
|
|
3
3
|
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ Canvas Kit v10+ introduces a new token system that replaces the old JavaScript-b
|
|
|
15
15
|
Android
|
|
16
16
|
- **Future-Proofing**: Aligns with modern CSS capabilities and Canvas Kit's long-term direction
|
|
17
17
|
|
|
18
|
-
## LLM Assisted Migration <
|
|
18
|
+
## LLM Assisted Migration <StorybookStatusIndicator type="ai" />
|
|
19
19
|
|
|
20
20
|
We provide a **LLM migration mapping file** (`llm-token-migration.txt`) specifically designed for
|
|
21
21
|
use with LLM-based code assistants (such as [Cursor](https://www.cursor.so/) or similar tools). This
|
|
@@ -23,8 +23,7 @@ file is not intended for direct human reference or team documentation, but rathe
|
|
|
23
23
|
input for LLMs to automate and assist with your token migration process.
|
|
24
24
|
|
|
25
25
|
> The LLM migration file is regularly updated to reflect the latest token mappings and best
|
|
26
|
-
> practices.
|
|
27
|
-
> For more details, see other sections of this migration guide.
|
|
26
|
+
> practices. For more details, see other sections of this migration guide.
|
|
28
27
|
|
|
29
28
|
This file contains a comprehensive mapping of old Canvas Kit token usages to their new equivalents
|
|
30
29
|
in `@workday/canvas-tokens-web`, along with migration tips and examples and formatted for optimal
|
package/index.ts
CHANGED