All Projects → UX-and-I → Storybook Design Token

UX-and-I / Storybook Design Token

Licence: mit
The Storybook Design Token Addon allows you to generate design token documentation from your stylesheets.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Storybook Design Token

orfium-ictinus
This repo will include the building blocks to create the Orfium Parthenons to come ...
Stars: ✭ 20 (-92.06%)
Mutual labels:  storybook, design-system
mod-uk-design-system
Build web applications that meet the Defence Digital service standards
Stars: ✭ 78 (-69.05%)
Mutual labels:  storybook, design-system
cuida
A design system built by Sysvale, using storybook and Vue components
Stars: ✭ 16 (-93.65%)
Mutual labels:  storybook, design-system
ripple
Ripple is the frontend framework for Single Digital Presence, delivered using Nuxt and Vue.js
Stars: ✭ 36 (-85.71%)
Mutual labels:  storybook, design-system
sodium-ui
Sodium is a simple, modular and customizable web component library to build elegant and accessible UI pieces for your React Application.
Stars: ✭ 23 (-90.87%)
Mutual labels:  storybook, design-system
react-uswds
USWDS 3.0 components built in React
Stars: ✭ 108 (-57.14%)
Mutual labels:  storybook, design-system
react-ecommerce
E-commerce monorepo application using NextJs, React, React-native, Design-System and Graphql with Typescript
Stars: ✭ 136 (-46.03%)
Mutual labels:  storybook, design-system
Componentdriven.org
Static site and content for Component Driven
Stars: ✭ 237 (-5.95%)
Mutual labels:  design-system, storybook
smores-react
🍭 Marshmallow React components
Stars: ✭ 34 (-86.51%)
Mutual labels:  storybook, design-system
pebble
Pebble Design System
Stars: ✭ 14 (-94.44%)
Mutual labels:  storybook, design-system
shared-react-components-example
An example of a mono-repository of shared React components libraries!
Stars: ✭ 85 (-66.27%)
Mutual labels:  storybook, design-system
vuetify-component-lib-template
Template for creating a component library/design system using Vue.js and Vuetify.js.
Stars: ✭ 35 (-86.11%)
Mutual labels:  storybook, design-system
Daisyui
⭐️ ⭐️ ⭐️ ⭐️ ⭐️  Tailwind Components
Stars: ✭ 382 (+51.59%)
Mutual labels:  design-pattern, design-system
ui-kit
D2iQ UI Kit
Stars: ✭ 29 (-88.49%)
Mutual labels:  storybook, design-system
Learnstorybook Code
Code for Learn Storybook
Stars: ✭ 249 (-1.19%)
Mutual labels:  design-system, storybook
Stardust
🎨Tiller Design System
Stars: ✭ 19 (-92.46%)
Mutual labels:  storybook, design-system
Learnstorybook.com
Static site and content for Storybook tutorials
Stars: ✭ 2,291 (+809.13%)
Mutual labels:  design-system, storybook
Awesome Design Systems
A curated list of bookmarks, resources and articles about design systems focused on developers.
Stars: ✭ 222 (-11.9%)
Mutual labels:  design-system, storybook
oskrhq-design-system
A mostly reasonable although opinionated approach to building responsive Digital Interfaces sharing the same anatomy.
Stars: ✭ 60 (-76.19%)
Mutual labels:  design-pattern, design-system
react-toolkit
Flexible components html + css + react using BEM convention. Maybe, you can call it "Design System" !
Stars: ✭ 89 (-64.68%)
Mutual labels:  storybook, design-system

Storybook Design Token Addon

Netlify Status

The Storybook Design Token Addon allows you to generate design token documentation from your stylesheets. Read more about the motivation for this addon here: https://dev.to/psqrrl/managing-design-tokens-using-storybook-5975

DEMO

Contents:

Some Features

  • Automatically generates design token descriptions from your annotated stylesheets and icon files
  • Parses CSS, SCSS/SASS, Less and SVG files
  • Provides various presenters to render examples of your design tokens
  • Automatically detects aliases of your css, sass or less variables
  • Preview changes to tokens directly in your browser (only for CSS variables)
  • Displays property values that match token values, so you can easily recognize hard coded values in your stylesheets

Installation

First, install the package using your package manager of choice.

npm install --save-dev storybook-design-token

or

yarn add --dev storybook-design-token

Configure for Storybook 5.3 and later

Skip to the next section if you are using Storybook 5.2 or older. For Storybook 5.2 and older add the addon to your main.js config file in the .storybook directory:

// main.js
module.exports = {
  stories: ['../**/*.stories.js'],
  addons: ['storybook-design-token']
};

Then add neccessary parameters to your preview.js in your .storybook directory:

import { addParameters } from '@storybook/react';

const cssReq = require.context('!!raw-loader!../src', true, /.\.css$/);
const cssTokenFiles = cssReq
  .keys()
  .map((filename) => ({ filename, content: cssReq(filename).default }));

const scssReq = require.context('!!raw-loader!../src', true, /.\.scss$/);
const scssTokenFiles = scssReq
  .keys()
  .map((filename) => ({ filename, content: scssReq(filename).default }));

const lessReq = require.context('!!raw-loader!../src', true, /.\.less$/);
const lessTokenFiles = lessReq
  .keys()
  .map((filename) => ({ filename, content: lessReq(filename).default }));

const svgIconsReq = require.context('!!raw-loader!../src', true, /.\.svg$/);
const svgIconTokenFiles = svgIconsReq
  .keys()
  .map((filename) => ({ filename, content: svgIconsReq(filename).default }));

addParameters({
  designToken: {
    files: {
      css: cssTokenFiles,
      scss: scssTokenFiles,
      less: lessTokenFiles,
      svgIcons: svgIconTokenFiles
    },
    options: {
      hideMatchingHardCodedValues: false
    }
  }
});

Configure for Storybook prior to version 5.3

Create a file called addons.js in your .storybook directory and import the plugin:

// addon.js
import 'storybook-design-token/register';

In your config.js in your .storybook directory: tell the plugin what files to parse. Important: Call addParameters before making the configure call.

// config.js
import { configure, addParameters } from '@storybook/react';

// [...]

const cssReq = require.context('!!raw-loader!../src', true, /.\.css$/);
const cssTokenFiles = cssReq
  .keys()
  .map((filename) => ({ filename, content: cssReq(filename).default }));

const scssReq = require.context('!!raw-loader!../src', true, /.\.scss$/);
const scssTokenFiles = scssReq
  .keys()
  .map((filename) => ({ filename, content: scssReq(filename).default }));

const lessReq = require.context('!!raw-loader!../src', true, /.\.less$/);
const lessTokenFiles = lessReq
  .keys()
  .map((filename) => ({ filename, content: lessReq(filename).default }));

const svgIconsReq = require.context('!!raw-loader!../src', true, /.\.svg$/);
const svgIconTokenFiles = svgIconsReq
  .keys()
  .map((filename) => ({ filename, content: svgIconsReq(filename).default }));

addParameters({
  designToken: {
    files: {
      css: cssTokenFiles,
      scss: scssTokenFiles,
      less: lessTokenFiles,
      svgIcons: svgIconTokenFiles
    },
    options: {
      hideMatchingHardCodedValues: false
    }
  }
});

// [...]

configure(loadStories, module);

Make sure to specify the right path after !!raw-loader!. The path has to be relative to your config file location.

Usage

The plugin tries to organize your tokens into token groups. You can annotate token groups by adding specific comment blocks to your stylesheets. Only annotated tokens will be listed by the plugin. The specified presenter is used to render examples of your tokens. See Presenters for further information.

CSS example:

/**
 * @tokens Colors
 * @presenter Color
 */

:root {
  --n0: #fff; /* Token Description */
  --n100: #fbfbfb;
  --n200: #edeeef;
  --n300: #e4e5e7;
  --primary: var(--n300);
}

/**
 * @tokens Border Radius
 * @presenter BorderRadius
 */

:root {
  --border-radius-m: 4px;
  --border-radius-l: 8px;
}

SCSS example:

/**
 * @tokens Colors
 * @presenter Color
 */

$n0: #fff; /* Token Description */
$n100: #fbfbfb;
$n200: #edeeef;
$n300: #e4e5e7;
$primary: $n300;

/**
 * @tokens Border Radius
 * @presenter BorderRadius
 */

$border-radius-m: 4px;
$border-radius-l: 8px;

SVG example:

<?xml version="1.0" encoding="UTF-8"?>
<svg
  data-token-name="check"
  width="24px"
  height="24px"
  viewBox="0 0 24 24"
  version="1.1"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
>
  <path
    d="M9.35221912,16.3536125 L19.5004166,5.34255149 C19.9029667,4.90884428 20.5808871,4.88358644 21.0145944,5.28613652 C21.4483016,5.6886866 21.4735594,6.36660707 21.0710093,6.80031428 L10.1375155,18.6574532 C9.71359736,19.1141823 8.99084087,19.1141823 8.56692275,18.6574532 L3.28613652,12.890538 C2.88358644,12.4568308 2.90884428,11.7789103 3.34255149,11.3763602 C3.77625869,10.9738101 4.45417917,10.999068 4.85672925,11.4327752 L9.35221912,16.3536125 Z"
    fill="currentColor"
  ></path>
</svg>

Make sure to specify the data-token-name attribute.

Presenters

Presenters are used to render examples for your design tokens. The following presenters are available:

  • Animation
  • BorderRadius
  • Border
  • Color
  • Easing
  • FontFamily
  • FontSize
  • FontWeight
  • Gradient
  • LineHeight
  • Opacity
  • Shadow
  • Spacing
  • Svg
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].