<?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: Brendan Carney</title>
    <description>The latest articles on DEV Community by Brendan Carney (@brendanrc2).</description>
    <link>https://dev.to/brendanrc2</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%2F331963%2F74721bc4-1fc3-4284-9087-02a894ca9b41.jpg</url>
      <title>DEV Community: Brendan Carney</title>
      <link>https://dev.to/brendanrc2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brendanrc2"/>
    <language>en</language>
    <item>
      <title>How We Use Tailwind in Components</title>
      <dc:creator>Brendan Carney</dc:creator>
      <pubDate>Sun, 22 Mar 2020 17:43:51 +0000</pubDate>
      <link>https://dev.to/brendanrc2/how-we-use-tailwind-in-components-f77</link>
      <guid>https://dev.to/brendanrc2/how-we-use-tailwind-in-components-f77</guid>
      <description>&lt;p&gt;I wrote about &lt;a href="https://dev.to/brendanrc2/why-we-use-tailwind-at-convertkit-1660"&gt;Why We Use Tailwind at ConvertKit&lt;/a&gt;. This is about how we use Tailwind in our components. &lt;/p&gt;

&lt;p&gt;The short version is that we use the tailwind classes directly in our components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"px-4 py-2 bg-gray-700 text-white"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But, we also want our components to do a little more. We want to work with a fixed set of colors, sizes, etc. to make development easier and our UI more consistent. That way, our developers can write code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt; &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"lg"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Save Form&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;instead of having to repeat classes all the time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"bg-red text-white px-4 py-2"&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here's how we do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DEFAULT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;border border-solid border-transparent&lt;/span&gt;&lt;span class="dl"&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;COLORS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;green&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text-white bg-green-400 hover:bg-green-500&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;red&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text-white bg-red-400 hover:bg-red-500&lt;/span&gt;&lt;span class="dl"&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;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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="nx"&gt;className&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;DEFAULT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;COLORS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;]].&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;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;This is a simplified example of our actual component that's only handling the different colors. We have a default set of classes that all buttons have (&lt;code&gt;DEFAULT&lt;/code&gt;), then, we have an object representing the different colors (&lt;code&gt;COLORS&lt;/code&gt;). When someone passes &lt;code&gt;red&lt;/code&gt; as the &lt;code&gt;color&lt;/code&gt; prop, we use the classes that match that key: &lt;code&gt;COLORS["red"]&lt;/code&gt;. We merge all this together with the &lt;code&gt;className&lt;/code&gt; prop that that you can also pass to our component to add additional classes if necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A red button with margin at the bottom&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"mb-2"&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We follow the same pattern for sizes, variants, and different states of our components. &lt;/p&gt;

&lt;p&gt;How are you using Tailwind in React components?&lt;/p&gt;

&lt;p&gt;P.S. We're hiring a few full stack engineers at ConvertKit. Learn more here &lt;a href="//convertk.it/engineer"&gt;convertk.it/engineer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why We Use Tailwind at ConvertKit</title>
      <dc:creator>Brendan Carney</dc:creator>
      <pubDate>Wed, 18 Mar 2020 11:53:44 +0000</pubDate>
      <link>https://dev.to/brendanrc2/why-we-use-tailwind-at-convertkit-1660</link>
      <guid>https://dev.to/brendanrc2/why-we-use-tailwind-at-convertkit-1660</guid>
      <description>&lt;p&gt;When my coworker first introduced me to &lt;a href="https://tailwindcss.com/"&gt;Tailwind&lt;/a&gt; (hi Mark), I had the same reaction as most people that hadn't used a utility-first CSS framework before. Why do we need this? If we're writing solid CSS everywhere, and all following the same patterns, conventions, and rules, and keeping our UI consistent across different teams, then we don't need a framework that pollutes our HTML with all these non-semantic class names. &lt;/p&gt;

&lt;p&gt;Then I took another look at our CSS...&lt;/p&gt;

&lt;p&gt;We used bootstrap, BEM, OOCSS, some css modules, and many other patterns and conventions across the application. No one really knew which one was the right one to use at any given time. No one knows what is used and unused. Our CSS had become an append-only stylesheet. &lt;/p&gt;

&lt;p&gt;So we decided to give Tailwind a shot and styling our application immediately became easier for everyone. We no longer need to think about what conventions we're following, what to name things, or where to put styles. We don't have to worry about breaking styles somewhere else in the application or our stylesheets continuing to grow unchecked. We only need to follow a few simple rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use our component library&lt;/li&gt;
&lt;li&gt;Use Tailwind&lt;/li&gt;
&lt;li&gt;Fallback to inline styles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that's it.&lt;/p&gt;

&lt;p&gt;There are many articles about why you should use Tailwind, but why do we use Tailwind? &lt;strong&gt;Because it simplifies just about everything when it comes to styling UI across our teams&lt;/strong&gt;. It eliminates decisions of where to put things or how to write them. It comes with great documentation. For teams, especially with varying backgrounds and UI skill levels, Tailwind is a massive productivity boost. &lt;/p&gt;

&lt;p&gt;Why do you use/not use Tailwind?&lt;/p&gt;

&lt;p&gt;P.S. We're hiring a few full stack engineers at ConvertKit. Learn more here &lt;a href="//convertk.it/engineer"&gt;convertk.it/engineer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Two Components are Better than One</title>
      <dc:creator>Brendan Carney</dc:creator>
      <pubDate>Tue, 17 Mar 2020 12:29:17 +0000</pubDate>
      <link>https://dev.to/brendanrc2/two-components-are-better-than-one-1hjo</link>
      <guid>https://dev.to/brendanrc2/two-components-are-better-than-one-1hjo</guid>
      <description>&lt;p&gt;Component based libraries like React are great in part because they allow us to encapsulate a piece of UI, and reuse it across our application. This allows us to have consistent UI, and makes tweaking styles easy. But, reusability can be taken too far. It might be tempting to only have one &lt;code&gt;Button&lt;/code&gt; in your component library that can handle everything, but you can easily end up with something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;
  &lt;span class="na"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"gear"&lt;/span&gt;
  &lt;span class="na"&gt;iconPosition&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"left"&lt;/span&gt;
  &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"small"&lt;/span&gt;
  &lt;span class="na"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"outline"&lt;/span&gt;
  &lt;span class="na"&gt;isLoading&lt;/span&gt;
  &lt;span class="na"&gt;fullWidth&lt;/span&gt;
  &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;andManyManyMore&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1002110517094371328-28" src="https://platform.twitter.com/embed/Tweet.html?id=1002110517094371328"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1002110517094371328-28');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1002110517094371328&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;What was once a simple &lt;code&gt;Button&lt;/code&gt; now has props for every imaginable use case), making it hard to maintain or change. &lt;/p&gt;

&lt;p&gt;Sometimes, it's better to have a few more components for specific use cases instead of one component that handles everything. Here are a few examples where I've created multiple components instead of adding more props to one:&lt;/p&gt;

&lt;p&gt;Instead of a &lt;code&gt;Button&lt;/code&gt; that can have text or just an icon, create a normal &lt;code&gt;Button&lt;/code&gt; and a separate &lt;code&gt;IconButton&lt;/code&gt;. This way, you won't have to special case spacing when there is text with an icon, and you can easily build an API that forces you to add a label for accessibility in your &lt;code&gt;IconButton&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Instead of a &lt;code&gt;SelectMenu&lt;/code&gt; component that can handle both single selection and multiple selection, split into &lt;code&gt;SelectMenu&lt;/code&gt; and &lt;code&gt;MultiselectMenu&lt;/code&gt;. The logic around these is different enough that maintenance and styling is much simpler when they are kept separate.&lt;/p&gt;

&lt;p&gt;What are some other examples of components trying to do too much?&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
