Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 1.81 KB

README.MD

File metadata and controls

63 lines (45 loc) · 1.81 KB

tokens-to-styles

Maintainability Test Coverage npm version npm downloads

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.