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

figma2theme

v0.9.3

Published

This CLI is a Portable tool designed to allow us to extract design tokens (colour palettes, typography, spacing scales, etc.) from a UI Kit Figma file and then use them to generate a theme.

Downloads

112

Readme

figma2theme 🎨

This CLI is a Portable tool designed to allow us to extract design tokens (colour palettes, typography, spacing scales, etc.) from a UI Kit Figma file and then use them to generate a theme.

figma2theme supports theme exports for the following UI frameworks:

Resources

UI Kit Figma template:

https://www.figma.com/design/b6tcOWalyHLDfsD0IBSXyE/Portable-UI-Kit-v2

Example Storybook generated from the template above using figma2theme and Chakra UI:

https://figma2theme.netlify.app/

Usage

1. Add figma2theme to your project

yarn add --dev figma2theme

2. Set your environment variables

a. Create a .figma2themerc file in your project repo and add the URL of your project's UI Kit file. Here's an example with the UI Kit template file:

{
  "fileUrl": "https://www.figma.com/design/b6tcOWalyHLDfsD0IBSXyE/Portable-UI-Kit-v2"
}

b. Generate a Figma API key and add it to the .env file of your project. An API key can be generated under the 'Personal Access Tokens' section of the Figma settings.

FIGMA_API_KEY=

3. Generate your theme

Tailwind CSS

Run the following command to generate your Tailwind CSS theme:

yarn figma2theme generate-tailwind

By default the generated file will be saved as tailwind.figma2theme.js in the root of your project.

Chakra UI

Run the following command to generate your Chakra UI theme:

yarn figma2theme generate-chakra

By default the generated files will be saved to the ./theme directory.

4. Import the theme

Tailwind CSS

Open your tailwind.config.js file and add the generated theme to your presets array like so:

import figmaPreset from './tailwind.figma2theme.js';

/** @type {import('tailwindcss').Config} */
const config = {
	presets: [figmaPreset],

This setting will use the generated theme as the base for your Tailwind configuration, giving you access to all the tokens from the UI Kit while still allowing you to extend or override them in your tailwind.config.js file as needed.

For more information on this setting see the Tailwind docs: https://tailwindcss.com/docs/presets

Chakra UI

Change your imports from import { theme } from '@chakra-ui/react' to the generated theme location so that the generated theme is used instead of the default Chakra UI theme.

5. Import the stories (Optional)

figma2theme provides a variety of Storybook stories that allow you to view elements of your current Chakra UI theme, including foundational values (e.g. colour palettes, font sizes, etc.) and component styles (e.g. button variants, text styles, etc.) These stories are currently only available for Chakra UI.

To view these stories in the Storybook of your project, open .storybook/main.js and insert the following glob to the stories array:

../node_modules/@portablestudios/figma2theme/lib/**/*.stories.js

Development

Want to work on figma2theme? Here's how to get started.

First set up your environment variables by duplicating the template:

cp .env.dist .env

Then generate a Figma API key and use it for the FIGMA_API_KEY environment variable. A key can be generated under the 'Personal Access Tokens' section of the Figma settings.

Running the CLI

While developing the CLI you can use it by running:

yarn dev

This is equivalent to running figma2theme in a project.

For example, to generate a Chakra UI theme run the following:

yarn dev generate-chakra

If you want to test figma2theme globally run the following:

yarn global:install

This will build the CLI and use Yarn to install it globally, allowing you to run the CLI by typing figma2theme anywhere.

To remove the globally installed package run the following:

yarn global:remove

Storybook

The provided stories can be previewed by running:

yarn storybook

Ensure you have generated a theme beforehand using yarn dev generate-chakra.