Liking cljdoc? Tell your friends :D

x-theme

Centralised theming wrapper for BareDom web components. Wrap any subtree with <x-theme> to apply a consistent design token palette to all descendant components.

All BareDom components are theme-aware out of the box. Each component references the 33 design tokens defined by x-theme via var(--x-token, fallback) — they work identically with or without a theme wrapper.

Every component demo page includes a theme preset picker for live preview.

Tag

<x-theme preset="ocean">
  <x-button>Themed button</x-button>
  <x-alert text="Themed alert"></x-alert>
</x-theme>

Attributes

AttributeTypeDefaultDescription
presetstring"default"Name of a built-in or custom preset.

Properties

PropertyTypeReflectsDescription
.presetstringyesGets/sets the preset attribute.

Events

None.

Slots

SlotDescription
(default)All child content. Tokens cascade into children.

CSS Custom Properties (Design Tokens)

These tokens are set by x-theme on its :host and inherited by all descendant components via CSS custom property inheritance through shadow DOM.

Colors (20 tokens)

TokenDescription
--x-color-primaryPrimary brand color
--x-color-primary-hoverPrimary hover state
--x-color-primary-activePrimary active/pressed state
--x-color-secondarySecondary accent color
--x-color-secondary-hoverSecondary hover state
--x-color-secondary-activeSecondary active state
--x-color-tertiaryTertiary/subtle accent
--x-color-tertiary-hoverTertiary hover state
--x-color-tertiary-activeTertiary active state
--x-color-surfaceCard/panel background
--x-color-surface-hoverSurface hover state
--x-color-surface-activeSurface active/pressed state
--x-color-bgPage-level background
--x-color-textPrimary text color
--x-color-text-mutedSecondary/muted text
--x-color-borderDefault border color
--x-color-focus-ringFocus indicator color
--x-color-dangerDestructive/error actions
--x-color-successSuccess/positive states
--x-color-warningWarning/caution states

Typography (4 tokens)

TokenDefault
--x-font-familysystem-ui, -apple-system, sans-serif
--x-font-family-monoui-monospace, 'SF Mono', monospace
--x-font-size-sm0.875rem
--x-font-size-base1rem

Shape (4 tokens)

TokenDefault
--x-radius-sm0.375rem
--x-radius-md0.75rem
--x-radius-lg1rem
--x-radius-full9999px

Elevation (3 tokens)

TokenDescription
--x-shadow-smSubtle shadow
--x-shadow-mdMedium elevation
--x-shadow-lgHigh elevation

Motion (2 tokens)

TokenDefault
--x-transition-duration140ms
--x-transition-easingcubic-bezier(0.2,0,0,1)

Built-in Presets

PresetDescription
defaultBlue/slate palette matching existing component defaults.
oceanTeal/cyan, cool aquatic tones.
forestGreen/earth, warm natural tones.
sunsetOrange/red, warm vibrant tones.
neo-brutalistHigh-contrast black/white, zero border-radius, offset shadows.
auroraSoft purple/teal/pink with semi-transparent surfaces.
mono-aiMonochrome + neon cyan accent, monospace font.
warm-mineralEarthy terracotta/sand/clay, digital naturalism.

All presets define both light and dark mode token values. Dark mode is activated automatically via @media (prefers-color-scheme: dark).

Custom Themes

CSS property overrides

Override any token directly on the element:

<x-theme preset="default" style="--x-color-primary: #e11d48;">
  <x-button>Custom accent</x-button>
</x-theme>

registerPreset() API

Register a reusable named preset via JavaScript:

import { registerPreset } from '@vanelsas/baredom/x-theme';

registerPreset("acme-brand", {
  light: {
    "--x-color-primary": "#e11d48",
    "--x-color-secondary": "#7c3aed",
    "--x-color-surface": "#fefefe"
  },
  dark: {
    "--x-color-primary": "#fb7185",
    "--x-color-secondary": "#a78bfa",
    "--x-color-surface": "#1a1a2e"
  }
});

Then use it like any built-in preset:

<x-theme preset="acme-brand">...</x-theme>

Partial presets are supported. Any tokens not specified fall back to the default preset values.

Multiple Themes Per Page

<x-theme preset="ocean">
  <x-sidebar>...</x-sidebar>
</x-theme>

<x-theme preset="sunset">
  <main>...</main>
</x-theme>

Nested Themes

Inner <x-theme> elements override outer ones via CSS custom property inheritance:

<x-theme preset="ocean">
  <x-button>Ocean button</x-button>
  <x-theme preset="sunset">
    <x-button>Sunset button (overrides ocean)</x-button>
  </x-theme>
</x-theme>

Accessibility

  • x-theme uses display: contents and adds no visual or interactive elements.
  • All theme tokens respect @media (prefers-color-scheme: dark) for dark mode support.
  • The neo-brutalist preset provides high contrast suitable for accessibility needs.

Rendering

x-theme is a pure theming scope. It uses shadow DOM with only a <style> element and a <slot>. It has no visual rendering of its own and does not affect layout (display: contents).

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close