Git Product home page Git Product logo

ux-and-i / storybook-design-token Goto Github PK

View Code? Open in Web Editor NEW
634.0 19.0 123.0 4.46 MB

Display design token documentation generated from your stylesheets and icon files. Preview design token changes in the browser. Add your design tokens to your Storybook Docs pages using the custom Doc Blocks.

Home Page: https://dev.to/psqrrl/managing-design-tokens-using-storybook-5975

License: MIT License

TypeScript 81.84% JavaScript 0.25% CSS 15.85% SCSS 0.53% MDX 0.94% HTML 0.06% Less 0.53%
storybook storybook-addon design-system design-pattern design-tokens react angular vue sass svg

storybook-design-token's Introduction

⚠️ This is the documentation for v3 which supports Storybook v7 and newer. Please check the v2 branch for the release supporting Storybook v6 and below. ⚠️

Storybook Design Token Addon

Netlify Status

Display design token documentation generated from your stylesheets and icon files. Preview design token changes in the browser. Add your design tokens to your Storybook Docs pages using the custom Doc Blocks.

Show me the demo

Teaser image

Contents:

Get started

First, install the addon.

$ yarn add --dev storybook-design-token
# or
$ npm add --save-dev storybook-design-token

Add the addon to your storybook addon list inside .storybook/main.js:

module.exports = {
  addons: ['storybook-design-token']
};

The last step is to annotate your design tokens with a category name and a presenter. You can do this by adding special comment blocks to your stylesheets. Below is an example of a css stylesheet defining three categories ("Animations", "Colors", "Others"). It works the same way for scss and less files.

:root {
  /**
  * @tokens Animations
  * @presenter Animation
  */

  --animation-rotate: rotate 1.2s infinite cubic-bezier(0.55, 0, 0.1, 1);

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

  --b100: hsl(240, 100%, 90%); /* Token Description Example  @presenter Color */
  --b200: hsl(240, 100%, 80%);
  --b300: hsl(240, 100%, 70%);

  /**
  * @tokens Others
  */
  --border-normal: 3px dashed red; /* Token Description Example @presenter BorderRadius */
}

The presenter controls how your token previews are rendered. See the next section for a complete list of available presenters. You can omit the presenter definition if you don't want to render a preview or no presenter works with your token.

By default, a token category ends with the comment block of the next category. If you want to end a category block before the next category comment, you can insert a special comment to end the block early:

/**
  * @tokens-end
  */

To list your svg icons, the addon parses your svg files searching for svg elements. Important: Only svg elements with an id or data-token-name attribute are added to the token list. You can provide descriptions and category names for your icons using the (optional) attributes data-token-description and data-token-category.

Available presenters

Please check the demo to see the presenters in action.

  • Animation
  • Border
  • BorderRadius
  • Color
  • Easing
  • FontFamily
  • FontSize
  • FontWeight
  • LetterSpacing
  • LineHeight
  • Opacity
  • Shadow
  • Spacing

Advanced configuration

Default tab

You can specify the default tab shown in the addon panel. Set it to the corresponding category name.

.storybook/preview.js

export default {
  parameters: {
    designToken: {
      defaultTab: 'Colors'
    }
  }
};

Visible tabs

If you don't want to show all available tabs, it is possible to specify which tabs should be shown in the addon panel via the tabs setting.

export default {
  parameters: {
    designToken: {
      tabs: ['Colors']
    }
  }
};

Style injection

To inject styles needed by your design token documentation, use the styleInjection parameter. A typical usecase are web fonts needed by your font family tokens. Please note that the styleInjection parameter only works with valid css.

.storybook/preview.js

export default {
  parameters: {
    designToken: {
      styleInjection:
        '@import url("https://fonts.googleapis.com/css2?family=Open+Sans&display=swap");'
    }
  }
};

Disable the addon panel

In some cases you might only want to use the Doc Blocks and hide the addon panel. You can do so by the setting the disable parameter:

export default {
  parameters: {
    designToken: {
      disable: true
    }
  }
};

Token search visibility

In some cases you might not need the search field to be visible. You can control its visibility by the setting the showSearch parameter:

export default {
  parameters: {
    designToken: {
      showSearch: false
    }
  }
};

Pagination

By default pageSize of the card view is 50 items. You can configure it by setting the pageSize parameter:

export default {
  parameters: {
    designToken: {
      pageSize: 10
    }
  }
};

You can disable pagination in the following way:

export default {
  parameters: {
    designToken: {
      // specify max value to disable pagination
      pageSize: Number.MAX_VALUE
    }
  }
};

Specify a custom glob for your token files

By default, the addon parses all .css, .scss, .less, .svg, .jpeg, .png and .gif files of your code base for annotated design tokens. If you only want to parse specific files, you can pass a glob via the DESIGN_TOKEN_GLOB environment variable or via an option in your main.js.

For example:

DESIGN_TOKEN_GLOB=**/*.tokens.{css,scss,less,svg}

Preserve CSS variables

By default, the addon extracts values of CSS variables at build time. As a result, presenters use fixed values at runtime. This behavior might impose limitations in some scenarios:

  • Stylesheet with CSS variables is loaded separately from tokens
  • Theme is replaced at runtime and new values of CSS variables are loaded

If you want to preserve CSS variables in the presenters, enable preserveCSSVars option in your main.js file:

module.exports = {
  stories: [
    // stories
  ],
  addons: [
    { name: 'storybook-design-token', options: { preserveCSSVars: true } }
  ]
  // other options
};

Design Token Doc Block

This addon comes with a custom Storybook Doc Block allowing you to display your design token documentation inside docs pages.

// colors.stories.mdx

import { DesignTokenDocBlock } from 'storybook-design-token';

<DesignTokenDocBlock categoryName="Colors" maxHeight={600} viewType="card" />;

The categoryName parameter references your token category name (the part after @tokens in your stylesheet annotations). The viewType parameter can be set to card or table to switch between both presentations. In some cases you might want to hide the token values. You can do that by passing showValueColumn={false}. Check the demo file for usage examples.

Custom Presenters

DesignTokenDocBlock component allows you to use custom presenters. You can either create a new presenter or override an existing one.

Example of overriding the existing Color presenter:

import React from 'react';

export function CircleColorPresenter({ token }) {
  return (
    <div
      style={{
        width: 30,
        height: 30,
        borderRadius: '50%',
        background: token.value
      }}
    ></div>
  );
}
import { DesignTokenDocBlock } from 'storybook-design-token';
import { CircleColorPresenter } from './CircleColorPresenter';

<DesignTokenDocBlock
  categoryName="Colors"
  viewType="card"
  presenters={{ Color: CircleColorPresenter }}
/>;

Check the demo file for usage examples.

Browser support

  • All modern browsers
  • Internet Explorer 11

storybook-design-token's People

Contributors

acherkashin avatar avremelm avatar bendobos avatar bileljegham avatar bmalinconico avatar comp615 avatar davembush avatar dependabot[bot] avatar dwightjack avatar edoardocavazza avatar lcoalves avatar mmmalik avatar nategreen avatar sod avatar sqrrl avatar squarefeet avatar tommykubity avatar yakky avatar zerotwofours avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storybook-design-token's Issues

Slow performance when using addon with 1000 style tokens

I have been using the storybook-design-token addon with file that includes roughly 1000 style tokens. I'm not seeing any build issues, but once storybook is booted up in the browser I'm seeing a lag of three to four seconds when I navigate between sections of SB.

Screen.Recording.2022-02-16.at.8.57.40.AM.mov

Is there a recommended capacity or limit to the number of style tokens that can be used with the addon?

Issues with Storybook v.6.4.0 beta?

Hello! I am trying to update my storybook to the v6.4.0 beta version, but it breaks when using

<DesignTokenDocBlock categoryName="Colors" viewType="card" />

at this lines:

var context = react_1.useContext(blocks_1.DocsContext);
var tabs = useTokenTabs_1.useTokenTabs(context.parameters.designToken).tabs;

because it seems that context.parameters is not defined anymore. It is a known bug? Is there any workaround?

Thanks!

Support for Storybook: OpenWC

Windows 10
Chrome 86
Storybook 5.3.10 : Framework Web Components
Build Framework via OpenWC

This add-on produced the following errors in browser:

Uncaught ReferenceError: exports is not defined at public_api.js:5
Uncaught ReferenceError: require is not defined at preview.js:3

The Font Weight presenter isn't being applied correctly

Hello,

First of all, thank you for this excellent project.

I'm having a problem using the Font Weight presenter. It doesn't seem to being applied correctly. See the code below:

/*
  * @tokens Font Weight
  * @presenter FontWeight
*/
$font-weight-bold: 700;
$font-weight-medium: 500;
$font-weight-regular: 400;
$font-weight-light: 300;

See the result:
Screenshot from 2021-10-04 10-21-45

Resolving NPM Vulnerabilities

Hello again! 👋 😁

I am currently working on an upgrade from Storybook v5.3 to the newest v6.1.x. It seems that the v5 packages incurred some vulnerabilities all at once and upgrading eliminated most of them. However, there are a couple remaining from your package, specifically.

I notice that you are referencing storybook v5 modules in your package.json. I don't see an upgrade tag or a "next" branch so I am going to assume nothing like that exists. Do you have plans to do some "spring cleaning" and get a branch up that's storybook v6-specific? I think it would help eliminate the remaining vulnerabilities for which NPM is blaming your library (at the very least, it should help future development go more smoothly). Maybe time for design-token v1? 😋

Here are the two vulnerabilities (which require manual review) after upgrading sb packages to v6.1.21 and design token to 0.8.1:
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.2.1 <1.0.0 || >=1.2.3                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ storybook-design-token [dev]                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ storybook-design-token > gonzales-pe > minimist              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1179                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ prismjs                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=1.23.0                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ storybook-design-token [dev]                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ storybook-design-token > @storybook/components >             │
│               │ react-syntax-highlighter > refractor > prismjs               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1638                            │
└───────────────┴──────────────────────────────────────────────────────────────┘

Incompatible with Webpack 5

When adding this addon to a storybook using webpack 5, the following error occurs:

ERROR in ./node_modules/storybook-design-token/node_modules/postcss/lib/previous-map.js 8:35-50
Module not found: Error: Can't resolve 'path' in '/node_modules/storybook-design-token/node_modules/postcss/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }
 @ ./node_modules/storybook-design-token/node_modules/postcss/lib/input.js 10:42-67
 @ ./node_modules/storybook-design-token/node_modules/postcss/lib/parse.js 8:36-54
 @ ./node_modules/storybook-design-token/node_modules/postcss/lib/postcss.js 18:36-54
 @ ./node_modules/storybook-design-token/dist/parsers/postcss.parser.js 54:32-50
 @ ./node_modules/storybook-design-token/dist/hooks/useTokenTabs.js 11:23-59
 @ ./node_modules/storybook-design-token/dist/components/Panel.js 27:21-53
 @ ./node_modules/storybook-design-token/dist/register.js 9:14-43

Adding resolve.fallback to the webpack configuration per the instructions does not seem to work for me.

DesignTokenDocBlock not working with npm

Hello all!

I'm having trouble us
ing DesignTokenDocBlock installing via npm. This error appears on the console:
Screenshot from 2021-10-07 17-30-44
Screenshot from 2021-10-07 17-31-36

The problem doesn't happen when I install via yarn, but I need it to work with npm..

Can someone help me, please?

Support for new Design Tokens format?

I ran across this addon looking for something to display our design tokens expressed according to the upcoming W3C Design Tokens schema, which is a JSON format. It’s still new and somewhat in flux, but I think the overall direction and basic boundaries have been solidified and from here it’s minor tweaks and tiny changes.

Currently the schema supports

  • color
  • dimension (e.g. 16px)
  • duration (e.g. 250ms)
  • font (name)
  • url (e.g. ./icon/alert.svg)
  • cubic-bezier
  • typography (multiple font styles)
  • gradient
  • shadow
  • transition

and a few other types are coming down the pipe soon (it’s moving pretty quickly)

I’ve been migrating our design tokens to use this new format, and I’ve also been building my own tooling and participating in the schema discussions as well.

So all that said, would supporting design tokens JSON be something you’d be interested in supporting? And would I be able to assist in that in some way?

Issue: Aliased/Inherited CSS Variables don't show up

When I do e.g.

--base-size: 16px;
--font-size-default: var(--base-size);

The latter don't show up in the tokens panel. However, it does show up if i do:

--font-size-default: calc(1 * var(--base-size));

Perhaps some issue with var(...) being the first part of the variable?

Storybook modules as peer dependencies?

Hello! Thank you for this addon, it is very very useful. I noticed that core Storybook modules like @storybook/addons, @storybook/components and @storybook/theming are treated as addon's dependencies. Shouldn't they be defined as peer dependencies instead? Any downside?

Feature Request: Setting Presenters per Property

It would be really cool if the presenter could be overridden per property:

/* vars.css */
/**
 * @tokens Borders
 */
:root {
  --border-radius: 3px; /** @presenter BorderRadius */
  --border-gray: 1px solid #DDDDDD; /** @presenter Border */
}

That way, developers could make "mixed blocks" of properties and would not be forced to structure their CSS in a certain way to make it work with this plugin. It would add quite a bit of flexibility, in my opinion.

Feature Request: Color Scheme support

I do have themes, that I want to swap in storybook and these themes do have different color schemes. Here is what I might look like:

:root {
	--background: gray;
}

@media (prefers-color-scheme: light) {
	:root {
		--background: white;
	}
}

@media (prefers-color-scheme: dark) {
	:root {
		--background: #333;
	}
}

.themeName-dark {
	--background: #333;
}

Color schemes can come in with media query support or custom classes.

Is there a way to make them been listed?

Bug: Encountered two children with the same key

This error occurs when using design tokens in an Angular project.

Screenshot 2021-08-18 at 12 10 14

This error occurs on a clean install of Storybook 6.3.7 and also 6.4-alpha.30 for Angular. The error appears for each CSS variable in the stylesheet.

To replicate:

  1. ng new testtoken
  2. You can choose CSS or SCSS when prompted. They both have the issue.
  3. cd testtoken
  4. npx sb init
  5. npm install storybook-design-token --save

Add the requited token configuration to main.js and preview,js,

Add token comments to styles.scss

:root {
 
  /**
  * @tokens Colors
  * @presenter Color
  */

  --b100: hsl(240, 100%, 90%); /* Token Description Example */
}

ng serve

Additional info:

ng version: 12.0.2 or 12.2.1 (issue occurs on both)

Feature Request: Ignore path for hard coded values and RGB support

Hello! First of all, this plugin is great. It was super easy to set up and has almost everything I need for my component library. Great work!

I am wondering if you could add a config option to disable or customize the hard coded values section. An option to disable this altogether would be fine to start, but it might be useful to include a path or two to ignore when compiling this list.

Finally, wondering if RGB support could be added? Is the plugin just reading hex values? Could it convert hex to rgb?

Thank you!

Justin

Hide value with SvgToken presenter

svg object value is of very little use in this context and it makes usage much more cumbersome and less clear

Maybe it would be possible to add a hideValue attribute to the Token object and render the value attribute based on that?

By setting it when parsing svg object would make it transparent and will not affect other token types

Feature request: Show examples for advanced sass colors and gradients

Thank you for the addon! Seems like it can be a life-saver for future projects. 🔥

I've noticed few issues with showing the examples of color tokens when:

  1. A color is defined with sass color functions:
$bg-grad-start: lighten(saturate(adjust-hue($c-grad-base, -5), 12.17), 4.12);
  1. A gradient is defined with color variables:
$bg-gradient: linear-gradient(180deg, $bg-grad-start 9.85%, $bg-grad-mid 53.92%, $bg-grad-end 100%);

Screenshot

As shown on screenshot, the value is not calculated and the example box doesn't have a background. Having sass code instead of calculated value seems fine, but it would be also great to see an example.

Full code sample:

/**
 * @tokens Colors
 * @presenter Color
 */
$red: red;
$c-light-blue: #DDE7F3;
$c-grad-base: $c-light-blue;
$bg-grad-start: lighten(saturate(adjust-hue($c-grad-base, -5), 12.17), 4.12);
$bg-grad-mid: $c-grad-base;
$bg-grad-end: lighten(saturate(adjust-hue($c-grad-base, -4), 13.46), 2.94);

/**
 * @tokens Gradients
 * @presenter Gradient
 */
$bg-gradient: linear-gradient(180deg, $bg-grad-start 9.85%, $bg-grad-mid 53.92%, $bg-grad-end 100%);
$bg-test: linear-gradient(180deg, $c-light-blue 9.85%, $c-light-blue 53.92%, $c-light-blue 100%);

I'm using Storybook 6.0.13 and Storybook-design-token 0.7.8

Disable the add-on tab

Is it possible to disable the "Design Tokens" Addon tab and still use Design Token Doc Blocks?

For example Essential's addons use the following disabling option syntax.

I've seen the active, but don't know how to officially use it.

I've tried to pass the tabs as an empty array. But it did not worked out. If any of these options are allowed having them documented would be helpful.

SCSS parser problem

Hi!

I am trying to use this cool addon, and I'm following the setup exactly as described for v1.0.0. I've checked the example 100 times.

The build goes without problems, but I get a problem in the browser:

Uncaught (in promise) CssSyntaxError: /scss/filename.scss:1:1: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser

I'm on storybook 6.1.21, and setup is totally basic. I use @storybook/preset-scss addon for scss, but I don't think that is anything but normal. The webpackFinal setup in main.js looks like this:

  webpackFinal: async (config, { configType }) => {
    config.module.rules.push({
      test: /\.scss$/,
      loaders: ["style-loader", "css-loader", "sass-loader"],
    });
    return config;
  },

I then load the scss file like this in preview.js: import "!style-loader!css-loader!sass-loader!../src/assets/scss/filename.scss";

Is this a bug, or is it me doing something wrong?

storybook fails with addon

I'm running storybook 6.2.17 with a view project.
Just adding this as an add-on in main.js, i get the following error on starting storybook.
ERR! TypeError: Cannot read property 'options' of undefined

Unused token section appearing as tab and out-of-place token annotations

Hello again! 😁

So I finally got around to doing some storybook upgrades and am currently pointing at the most recent version (6.3.2) so it seemed logical to upgrade your addon as well, since I was previously on 0.x.x. Nice to see the new layouts and features! I have two issues though, and I'm happy to open a second issue if needed, but the most pressing issue is this empty tab:

Screen Shot 2021-07-01 at 7 19 57 PM

I never once reference an svg presenter in my comment annotations, nor are there any sass variables (tokens) which represent svgs. I do have some svg's in the app, but we use FontAwesome packages for their display, so we have no need to list them as tokens. I'm not sure why this tab is appearing.

The second issue is that individual token annotations (line-level comments) seem to be getting mixed up and/or pulled randomly, while others display just fine (btw, the tooltip-style of delivery is convenient!). Here is an example from my _colors.scss file:

/**
 * @tokens Colors
 * @presenter Color
 *
 * NOTE: legacy color files are in styles/components/Color. when there
 *       are multiple colors listed, they are located in multiple files.
 *       commented colors are generally included when names drastically
 *       differ, but some are listed for convenience as well. may be
 *       helpful to simply list _all_ defined stylus vars to use as a
 *       complete reference.
 */

// primary palette
$purple: #723080; // formerly purple
$purple-tint-1: #f1e9ef;
$purple-tint-2: #d4c0d7;
$purple-tint-3: #b897bf; // formerly color-p-tint-1 (colors.js)
$purple-tint-4: #8e5999; // formerly color-p-tint-2 (colors.js)
$purple-shade-1: #5b2666;
$purple-shade-2: #441c4c;
$purple-shade-3: #2d1631;

Observe the tooltips:
storybook-design-token_annotations

Only one of the tooltips was correct, and the others seem to be coming from other files. I suspect it's a small react snafu, but a snafu nonetheless. Again, let me know if you'd prefer this to be in a separate issue. 😅

Feature Request: Theme support

I'm having multiple themes (with multiple color schemes - see #14) and my natural place to switch them would be the toolbar addon coming in v6.

Is there a way to provide a bridge to the toolbar addon and connect the switch here?

(Ideally tokens should stay the same, only the value changes)

Any way to compile sass?

Hello,
I would love to use this addon, but all mu colors are generated.
Is any way to compile the sass files before extracting the values?
Thanks in advance.

Module not found error after install

After getting storybook running locally, I install the addon and get this error

Error

Screenshot 2019-10-07 22 36 10

Storybook config

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


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


addParameters({
 designToken: {
   files: {
     css: cssTokenFiles,
     scss: scssTokenFiles,
     //svgIcons: svgIconTokenFiles
   }
 }
});

// automatically import all files ending in *.stories.js
configure(require.context('../src/stories', true, /\.stories\.js$/), module);

Not IE11 compatible

Can this be made IE11 compatible?

E.g. can packages like @illinois/react-use-local-storage be replaced with an alternative as it uses arrow functions?

Upgraded to 0.7.1 and it broke

ERROR in /xxx/node_modules/storybook-design-token/dist/components/TokenOverview.js
Module not found: Error: [CaseSensitivePathsPlugin] /xxx/node_modules/storybook-design-token/dist/components/presenter/TokenPresenter.js does not match the corresponding path on disk Presenter.
@ /xxx/node_modules/storybook-design-token/dist/components/TokenOverview.js 15:23-60

And a few other similar errors. I'm going to downgrade back to 0.5.1 now.

Feature Request: Tokens as Story/Canvas

Thanks for putting this addon together.

For now the tokens show up in the addons sidebar, which is a thing I'm wondering about. For me they are informative instead of letting you customize the story at hand.

I would like to put them into the navigation of the sidebar and let them show up in the main/story area.

JSON and XML file support

HI, thanks for great plugin.

Is there any support to load JSON or XML files?
In demo files the is a theo.token.json file, but it looks that its values are not imported.

Feature request: Component-level token view + Extract hard coded token values

Hey there! I love what you are doing with this addon. I think it will be very useful for a lot of teams, especially those that use design systems. I have a couple of ideas that I wanted to throw out there for future additions:

  • Have an all tokens view and a component level usage view (potentially 2 tabs) - maintain a list of all tokens and display only the tokens that each component uses
  • Add a check against the css/scss/less/etc. to see if there are any font sizes, colors, etc. that are hardcoded and could instead use the tokens. These could then be called out in the addon.

Again, Great work! Let me know what you think. We can chat here or on twitter @CodeByAlex

Allow to define custom categories on SVG icons

Currently there is no way to define categories for SVG icons, like it's available for the other tokens

In case a design system contains lots of icons the resulting page is confusing and not friendly.

By using data attribute on each SVG we can provide a category name, group icons according to this category and use the category name in DesignTokenDocBlock to display the corresponding tokens.

SCSS Custom variable name compilation

SCSS Example:

$someVar: 'myprefix';

/**

* @tokens Colors

* @presenter Color

*/

--#{$somevar}-color: var(--#{$someVar}-my-col);

Currently complex names are not compiled properly

Alias from two different files is not displayed

Hi there! I noticed the following behavior:

Have two different css files, for example:

/* file1.css */

/**
 * @tokens Colors 1
 * @presenter Color
 */
 --gray-300: #DDDDDD;
 --gray-400: #AAAAAA;
 --gray-500: #777777;
/**
 * @tokens Colors 2
 * @presenter Color
 */

/* file2.css */
--gray-default: var(--gray-300);

--another-var: #BADA55;

In Storybook, --gray-default is not shown at all, while --another-var is shown. --gray-default is also not displayed as an alias.
When I move everything in one file, the aliases are detected as expected.
Having the same value for @tokens in both files shows the same behavior.

Webpack 5: raw-loader deprecated, require.context approach no longer working

After the upgrade to builder-webpack5 and 6.3.12 on storybook, I noticed that the approach suggested in the readme is no longer working. Attempting to load all scss files in a folder no longer provides the sourcecode:

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

...

> svgIconTokenFiles
[... { filename: './add.svg', content: undefined }, { filename: './delete.svg', content: undefined } ...]

It looks like the raw-loader approach is no longer going to be supported moving forward (see: https://webpack.js.org/guides/asset-modules/#replacing-inline-loader-syntax), and using the new method isn't going to allow inlining without modifications to the existing rules: (see: webpack/webpack#12900). The only files that weren't dropped from importing were ones that were marked as entrypoints.

Feature Request: Custom Presenters

First off, THANK YOU! I have been dreading setting up a custom story that manually displays brand colors via variables, so this add-on really hit home for me. 👏

Now for the feature request, custom presenters. The default presenter for colors is pretty good, but it isn't responsive so I basically need my browser at full width on a 15" screen to see all the info. This could be solved by a custom color presenter (I'd prefer to avoid storybook ui style overrides).

Additionally, some of my components have their own variables that are made available to other components which makes it easier for the latter to compose the former. It would be great to have a "General" or custom presenter to display the variables, descriptions, and values at a component level.

Don't get me wrong; you have a pretty solid set of default presenters already, but having the option of using a custom presenter greatly increases the flexibility of this addon. 😋

DesignTokenDocBlock Tab per Context

Joining #14 and #15, it would be awesome to support multiple contexts (more generic than "themes") and organize tokens per context in tabs.

Like this example:

<DesignTokenDocTabs>
  <DesignTokenDocBlock categoryName="Color Base Dark" tabName="Dark" />
  <DesignTokenDocBlock categoryName="Color Base Light" tabName="Light" />
</DesignTokenDocTabs>

// or 

<DesignTokenDocTabs categoryNames="Color Base *" />

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.