Skip to content

Commit 1b4e1ae

Browse files
committed
refactor(ui-codemods): add codemod to remove the 'as' prop from InstUISettingsProvider
also some smaller refactoringa to codemods INSTUI-4113
1 parent dabd148 commit 1b4e1ae

File tree

26 files changed

+373
-132
lines changed

26 files changed

+373
-132
lines changed
File renamed without changes.

docs/contributor-docs/v11-upgrade-guide.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ isWIP: true
77

88
# Upgrade Guide for Version 11 (WIP)
99

10-
## Removal of deprecated props/components
10+
## Removal of deprecated props/components/APIs
11+
12+
### InstUISettingsProvider
13+
14+
[InstUISettingsProvider](/#InstUISettingsProvider)'s `as` prop was removed, it will always render as a `<span>` (note: it will only render anything to the DOM if you provide a value to the `dir` prop.). The provided codemod will remove this prop automatically (see below).
1115

1216
### Table
1317

@@ -22,13 +26,31 @@ isWIP: true
2226

2327
### Theming engine changes
2428

25-
| Deprecation | What to use instead? |
26-
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
27-
| `canvas.use()`, `canvasHighContrast.use()` | Wrap all your application roots in `<InstUISettingsProvider>` |
28-
| `variables` field on theme objects | Use the fields from the object above, e.g. use `canvas.borders` instead of `canvas.variables.borders` |
29-
| `@instructure/theme-registry` package | This added the deprecated functions above. Wrap all your application roots in `<InstUISettingsProvider>` |
29+
| Deprecation | What to use instead? |
30+
| ------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
31+
| `canvas.use()`, `canvasHighContrast.use()` | Wrap all your application roots in `<InstUISettingsProvider>` |
32+
| `variables` field on theme objects | Use `canvas.borders` instead of `canvas.variables.borders` (same for all othere fields) |
33+
| `@instructure/theme-registry` package | This added the removed functions above. Wrap all your application roots in `<InstUISettingsProvider>` |
3034

31-
## Changes
35+
## API Changes
3236

3337
- `ui-dom-utils`/`getComputedStyle` can now return `undefined`: In previous versions sometimes returned an empty object which could lead to runtime exceptions when one tried to call methods of `CSSStyleDeclaration` on it.
3438
- TO-DO: [TimeSelect](/#TimeSelect) as a controlled component can now return an '' instead of a valid date when its input field is cleared. In previous versions it always reverted to the last selected value when the input field was cleared and lost focus.
39+
40+
## Codemods
41+
42+
To ease the upgrade we provide codemods that will automate most of the changes. Pay close attention to its output, it cannot refactor complex code! The codemod scripts can be run via the following commands:
43+
44+
```sh
45+
---
46+
type: code
47+
---
48+
npm install @instructure/ui-codemods@11
49+
npx [email protected] -t node_modules/@instructure/ui-codemods/lib/instUIv11Codemods.ts <path> --usePrettier=false
50+
```
51+
52+
Options for the codemod:
53+
54+
- `filename`: if specified then emitted warnings are written to this file.
55+
- `usePrettier`: if `true` the transformed code will be run through Prettier. You can customize this through a [Prettier
56+
config file](https://prettier.io/docs/configuration.html)

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const finalConfig = tseslint.config(
7676
// https://github.com/eslint/eslint/discussions/18304#discussioncomment-9069706
7777
ignores: [ // global ignores
7878
"**/node_modules/**",
79+
"packages/ui-codemods/lib/__node_tests__/__testfixtures__/**",
7980
"**/types/**",
8081
"**/es/**",
8182
"packages/!(" + NODE_PACKAGES + ")/lib/**/*",

packages/__docs__/src/Hero/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class Hero extends Component<HeroProps> {
309309
</Flex>
310310
<List isUnstyled margin="small none none">
311311
<List.Item>
312-
<Link href="#v10-upgrade-guide">Version 10 Upgrade Guide</Link>
312+
<Link href="#upgrade-guide">Version 10 Upgrade Guide</Link>
313313
</List.Item>
314314
<List.Item>
315315
<Link href="#CHANGELOG">Change Log ({version})</Link>
@@ -486,7 +486,7 @@ class Hero extends Component<HeroProps> {
486486
<Button
487487
focusColor="inverse"
488488
color="success"
489-
href="#v10-upgrade-guide"
489+
href="#upgrade-guide"
490490
size={bigScreen ? 'large' : 'medium'}
491491
margin="0 x-small x-small 0"
492492
>

packages/emotion/src/InstUISettingsProvider/README.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,3 @@ type: example
9595
<div>LTR text</div>
9696
</InstUISettingsProvider>
9797
```
98-
99-
### Server Side Rendering support
100-
101-
The `instanceCounterMap` prop is used for deterministic id generation. The prop accepts a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) (generated by the `generateInstanceCounterMap` util) that keeps the id-s of the components in sync on both the frontend and backend.
102-
103-
See more info on the [Server Side Rendering (SSR)](/#server-side-rendering) docs page.
104-
105-
```jsx
106-
---
107-
type: code
108-
---
109-
import { InstUISettingsProvider } from '@instructure/emotion'
110-
import { generateInstanceCounterMap } from '@instructure/ui-react-utils'
111-
112-
const counter = generateInstanceCounterMap()
113-
counter.set('Alert', 5)
114-
;<InstUISettingsProvider instanceCounterMap={counter}>
115-
// this Alert's rendered DOM Node will have [id="Alert_5"] on it
116-
<Alert>Test!</Alert>
117-
</InstUISettingsProvider>
118-
```

packages/emotion/src/InstUISettingsProvider/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ type InstUIProviderProps = {
6161
*/
6262
dir: 'ltr' | 'rtl'
6363
/**
64-
* @deprecated remove in v11
64+
* @deprecated This prop will be removed in InstUI v11
65+
*
6566
* The element type to render as
6667
*/
6768
as?: AsElementType
6869
}
6970
| {
7071
dir?: never
7172
/**
72-
* @deprecated remove in v11
73+
* @deprecated This prop will be removed in InstUI v11
74+
*
7375
* The element type to render as
7476
*/
7577
as?: never

packages/ui-codemods/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ The codemod scripts can be installed via the following command:
1919
type: code
2020
---
2121
# use here the InstUI version number you are upgrading to
22-
npm install @instructure/ui-codemods@10
22+
npm install @instructure/ui-codemods@11
2323
```
2424

25-
### Codemod for changing the color palette to the v10 color palette
25+
Then run them with `jscodeshift`:
2626

2727
```sh
2828
---
2929
type: code
3030
---
31-
npx [email protected] -t node_modules/@instructure/ui-codemods/lib/updateV10Breaking.ts <path> --usePrettier=false
31+
# substitute updateV10Breaking with the codemod name you want to run
32+
npx jscodeshift@latest -t node_modules/@instructure/ui-codemods/lib/updateV10Breaking.ts <path>
3233
```
3334

34-
This codemod updates the `canvas` and `canvas-high-contrast` color palettes. Execute this in your project post-upgrade to InstUI v10. Prettier is turned on by default for output formatting, and you can also use the `usePrettier` flag.
35+
For more information about what the codemods do, see the [major version upgrade guides](#upgrade-guide)
3536

3637
[npm]: https://img.shields.io/npm/v/@instructure/ui-codemods.svg
3738
[npm-url]: https://npmjs.com/package/@instructure/ui-codemods

packages/ui-codemods/lib/__node_tests__/__testfixtures__/kiscica/colors.input.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/ui-codemods/lib/__node_tests__/__testfixtures__/kiscica/colors.output.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @ts-nocheck
2+
3+
import { InstUISettingsProvider as ABC } from '@instructure/emotion'
4+
import { Button } from '@instructure/ui-buttons'
5+
6+
function asd() {
7+
const a = (
8+
<ABC
9+
as="div"
10+
theme={{
11+
componentOverrides: {
12+
AppNav: { borderWidth: 0 },
13+
'AppNav.Item': {
14+
as: 23,
15+
fontWeight: 400,
16+
textColor: 'white',
17+
textColorSelected: 'white'
18+
}
19+
}
20+
}}
21+
>
22+
as
23+
<Button as="div" />
24+
</ABC>
25+
)
26+
27+
return (
28+
<ABC as={callHereAFunction('as')} dir="rtl">
29+
as
30+
<div dir="rtl">as</div>
31+
</ABC>
32+
)
33+
}

0 commit comments

Comments
 (0)