<?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>DEV Community: ɥɔɐ⅂ ɐɥɔsɐS</title>
    <description>The latest articles on DEV Community by ɥɔɐ⅂ ɐɥɔsɐS (@voodoocode).</description>
    <link>https://dev.to/voodoocode</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%2F7068%2F3186201.png</url>
      <title>DEV Community: ɥɔɐ⅂ ɐɥɔsɐS</title>
      <link>https://dev.to/voodoocode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/voodoocode"/>
    <language>en</language>
    <item>
      <title>TIL: Using decorators in Storybook to document invalid inputs</title>
      <dc:creator>ɥɔɐ⅂ ɐɥɔsɐS</dc:creator>
      <pubDate>Mon, 10 May 2021 08:35:09 +0000</pubDate>
      <link>https://dev.to/voodoocode/til-using-decorators-in-storybook-to-document-invalid-inputs-45j3</link>
      <guid>https://dev.to/voodoocode/til-using-decorators-in-storybook-to-document-invalid-inputs-45j3</guid>
      <description>&lt;p&gt;Today I learned about &lt;a href="https://storybook.js.org/docs/vue/writing-stories/decorators"&gt;Storybooks decorators&lt;/a&gt; and used them for documenting validation errors on inputs.&lt;/p&gt;

&lt;p&gt;Decorators are Storybooks way to wrap a story into some extra HTML.&lt;br&gt;
 By that, a basic component can for example be documented in a better visual way, as suggested by Storybooks, by adding some space around a story.&lt;/p&gt;
&lt;h2&gt;
  
  
  Writing an input component
&lt;/h2&gt;

&lt;p&gt;Now to my use-case: I was developing input components with Vue, while writing the related stories.&lt;br&gt;
Besides showing the default state of an input, I alse wanted to show the invalid state.&lt;/p&gt;

&lt;p&gt;As an example I'd have a component called InputText.vue in which I would simply pass down all the props and attrs to the input field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"label"&lt;/span&gt; &lt;span class="na"&gt;:for=&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{...$props, ...$attrs}" /&amp;gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

...

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:invalid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With an InputText.stories.js as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Forms/Inputs/Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;InputText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;decorators&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;InputText&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;InputText v-bind="$props" /&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;EmptyRequired&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
&lt;span class="nx"&gt;EmptyRequired&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Required field&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;field1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Some Label&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&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;So the &lt;code&gt;required&lt;/code&gt; attribute would end up at the components input tag, making it invalid with an empty value.&lt;/p&gt;

&lt;p&gt;Per default the invalid state would never be shown in Storybook. &lt;/p&gt;

&lt;p&gt;Sure, I could've added an extra class to my CSS, which probably wouldn't ever be used in the final application, so I wanted to avoid that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a decorator
&lt;/h2&gt;

&lt;p&gt;Instead I used a decorator to wrap my story into a &lt;code&gt;form&lt;/code&gt; tag with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  decorators: [() =&amp;gt; ({ template: "&amp;lt;form&amp;gt;&amp;lt;story /&amp;gt;&amp;lt;/form&amp;gt;" })],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By that I could make use of the browser built-in validation and have my possible validation states show up right away when setting the attribute required and no value. &lt;/p&gt;

&lt;p&gt;This of course works not only with the &lt;code&gt;required&lt;/code&gt; attribute, but also with something like an invalid e-mail address on &lt;code&gt;type="email"&lt;/code&gt; inputs.&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>TIL: starting my own UI-library using Vue, Storybook &amp; Sass</title>
      <dc:creator>ɥɔɐ⅂ ɐɥɔsɐS</dc:creator>
      <pubDate>Tue, 13 Apr 2021 15:42:28 +0000</pubDate>
      <link>https://dev.to/voodoocode/til-starting-my-own-ui-library-using-vue-storybook-sass-4ih5</link>
      <guid>https://dev.to/voodoocode/til-starting-my-own-ui-library-using-vue-storybook-sass-4ih5</guid>
      <description>&lt;p&gt;I wanted to start my own Vue UI-library 🎨, to be used in different projects. &lt;/p&gt;

&lt;h2&gt;
  
  
  Scaffolding
&lt;/h2&gt;

&lt;p&gt;I was trying around with &lt;a href="https://github.com/team-innovation/vue-sfc-rollup"&gt;vue-sfc-rollup&lt;/a&gt;, which is a tool to &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"scaffold a minimal setup for compiling a Vue Single File Component (SFC) - or library of multiple SFCs - into a form ready to share via npm". &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Following &lt;a href="https://www.npmjs.com/package/vue-sfc-rollup#user-content-tldr"&gt;their setup docu&lt;/a&gt;, it worked without a problem, so I went with it. &lt;br&gt;
Having the Vue CLI dev server in place, I could add some first basic components, and view them with that in the browser.&lt;/p&gt;

&lt;p&gt;I wanted my vue components to use &lt;code&gt;lang="scss"&lt;/code&gt; in the style block, which worked out of the box. &lt;/p&gt;
&lt;h2&gt;
  
  
  Using Storybook
&lt;/h2&gt;

&lt;p&gt;My next step was to install Storybook to my project, because I did want to use that, instead of the Vue CLI dev server, suggested by vue-sfc-roll.&lt;/p&gt;

&lt;p&gt;I followed the &lt;a href="https://storybook.js.org/docs/vue/get-started/install"&gt;guide to install it to a Vue project&lt;/a&gt; and also found the helpful guide to &lt;a href="https://storybook.js.org/docs/vue/configure/webpack#extending-storybooks-webpack-config"&gt;extend the webpack configuration&lt;/a&gt;, to add the sass and style loaders.&lt;/p&gt;

&lt;p&gt;Now running Storybook's server, the components themselves did appear in their stories, but completely &lt;em&gt;without&lt;/em&gt; any styles applied just bare-naked browser defaults. 😿&lt;br&gt;
Only when using no &lt;code&gt;lang&lt;/code&gt;-attribute at all, they would appear styled.&lt;/p&gt;

&lt;p&gt;I realized, that Storybook must be misconfigured somehow.&lt;/p&gt;
&lt;h2&gt;
  
  
  Webpack's shaking trees to hard
&lt;/h2&gt;

&lt;p&gt;At one point (and dozens of Github/SO searches later 😅) I found a hint in Webpack's docu: &lt;a href="https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free"&gt;Marking as side-effect-free&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;As I didn't setup anything like that myself, I was quite surprised to find, that seemingly vue-sfc-rollup had set &lt;code&gt;"sideEffects": false&lt;/code&gt; in the package.json. &lt;/p&gt;

&lt;p&gt;Removing that property, or even better using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"sideEffects": ["*.vue"],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would solve my problem! 🥳 The components were styled even in Storybook.&lt;/p&gt;

&lt;p&gt;So apparently Storybook's webpack had pruned the Sass inside my &lt;code&gt;.vue&lt;/code&gt; files, where the Vue CLI service dev server did not do that.&lt;/p&gt;

&lt;p&gt;And yes, a quick search in Vue CLI's documentation would reveal &lt;a href="https://cli.vuejs.org/guide/build-targets.html#library"&gt;this page, where they even have a yellow warning&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are developing a library or in a monorepo, please be aware that CSS imports are side effects. Make sure to remove "sideEffects": false in the package.json, otherwise CSS chunks will be dropped by webpack in production builds. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Great, now I am able to continue developing my very first Vue UI-library!&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
