Socket
Book a DemoInstallSign in
Socket

@choiceform/design-tokens

Package Overview
Dependencies
Maintainers
10
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@choiceform/design-tokens

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

0.2.11
latest
Source
npmnpm
Version published
Weekly downloads
350
-73.6%
Maintainers
10
Weekly downloads
ย 
Created
Source

๐ŸŽจ @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

TypeCountExamples
Colors243background.*, text.*, border.*, icon.*
Typography39heading.large, body.medium, code.small
SpacingFlexiblespacing(4), spacing("1/2"), custom values
Shadows22sm, md, lg, xl (with theme variants)
Breakpoints6xs, sm, md, lg, xl, 2xl
Radius3sm, md, lg
Z-Index9sticky, 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

Keywords

design-tokens

FAQs

Package last updated on 01 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.