-
Notifications
You must be signed in to change notification settings - Fork 15
Migrate Separator and Spacer to SCSS modules #731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Refactored Separator and Spacer components to use SCSS modules for styling instead of styled-components. Added new SCSS files, updated Storybook configuration and preview to support SCSS, and introduced a script to generate a filtered CSS theme for SCSS-migrated components. Updated package.json, .gitignore, and index.ts to ensure proper CSS variable imports and side effects. Also added utility functions and mixins for SCSS, and improved Storybook controls for these components.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the Separator and Spacer components from styled-components to SCSS modules as the first step in a broader SCSS migration strategy. The changes introduce SCSS infrastructure, build tooling, and utility functions to support this transition while maintaining compatibility with the existing design system.
Key changes:
- Refactored Separator and Spacer components to use SCSS modules with CSS variables
- Added SCSS build infrastructure including mixins, variants, and theme generation
- Updated Storybook configuration to support SCSS compilation
Reviewed changes
Copilot reviewed 23 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| vite.config.ts | Added copyCSSPlugin to bundle SCSS theme CSS and configured SCSS import aliases |
| src/utils/capitalize.ts | Added utility function to convert strings and kebab-case to PascalCase |
| src/utils/capitalize.test.ts | Added comprehensive test coverage for capitalize utility |
| src/theme/tokens/variables.json | Reordered JSON properties and updated color values (no functional changes) |
| src/theme/tokens/types.ts | Reordered TypeScript interface properties to match JSON structure |
| src/styles/cui.css | Added main CSS entry point with theme imports |
| src/styles/cui-scss-theme.css | Generated filtered CSS variables for SCSS-migrated components |
| src/styles/_mixins.scss | Added comprehensive SCSS mixins library for component styling |
| src/styles/_cui-variants.scss | Added SCSS variant mixins using :where() for low specificity |
| src/index.ts | Added auto-import of SCSS theme CSS |
| src/components/Typography/Text/Text.tsx | Fixed TypeScript type casting for forwardRef |
| src/components/Spacer/Spacer.tsx | Migrated from styled-components to SCSS modules |
| src/components/Spacer/Spacer.stories.tsx | Updated story controls and removed TypeScript story types |
| src/components/Spacer/Spacer.module.scss | Added SCSS module with size variants |
| src/components/Separator/Separator.tsx | Migrated from Radix primitives to SCSS with semantic HTML |
| src/components/Separator/Separator.stories.tsx | Updated story controls and removed TypeScript story types |
| src/components/Separator/Separator.module.scss | Added SCSS module with orientation and size variants |
| scripts/generate-scss-theme.js | Added script to generate filtered CSS theme for migrated components |
| package.json | Added SCSS dependencies, sideEffects field, and CSS export path |
| build-tokens.js | Removed lodash dependency, implemented custom setWith function |
| .storybook/preview.tsx | Migrated ThemeBlock from styled-components to SCSS module |
| .storybook/preview.module.scss | Added SCSS module for Storybook preview layout |
| .storybook/main.ts | Added SCSS preprocessor configuration with modern-compiler API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactored ThemeBlock in Storybook to accept a theme prop and set color-scheme for better light/dark support. Updated SCSS theme generation script to always include Storybook-specific variables. Added --click-storybook-global-background to SCSS theme and improved preview styles for better layout handling.
Added a useEffect to update the document root's color-scheme and data-theme attributes based on the selected theme. This enables support for the CSS light-dark() function and improves theme handling.
gjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall functionality is good. So 👍
There's quite a few changes to the build-tokens.js file in here, I'm unsure why they would be in with the separator and spacer updates. What do they do?
Regenerated yarn.lock to update and add new package versions, reflecting changes in project dependencies. This may include upgrades, security patches, or compatibility improvements.
Updated SCSS files for Separator and Spacer components to replace CSS custom properties with SCSS tokens variables for consistency and maintainability. Added data-cui attributes to both components for improved DOM identification and testing.
Removed legacy CSS files and replaced them with SCSS modules for global and app styles. Updated imports and file references throughout the codebase to use SCSS. Deleted the generate-scss-theme script and filtered theme CSS, as SCSS modules now handle component styling. Updated documentation to clarify CSS import requirements and migration status.
Removed legacy global CSS files and updated styles to use SCSS modules. Updated Storybook and Vite configuration for modern SCSS compiler support. Cleaned up README and code references to legacy CSS imports, and improved VSCode TypeScript settings.
Moved SCSS preprocessor configuration to root vite.config.ts to prevent CSS injection order issues with styled-components. Storybook now inherits SCSS settings from the main Vite config.
Set `cssCodeSplit` to false in Storybook Vite config to ensure styled-components styles are injected after CSS modules. This resolves specificity problems when using the polymorphic 'as' prop in components.
ariser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm in general, but I'm not sure why we need these variant mixins
| * capitalize('space-between') // 'SpaceBetween' | ||
| * capitalize('space-around') // 'SpaceAround' | ||
| */ | ||
| export const capitalize = (str: string): string => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the naming is ambiguous
toPascalCase, toUpperCamelCase?
or even kebabToPascalCase, as it expects input to be in a specific format
| @include variants.variant('cuiHorizontal') { | ||
| width: 100%; | ||
| border-top: 0.0625rem solid tokens.$clickSeparatorColorStrokeDefault; | ||
|
|
||
| @include variants.variant('cuiSizeXs') { | ||
| margin: tokens.$clickSeparatorHorizontalSpaceYXs tokens.$clickSeparatorHorizontalSpaceXAll; | ||
| } | ||
| @include variants.variant('cuiSizeSm') { | ||
| margin: tokens.$clickSeparatorHorizontalSpaceYSm tokens.$clickSeparatorHorizontalSpaceXAll; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll have to walk me though this
why do we need these mixins instead of simply writing
.cuiSeparator {
&.cuiHorizontal {
...
&.cuiSizeXs {
...
}
}
}?
and if we are creating these utils, the least they can do is allow us to not include this cui prefix all the time
| display: flex; | ||
|
|
||
| @include variants.variant('cuiSizeXs') { | ||
| padding: tokens.$clickSpacerHorizontalSpaceYXs tokens.$clickSpacerHorizontalSpaceXAll; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand this right, all SCSS tokens are actually pointing at native CSS variables? So on the consumer side, we're free to override any css variable value to adjust the styles if we need?
Refactored Separator and Spacer components to use SCSS modules for styling instead of styled-components. Added new SCSS files, updated Storybook configuration and preview to support SCSS, and introduced a script to generate a filtered CSS theme for SCSS-migrated components. Updated package.json, .gitignore, and index.ts to ensure proper CSS variable imports and side effects. Also added utility functions and mixins for SCSS, and improved Storybook controls for these components.
Note: This is the first step to migrating components to scss one