@workday/canvas-kit-docs 14.0.0-alpha.1251-next.0 → 14.0.0-alpha.1253-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/lib/docs.js +198 -21
- package/dist/es6/mdx/welcomePage.d.ts.map +1 -1
- package/dist/es6/mdx/welcomePage.js +10 -5
- package/dist/mdx/14.0-UPGRADE-GUIDE.mdx +169 -100
- package/dist/mdx/14.0-VISUAL-CHANGES.mdx +44 -0
- package/dist/mdx/react/common/mdx/Theming.mdx +417 -0
- package/dist/mdx/react/common/mdx/examples/RTL.tsx +54 -0
- package/dist/mdx/react/common/mdx/examples/Theming.tsx +34 -0
- package/dist/mdx/welcome.mdx +2 -13
- package/package.json +6 -6
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import {ExampleCodeBlock} from '@workday/canvas-kit-docs';
|
|
2
|
+
import RTL from './examples/RTL';
|
|
3
|
+
import Theming from './examples/Theming';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# Canvas Kit Theming Guide
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Canvas Kit v14 introduces a significant shift in our approach to theming: we've moved away from JavaScript-based theme objects to CSS variables. This change provides better performance, improved developer experience, and greater flexibility for theming applications.
|
|
11
|
+
|
|
12
|
+
## Migration from v10 Theme Prop to v14 CSS Variables
|
|
13
|
+
|
|
14
|
+
### The Evolution
|
|
15
|
+
|
|
16
|
+
**Canvas Kit v10** introduced CSS tokens through the `@workday/canvas-tokens-web` package, providing a foundation for consistent design system values.
|
|
17
|
+
|
|
18
|
+
**Canvas Kit v14** Removes the cascade barrier created by the `CanvasProvider`, allowing CSS variables to work as intended.
|
|
19
|
+
|
|
20
|
+
## Old Approach (v10-v13)
|
|
21
|
+
|
|
22
|
+
The old theming approach used JavaScript objects passed to the `CanvasProvider` theme prop:
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import {CanvasProvider} from "@workday/canvas-kit-react/common"
|
|
26
|
+
import {base} from "@workday/canvas-tokens-web"
|
|
27
|
+
|
|
28
|
+
<CanvasProvider theme={{canvas: {palette: {primary: {main: 'purple'}}}}}>
|
|
29
|
+
<App/>
|
|
30
|
+
</CanvasProvider>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This would use `chroma.js` to generate a palette based on the `main` color provided.
|
|
34
|
+
|
|
35
|
+
**Why we're moving away from this approach:**
|
|
36
|
+
- Performance overhead from JavaScript theme object processing
|
|
37
|
+
- Limited flexibility for complex theming scenarios
|
|
38
|
+
- Inconsistent cascade behavior
|
|
39
|
+
|
|
40
|
+
Any time `theme` is passed, the `CanvasProvider` would generate a palette and attach brand variables via a `className` scoping those brand variables to a wrapping div.
|
|
41
|
+
In order for us to provide a better solution to theming that is scalable and is more aligned with our CSS variables, we changed this approach.
|
|
42
|
+
|
|
43
|
+
## What is a Cascade Barrier?
|
|
44
|
+
|
|
45
|
+
When we say "cascade barrier", we're talking about how [CSS cascades](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascade/Cascade) and takes precedence. Take the following example:
|
|
46
|
+
|
|
47
|
+
```css
|
|
48
|
+
:root {
|
|
49
|
+
--cnbvs-brand-primary-base: blue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// the element with the class .my-app will have a higher specificity than root, creating a barrier where the CSS variables gets redefined and takes precedence over what is defined at root.
|
|
53
|
+
.my-app {
|
|
54
|
+
--cnvs-brand-primary-base: red;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
In the case of the `CanvasProvider` prior to v14, all our brand tokens where defined within a class and scoped to the `div` that the `CanvasProvider` created. This meant that anything set on `:root` or outside of the `CanvasProvider` would not be able to cascade down to the components within the `CanvasProvider`.
|
|
58
|
+
|
|
59
|
+
## ✅ Preferred Approach (v14+)
|
|
60
|
+
|
|
61
|
+
Canvas Kit v14 promotes using CSS variables for theming, which can be applied in two ways:
|
|
62
|
+
|
|
63
|
+
### Method 1: Global CSS Variables (Recommended)
|
|
64
|
+
|
|
65
|
+
Apply theming at the global level by importing CSS variable files and overriding values in your root CSS:
|
|
66
|
+
|
|
67
|
+
```css
|
|
68
|
+
/* index.css */
|
|
69
|
+
@import '@workday/canvas-tokens-web/css/base/_variables.css';
|
|
70
|
+
@import '@workday/canvas-tokens-web/css/system/_variables.css';
|
|
71
|
+
@import '@workday/canvas-tokens-web/css/brand/_variables.css';
|
|
72
|
+
|
|
73
|
+
:root {
|
|
74
|
+
/* Override brand primary colors */
|
|
75
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-magenta-600);
|
|
76
|
+
--cnvs-brand-primary-light: var(--cnvs-base-palette-magenta-200);
|
|
77
|
+
--cnvs-brand-primary-lighter: var(--cnvs-base-palette-magenta-50);
|
|
78
|
+
--cnvs-brand-primary-lightest: var(--cnvs-base-palette-magenta-25);
|
|
79
|
+
--cnvs-brand-primary-dark: var(--cnvs-base-palette-magenta-700);
|
|
80
|
+
--cnvs-brand-primary-darkest: var(--cnvs-base-palette-magenta-800);
|
|
81
|
+
--cnvs-brand-primary-accent: var(--cnvs-base-palette-neutral-0);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> **Note:** You should only import the CSS variables *once* at the root level of your application. If your application renders within another environment that imports these and sets them, **do not** re import them.
|
|
86
|
+
|
|
87
|
+
### Method 2: Provider-Level CSS Variables
|
|
88
|
+
|
|
89
|
+
Use Canvas Kit's `createStyles` utility to generate themed class names that can be applied to specific components or sections:
|
|
90
|
+
|
|
91
|
+
> **Note:** Doing the following **will create a cascade barrier**. Only use this method if you intentionally want to override the default theme.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import {createStyles}from "@workday/canvas-kit-styling"
|
|
95
|
+
import {brand, base} from "@workday/canvas-tokens-web"
|
|
96
|
+
import {CanvasProvider} from "@workday/canvas-kit-react/common"
|
|
97
|
+
|
|
98
|
+
// You can import the CSS variables in a ts file or an index.css file. You do not need to do both.
|
|
99
|
+
import '@workday/canvas-tokens-web/css/base/_variables.css';
|
|
100
|
+
import '@workday/canvas-tokens-web/css/system/_variables.css';
|
|
101
|
+
import '@workday/canvas-tokens-web/css/brand/_variables.css';
|
|
102
|
+
|
|
103
|
+
// Generate a class name that defines CSS variables
|
|
104
|
+
const themedBrand = createStyles({
|
|
105
|
+
[brand.primary.accent]: base.neutral0,
|
|
106
|
+
[brand.primary.darkest]: base.blue800,
|
|
107
|
+
[brand.primary.dark]: base.blue700,
|
|
108
|
+
[brand.primary.base]: base.blue600,
|
|
109
|
+
[brand.primary.light]: base.blue200,
|
|
110
|
+
[brand.primary.lighter]: base.blue50,
|
|
111
|
+
[brand.primary.lightest]: base.blue25,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
<CanvasProvider className={themedBrand}>
|
|
115
|
+
<App/>
|
|
116
|
+
</CanvasProvider>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## CSS Token Structure
|
|
120
|
+
|
|
121
|
+
Canvas Kit provides three layers of CSS variables.
|
|
122
|
+
|
|
123
|
+
### Base Tokens (`base/_variables.css`)
|
|
124
|
+
Base tokens define foundation palette and design values.
|
|
125
|
+
```css
|
|
126
|
+
--cnvs-base-palette-blue-600: oklch(0.5198 0.1782 256.11 / 1);
|
|
127
|
+
--cnvs-base-palette-magenta-600: oklch(0.534 0.183 344.19 / 1);
|
|
128
|
+
--cnvs-base-font-size-100: 1rem;
|
|
129
|
+
--cnvs-base-space-x4: calc(var(--cnvs-base-unit) * 4);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Brand Tokens (`brand/_variables.css`)
|
|
133
|
+
Brand tokens define semantic color assignments.
|
|
134
|
+
```css
|
|
135
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-blue-600);
|
|
136
|
+
--cnvs-brand-primary-accent: var(--cnvs-base-palette-neutral-0);
|
|
137
|
+
--cnvs-brand-error-base: var(--cnvs-base-palette-red-600);
|
|
138
|
+
--cnvs-brand-success-base: var(--cnvs-base-palette-green-600);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### System Tokens (`system/_variables.css`)
|
|
142
|
+
System tokens define component-specific values.
|
|
143
|
+
```css
|
|
144
|
+
--cnvs-sys-color-bg-primary-default: var(--cnvs-base-palette-blue-600);
|
|
145
|
+
--cnvs-sys-color-text-primary-default: var(--cnvs-base-palette-blue-600);
|
|
146
|
+
--cnvs-sys-space-x4: calc(var(--cnvs-base-unit) * 4);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Practical Examples
|
|
150
|
+
|
|
151
|
+
### Complete Brand Theming
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
/* themes/magenta-theme.css */
|
|
155
|
+
@import '@workday/canvas-tokens-web/css/base/_variables.css';
|
|
156
|
+
@import '@workday/canvas-tokens-web/css/system/_variables.css';
|
|
157
|
+
@import '@workday/canvas-tokens-web/css/brand/_variables.css';
|
|
158
|
+
|
|
159
|
+
:root {
|
|
160
|
+
/* Primary brand colors */
|
|
161
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-magenta-600);
|
|
162
|
+
--cnvs-brand-primary-light: var(--cnvs-base-palette-magenta-200);
|
|
163
|
+
--cnvs-brand-primary-lighter: var(--cnvs-base-palette-magenta-50);
|
|
164
|
+
--cnvs-brand-primary-lightest: var(--cnvs-base-palette-magenta-25);
|
|
165
|
+
--cnvs-brand-primary-dark: var(--cnvs-base-palette-magenta-700);
|
|
166
|
+
--cnvs-brand-primary-darkest: var(--cnvs-base-palette-magenta-800);
|
|
167
|
+
--cnvs-brand-primary-accent: var(--cnvs-base-palette-neutral-0);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### App-Specific Theming
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
import {createStyles} from "@workday/canvas-kit-styling";
|
|
175
|
+
import {brand, base} from "@workday/canvas-tokens-web";
|
|
176
|
+
import {PrimaryButton} from "@workday/canvas-kit-react/button";
|
|
177
|
+
import {CanvasProvider} from "@workday/canvas-kit-react/common";
|
|
178
|
+
|
|
179
|
+
const greenTheme = createStyles({
|
|
180
|
+
[brand.primary.base]: base.green600,
|
|
181
|
+
[brand.primary.dark]: base.green700,
|
|
182
|
+
[brand.primary.darkest]: base.green800,
|
|
183
|
+
[brand.primary.light]: base.green200,
|
|
184
|
+
[brand.primary.lighter]: base.green50,
|
|
185
|
+
[brand.primary.lightest]: base.green25,
|
|
186
|
+
[brand.primary.accent]: base.neutral0,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
<CanvasProvider className={greenTheme}>
|
|
190
|
+
<PrimaryButton>Click me</PrimaryButton>
|
|
191
|
+
</CanvasProvider>
|
|
192
|
+
);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
<ExampleCodeBlock code={Theming} />
|
|
196
|
+
|
|
197
|
+
### Dark Mode Implementation
|
|
198
|
+
|
|
199
|
+
```css
|
|
200
|
+
/* Dark mode theming */
|
|
201
|
+
[data-theme="dark"] {
|
|
202
|
+
--cnvs-sys-color-bg-default: var(--cnvs-base-palette-neutral-950);
|
|
203
|
+
--cnvs-sys-color-text-default: var(--cnvs-base-palette-neutral-50);
|
|
204
|
+
--cnvs-sys-color-border-container: var(--cnvs-base-palette-slate-700);
|
|
205
|
+
--cnvs-sys-color-bg-alt-default: var(--cnvs-base-palette-slate-800);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### RTL Support
|
|
210
|
+
Canvas Kit supports RTL out of the box. Our components are styled to use [CSS logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values). If you want to add additional styles based on RTL,
|
|
211
|
+
you can also use the `:dir` [pseudo selector](https://developer.mozilla.org/en-US/docs/Web/CSS/:dir).
|
|
212
|
+
|
|
213
|
+
<ExampleCodeBlock code={RTL} />
|
|
214
|
+
|
|
215
|
+
### Resetting to Default Brand Theme
|
|
216
|
+
|
|
217
|
+
If you need to reset the theme in parts of your application, there's a few ways to do this.
|
|
218
|
+
We export a `defaultBranding` class that can be applied to the `CanvasProvider` which can wrap parts of your application.
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
import {CanvasProvider, defaultBranding} from "@workday/canvas-kit-react/common"
|
|
222
|
+
|
|
223
|
+
<CanvasProvider className={defaultBranding}>
|
|
224
|
+
<SomeSubComponent/>
|
|
225
|
+
</CanvasProvider>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
> **Note:** Doing the following **will create a cascade barrier**. Only use this method if you intentionally want to override the default theme.
|
|
229
|
+
|
|
230
|
+
## Migration Guide
|
|
231
|
+
|
|
232
|
+
### Step 1: Identify Current Theme Usage
|
|
233
|
+
|
|
234
|
+
Find all instances of `CanvasProvider` with theme props in your application.
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
// Find these patterns:
|
|
238
|
+
<CanvasProvider theme={{canvas: {palette: {...}}}}>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Step 2: Extract Theme Values
|
|
242
|
+
|
|
243
|
+
Convert JavaScript theme objects to CSS variable overrides.
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
// Old approach:
|
|
247
|
+
const theme = {
|
|
248
|
+
canvas: {
|
|
249
|
+
palette: {
|
|
250
|
+
primary: {
|
|
251
|
+
main: colors.greenApple400,
|
|
252
|
+
dark: colors.greenApple500,
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// New approach - CSS variables:
|
|
259
|
+
:root {
|
|
260
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-green-400);
|
|
261
|
+
--cnvs-brand-primary-dark: var(--cnvs-base-palette-green-500);
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Step 3: App Level Theming Usage
|
|
266
|
+
|
|
267
|
+
Replace theme-based `CanvasProvider` usage with CSS class-based theming.
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
// Before:
|
|
271
|
+
<CanvasProvider theme={customTheme}>
|
|
272
|
+
<App />
|
|
273
|
+
</CanvasProvider>
|
|
274
|
+
|
|
275
|
+
// After:
|
|
276
|
+
<CanvasProvider className={customThemeClass}>
|
|
277
|
+
<App />
|
|
278
|
+
</CanvasProvider>
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
> **Note:** Using a class means you will need to define each property of the palette for full control over theming.
|
|
282
|
+
|
|
283
|
+
### Step 4: Test Component Rendering
|
|
284
|
+
|
|
285
|
+
Verify that Canvas Kit components (like `PrimaryButton`) correctly use the new CSS variables.
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
import {PrimaryButton} from "@workday/canvas-kit-react/button";
|
|
289
|
+
|
|
290
|
+
// This should automatically use your CSS variable overrides
|
|
291
|
+
<PrimaryButton>Themed Button</PrimaryButton>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Best Practices
|
|
295
|
+
|
|
296
|
+
### 1. Use Semantic Token Names
|
|
297
|
+
Use brand tokens instead of base tokens for better maintainability.
|
|
298
|
+
|
|
299
|
+
```css
|
|
300
|
+
/* ✅ Good - semantic meaning */
|
|
301
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-blue-600);
|
|
302
|
+
|
|
303
|
+
/* ❌ Avoid - direct base token usage */
|
|
304
|
+
--cnvs-base-palette-blue-600: blue;
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
### 2. Test Accessibility
|
|
309
|
+
Ensure color combinations meet accessibility standards.
|
|
310
|
+
|
|
311
|
+
```css
|
|
312
|
+
/* Verify contrast ratios for text/background combinations */
|
|
313
|
+
:root {
|
|
314
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-blue-600);
|
|
315
|
+
--cnvs-brand-primary-accent: var(--cnvs-base-palette-neutral-0); /* White text */
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### 3. Avoid Component Level Theming
|
|
320
|
+
|
|
321
|
+
Theming is meant to be done at the app level or root level of the application. Avoid theming at the component level.
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
/* ✅ Good - App level theming */
|
|
325
|
+
import {CanvasProvider} from '@workday/canvas-kit-react/common';
|
|
326
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
327
|
+
import {base, brand} from '@workday/canvas-tokens-web';
|
|
328
|
+
|
|
329
|
+
const myCustomTheme = createStyles({
|
|
330
|
+
[brand.primary.base]: base.magenta600
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
<CanvasProvider className={myCustomTheme}>
|
|
335
|
+
<App/>
|
|
336
|
+
</CanvasProvider>
|
|
337
|
+
|
|
338
|
+
/* ❌ Avoid - wrapping components to theme */
|
|
339
|
+
import {CanvasProvider} from '@workday/canvas-kit-react/common';
|
|
340
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
341
|
+
|
|
342
|
+
const myCustomTheme = createStyles({
|
|
343
|
+
[brand.primary.base]: base.magenta600
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
<CanvasProvider className={myCustomTheme}>
|
|
347
|
+
<PrimaryButton>Click Me</PrimaryButton>
|
|
348
|
+
</CanvasProvider>
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Component Compatibility
|
|
353
|
+
|
|
354
|
+
All Canvas Kit components in v14 automatically consume CSS variables. No component-level changes are required when switching from the theme prop approach to CSS variables.
|
|
355
|
+
|
|
356
|
+
### Supported Components
|
|
357
|
+
- ✅ All Button variants (`PrimaryButton`, `SecondaryButton`, etc.)
|
|
358
|
+
- ✅ Form components (`TextInput`, `FormField`, etc.)
|
|
359
|
+
- ✅ Layout components (`Card`, `Modal`, etc.)
|
|
360
|
+
- ✅ Navigation components (`Tabs`, `SidePanel`, etc.)
|
|
361
|
+
|
|
362
|
+
## Performance Benefits
|
|
363
|
+
|
|
364
|
+
The CSS variable approach provides several performance improvements:
|
|
365
|
+
|
|
366
|
+
- **Reduced Bundle Size**: No JavaScript theme object processing
|
|
367
|
+
- **Better Caching**: CSS variables can be cached by the browser
|
|
368
|
+
- **Faster Rendering**: Native CSS cascade instead of JavaScript calculations
|
|
369
|
+
- **Runtime Efficiency**: No theme context propagation overhead
|
|
370
|
+
|
|
371
|
+
## Troubleshooting
|
|
372
|
+
|
|
373
|
+
### Theme Not Applied
|
|
374
|
+
Ensure CSS variable files are imported in the correct order.
|
|
375
|
+
|
|
376
|
+
```css
|
|
377
|
+
/* Correct order */
|
|
378
|
+
@import '@workday/canvas-tokens-web/css/base/_variables.css';
|
|
379
|
+
@import '@workday/canvas-tokens-web/css/system/_variables.css';
|
|
380
|
+
@import '@workday/canvas-tokens-web/css/brand/_variables.css';
|
|
381
|
+
|
|
382
|
+
/* Your overrides after imports */
|
|
383
|
+
:root {
|
|
384
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-magenta-600);
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Inconsistent Theming
|
|
389
|
+
Check for CSS specificity issues.
|
|
390
|
+
|
|
391
|
+
```css
|
|
392
|
+
/* Ensure your overrides have sufficient specificity */
|
|
393
|
+
:root {
|
|
394
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-blue-600) !important;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* Or use more specific selectors */
|
|
398
|
+
.my-app {
|
|
399
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-blue-600);
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Missing Token Values
|
|
404
|
+
Verify all required CSS token files are imported and token names are correct.
|
|
405
|
+
|
|
406
|
+
```tsx
|
|
407
|
+
import {brand, base, system} from "@workday/canvas-tokens-web";
|
|
408
|
+
|
|
409
|
+
// Check token availability in development
|
|
410
|
+
console.log(brand.primary.base); // Should output CSS variable name
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Conclusion
|
|
414
|
+
|
|
415
|
+
The migration to CSS variables in Canvas Kit v14 provides a more performant, flexible, and maintainable theming solution. By following this guide and best practices, you can successfully migrate your applications and take advantage of the improved theming capabilities.
|
|
416
|
+
|
|
417
|
+
For additional support and examples, refer to the Canvas Kit Storybook documentation and the `@workday/canvas-tokens` [repository](https://github.com/Workday/canvas-tokens).
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
3
|
+
|
|
4
|
+
import {CanvasProvider} from '@workday/canvas-kit-react/common';
|
|
5
|
+
import {Card} from '@workday/canvas-kit-react/card';
|
|
6
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
7
|
+
import {FormField} from '@workday/canvas-kit-react/form-field';
|
|
8
|
+
import {TextInput} from '@workday/canvas-kit-react/text-input';
|
|
9
|
+
import {arrowRightSmallIcon} from '@workday/canvas-system-icons-web';
|
|
10
|
+
import {system} from '@workday/canvas-tokens-web';
|
|
11
|
+
|
|
12
|
+
const rtlStyles = createStyles({
|
|
13
|
+
paddingInlineStart: system.space.x16,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const rtlButtonStyles = createStyles({
|
|
17
|
+
':dir(rtl)': {
|
|
18
|
+
svg: {
|
|
19
|
+
transform: 'rotate(180deg)',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const App = () => {
|
|
25
|
+
const [value, setValue] = React.useState('');
|
|
26
|
+
|
|
27
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
28
|
+
setValue(event.target.value);
|
|
29
|
+
};
|
|
30
|
+
return (
|
|
31
|
+
<Card>
|
|
32
|
+
<Card.Heading>RTL Support</Card.Heading>
|
|
33
|
+
<Card.Body cs={rtlStyles}>
|
|
34
|
+
<FormField>
|
|
35
|
+
<FormField.Label>Email</FormField.Label>
|
|
36
|
+
<FormField.Field>
|
|
37
|
+
<FormField.Input as={TextInput} onChange={handleChange} value={value} />
|
|
38
|
+
</FormField.Field>
|
|
39
|
+
</FormField>
|
|
40
|
+
<PrimaryButton cs={rtlButtonStyles} iconPosition="end" icon={arrowRightSmallIcon}>
|
|
41
|
+
RTL
|
|
42
|
+
</PrimaryButton>
|
|
43
|
+
</Card.Body>
|
|
44
|
+
</Card>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default () => {
|
|
49
|
+
return (
|
|
50
|
+
<CanvasProvider dir="rtl">
|
|
51
|
+
<App />
|
|
52
|
+
</CanvasProvider>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
2
|
+
import {brand, base, system} from '@workday/canvas-tokens-web';
|
|
3
|
+
import {CanvasProvider} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {Card} from '@workday/canvas-kit-react/card';
|
|
5
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
6
|
+
|
|
7
|
+
const customTheme = createStyles({
|
|
8
|
+
[brand.primary.base]: base.green600,
|
|
9
|
+
[brand.primary.dark]: base.green700,
|
|
10
|
+
[brand.primary.darkest]: base.green800,
|
|
11
|
+
[brand.common.focusOutline]: base.green600,
|
|
12
|
+
[system.color.fg.strong]: base.indigo900,
|
|
13
|
+
[system.color.border.container]: base.indigo300,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const App = () => {
|
|
17
|
+
return (
|
|
18
|
+
<Card>
|
|
19
|
+
<Card.Heading>Theming</Card.Heading>
|
|
20
|
+
<Card.Body>
|
|
21
|
+
<PrimaryButton>Theming</PrimaryButton>
|
|
22
|
+
<input />
|
|
23
|
+
</Card.Body>
|
|
24
|
+
</Card>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default () => {
|
|
29
|
+
return (
|
|
30
|
+
<CanvasProvider className={customTheme}>
|
|
31
|
+
<App />
|
|
32
|
+
</CanvasProvider>
|
|
33
|
+
);
|
|
34
|
+
};
|
package/dist/mdx/welcome.mdx
CHANGED
|
@@ -9,8 +9,7 @@ import { version } from '../../../lerna.json';
|
|
|
9
9
|
|
|
10
10
|
### Canvas Provider
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
styling your components, the `<CanvasProvider>` ensures your styles will merge as expected. Note:
|
|
12
|
+
If you use Emotion for styling your components, the `<CanvasProvider>` ensures your styles will merge as expected. Note:
|
|
14
13
|
Custom use of `<CacheProvider>` provided by Emotion is not supported. `@workday/canvas-kit-styling`
|
|
15
14
|
owns the creating of the cache reference. This ensures both static styling and Emotion’s dynamic
|
|
16
15
|
styling solutions work together. In most cases you'll want to wrap your application at the root
|
|
@@ -20,9 +19,6 @@ level in `<CanvasProvider>`.
|
|
|
20
19
|
import * as React from 'react';
|
|
21
20
|
import {
|
|
22
21
|
CanvasProvider,
|
|
23
|
-
ContentDirection,
|
|
24
|
-
PartialEmotionCanvasTheme,
|
|
25
|
-
useTheme,
|
|
26
22
|
} from '@workday/canvas-kit-react/common';
|
|
27
23
|
// Ensure CSS variables are defined. You Can also do this at the root index.css
|
|
28
24
|
import '@workday/canvas-tokens-web/css/base/_variables.css';
|
|
@@ -30,15 +26,8 @@ import '@workday/canvas-tokens-web/css/brand/_variables.css';
|
|
|
30
26
|
import '@workday/canvas-tokens-web/css/system/_variables.css';
|
|
31
27
|
|
|
32
28
|
export const App = () => {
|
|
33
|
-
// useTheme is filling in the Canvas theme object if any keys are missing
|
|
34
|
-
const canvasTheme: PartialEmotionCanvasTheme = useTheme({
|
|
35
|
-
canvas: {
|
|
36
|
-
// Switch to `ContentDirection.RTL` to change direction
|
|
37
|
-
direction: ContentDirection.LTR,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
29
|
return (
|
|
41
|
-
<CanvasProvider
|
|
30
|
+
<CanvasProvider>
|
|
42
31
|
<main>
|
|
43
32
|
<p>Get Started With Canvas Kit</p>
|
|
44
33
|
</main>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "14.0.0-alpha.
|
|
3
|
+
"version": "14.0.0-alpha.1253-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.
|
|
49
|
-
"@workday/canvas-kit-preview-react": "^14.0.0-alpha.
|
|
50
|
-
"@workday/canvas-kit-react": "^14.0.0-alpha.
|
|
51
|
-
"@workday/canvas-kit-styling": "^14.0.0-alpha.
|
|
48
|
+
"@workday/canvas-kit-labs-react": "^14.0.0-alpha.1253-next.0",
|
|
49
|
+
"@workday/canvas-kit-preview-react": "^14.0.0-alpha.1253-next.0",
|
|
50
|
+
"@workday/canvas-kit-react": "^14.0.0-alpha.1253-next.0",
|
|
51
|
+
"@workday/canvas-kit-styling": "^14.0.0-alpha.1253-next.0",
|
|
52
52
|
"@workday/canvas-system-icons-web": "^3.0.35",
|
|
53
53
|
"@workday/canvas-tokens-web": "3.0.0-alpha.12",
|
|
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": "
|
|
64
|
+
"gitHead": "7b01743972e4f21990fe36d90fa5938f25c57410"
|
|
65
65
|
}
|