<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Philipp Siekmann</title>
    <description>The latest articles on Forem by Philipp Siekmann (@psqrrl).</description>
    <link>https://forem.com/psqrrl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F103208%2F2adeca0a-bf42-4c0d-81b2-74ebd87c5382.JPG</url>
      <title>Forem: Philipp Siekmann</title>
      <link>https://forem.com/psqrrl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/psqrrl"/>
    <language>en</language>
    <item>
      <title>Managing Design Tokens Using Storybook</title>
      <dc:creator>Philipp Siekmann</dc:creator>
      <pubDate>Fri, 02 Aug 2019 14:06:35 +0000</pubDate>
      <link>https://forem.com/psqrrl/managing-design-tokens-using-storybook-5975</link>
      <guid>https://forem.com/psqrrl/managing-design-tokens-using-storybook-5975</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; I built a &lt;a href="https://github.com/UX-and-I/storybook-design-token" rel="noopener noreferrer"&gt;storybook addon generating design token documentation&lt;/a&gt; from your stylesheets and asset files. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out the demo here:&lt;/strong&gt; &lt;a href="https://storybook-design-token.netlify.com/" rel="noopener noreferrer"&gt;https://storybook-design-token.netlify.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a frontend developer I've built a number of ui component libraries enabling product teams to build software according to the underlying design systems. In doing so, one of my major issues has always been keeping design and development in sync. Translating the design language, in my case most likely delivered in form of various Sketch files, into code is an ongoing process with design changes throughout the entire lifecycle of the design system.&lt;/p&gt;

&lt;p&gt;To narrow the gap between design and development, I like to evaluate ways to move as much of the design system documentation into the browser and create a single point of truth for crucial parts of the design system. That means going beyond ui components and looking into the underlying design language. While tools like Sketch and Figma are great for drafting, prototyping and conveying the look-and-feel of your software, they scatter the design system's knowledge, making it harder to find and access these information. Putting them closer to the actual products (i.e. the code) helps to maintain a living documentation that has fewer risks of getting outdated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design Tokens
&lt;/h2&gt;

&lt;p&gt;While components provide the building blocks of our products, design tokens define a set of properties we can use to shape our components appearance. Typically they define things like typography, colors, spacings or the iconography of a design system. Have a look at &lt;a href="https://www.lightningdesignsystem.com/design-tokens/" rel="noopener noreferrer"&gt;Salesforce's collection of design tokens&lt;/a&gt; to get some nice examples. Brad Frost recently put &lt;a href="http://bradfrost.com/blog/post/extending-atomic-design/" rel="noopener noreferrer"&gt;design tokens in context of his atomic design principles&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The neat thing about design tokens from a developer's perspective? In most cases, they can be described as variables (e.g. css custom properties or sass variables) and assets like icon files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing Design Tokens with Storybook
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://storybook.js.org/" rel="noopener noreferrer"&gt;Storybook&lt;/a&gt; is a great tool for developing reusable component libraries in an isolated environment, while also creating neat visual and technical documentation for the product teams using your library. I highly recommend you give it a try if you need to build a reusable component library. It works great with all major JavaScript frameworks or just plain HTML and CSS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design Tokens as Stories
&lt;/h3&gt;

&lt;p&gt;Storybook uses stories to describe components and their different states. These stories are written by the developer in form of small templates showing example usages of the components. &lt;a href="http://react.carbondesignsystem.com/" rel="noopener noreferrer"&gt;IBM's storybook&lt;/a&gt; provides a nice example with a variety of components.&lt;/p&gt;

&lt;p&gt;My first attempt getting design tokens into Storybook was by manually writing stories listing our tokens in form of some simple html tables. That got messy very quickly. Instead of syncing the tokens between my component styles and Sketch files, I now had to sync between component styles, Sketch files and my stories. Furthermore, I found myself constantly jumping between the design token stories and my component stories to find the correct tokens I wanted to use in my components. (Storybook only shows you one story at a time.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Introducing the &lt;a href="https://github.com/UX-and-I/storybook-design-token" rel="noopener noreferrer"&gt;Storybook Design Token Addon&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Luckily, Storybook provides a great API for addon development that you can use to augment your stories. There are some great addons that automatically generate component documentation, provide a11y testing, display source code, and &lt;a href="https://storybook.js.org/addons/" rel="noopener noreferrer"&gt;much more&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Struggling with my manually maintained design token stories, I decided to write an addon that would display all our design tokens alongside the component stories while also eliminating the need to manually maintain the design token lists. It does that by parsing css or sass stylesheets and asset files (only SVG files at the moment) to generate design token documentation, complete with rendered examples. Further it allows you to organize the design tokens in groups, using annotations in your stylesheets. This way you can also define how token examples should be rendered (e.g. as a color, border radius, box shadow, …). Below is a small example of annotated tokens in a css stylesheet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/**
 * @tokens Colors
 * @presenter Color
 */&lt;/span&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--n0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Optional token description */&lt;/span&gt;
  &lt;span class="py"&gt;--n100&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fbfbfb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--n200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#edeeef&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--n300&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e4e5e7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--n300&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c"&gt;/* --primary will be listed as an alias of --n300 */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/**
 * @tokens Border Radius
 * @presenter BorderRadius
 */&lt;/span&gt;

&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--border-radius-m&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--border-radius-l&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Have a look at &lt;a href="https://storybook-design-token.netlify.com/" rel="noopener noreferrer"&gt;the demo&lt;/a&gt; to see what it does, or check out &lt;a href="https://github.com/UX-and-I/storybook-design-token" rel="noopener noreferrer"&gt;the repo&lt;/a&gt; for a more complete feature list and usage guide.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fs64bw0bi0u2c54z27zhx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fs64bw0bi0u2c54z27zhx.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would really love to hear your feedback.&lt;/strong&gt; Could you make good use of the addon? How do you handle design tokens in your design systems? With its &lt;a href="https://github.com/storybookjs/storybook/issues/7430" rel="noopener noreferrer"&gt;latest beta release&lt;/a&gt;, Storybook is introducing more tools to document your design system in the browser. Do you see design deliverables moving away from static design tools and towards the browser?&lt;/p&gt;

</description>
      <category>storybook</category>
      <category>javascript</category>
      <category>designsystem</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
