@workday/canvas-kit-mcp 13.2.41
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/LICENSE +126 -0
- package/README.md +75 -0
- package/dist/cli.js +14691 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.js +14585 -0
- package/dist/index.js.map +7 -0
- package/dist/lib/upgrade-guides/12.0-UPGRADE-GUIDE.md +833 -0
- package/dist/lib/upgrade-guides/13.0-UPGRADE-GUIDE.md +516 -0
- package/dist/types/lib/cli.d.ts +3 -0
- package/dist/types/lib/cli.d.ts.map +1 -0
- package/dist/types/lib/index.d.ts +3 -0
- package/dist/types/lib/index.d.ts.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
# Canvas Kit 12.0 Upgrade Guide
|
|
2
|
+
|
|
3
|
+
This guide contains an overview of the changes in Canvas Kit v12. Please
|
|
4
|
+
[reach out](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you have
|
|
5
|
+
any questions.
|
|
6
|
+
|
|
7
|
+
## Why You Should Upgrade
|
|
8
|
+
|
|
9
|
+
Canvas Kit is transitioning into a
|
|
10
|
+
[new way of styling](https://github.com/Workday/canvas-kit/discussions/2265). Theming and building
|
|
11
|
+
an in sync Canvas Kit CSS has been at the top of our minds. We've started using our new
|
|
12
|
+
[Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)
|
|
13
|
+
package to take advantage of
|
|
14
|
+
[CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) and
|
|
15
|
+
provide semantic tokens that can translate to theming components.
|
|
16
|
+
|
|
17
|
+
A note to the reader:
|
|
18
|
+
|
|
19
|
+
- While we still support our old tokens from `@workday/canvas-kit-react/tokens`, **you must**
|
|
20
|
+
install our new tokens from `@workday/canvas-tokens-web`. You can find more info in our
|
|
21
|
+
[docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
|
|
22
|
+
- If your application lives within another application that already imports the CSS variables, **you do not need to import these again**.
|
|
23
|
+
|
|
24
|
+
## Table of contents
|
|
25
|
+
|
|
26
|
+
- [Canvas Tokens](#canvas-tokens)
|
|
27
|
+
- [Codemod](#codemod)
|
|
28
|
+
- [Instructions](#instructions)
|
|
29
|
+
- [Styling Updates](#styling-updates)
|
|
30
|
+
- [Compatibility Mode](#compatibility-mode)
|
|
31
|
+
- [Deprecations](#deprecations)
|
|
32
|
+
- [Form Field Container](#form-field-container)
|
|
33
|
+
- [Removals](#removals)
|
|
34
|
+
- [Input Icon Container](#input-icon-container)
|
|
35
|
+
- [Infrastructure](#infrastructure)
|
|
36
|
+
- [TypeScript](#typescript)
|
|
37
|
+
- [Component Updates](#component-updates)
|
|
38
|
+
- [Styling API and CSS Tokens](#styling-api-and-css-tokens)
|
|
39
|
+
- [Avatar](#avatar)
|
|
40
|
+
- [Collections](#collections)
|
|
41
|
+
- [Combobox](#combmbox)
|
|
42
|
+
- [Form Field](#form-field)
|
|
43
|
+
- [Form Field Group](#form-field-group)
|
|
44
|
+
- [Form Field Field](#form-field-field)
|
|
45
|
+
- [Menu Item](#menu-item)
|
|
46
|
+
- [MultiSelect](#multiselect)
|
|
47
|
+
- [Search Form](#search-form)
|
|
48
|
+
- [Select](#select)
|
|
49
|
+
- [Text Area](#text-area)
|
|
50
|
+
- [Text Input](#text-input)
|
|
51
|
+
- [Utility Updates](#utility-updates)
|
|
52
|
+
- [Troubleshooting](#troubleshooting)
|
|
53
|
+
- [Glossary](#glossary)
|
|
54
|
+
- [Main](#main)
|
|
55
|
+
- [Preview](#preview)
|
|
56
|
+
- [Labs](#labs)
|
|
57
|
+
|
|
58
|
+
## Canvas Tokens
|
|
59
|
+
|
|
60
|
+
In v12, all the components listed in this guide have started using our new
|
|
61
|
+
[Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
|
|
62
|
+
**You must** add `@workday/canvas-tokens-web` to ensure our components are properly styled and the
|
|
63
|
+
variables are defined at the root of your application. For more information on installing and using, please reference our tokens
|
|
64
|
+
[docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
|
|
65
|
+
|
|
66
|
+
> **Note:** If your application lives within another application that already imports the CSS variables, **you do not need to import these again**. If you need them for local development either add them via a plugin or at the root of the environment, **do not ship code to production duplicating the imports**.
|
|
67
|
+
|
|
68
|
+
## Codemod
|
|
69
|
+
|
|
70
|
+
We've provided a [codemod](https://github.com/Workday/canvas-kit/tree/master/modules/codemod) to
|
|
71
|
+
automatically update your code to work with most of the breaking changes in v12. **Breaking changes
|
|
72
|
+
handled by the codemod are marked with 🤖 in the Upgrade Guide.**
|
|
73
|
+
|
|
74
|
+
> **Note: In v12, we have done some infrastructure updates with moving to Storybook 7, Webpack 5,
|
|
75
|
+
> TypeScript 5.0 and Cypress 13 . With these updates has come some formatting issues after running
|
|
76
|
+
> our codemods. We recommend running a formatter to address the format issues that have been
|
|
77
|
+
> introduced in v12.**
|
|
78
|
+
|
|
79
|
+
A codemod is a script that makes programmatic transformations on your codebase by traversing the
|
|
80
|
+
[AST](https://www.codeshiftcommunity.com/docs/understanding-asts), identifying patterns, and making
|
|
81
|
+
prescribed changes. This greatly decreases opportunities for error and reduces the number of manual
|
|
82
|
+
updates, which allows you to focus on changes that need your attention. **We highly recommend you
|
|
83
|
+
use the codemod for these reasons.**
|
|
84
|
+
|
|
85
|
+
If you're new to running codemods or if it's been a minute since you've used one, there are a few
|
|
86
|
+
things you'll want to keep in mind.
|
|
87
|
+
|
|
88
|
+
- Our codemods are meant to be run sequentially. For example, if you're using v8 of Canvas Kit,
|
|
89
|
+
you'll need to run the v9 codemod before you run v10 and so on.
|
|
90
|
+
- The codemod will update your code to be compatible with the specified version, but it will **not**
|
|
91
|
+
remove outdated dependencies or upgrade dependencies to the latest version. You'll need to upgrade
|
|
92
|
+
dependencies on your own.
|
|
93
|
+
- We recommend upgrading dependencies before running the codemod.
|
|
94
|
+
- Always review your `package.json` files to make sure your dependency versions look correct.
|
|
95
|
+
- The codemod will not handle every breaking change in v12. You will likely need to make some manual
|
|
96
|
+
changes to be compatible. Use our Upgrade Guide as a checklist.
|
|
97
|
+
- Codemods are not bulletproof.
|
|
98
|
+
- Conduct a thorough PR and QA review of all changes to ensure no regressions were introduced.
|
|
99
|
+
- As a safety precaution, we recommend committing the changes from the codemod as a single
|
|
100
|
+
isolated commit (separate from other changes) so you can roll back more easily if necessary.
|
|
101
|
+
|
|
102
|
+
We're here to help! Automatic changes to your codebase can feel scary. You can always reach out to
|
|
103
|
+
our team. We'd be very happy to walk you through the process to set you up for success.
|
|
104
|
+
|
|
105
|
+
### Instructions
|
|
106
|
+
|
|
107
|
+
The easiest way to run our codemod is to use `npx` in your terminal.```sh
|
|
108
|
+
npx @workday/canvas-kit-codemod v12 [path]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Be sure to provide specific directories that need to be updated via the `[path]` argument. This
|
|
112
|
+
decreases the amount of AST the codemod needs to traverse and reduces the chances of the script
|
|
113
|
+
having an error. For example, if your source code lives in `src/`, use `src/` as your `[path]`. Or,
|
|
114
|
+
if you have a monorepo with three packages using Canvas Kit, provide those specific packages as your
|
|
115
|
+
`[path]`.
|
|
116
|
+
|
|
117
|
+
Alternatively, if you're unable to run the codemod successfully using `npx`, you can install the
|
|
118
|
+
codemod package as a dev dependency, run it with `yarn`, and then remove the package after you're
|
|
119
|
+
finished.
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
yarn add @workday/canvas-kit-codemod --dev
|
|
123
|
+
yarn canvas-kit-codemod v12 [path]
|
|
124
|
+
yarn remove @workday/canvas-kit-codemod
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> **Note**: The codemod only works on `.js`, `.jsx`, `.ts`, and `.tsx` files. You'll need to
|
|
128
|
+
> manually edit other file types (`.json`, `.mdx`, `.md`, etc.). You may need to run your linter
|
|
129
|
+
> after executing the codemod, as its resulting formatting (spacing, quotes, etc.) may not match
|
|
130
|
+
> your project conventions.
|
|
131
|
+
|
|
132
|
+
## Styling Updates
|
|
133
|
+
|
|
134
|
+
### Compatibility Mode
|
|
135
|
+
|
|
136
|
+
In v12, we have addressed a style merge issue with removing forced compatibility mode. For more
|
|
137
|
+
information on this change, please read our
|
|
138
|
+
[discussion](https://github.com/Workday/canvas-kit/discussions/2893).
|
|
139
|
+
|
|
140
|
+
## Deprecations
|
|
141
|
+
|
|
142
|
+
We add the [@deprecated](https://jsdoc.app/tags-deprecated.html) JSDoc tag to code we plan to remove
|
|
143
|
+
in a future major release. This signals consumers to migrate to a more stable alternative before the
|
|
144
|
+
deprecated code is removed.
|
|
145
|
+
|
|
146
|
+
### Form Field Container
|
|
147
|
+
|
|
148
|
+
**PR:** [#2865](https://github.com/Workday/canvas-kit/pull/2865)
|
|
149
|
+
|
|
150
|
+
We've deprecated `FormField.Container` in v12. Please use `FormField.Field` or
|
|
151
|
+
`FormFieldGroup.Field` for grouped inputs as this ensures proper label alignment and spacing of
|
|
152
|
+
inputs and hint text, regardless of the orientation.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
// v11
|
|
156
|
+
<FormField>
|
|
157
|
+
<FormField.Label>Email</FormField.Label>
|
|
158
|
+
<FormField.Container>
|
|
159
|
+
<FormField.Input as={TextInput} />
|
|
160
|
+
<FormField.Hint>You must provide an email</FormField.Hint>
|
|
161
|
+
</FormField.Container>
|
|
162
|
+
</FormField>
|
|
163
|
+
|
|
164
|
+
// v12
|
|
165
|
+
<FormField>
|
|
166
|
+
<FormField.Label>Email</FormField.Label>
|
|
167
|
+
<FormField.Field>
|
|
168
|
+
<FormField.Input as={TextInput} />
|
|
169
|
+
<FormField.Hint>You must provide an email</FormField.Hint>
|
|
170
|
+
</FormField.Field>
|
|
171
|
+
</FormField>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Removals
|
|
175
|
+
|
|
176
|
+
Removals are deletions from our codebase and you can no longer consume this component. We've either
|
|
177
|
+
promoted or replaced a component or utility.
|
|
178
|
+
|
|
179
|
+
### Input Icon Container
|
|
180
|
+
|
|
181
|
+
**PR:** [#2838](https://github.com/Workday/canvas-kit/pull/2838)
|
|
182
|
+
|
|
183
|
+
We've removed `InputIconContainer` from Main. Please use
|
|
184
|
+
[InputGroup](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-text-input--icons)
|
|
185
|
+
from Main instead.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Infrastructure
|
|
190
|
+
|
|
191
|
+
### TypeScript
|
|
192
|
+
|
|
193
|
+
**PR:** [#2908](https://github.com/Workday/canvas-kit/pull/2908)
|
|
194
|
+
|
|
195
|
+
We've upgraded to TypeScript 5.0 to make use of
|
|
196
|
+
[const Type Parameters](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters).
|
|
197
|
+
You will need to upgrade to TypeScript 5.0+ to avoid any TypeScript syntax errors. TypeScript does
|
|
198
|
+
not follow semver, so 5.0 doesn't mean a large breaking change from 4.9. TypeScript doesn't have a
|
|
199
|
+
`x.10` release, they bump the `x.9` to `{x+1}.0`.
|
|
200
|
+
|
|
201
|
+
## Component Updates
|
|
202
|
+
|
|
203
|
+
### Styling API and CSS Tokens
|
|
204
|
+
|
|
205
|
+
**PRs:** [#2793](https://github.com/Workday/canvas-kit/pull/2793),
|
|
206
|
+
[#2865](https://github.com/Workday/canvas-kit/pull/2865),
|
|
207
|
+
[#2881](https://github.com/Workday/canvas-kit/pull/2881),
|
|
208
|
+
[#2825](https://github.com/Workday/canvas-kit/pull/2825),
|
|
209
|
+
[#2795](https://github.com/Workday/canvas-kit/pull/2795),
|
|
210
|
+
|
|
211
|
+
Several components have been refactored to use our new
|
|
212
|
+
[Canvas Tokens](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) and
|
|
213
|
+
[styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-modifiers#createstyles-api).
|
|
214
|
+
The React interface **has not changed**, but CSS variables are now used for dynamic properties.
|
|
215
|
+
|
|
216
|
+
> **Note:** These components also support our new `cs` prop for styling. Learn more about styling
|
|
217
|
+
> with `cs` in our
|
|
218
|
+
> [documentation](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--cs-prop).
|
|
219
|
+
|
|
220
|
+
The following components are affected:
|
|
221
|
+
|
|
222
|
+
- `Avatar`
|
|
223
|
+
- `Dialog`
|
|
224
|
+
- `Modal`
|
|
225
|
+
- `Popup`
|
|
226
|
+
- `TextArea`
|
|
227
|
+
- `TextInput`
|
|
228
|
+
- `Toast`
|
|
229
|
+
|
|
230
|
+
### Avatar
|
|
231
|
+
|
|
232
|
+
**PR** [#2793](https://github.com/Workday/canvas-kit/pull/2793)
|
|
233
|
+
|
|
234
|
+
Avatar has been updated to use our new
|
|
235
|
+
[styling utilities](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-stencil).
|
|
236
|
+
The following changes have been made to the API:
|
|
237
|
+
|
|
238
|
+
- `Avatar.Size` has been deprecated. The `size` prop still accepts `Avatar.Size` in addition to the
|
|
239
|
+
following values:
|
|
240
|
+
`"extraExtraLarge" | "extraLarge" | "large" | "medium" | "small" | "extraSmall" | (string{})`
|
|
241
|
+
- `Avatar.Variant` has been deprecated. The `variant` prop still accepts `Avatar.Variant` in
|
|
242
|
+
addition to the following values: `"dark" | "light"`
|
|
243
|
+
- The `as` prop now accepts any element, not just a `div`.
|
|
244
|
+
|
|
245
|
+
> **Note:** Both `Avatar.Size` and `Avatar.Variant` have been deprecated in favor of the new string
|
|
246
|
+
> union types. You will see a console warn message while in development if you're still using this.
|
|
247
|
+
> Please update your types and usage before v13.
|
|
248
|
+
|
|
249
|
+
### Combobox
|
|
250
|
+
|
|
251
|
+
**PR** [#2983](https://github.com/Workday/canvas-kit/pull/2983)
|
|
252
|
+
|
|
253
|
+
The `useComboboxInput` hook, and the `Combobox.Input` component used to automatically update the
|
|
254
|
+
input when an option was selected. This functionality has been split between
|
|
255
|
+
`useComboboxInputArbitrary` and `useComboboxInputConstrained` depending on the combobox's value
|
|
256
|
+
type. The `useComboboxInput` had the arbitrary functionality built in. This has been separated out.
|
|
257
|
+
The `<Select>` component has been updated to use `useComboboxInputConstrained` hook and the
|
|
258
|
+
`Autocomplete` example uses the `useComboboxInputArbitrary` hook. This is a breaking change if you
|
|
259
|
+
use the `Combobox.Input` component directly. You'll have to either pass the
|
|
260
|
+
`useComboboxInputArbitrary` elemProps hook directly to the `<Combbox.Input>` or create a new
|
|
261
|
+
component composing them.
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
// v11
|
|
265
|
+
<Combobox>
|
|
266
|
+
<Combobox.Input />
|
|
267
|
+
// ...
|
|
268
|
+
</Combobox>
|
|
269
|
+
|
|
270
|
+
// v12
|
|
271
|
+
<Combobox>
|
|
272
|
+
<Combobox.Input elemPropsHook={useComboboxInputArbitrary} />
|
|
273
|
+
// ...
|
|
274
|
+
</Combobox>
|
|
275
|
+
|
|
276
|
+
// Better - create a specialized component
|
|
277
|
+
const useMyComboboxInput = composeHooks(
|
|
278
|
+
// or your own model that extends `useComboboxModel`
|
|
279
|
+
createElemPropsHook(useComboboxModel)(model => {
|
|
280
|
+
return {
|
|
281
|
+
// anything you need your input to do
|
|
282
|
+
}
|
|
283
|
+
}),
|
|
284
|
+
useComboboxInputArbitrary,
|
|
285
|
+
useComboboxInput
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
const MyComboboxInput = createSubcomponent(TextInput)({
|
|
289
|
+
// or your own model that extends `useComboboxModel`
|
|
290
|
+
modelHook: useComboboxModel,
|
|
291
|
+
elemPropsHook: useMyComboboxInput,
|
|
292
|
+
})((elemProps, Element) => {
|
|
293
|
+
// return a TextInput
|
|
294
|
+
return <Element {...elemProps} />
|
|
295
|
+
|
|
296
|
+
// return an InputGroupgs
|
|
297
|
+
return (
|
|
298
|
+
<InputGroup>
|
|
299
|
+
<InputGroup.InnerStart>{/* Icon or something */}</InputGroup.InnerStart>
|
|
300
|
+
<InputGroup.Input as={Element} {...elemProps} />
|
|
301
|
+
<InputGroup.InnerEnd><InputGroup.ClearButton /></InputGroup.InnerEnd>
|
|
302
|
+
</InputGroup>
|
|
303
|
+
)
|
|
304
|
+
})
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Form Field
|
|
308
|
+
|
|
309
|
+
<div style={{display: 'inline-flex', gap: '.5rem'}}>
|
|
310
|
+
<StatusIndicator variant="red" emphasis="low">
|
|
311
|
+
<StatusIndicator.Label>Breaking Change</StatusIndicator.Label>
|
|
312
|
+
</StatusIndicator>
|
|
313
|
+
<StatusIndicator variant="green" emphasis="low">
|
|
314
|
+
<StatusIndicator.Label>🤖 Codemod Available</StatusIndicator.Label>
|
|
315
|
+
</StatusIndicator>
|
|
316
|
+
</div>
|
|
317
|
+
|
|
318
|
+
**PRs:** [#2865](https://github.com/Workday/canvas-kit/pull/2865),
|
|
319
|
+
[#2881](https://github.com/Workday/canvas-kit/pull/2881),
|
|
320
|
+
[#2934](https://github.com/Workday/canvas-kit/pull/2934),
|
|
321
|
+
[#2973](https://github.com/Workday/canvas-kit/pull/2973)
|
|
322
|
+
|
|
323
|
+
We've promoted FormField from [Preview](#preview) to [Main](#main). The following changes has been
|
|
324
|
+
made to provide more flexibility and better explicit components when using inputs.
|
|
325
|
+
|
|
326
|
+
- The orientation prop on the `FormField` component will be updated to accept the following values:
|
|
327
|
+
`"vertical"`, `"horizontalStart"`, and `"horizontalEnd"`. `"horizontal"` will still be accepted as
|
|
328
|
+
a value in v12, but it will be deprecated and slated for removal in a future major release. These
|
|
329
|
+
changes are intended to provide more flexibility with label alignments on `FormField` elements.
|
|
330
|
+
|
|
331
|
+
> **Note**: The horizontal alignment of start and end are relative to its container, meaning start
|
|
332
|
+
> and end match the flex property of `flex-start` and `flex-end`. This is especially applicable for
|
|
333
|
+
> moving between RTL (right-to-left) and LTR (left-to-right) languages.
|
|
334
|
+
|
|
335
|
+
> **Note:** Orientation `"horizontal"` has been deprecated. You will see a console warn message
|
|
336
|
+
> suggesting to update your types and usage to `"horizontalStart"`, `"horizontalEnd"` or
|
|
337
|
+
> `"vertical"`.
|
|
338
|
+
|
|
339
|
+
- `useFormFieldModel`: `orientation` has been added back into `useFormFieldModel`. While we still
|
|
340
|
+
support compat mode due to
|
|
341
|
+
[style merging issues](https://github.com/Workday/canvas-kit/discussions/2893), having orientation
|
|
342
|
+
on the model allows for proper styling of sub components.
|
|
343
|
+
|
|
344
|
+
- Styles clean up: `FormField.Hint` and `FormField.Label` where using `margin` for spacing. We've
|
|
345
|
+
updated styles so that the containing element uses `gap` for proper spacing.
|
|
346
|
+
|
|
347
|
+
- We've added a new
|
|
348
|
+
[example](https://workday.github.io/canvas-kit/?path=/docs/examples-forms-density-and-alignment--docs)
|
|
349
|
+
to our docs to showcase how our inputs can be styled in different environments like density and
|
|
350
|
+
container alignment.
|
|
351
|
+
|
|
352
|
+
> **Note:** If spacing seems off between the input and hint text, ensure you're using
|
|
353
|
+
> `FormField.Field` wrapping your input and hint text.
|
|
354
|
+
|
|
355
|
+
##### Breaking API Change
|
|
356
|
+
|
|
357
|
+
The newly promoted `FormField` is a
|
|
358
|
+
[compound component](https://workday.github.io/canvas-kit/?path=/docs/guides-compound-components--docs).
|
|
359
|
+
Due to the different APIs of the component, this change is **not codemodable**. The following shows
|
|
360
|
+
an example of how to **update** your code to match the new compound component API.
|
|
361
|
+
|
|
362
|
+
```tsx
|
|
363
|
+
// v11 FormField in Main
|
|
364
|
+
<FormField
|
|
365
|
+
error={FormField.ErrorType.Alert}
|
|
366
|
+
labelPosition={FormField.LabelPosition.Left}
|
|
367
|
+
useFieldSet={true}
|
|
368
|
+
required={true}
|
|
369
|
+
inputId='input-id'
|
|
370
|
+
hintId="hint-alert"
|
|
371
|
+
hintText="Please enter a valid email."
|
|
372
|
+
label="Email"
|
|
373
|
+
>
|
|
374
|
+
<TextInput onChange={handleChange} value={value} />
|
|
375
|
+
</FormField>
|
|
376
|
+
|
|
377
|
+
// v12 Newly promoted FormField from Preview to Main
|
|
378
|
+
<FormField
|
|
379
|
+
error="alert"
|
|
380
|
+
orientation="horizontalStart"
|
|
381
|
+
isRequired={true}
|
|
382
|
+
id='input-id'
|
|
383
|
+
>
|
|
384
|
+
<FormField.Label>Email</FormField.Label>
|
|
385
|
+
<FormField.Field>
|
|
386
|
+
<FormField.Input as={TextInput} onChange={handleChange} value={value} />
|
|
387
|
+
<FormField.Hint>Please enter a valid email.</FormField.Hint>
|
|
388
|
+
</FormField.Field>
|
|
389
|
+
</FormField>
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
- `FormField.LabelPosition.Hidden` is no longer valid. If you still want to hide the label, use the
|
|
393
|
+
prop `isHidden`.
|
|
394
|
+
|
|
395
|
+
```tsx
|
|
396
|
+
// v11 FormField in Main
|
|
397
|
+
<FormField
|
|
398
|
+
error={FormField.ErrorType.Alert}
|
|
399
|
+
labelPosition={FormField.LabelPosition.Hidden}
|
|
400
|
+
useFieldSet={true}
|
|
401
|
+
required={true}
|
|
402
|
+
inputId="input-id"
|
|
403
|
+
label="Search"
|
|
404
|
+
>
|
|
405
|
+
<TextInput onChange={handleChange} value={value} />
|
|
406
|
+
</FormField>;
|
|
407
|
+
|
|
408
|
+
// v12 Newly promoted FormField from Preview to Main
|
|
409
|
+
|
|
410
|
+
//...
|
|
411
|
+
|
|
412
|
+
<FormField error="alert" orientation="horizontalStart" isRequired={true} id="input-id">
|
|
413
|
+
<FormField.Label isHidden>Search</FormField.Label>
|
|
414
|
+
<FormField.Field>
|
|
415
|
+
<FormField.Input as={TextInput} onChange={handleChange} value={value} />
|
|
416
|
+
</FormField.Field>
|
|
417
|
+
</FormField>;
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Noticeable changes:**
|
|
421
|
+
|
|
422
|
+
- `error` prop takes in the following values: `"error" | "alert"`.
|
|
423
|
+
- `labelPosition` becomes `orientation` with the following values:
|
|
424
|
+
`"horizontal" | "horizontalStart" | "horizontalEnd" | "vertical"`.
|
|
425
|
+
- `useFieldSet` is no longer valid. If you want to group inputs, use
|
|
426
|
+
[`FormFieldGroup`](#form-field-group) component.
|
|
427
|
+
- `required` becomes `isRequired`.
|
|
428
|
+
- `hintId` is no longer needed. The component handles associating the hint text, label and input
|
|
429
|
+
automatically. If you wish to have a unique `id`, you can add one onto the `FormField` element.
|
|
430
|
+
- `hintText` is no longer a valid prop. Use `FormField.Hint` sub-component.
|
|
431
|
+
- `errorLabel` and `alertLabel` are no longer valid props. Customize your hint text inside of
|
|
432
|
+
`FormField.Hint`.
|
|
433
|
+
- `label` is no longer a valid prop. Use `FormField.Label` sub component to render your label text.
|
|
434
|
+
- Instead of rendering an input, ensure you use `FormField.Input` with the `as` prop. This ensures
|
|
435
|
+
proper error handling and aria attributes for accessibility.
|
|
436
|
+
- `inputId` is no longer a valid prop. Use `id` if you want a custom `id`, otherwise, the component
|
|
437
|
+
will handle generating a unique id to associate each element for accessibility.
|
|
438
|
+
- `isHidden` has been added as a prop to `FormField.Label` in cases where you want to hide the label
|
|
439
|
+
while still meeting accessibility standards.
|
|
440
|
+
|
|
441
|
+
🤖 The codemod will handle the change of `orientation="horizontal"` to
|
|
442
|
+
`orientation="horizontalStart"` if you're using the string literal values. It will also handle
|
|
443
|
+
updating your imports from `@workday/canvas-kit-preview-react/form-field` to
|
|
444
|
+
`@workday/canvas-kit-react/form-field`.
|
|
445
|
+
|
|
446
|
+
#### Form Field Group
|
|
447
|
+
|
|
448
|
+
We've added a new component to the `FormField` package to allow users to group inputs without
|
|
449
|
+
worrying about setting the `as` prop on the `FormField` component.
|
|
450
|
+
|
|
451
|
+
Use `FormFieldGroup` when you have a group of inputs that need to be associated to one another, like
|
|
452
|
+
`RadioGroup` or a group of `Checkbox`'s.
|
|
453
|
+
|
|
454
|
+
`FormFieldGroup` supports the same props of `FormField`:
|
|
455
|
+
|
|
456
|
+
- `error`: `"alert" | "error"` Defines the error around the whole group of inputs.
|
|
457
|
+
- `orientation`: `"horizontalStart" | "horizontalEnd" | "vertical" | "horizontal" `. Defines the
|
|
458
|
+
label placement.
|
|
459
|
+
- `isRequired`: `true` Defines if a group like `RadioGroup` is required.
|
|
460
|
+
|
|
461
|
+
#### Form Field Field
|
|
462
|
+
|
|
463
|
+
We've added a new sub-component to `FormField` and `FormFieldGroup`, `FormField.Field` and
|
|
464
|
+
`FormFieldGroup.Field`. This sub-component is meant to ensure that the label is always aligned with
|
|
465
|
+
the input regardless of the `orientation`prop's value on`FormField` or `FormFieldGroup`. This
|
|
466
|
+
component should replace `FormField.Container` and always be used to ensure proper alignment of the
|
|
467
|
+
label and hint text. Our examples have been updated to reflect this.
|
|
468
|
+
|
|
469
|
+
Although there is no codemod for this change and it's non-breaking, we suggest moving towards adding
|
|
470
|
+
this sub-component when using `FormField`. This component also exists on `FormFieldGroup`.
|
|
471
|
+
|
|
472
|
+
```tsx
|
|
473
|
+
<FormField orientation="horizontal">
|
|
474
|
+
<FormField.Label>Email</FormField.Label>
|
|
475
|
+
<FormField.Field>
|
|
476
|
+
<FormField.Input as={TextInput} />
|
|
477
|
+
<FormField.Hint>You must provide an email</FormField.Hint>
|
|
478
|
+
</FormField.Field>
|
|
479
|
+
</FormField>
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Menu Item
|
|
483
|
+
|
|
484
|
+
**PR:** [2969](https://github.com/Workday/canvas-kit/pull/2969)
|
|
485
|
+
|
|
486
|
+
`Menu.Item` was converted to use Stencils for styling and uses `SystemIcon` stencil variables to
|
|
487
|
+
change icon color instead of deeply nested selectors. We also added `Menu.Option` component for
|
|
488
|
+
menus that have a selected visual state. `Menu.Option` will need more accessibility affordances that
|
|
489
|
+
depend on the nature of your use of the `Menu` component. For example, `<Combobox>` and `<Select>`
|
|
490
|
+
use `Menu.Option` and add keyboard events and `aria-*` attributes to function according to w3c
|
|
491
|
+
specifications.
|
|
492
|
+
|
|
493
|
+
We've deprecated the `isDisabled` prop. It didn't do anything in v10 or v11. It was part of the
|
|
494
|
+
preview Menu deprecation, but was never hooked up. We mapped it to `aria-disabled` and added a
|
|
495
|
+
deprecation comment to use `aria-disabled` instead.
|
|
496
|
+
|
|
497
|
+
We've removed the `MenuItemProps` export from `@workday/canvas-kit-react/menu`. Use
|
|
498
|
+
`ExtractProps<typeof Menu.Item, never>` instead. We don't mean to export prop interfaces of
|
|
499
|
+
polymorphic components. The `never` means "don't add element props". The second parameter is used to
|
|
500
|
+
pass the interface that the `as` prop is pointing to.
|
|
501
|
+
|
|
502
|
+
`Menu.Item` no longer sets `aria-selected` since that attribute is not valid on a `role=menuitem`.
|
|
503
|
+
The `Menu.Option` was added to support the role of a `role=option` for going inside a
|
|
504
|
+
`role=listbox`. The `Combobox` family of components uses a `role=listbox` for menu options. The
|
|
505
|
+
`Menu.Option` renders a checkmark for a visual indication of selected options.
|
|
506
|
+
|
|
507
|
+
### MultiSelect
|
|
508
|
+
|
|
509
|
+
**PR:** [2911](https://github.com/Workday/canvas-kit/pull/2911)
|
|
510
|
+
|
|
511
|
+
Added the `MultiSelect` component to select more than one option from a list of options. The
|
|
512
|
+
`MultiSelect` is similar in API to the `Select` component, except the values are comma delimited
|
|
513
|
+
with a space. If the ids represented are `['1', '2']`, then the string value of the form field is
|
|
514
|
+
`'1, 2'`.
|
|
515
|
+
|
|
516
|
+
### Search Form (Labs)
|
|
517
|
+
|
|
518
|
+
**PRs:** [#2934](https://github.com/Workday/canvas-kit/pull/2934),
|
|
519
|
+
|
|
520
|
+
`SearchForm` is now using the newly promoted `FormField` component. `SearchForm` now uses `labelId`
|
|
521
|
+
to set the appropiate aria attributes and `id` on the underlying input element.
|
|
522
|
+
|
|
523
|
+
### Select
|
|
524
|
+
|
|
525
|
+
**PRs:** [#2865](https://github.com/Workday/canvas-kit/pull/2865),
|
|
526
|
+
[#2983](https://github.com/Workday/canvas-kit/pull/2983)
|
|
527
|
+
|
|
528
|
+
As we transition to use our CSS tokens to provide better theming capabilities and our new styling
|
|
529
|
+
methods, we're moving away from components extending `Themeable`. `Themeable` has been removed from
|
|
530
|
+
`SelectProps.`
|
|
531
|
+
|
|
532
|
+
If you wish to theme `Select` we suggest using the `CanvasProvider` to do so.
|
|
533
|
+
|
|
534
|
+
```tsx
|
|
535
|
+
const theme: PartialEmotionCanvasTheme = {
|
|
536
|
+
canvas: {
|
|
537
|
+
palette: {
|
|
538
|
+
common: {
|
|
539
|
+
focusOutline: 'pink',
|
|
540
|
+
},
|
|
541
|
+
primary: {
|
|
542
|
+
main: 'green',
|
|
543
|
+
light: 'lightgreen',
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
},
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
//...
|
|
550
|
+
|
|
551
|
+
<CanvasProvider theme={theme}>
|
|
552
|
+
<Flex cs={parentContainerStyles}>
|
|
553
|
+
<Select items={options}>
|
|
554
|
+
<FormField>
|
|
555
|
+
<FormField.Label>Contact</FormField.Label>
|
|
556
|
+
<FormField.Input as={Select.Input} onChange={handleChange} />
|
|
557
|
+
<Select.Popper>
|
|
558
|
+
<Select.Card>
|
|
559
|
+
<Select.List>
|
|
560
|
+
{item => {
|
|
561
|
+
return <Select.Item>{item}</Select.Item>;
|
|
562
|
+
}}
|
|
563
|
+
</Select.List>
|
|
564
|
+
</Select.Card>
|
|
565
|
+
</Select.Popper>
|
|
566
|
+
</FormField>
|
|
567
|
+
</Select>
|
|
568
|
+
Selected Value: {value}
|
|
569
|
+
</Flex>
|
|
570
|
+
</CanvasProvider>;
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
`Select` has been refactored to use `useComboboxInputConstrained` to sync the model and the `input`
|
|
574
|
+
element regardless of the source. This makes the `Select` a controllable component.
|
|
575
|
+
|
|
576
|
+
### Text Area
|
|
577
|
+
|
|
578
|
+
**PR:** [#2825](https://github.com/Workday/canvas-kit/pull/2825)
|
|
579
|
+
|
|
580
|
+
`TextAreaResizeDirection` is no longer a TypeScript enum, but a JavaScript object. This change does
|
|
581
|
+
not effect runtime at all, but may cause TypeScript errors if you use `TextAreaResizeDirection` as a
|
|
582
|
+
type.
|
|
583
|
+
|
|
584
|
+
```tsx
|
|
585
|
+
// v11
|
|
586
|
+
interface MyProps {
|
|
587
|
+
resize?: TextAreaResizeDirection;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// v12
|
|
591
|
+
type ValueOf<T> = T[keyof T];
|
|
592
|
+
interface MyProps {
|
|
593
|
+
resize?: ValueOf<typeof TextAreaResizeDirection>;
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
`Themeable` has been removed from `TextAreaProps`. If you wish to theme `TextArea`, use our
|
|
598
|
+
`CanvasProvider` with the `theme` object.
|
|
599
|
+
|
|
600
|
+
```tsx
|
|
601
|
+
const theme: PartialEmotionCanvasTheme = {
|
|
602
|
+
canvas: {
|
|
603
|
+
palette: {
|
|
604
|
+
common: {
|
|
605
|
+
focusOutline: 'pink',
|
|
606
|
+
},
|
|
607
|
+
primary: {
|
|
608
|
+
main: 'green',
|
|
609
|
+
light: 'lightgreen',
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
//...
|
|
616
|
+
|
|
617
|
+
<CanvasProvider theme={theme}>
|
|
618
|
+
<FormField>
|
|
619
|
+
<FormField.Label>Contact</FormField.Label>
|
|
620
|
+
<FormField.Input as={TextArea} onChange={handleChange} />
|
|
621
|
+
</FormField>
|
|
622
|
+
</CanvasProvider>;
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
### Text Input
|
|
626
|
+
|
|
627
|
+
**PR:** [#2825](https://github.com/Workday/canvas-kit/pull/2825)
|
|
628
|
+
|
|
629
|
+
`Themeable` has been removed from `TextInputProps`. If you wish to theme `TextInput`, use our
|
|
630
|
+
`CanvasProvider` with the `theme` object.
|
|
631
|
+
|
|
632
|
+
```tsx
|
|
633
|
+
const theme: PartialEmotionCanvasTheme = {
|
|
634
|
+
canvas: {
|
|
635
|
+
palette: {
|
|
636
|
+
common: {
|
|
637
|
+
focusOutline: 'pink',
|
|
638
|
+
},
|
|
639
|
+
primary: {
|
|
640
|
+
main: 'green',
|
|
641
|
+
light: 'lightgreen',
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
//...
|
|
648
|
+
|
|
649
|
+
<CanvasProvider theme={theme}>
|
|
650
|
+
<FormField>
|
|
651
|
+
<FormField.Label>Contact</FormField.Label>
|
|
652
|
+
<FormField.Input as={TextInput} onChange={handleChange} />
|
|
653
|
+
</FormField>
|
|
654
|
+
</CanvasProvider>;
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
### Collections
|
|
658
|
+
|
|
659
|
+
**PR:** [#2982](https://github.com/Workday/canvas-kit/pull/2982)
|
|
660
|
+
|
|
661
|
+
The `navigation.getItem()` function can now return `undefined` instead of throwing an error when an
|
|
662
|
+
item is not found. Throwing an error caused lots of problems when it came to dynamic data. This is a
|
|
663
|
+
breaking change if your application uses `getItem`. It will now have to deal with the possibility of
|
|
664
|
+
an `undefined`.
|
|
665
|
+
|
|
666
|
+
## Utility Updates
|
|
667
|
+
|
|
668
|
+
**PR:** [#2908](https://github.com/Workday/canvas-kit/pull/2908)
|
|
669
|
+
|
|
670
|
+
### `mergeProps`
|
|
671
|
+
|
|
672
|
+
`mergeProps` had a bug where sometimes the returned props would be `never`. Also `mergeProps` would
|
|
673
|
+
not narrow types which would require you to add `as const`. We fixed the type signature to more
|
|
674
|
+
accurately reflect how `mergeProps` works. This may catch new type errors not caught before. There
|
|
675
|
+
is no way to codemod this. Let us know if you need help fixing new type errors introduced by this
|
|
676
|
+
change.
|
|
677
|
+
|
|
678
|
+
More information: https://github.com/Workday/canvas-kit/discussions/2979
|
|
679
|
+
|
|
680
|
+
### `createElemPropsHook`
|
|
681
|
+
|
|
682
|
+
`createElemPropsHook` now uses
|
|
683
|
+
[const Type Parameters](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters)
|
|
684
|
+
to narrow types in the object. This prevents requiring `as const` in some situations. This alone
|
|
685
|
+
should fix bugs instead of introduce them.
|
|
686
|
+
|
|
687
|
+
More information: https://github.com/Workday/canvas-kit/discussions/2979
|
|
688
|
+
|
|
689
|
+
### `composeHooks`
|
|
690
|
+
|
|
691
|
+
`composeHooks` uses `mergeProps` and suffered the same bugs. If any hook in the `composeHooks` chain
|
|
692
|
+
used a `null` prop, the entire prop object returned was typed as `never`. This caused a bug where if
|
|
693
|
+
the Component required a prop, it wasn't being provided by the composed hook. Some of our components
|
|
694
|
+
manually added to the component's prop interface so the component's render function wouldn't
|
|
695
|
+
complain. This has been fixed. This may be a breaking change where before the spread `elemProps` was
|
|
696
|
+
`never`, so no type conflicts could exist with component props. Now all props are properly
|
|
697
|
+
represented which may mean TypeScript is now catching bugs it didn't before.
|
|
698
|
+
|
|
699
|
+
More information: https://github.com/Workday/canvas-kit/discussions/2979
|
|
700
|
+
|
|
701
|
+
## Troubleshooting
|
|
702
|
+
|
|
703
|
+
### My Styles Seem Broken?
|
|
704
|
+
|
|
705
|
+
Our components are reliant on our new Canvas Tokens Web package. Be sure to install
|
|
706
|
+
`@workday/canvas-tokens-web`. For more information, reference our
|
|
707
|
+
[Getting Started docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)
|
|
708
|
+
for this package.
|
|
709
|
+
|
|
710
|
+
### Did You Upgrade All Canvas Kit Related Packages?
|
|
711
|
+
|
|
712
|
+
In order for all the packages to work in harmony, you must upgrade all Canvas Kit packages to the
|
|
713
|
+
same version that you're using, including:
|
|
714
|
+
|
|
715
|
+
- `@workday/canvas-kit-react`
|
|
716
|
+
- `@workday/canvas-kit-preview-react`
|
|
717
|
+
- `@workday/canvas-kit-labs-react`
|
|
718
|
+
- `@workday/canvas-kit-styling`
|
|
719
|
+
- `@workday/canvas-kit-react-fonts`
|
|
720
|
+
- `@workday/canvas-kit-docs`
|
|
721
|
+
|
|
722
|
+
## Glossary
|
|
723
|
+
|
|
724
|
+
### Main
|
|
725
|
+
|
|
726
|
+
Our Main package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-react` has
|
|
727
|
+
undergone a full design and a11y review and is approved for use in product.
|
|
728
|
+
|
|
729
|
+
Breaking changes to code in Main will only occur during major version updates and will always be
|
|
730
|
+
communicated in advance and accompanied by migration strategies.
|
|
731
|
+
|
|
732
|
+
---
|
|
733
|
+
|
|
734
|
+
### Preview
|
|
735
|
+
|
|
736
|
+
Our Preview package of Canvas Kit tokens, components, and utilities at
|
|
737
|
+
`@workday/canvas-kit-preview-react` has undergone a full design and a11y review and is approved for
|
|
738
|
+
use in product, but may not be up to the high code standards upheld in the [Main](#main) package.
|
|
739
|
+
Preview is analagous to code in beta.
|
|
740
|
+
|
|
741
|
+
Breaking changes are unlikely, but possible, and can be deployed to Preview at any time without
|
|
742
|
+
triggering a major version update, though such changes will be communicated in advance and
|
|
743
|
+
accompanied by migration strategies.
|
|
744
|
+
|
|
745
|
+
Generally speaking, our goal is to eventually promote code from Preview to [Main](#main).
|
|
746
|
+
Occasionally, a component with the same name will exist in both [Main](#main) and Preview (for
|
|
747
|
+
example, see Segmented Control in [Preview](/components/buttons/segmented-control/) and
|
|
748
|
+
[Main](https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/components-buttons-segmented-control--basic)).
|
|
749
|
+
In these cases, Preview serves as a staging ground for an improved version of the component with a
|
|
750
|
+
different API. The component in [Main](#main) will eventually be replaced with the one in Preview.
|
|
751
|
+
|
|
752
|
+
---
|
|
753
|
+
|
|
754
|
+
### Labs
|
|
755
|
+
|
|
756
|
+
Our Labs package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-labs-react`
|
|
757
|
+
has **not** undergone a full design and a11y review. Labs serves as an incubator space for new and
|
|
758
|
+
experimental code and is analagous to code in alpha.
|
|
759
|
+
|
|
760
|
+
Breaking changes can be deployed to Labs at any time without triggering a major version update and
|
|
761
|
+
may not be subject to the same rigor in communcation and migration strategies reserved for breaking
|
|
762
|
+
changes in [Preview](#preview) and [Main](#main).
|
|
763
|
+
`import { opacity } from "@workday/canvas-tokens-web/dist/es6/system"`
|
|
764
|
+
|
|
765
|
+
---
|
|
766
|
+
|
|
767
|
+
## Codemod Reference
|
|
768
|
+
|
|
769
|
+
# What is a Codemod?
|
|
770
|
+
|
|
771
|
+
A codemod is a script that makes programmatic transformations on your codebase by traversing the
|
|
772
|
+
[AST](https://www.codeshiftcommunity.com/docs/understanding-asts), identifying patterns, and making
|
|
773
|
+
prescribed changes. This greatly decreases opportunities for error and reduces the number of manual
|
|
774
|
+
updates, which allows you to focus on changes that need your attention. **We highly recommend you
|
|
775
|
+
use the codemod for these reasons.**
|
|
776
|
+
|
|
777
|
+
If you're new to running codemods or if it's been a minute since you've used one, there are a few
|
|
778
|
+
things you'll want to keep in mind.
|
|
779
|
+
|
|
780
|
+
- Our codemods are meant to be run sequentially. For example, if you're using v8 of Canvas Kit,
|
|
781
|
+
you'll need to run the v9 codemod before you run v10 and so on.
|
|
782
|
+
- The codemod will update your code to be compatible with the specified version, but it will **not**
|
|
783
|
+
remove outdated dependencies or upgrade dependencies to the latest version. You'll need to upgrade
|
|
784
|
+
dependencies on your own.
|
|
785
|
+
- We recommend upgrading dependencies before running the codemod.
|
|
786
|
+
- Always review your `package.json` files to make sure your dependency versions look correct.
|
|
787
|
+
- The codemod will not handle every breaking change in v13. You will likely need to make some manual
|
|
788
|
+
changes to be compatible. Use our Upgrade Guide as a checklist.
|
|
789
|
+
- Codemods are not bulletproof.
|
|
790
|
+
- Conduct a thorough PR and QA review of all changes to ensure no regressions were introduced.
|
|
791
|
+
- As a safety precaution, we recommend committing the changes from the codemod as a single
|
|
792
|
+
isolated commit (separate from other changes) so you can roll back more easily if necessary.
|
|
793
|
+
|
|
794
|
+
We're here to help! Automatic changes to your codebase can feel scary. You can always reach out to
|
|
795
|
+
our team. We'd be very happy to walk you through the process to set you up for success.
|
|
796
|
+
|
|
797
|
+
## Running a Codemod
|
|
798
|
+
|
|
799
|
+
### Instructions
|
|
800
|
+
|
|
801
|
+
The easiest way to run our codemod is to use `npx` in your terminal.```sh
|
|
802
|
+
npx @workday/canvas-kit-codemod v${canvasKitMajorVersionNumber} [path]
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
Be sure to provide specific directories that need to be updated via the `[path]` argument. This
|
|
806
|
+
decreases the amount of AST the codemod needs to traverse and reduces the chances of the script
|
|
807
|
+
having an error. For example, if your source code lives in `src/`, use `src/` as your `[path]`. Or,
|
|
808
|
+
if you have a monorepo with three packages using Canvas Kit, provide those specific packages as your
|
|
809
|
+
`[path]`.
|
|
810
|
+
|
|
811
|
+
Alternatively, if you're unable to run the codemod successfully using `npx`, you can install the
|
|
812
|
+
codemod package as a dev dependency, run it with `yarn`, and then remove the package after you're
|
|
813
|
+
finished.
|
|
814
|
+
|
|
815
|
+
```sh
|
|
816
|
+
yarn add @workday/canvas-kit-codemod --dev
|
|
817
|
+
yarn canvas-kit-codemod v${canvasKitMajorVersion} [path]
|
|
818
|
+
yarn remove @workday/canvas-kit-codemod
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
> **Note**: The codemod only works on `.js`, `.jsx`, `.ts`, and `.tsx` files. You'll need to
|
|
822
|
+
> manually edit other file types (`.json`, `.mdx`, `.md`, etc.). You may need to run your linter
|
|
823
|
+
> after executing the codemod, as its resulting formatting (spacing, quotes, etc.) may not match
|
|
824
|
+
> your project conventions.
|
|
825
|
+
|
|
826
|
+
## Codemod Transformations for v12
|
|
827
|
+
|
|
828
|
+
The following automated transformations are available for upgrading to v12:
|
|
829
|
+
|
|
830
|
+
- **Promote Form Field**: promoteFormField
|
|
831
|
+
- **Rename Form Field Horizontal**: renameFormFieldHorizontal
|
|
832
|
+
|
|
833
|
+
Run the codemod with: `npx @workday/canvas-kit-codemod v12 [path]`
|