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

Merged
merged 11 commits into from
Jun 17, 2025

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: 6f34a4b

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 AI and others added 2 commits June 11, 2025 19:45
… and LabelGroup stories

Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
@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 <54012+jonrohan@users.noreply.github.com>
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.28 KB (0%)
packages/react/dist/browser.umd.js 92.39 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
@github-actions github-actions bot temporarily deployed to storybook-preview-6197 June 11, 2025 22:15 Inactive
@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)

Copilot finished work on behalf of jonrohan June 16, 2025 18:22
@jonrohan
Copy link
Member

@copilot can you revert the commit f05f7d9

Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 16, 2025

@copilot can you revert the commit f05f7d9

Reverted commit f05f7d9 - restored the conditional CSS custom property setting where the style prop is only set when maxWidth exists (ccdd42d)

Copilot finished work on behalf of jonrohan June 16, 2025 18:31
@jonrohan jonrohan requested a review from francinelucca June 16, 2025 18:31
@jonrohan jonrohan enabled auto-merge June 16, 2025 18:40
@github-actions github-actions bot temporarily deployed to storybook-preview-6197 June 16, 2025 18:55 Inactive
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

LGTM! Just had a question around one migration

background-color: ${themeGet('colors.bg.canvas')};
}
`
const GlobalStyle = () => (
Copy link
Member

Choose a reason for hiding this comment

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

This migration seems a little odd 🤔 Would this be a :global in the corresponding CSS Modules file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right! I've converted the inline <style> component to a proper CSS Modules file using :global(body) syntax. This is the correct approach for targeting global elements like body when using CSS Modules. (901eb8b)

Co-authored-by: joshblack <3901764+joshblack@users.noreply.github.com>
auto-merge was automatically disabled June 16, 2025 21:03

Head branch was pushed to by a user without write access

Copilot finished work on behalf of joshblack June 16, 2025 21:04
@github-actions github-actions bot temporarily deployed to storybook-preview-6197 June 16, 2025 22:59 Inactive
@francinelucca
Copy link
Member

@copilot run 'npm format' and commit the result

Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 17, 2025

@copilot run 'npm format' and commit the result

Ran npm format and committed the formatting fix (6f34a4b)

Copilot finished work on behalf of francinelucca June 17, 2025 13:37
@francinelucca francinelucca enabled auto-merge June 17, 2025 14:01
@francinelucca francinelucca added this pull request to the merge queue Jun 17, 2025
Merged via the queue into main with commit c9a11eb Jun 17, 2025
35 checks passed
@francinelucca francinelucca deleted the copilot/fix-6196 branch June 17, 2025 14:15
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
4 participants