Repository navigation
Description
Summary
XDS components should work out of the box with no theme installed. Themes are optional overlays — consumers can use @xds/core standalone and get a functional UI with proper light/dark mode support using the base token defaults from defineVars. Themes are distributed as separate packages that consumers opt into.
This separation also opens the door for designers and other system teams to craft and publish their own theme bundles for XDS, without touching core.
Current State
packages/core/src/theme/contains both infrastructure and themes:- Infrastructure —
tokens.stylex.ts(defineVars),ThemeContext.ts,XDSTheme.tsx,types.ts - Themes —
defaultTheme.stylex.ts,neutralTheme.stylex.ts(usecreateThemeto override token vars)
- Infrastructure —
⚠️ Base tokens use light-mode-only values —tokens.stylex.tsdefaults are single hex values (e.g.#0064E0), whiledefaultTheme.stylex.tsuseslight-dark()(e.g.light-dark(#0064E0, #2694FE)). This means components without a theme applied don't support dark mode.- Components import token vars (
colorVars,spacingVars, etc.) directly — they never import a theme @xds/core/themere-exports everything together: tokens, provider, and theme objects- CLI
themecommand scanspackages/core/src/theme/*Theme.stylex.tsto discover themes
Design Principles
- Components work without themes —
@xds/coreships with base token defaults viadefineVars, including properlight-dark()support. Install core, use components, done. - Themes are additive — Wrapping your app in
<XDSTheme theme={someTheme}>appliescreateThemeoverrides on top of the defaults. No theme = base defaults. - Themes are independently distributable — Anyone (XDS team, partner design systems, community) can author and publish a theme package that targets XDS tokens.
- Component style overrides belong in themes — Themes can include component-level style overrides (e.g.,
buttonVariants,headingStyles,proseElementStyles). This gives theme authors full control over component rendering, not just token values.
Proposed Structure
@xds/core (infrastructure + base tokens)
tokens.stylex.ts—defineVarswithlight-dark()defaults (components depend on these)ThemeContext.ts— React context for runtime theme accessXDSTheme.tsx— Provider component (<XDSTheme theme={...}>)types.ts—Theme,ThemeRaw,ComponentStyles, etc. (stays in core — components augmentComponentStylesviadeclare module)
Components continue to import colorVars, spacingVars, etc. from core. No change needed.
@xds/theme/default and @xds/theme/neutral (new package with subpath exports)
default/— the XDS default theme (token overrides + component style overrides)neutral/— the neutral grayscale theme- Future: additional brand themes, community themes
Each theme uses createTheme() against @xds/core's token vars and can include component-level style overrides — clean peer dependency.
Usage
// Minimal — no theme, base defaults with light-dark() support
import { XDSButton } from '@xds/core/Button';
// Just works ✓ (light and dark mode)
// With a theme
import { XDSTheme } from '@xds/core/theme';
import { defaultTheme } from '@xds/theme/default';
<XDSTheme theme={defaultTheme}>
<XDSButton>Themed</XDSButton>
</XDSTheme>
// Infrastructure imports stay the same
import { colorVars, spacingVars } from '@xds/core/theme';Theme authoring (third-party)
// @my-org/xds-theme-brand/index.ts
import * as stylex from '@stylexjs/stylex';
import { colorVars, spacingVars, ... } from '@xds/core/theme/tokens.stylex';
import type { Theme } from '@xds/core/theme';
const colors = stylex.createTheme(colorVars, {
'--color-accent': 'light-dark(#E91E63, #F48FB1)',
// ... all color tokens inline
});
// Component-level overrides
const headingStyles = stylex.create({ ... });
const buttonVariants = stylex.create({ ... });
export const myBrandTheme: Theme = {
name: 'my-brand',
styles: { colors, ... },
raw: { ... },
components: {
button: { variants: buttonVariants },
heading: { styles: headingStyles },
},
};Challenges & Spike Results
1. Theme type lives in core (module augmentation)
Components augment the ComponentStyles interface via declare module '../theme/types' — e.g., XDSButton adds button?: { variants?: ... } to ComponentStyles. This means the Theme type grows as you import components — which is the desired behavior (theme type is as concise as the components you're using). The Theme type definition must stay in @xds/core.
2. Cross-package createTheme — SPIKED ✅
Result: it works, with constraints.
createTheme across package boundaries works when:
- Themes import directly from the
.stylex.tssource file (e.g.,@xds/core/theme/tokens.stylex), NOT through a re-exportingindex.ts - The StyleX Babel plugin has
aliasesconfigured to resolve@xds/core/*to source
What doesn't work:
- Importing via
@xds/core/theme(resolves toindex.ts→ re-export chain breaks static analysis) - Using
as unknown astype casts on override objects (StyleX requires inline object literals)
Approach for @xds/theme:
// Theme files import tokens directly from the .stylex.ts source
import { colorVars } from '@xds/core/theme/tokens.stylex';
export const defaultTheme = stylex.createTheme(colorVars, {
'--color-accent': 'light-dark(#0064E0, #2694FE)',
// ... inline literal values only
});@xds/core needs a new subpath export pointing to source:
"./theme/tokens.stylex": {
"types": "./src/theme/tokens.stylex.ts",
"default": "./src/theme/tokens.stylex.ts"
}Fallback for third-party themes without source access: Use stylex.create() with raw CSS variable names instead of createTheme(). Works anywhere but loses type safety.
Full spike details: packages/theme/spike/FINDINGS.md
Testing Strategy
Storybook (visual verification)
Storybook is the primary tool for visual testing. The current setup already has theme and color mode switchers in the toolbar.
- ✅ "No Theme" option added to the Storybook theme toolbar — renders components without the
<XDSTheme>wrapper to verify they look correct using only basedefineVarsdefaults - Test all three states for each component: no theme, default theme, neutral theme — in both light and dark mode
- After package separation, update
apps/storybook/.storybook/preview.tsxto import themes from@xds/theme/defaultand@xds/theme/neutral
Unit tests (vitest)
- Existing component tests already render without a theme provider — these implicitly test the "no theme" path. Verify they still pass after
tokens.stylex.tsgetslight-dark()defaults. - Add a test that verifies the
Themetype from@xds/coreaccepts theme objects from@xds/theme/*(type-level check)
Sandbox app
apps/sandbox(Next.js) serves as an integration test — update it to import from@xds/theme/*and verify the full build pipeline works with the separated packages
Work Items
Prerequisites
- Spike cross-package
createTheme— Works with direct.stylex.tsimports + aliases config. See findings above. - Add "No Theme" to Storybook toolbar — Done in
preview.tsx - Update
tokens.stylex.tsto uselight-dark()values — Branch:navi/feat/tokens-light-dark(ready, needs PR) - Verify components render correctly in both light and dark mode with no theme applied (via Storybook "No Theme" mode)
Package separation
- Create
packages/themewith its ownpackage.json(@xds/theme), peer dep on@xds/core - Add
./theme/tokens.stylexsubpath export to@xds/core/package.json(points to source) - Set up subpath exports:
@xds/theme/default,@xds/theme/neutral - Move
defaultTheme.stylex.tsandneutralTheme.stylex.tsintopackages/theme, update imports to use@xds/core/theme/tokens.stylex - Remove theme object re-exports from
@xds/core/theme/index.ts(keep infrastructure exports) - Configure StyleX aliases in theme package build config
Downstream updates
- Update Storybook preview to import themes from
@xds/theme/* - Update sandbox app to import themes from
@xds/theme/* - Update CLI
themecommand to discover themes from@xds/themepackage
-Update agent docs (xds.md, CLIcomponentoutput) to reflect new import paths - Document theme authoring guide — how third parties create and publish XDS themes
Open Questions
- Theme authoring helpers — Should we export a
createXDSTheme()utility that handles the boilerplate of callingcreateTheme()for each token group? Would lower the bar for theme authors. - Base tokens vs default theme divergence — Once base tokens have
light-dark()values, the default theme may initially be identical to the base. Over time they could diverge (e.g., default theme gets opinionated component overrides). Is that the intent? - Versioning — Should
@xds/themeversion in lockstep with@xds/core, or independently?
Related
- [Discussion] Packaging and distribution strategy #129 — Packaging and distribution strategy (broader discussion)
- CLI
themecommand (packages/cli/src/commands/theme.mjs) - Spike files:
packages/theme/spike/
Activity