1.4.3 • Published 5 months ago

@cobalt-ui/plugin-js v1.4.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@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

1.4.3

5 months ago

1.4.2

7 months ago

1.4.1

8 months ago

1.2.3

10 months ago

1.4.0

8 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.2

11 months ago

1.2.1

12 months ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago