Foundations
Theming
Dark, light and system modes, and project brands.
Percent's look is the default. data-theme sets the mode of any element: dark (also without the attribute), light, or system (follows the device). A project writes its brand as one object; brandCss() from @percentsa/tokens turns it into a CSS file, which the project loads after the design-system CSS. Components do not change. checkBrand() returns the color pairs that fail WCAG AA.
import { brandCss, checkBrand } from "@percentsa/tokens";
export const brand = {
"dark": {
"primary": "#3ecf8e",
"primary-fg": "#000000"
},
"light": {
"primary": "#0f5b4a",
"primary-fg": "#ffffff"
},
"vars": {
"font-sans": "\"Brand Sans\", system-ui, sans-serif",
"font-sans-ar": "\"Brand Arabic\", \"Brand Sans\", sans-serif",
"radius-card": "8px"
}
};
// scripts/brand.ts: write the file once, commit it, load it after the design-system CSS.
await Bun.write("app/brand.css", brandCss(brand));
// In a test: expect(checkBrand(brand)).toEqual([]);/* Generated by brandCss() from @percentsa/tokens. Do not edit. */
:root, [data-theme="dark"], [data-theme="system"] {
--p-primary: #3ecf8e;
--p-primary-fg: #000000;
}
[data-theme="light"] {
--p-primary: #0f5b4a;
--p-primary-fg: #ffffff;
}
@media (prefers-color-scheme: light) {
[data-theme="system"] {
--p-primary: #0f5b4a;
--p-primary-fg: #ffffff;
}
}
:root {
--p-font-sans: "Brand Sans", system-ui, sans-serif;
--p-font-sans-ar: "Brand Arabic", "Brand Sans", sans-serif;
--p-radius-card: 8px;
}
Same components
PrimarySecondary
Same components
PrimarySecondary
Same components
PrimarySecondary