Skip to content

feat(theme): separate themes into @xds/theme package - #141

Merged
cixzhang merged 7 commits into
mainfrom
navi/feat/theme-package
Feb 19, 2026
Merged

cixzhang merged 7 commits into
mainfrom
navi/feat/theme-package

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Summary

Extracts themes from @xds/core into a new @xds/theme package. Components now work standalone with no theme — themes are optional overlays that consumers opt into.

Depends on #140 (base tokens with light-dark() defaults — cherry-picked into this branch).

What Changed

New: packages/theme/ (@xds/theme)

packages/theme/
├── src/
│   ├── default/
│   │   ├── defaultTheme.stylex.ts
│   │   └── index.ts
│   └── neutral/
│       ├── neutralTheme.stylex.ts
│       └── index.ts
├── package.json
├── tsconfig.json
└── tsup.config.ts
  • Subpath exports: @xds/theme/default and @xds/theme/neutral
  • Peer dependency on @xds/core
  • Theme files import tokens via relative path to core source (../../../core/src/theme/tokens.stylex) for StyleX createTheme cross-package compatibility (see spike findings in Separate themes into their own package (@xds/themes) #139)
  • Types use ThemeType alias from @xds/core/theme since Theme is exported as a component value
  • Component style overrides use as Theme['components'] assertion since ComponentStyles augmentations aren't visible across package boundaries

Updated: @xds/core/theme

  • Removed defaultTheme and neutralTheme re-exports from index.ts
  • Infrastructure stays: XDSTheme, useXDSTheme, tokens, types

Updated: Downstream consumers

File Change
apps/storybook/.storybook/preview.tsx Import themes from @xds/theme/*, added "No Theme" toolbar option
apps/storybook/stories/Layout.stories.tsx Import themes from @xds/theme/*
apps/storybook/stories/FontWrapper.stories.tsx Updated code example
apps/sandbox/src/app/layout.tsx Import theme from @xds/theme/default
packages/cli/src/commands/init.mjs Updated getting-started instructions
apps/storybook/package.json Added @xds/theme dependency
apps/sandbox/package.json Added @xds/theme dependency

Usage

// Components work with no theme — base light-dark() tokens
import { XDSButton } from '@xds/core/Button';
<XDSButton label="Click me" />  // ✓ works in light + dark mode

// Optionally add a theme
import { XDSTheme } from '@xds/core/theme';
import { defaultTheme } from '@xds/theme/default';

<XDSTheme theme={defaultTheme}>
  <XDSButton label="Themed" />
</XDSTheme>

Technical Notes

Cross-package createTheme

StyleX's createTheme requires resolving the original defineVars source file. Importing via @xds/core/theme (which resolves to dist/) breaks static analysis. The solution: theme files use relative imports to the core source (../../../core/src/theme/tokens.stylex), which StyleX resolves correctly. See spike findings in #139.

Module augmentation boundary

ComponentStyles is augmented by components via declare module (e.g., XDSButton adds button?: {...}). Since the theme package doesn't import components, these augmentations aren't visible — hence the as Theme['components'] assertion. Types are enforced at the consumer site where both components and themes are imported.

Testing

  • npx tsc --noEmit passes for both packages/theme and packages/core
  • 59/59 runnable unit tests pass (same as main)
  • Storybook "No Theme" toolbar option added for visual verification

Related


Crafted with care by Navi

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 18, 2026
@cixzhang
cixzhang requested a review from mellyeliu February 18, 2026 21:53
Navi added 3 commits February 18, 2026 22:05
Move defaultTheme and neutralTheme from @xds/core into a new
@xds/theme package with subpath exports:
  - import { defaultTheme } from '@xds/theme/default'
  - import { neutralTheme } from '@xds/theme/neutral'

@xds/core retains theme infrastructure (tokens, ThemeContext,
XDSTheme provider, types). Components work without any theme
applied using base defineVars defaults.

Theme files import tokens via relative path to core source
for StyleX createTheme cross-package compatibility.

Updates all downstream consumers:
  - Storybook preview + stories
  - Sandbox app
  - CLI init command

Also adds 'No Theme' option to Storybook toolbar for testing
components without any theme wrapper.

Co-authored-by: Navi <[email protected]>
Replace workspace:* with * for yarn v1 compatibility.
Add proper version ranges for theme package devDependencies.
Add @xds/theme aliases to Storybook Vite + StyleX config.

Co-authored-by: Navi <[email protected]>
defaultTheme.stylex.ts and neutralTheme.stylex.ts now live in
packages/theme/. The copies in packages/core/src/theme/ are no
longer imported by anything.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/feat/theme-package branch from 656aef8 to 98dfe99 Compare February 18, 2026 22:05
Navi and others added 2 commits February 18, 2026 22:33
Text, Heading, and FontWrapper tests were importing defaultTheme
from the old location. These tests don't need a theme wrapper —
components work standalone with base token defaults.

Co-authored-by: Navi <[email protected]>
Components should work without a theme provider. useXDSTheme now
returns null instead of throwing when used outside <XDSTheme>.
Updated XDSFontWrapper to handle the null case with optional
chaining, consistent with how all other components already
use useContext(ThemeContext) directly.

Co-authored-by: Navi <[email protected]>
@github-actions

github-actions Bot commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

Modified Components

Text
Metric Before After Delta
Bundle Size (ESM) N/A 489B N/A
Lines of Code N/A 527 -
Complexity N/A Very High (76) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 6.0KB 9.9KB 1.6KB

Accessibility Audit

Status: 4 accessibility violation(s) found.

XDSText - 2 issue(s)
  • critical: Form elements must have labels
    • Rule: label
  • serious: Links must have discernible text
    • Rule: link-name
XDSTextArea - 1 issue(s)
  • serious: Links must have discernible text
    • Rule: link-name
XDSTextInput - 1 issue(s)
  • serious: Links must have discernible text
    • Rule: link-name

Component Previews

Includes interactive hover previews as animated GIFs.

XDSText

Body

Screenshot:

Body

Interaction Preview: (view video)

Body interaction

Run yarn storybook and navigate to: typography-xdstext--body

Large

Screenshot:

Large

Interaction Preview: (view video)

Large interaction

Run yarn storybook and navigate to: typography-xdstext--large

Label

Screenshot:

Label

Interaction Preview: (view video)

Label interaction

Run yarn storybook and navigate to: typography-xdstext--label

Supporting

Screenshot:

Supporting

Interaction Preview: (view video)

Supporting interaction

Run yarn storybook and navigate to: typography-xdstext--supporting

Code

Screenshot:

Code

Interaction Preview: (view video)

Code interaction

Run yarn storybook and navigate to: typography-xdstext--code

All Types

Screenshot:

All Types

Interaction Preview: (view video)

All Types interaction

Run yarn storybook and navigate to: typography-xdstext--all-types

Color Variants

Screenshot:

Color Variants

Interaction Preview: (view video)

Color Variants interaction

Run yarn storybook and navigate to: typography-xdstext--color-variants

Weight Variants

Screenshot:

Weight Variants

Interaction Preview: (view video)

Weight Variants interaction

Run yarn storybook and navigate to: typography-xdstext--weight-variants

Display Modes

Screenshot:

Display Modes

Interaction Preview: (view video)

Display Modes interaction

Run yarn storybook and navigate to: typography-xdstext--display-modes

Single Line Truncation

Screenshot:

Single Line Truncation

Interaction Preview: (view video)

Single Line Truncation interaction

Run yarn storybook and navigate to: typography-xdstext--single-line-truncation

Multi Line Truncation

Screenshot:

Multi Line Truncation

Interaction Preview: (view video)

Multi Line Truncation interaction

Run yarn storybook and navigate to: typography-xdstext--multi-line-truncation

Truncation Without Tooltip

Screenshot:

Truncation Without Tooltip

Interaction Preview: (view video)

Truncation Without Tooltip interaction

Run yarn storybook and navigate to: typography-xdstext--truncation-without-tooltip

Truncation Variants

Screenshot:

Truncation Variants

Interaction Preview: (view video)

Truncation Variants interaction

Run yarn storybook and navigate to: typography-xdstext--truncation-variants

Word Break Variants

Screenshot:

Word Break Variants

Interaction Preview: (view video)

Word Break Variants interaction

Run yarn storybook and navigate to: typography-xdstext--word-break-variants

Text Wrap Variants

Screenshot:

Text Wrap Variants

Interaction Preview: (view video)

Text Wrap Variants interaction

Run yarn storybook and navigate to: typography-xdstext--text-wrap-variants

Strikethrough

Screenshot:

Strikethrough

Interaction Preview: (view video)

Strikethrough interaction

Run yarn storybook and navigate to: typography-xdstext--strikethrough

Tabular Numbers

Screenshot:

Tabular Numbers

Interaction Preview: (view video)

Tabular Numbers interaction

Run yarn storybook and navigate to: typography-xdstext--tabular-numbers

Capsize

Screenshot:

Capsize

Interaction Preview: (view video)

Capsize interaction

Run yarn storybook and navigate to: typography-xdstext--capsize

As Elements

Screenshot:

As Elements

Interaction Preview: (view video)

As Elements interaction

Run yarn storybook and navigate to: typography-xdstext--as-elements

Card Example

Screenshot:

Card Example

Interaction Preview: (view video)

Card Example interaction

Run yarn storybook and navigate to: typography-xdstext--card-example

Metrics Example

Screenshot:

Metrics Example

Interaction Preview: (view video)

Metrics Example interaction

Run yarn storybook and navigate to: typography-xdstext--metrics-example

Form Example

Screenshot:

Form Example

Interaction Preview: (view video)

Form Example interaction

Run yarn storybook and navigate to: typography-xdstext--form-example


Generated by PR Enrichment workflow | Storybook | View full report

@cixzhang

Copy link
Copy Markdown
Contributor Author

Packaging consideration: cross-package imports for source distribution

The relative path imports in theme files (../../../core/src/theme/tokens.stylex) work in the monorepo but will break for source distribution consumers, where packages land in separate node_modules/@xds/core and node_modules/@xds/theme directories.

Suggestion: use package specifiers + StyleX aliases

In theme source files, replace:

import { colorVars, ... } from '../../../core/src/theme/tokens.stylex';

with:

import { colorVars, ... } from '@xds/core/theme/tokens.stylex';

In @xds/core source package.json, add the subpath export:

"./theme/tokens.stylex": "./theme/tokens.stylex.ts"

Consumers then configure StyleX aliases to resolve the path:

// babel.config.js
plugins: [
  ['@stylexjs/babel-plugin', {
    aliases: {
      '@xds/core/*': [
        path.join(__dirname, 'node_modules/@xds/core/*')
      ],
    },
    // ...
  }]
]

This is consistent with how the storybook already configures aliases for @xds/core/* and @xds/theme/*.

Other packaging impacts

  • Two source tarballs: package-source.js would need to produce both xds-core and xds-theme tarballs (or include themes as an optional subdirectory in the core tarball)
  • PostCSS/unplugin include patterns need to cover both packages: node_modules/@xds/core/** and node_modules/@xds/theme/**
  • Zero-config path is simpler now: since components work with no theme, consumers can skip @xds/theme entirely — no XDSTheme provider, no 'use client' boundary needed

Worth verifying

Whether unstable_moduleResolution: { type: 'commonJS' } already resolves @xds/core/theme/tokens.stylex from node_modules without explicit aliases. If it does, consumers wouldn't need the aliases config at all — just the subpath export in @xds/core's package.json.

Navi added 2 commits February 19, 2026 04:10
Replace relative path imports ('../../../core/src/theme/tokens.stylex')
with clean package specifiers ('@xds/core/theme/tokens.stylex').

This makes theme files portable across monorepo and source distribution:
- Monorepo: resolved via tsconfig paths + StyleX aliases
- Source tarball: resolved via StyleX aliases pointing to node_modules

Changes:
- Theme files: import from '@xds/core/theme/tokens.stylex'
- @xds/core package.json: add './theme/tokens.stylex' subpath export
- Theme tsconfig: add paths for '@xds/core/*'
- Theme tsup: add StyleX aliases config

Co-authored-by: Navi <[email protected]>
…ring

Vite uses LightningCSS as its CSS transformer, which polyfills light-dark()
into --lightningcss-light/--lightningcss-dark custom properties when targeting
older browsers. Set explicit targets to Chrome 123+, Firefox 120+, Safari 17.5+
(where light-dark() is natively supported) to keep the output clean.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang merged commit 75123cf into main Feb 19, 2026
5 checks passed
@cixzhang
cixzhang deleted the navi/feat/theme-package branch February 19, 2026 04:42
cixzhang added a commit that referenced this pull request Apr 26, 2026
* feat(theme): separate themes into @xds/theme package

Move defaultTheme and neutralTheme from @xds/core into a new
@xds/theme package with subpath exports:
  - import { defaultTheme } from '@xds/theme/default'
  - import { neutralTheme } from '@xds/theme/neutral'

@xds/core retains theme infrastructure (tokens, ThemeContext,
XDSTheme provider, types). Components work without any theme
applied using base defineVars defaults.

Theme files import tokens via relative path to core source
for StyleX createTheme cross-package compatibility.

Updates all downstream consumers:
  - Storybook preview + stories
  - Sandbox app
  - CLI init command

Also adds 'No Theme' option to Storybook toolbar for testing
components without any theme wrapper.

Co-authored-by: Navi <[email protected]>

* fix: use yarn v1 compatible dependency specifiers

Replace workspace:* with * for yarn v1 compatibility.
Add proper version ranges for theme package devDependencies.
Add @xds/theme aliases to Storybook Vite + StyleX config.

Co-authored-by: Navi <[email protected]>

* chore: remove old theme files from @xds/core

defaultTheme.stylex.ts and neutralTheme.stylex.ts now live in
packages/theme/. The copies in packages/core/src/theme/ are no
longer imported by anything.

Co-authored-by: Navi <[email protected]>

* fix(tests): remove theme dependency from core component tests

Text, Heading, and FontWrapper tests were importing defaultTheme
from the old location. These tests don't need a theme wrapper —
components work standalone with base token defaults.

Co-authored-by: Navi <[email protected]>

* fix(theme): make useXDSTheme return null when no provider

Components should work without a theme provider. useXDSTheme now
returns null instead of throwing when used outside <XDSTheme>.
Updated XDSFontWrapper to handle the null case with optional
chaining, consistent with how all other components already
use useContext(ThemeContext) directly.

Co-authored-by: Navi <[email protected]>

* refactor(theme): use package specifier imports + StyleX aliases

Replace relative path imports ('../../../core/src/theme/tokens.stylex')
with clean package specifiers ('@xds/core/theme/tokens.stylex').

This makes theme files portable across monorepo and source distribution:
- Monorepo: resolved via tsconfig paths + StyleX aliases
- Source tarball: resolved via StyleX aliases pointing to node_modules

Changes:
- Theme files: import from '@xds/core/theme/tokens.stylex'
- @xds/core package.json: add './theme/tokens.stylex' subpath export
- Theme tsconfig: add paths for '@xds/core/*'
- Theme tsup: add StyleX aliases config

Co-authored-by: Navi <[email protected]>

* fix(storybook): set LightningCSS targets to prevent light-dark() lowering

Vite uses LightningCSS as its CSS transformer, which polyfills light-dark()
into --lightningcss-light/--lightningcss-dark custom properties when targeting
older browsers. Set explicit targets to Chrome 123+, Firefox 120+, Safari 17.5+
(where light-dark() is natively supported) to keep the output clean.

Co-authored-by: Navi <[email protected]>

---------

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* feat(theme): separate themes into @xds/theme package

Move defaultTheme and neutralTheme from @xds/core into a new
@xds/theme package with subpath exports:
  - import { defaultTheme } from '@xds/theme/default'
  - import { neutralTheme } from '@xds/theme/neutral'

@xds/core retains theme infrastructure (tokens, ThemeContext,
XDSTheme provider, types). Components work without any theme
applied using base defineVars defaults.

Theme files import tokens via relative path to core source
for StyleX createTheme cross-package compatibility.

Updates all downstream consumers:
  - Storybook preview + stories
  - Sandbox app
  - CLI init command

Also adds 'No Theme' option to Storybook toolbar for testing
components without any theme wrapper.


* fix: use yarn v1 compatible dependency specifiers

Replace workspace:* with * for yarn v1 compatibility.
Add proper version ranges for theme package devDependencies.
Add @xds/theme aliases to Storybook Vite + StyleX config.


* chore: remove old theme files from @xds/core

defaultTheme.stylex.ts and neutralTheme.stylex.ts now live in
packages/theme/. The copies in packages/core/src/theme/ are no
longer imported by anything.


* fix(tests): remove theme dependency from core component tests

Text, Heading, and FontWrapper tests were importing defaultTheme
from the old location. These tests don't need a theme wrapper —
components work standalone with base token defaults.


* fix(theme): make useXDSTheme return null when no provider

Components should work without a theme provider. useXDSTheme now
returns null instead of throwing when used outside <XDSTheme>.
Updated XDSFontWrapper to handle the null case with optional
chaining, consistent with how all other components already
use useContext(ThemeContext) directly.


* refactor(theme): use package specifier imports + StyleX aliases

Replace relative path imports ('../../../core/src/theme/tokens.stylex')
with clean package specifiers ('@xds/core/theme/tokens.stylex').

This makes theme files portable across monorepo and source distribution:
- Monorepo: resolved via tsconfig paths + StyleX aliases
- Source tarball: resolved via StyleX aliases pointing to node_modules

Changes:
- Theme files: import from '@xds/core/theme/tokens.stylex'
- @xds/core package.json: add './theme/tokens.stylex' subpath export
- Theme tsconfig: add paths for '@xds/core/*'
- Theme tsup: add StyleX aliases config


* fix(storybook): set LightningCSS targets to prevent light-dark() lowering

Vite uses LightningCSS as its CSS transformer, which polyfills light-dark()
into --lightningcss-light/--lightningcss-dark custom properties when targeting
older browsers. Set explicit targets to Chrome 123+, Firefox 120+, Safari 17.5+
(where light-dark() is natively supported) to keep the output clean.


---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant