✨ Add tokens package (@navikt/ds-tokens)

Color, spacing, radius and typography tokens defined in src/tokens.json,
compiled to CSS custom properties on the --a-* namespace by build.mjs.
This commit is contained in:
Aksel Mini committed 2026-08-04 10:30:00 +02:00
1 parent eead0535a2
commit 7382e691ef
4 files changed
+125

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
# @navikt/ds-tokens
Design tokens for Aksel Mini. Tokens live in `src/tokens.json` and are compiled to
CSS custom properties under the `--a-*` namespace by `build.mjs`.
## Usage
```css
@import "@navikt/ds-tokens/dist/tokens.css";
```
+31
View File
@@ -0,0 +1,31 @@
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = dirname(fileURLToPath(import.meta.url));
const tokens = JSON.parse(readFileSync(join(root, "src", "tokens.json"), "utf8"));
function flatten(node, prefix = []) {
return Object.entries(node).flatMap(([key, value]) =>
typeof value === "object" && "value" in value
? [[prefix.concat(key).join("-"), value.value]]
: flatten(value, prefix.concat(key)),
);
}
const lines = flatten(tokens)
.sort(([a], [b]) => a.localeCompare(b))
.map(([name, value]) => ` --a-${name}: ${value};`);
const css = `/**
* Design tokens — generated by build.mjs from src/tokens.json. Do not edit manually.
*/
:root {
${lines.join("\n")}
}
`;
mkdirSync(join(root, "dist"), { recursive: true });
writeFileSync(join(root, "dist", "tokens.css"), css);
console.log(`Emitted ${lines.length} tokens to dist/tokens.css`);
+14
View File
@@ -0,0 +1,14 @@
{
"name": "@navikt/ds-tokens",
"version": "0.1.0",
"description": "Design tokens for Aksel Mini, emitted as CSS custom properties",
"license": "MIT",
"type": "module",
"files": [
"dist"
],
"scripts": {
"build": "node build.mjs",
"clean": "rm -rf dist"
}
}
+70
View File
@@ -0,0 +1,70 @@
{
"color": {
"bg": {
"default": { "value": "#ffffff" },
"subtle": { "value": "#f2f3f5" }
},
"text": {
"default": { "value": "#23262a" },
"subtle": { "value": "#555a65" },
"on-action": { "value": "#ffffff" },
"on-danger": { "value": "#ffffff" }
},
"surface": {
"action": { "value": "#0067c5" },
"action-hover": { "value": "#0056b4" },
"action-active": { "value": "#00459c" },
"danger": { "value": "#c30000" },
"danger-hover": { "value": "#a80000" },
"info-moderate": { "value": "#e6f0ff" },
"success-moderate": { "value": "#ccf1d6" },
"warning-moderate": { "value": "#fff9e0" },
"error-moderate": { "value": "#ffdcdc" }
},
"border": {
"default": { "value": "#6b7280" },
"subtle": { "value": "#c9ccd1" },
"action": { "value": "#0067c5" },
"danger": { "value": "#c30000" },
"focus": { "value": "#0056b4" }
},
"icon": {
"default": { "value": "#23262a" },
"action": { "value": "#0067c5" },
"success": { "value": "#06893a" },
"warning": { "value": "#b26d14" },
"danger": { "value": "#c30000" }
}
},
"spacing": {
"1": { "value": "0.25rem" },
"2": { "value": "0.5rem" },
"3": { "value": "0.75rem" },
"4": { "value": "1rem" },
"5": { "value": "1.25rem" },
"6": { "value": "1.5rem" },
"8": { "value": "2rem" }
},
"border-radius": {
"small": { "value": "2px" },
"medium": { "value": "4px" },
"large": { "value": "8px" },
"full": { "value": "9999px" }
},
"font": {
"family": { "value": "\"Source Sans 3\", \"Source Sans Pro\", Arial, sans-serif" },
"weight": {
"regular": { "value": "400" },
"bold": { "value": "600" }
},
"size": {
"xs": { "value": "0.875rem" },
"md": { "value": "1.125rem" },
"heading-xsmall": { "value": "1.125rem" },
"heading-small": { "value": "1.25rem" },
"heading-medium": { "value": "1.5rem" },
"heading-large": { "value": "1.75rem" },
"heading-xlarge": { "value": "2rem" }
}
}
}