You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,3 +103,66 @@ Components follow a consistent pattern:
103
103
-**Conventional Commits**: Follow conventional commit format for semantic releases
104
104
-**Accessibility**: All components must be accessible and support keyboard navigation
105
105
-**Storybook**: Every component requires comprehensive stories showing all variants
106
+
107
+
## Vanilla Extract Migration Guidelines
108
+
109
+
When working with vanilla-extract components during the migration:
110
+
111
+
### Component Isolation Rule
112
+
113
+
**CRITICAL:** Never mix Stitches and vanilla-extract components. Always use vanilla-extract versions of components inside vanilla-extract components.
114
+
115
+
```tsx
116
+
// ❌ Wrong - mixing Stitches and vanilla-extract
117
+
import { Box } from'../Box';
118
+
import { Label } from'../Label';
119
+
<Boxcss={css}>...</Box>;
120
+
121
+
// ✅ Correct - use vanilla versions or plain HTML
122
+
import { BoxVanilla } from'../Box';
123
+
import { LabelVanilla } from'../Label';
124
+
<BoxVanillacss={css}>...</BoxVanilla>;
125
+
```
126
+
127
+
**Why:** Stitches components expect Stitches `CSS` type, but vanilla components use `CSSProps` type. Mixing them causes type errors and architectural inconsistency.
128
+
129
+
**When vanilla version doesn't exist:** Use plain HTML elements (`<div>`, `<span>`, etc.) with manual style processing.
130
+
131
+
### CSSProps Type System
132
+
133
+
Understanding the `CSSProps` interface is crucial for proper type safety:
134
+
135
+
**Key Pattern - `CSSProps['css']` vs `CSSProps`:**
Without `NonNullable`, TypeScript may treat the variants as `undefined`, causing errors like "Property 'size' does not exist on type 'MyComponentVariants'".
968
+
969
+
#### Problem: Stitches components used in vanilla components cause type errors
970
+
971
+
**CRITICAL RULE:** Never mix Stitches and vanilla-extract components. Always use vanilla-extract versions inside vanilla components.
972
+
973
+
```tsx
974
+
// ❌ Bad - Type error: CSSProps not assignable to Stitches CSS type
975
+
import { Box } from'../Box';
976
+
import { Label } from'../Label';
977
+
<Boxcss={rootCss}>...</Box>
978
+
<Labelvariant={variant}>...</Label>
979
+
980
+
// ✅ Good - Use vanilla-extract components
981
+
import { BoxVanilla } from'../Box';
982
+
import { LabelVanilla } from'../Label';
983
+
<BoxVanillacss={rootCss}>...</BoxVanilla>
984
+
<LabelVanillavariant={variant}>...</LabelVanilla>
985
+
986
+
// ✅ Also good - Use plain HTML when vanilla version doesn't exist
987
+
<divstyle={rootMergedStyles}>...</div>
988
+
```
989
+
990
+
**Why this matters:**
991
+
992
+
- Stitches components expect Stitches `CSS` type
993
+
- Vanilla components use vanilla-extract `CSSProps` type
994
+
- Mixing them causes TypeScript errors and architectural inconsistency
995
+
- Always prefer vanilla-extract components (`BoxVanilla`, `LabelVanilla`, etc.) over plain HTML for consistency
996
+
997
+
**Real-world example from TextField migration:**
998
+
999
+
```tsx
1000
+
// Before (wrong):
1001
+
import { Box } from'../Box';
1002
+
import { Label } from'../Label';
1003
+
1004
+
// After (correct):
1005
+
import { BoxVanilla } from'../Box';
1006
+
import { LabelVanilla } from'../Label';
953
1007
```
954
1008
1009
+
#### Problem: Props typed as `CSSProps` require `as any` in tests
1010
+
1011
+
If you see `as any` being used to pass CSS properties to a component prop, this indicates a type mismatch.
1012
+
1013
+
**Root cause:** The prop is typed as `CSSProps` but should be `CSSProps['css']`.
0 commit comments