<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Liam Hall on Medium]]></title>
        <description><![CDATA[Stories by Liam Hall on Medium]]></description>
        <link>https://medium.com/@wearethreebears?source=rss-cb538909ca6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*1xbkRUWnp6cEPRiRsqpdPw.jpeg</url>
            <title>Stories by Liam Hall on Medium</title>
            <link>https://medium.com/@wearethreebears?source=rss-cb538909ca6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:29:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wearethreebears/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring Typesafe design tokens in Tailwind 4]]></title>
            <link>https://levelup.gitconnected.com/exploring-typesafe-design-tokens-in-tailwind-4-4db0e283c9c1?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4db0e283c9c1</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Fri, 29 Nov 2024 11:54:32 GMT</pubDate>
            <atom:updated>2024-12-02T01:54:57.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*V5bSeGXuc-y2Ketn2waVKA.png" /></figure><p>Tailwind 4 has been on the horizon for a while, with the team first open-sourcing their progress in March 2024. One of the most noteworthy changes, in my opinion, is the shift from a JavaScript-based configuration to a CSS-based one. Tailwind 4 is currently in beta, and from what I gather, the team is still dealing with some challenges, especially with Safari compatibility.</p><p>NOTE: Later in the article, we’ll assume you’re using a component-based framework / library, but the concepts discussed are easily transferable to other approaches.</p><h3>Changes in Tailwind 4</h3><h3>The move to a CSS config</h3><p>I’ve heard some complaints about this, especially from TypeScript users. However, the roadmap for Tailwind 4.0 does include support for the classic tailwind.config.js as its top priority:</p><blockquote><em>Support for JavaScript configuration files — reintroducing compatibility with the classic tailwind.config.js file to make migrating to v4 easy.</em></blockquote><p>That said, it seems like this is intended primarily for migration purposes and may not be a sustainable long-term solution.</p><h3>What does this mean for Typesafety</h3><p>Under the hood Tailwind 4 uses the new @property CSS rules to to define internal custom properties.</p><blockquote><em>We use </em><em>@property to define our internal custom properties with proper types and constraints</em></blockquote><p>As it stands I’m unable to find decent syntax highlighting support for @property rules in VS code, I have reached out on <a href="https://bsky.app/profile/liamhall91.bsky.social">Bluesky</a> to see if anyone has had more luck than me.</p><p>I’m hoping better @property support can aide us in future, more on that later.</p><h4>What is the @property CSS rule</h4><blockquote><em>The </em><em>@property rule represents a custom property registration directly in a stylesheet without having to run any JavaScript. Valid @property rules result in a registered custom property, which is similar to calling </em><em>registerProperty() with equivalent parameters.</em></blockquote><h3>What are design tokens</h3><p>Now that we’ve covered the upcoming changes in Tailwind 4 and their potential impact, let’s take a moment to talk about design tokens. If you’re not familiar with the term, here’s a quick explanation: Design tokens are a method of storing and managing design decisions in a consistent, reusable format, typically as variables. They represent key visual properties of a design system, like colours, typography, spacing, shadows, in a structured way. The goal is to centralise these design values so they can be easily updated, maintained, and shared across different platforms and tools.</p><p>Design systems are typically made up of two main types of values: System values and Component values. For example, your system values might look something like this:</p><pre>const SYSTEM_TOKENS: ISystemTokens = {<br>  /* ... */<br>  COLORS: {<br>    /* ... */<br>    GREEN: {<br>      LIGHT: &quot;#E0E5D9&quot;,<br>      MEDIUM: &quot;#3F6212&quot;,<br>      DARK: &quot;#28331A&quot;,<br>    }<br>    /* ... */<br>  },<br>  TYPOGRAPHY: {<br>    /* ... */<br>  }<br>  /* ... */<br>}</pre><p>You can then reference your system values within your component tokens like this:</p><pre>import { SYSTEM_TOKENS } from &quot;...&quot;;<br><br>const BUTTON_VALUES: IButtonTokens = {<br>  /* ... */<br>  COLORS: {<br>    /* ... */<br>    BACKGROUND: SYSTEM_TOKENS.COLORS.GREEN.DARK,<br>    /* ... */<br>  },<br>  TYPOGRAPHY: {<br>    /* ... */<br>  }<br>  /* ... */<br>}</pre><p>If you’re interested in learning more about design systems, it’s worth exploring well-known systems like<a href="https://m3.material.io/foundations/design-tokens/overview">Material Design</a>.</p><h3>Structuring component design tokens with Tailwind</h3><p>About a week ago, I wrote an article discussing an alternative approach I’ve been using for creating component variants with Tailwind CSS. In brief, the article explores how we can leverage CSS variables alongside Tailwind to manage complex variants, setting variant values inline through dynamic component props and variable mapping. If you’re curious about how I arrived at this approach, you can read more about it here: <a href="https://dev.to/wearethreebears/a-different-approach-to-writing-component-variants-with-tailwind-css-354c">A different approach to writing component variants with Tailwind CSS</a>.</p><p>We should start by identifying the parts of our component that depend on design tokens. As mentioned earlier, this will include colors, typography, spacing, and any other fixed system values that are integral to your design. Let’s take a look at the following Button component, without design tokens:</p><pre>&lt;button class=&quot;p-4 bg-red text-white rounded-lg relative flex justify-center&quot;&gt;Click me&lt;/button&gt;</pre><p>In the example above, we can pinpoint several values that can be tokenized. Each of the following classes could correspond to a value in our design system:</p><ul><li>p-4</li><li>bg-red</li><li>text-white</li></ul><p>Now that we’ve identified the values that can be tokenised, we can categorise them into two groups: static values and dynamic values. Static values are those in your component that remain constant, while dynamic values are those that can change based on the props passed to the component. For our example we&#39;ll make the padding (p-4) static, while the text colour (text-white) and background (bg-red) should be set dynamically via a theme prop.</p><h3>Creating the tokens</h3><h4>Tailwind 4 config</h4><p>First we need to define our System tokens in the new Tailwind CSS config:</p><pre>@import &quot;tailwindcss&quot;;<br><br>@theme {<br>  --color-white: #FFFFFF;<br>  --color-green-light: #E0E5D9;<br>  --color-green-medium: #3F6212;<br>  --color-green-dark: #28331A;<br>  --color-red-light: #F4CCCC;<br>  --color-red-medium: #D50000;<br>  --color-red-dark: #640000;<br>  --spacing-sm: 1rem;<br>  --spacing-md: 2rem;<br>}</pre><h4>System tokens</h4><p>Next we need to create our system.tokens.ts file:</p><pre>export type TColor = &quot;--color-white&quot; | &quot;--color-green-light&quot; | &quot;--color-green-medium&quot; | &quot;--color-green-dark&quot; | &quot;--color-red-light&quot; | &quot;--color-red-medium&quot; | &quot;--color-red-dark&quot;;</pre><pre>export type TSpacing = &quot;--spacing-sm&quot; | &quot;--spacing-md&quot;;<br><br>interface ISystemTokens {<br>  COLORS: {<br>    WHITE: TColor;<br>    GREEN: {<br>      LIGHT: TColor;<br>      MEDIUM: TColor;<br>      DARK: TColor;<br>    },<br>    RED: {<br>      LIGHT: TColor;<br>      MEDIUM: TColor;<br>      DARK: TColor;<br>    }<br>  },<br>  SPACING: {<br>    SMALL: TSpacing;<br>    MEDIUM: TSpacing;<br>  }<br>}<br>export const  SYSTEM_TOKENS: ISystemTokens {<br>  COLORS: {<br>    WHITE: &quot;--color-white&quot;;<br>    GREEN: {<br>      LIGHT: &quot;--color-green-light&quot;;<br>      MEDIUM: &quot;--color-green-light&quot;;<br>      DARK: &quot;--color-green-light&quot;;<br>    },<br>    RED: {<br>      LIGHT: &quot;--color-red-light&quot;;<br>      MEDIUM: &quot;--color-red-medium&quot;;<br>      DARK: &quot;--color-red-dark&quot;;<br>    }<br>  },<br>  SPACING: {<br>    SMALL: &quot;--spacing-sm&quot;;<br>    MEDIUM: &quot;--spacing-md&quot;;<br>  }<br>}</pre><p>System design tokens can be referenced in designs like so:<br>$system.COLORS.GREEN.LIGHT.</p><p>In an ideal world, we could directly export types from our CSS file’s @property rules into our TColor and TSpacing types, much like how SCSS imports can be transformed into JavaScript. Unfortunately, as of now, to the best of my knowledge, this isn&#39;t possible.</p><h4>Component tokens</h4><p>Now that we’ve implemented our system tokens, we can start integrating them into our components. The first step is to set up our &lt;Component&gt;.tokens.ts file. To illustrate this, let’s take the example of the Button component we looked at earlier, and create a corresponding Button.tokens.ts file.</p><p>To recap, here’s how our Button component was structured:</p><pre>&lt;button class=&quot;p-4 bg-red text-white rounded-lg relative flex justify-center&quot;&gt;Click me&lt;/button&gt;</pre><p>Earlier, we discussed the distinction between static values (like p-4) and dynamic values (like bg-red and text-white). This distinction will guide how we organise our design tokens. Static properties, like p-4, should be grouped under STATIC, while dynamic properties, like bg-red and text-white, should be grouped under the appropriate prop identifier. In this case, since we’re controlling bg-red and text-white through a theme prop, they should be placed under the THEME section in our tokens file. For our example we&#39;ll assume 2 theme variables - PRIMARY and SECONDARY.</p><pre>import { SYSTEM_TOKENS, TColor, TSpacing } from &quot;./system.tokens.ts&quot;;<br>import { TTheme } from &quot;./Button&quot;; // PRIMARY, SECONDARY</pre><pre>interface IButtonStaticTokens {<br>  padding: TSpacing;<br>}<br>interface IButtonThemeTokens {<br>  backgroundColor: TColor;<br>  textColor: TColor;<br>}<br>export const STATIC: IButtonStaticTokens {<br>  padding: &quot;--spacing-sm&quot;;<br>}<br>export const THEME: IButtonStaticTokens {<br>  PRIMARY: {<br>    backgroundColor: &quot;--color-red-dark&quot;;<br>    textColor: &quot;--color-red-light&quot;;<br>  },<br>  SECONDARY: {<br>    backgroundColor: &quot;--color-green-dark&quot;;<br>    textColor: &quot;--color-green-light&quot;;<br>  };<br>}</pre><p>Component design tokens can be referenced in designs like so: $component.Button.THEME.PRIMARY.backgroundColor. My preference for naming conventions is to use:<br>$component.&lt;ComponentName&gt;.&lt;PROP_NAME&gt;&lt;PROP_VALUE&gt;.tokenName</p><p>$component: Differentiate between $system and $component tokens<br>&lt;ComponentName&gt;: Follow internal file naming convention for components<br>PROP_NAME: Constant case<br>PROP_VALUE: Should follow internal prop value casing<br>Token name (backgroundColor): Camel case*</p><p>This is ultimately a matter of personal preference, and it’s up to you to decide what works best for your workflow.</p><ul><li>When naming tokens, I slightly deviate from Camel case if I need to specify a token for an element’s state, such as :hover. In those cases, I prefix the token name with the state followed by two underscores, like so: hover__backgroundColor.</li></ul><h3>Using design tokens in components</h3><p>As I mentioned earlier in the article, I previously wrote about exploring<a href="https://dev.to/wearethreebears/a-different-approach-to-writing-component-variants-with-tailwind-css-354c">a different approach to writing component variants with Tailwind CSS</a>. I’ll be referencing that approach here, so if you haven’t read it yet, it might be helpful to check it out first to understand the context behind this method.</p><p>This part of the article will assume you are using a Javascript framework or library to build your components.</p><h4>Updating the Button component</h4><p>We need to replace the existing tokenisable classes with Tailwind classes powered by css variables. Note the variable names match those in our 2 Button component token interfaces, IButtonStaticTokens and IButtonThemeTokens;</p><pre>&lt;button class=&quot;p-[--padding] bg-[--backgroundColor] text-[--textColor] rounded-lg relative flex justify-center&quot;&gt;Click me&lt;/button&gt;</pre><p>Now that we’ve updated our classes, we need to dynamically apply the component styles and update the variables. To achieve this, we’ll use a variableMap function on the component. Essentially, this function maps our tokens from Button.tokens.ts to inline CSS variables directly on the component, which our classes can then reference. For an example of a variable map please see the end of <a href="https://dev.to/wearethreebears/a-different-approach-to-writing-component-variants-with-tailwind-css-354c">this article</a>.</p><pre>&lt;template&gt;<br>  &lt;button<br>    :style=&quot;[variableMap(STATIC), variableMap(THEME[props.THEME])]&quot;<br>    class=&quot;p-[--padding] bg-[--backgroundColor] text-[--textColor] <br>    rounded-lg relative flex justify-center&quot;<br>  &gt;<br>    Click me<br>  &lt;/button&gt;<br>&lt;/template&gt;<br>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { variableMap } from &quot;...&quot;;<br>import { STATIC, THEME } from &quot;Button.tokens.ts&quot;;<br>const props = /*THEME*/<br>&lt;/script&gt;</pre><h3>Conclusion</h3><p>I’m looking forward to the release of Tailwind 4 and what changes the team make between now and then. I’ve enjoyed experimenting with ideas to deal with some of the challenges around design tokens, variants and typesafety.</p><p>This is an experimental approach on which I’m sure there will be some strong opinions.</p><p>If you’ve found this article interesting or useful, please follow me on <a href="https://bsky.app/profile/liamhall91.bsky.social">Bluesky</a> (I’m most active here), <a href="https://medium.com/@wearethreebears">Medium</a>, <a href="https://dev.to/wearethreebears">Dev</a> and/ or <a href="https://dev.totwitter/">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4db0e283c9c1" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/exploring-typesafe-design-tokens-in-tailwind-4-4db0e283c9c1">Exploring Typesafe design tokens in Tailwind 4</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A different approach to writing component variants with Tailwind CSS]]></title>
            <link>https://levelup.gitconnected.com/a-different-approach-to-writing-component-variants-with-tailwind-css-9b369a466280?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b369a466280</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Sun, 17 Nov 2024 20:55:33 GMT</pubDate>
            <atom:updated>2024-11-19T18:37:01.704Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*IppaxADiDZWmyv8YvHieeQ.png" /></figure><h3>The problem</h3><p>Traditionally when writing component variants with Tailwind CSS I’ve reached for simple class maps that map a prop value to component slots:</p><pre>type TTheme = &quot;DEFAULT&quot; | &quot;SECONDARY&quot;;<br>interface IComponentSlot {<br>  root: string;<br>  accent: string;<br>}<br><br>const THEME_MAP: Record&lt;TTheme, IComponentSlot&gt; = {<br>  DEFAULT: {<br>    root: &quot;bg-red hover:background-pink&quot;,<br>    accent: &quot;text-blue hover:text-green&quot;,<br>  },<br>  SECONDARY: {<br>    root: &quot;bg-green hover:background-black&quot;,<br>    accent: &quot;text-pink hover:text-white&quot;,<br>  }<br>}<br><br><br>&lt;div :class=&quot;THEME_MAP[&#39;DEFAULT&#39;].root&quot;&gt;<br>  &lt;div :class=&quot;THEME_MAP[&#39;DEFAULT&#39;].accent&quot;&gt;/**/&lt;/div&gt;<br>&lt;/div&gt;<br></pre><p>The problem with this approach is keeping the required classes in line with one another, ensuring each variant has all the required classes, particularly in more complicated components. In components where we want to share a style, say text color, across different component slotsit requires us to update each slot individually.</p><h3>The limitations of Tailwind</h3><p>Tailwind generates utility classes by scanning your codebase and matching strings, this means while Tailwind can create classes from arbitrary values, we can’t initiate them dynamically without creating a safe list. So this will not work:</p><pre>// .ts<br>type TTheme = &quot;DEFAULT&quot; | &quot;SECONDARY&quot;;<br><br>const colors: Record&lt;TTheme, string&gt; = {<br>  DEFAULT: &quot;red&quot;,<br>  SECONDARY: &quot;blue&quot;,<br>}<br><br>// .html<br>&lt;div :class=&quot;`text-[${colors[DEFAULT]}]`&quot;&gt;<br></pre><p>However, we can imitate the desired behavior by taking advantage of CSS variables, something Tailwind uses under the hood for lots of its classes. We can set a variable via a class in Tailwind using the following syntax: [--my-variable-key:--my-variable-value]</p><p>So how could we update the above code example to use dynamic values?</p><pre>// .ts<br>type TTheme = &quot;DEFAULT&quot; | &quot;SECONDARY&quot;;<br><br>const colors: Record&lt;TTheme, string&gt; = {<br>  DEFAULT: &quot;[--text-color:red]&quot;,<br>  SECONDARY: &quot;[--text-color:blue]&quot;,<br>}<br><br>// .html<br>&lt;div<br>  :class=&quot;[<br>    colors[DEFAULT],<br>    &#39;text-[--text-color]&#39;<br>  ]&quot;&gt;</pre><h3>Tackling the initial problem</h3><p>Now we understand the limitations of Tailwind, we need to look into ways to solve our initial problem caused by our class maps approach. We can start by simplifying our class maps:</p><pre>type TTheme = &quot;DEFAULT&quot; | &quot;SECONDARY&quot;;<br>interface IComponentSlot {<br>  root: string;<br>  accent: string;<br>}<br><br>const THEME_MAP: Record&lt;TTheme, string&gt; = {<br>  DEFAULT: &quot;[--backgound:red] [--hover__background:pink] [--text:blue] [--hover__text:green]&quot;,<br>  SECONDARY: &quot;[--backgound:green] [--hover__background:black] [--text:pink] [--hover__text:white]&quot;,<br>}<br><br><br>&lt;div class=&quot;bg-[--background] hover:bg-[--hover__background]&quot;&gt;<br>  &lt;div class=&quot;text-[--text] hover:text-[--hover__text&quot;&gt;/**/&lt;/div&gt;<br>&lt;/div&gt;</pre><p>Unfortunately, this alone doesn’t solve our problem, we still can’t ensure we’ve set all of the classes we need to display each variant correctly. So how can we take this a step further? Well, we could begin writing an interfaceto force us to set specified values:</p><pre>interface IComponentThemeVariables {<br>  backgound: string;<br>  hover__backgound: string;<br>  text: string;<br>  hover__text: string;<br>}<br><br>const THEME_MAP: Record&lt;TTheme, IComponentThemeVariables&gt; = {<br>  DEFAULT: {<br>    backgound: &quot;[--backgound:red]&quot;,<br>    text: &quot;[--hover__background:pink]&quot;,<br>    hover__background: &quot;[--text:blue]&quot;,<br>    hover__text:&quot;[--hover__text:green]&quot;,<br>  },<br>  SECONDARY: {<br>    backgound: &quot;[--backgound:green]&quot;,<br>    text: &quot;[--hover__background:black]&quot;,<br>    hover__background: &quot;[--text:pink]&quot;,<br>    hover__text:&quot;[--hover__text:white]&quot;,<br>  },<br>}</pre><p>So this would work, but, there’s still a problem, nothing is stopping us from mixing up our string values. For example, we could accidentally set key background to [--text:blue].</p><p>So maybe we should type our values as well. We can’t type entire classes, that would be a maintenance nightmare, so what if we typed our colors and wrote a helper method to generate our CSS variables:</p><pre>type TColor = &quot;red&quot; | &quot;pink&quot; | &quot;blue&quot; | &quot;green&quot; | &quot;black&quot; | &quot;white&quot;;<br><br>interface IComponentThemeVariables {<br>  backgound: TColor;<br>  hover__backgound: TColor;<br>  text: TColor;<br>  hover__text: TColor;<br>}<br><br>// Example variableMap method at the end of the article<br><br>const THEME_MAP: Record&lt;TTheme, string&gt; = {<br>  DEFAULT: variableMap({<br>    backgound: &quot;red&quot;,<br>    text: &quot;pink&quot;,<br>    hover__background: &quot;blue&quot;,<br>    hover__text:&quot;green&quot;,<br>  }),<br>  SECONDARY: variableMap({<br>    backgound: &quot;green&quot;,<br>    text: &quot;black&quot;,<br>    hover__background: &quot;pink&quot;,<br>    hover__text:&quot;white&quot;,<br>  }),<br>}</pre><p>Okay so this is great, we can ensure we are always setting the correct variables for every variant of our component. But wait, we’ve just run into the initial issue we found with Tailwind, we can’t just generate classes, Tailwind won’t pick them up. So how are we going to tackle this?</p><h3>What about CSS in JS?</h3><p>CSS in JS seemed like the obvious answer here, just generate a class that creates a custom class with correct variables. But there’s a snag, the Javascript runs on the client, and this causes a “Flash”, where the component initially loads without the variables set before updating to display correctly.</p><h4>How do CSS in JS libraries deal with this?</h4><p>Libraries like Emotion deal with this by inserting inline style tags about the components:</p><pre>&lt;body&gt;<br>  &lt;div&gt;<br>    &lt;style data-emotion-css=&quot;21cs4&quot;&gt;.css-21cs4 { font-size: 12 }&lt;/style&gt;<br>    &lt;div class=&quot;css-21cs4&quot;&gt;Text&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;</pre><p>This didn’t feel like the right approach to me.</p><h3>So how do we solve this?</h3><p>I was working with Vue, this led me down the path of v-bindin CSS, a feature in Vue to bind Javascript as CSS values. I’d only used this feature sparingly in the past and never taken a deep dive into what it’s doing. v-bindin CSS simply sets an inline style on the relevant element.</p><p>This jogged my memory about a Tweet I saw from the creator of Tailwind CSS, Adam Wathan a couple of months previously:</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/adamwathan/status/1838936902084247968&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/2de421f84ae991cc658a052a98cdfe5e/href">https://medium.com/media/2de421f84ae991cc658a052a98cdfe5e/href</a></iframe><p>So how does this help us? Well, while we can’t dynamically generate Tailwind classes, we can dynamically generate inline styles and consume those inline styles from our Tailwind classes. So what would that look like?</p><pre>type TColor = &quot;red&quot; | &quot;pink&quot; | &quot;blue&quot; | &quot;green&quot; | &quot;black&quot; | &quot;white&quot;;<br><br>interface IComponentThemeVariables {<br>  backgound: TColor;<br>  hover__backgound: TColor;<br>  text: TColor;<br>  hover__text: TColor;<br>}<br><br>// Example variableMap method at the end of the article<br><br>const THEME_MAP: Record&lt;TTheme, string&gt; = {<br>  DEFAULT: variableMap({<br>    backgound: &quot;red&quot;,<br>    text: &quot;pink&quot;,<br>    hover__background: &quot;blue&quot;,<br>    hover__text: &quot;green&quot;,<br>  }),<br>  SECONDARY: variableMap({<br>    backgound: &quot;green&quot;,<br>    text: &quot;black&quot;,<br>    hover__background: &quot;pink&quot;,<br>    hover__text: &quot;white&quot;,<br>  }),<br>}<br><br>&lt;div<br>  class=&quot;bg-[--background] hover:bg-[--hover__background]&quot;<br>  :style=&quot;THEME_MAP[&#39;DEFAULT&#39;]&quot;<br>&gt;<br>  &lt;div class=&quot;text-[--text] hover:text-[--hover__text&quot;&gt;/**/&lt;/div&gt;<br>&lt;/div&gt;<br><br>/*<br>OUTPUT:<br>&lt;div<br>  class=&quot;bg-[--background] hover:bg-[--hover__background]&quot;<br>  style=&quot;--background: red; --text: pink; --hover__background: blue; --hover__text: green;&quot;<br>&gt;<br>  &lt;div class=&quot;text-[--text] hover:text-[--hover__text&quot;&gt;...&lt;/div&gt;<br>&lt;/div&gt;<br>*/</pre><h3>Conclusion</h3><p>By combining the powers of Typescript, CSS variables, and inline styles we were able to ensure that while using Tailwind CSS, each variant of our component would have every option set and with the correct type.</p><p>This is an experimental approach on which I’m sure there will be some strong opinions. Am I convinced this is the best approach? At this stage, I’m not sure, but I think it has legs.</p><p>If you’ve found this article interesting or useful, please follow me on <a href="https://bsky.app/profile/liamhall91.bsky.social">Bluesky</a> (I’m most active here), <a href="https://medium.com/@wearethreebears">Medium</a>, <a href="https://dev.to/wearethreebears">Dev</a> and/ or <a href="https://twitter.com/wearethreebears">Twitter</a>.</p><h4>Example: variableMap</h4><pre>// variableMap example<br>export const variableMap = &lt;T extends Record&lt;string, string&gt;&gt;(<br> map: T<br>): string =&gt; {<br> const styles: string[] = [];<br> Object.entries(map).forEach(([key, value]) =&gt; {<br> const wrappedValue = value.startsWith(&quot; - &quot;) ? `var(${value})` : value;<br> const variableClass = ` - ${key}: ${wrappedValue};`;<br> styles.push(variableClass);<br> });<br> return styles.join(&quot; &quot;);<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b369a466280" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/a-different-approach-to-writing-component-variants-with-tailwind-css-9b369a466280">A different approach to writing component variants with Tailwind CSS</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are higher order components and how to use them in Vue]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/what-are-higher-order-components-and-how-to-use-them-in-vue-ed73ff47d099?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/880/0*LFyRUVEyVqGoVTZ7.jpg" width="880"></a></p><p class="medium-feed-snippet">What is a higher order component</p><p class="medium-feed-link"><a href="https://medium.com/swlh/what-are-higher-order-components-and-how-to-use-them-in-vue-ed73ff47d099?source=rss-cb538909ca6f------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/what-are-higher-order-components-and-how-to-use-them-in-vue-ed73ff47d099?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed73ff47d099</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 19:18:57 GMT</pubDate>
            <atom:updated>2023-01-30T19:18:57.026Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding and Utilising TypeScript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/understanding-and-utilising-typescript-by-example-8ad2f0762ec3?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/1000/1*R8IEWZiR02BJab4bjCwRAg.png" width="1000"></a></p><p class="medium-feed-snippet">TypeScript is a powerful, open-source programming language that is a strict superset of JavaScript. Developed and maintained by Microsoft&#x2026;</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/understanding-and-utilising-typescript-by-example-8ad2f0762ec3?source=rss-cb538909ca6f------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/understanding-and-utilising-typescript-by-example-8ad2f0762ec3?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ad2f0762ec3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Mon, 16 Jan 2023 13:36:41 GMT</pubDate>
            <atom:updated>2023-03-13T05:26:37.931Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Getting started with Barebones components — A component library without design constraints built…]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@wearethreebears/getting-started-with-barebones-components-a-component-library-without-design-constraints-built-7897c4bbcb84?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/1000/1*wkhhXLFdxsVm9pUKpg3PIw.png" width="1000"></a></p><p class="medium-feed-snippet">Get started with Barebones components, a component library without design constraints built for Vue and Nuxt.</p><p class="medium-feed-link"><a href="https://medium.com/@wearethreebears/getting-started-with-barebones-components-a-component-library-without-design-constraints-built-7897c4bbcb84?source=rss-cb538909ca6f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@wearethreebears/getting-started-with-barebones-components-a-component-library-without-design-constraints-built-7897c4bbcb84?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7897c4bbcb84</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[component-libraries]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 10:02:55 GMT</pubDate>
            <atom:updated>2022-07-01T10:02:55.392Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding Javascript imports and exports]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@wearethreebears/understanding-javascript-imports-and-exports-9852f4fa3b49?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/979/1*Xcjgtw0C_Yhcxr9iwh-y1A.jpeg" width="979"></a></p><p class="medium-feed-snippet">If you&#x2019;ve spent any time working with Javascript, you&#x2019;ve probably come across Javascript Imports and Exports. Learn all about them here.</p><p class="medium-feed-link"><a href="https://medium.com/@wearethreebears/understanding-javascript-imports-and-exports-9852f4fa3b49?source=rss-cb538909ca6f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@wearethreebears/understanding-javascript-imports-and-exports-9852f4fa3b49?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9852f4fa3b49</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 09:25:51 GMT</pubDate>
            <atom:updated>2022-01-14T09:25:51.661Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building Shopify Themes With Tailwind CSS]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/building-shopify-themes-with-tailwind-css-fa27b788c8d8?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/1000/1*W9a9fmXB9s8Fol-B7OT_yg.png" width="1000"></a></p><p class="medium-feed-snippet">Learn how to get started building Shopify theme&#x2019;s with Tailwind CSS.</p><p class="medium-feed-link"><a href="https://medium.com/swlh/building-shopify-themes-with-tailwind-css-fa27b788c8d8?source=rss-cb538909ca6f------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/building-shopify-themes-with-tailwind-css-fa27b788c8d8?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa27b788c8d8</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[shopify]]></category>
            <category><![CDATA[shopify-development]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Fri, 09 Oct 2020 11:56:39 GMT</pubDate>
            <atom:updated>2020-10-10T14:31:02.980Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Dynamic component styles in Vue (Composition API and TypeScript) using Tailwind CSS and Lookup…]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/dynamic-component-styles-in-vue-composition-api-and-typescript-using-tailwind-css-and-lookup-8322eff93a96?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/1000/1*EoXvrfInMC18-zaYIWkizw.png" width="1000"></a></p><p class="medium-feed-snippet">Utilize lookup tables to handle dynamic component styles and related prop validation in Vue (Composition API and TS) using Tailwind CSS.</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/dynamic-component-styles-in-vue-composition-api-and-typescript-using-tailwind-css-and-lookup-8322eff93a96?source=rss-cb538909ca6f------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/dynamic-component-styles-in-vue-composition-api-and-typescript-using-tailwind-css-and-lookup-8322eff93a96?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8322eff93a96</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Tue, 29 Sep 2020 13:37:37 GMT</pubDate>
            <atom:updated>2020-09-29T19:57:42.044Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Dynamic component styles in Vue (Options API) using Tailwind CSS and Lookup tables]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/dynamic-component-styles-in-vue-options-api-using-tailwind-css-and-lookup-tables-99f9098646e4?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/1000/1*EoXvrfInMC18-zaYIWkizw.png" width="1000"></a></p><p class="medium-feed-snippet">Utilize lookup tables to handle dynamic component styles and related prop validation in Vue (options API) using Tailwind CSS.</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/dynamic-component-styles-in-vue-options-api-using-tailwind-css-and-lookup-tables-99f9098646e4?source=rss-cb538909ca6f------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/dynamic-component-styles-in-vue-options-api-using-tailwind-css-and-lookup-tables-99f9098646e4?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/99f9098646e4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Tue, 29 Sep 2020 10:33:04 GMT</pubDate>
            <atom:updated>2020-10-03T14:12:45.293Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Dynamic component styles in Nuxt using Tailwind CSS and Lookup tables]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/dynamic-component-styles-in-nuxt-using-tailwind-css-and-lookup-tables-a86f9f487e2b?source=rss-cb538909ca6f------2"><img src="https://cdn-images-1.medium.com/max/1000/1*T_hcmB1rqcLypOuTR_Zlkg.png" width="1000"></a></p><p class="medium-feed-snippet">Learn how to utilize lookup tables for dynamic styles in Nuxt components using Tailwind, while keeping validators in sync.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/dynamic-component-styles-in-nuxt-using-tailwind-css-and-lookup-tables-a86f9f487e2b?source=rss-cb538909ca6f------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/dynamic-component-styles-in-nuxt-using-tailwind-css-and-lookup-tables-a86f9f487e2b?source=rss-cb538909ca6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a86f9f487e2b</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Liam Hall]]></dc:creator>
            <pubDate>Fri, 25 Sep 2020 08:27:48 GMT</pubDate>
            <atom:updated>2020-09-29T10:39:43.186Z</atom:updated>
        </item>
    </channel>
</rss>