Skip to content

Theme & dark mode

// 1. Auto (default in v2.7) — follows the OS preference reactively
<ThemeProvider mode="auto">{children}</ThemeProvider>
// 2. Pinned dark
<ThemeProvider mode="dark">{children}</ThemeProvider>
// 3. Pinned light
<ThemeProvider mode="light">{children}</ThemeProvider>

mode="auto" reads (prefers-color-scheme: dark) on mount and subscribes to changes — flipping themes live when the user switches their OS.

import { usePrefersColorScheme } from 'tekivex-ui';
function MyComponent() {
const scheme = usePrefersColorScheme(); // "dark" | "light"
return <p>You prefer {scheme}.</p>;
}

Built-in: quantumDark (default for dark) and auroraLight (default for light). Compose your own via createTheme:

import { ThemeProvider, createTheme, quantumDark } from 'tekivex-ui';
const myDark = createTheme(quantumDark, {
primary: '#ff00aa',
secondary: '#7700ff',
});
<ThemeProvider theme={myDark}>{children}</ThemeProvider>

createTheme validates every token at runtime — invalid hex throws, and contrast that fails WCAG AA logs a console warning.

Generate a 50–900 colour scale from any hex:

import { generatePalette } from 'tekivex-ui';
const brand = generatePalette('#7b2ff7');
// → { 50: '#…', 100: '…', 200: '…', …, 900: '…' }

Inside the React tree, <html> gets a data-tkx-scheme="dark" (or "light") attribute. Use that to write scheme-aware CSS:

html[data-tkx-scheme='dark'] .my-element {
background: rgba(255, 255, 255, 0.04);
}

tkx() and cx() are zero-runtime helpers — atomic class names resolved at build time:

import { tkx, cx } from 'tekivex-ui';
<div className={cx('p-4 rounded-lg', isActive && tkx('bg-primary text-white'))} />

No Tailwind dependency. The generated CSS is tree-shaken to only the atoms you actually use.