Consistent design, zero guesswork.
A type-safe color token system with light/dark theme support built for @builder.io/qwik.
日本語 | English
- Color Token System - Structured color categories (surface, content, accent, semantic, status indicators) with light/dark variants
- Qwik Hooks -
useTheme()anduseColorPreference()for reactive theme management - CSS Variable Utilities -
getCSSVariable(),colorClass(),colorStyle()for flexible styling - System Preference Detection - Automatic
prefers-color-schemedetection with live updates - Generated CSS - Pre-built CSS file with all token variables for direct import
- Sub-path Exports - Import only what you need:
./tokens,./colors,./utils,./css
npm install @aid-on/design-systemPeer dependency:
npm install @builder.io/qwik@^1.11.0import { useTheme } from "@aid-on/design-system";
export const App = component$(() => {
const { theme, resolvedTheme, setTheme, toggleTheme } = useTheme();
return (
<div>
<p>Current theme: {resolvedTheme.value}</p>
<button onClick$={() => toggleTheme()}>Toggle Theme</button>
<button onClick$={() => setTheme("light")}>Light</button>
<button onClick$={() => setTheme("dark")}>Dark</button>
<button onClick$={() => setTheme("system")}>System</button>
</div>
);
});// Import generated CSS with all color variables
import "@aid-on/design-system/css";.card {
background-color: var(--surface);
color: var(--content);
border-color: var(--accent-ghost);
}
.card:hover {
background-color: var(--surface-hover);
}
.error-message {
color: var(--red-4);
background-color: var(--red-7);
}The token system is organized into semantic categories, each with light and dark theme variants:
| Category | Tokens | Description |
|---|---|---|
| Surface | --surface, --surface-elevated, --surface-hover, --surface-active, --surface-disabled |
Background colors for containers and layouts |
| Content | --content through --content-ghost |
Text and icon colors with 7 levels of emphasis |
| Accent | --accent through --accent-background |
Interactive element colors with 8 variants |
| Semantic | --white-1 through --white-7 |
Neutral white scale for overlays and borders |
| Caution Red | --red-1 through --red-7 |
Error and destructive action indicators |
| Alert Orange | --orange-1 through --orange-7 |
Warning and caution indicators |
| Success Green | --green-1 through --green-7 |
Success and confirmation indicators |
| Link Blue | --blue-1 through --blue-7 |
Links and informational indicators |
Qwik hook for theme management with reactive state.
const { theme, resolvedTheme, setTheme, toggleTheme } = useTheme();| Return | Type | Description |
|---|---|---|
theme |
Signal<Theme> |
Current theme setting ('light', 'dark', or 'system') |
resolvedTheme |
Signal<'light' | 'dark'> |
Resolved theme after applying system preference |
setTheme |
(theme: Theme) => void |
Set theme and persist to localStorage |
toggleTheme |
() => void |
Toggle between light and dark |
Hook to track system color scheme preference changes.
const preference = useColorPreference();
// preference.value is 'light' or 'dark'Initialize theme from localStorage on app startup. Call this early in your app lifecycle.
import { initializeTheme } from "@aid-on/design-system";
const theme = initializeTheme(); // Returns current themeGet the computed value of a CSS variable at runtime.
import { getCSSVariable } from "@aid-on/design-system";
const surfaceColor = getCSSVariable("--surface");Generate BEM-style class names for components.
import { colorClass } from "@aid-on/design-system";
colorClass("btn"); // "btn"
colorClass("btn", "primary"); // "btn btn--primary"
colorClass("btn", "primary", "hover"); // "btn btn--primary btn--hover"
colorClass("btn", undefined, "disabled"); // "btn btn--disabled"Variants: 'primary', 'secondary', 'accent', 'ghost', 'error', 'warning', 'success', 'info'
States: 'hover', 'active', 'disabled'
Generate inline style objects with CSS variable support.
import { colorStyle } from "@aid-on/design-system";
// CSS variable names are automatically wrapped in var()
colorStyle("--content", "--surface");
// { color: "var(--content)", backgroundColor: "var(--surface)" }
// Raw color values pass through unchanged
colorStyle("#333", "#fff", "#ccc");
// { color: "#333", backgroundColor: "#fff", borderColor: "#ccc" }Get all color tokens as a flat array for a given theme.
import { getAllColorTokens } from "@aid-on/design-system/tokens";
const lightTokens = getAllColorTokens("light");
const darkTokens = getAllColorTokens("dark");Look up a color value by its CSS variable name.
import { getColorByVariable } from "@aid-on/design-system/tokens";
const color = getColorByVariable("--surface", "light"); // "#6C4FEA"Generate CSS custom properties string for a theme.
import { generateColorCSSVariables } from "@aid-on/design-system/tokens";
const css = generateColorCSSVariables("dark");
// :root[data-theme="dark"] { --surface: #6C4FEA; ... }// Everything
import { colors, useTheme, colorStyle } from "@aid-on/design-system";
// Tokens only (no Qwik dependency)
import { colors, getAllColorTokens, getColorByVariable } from "@aid-on/design-system/tokens";
// Colors directly
import { colors, ColorSystem } from "@aid-on/design-system/colors";
// Utilities (requires Qwik)
import { useTheme, getCSSVariable, colorClass } from "@aid-on/design-system/utils";
// CSS file
import "@aid-on/design-system/css";import type {
ColorToken, // { name: string; value: string; description: string }
ColorCategory, // { light: ColorToken[]; dark: ColorToken[] }
ColorSystem, // Full color system with all categories
Theme, // 'light' | 'dark' | 'system'
} from "@aid-on/design-system";useTheme()setsdata-themeattribute on<html>and applies CSS variables inline- Theme preference is persisted to
localStorageunder the keyaid-on-theme - When set to
'system', the hook listens toprefers-color-schememedia query changes - CSS variables are applied directly to
document.documentElement.style, so they override any stylesheet defaults
MIT