Skip to content

feat(tokens,react): theme runtime improvements#127

Closed
wangdicoder wants to merge 1 commit intomasterfrom
feat/theme-runtime-improvements
Closed

feat(tokens,react): theme runtime improvements#127
wangdicoder wants to merge 1 commit intomasterfrom
feat/theme-runtime-improvements

Conversation

@wangdicoder
Copy link
Copy Markdown
Owner

Summary

  • Fix scoped light-inside-dark: base.css now emits light defaults under :root, [data-tiny-theme='light'] so a nested <ConfigProvider theme="light"> inside a dark root flips back correctly.
  • SSR helper: new getThemeStylesheet(theme, { selector? }) in @tiny-design/tokens/resolve-theme (re-exported from @tiny-design/react) returns a CSS string for pre-hydration <style> injection, including color-scheme.
  • useActiveTheme(): returns the effective { mode, themeConfig } for the current subtree (nearest ConfigProvider wins, falls back to the document-level store).
  • Context-aware useTheme: now reads the nearest ConfigProvider's mode first; accepts { initialMode } for SSR hydration. Extracted the shared external store into _utils/theme-store.ts.
  • Typed token keys: dist/registry.d.ts exports PrimitiveTokenKey, SemanticTokenKey, ComponentTokenKey, and TokenKey unions; dist/presets.d.ts exports TypedThemeDocument for autocompleted theme authoring.
  • Primitive token layer (additive): new source/primitive/ directory with an initial brand color scale and spacing scale; build loads category: 'primitive'. Semantic tokens keep their current defaults — migrating them to reference primitives is a follow-up.
  • Stronger registry validation: build now fails on invalid fallback targets and on $type / $value mismatches for color, dimension, and number (supports color-mix, gradients, calc(), var(), and padding-shorthand).

Release

  • Bump type: minor
  • Affected packages: @tiny-design/react, @tiny-design/tokens (fixed version group, also moves @tiny-design/icons and @tiny-design/charts)

Test plan

  • pnpm --filter @tiny-design/react exec jest — all 799 tests across 97 suites pass
  • pnpm --filter @tiny-design/react exec tsc --noEmit — clean
  • pnpm build — full turborepo build (tokensiconsreactdocs) succeeds
  • Visual check: <ConfigProvider theme="light"> inside <html data-tiny-theme="dark"> now renders light
  • Verify useTheme().mode inside a scoped <ConfigProvider theme="dark"> reports 'dark' instead of the html-level mode
  • Call getThemeStylesheet({ extends: 'tiny-dark', mode: 'dark' }) server-side and confirm the returned CSS has only overrides + color-scheme: dark

🤖 Generated with Claude Code

…rades

Fix scoped light-inside-dark theming, add SSR stylesheet helper, typed token
keys, a primitive token layer, and unify useTheme with ConfigProvider via a
shared external store.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant