npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

figma-tokens-to-tailwind-variables

v1.1.3

Published

Convert Figma Token JSON to useful TailwindCSS variables.

Downloads

91

Readme

Usage

Use this package to convert exported Figma tokens JSON into valuable TailwindCSS data.

Install

yarn add figma-tokens-to-tailwind-variables

or

npm install figma-tokens-to-tailwind-variables

Usage

In your tailwind.config.js file.

/*
 * Change "figma-tokens.json" to point to
 * the location of your exported tokens file.
 */
import tokens from "figma-tokens.json" assert { "type": "json" };
import FigmaTokensToTailwindVariables from "figma-tokens-to-tailwind-variables";

const {
  Colors,
  FontSizes,
  FontFamilies,
  FontWeights,
  LineHeights,
  BoxShadows,
} = FigmaTokensToTailwindVariables(tokens);

export default {
  // ... Your other TailwindCSS configuration
  theme: {
    /*
     * NOTE: You can use color or font-family
     * variables inside of extend, but
     * I prefer to have my colors only.
     */
    colors: {
      ...Colors,
    },
    fontFamily: {
      ...FontFamilies,
    },

    extend: {
      fontSize: {
        ...FontSizes,
      },
      fontWeight: {
        ...FontWeights,
      },
      lineHeight: {
        ...LineHeights,
      },
      boxShadow: {
        ...BoxShadows,
      }
    }
  }
};

Other helpful snippets

Color variables

export default = {
  // ... Your other TailwindCSS configuration
  theme: {
    /*
     * NOTE: I use this in tandem with
     * @mertasan/tailwindcss-variables
     * to export CSS variables.
     * Variables are exported as
     * --color-NAME-NUMBER into the CSS :root
     * (eg --color-green-100: #E5F2EB)
     */
    variables: {
      DEFAULT: {
        color: {
          ...Colors,
        },
      },
    },
  }
  plugins: [
    require("@mertasan/tailwindcss-variables"),
  ],
};

Require vs import.

This can alternately be called in via require.

const tokens = require("figma-tokens.json");
const { default: FigmaTokensToTailwindVariables } = require("figma-tokens-to-tailwind-variables");
const { Colors } = FigmaTokensToTailwindVariables(tokens);

Options

The function FigmaTokensToTailwindVariables allows a secondary parameter with options:

import tokens from "figma-tokens.json" assert { "type": "json" };
import FigmaTokensToTailwindVariables from "figma-tokens-to-tailwind-variables";

const {
  ...
} = FigmaTokensToTailwindVariables(tokens, {
  // Place your options here
});

| Option name | Default | Usage | Type | | :--- |---|---|---| | fontFamilyNamespace | typography/font-family | Defines the string-based search pattern that the processor searches for define font family names. Eg. a token with a variable name typography/font-family/base will return FontFamily { 'base': value } | String | | fontSizeNamespace | typography/size | Defines the string-based search pattern that the processor searches for define font sizes. Eg. a token with a variable name typography/size/h1-mobile will return FontSize { 'h1-mobile': VALUE } | String | | fontWeightNamespace | typography/weights | Defines the string-based search pattern that the processor searches for define font weights. Eg. a token with a variable name typography/weights/base/bold will return FontWeights { base: { bold: VALUE } } | String | | lineHeightNamespace | typography/line-height | Defines the string-based search pattern that the processor searches for define line-heights. Eg. a token with a variable name typography/line-height/heading will return LineHeights { heading: VALUE } | String |

Figma naming recommendations

  • Store groups of variables in collections and folders that can be easily found by their namespace (eg. all font size variables should fall under Typography/Font size/H1 or, better, typography/font-size/h1).
  • While the tokens processor sanitizes the value placed beyond the final slash (eg. tokens stored as Typography/Font Size/H1 Mobile will return as h1-mobile), we recommend adopting a lowercase formatting and using hyphens (-) instead of spaces.