Skip to content

chore(css): remove styled-components as a dependency - #1151

Merged
DreaminDani merged 8 commits into
mainfrom
cui-173-remove-styled-components
Jul 21, 2026
Merged

chore(css): remove styled-components as a dependency#1151
DreaminDani merged 8 commits into
mainfrom
cui-173-remove-styled-components

Conversation

@DreaminDani

@DreaminDani DreaminDani commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Completes the CSS Modules migration by removing styled-components entirely. Every component already renders from CSS Modules — styled-components survived only as the runtime theme-delivery mechanism (its ThemeProvider/useTheme React context) plus some stale comments, deprecated exports, and build config. This replaces that runtime with click-ui's own React context and drops the dependency.

Delivered as four reviewable commits:

  1. Clean up stale styled-components comments/references (.tsx/.test.tsx) — pure comment rewording, no behavior change. Keeps useInitialTheme's mounted flag (SSR/hydration gate); only its stale TODO is updated.
  2. Remove leftover styled-components exports — deletes the deprecated linkStyles / StyledLinkProps public exports (built on styled-components' css, no internal consumers).
  3. Remove styled-components as a dependency — the main change (details below).
  4. Reconcile remaining stale styled-components references — the .module.css sweep the cleanup ticket calls for: corrects Badge comments that claimed Icon injects styled-components at runtime (Icon is a CSS Module now), rewords pre-migration references in GenericLabel/Label/SidebarNavigation*/Text/Title, and fixes the functional @covers EmptyButtonIconButton directive in the CodeBlock spec (CodeBlock renders IconButton directly now, so affected-spec selection was mis-targeted). The doubled-class / :where() override rules themselves are left for the cascade-layer follow-up — only their stale comments are reconciled here.

How the theme runtime was replaced

  • New src/theme/ThemeContext.ts: a plain React context typed as Theme (default themes.light) plus a useTheme(): Theme hook — a drop-in for styled-components' useTheme delivering the identical theme object.
  • ThemeProvider now wraps children in that context and reproduces the old createGlobalStyle body rule with a behavior-preserving effect that sets document.body text/background from the resolved theme (restored on unmount). The public ClickUIProvider / ThemeProvider API is unchanged for consumers.
  • All useTheme call sites (useCUITheme, CodeBlock, Flyout, and the four Assets) now import from the new context.
  • Removed the declare module 'styled-components' type augmentation.
  • Story-local styled components and the Storybook ThemeBlock decorator converted to inline styles / the new useTheme; GenericMenu's test wrapper uses click-ui's own ThemeProvider.
  • Dropped babel-plugin-styled-components from vite.config.ts; removed styled-components from dependencies, peerDependencies, and resolutions.

Breaking changes

  • styled-components is no longer a peer dependency (remove it if your app doesn't use it directly).
  • linkStyles / StyledLinkProps exports removed — use the Link component with the component prop.

A major changeset is included.

Behavior note for reviewers

Body styling is now an inline-style effect rather than a global stylesheet rule, so it has higher specificity than the old injected rule — a theoretical edge case only if a consumer app styles body and relied on beating the old rule.

Verification

  • tsc --noEmit, lint:code, format (Prettier), stylelint all clean
  • yarn build succeeds with styled-components uninstalled
  • ✅ 518 unit tests pass
  • ✅ Visual regression: 1236 snapshots pass, 0 diffs (1 flaky, passed on retry) — confirms the theme re-plumbing is byte-for-byte identical
  • ✅ No styled-components references remain in source, .storybook, vite.config.ts, package.json, or yarn.lock

🤖 Generated with Claude Code

DreaminDani and others added 3 commits July 16, 2026 11:06
Migrated components no longer use styled-components, but several comments
still referenced it. Reword these to describe current behavior; no code
changes. Keeps the `mounted` flag in useInitialTheme (SSR/hydration gate);
only its stale TODO comment is updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove the deprecated `linkStyles` and `StyledLinkProps` public exports.
Both were built on styled-components' `css` template and had no internal
consumers (the Link component renders from Link.module.css). Consumers
should use the `Link` component with the `component` prop instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace styled-components' runtime theme delivery (ThemeProvider/useTheme)
with click-ui's own React context (src/theme/ThemeContext). The public
ClickUIProvider/ThemeProvider API is unchanged; consumers of useCUITheme,
Flyout, CodeBlock, and the Assets read the identical theme object.

The old createGlobalStyle body rule is reproduced with a behavior-preserving
effect on ThemeProvider that sets document.body text/background from the
resolved theme. Story-local styled components and the Storybook ThemeBlock
decorator are converted to inline styles / the new useTheme; GenericMenu's
test wrapper now uses click-ui's ThemeProvider. Drops the
babel-plugin-styled-components transform from vite.config and removes
styled-components from dependencies, peerDependencies, and resolutions.

Verified byte-for-byte against the full visual-regression suite
(1237 snapshots, 0 diffs) plus typecheck, build, and 518 unit tests.

BREAKING CHANGE: styled-components is no longer a peer dependency; the
deprecated linkStyles/StyledLinkProps exports were removed in the prior
commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e2ec603

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Major

Not sure what this means? Click here to learn what changesets are.

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

Comment thread src/providers/ThemeProvider.tsx Outdated
Complete the CUI-171 sweep across the files the ticket names:
- Correct the Badge.module.css comments that claimed Icon injects a
  styled-components rule at runtime (Icon is a CSS Module now); reframe the
  doubled-class specificity rationale in terms of CSS Module bundle order.
  The doubled-class rules themselves are left for the cascade-layer follow-up.
- Reword pre-migration references in GenericLabel, Label, SidebarNavigation*,
  Text, and Title module CSS to drop the now-removed dependency's framing
  while keeping the current-behavior rationale.
- Update the CodeBlock story comment and the codeblock.spec.ts header to
  describe the buttons rendering via IconButton directly, and fix the stale
  `@covers src/components/EmptyButton` directive to `IconButton` (CodeBlock
  no longer renders EmptyButton, so affected-spec selection was mis-targeted).

Comment-only changes plus one `@covers` directive; no behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread src/providers/ThemeProvider.tsx Outdated
@DreaminDani
DreaminDani requested a review from BEvgeniyS July 16, 2026 19:59
Comment thread .storybook/preview.tsx Outdated
Comment thread src/theme/ThemeContext.ts
Comment thread src/providers/ThemeProvider.tsx Outdated
Comment thread src/stories/chartColors.stories.tsx Outdated
Comment thread vite.config.ts
@DreaminDani
DreaminDani removed the request for review from BEvgeniyS July 17, 2026 14:46
DreaminDani and others added 2 commits July 17, 2026 09:45
… via CSS

Address review feedback:
- Move ThemeProvider next to ThemeContext under src/theme/ (context and
  provider co-located; public export path via providers/index.ts unchanged).
- Replace the imperative document.body inline-style effect with a declarative
  `body { color; background-color }` rule in src/theme/styles/global.css using
  the token custom properties. It swaps with `data-cui-theme` and ships in the
  `@layer clickui` layer, so any consumer `body` rule overrides it. Non-breaking:
  ClickUIProvider sets data-cui-theme, and this is lower-priority than the old
  inline styles (which would have clobbered a consumer's own body color).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Swap the hard-coded `borderRadius: '4px'` for `var(--click-grid-radii-sm)`
(the sm step of the shared radius scale the Grid component uses, = 0.25rem).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread src/theme/ThemeProvider.tsx Outdated
DreaminDani and others added 2 commits July 17, 2026 10:00
Fold the lower-level ThemeProvider into ClickUIProvider and drop it from the
public API. ClickUIProvider now provides the theme React context directly
(alongside the data-cui-theme attribute, persistence, toast, and tooltip it
already owned) and imports the base token CSS. Having two public providers —
one that fully themed and one that only half-themed (never set data-cui-theme,
so CSS Module components stayed light) — was a documented footgun.

BREAKING CHANGE: the `ThemeProvider` export is removed. Replace any bare
`<ThemeProvider theme={…}>` with `<ClickUIProvider theme={…}>`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the ThemeBlock component and the withTheme decorator out of preview.tsx
into .storybook/withThemeDecorator.tsx, leaving preview.tsx with just Storybook
config. Addresses optional review feedback.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

✅ Preview URL: https://click-948o08fvk-clickhouse.vercel.app

Built from commit: 39d6815e641653b0f97176742e65b4698277932c

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e2ec603. Configure here.

Comment thread src/providers/ClickUIProvider.tsx
@DreaminDani
DreaminDani requested a review from XOP July 17, 2026 17:15

@hoorayimhelping hoorayimhelping left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Send it!

@DreaminDani
DreaminDani merged commit 0a02c6b into main Jul 21, 2026
9 checks passed
@DreaminDani
DreaminDani deleted the cui-173-remove-styled-components branch July 21, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants