<?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: timreach</title>
    <description>The latest articles on DEV Community by timreach (@timreach).</description>
    <link>https://dev.to/timreach</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%2F1001666%2Fec4e32d9-b4a7-4d86-b827-b9490dfdc21a.jpeg</url>
      <title>DEV Community: timreach</title>
      <link>https://dev.to/timreach</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/timreach"/>
    <language>en</language>
    <item>
      <title>How to stop Storybook opening a new webpage on start (automatically with zsh)</title>
      <dc:creator>timreach</dc:creator>
      <pubDate>Tue, 21 May 2024 10:29:29 +0000</pubDate>
      <link>https://dev.to/timreach/how-to-automatically-add-options-to-storybook-or-any-yarn-scripts-with-zsh-3nm0</link>
      <guid>https://dev.to/timreach/how-to-automatically-add-options-to-storybook-or-any-yarn-scripts-with-zsh-3nm0</guid>
      <description>&lt;p&gt;This started as a tip for Storybook users but it is probably useful for anyone who uses zsh -&lt;/p&gt;

&lt;p&gt;Do you find it annoying that whenever you run &lt;code&gt;$ yarn storybook&lt;/code&gt;, Storybook takes the liberty of opening itself in a brand new tab? No fun if you're just restarting it because hot reload isn't working or something.&lt;/p&gt;

&lt;p&gt;You may or may not know that there is an option to prevent this from happening: &lt;code&gt;$ yarn storybook --ci&lt;/code&gt; will start Storybook but not open a tab. Hoorah.&lt;/p&gt;

&lt;p&gt;But even knowing this, I often forget and become annoyed for literally microseconds as I close the superfluous tab. Sure, I could just suck up the minor inconvenience, meditate more, drink less caffeine, get some perspective. Or, I could just automate a fix. &lt;/p&gt;

&lt;p&gt;I don't want to impose my preference upon the whole team so I don't want to just add the flag to the scripts definition in package.json so instead let's just configure the terminal to add the flag in automatically.&lt;/p&gt;

&lt;p&gt;Simply add the following to your &lt;code&gt;~/.zshrc&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;yarn&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"storybook"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;yarn storybook &lt;span class="nt"&gt;--ci&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="p"&gt;@&lt;/span&gt;:2&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;yarn &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;P.S. don't forget to restart your terminal before testing it works...&lt;/p&gt;

&lt;p&gt;This basically does a check any time yarn is run and if you're executing storybook will automatically add the flag. I'm sure you can imagine other uses of this pattern for similar issues where you want edit the default way a script executes on your machine but not your team's.&lt;/p&gt;

</description>
      <category>zsh</category>
      <category>webdev</category>
      <category>storybook</category>
      <category>yarn</category>
    </item>
    <item>
      <title>Using fonts in Storybook for Next.JS and Tailwind Projects</title>
      <dc:creator>timreach</dc:creator>
      <pubDate>Thu, 29 Feb 2024 21:53:48 +0000</pubDate>
      <link>https://dev.to/timreach/using-fonts-in-storybook-for-nextjs-and-tailwind-projects-4f1p</link>
      <guid>https://dev.to/timreach/using-fonts-in-storybook-for-nextjs-and-tailwind-projects-4f1p</guid>
      <description>&lt;p&gt;I'm pretty new to Storybook. I am so frustrated I haven't used it in projects earlier as developing components in isolation is incredible. However I hit a bit of a gotcha this week when using it in my shadcn/ui based Next/Tailwind project.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy368k6o6p6ct12qhwdl1.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy368k6o6p6ct12qhwdl1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to use a custom font in Next app router you need to &lt;a href="https://nextjs.org/docs/app/building-your-application/optimizing/fonts" rel="noopener noreferrer"&gt;import them the next way&lt;/a&gt; to get the benefit of all Next's nextiness. If you're using Tailwind, &lt;a href="https://nextjs.org/docs/app/building-your-application/optimizing/fonts#with-tailwind-css" rel="noopener noreferrer"&gt;the Next docs instruct you&lt;/a&gt; to export a variable name from the Next font object and insert it into the &lt;code&gt;classNames&lt;/code&gt; of the body element in your root layout. You then reference this variable in your tailwind config under &lt;code&gt;sans&lt;/code&gt; or your own chosen selector. This is also the instructions provided in &lt;a href="https://ui.shadcn.com/docs/installation/next" rel="noopener noreferrer"&gt;the shadcn/ui Next setup docs&lt;/a&gt;. As someone who doesn't really use CSS variables this seems incredibly arkane, but it works fantastically well.&lt;/p&gt;

&lt;p&gt;However, I noticed that it wasn't &lt;strong&gt;always&lt;/strong&gt; working. I don't want to admit how long it took me to simply realising that when I was working in Storybook the font wasn't loading. In fact the only thing that flagged this issue was that it was falling back to a default sans-serif system font which didn't have a full range of font weights. Long story short, my fonts were not in Storybook.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcnhngpxh8hr7f7c3t9s.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcnhngpxh8hr7f7c3t9s.png" alt="Storybook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course Storybook is &lt;strong&gt;NOT&lt;/strong&gt; Next. The root layout where you are importing your font and defining its CSS variable isn't in use. Forehead slapping aside, the solution was relatively easy. In my case, I am using the shadcn/ui default font of &lt;a href="https://fonts.google.com/specimen/Inter" rel="noopener noreferrer"&gt;Inter&lt;/a&gt; so I just needed to load this in and apply it to the body of the Storybook instance. And of course, you load this in, as per Google's advice, in the header of the document.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://storybook.js.org/docs/api/main-config-preview-head" rel="noopener noreferrer"&gt;A little digging into the Storybook docs reveals a useful feature&lt;/a&gt; of &lt;code&gt;preview-head.html&lt;/code&gt;, which is a file you can define in your &lt;code&gt;.storybook&lt;/code&gt; directory which will then be treated as the head element of Storybook. This gives you somewhere to import your font from Google Font's CDN and also define a style tag where you apply the font to the body element. My file ended up looking like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.gstatic.com"&lt;/span&gt; &lt;span class="na"&gt;crossorigin&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Inter:wght@100..900&amp;amp;display=swap"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"Inter"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;-webkit-font-smoothing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;antialiased&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;-moz-osx-font-smoothing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grayscale&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;/style&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A previous attempt at solving this involved importing the font at Storybook's &lt;code&gt;preview.tsx&lt;/code&gt; in a global decorator, however this doesn't catch instances where components are instantiated as siblings of your story, such as with popovers or alert dialogs. A wrapper is almost as good, but using the preview head is more universal.&lt;/p&gt;

&lt;p&gt;I hope this helps someone else in this confusing but not all that uncommon situation solve the problem a little faster than I did.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>tailwindcss</category>
      <category>storybook</category>
      <category>shadcnui</category>
    </item>
    <item>
      <title>How to preview a Next.JS app on a mobile device</title>
      <dc:creator>timreach</dc:creator>
      <pubDate>Fri, 17 Mar 2023 12:36:15 +0000</pubDate>
      <link>https://dev.to/timreach/how-to-preview-a-nextjs-app-on-a-mobile-device-lf6</link>
      <guid>https://dev.to/timreach/how-to-preview-a-nextjs-app-on-a-mobile-device-lf6</guid>
      <description>&lt;p&gt;So you're building a mobile web app and you want to view it on an actual phone not a virtual one in your dev tools? No, you don't have to deploy! If you've ever used Create React App, running developer mode gives you simple instructions for doing this, however Next.JS &lt;code&gt;$ yarn dev&lt;/code&gt; does not! Fear not, it is very simple...&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Get your machine's IP address
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Linux/Mac&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ifconfig

&lt;span class="c"&gt;# Or Windows...&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ipconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Run your project
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.Open browser on your phone
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If your machine's IP is &lt;code&gt;192.168.0.69&lt;/code&gt;...&lt;/li&gt;
&lt;li&gt;...navigate to &lt;code&gt;192.168.0.69:3000&lt;/code&gt; on your phone&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's as easy as that!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
