Skip to content

feat(viewer): host icons through an icons map or resolver - #5

Open
mkroemer wants to merge 4 commits into
p10node:mainfrom
mkroemer:host-icons
Open

mkroemer wants to merge 4 commits into
p10node:mainfrom
mkroemer:host-icons

Conversation

@mkroemer

Copy link
Copy Markdown

Builds on #4 (theming). Until that is merged this PR shows its commit too; the icons part is the last three commits.

This lets a host draw the viewer's chrome with its own icon set, all of it or just a few icons.

Every icon the chrome draws now goes through Icon. A few controls still used text glyphs: the zoom buttons, the outline toggle and its close button, find & replace, Present and the add-sheet tab. They get the names zoomIn, zoomOut, present, sheetAdd and replace (outline and close are reused) and look the same as before.

icons on DocViewer, mount() and <office-viewer> (as the .icons property) takes a partial map or a resolver:

<DocViewer src={file} icons={{ undo: <MyUndo />, redo: <MyRedo /> }} />

const lucide = (name: IconName) => {
  const C = LUCIDE[name]
  return C && <C size="1em" strokeWidth={1.8} />
}
<DocViewer src={file} icons={lucide} />

A name the map leaves out, or a resolver returning undefined or null, keeps the built-in icon. Host icons render in span.de-icon, sized by its font-size, so an icon drawn at 1em with currentColor follows the size and the theme. IconName is the union of the built-in names (all of them in ICON_NAMES), and the icon props in the toolbars, menus and FileMenuItem are typed with it. IconsProvider gives the standalone views the same icons; a nested provider falls back to the enclosing one. docs/api.md has Lucide and Phosphor examples; there are no new dependencies.

test/icons.test.tsx covers the precedence of map, resolver and built-in icons. e2e/icons.spec.ts checks that host icons replace the built-in ones in the DOCX, XLSX and PPTX chrome. bun run typecheck, bun test and the e2e suite pass in CI.

🤖 Generated with Claude Code

markus-kroemer and others added 4 commits November 14, 2026 10:43
…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>
Every icon the chrome draws now goes through `Icon`: the zoom buttons,
the outline toggle and its close button, find & replace, Present and the
add-sheet tab used text glyphs and get the names `zoomIn`, `zoomOut`,
`present`, `sheetAdd`, `replace` (with `outline` and `close` reused),
drawn like today.

- `IconName` is the union of the built-in names (exported with
  `ICON_NAMES`); icon props in the toolbars, menus and `FileMenuItem`
  are typed with it.
- `icons` on DocViewer, `mount()` and `<office-viewer>` (`.icons`
  property) takes a partial map or a resolver `(name, { size })`;
  a missing entry or `undefined` / `null` keeps the built-in icon.
  Host icons render in `span.de-icon`, sized by font-size.
- `IconsProvider` gives standalone views the same icons; nested
  providers fall back to the enclosing one.
- Docs with Lucide and Phosphor resolvers; unit test for precedence,
  e2e spec for DOCX, XLSX and PPTX chrome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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