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

react-design-tokens-table

v1.1.0

Published

Visualize design tokens. Dynamically insert beautiful tables of design tokens into your storybook.

Downloads

80

Readme

React Design Tokens Table

Visualize design tokens. Dynamically insert beautiful tables of design tokens into your storybook.

DEMO

| Color | Spacing | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | |

| Typography | Border | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | |

| Shadow | Opacity | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | |

🎨 Previewable Design Tokens

Design tokens can be visualized for the following properties. If you want to see all the examples, check out our Storybook DEMO.

  • Color
  • Opacity
  • Box Shadow
  • BorderWidth
  • Border Radius
  • Sizing / Spacing
  • Font
    • Family
    • Size
    • Weight
  • Letter Spacing
  • Line Height
  • Paragraph Spacing
  • Typograhy

🚧 Getting Started

1. Install

run: $ npm i react-design-tokens-table

2. Create design tokens JSON

ex.) design-token-transformer or Figma Tokens.

FigmaTokens is a useful tool to export json.

3. Convert JSON to JS

Generate js files with style-dictionary.

run: $ npm i -D style-dictionary

// ./style-dictionary/config.json
{
	"source": ["./.style_dictionary/tokens.json"],
	"platforms": {
		"js": {
			"transformGroup": "js",
			"buildPath": "./stories/tokens/",
			"files": [
				{
					"format": "javascript/module",
					"destination": "tokens.js"
				},
				{
					"format": "typescript/module-declarations",
					"destination": "tokens.d.ts"
				}
			]
		}
	}
}

run: $ npx style-dictionary build If style-dictionary conversion is successful, file like the following is generated.

module.exports = {
	color: {
		brand: {
			primary: {
				value: '#16d4c8',
				type: 'color',
				description: 'This is the main color.',
				filePath: './.style_dictionary/tokens.json',
				isSource: true,
				original: {
					value: '#16D4C8',
					type: 'color',
				},
				name: 'ColorBrandPrimary',
				attributes: {
					category: 'color',
					type: 'brand',
					item: 'primary',
				},
				path: ['color', 'brand', 'primary'],
			},
		},
	},
	/* Other Tokens*/
}

4. Import and use

import { DesignTokensTable } from 'react-design-tokens-table'
import tokens from './tokens'

const Page = () => {
	return {
		<>
			<h1>Colors</h1>
			<DesignTokensTable tokens={tokens.color} />

			<h1>Opacities</h1>
			<DesignTokensTable tokens={tokens.opacity} />
		</>
	}
}

Parse Method

The JSON object passed to the component will be parsed into a table as follows.

color: {
	brand: {
		primary: {
			value: '#16d4c8',
			type: 'color',
			description: 'This is the main color.',
			name: 'ColorBrandPrimary',
			path: ['color', 'brand', 'primary'],
		},
	},
}

| Propaty | | Table | Result | | ----------- | --- | --------------- | ------------------------------------------------------ | | name | => | Name | ColorBrandPrimary | | description | => | Description | This is the main color. | | path | => | Variable | color.brand.promary | | value | => | Value | #16d4c8 | | type | => | Preview | Show previews depending on the type of design token. |

Component Properties

React Design Tokens Table uses Stitches to assign a Storybook-like style. If you don't like this, you can override the style with css props. If noStyle is specified, you get a plain dom component.

| Propaty | Type | | | -------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | | tokens* | TokenType | Token object to be reflected in the table | | css | @stitches/react/CSS | To override the style. | | noStyle | boolean | If true, no style is applied. |


📖 Example in Storybook Docs Addon

It is useful to visualize design tokens in a storybook.

// *.stories.mdx

import { Meta, Unstyled } from '@storybook/addon-docs'
import { DesignTokensTable } from 'react-design-tokens-table' //👈
import tokens from './tokens' //👈


<Meta title='ReactDesignTokensTableExample' />

# React Design Tokens Table Example
<Unstyled> // If you want to resolve conflicts with storybook's default styling
	<DesignTokensTable tokens={tokens.color} /> //👈
</Unstyled>

🚀 Roadmap

Upcoming ideas:

  • Testing Framework
  • Input form of token's value
  • JSON support
  • Other design token properties

🐛 Feature request & bugs

Please create an issues in the repository.