tokens-to-styles
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

tokens-to-styles

Maintainability Test Coverage

A simple JavaScript library for converting design tokens into CSS variables exported through the :root pseudo-class.

Installation

You can install tokens-to-styles using npm install command:

npm install tokens-to-styles

Usage

const { TokensConverter } = require('tokens-to-styles');

const tokens = {
  colors: {
    primary: '#000',
    secondary: '#fff',
  },
  fontSizes: {
    small: '12px',
    medium: '16px',
    large: '20px',
  },
};

const tokensConverter = new TokensConverter();
const css = tokensConverter.toCssVariables(tokens);
console.log(css);

This will output the following CSS:

:root {
  /* colors */
  --colors-primary: #000;
  --colors-secondary: #fff;

  /* ------------------------- */

  /* fontSizes */
  --fontSizes-small: 12px;
  --fontSizes-medium: 16px;
  --fontSizes-large: 20px;
}

How it works

The tokens-to-styles library takes a JavaScript object representing design tokens and converts it into a CSS module with variables exported through the :root pseudo-class. This allows for easy integration of design tokens into your stylesheets.

API

You can check our API documentation here.

Readme

Keywords

none

Package Sidebar

Install

npm i tokens-to-styles

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

23.9 kB

Total Files

24

Last publish

Collaborators

  • thiagog3