Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@cobalt-ui/plugin-js

drwpow5.1kMIT1.4.4TypeScript support: included

Generate JS, TS, and JSON from your design tokens schema (requires @cobalt-ui/cli)

cobalt, design tokens, design tokens community group, design tokens format module, design system, dtcg, w3c design tokens

readme

@cobalt-ui/plugin-js

Generate JSON and JS (with TypeScript types) from your design tokens using Cobalt.

Features

  • ✅ Universal JSON format makes it easy to consume tokens in any platform (including native/compiled code)
  • ✅ Access all your design tokens safely and programatically in any frontend or backend setup
  • ✅ Full support for token modes (e.g. light/dark mode)
  • ✅ Automatic TypeScript types for strong typechecking (never have a broken style)

Setup

Install the plugin from npm:

npm i -D @cobalt-ui/plugin-js

Then add to your tokens.config.mjs file:

// tokens.config.mjs
import pluginJS from "@cobalt-ui/plugin-js";

/** @type {import("@cobalt-ui/core").Config} */
export default {
  tokens: "./tokens.json",
  outDir: "./tokens/",
  plugins: [
    pluginJS({
      /** output JS (with TS types)? boolean or filename (default: true) */
      js: true,
      /** output JSON? boolean or filename (default: false) */
      json: false,
    }),
  ],
};

The default plugin exports a plain .js with invisible .d.ts TypeScript declarations alongside it, which means you don’t have to configure anything whether using TypeScript or not.

And run:

npx co build

You’ll then get generated JS with a token() function you can use to grab token values:

import { token } from "./tokens/index.js";

// get default token
const red = token("color.red.10");

// get token for mode: dark
const redDark = token("color.red.10", "dark");

// cubicBezier + bezier-easing library
import BezierEasing from "bezier-easing";
const easing = BezierEasing(...token("ease.cubic-in-out"));

Docs

View the full documentation

changelog

@cobalt-ui/plugin-js

1.4.4

Patch Changes

1.4.3

Patch Changes

1.4.2

Patch Changes

1.4.1

Patch Changes

1.4.0

Minor Changes

1.3.1

Patch Changes

1.3.0

Minor Changes

Patch Changes

1.2.3

Patch Changes

1.2.2

Patch Changes

1.2.1

Patch Changes

1.2.0

Minor Changes

  • 51fd059: Allow meta fields to not be generated for javascript builds

1.1.0

Minor Changes

  • 526777f: Add fontFamily, fontWeight, fontName, and number types, remove font type

Patch Changes

1.0.7

Patch Changes

1.0.6

Patch Changes

  • 28baebe: Fix TypeScript types for token fn
  • Updated dependencies [42401cd]

1.0.5

Patch Changes

  • faa7340: Fix TS function overload

1.0.4

Patch Changes

  • 91b1eed: Fix $value resolution on tokens.meta

1.0.3

Patch Changes

  • 2da8f16: Fix missing _group and _original data

1.0.2

Patch Changes

  • 9edc9d9: Fix token._original.$extensions.modes shallow clone bug
  • Updated dependencies [9edc9d9]

1.0.1

Patch Changes

  • 51647a3: Add missing $type from meta info

1.0.0

Minor Changes

  • e50c864: Add strokeStyle and border support in plugins, improve validation in core

Patch Changes

0.0.3

Patch Changes

0.0.2

Patch Changes

  • 0d993c8: Fix main entry

0.0.1

Minor Changes

  • 8c92d45: Initial release: JS codegen with all the features of @cobalt-ui/plugin-ts and @cobalt-ui/plugin-json

Patch Changes