Skip to content

feat(theme): design tokens for every color, type and shape; theme objects - #4

Open
mkroemer wants to merge 1 commit into
p10node:mainfrom
mkroemer:theming
Open

mkroemer wants to merge 1 commit into
p10node:mainfrom
mkroemer:theming

Conversation

@mkroemer

Copy link
Copy Markdown

This lets a host give the viewer its own look without overriding the stylesheet's selectors.

Every color in styles.css is now a --de-* custom property on .de-root, with the dark values on .de-root.de-dark. That includes the find highlights, collaboration status and avatars, the slideshow, tooltips, file badges, paper and placeholders, and the source editor's syntax colors, which moved to the root so a theme reaches them. Fonts, radii and shadows are tokens too.

theme still takes 'light' | 'dark' | 'auto', and now also an object:

<DocViewer
  src={file}
  theme={{
    mode: 'auto',
    tokens: { accent: '#7c3aed', font: 'Inter, sans-serif', radius: '4px' },
    dark: { accent: '#a78bfa' },
  }}
/>

Token names are typed and camelCase (accentHover sets --de-accent-hover, list in THEME_TOKENS). createTheme, themeStyle and useThemeRoot are exported for hosts that mount DocxView, XlsxView or PptxView in a root of their own. A host that cannot inject a style tag (CSP, extracted CSS, cascade layers) passes injectStyles={false} and imports @p10node/office-engine/styles.css. docs/theming.md describes it all.

Rendering is unchanged. I compared computed styles against the current stylesheet over DOCX, XLSX, PPTX and Markdown files, light and dark. The only differences are equivalent font stacks and the color button's swatch edge, which now follows swatch-border and so is visible in dark mode.

test/theme.test.ts keeps THEME_TOKENS and the stylesheet in step and fails on a literal color outside a token definition. e2e/viewer.spec.ts covers theme objects in both modes and injectStyles={false}. On current main (v0.13.2), bun run typecheck, bun test and the e2e suite pass in CI.

This is the first of a few small PRs I'd like to propose, each building on the one before: host icons, translatable UI texts (English and German), replaceable toolbar components, and a headless mode where the host draws its own controls from a controller. Happy to rename things or split this further if you prefer.

🤖 Generated with Claude Code

…ects

Every color in the stylesheet is now a --de-* token on .de-root, with the
dark values on .de-root.de-dark: find highlights, collaboration status,
avatars, slideshow, tooltips, file badges, paper and placeholders, and the
source editor's syntax colors (moved to the root so a theme reaches them).
Fonts, radii and shadows are tokens too. Rendering is unchanged: a
computed-style comparison against the previous stylesheet over DOCX, XLSX,
PPTX and Markdown, light and dark, differs only in equivalent font stacks
and the color-button swatch edge, which now follows swatch-border (visible
in dark).

- theme accepts { mode, tokens, light, dark } with typed camelCase token
  names (ThemeTokens); THEME_TOKENS, createTheme, themeStyle, useThemeRoot
- injectStyles={false} and @p10node/office-engine/styles.css for hosts that
  load the stylesheet themselves (CSP, extracted CSS, cascade layers)
- docs/theming.md; unit tests keep THEME_TOKENS and the stylesheet in step
  and reject literal colors outside token definitions; e2e for theme
  objects in both modes and for injectStyles=false

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants