Theming

Teryx uses CSS custom properties for its entire design system. Switch themes at runtime or create your own.

Built-in Themes

Color Palette

primary
secondary
success
warning
danger
info

setTheme API

import { setTheme, getTheme, getThemeNames } from 'teryx';
setTheme('dark');
console.log(getTheme()); // 'dark'
console.log(getThemeNames()); // ['light', 'dark', 'highContrast']

registerTheme API

import { registerTheme, setTheme } from 'teryx';
registerTheme({
  name: 'ocean',
  vars: {
    '--tx-primary': '#0ea5e9',
    '--tx-primary-hover': '#0284c7',
    '--tx-primary-light': '#e0f2fe',
    '--tx-bg': '#f0f9ff',
    '--tx-bg-secondary': '#e0f2fe',
    '--tx-text': '#0c4a6e',
    '--tx-border': '#7dd3fc',
  },
});
setTheme('ocean');

registerTheme() does not activate the theme. Call setTheme(name) afterwards.

CSS Variables Reference

Colors

VariableDefaultDescription
--tx-primary#3b82f6Primary brand color
--tx-primary-hover#2563ebHover state
--tx-primary-light#dbeafeLight background
--tx-secondary#6b7280Secondary
--tx-success#10b981Success
--tx-warning#f59e0bWarning
--tx-danger#ef4444Danger
--tx-info#06b6d4Info

Surfaces

VariableDefaultDescription
--tx-bg#ffffffPage background
--tx-bg-secondary#f9fafbSidebars, headers
--tx-bg-tertiary#f3f4f6Code blocks
--tx-surface#ffffffCards, panels
--tx-overlayrgba(0,0,0,0.5)Backdrop

Text

VariableDefaultDescription
--tx-text#111827Primary text
--tx-text-secondary#6b7280Secondary text
--tx-text-muted#9ca3afMuted text

Borders, Shadows, Typography

VariableDefaultDescription
--tx-border#e5e7ebDefault border
--tx-shadow-sm0 1px 3px ...Small shadow
--tx-shadow0 4px 6px ...Default shadow
--tx-fontsystem stackFont family
--tx-font-monomonospace stackMono font
--tx-radius0.375remBorder radius

Layout

VariableDefaultDescription
--tx-sidebar-width260pxSidebar width
--tx-navbar-height56pxNavbar height
--tx-container-max1280pxMax container

CSS-Only Theming

:root {
  --tx-primary: #8b5cf6;
  --tx-primary-hover: #7c3aed;
  --tx-radius: 0.75rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --tx-bg: #111827;
    --tx-text: #f9fafb;
    --tx-border: #374151;
  }
}

Dark Mode Toggle

<button id="theme-toggle">Toggle Dark Mode</button>
<script>
  document.getElementById('theme-toggle').addEventListener('click', () => {
    const cur = Teryx.getTheme();
    Teryx.setTheme(cur === 'light' ? 'dark' : 'light');
  });
</script>

The data-theme attribute on <html> is set automatically by setTheme(). Use it for theme-specific CSS: [data-theme="dark"] .my-class { ... }