Skip to content

feat: theme system and tabs - #16

Merged
SamTV12345 merged 2 commits into
mainfrom
feat/theme-system
Nov 23, 2026
Merged

SamTV12345 merged 2 commits into
mainfrom
feat/theme-system

Conversation

@SamTV12345

Copy link
Copy Markdown
Member

Second step of the component library: a theme system that etherpad-go can build its own design on, while colibris (light green) stays the default for etherpad-lite.

Builds on #13 (pnpm 11 CI) – that commit is included here; merge #13 first.

Theme system

  • themes.ts (also exported as /themes.js, no custom elements): defineTheme(name, partialTokens, base) only needs the tokens that differ, themeToCss(), applyTheme(), onThemeDefined().
  • New tokens: --primary-text-color, --danger-color, --success-color, --warning-color, --focus-color, --radius, --radius-large, --shadow. All components read them; the previous values stay as fallbacks, so colibris looks exactly as before.
  • <ep-theme>: name="auto" with light/dark (follows prefers-color-scheme), .tokens for single overrides, data-scheme, ep-theme-change, live update when a theme is redefined, stale tokens removed when switching.

Components

  • <ep-tabs> / <ep-tab> (underline / pills), keyboard navigation (arrows, Home/End, skips disabled tabs).
  • ep-checkbox is announced as a switch.
  • Fix: toast icons used fill="var(...)" which browsers ignore → style="fill: ...".

Tests

  • Unit tests for the theme functions, Storybook play tests for tabs, custom accent, auto and applyTheme (19 files / 112 tests locally).

Generated by Claude Code

- themes.ts: token sets without custom elements; defineTheme() inherits
  missing tokens from a base theme, themeToCss(), applyTheme(),
  onThemeDefined()
- new tokens: primary-text, danger, success, warning, focus, radius,
  radius-large, shadow; all components read them (fallbacks unchanged)
- <ep-theme>: name="auto" with light/dark, .tokens overrides,
  data-scheme, ep-theme-change, live update on redefinition, removes
  stale tokens when switching
- <ep-tabs>/<ep-tab> with keyboard navigation (arrows, Home/End)
- checkbox announces itself as switch; toast icons use style fill
  (presentation attributes ignore var())

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012RMvvMtnCwj6ycD9fwLYVu
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add reusable themes and accessible tabs

✨ Enhancement 🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Add inheritable themes and standalone theme utilities for branded designs without changing
 components.
• Add automatic light/dark theming, token overrides, and keyboard-accessible tabs.
• Expand theme tests and fix switch announcements and toast icon colors.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 3 capabilities

  • 3 affected capabilities span independent functional scopes: component_theming, tab_navigation.
  • All listed changes alter the same end-to-end behavior: rendering existing component surfaces according to inherited theme tokens.
  • The files are separate component implementations, but they consume one bounded theming contract rather than representing independent business capabilities.
  • These APIs form one bounded theming integration: definitions feed EpTheme instances, inline token application, CSS serialization, and downstream component CSS.
  • The registry, listener set, and element application are propagation hops within that integration, not separate functional scopes.
  • Tab navigation is an independent user-facing behavior from the component theming integration: it maps user clicks or keyboard commands to one selected tab, one visible panel, and an ep-tab-change event.
  • Package and index edits only expose this same capability and do not create separate capabilities.
Sources

src/themes.ts[194-208]

export function applyTheme(el: HTMLElement, theme: string | Partial<ThemeTokens>): void {
  const tokens = typeof theme === 'string' ? themes[theme] : theme;
  if (!tokens) return;
  const previous = applied.get(el) ?? [];
  const next: string[] = [];
  for (const [prop, value] of Object.entries(tokens)) {
    if (value === undefined || value === '') continue;
    el.style.setProperty(prop, String(value));
    next.push(prop);
  }
  for (const prop of previous) {
    if (!next.includes(prop)) el.style.removeProperty(prop);
  }
  applied.set(el, next);
}
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Data transformation

  • Before: EpTheme selected one complete static token set and applied it on name changes.
  • After: partial definitions are merged with a base; EpTheme resolves auto mode through media-query state, subscribes to runtime registry notifications, merges per-element overrides, tracks previously applied properties for cleanup, and derives scheme state from parsed or browser-resolved colors.
  • New correctness conditions are: precedence between base, selected theme, and per-element tokens; consistency between registry updates and every subscribed element; correct cleanup of properties removed by a later application; and agreement between color resolution and data-scheme.
  • These are newly interacting states, not merely reuse of the existing CSS custom-property mechanism.
Sources

src/themes.ts[194-208]

export function applyTheme(el: HTMLElement, theme: string | Partial<ThemeTokens>): void {
  const tokens = typeof theme === 'string' ? themes[theme] : theme;
  if (!tokens) return;
  const previous = applied.get(el) ?? [];
  const next: string[] = [];
  for (const [prop, value] of Object.entries(tokens)) {
    if (value === undefined || value === '') continue;
    el.style.setProperty(prop, String(value));
    next.push(prop);
  }
  for (const prop of previous) {
    if (!next.includes(prop)) el.style.removeProperty(prop);
  }
  applied.set(el, next);
}
Potential damage 🟡 Medium 🩹 Recoverable

  • A faulty theme transition can leave a page with stale, incomplete, or visually incorrect styling and can affect multiple themed components within the target subtree.
  • Reverting code restores behavior, but already-applied inline properties may require a subsequent applyTheme call or page reload; no persistent business data or external effect is involved.
  • Recoverable through a corrected theme application, redefinition, or reload.
  • Code rollback alone does not necessarily remove inline properties already written during the activated transition, so state cleanup may be required.
Sources

src/themes.ts[194-208]

export function applyTheme(el: HTMLElement, theme: string | Partial<ThemeTokens>): void {
  const tokens = typeof theme === 'string' ? themes[theme] : theme;
  if (!tokens) return;
  const previous = applied.get(el) ?? [];
  const next: string[] = [];
  for (const [prop, value] of Object.entries(tokens)) {
    if (value === undefined || value === '') continue;
    el.style.setProperty(prop, String(value));
    next.push(prop);
  }
  for (const prop of previous) {
    if (!next.includes(prop)) el.style.removeProperty(prop);
  }
  applied.set(el, next);
}
Assessed commit 862743f
Diagram

graph TD
  Registry["Theme Registry"] --> Provider(["EpTheme Provider"]) --> Tokens["CSS Tokens"] --> Components(["Existing Components"])
  Tokens --> Tabs(["EpTabs Group"]) --> Tab(["EpTab Panels"])
  Registry --> Tokens
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. CSS stylesheet presets
  • ➕ Uses CSS cascade rather than an inline-token registry
  • ➕ Could simplify static theme delivery
  • ➖ Makes runtime theme registration and scoped overrides harder
  • ➖ Requires a separate strategy for automatic switching and change notifications

Recommendation: Keep the standalone theme utilities and scoped EpTheme provider: they support both programmatic use and dynamic per-subtree themes without making consumers load a custom element. CSS-only presets are attractive for static themes but do not serve the runtime behavior as directly.

Files changed (21) +822 / -130

Enhancement (15) +554 / -111
package.jsonExpose tabs and standalone themes entry points +2/-0

Expose tabs and standalone themes entry points

• Adds package subpath exports for EpTabs.js and themes.js so consumers can import either without using the full library entry point.

package.json

EpButton.tsTheme button shape, focus, and accent text +4/-4

Theme button shape, focus, and accent text

• Reads radius, focus-ring color, and primary-button text color from tokens while retaining CSS fallbacks.

src/EpButton.ts

EpCard.tsTheme card radius and shadow +2/-2

Theme card radius and shadow

• Makes card shape and elevation configurable through the large-radius and shadow tokens.

src/EpCard.ts

EpColorPicker.tsTheme picker shadow and focus ring +2/-2

Theme picker shadow and focus ring

• Uses shared shadow and focus-color tokens for the picker surface and swatches.

src/EpColorPicker.ts

EpDropdown.tsTheme dropdown surface +2/-2

Theme dropdown surface

• Replaces fixed dropdown radius and shadow values with shared surface tokens.

src/EpDropdown.ts

EpDropdownItem.tsTheme dropdown-item focus ring +1/-1

Theme dropdown-item focus ring

• Uses the focus-color token for keyboard focus styling.

src/EpDropdownItem.ts

EpInput.tsTheme input shape and error state +3/-3

Theme input shape and error state

• Uses radius and danger-color tokens for input corners, error borders, and error text.

src/EpInput.ts

EpModal.tsTheme modal and prompt shapes +6/-6

Theme modal and prompt shapes

• Applies radius and shadow tokens to the dialog and its controls, including the programmatically created prompt input.

src/EpModal.ts

EpNotification.tsTheme notification elevation and errors +4/-4

Theme notification elevation and errors

• Connects notification radius and shadow to shared tokens and uses the danger-color token for error styling.

src/EpNotification.ts

EpSelect.tsTheme select control corners +2/-2

Theme select control corners

• Uses the radius token for both the select control and its menu.

src/EpSelect.ts

EpTabs.tsAdd tab group and tab panels +235/-0

Add tab group and tab panels

• Introduces ep-tabs and ep-tab with underline and pills variants, selection events, disabled-tab handling, and arrow/Home/End navigation. The group derives buttons from child tabs and shows the selected panel.

src/EpTabs.ts

EpTheme.tsExtend the theme provider with automatic selection +67/-82

Extend the theme provider with automatic selection

• Moves token definitions to the standalone theme module and adds light/dark selection, per-element overrides, scheme metadata, and theme-change events. Connected providers also respond to theme redefinitions and remove stale applied tokens.

src/EpTheme.ts

EpToolbarSelect.tsTheme toolbar select radius and focus +2/-2

Theme toolbar select radius and focus

• Uses shared radius and focus-color tokens for the toolbar select trigger.

src/EpToolbarSelect.ts

index.tsExport tabs and theme utilities +3/-1

Export tabs and theme utilities

• Adds EpTabs and EpTab to the library entry point and re-exports the standalone theme API alongside EpTheme.

src/index.ts

themes.tsIntroduce standalone theme registry and utilities +219/-0

Introduce standalone theme registry and utilities

• Defines expanded built-in token sets and APIs for inherited theme definitions, CSS generation, direct application, and definition notifications. The module has no custom-element registration.

src/themes.ts

Bug fix (2) +8 / -8
EpCheckbox.tsAnnounce checkbox as a switch +2/-2

Announce checkbox as a switch

• Adds a switch role to the native input and uses the focus-color token for its visible focus ring.

src/EpCheckbox.ts

EpToast.tsFix toast icon colors and theme toast styling +6/-6

Fix toast icon colors and theme toast styling

• Moves SVG fill values into inline styles so CSS custom properties resolve, including the new danger color for errors. Uses shared radius and shadow tokens for the toast surface.

src/EpToast.ts

Tests (3) +219 / -1
EpTabs.stories.tsExercise tab variants and navigation +94/-0

Exercise tab variants and navigation

• Adds Storybook stories and play assertions for tab selection, events, disabled-tab skipping, keyboard navigation, pills styling, and unknown-value fallback.

stories/EpTabs.stories.ts

EpTheme.stories.tsDemonstrate and test dynamic themes +78/-1

Demonstrate and test dynamic themes

• Adds stories exercising custom accent themes, local overrides, live redefinition, scheme changes, automatic selection, and direct token application.

stories/EpTheme.stories.ts

themes.test.tsTest standalone theme utilities +47/-0

Test standalone theme utilities

• Adds unit tests for built-in token completeness, inheritance, listener notifications, CSS generation, and background-based dark detection.

test/themes.test.ts

Documentation (1) +41 / -10
README.mdDocument package imports, theming, and tabs +41/-10

Document package imports, theming, and tabs

• Corrects installation and import examples to use the scoped package. Documents theme tokens and utilities, automatic theme selection, overrides, and the new tabs API.

README.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Duplicate tab values show multiple panels ✓ Resolved
Description
_sync() shows every panel whose effective value equals selected, without ensuring that effective
values are unique. Two tabs with the same explicit value, or an explicit value matching another
tab’s position-derived value, therefore show both panels and cannot be selected independently.

2. Screen readers cannot link tabs to panels ✓ Resolved
Description
EpTabs.render() creates tab buttons without aria-controls, while EpTab assigns
role="tabpanel" without an ID or a reference back to its tab. Assistive technology encounters the
tabs and panels without an explicit association, particularly when several panels are present.

3. Arrow keys can skip the focused tab ✓ Resolved
Description
_onKeydown() calculates its starting position from this.selected rather than the focused button.
If an application changes value while focus remains on the former selection, the next arrow press
moves relative to the new selection instead of the button under keyboard focus.

View medium (6)
4. Success notices ignore their theme color ✓ Resolved
Description
ThemeTokens introduces --success-color, but success notifications and toasts still read
--primary-color for their icons and borders. A theme with a distinct success color changes neither
component’s success appearance.

5. Default buttons lose their original radius ✓ Resolved
Description
EpButton now reads --radius for its main button, and the colibris theme sets that token to 3px
despite the button’s previous 4px radius. Buttons inside the default `` therefore change shape
even though the new theme is intended to preserve their existing appearance.

6. Background overrides leave the wrong scheme ✓ Resolved
Description
EpTheme._applyTokens() passes the merged theme and per-element overrides to applyTheme() but
passes only base to isDark(). When .tokens overrides --bg-color from light to dark or the
reverse, the rendered background changes while data-scheme reflects the original theme, affecting
styling keyed on that attribute.

7. Dark themes using named colors look light ✓ Resolved
Description
isDark() returns false unless --bg-color matches a three- or six-digit hex literal. A custom
theme using a valid dark CSS color such as black or rgb(0, 0, 0) consequently receives
data-scheme="light".

8. Custom shadows leave select menus unchanged ✓ Resolved
Description
EpSelect changes its menu radius to a theme token but retains a hard-coded menu shadow rather than
reading the new --shadow token. Themes that remove or change elevation update other floating
surfaces but leave the select menu’s shadow intact.

9. Theme CSS output can be escaped by crafted tokens ✓ Resolved
Description
themeToCss removes only ;, { and } from values. It writes token keys, the selector, and ``
in values into the output unchanged. When a token object comes from user or tenant input (the README
suggests rendering it server-side), a key like --a:x}body{… or a value containing `` gets past the
filter, so the output can inject CSS or, inside a `` tag, HTML/script.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

- tabs: unique keys per tab (duplicate values no longer show two
  panels), arrow keys start at the focused tab, buttons point at their
  panels via ariaControlsElements where supported
- success notices/toasts use --success-color, select menu uses --shadow
- --radius is 4px (buttons unchanged); inputs/selects use radius - 1px
- data-scheme uses the merged tokens, resolves any CSS colour in the
  browser, honours --color-scheme; parseColor() for hex/rgb/names
- themeToCss() rejects invalid token names and unsafe values

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012RMvvMtnCwj6ycD9fwLYVu
@SamTV12345
SamTV12345 merged commit d19b5c3 into main Nov 23, 2026
3 checks passed
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