๐จ @choiceform/design-tokens
A type-safe, W3C-compliant design token system that bridges the gap between design and development.

โจ Features
- ๐ Type-Safe: 100% TypeScript with strict mode and intelligent autocomplete
- ๐ฏ W3C Compliant: Fully adheres to the W3C Design Tokens specification
- ๐ Multi-Theme: Seamless light/dark mode switching
- ๐ฆ Multiple Formats: CSS, SCSS, JavaScript, and TypeScript outputs
- ๐ Smart Aliases: Intuitive naming like
background.default
and text.secondary
- โก Zero Runtime: Optional compile-time CSS generation
๐ฆ Installation
npm install @choiceform/design-tokens
pnpm add @choiceform/design-tokens
yarn add @choiceform/design-tokens
๐ Quick Start
JavaScript/TypeScript
import {
color,
spacing,
shadow,
typography,
radius,
breakpoint,
} from "@choiceform/design-tokens";
const styles = {
background: color("background.default"),
color: color("text.secondary", "dark"),
border: color("border.strong", 0.5),
};
const layout = {
padding: spacing(4),
margin: spacing("1/2"),
gap: spacing("[10vh]"),
};
const components = {
borderRadius: radius("md"),
boxShadow: shadow("lg"),
fontFamily: typography("heading.large").fontFamily,
zIndex: zIndex("modal"),
};
const mediaQuery = breakpoint.up("md");
CSS Variables
@import "@choiceform/design-tokens/tokens.css";
.my-component {
background: var(--color-background-default);
color: var(--color-text-secondary);
padding: var(--spacing-4);
border-radius: var(--radius-md);
box-shadow: var(--shadow-lg);
}
SCSS with Functions
@import "@choiceform/design-tokens/functions";
@import "@choiceform/design-tokens/mixins";
.component {
background: color("background.default");
padding: spacing(4);
border-radius: radius("md");
@include typography-styles("heading.large");
@include up("md") {
padding: spacing(6);
@include typography-styles("heading.display");
}
}
๐ฏ Core APIs
Colors
color("background.default");
color("text.accent", "dark");
color("border.default", 0.8);
color("background.default");
color("text.secondary");
color("border.strong");
color("icon.primary");
Spacing
spacing(4);
spacing(8);
spacing("1/2");
spacing("1/3");
spacing("[10vh]");
spacing("[calc(100% - 2rem)]");
spacingList([2, 4]);
Typography
const heading = typography("heading.large");
const cssString = typographyStyles("body.medium");
fontFamily("default");
fontSize("lg");
fontWeight("semibold");
Responsive Breakpoints
breakpoint.up("md");
breakpoint.down("lg");
breakpoint.between("sm", "xl");
breakpoint.only("md");
breakpoint.mobile();
breakpoint.tablet();
breakpoint.desktop();
๐ Advanced Usage
Theme Switching
const autoStyles = {
background: color("background.default"),
color: color("text.default"),
};
const lightStyles = {
background: color("background.default", "light"),
color: color("text.default", "light"),
};
const darkStyles = {
background: color("background.default", "dark"),
color: color("text.default", "dark"),
};
SCSS Best Practices
@import "@choiceform/design-tokens/functions";
@import "@choiceform/design-tokens/mixins";
.card {
background: color("background.default");
padding: spacing(4);
border: 1px solid color("border.default");
}
.heading {
@include typography-styles("heading.large");
@include text-ellipsis();
}
.responsive-component {
@include typography-styles("body.medium");
@include up("md") {
@include typography-styles("body.large");
}
}
Performance Optimization
import { color } from "@choiceform/design-tokens";
const margins = spacingList([2, 4, 6, 8]);
const shadows = shadowList(["sm", "md"]);
const styles = {
padding: spacing(4),
margin: spacing(props.size),
};
๐ Token Overview
Colors | 243 | background.* , text.* , border.* , icon.* |
Typography | 39 | heading.large , body.medium , code.small |
Spacing | Flexible | spacing(4) , spacing("1/2") , custom values |
Shadows | 22 | sm , md , lg , xl (with theme variants) |
Breakpoints | 6 | xs , sm , md , lg , xl , 2xl |
Radius | 3 | sm , md , lg |
Z-Index | 9 | sticky , modal , tooltip , etc. |
๐จ Available Exports
import "@choiceform/design-tokens/tokens.css";
import "@choiceform/design-tokens/preflight.css";
@import "@choiceform/design-tokens/functions";
@import "@choiceform/design-tokens/mixins";
@import "@choiceform/design-tokens/tokens";
import {
color, spacing, shadow, typography, radius, zIndex,
spacingList, shadowList, typographyStyles,
breakpoint, fontFamily, fontSize, fontWeight
} from "@choiceform/design-tokens";
๐ค Support
๐ License
MIT License - see the LICENSE file for details.