Theming
Teryx uses CSS custom properties for its entire design system. Switch themes at runtime or create your own.
Built-in Themes
- light (default) -- White backgrounds, dark text
- dark -- Dark backgrounds, light text
- highContrast -- Maximum contrast for accessibility
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
| Variable | Default | Description |
|---|---|---|
--tx-primary | #3b82f6 | Primary brand color |
--tx-primary-hover | #2563eb | Hover state |
--tx-primary-light | #dbeafe | Light background |
--tx-secondary | #6b7280 | Secondary |
--tx-success | #10b981 | Success |
--tx-warning | #f59e0b | Warning |
--tx-danger | #ef4444 | Danger |
--tx-info | #06b6d4 | Info |
Surfaces
| Variable | Default | Description |
|---|---|---|
--tx-bg | #ffffff | Page background |
--tx-bg-secondary | #f9fafb | Sidebars, headers |
--tx-bg-tertiary | #f3f4f6 | Code blocks |
--tx-surface | #ffffff | Cards, panels |
--tx-overlay | rgba(0,0,0,0.5) | Backdrop |
Text
| Variable | Default | Description |
|---|---|---|
--tx-text | #111827 | Primary text |
--tx-text-secondary | #6b7280 | Secondary text |
--tx-text-muted | #9ca3af | Muted text |
Borders, Shadows, Typography
| Variable | Default | Description |
|---|---|---|
--tx-border | #e5e7eb | Default border |
--tx-shadow-sm | 0 1px 3px ... | Small shadow |
--tx-shadow | 0 4px 6px ... | Default shadow |
--tx-font | system stack | Font family |
--tx-font-mono | monospace stack | Mono font |
--tx-radius | 0.375rem | Border radius |
Layout
| Variable | Default | Description |
|---|---|---|
--tx-sidebar-width | 260px | Sidebar width |
--tx-navbar-height | 56px | Navbar height |
--tx-container-max | 1280px | Max 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 { ... }