@workday/canvas-kit-docs 15.0.0-alpha.1301-next.0 → 15.0.0-alpha.1326-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,424 @@
1
+ import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
2
+ import {StorybookStatusIndicator, DownloadLLMFile} from '@workday/canvas-kit-docs';
3
+
4
+
5
+ # Style Props Deprecation Overview
6
+
7
+ ### Purpose
8
+
9
+ As part of the Canvas Kit’s modernization process, we’re moving away from Emotion’s runtime styling
10
+ and promoting a custom CSS-in-JS solution: `@workday/canvas-kit-styling`. This change improves
11
+ **performance**, **consistency**, and **maintainability** across our codebase. For more information,
12
+ view our [Future of](https://github.com/Workday/canvas-kit/discussions/2265) discussion.
13
+
14
+ ### Goals
15
+
16
+ - **Reduce runtime overhead** by removing Emotion’s runtime from `@emotion/react`
17
+ - **Promote prescriptive, opinionated styling** across Workday
18
+ - **Enable static CSS compilation** for faster load times and smaller bundles
19
+ - **Support new design tokens and CSS Variables** for scalable theming
20
+ - **Ensure proper style merging** and stable selector behavior
21
+ - **Support advanced styling patterns** like compound styles, modifiers, and `data-parts`
22
+
23
+ > Emotion dynamically injects styles at runtime, causing costly re-renders and cache invalidations.
24
+ > The new system statically compiles styles at build time for optimal performance.
25
+
26
+ ### Timeline
27
+
28
+ - **Deprecation introduced:** Canvas Kit **v14.1**
29
+ - **Removal:** _Not immediate_ — style props and `styled()` will continue to function in upcoming
30
+ releases
31
+ - **Migration timeline:** Gradual; no immediate codebase-wide update required
32
+
33
+ ## LLM Assisted Migration <StorybookStatusIndicator type="ai" />
34
+
35
+ We've provided an **LLM migration mapping file** (`llm-style-props-migration.txt`) specifically
36
+ designed for use with LLM-based code assistants such as [Cursor](https://www.cursor.so/). It
37
+ contains a compiled LLM consumption version of this v14 Upgrade Guide. It is not intended for direct
38
+ human reference or team documentation, but rather as structured input for LLMs to automate and
39
+ assist with your migration process.
40
+
41
+ > **Important:** LLMs can make mistakes. Please verify changes using this Migration Guide.
42
+
43
+ **How to use:**
44
+
45
+ - **View raw file**: Open the file in a new tab to see the complete migration mapping
46
+ - **Download LLM File**: Save the file locally to upload or paste into your LLM/code assistant
47
+ - **Use with LLM**: Provide the raw content to your LLM/code assistant as context for automated
48
+ migration
49
+
50
+ <DownloadLLMFile
51
+ rawFileLink="https://raw.githubusercontent.com/Workday/canvas-kit/master/modules/docs/llm-txt/llm-style-props-migration.txt"
52
+ filename="llm-style-props-migration.txt"
53
+ />
54
+
55
+ ## Changes Overview
56
+
57
+ ### Replacements
58
+
59
+ Use the new **Canvas Kit Styling** utilities:
60
+
61
+ | Old API | New API | Purpose |
62
+ | -------------------------------------------------- | -------------------------------- | ------------------------------------------ |
63
+ | `styled()` | `createStyles` / `createStencil` | Define static or component-level styles |
64
+ | Inline style props, like `background` or `padding` | `cs` prop | Safely merge class names and styles |
65
+ | Dynamic values | `createVars` | Manage CSS variables for runtime overrides |
66
+ | Emotion modifiers | `modifiers`, `compound` | Define consistent appearance variants |
67
+
68
+ ## Canvas Kit Styling
69
+
70
+ <InformationHighlight className="sb-unstyled" cs={{p: {marginBlock: 0}}}>
71
+ <InformationHighlight.Icon />
72
+ <InformationHighlight.Heading>Canvas Kit Styling Docs</InformationHighlight.Heading>
73
+ For a detailed overview of our styling approach, view our styling docs.
74
+ <InformationHighlight.Link href="https://workday.github.io/canvas-kit/?path=/docs/styling-getting-started-overview--docs">
75
+ Read more
76
+ </InformationHighlight.Link>
77
+ </InformationHighlight>
78
+
79
+ Canvas Kit’s styling utilities are built for **static CSS generation**, **token integration**, and
80
+ **predictable composition**.
81
+
82
+ ### Core APIs
83
+
84
+ - **`createStyles`** — define reusable, static CSS objects.
85
+ - **`createStencil`** — define reusable, dynamic component styles with parts, vars, and modifiers
86
+ - **`cs` prop** — apply multiple styles and handle merges consistently to Canvas Kit components
87
+
88
+ ### Best Practices
89
+
90
+ These best practices ensure your components remain **performant**, **consistent**, and
91
+ **maintainable** under the new Canvas Kit Styling system.
92
+
93
+ #### Define Styles Outside the Render Function
94
+
95
+ Always declare styles at the module level. Creating styles inside the render or component function
96
+ will trigger component re-render.
97
+
98
+ ✅ **Do**
99
+
100
+ ```tsx
101
+ // `createStyles` returns a string of className
102
+ const buttonStyles = createStyles({
103
+ backgroundColor: system.color.bg.primary.default,
104
+ color: system.color.text.inverse,
105
+ });
106
+
107
+ export const MyButton = () => <button className={buttonStyles}>Click me</button>;
108
+ ```
109
+
110
+ ❌ **Don’t**
111
+
112
+ ```tsx
113
+ export const MyButton = () => {
114
+ const buttonStyles = createStyles({backgroundColor: 'red'}); // bad
115
+ return <button cs={buttonStyles}>Click me</button>;
116
+ };
117
+ ```
118
+
119
+ #### Use `createStyles` for Static Styling
120
+
121
+ Use `createStyles` for simple, reusable style objects that do **not** depend on dynamic data or
122
+ props.
123
+
124
+ ✅ Ideal for:
125
+
126
+ - Defining base styles
127
+ - Applying static overrides
128
+ - Styling tokens-based components
129
+
130
+ `createStyles` returns a string of className that can be applied to a React element. If you're
131
+ applying the class to a Canvas Kit component, you can use the `cs` prop.
132
+
133
+ ```tsx
134
+ import {BaseButton} from '@workday/canvas-kit-react/button';
135
+ import {createStyles} from '@workday/canvas-kit-styling';
136
+ // `createStyles` returns a string of className
137
+ const buttonStyles = createStyles({
138
+ backgroundColor: system.color.bg.primary.default,
139
+ color: system.color.text.inverse,
140
+ });
141
+
142
+ export const MyButton = () => <BaseButton cs={buttonStyles}>Click me</button>;
143
+ ```
144
+
145
+ #### Use `createStencil` for Dynamic or Complex Styling
146
+
147
+ Use `createStencil` when styles depend on **props**, **variants**, or **component parts**.
148
+
149
+ Examples:
150
+
151
+ - Size or color variants (`primary`, `secondary`)
152
+ - Compound state combinations (`size=small`, `iconPosition=end`)
153
+ - Multi-part components (e.g. `Button`, `Card`, `MenuItem`)
154
+
155
+ ✅ **Do**
156
+
157
+ ```tsx
158
+ const buttonStencil = createStencil({
159
+ vars: {color: '', background: ''},
160
+ base: ({color, backgroundColor}) => ({
161
+ color: cssVar(color, system.color.text.default),
162
+ backgroundColor: cssVar(backgroundColor, system.color.bg.default),
163
+ }),
164
+ modifiers: {
165
+ variant: {
166
+ primary: {background: system.color.bg.primary.default},
167
+ secondary: {background: system.color.bg.muted.default},
168
+ },
169
+ },
170
+ });
171
+ ```
172
+
173
+ - **vars**: If you initialize the variable with an empty string, it will allow the variable to
174
+ cascade and be defined.
175
+
176
+ ```tsx
177
+ const customButtonStencil = createStencil({
178
+ base: {
179
+ // Set the color variable to the primary color
180
+ [buttonStencil.vars.color]: system.color.fg.primary.default,
181
+ },
182
+ });
183
+ ```
184
+
185
+ - **cssVar**: The `cssVar` function is used when you want to add a default value if the CSS Variable
186
+ is not defined.
187
+ - **modifiers**: The `modifiers` property is used to define the styles for the different variants of
188
+ the component.
189
+
190
+ #### Use `cs` Prop to Merge Styles
191
+
192
+ The `cs` prop merges `className` and `style` attributes safely and consistently. Use this over using
193
+ style props or className concatenation.
194
+
195
+ ✅ **Do**
196
+
197
+ ```tsx
198
+ <PrimaryButton cs={[baseStyles, variantStyles]} />
199
+ ```
200
+
201
+ ❌ **Don’t**
202
+
203
+ ```tsx
204
+ <PrimaryButton className={`${baseStyles} ${variantStyles}`} />
205
+ ```
206
+
207
+ #### Use Variables for Dynamic Values
208
+
209
+ Instead of inline styles or runtime calculations, use stencil variables.
210
+
211
+ ✅ **Do**
212
+
213
+ ```tsx
214
+ const primaryButtonStencil = createStencil({
215
+ base: {
216
+ // Use the buttonStencil variable to set the background color
217
+ [buttonStencil.vars.background]: 'orange',
218
+ }
219
+ })
220
+ <PrimaryButton cs={primaryButtonStencil} />
221
+ ```
222
+
223
+ ❌ **Don’t**
224
+
225
+ ```tsx
226
+ <PrimaryButton cs={{backgroundColor: 'orange'}} /> // breaks static optimization
227
+ ```
228
+
229
+ #### Extend Existing Stencils Instead of Overriding Styles
230
+
231
+ When modifying Canvas Kit components, extend the provided `Stencil` instead of creating your own
232
+ from scratch.
233
+
234
+ ✅ **Do**
235
+
236
+ ```tsx
237
+ const customIconStencil = createStencil({
238
+ extends: systemIconStencil,
239
+ base: {
240
+ margin: system.space.x2,
241
+ },
242
+ });
243
+ ```
244
+
245
+ This will inherit both the styles and variables from the `systemIconStencil`.
246
+
247
+ #### Use Modifiers for Variants and States
248
+
249
+ Define component variations (size, color, emphasis) using **modifiers** rather than conditional
250
+ logic.
251
+
252
+ ✅ **Do**
253
+
254
+ ```tsx
255
+ const badgeStencil = createStencil({
256
+ modifiers: {
257
+ status: {
258
+ success: {background: system.color.bg.success.default},
259
+ error: {background: system.color.bg.negative.default},
260
+ },
261
+ },
262
+ });
263
+ ```
264
+
265
+ #### Use Compound Modifiers for Complex Conditions
266
+
267
+ When two or more modifiers combine to produce a new style, define a **compound modifier**.
268
+
269
+ ✅ **Do**
270
+
271
+ ```tsx
272
+ const myCustomStencil = createStencil({
273
+ base: {
274
+ //base styles
275
+ },
276
+ modifiers: {
277
+ variant: {
278
+ primary: {
279
+ // primary variant styles
280
+ },
281
+ },
282
+ size: {
283
+ large: {
284
+ // large size styles
285
+ },
286
+ },
287
+ },
288
+ compound: [
289
+ {
290
+ // apply styles when the variant is primary AND the size is large
291
+ modifiers: {variant: 'primary', size: 'large'},
292
+ styles: {paddingInline: system.space.x5},
293
+ },
294
+ ],
295
+ });
296
+ ```
297
+
298
+ #### Avoid Nested Stencils Unless Necessary
299
+
300
+ Each Stencil should map to one semantic component. Nested stencils can increase CSS specificity and
301
+ complexity. Use **parts** instead of deep nesting.
302
+
303
+ ✅ **Do**
304
+
305
+ ```tsx
306
+ const cardStencil = createStencil({
307
+ parts: {header: 'card-header', body: 'card-body'},
308
+ base: ({headerPart}) => ({
309
+ [headerPart]: {
310
+ fontWeight: 'bold',
311
+ },
312
+ }),
313
+ });
314
+
315
+ <Card cs={cardStencil}>
316
+ <Card.Heading {...cardStencil.parts.header}>Card Title</Card.Heading>
317
+ <Card.Body {...cardStencil.parts.body}>Card Body</Card.Body>
318
+ </Card>;
319
+ ```
320
+
321
+ #### Prefer Tokens and System Variables
322
+
323
+ Always use design tokens (`system`) for spacing, colors, typography, etc., instead of raw values.
324
+ View our System Tokens
325
+ [docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-system-tokens-overview--docs) for
326
+ more information.
327
+
328
+ ✅ **Do**
329
+
330
+ ```tsx
331
+ color: system.color.text.default;
332
+ margin: system.space.x2;
333
+ ```
334
+
335
+ ❌ **Don’t**
336
+
337
+ ```tsx
338
+ color: '#333';
339
+ margin: '8px';
340
+ ```
341
+
342
+ #### Debugging and Static Compilation
343
+
344
+ - Enable static compilation during development to catch type or value errors early.
345
+ - Use `as const` for static objects to ensure values are type-locked for the compiler.
346
+
347
+ ✅ **Do**
348
+
349
+ ```tsx
350
+ const reusableStyles = {
351
+ position: 'absolute',
352
+ } as const;
353
+ ```
354
+
355
+ #### Don’t Mix Emotion and Static Styling
356
+
357
+ Avoid combining Emotion’s `styled` or `css` with `createStyles` or `createStencil`. It reintroduces
358
+ runtime style recalculations and negates static benefits.
359
+
360
+ ❌ **Don’t**
361
+
362
+ ```tsx
363
+ const StyledButton = styled(Button)(styles);
364
+ <StyledButton cs={createStyles({padding: 8})} />;
365
+ ```
366
+
367
+ ## Migration Example
368
+
369
+ ### Style Props
370
+
371
+ #### Before
372
+
373
+ ```typescript
374
+ import {Flex} from '@workday/canvas-kit-react/layout';
375
+
376
+ <Flex depth={1} marginX={10} background="frenchVanilla100" />;
377
+ ```
378
+
379
+ #### After
380
+
381
+ ```typescript
382
+ import {Flex} from '@workday/canvas-kit-react/layout';
383
+ import {system} from '@workday/canvas-tokens-web';
384
+ import {px2rem} from '@workday/canvas-kit-styling';
385
+
386
+ <Flex
387
+ cs={{
388
+ boxShadow: system.depth[1],
389
+ marginInline: px2rem(10),
390
+ background: system.color.bg.default,
391
+ }}
392
+ />;
393
+ ```
394
+
395
+ - **px2rem**: The `px2rem` function is used to convert a pixel value to a rem value.
396
+ - Use [CSS logical
397
+ properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values
398
+ - Use `system` tokens over `base` tokens for better theming support.
399
+
400
+ ### Emotion styled
401
+
402
+ #### Before (Emotion)
403
+
404
+ ```tsx
405
+ const StyledButton = styled('button')({
406
+ backgroundColor: 'blue',
407
+ color: 'white',
408
+ });
409
+ ```
410
+
411
+ #### After (Canvas Kit Styling)
412
+
413
+ ```tsx
414
+ import {createStyles} from '@workday/canvas-kit-styling';
415
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
416
+ import {system} from '@workday/canvas-tokens-web';
417
+
418
+ const primaryButtonStyles = createStyles({
419
+ backgroundColor: system.color.bg.primary.default,
420
+ color: system.color.text.inverse,
421
+ });
422
+
423
+ <PrimaryButton cs={primaryButtonStyles}>Click me</PrimaryButton>;
424
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "15.0.0-alpha.1301-next.0",
3
+ "version": "15.0.0-alpha.1326-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,12 +45,12 @@
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": "^15.0.0-alpha.1301-next.0",
49
- "@workday/canvas-kit-preview-react": "^15.0.0-alpha.1301-next.0",
50
- "@workday/canvas-kit-react": "^15.0.0-alpha.1301-next.0",
51
- "@workday/canvas-kit-styling": "^15.0.0-alpha.1301-next.0",
48
+ "@workday/canvas-kit-labs-react": "^15.0.0-alpha.1326-next.0",
49
+ "@workday/canvas-kit-preview-react": "^15.0.0-alpha.1326-next.0",
50
+ "@workday/canvas-kit-react": "^15.0.0-alpha.1326-next.0",
51
+ "@workday/canvas-kit-styling": "^15.0.0-alpha.1326-next.0",
52
52
  "@workday/canvas-system-icons-web": "^3.0.36",
53
- "@workday/canvas-tokens-web": "^3.1.1",
53
+ "@workday/canvas-tokens-web": "4.0.0-alpha.1",
54
54
  "markdown-to-jsx": "^7.2.0",
55
55
  "react-syntax-highlighter": "^15.5.0",
56
56
  "ts-node": "^10.9.1"
@@ -61,5 +61,5 @@
61
61
  "mkdirp": "^1.0.3",
62
62
  "typescript": "5.0"
63
63
  },
64
- "gitHead": "5a43df05e8c2e88e1bf2aa502b38c511f6a35117"
64
+ "gitHead": "9cdfd5792eab2f74d194662da6b9957fdf573654"
65
65
  }