@staffbase/design 20.4.0 → 21.2.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/codemods/v21-migrate-toggle/README.md +52 -0
- package/codemods/v21-migrate-toggle/transform.js +99 -0
- package/dist/components.css +1 -1
- package/dist/main.cjs +137 -157
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.ts +72 -111
- package/dist/main.js +137 -154
- package/dist/main.js.map +1 -1
- package/dist/theme.css +4 -1
- package/dist/tokens/component.css +4 -3
- package/dist/tokens/primitive.css +9 -16
- package/dist/tokens/semantic.css +50 -46
- package/package.json +6 -8
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# v21 — Breaking-change migrations
|
|
2
|
+
|
|
3
|
+
This codemod handles the breaking change to `Toggle` introduced in v21 of `@staffbase/design`.
|
|
4
|
+
|
|
5
|
+
## What it transforms
|
|
6
|
+
|
|
7
|
+
### Toggle → SwitchDeprecated
|
|
8
|
+
|
|
9
|
+
`Toggle` is now a new button-style toggle component. The old switch-style Toggle has been renamed to `SwitchDeprecated`.
|
|
10
|
+
|
|
11
|
+
| Before (v20) | After (v21) |
|
|
12
|
+
| ------------------------------------------------- | ----------------------------------------------------------- |
|
|
13
|
+
| `import { Toggle } from '@staffbase/design'` | `import { SwitchDeprecated } from '@staffbase/design'` |
|
|
14
|
+
| `import { ToggleProps } from '@staffbase/design'` | `import { SwitchDeprecatedProps } from '@staffbase/design'` |
|
|
15
|
+
| `<Toggle … />` | `<SwitchDeprecated … />` |
|
|
16
|
+
| `const props: ToggleProps` | `const props: SwitchDeprecatedProps` |
|
|
17
|
+
|
|
18
|
+
Aliased imports are handled — only the imported binding is renamed, the local alias is preserved:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
// Before
|
|
22
|
+
import { Toggle as MyToggle } from '@staffbase/design';
|
|
23
|
+
<MyToggle … />
|
|
24
|
+
|
|
25
|
+
// After (local alias unchanged)
|
|
26
|
+
import { SwitchDeprecated as MyToggle } from '@staffbase/design';
|
|
27
|
+
<MyToggle … />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Step 1 — Install jscodeshift
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install --save-dev jscodeshift
|
|
36
|
+
# or
|
|
37
|
+
pnpm add -D jscodeshift
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Step 2 — Run the codemod
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx jscodeshift@latest \
|
|
44
|
+
--transform node_modules/@staffbase/design/codemods/v21-migrate-toggle/transform.js \
|
|
45
|
+
--extensions tsx,ts \
|
|
46
|
+
--parser tsx \
|
|
47
|
+
src/
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Step 3 — Migrate to the new Toggle (optional but recommended)
|
|
51
|
+
|
|
52
|
+
After running this codemod your code compiles again, but `SwitchDeprecated` will be removed in a future release. Consider migrating to the new [`Switch`](https://design.staffbase.com/components/switch) component combined with [`Field`](https://design.staffbase.com/components/field) when you're ready.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jscodeshift codemod: v21 breaking-change migrations.
|
|
3
|
+
*
|
|
4
|
+
* 1. Rename old Toggle to SwitchDeprecated:
|
|
5
|
+
* import { Toggle } from '@staffbase/design'
|
|
6
|
+
* → import { SwitchDeprecated } from '@staffbase/design'
|
|
7
|
+
*
|
|
8
|
+
* import { ToggleProps } from '@staffbase/design'
|
|
9
|
+
* → import { SwitchDeprecatedProps } from '@staffbase/design'
|
|
10
|
+
*
|
|
11
|
+
* <Toggle ... /> → <SwitchDeprecated ... />
|
|
12
|
+
*
|
|
13
|
+
* const props: ToggleProps → const props: SwitchDeprecatedProps
|
|
14
|
+
*
|
|
15
|
+
* If Toggle/ToggleProps was aliased locally the local name is preserved:
|
|
16
|
+
* import { Toggle as MyToggle } → import { SwitchDeprecated as MyToggle }
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* npx jscodeshift@latest \
|
|
20
|
+
* --transform node_modules/@staffbase/design/codemods/v21-migrate-toggle/transform.js \
|
|
21
|
+
* --extensions tsx,ts \
|
|
22
|
+
* --parser tsx \
|
|
23
|
+
* src/
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const DESIGN_PKG = '@staffbase/design';
|
|
27
|
+
|
|
28
|
+
export default function transform(file, api) {
|
|
29
|
+
const j = api.jscodeshift;
|
|
30
|
+
const root = j(file.source);
|
|
31
|
+
let dirty = false;
|
|
32
|
+
|
|
33
|
+
// Bail early if there are no @staffbase/design imports.
|
|
34
|
+
const designImports = root.find(j.ImportDeclaration, {source: {value: DESIGN_PKG}});
|
|
35
|
+
if (!designImports.length) return undefined;
|
|
36
|
+
|
|
37
|
+
// 1. Find the `Toggle` and `ToggleProps` import specifiers.
|
|
38
|
+
let localName = null;
|
|
39
|
+
let localPropsName = null;
|
|
40
|
+
|
|
41
|
+
designImports.find(j.ImportSpecifier).forEach((spec) => {
|
|
42
|
+
const importedName = spec.node.imported.name;
|
|
43
|
+
|
|
44
|
+
if (importedName === 'Toggle') {
|
|
45
|
+
localName = spec.node.local ? spec.node.local.name : 'Toggle';
|
|
46
|
+
const hasAlias = localName !== 'Toggle';
|
|
47
|
+
|
|
48
|
+
spec.node.imported.name = 'SwitchDeprecated';
|
|
49
|
+
|
|
50
|
+
if (!hasAlias) {
|
|
51
|
+
spec.node.local = j.identifier('SwitchDeprecated');
|
|
52
|
+
localName = 'SwitchDeprecated';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
dirty = true;
|
|
56
|
+
} else if (importedName === 'ToggleProps') {
|
|
57
|
+
localPropsName = spec.node.local ? spec.node.local.name : 'ToggleProps';
|
|
58
|
+
const hasAlias = localPropsName !== 'ToggleProps';
|
|
59
|
+
|
|
60
|
+
spec.node.imported.name = 'SwitchDeprecatedProps';
|
|
61
|
+
|
|
62
|
+
if (!hasAlias) {
|
|
63
|
+
spec.node.local = j.identifier('SwitchDeprecatedProps');
|
|
64
|
+
localPropsName = 'SwitchDeprecatedProps';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
dirty = true;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// 2. Rename all JSX usages only when there was no alias (alias keeps its
|
|
72
|
+
// local name unchanged, so no JSX rename is needed).
|
|
73
|
+
if (localName === 'SwitchDeprecated') {
|
|
74
|
+
root
|
|
75
|
+
.find(j.JSXIdentifier, {name: 'Toggle'})
|
|
76
|
+
.filter((path) => {
|
|
77
|
+
return path.parent.node.type === 'JSXOpeningElement' || path.parent.node.type === 'JSXClosingElement';
|
|
78
|
+
})
|
|
79
|
+
.forEach((path) => {
|
|
80
|
+
path.node.name = 'SwitchDeprecated';
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 3. Rename ToggleProps type references when there was no alias.
|
|
85
|
+
if (localPropsName === 'SwitchDeprecatedProps') {
|
|
86
|
+
root.find(j.Identifier, {name: 'ToggleProps'}).forEach((path) => {
|
|
87
|
+
const parentType = path.parent.node.type;
|
|
88
|
+
if (
|
|
89
|
+
parentType === 'TSTypeReference' ||
|
|
90
|
+
parentType === 'TSTypeAliasDeclaration' ||
|
|
91
|
+
parentType === 'TSInterfaceHeritage'
|
|
92
|
+
) {
|
|
93
|
+
path.node.name = 'SwitchDeprecatedProps';
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return dirty ? root.toSource() : undefined;
|
|
99
|
+
}
|