Skip to content

Cleanup styled-components in *.stories.tsx files and convert to CSS modules #6197

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 11, 2025

This PR removes all styled-components imports from story files and converts them to use CSS modules, following the established pattern in the codebase as outlined in ADR-016.

Changes Made

Files Updated

  • 8 story files migrated from styled-components to CSS modules
  • 7 new CSS module files created following established patterns

Specific Conversions

ActionList/ActionMenu Stories:

  • Replaced ErsatzOverlay styled div with CSS module class
  • Replaced StyledDiv components that used sx prop with Box component + CSS classes

LabelGroup Stories:

  • Replaced ResizableContainer styled div with CSS module class

Hook Stories (useFocusZone, useFocusTrap, useAnchoredPosition, ThemeProvider):

  • Replaced MarginButton styled Button components with CSS module classes
  • Converted createGlobalStyle usage to inline <style> components for demo purposes
  • Replaced complex styled components (Float, Anchor, Nav, Main) with CSS module classes

CSS Module Pattern

All new CSS modules follow the established conventions:

  • Use @layer primer.stories.<story-name> for proper CSS layering
  • Utilize CSS custom properties for theming (e.g., var(--bgColor-default))
  • Maintain original styling behavior while eliminating runtime style generation

Benefits

  • Performance improvement: No runtime CSS-in-JS generation for story components
  • Consistency: Aligns with the migration strategy outlined in ADR-016
  • Maintainability: Explicit CSS dependencies and standard CSS authoring

Verification

  • ✅ All linting passes
  • ✅ Build completes successfully
  • ✅ Storybook starts without errors
  • ✅ No styled-components imports remain in any *.stories.tsx files

Fixes #6196.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

changeset-bot bot commented Jun 11, 2025

⚠️ No Changeset found

Latest commit: 420f132

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Copilot Copilot AI changed the title [WIP] Cleanup styled-components in *.stories.tsx files Cleanup styled-components in *.stories.tsx files and convert to CSS modules Jun 11, 2025
@Copilot Copilot AI requested a review from jonrohan June 11, 2025 19:56
Copilot finished work on behalf of jonrohan June 11, 2025 19:56
@@ -0,0 +1,9 @@
@layer primer.stories.label-group {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the CSS layers from these changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed CSS layers from all story CSS module files (5412c12)

@@ -172,9 +172,9 @@ export function ComplexListInsetVariantStory(): JSX.Element {
<ActionList.Item
{...props}
leadingVisual={() => (
<StyledDiv sx={{'&>svg': {fill: 'white'}}}>
<Box className={classes.StyledDivWithWhiteFill}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anytime we have a Box component without any sx prop or as prop, use a div instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced Box components without sx/as props with div elements and removed unused Box import (5412c12)

- Removed @layer declarations from all story CSS module files
- Replaced Box components without sx/as props with div elements in ActionList.stories.tsx
- Removed unused Box import from ActionList.stories.tsx

Co-authored-by: jonrohan <[email protected]>
Copilot finished work on behalf of jonrohan June 11, 2025 20:14
@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jun 11, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

github-actions bot commented Jun 11, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 92.18 KB (0%)
packages/react/dist/browser.umd.js 92.25 KB (0%)

@jonrohan jonrohan added the skip changeset This change does not need a changelog label Jun 11, 2025
@jonrohan jonrohan marked this pull request as ready for review June 11, 2025 22:11
@jonrohan jonrohan requested a review from a team as a code owner June 11, 2025 22:11
@jonrohan jonrohan self-requested a review June 11, 2025 22:11
@jonrohan jonrohan requested a review from francinelucca June 11, 2025 22:18
@jonrohan jonrohan enabled auto-merge June 11, 2025 22:19
`
const ErsatzOverlay = ({maxWidth, children, ...props}: {maxWidth?: string; children: React.ReactNode}) => (
<div
className={clsx(classes.ErsatzOverlay, maxWidth && classes.ErsatzOverlay)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't look right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the duplicate className issue - removed the incorrect conditional duplicate class assignment (420f132)

box-shadow:
0 1px 3px rgba(0, 0, 0, 0.12),
0 8px 24px rgba(149, 157, 165, 0.2);
overflow: hidden;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this one in the original

Suggested change
overflow: hidden;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the incorrect overflow: hidden property that wasn't in the original ActionMenu styled component (420f132)

Comment on lines 5 to 8
/* Helper styles for focus trap visual aids */
.HelperGlobalStyling {
/* These styles need to be applied globally for the demo */
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Helper styles for focus trap visual aids */
.HelperGlobalStyling {
/* These styles need to be applied globally for the demo */
}
/* Helper styles for focus trap visual aids */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied the suggested comment simplification (420f132)

auto-merge was automatically disabled June 13, 2025 23:46

Head branch was pushed to by a user without write access

Copilot finished work on behalf of francinelucca June 13, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup styled-components in *.stories.tsx files
3 participants