npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@choiceform/design-tokens

v0.2.12

Published

Design tokens generator for Choiceform Design System - converts TypeScript tokens to W3C format and outputs to multiple formats

Downloads

897

Readme

🎨 @choiceform/design-tokens

A type-safe, W3C-compliant design token system that bridges the gap between design and development.

npm version TypeScript W3C Standard

✨ 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
npm install @choiceform/design-tokens

# pnpm (recommended)
pnpm add @choiceform/design-tokens

# yarn
yarn add @choiceform/design-tokens

🚀 Quick Start

JavaScript/TypeScript

import {
  color,
  spacing,
  shadow,
  typography,
  radius,
  breakpoint,
} from "@choiceform/design-tokens";

// 🎨 Colors with theme support
const styles = {
  background: color("background.default"), // Auto theme
  color: color("text.secondary", "dark"), // Force dark theme
  border: color("border.strong", 0.5), // With opacity
};

// 📏 Spacing system
const layout = {
  padding: spacing(4), // → "1rem"
  margin: spacing("1/2"), // → "50%"
  gap: spacing("[10vh]"), // → "10vh"
};

// ✨ Other tokens
const components = {
  borderRadius: radius("md"), // → "0.3125rem"
  boxShadow: shadow("lg"), // → theme-aware shadow
  fontFamily: typography("heading.large").fontFamily,
  zIndex: zIndex("modal"), // → 810
};

// 📱 Responsive breakpoints
const mediaQuery = breakpoint.up("md"); // → "@media screen and (min-width: 48rem)"

CSS Variables

/* Import 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 functions (must be first)
@import "@choiceform/design-tokens/functions";
// Import mixins (must be second)
@import "@choiceform/design-tokens/mixins";

.component {
  // 🎯 Individual values with functions
  background: color("background.default");
  padding: spacing(4);
  border-radius: radius("md");

  // 🔥 Multi-property mixins
  @include typography-styles("heading.large");

  // 📱 Responsive design
  @include up("md") {
    padding: spacing(6);
    @include typography-styles("heading.display");
  }
}

🎯 Core APIs

Colors

// Basic usage
color("background.default"); // Auto theme
color("text.accent", "dark"); // Force theme
color("border.default", 0.8); // With opacity

// Available aliases
color("background.default"); // Background colors
color("text.secondary"); // Text colors
color("border.strong"); // Border colors
color("icon.primary"); // Icon colors

Spacing

// Numeric scale (0.25rem increments)
spacing(4); // → "1rem"
spacing(8); // → "2rem"

// Percentage values
spacing("1/2"); // → "50%"
spacing("1/3"); // → "33.333333%"

// Custom values
spacing("[10vh]"); // → "10vh"
spacing("[calc(100% - 2rem)]"); // → "calc(100% - 2rem)"

// Multiple values
spacingList([2, 4]); // → "0.5rem 1rem"

Typography

// Complete typography objects
const heading = typography("heading.large");
// Returns: { fontFamily, fontSize, fontWeight, lineHeight, letterSpacing }

// CSS string for styled-components
const cssString = typographyStyles("body.medium");

// Individual properties
fontFamily("default"); // → "Inter, system-ui, sans-serif"
fontSize("lg"); // → "1.125rem"
fontWeight("semibold"); // → 600

Responsive Breakpoints

// Media queries
breakpoint.up("md"); // → "@media screen and (min-width: 48rem)"
breakpoint.down("lg"); // → "@media screen and (max-width: 63.98rem)"
breakpoint.between("sm", "xl"); // → Between sm and xl
breakpoint.only("md"); // → Only md breakpoint

// Device aliases
breakpoint.mobile(); // → Tablet and up
breakpoint.tablet(); // → Tablet only
breakpoint.desktop(); // → Desktop and up

🌟 Advanced Usage

Theme Switching

// Auto theme (follows system preference)
const autoStyles = {
  background: color("background.default"),
  color: color("text.default"),
};

// Manual theme control
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

// ✅ Correct import order
@import "@choiceform/design-tokens/functions"; // First
@import "@choiceform/design-tokens/mixins"; // Second

// ✅ Use functions for individual properties
.card {
  background: color("background.default");
  padding: spacing(4);
  border: 1px solid color("border.default");
}

// ✅ Use mixins for complex operations
.heading {
  @include typography-styles("heading.large"); // 5 properties at once
  @include text-ellipsis(); // Utility mixin
}

// ✅ Responsive patterns
.responsive-component {
  @include typography-styles("body.medium");

  @include up("md") {
    @include typography-styles("body.large");
  }
}

Performance Optimization

// ✅ Tree shaking - import only what you need
import { color } from "@choiceform/design-tokens";

// ✅ Bulk operations
const margins = spacingList([2, 4, 6, 8]);
const shadows = shadowList(["sm", "md"]);

// ✅ Static values are optimized at build time
const styles = {
  padding: spacing(4), // Static → "1rem"
  margin: spacing(props.size), // Dynamic → runtime
};

📊 Token Overview

| Type | Count | Examples | | --------------- | -------- | ---------------------------------------------- | | 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

// CSS files
import "@choiceform/design-tokens/tokens.css";     // CSS custom properties
import "@choiceform/design-tokens/preflight.css";  // Reset styles

// SCSS files
@import "@choiceform/design-tokens/functions";     // SCSS functions
@import "@choiceform/design-tokens/mixins";        // SCSS mixins
@import "@choiceform/design-tokens/tokens";        // SCSS variables

// JavaScript/TypeScript
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.


Built with ❤️ by the Choiceform Design System Team

Examples · Documentation · npm