Terrazzo Documentation

repository·main·Indexed 19 days ago

https://github.com/terrazzoapp/terrazzo

A design system tooling monorepo for transforming DTCG design tokens into multi-platform code. It includes a CLI for token transformation, a JS API parser for building token systems, and various plugins for generating CSS, Sass, JS/TS, Swift (.xcassets), and Tailwind v4 themes. The ecosystem also provides curated icon sets via @terrazzo/icons and open-source font redistributions via @terrazzo/fonts.

Tokens
139.6K
Snippets
465
Records
598
Agent score
64%

What's inside Terrazzo

  1. Overview of Terrazzo Monorepo

    main

    Terrazzo is a monorepo containing tools for design system automation and color management. Its primary components include:

    • Terrazzo CLI: A tool used to generate code from DTCG tokens (formerly known as Cobalt UI). It supports multiple output formats including CSS, Sass, JS/TS, Swift, and Tailwind.
    • Terrazzo Color Picker: A specialized color picker component designed for wide gamut and high bit-depth color reproduction.
    • Token Lab (Coming Soon): A tool for generating design systems from scratch or starting from existing open-source design systems.
  2. Overview of @terrazzo/token-types

    main
    @terrazzo/token-types provides shared, dependency-free TypeScript types specifically designed for DTCG (Design Tokens Community Group) design tokens. It is intended to be used as a lightweight type definition layer in projects that consume or produce design tokens, ensuring type safety without adding extra weight to your dependency tree.
  3. Install and use @terrazzo/icons

    main
    The @terrazzo/icons package provides a curated set of icons for Terrazzo projects. It contains icons repackaged from the react-icons project to ensure continued maintenance and compatibility. You can use these icons in your React components by importing specific icon components from the package.
  4. Explore Terrazzo Integrations

    main

    Terrazzo provides specialized integration guides for various styling and programming environments. You can find detailed setup instructions and usage patterns for the following technologies:

    • CSS: Standard CSS integration.
    • JS/TS: JavaScript and TypeScript integration.
    • JSON/Native: Integration for JSON-based or native environments.
    • Sass: Integration for Sass preprocessors.
    • Tailwind: Integration for Tailwind CSS.
    • Vanilla Extract: Integration for Vanilla Extract CSS-in-JS.
  5. What is the Token Listing Format?

    main

    The Token Listing Format is a community proposal that provides a predictable, known data structure for design tokens. It improves interoperability between design token tools by consolidating information about:

    • Source tokens: The original design values.
    • Modes: Variations like light/dark themes.
    • Platforms: Where tokens are built (e.g., CSS, Figma, Swift).
    • Name Mappings: How a single token name translates across different platforms (e.g., a Figma variable name vs. a CSS variable name).

    This format is intended for use by tools such as diffing algorithms, changelog generators, documentation websites, and linting plugins.

  6. What is a Resolver?

    main

    A resolver is a DTCG standard meta-file that describes how collections of Design Tokens (DTCG tokens) relate to one another. It acts as an "entry" file for your tokens, similar to how webpack or Rollup works for JavaScript.

    Resolvers are used to:

    • Flatten multiple token JSON files into a single set.
    • Provide contextual token values (e.g., light/dark mode, color themes, or responsive breakpoints).

    Resolvers are the successor to legacy "modes" in Terrazzo/Cobalt.

  7. What is a Resolver in the Plugin API

    main

    A resolver is a specialized tokens file that can generate multiple sets of tokens from a single JSON source. This is primarily used for implementing design modes (e.g., light vs. dark mode) and theming.

    In the Plugin API, the resolver provides a way to access all possible permutations of a token set based on specific inputs. Unlike getTransforms() or setTransforms(), the resolver is used to derive specific token sets by applying inputs to a source file.

  8. Align color token ranges to CSS Color Module 4 in @terrazzo/cli v0.10.0

    main

    Version 0.10.0 introduced breaking changes to align color token ranges with the CSS Color Module 4 specification. Specifically, HSL and HWB color spaces now normalize to a range of 0 - 100 instead of 0 - 1.

    Example Change:

    // Old (0-1 range)
    {
      "colorSpace": "hsl",
      "components": [270, 0.5, 0.4]
    }
    
    // New (0-100 range)
    {
      "colorSpace": "hsl",
      "components": [270, 50, 40]
    }
  9. Understand DTCG Tokens format

    main

    DTCG (Design Tokens Community Group) tokens are a standard, universal design token format stored in JSON. This format allows you to centrally manage design values and generate code for various output targets like web, print, and native apps.

    A token entry typically includes a $type and a $value.

    {
      "rebeccapurple": {
        "$type": "color",
        "$value": {
          "colorSpace": "srgb",
          "components": [0.4, 0.2, 0.6]
        }
      }
    }
  10. How mode selectors work in @terrazzo/plugin-css

    main

    Mode selectors allow you to map your design token modes to CSS media queries, class names, or any other CSS selector. This enables dynamic theme switching (like light/dark mode) or responsive styles (like mobile/desktop) using the same token variable.

    Each entry in the modeSelectors array requires:

    1. mode: The mode name (supports globs like "*-light").
    2. selectors: An array of CSS selectors that trigger this mode.

    You can optionally provide a scheme to automatically set the CSS color-scheme property for that mode.

    Common patterns:

    • Color: prefers-color-scheme, prefers-contrast
    • Duration: prefers-reduced-motion
    • Typography: Viewport width media queries
    // Example: Mapping light and dark modes
    css({
      modeSelectors: [
        {
          mode: "light",
          selectors: ["@media (prefers-color-scheme: light)", '[data-mode="light"]'],
          scheme: "light",
        },
        {
          mode: "dark",
          selectors: ["@media (prefers-color-scheme: dark)", '[data-mode="dark"]'],
          scheme: "dark",
        },
      ],
    });