<?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: Sybren W</title>
    <description>The latest articles on DEV Community by Sybren W (@carwack).</description>
    <link>https://dev.to/carwack</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%2F459281%2F04e25193-c9de-45d9-befb-5195c03f5a73.jpeg</url>
      <title>DEV Community: Sybren W</title>
      <link>https://dev.to/carwack</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/carwack"/>
    <language>en</language>
    <item>
      <title>The one with styling Zag.js components with Tailwind CSS</title>
      <dc:creator>Sybren W</dc:creator>
      <pubDate>Tue, 29 Nov 2022 16:38:36 +0000</pubDate>
      <link>https://dev.to/carwack/the-one-with-styling-zagjs-components-with-tailwind-css-3i4h</link>
      <guid>https://dev.to/carwack/the-one-with-styling-zagjs-components-with-tailwind-css-3i4h</guid>
      <description>&lt;p&gt;When building a web application, I would advise using Chakra UI Vue to speed up your development and have accessibility build in. &lt;br&gt;
But sometimes the project requirements are different, and you have to use Tailwind CSS, for example. &lt;/p&gt;

&lt;p&gt;There is no reason to not start from zero, you can use Zag.js components with Vue.js (or React or Solid.js). Those components come with all the logic and accessibility in mind that you need to have a solid foundation.&lt;/p&gt;

&lt;p&gt;Let’s go over how we can style Zag.js components using Tailwind CSS as CSS Framework. I will use the accordion component as an example, the purpose of this post is to show how you can set up Tailwind CSS and use it to add styling to the Zag.js components you are using.&lt;/p&gt;

&lt;p&gt;A StackBlitz playground can be found here: &lt;a href="https://stackblitz.com/edit/vue-zag-tailwind?file=src/App.vue" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/vue-zag-tailwind?file=src/App.vue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those who do not know Zag.js, let’s start there first.&lt;/p&gt;
&lt;h2&gt;
  
  
  Zag.js
&lt;/h2&gt;

&lt;p&gt;Zag is a toolkit that provides framework-agnostic UI components powered by State Machines. The components are build with accessibility in mind and handle all the logic for you. They are completely headless and unstyled, which gives you the full control to use your favourite styling solution.&lt;/p&gt;

&lt;p&gt;Zag.js currently works seamless with React, Vue.js and Solid.js. In this blog, we will use Vue.js.&lt;/p&gt;

&lt;p&gt;The Zag.js documentation can be found here: &lt;a href="https://zagjs.com/" rel="noopener noreferrer"&gt;https://zagjs.com/&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Styling solution
&lt;/h2&gt;

&lt;p&gt;As you might have guessed from the title, the styling solution will be Tailwind CSS. Let’s assume you do know about this CSS Framework, documentation can be found here: &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;https://tailwindcss.com/&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;We will probably start with setting up our Vue.js project, using the Vue CLI and use Vite for example. When this has been done, we can easily add Zag.js to our project. If we scan the documentation, we quickly notice we first will have to pick a component we would like to use and style. Lets for example say the Accordion component. Documentation here: &lt;a href="https://zagjs.com/components/vue-sfc/accordion" rel="noopener noreferrer"&gt;https://zagjs.com/components/vue-sfc/accordion&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We will have to install the machine for this component, which is completely framework-agnostic.&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="nx"&gt;yarn&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;zag&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;accordion&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then comes the part to connect this machine with the Vue.js framework. For this, we need to install the adapter.&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="nx"&gt;yarn&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;zag&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;vue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just to play around with the accordion, we will add it to the &lt;code&gt;App.vue&lt;/code&gt; file. For more information about what the Zag.js code does, please take a look at the documentation of Zag.js.&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="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import * as accordion from '@zag-js/accordion'
import &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;normalizeProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useMachine&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; from '@zag-js/vue'
import &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;computed&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; from 'vue'

const data = [
    &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Watercraft&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sample accordion content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt;,
    &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Automobiles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sample accordion content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt;,
    &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Aircrafts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sample accordion content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt;,
]
const [state, send] = useMachine(accordion.machine(&lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt;))
const api = computed(() =&amp;gt; accordion.connect(state.value, send, normalizeProps))
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ref"&lt;/span&gt; &lt;span class="na"&gt;v-bind&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"api.rootProps"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
            &lt;span class="na"&gt;v-for&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"item in data"&lt;/span&gt;
            &lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"item.title"&lt;/span&gt;
            &lt;span class="na"&gt;v-bind&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"api.getItemProps({ value: item.title })"&lt;/span&gt;
        &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&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="na"&gt;v-bind&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"api.getTriggerProps({ value: item.title })"&lt;/span&gt;
                &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="p"&gt;}&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;svg&lt;/span&gt;
                        &lt;span class="na"&gt;data-accordion-icon&lt;/span&gt;
                        &lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"currentColor"&lt;/span&gt;
                        &lt;span class="na"&gt;viewBox&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0 0 20 20"&lt;/span&gt;
                        &lt;span class="na"&gt;xmlns&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;path&lt;/span&gt;
                            &lt;span class="na"&gt;fill-rule&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"evenodd"&lt;/span&gt;
                            &lt;span class="na"&gt;d&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"&lt;/span&gt;
                            &lt;span class="na"&gt;clip-rule&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"evenodd"&lt;/span&gt;
                        &lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;path&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;svg&lt;/span&gt;&lt;span class="p"&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="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
                &lt;span class="na"&gt;v-bind&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"api.getContentProps({ value: item.title })"&lt;/span&gt;
            &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;}&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;template&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;Inside the accordion header, we have added an SVG which is an arrow to indicate the state of the accordion item. Right now we notice our accordion component has any styling to it, the SVG arrow is not rotating or anything. It’s time to add Tailwind CSS to make this all possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0412h35g9ilc3etn7qom.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0412h35g9ilc3etn7qom.png" alt="Unstyled Zagjs Accordion component" width="620" height="670"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding styling
&lt;/h3&gt;

&lt;p&gt;The Zag.js documentation does show a styling guide on how to style each accordion part with CSS &lt;a href="[https://zagjs.com/components/react/accordion#styling-guide](https://zagjs.com/components/react/accordion#styling-guide)"&gt;here&lt;/a&gt;.&lt;br&gt;
We won’t be using this solution since we would like to use the Tailwind CSS framework.&lt;/p&gt;

&lt;p&gt;First, we will have to install Tailwind CSS, and it’s dependencies. Then run the init command to generate the following Tailwind CSS files: &lt;code&gt;tailwind.config.cjs&lt;/code&gt;&lt;br&gt;
 and &lt;code&gt;postcss.config.cjs&lt;/code&gt;.&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="nx"&gt;yarn&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="nx"&gt;tailwindcss&lt;/span&gt; &lt;span class="nx"&gt;postcss&lt;/span&gt; &lt;span class="nx"&gt;autoprefixer&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;D&lt;/span&gt;

&lt;span class="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;tailwindcss&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the generated &lt;code&gt;tailwind.config.cjs&lt;/code&gt; file, we add the paths to all our/ template files.&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="c1"&gt;// tailwind.config.cjs&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./index.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/**/*.{vue,js,ts,jsx,tsx}&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="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;The last thing we need to do before adding Tailwind CSS classes and running our project is adding the &lt;code&gt;@tailwind&lt;/code&gt; directives to our &lt;code&gt;./src/style.css&lt;/code&gt; file.&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="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;style&lt;/span&gt;&lt;span class="nc"&gt;.css&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can run the project and add some styling!&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Tailwind CSS styling
&lt;/h2&gt;

&lt;p&gt;We can start with adding some styling to the header of our accordion component by adding the following classes, for example.&lt;br&gt;
&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;template&amp;gt;&lt;/span&gt;
...
    &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt;
            &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"api.getTriggerProps({ value: item.title })"&lt;/span&gt;
            &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex justify-between items-center p-5 w-full font-medium text-left text-gray-500 rounded-t-xl border border-b-0 border-gray-200 focus:ring-4 focus:ring-gray-200 hover:bg-gray-100"&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            ...
        &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
...
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the accordion header we can now add the style logic to have the arrow SVG turn depending on the state. If the Zag machine &lt;code&gt;api value&lt;/code&gt; is the same as the accordions &lt;code&gt;item title&lt;/code&gt; this accordion item is open.&lt;br&gt;
&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;template&amp;gt;&lt;/span&gt;
...
    &lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt;
        &lt;span class="na"&gt;data-accordion-icon&lt;/span&gt;
        &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-6 h-6 shrink-0"&lt;/span&gt;
        &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"{ 'rotate-180': api.value == item.title }"&lt;/span&gt;
        &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"currentColor"&lt;/span&gt;
        &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 20 20"&lt;/span&gt;
        &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt;
            &lt;span class="na"&gt;fill-rule=&lt;/span&gt;&lt;span class="s"&gt;"evenodd"&lt;/span&gt;
            &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"&lt;/span&gt;
            &lt;span class="na"&gt;clip-rule=&lt;/span&gt;&lt;span class="s"&gt;"evenodd"&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;gt;&amp;lt;/path&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
...
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some small styling to the accordion content, and we have a nicely styled accordion that is also accessible.&lt;br&gt;
&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;template&amp;gt;&lt;/span&gt;
    ...
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt;
        &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"api.getContentProps({ value: item.title })"&lt;/span&gt;
        &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"p-5 border border-b-0 border-gray-200"&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        {{ item.content }}
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
...
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F7m0pfgj5qzgum1hsg9jg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7m0pfgj5qzgum1hsg9jg.png" alt="Styled Zagjs Accordion component with Tailwind CSS" width="307" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Slot
&lt;/h2&gt;

&lt;p&gt;That’s it! Not that complicated to set up and a pleasure to use! &lt;br&gt;
I do know I didn’t put much time or thought into the styling itself, feel free to make it better! I would also like to challenge you to make the accordion component reusable. &lt;br&gt;
Note that setting this up for a React project with Vite is very similar.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sources
&lt;/h3&gt;

&lt;p&gt;StackBlitz playground: &lt;a href="https://stackblitz.com/edit/vue-zag-tailwind?file=src/App.vue" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/vue-zag-tailwind?file=src/App.vue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Zag.js Documentation: &lt;a href="https://zagjs.com/" rel="noopener noreferrer"&gt;https://zagjs.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tailwind CSS Documentation: &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;https://tailwindcss.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>The one with icon libraries in Nuxt.js and Chakra UI Vue</title>
      <dc:creator>Sybren W</dc:creator>
      <pubDate>Fri, 25 Sep 2020 09:56:51 +0000</pubDate>
      <link>https://dev.to/carwack/the-one-with-icon-libraries-in-nuxt-js-and-chakra-ui-vue-5fjf</link>
      <guid>https://dev.to/carwack/the-one-with-icon-libraries-in-nuxt-js-and-chakra-ui-vue-5fjf</guid>
      <description>&lt;p&gt;When I was working on my personal project with &lt;strong&gt;Nuxt.js&lt;/strong&gt; and &lt;strong&gt;Chakra UI Vue&lt;/strong&gt; I wanted to use &lt;strong&gt;FontAwesome Icons&lt;/strong&gt;. I did struggle a bit to get the icons working in Chakra UI Vue inside my Nuxt.js project. Due to the fact that the &lt;strong&gt;Nuxt.config.js&lt;/strong&gt; object looks a little different then the normal &lt;strong&gt;Vue.config.js&lt;/strong&gt; object.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting started 🏃‍♂️
&lt;/h1&gt;

&lt;p&gt;This small blog is all about Nuxt.js and Chakra UI Vue, meaning we have to start with creating a new Nuxt.js project.&lt;/p&gt;

&lt;p&gt;Let's start quickly by using the &lt;a href="https://github.com/nuxt/create-nuxt-app" rel="noopener noreferrer"&gt;create-nuxt-app&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-nuxt-app &amp;lt;my-project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside our terminal, we will have to answer a few questions. The only thing that's really important is that we select the &lt;strong&gt;Chakra UI&lt;/strong&gt; option.&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%2Fi%2F0fdchovhgwikdpp4oxfj.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%2Fi%2F0fdchovhgwikdpp4oxfj.png" alt="Options in Nuxt create-nuxt-app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Personally, I've chosen for &lt;strong&gt;Yarn&lt;/strong&gt; as 'package manager', but feel free to pick what you prefer. After going inside the project folder we can launch our project.&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="nb"&gt;cd&lt;/span&gt; &amp;lt;project-name&amp;gt;
yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅  The first step is done!  We have our project running! Chakra UI is kind enough to change the &lt;strong&gt;Index.vue&lt;/strong&gt; page to let us know everything is running correctly.&lt;/p&gt;

&lt;h1&gt;
  
  
  🎁 Adding the Icons
&lt;/h1&gt;

&lt;p&gt;In this post, I'll be using &lt;strong&gt;FontAwesome Icons&lt;/strong&gt;, here again, pick your favorite icon pack if you want.&lt;/p&gt;

&lt;p&gt;We can add it to our project using the following yarn command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add @fortawesome/fontawesome-free
yarn add @fortawesome/free-brands-svg-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first package &lt;strong&gt;@fontawesome-free&lt;/strong&gt; are the free icons from the Font Awesome library. The other package &lt;strong&gt;@free-brands-svg-icons&lt;/strong&gt; are the free icons from brands like Twitter etc. from the Font Awesome library.&lt;/p&gt;

&lt;p&gt;For this project, I'm using the &lt;strong&gt;brands-svg-icons&lt;/strong&gt; to make a list as shown below.&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%2Fi%2F8qst0nlau7jxlmvoiqzf.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%2Fi%2F8qst0nlau7jxlmvoiqzf.png" alt="Preview of the list of brand icons"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next big step is to import the icons we wish to use, for example, the &lt;strong&gt;Twitter&lt;/strong&gt; icon.&lt;/p&gt;

&lt;p&gt;Inside the &lt;strong&gt;nuxt.config.js&lt;/strong&gt; file we have to add an import at the top for the icons.&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;faTwitter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;faGithub&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;faLinkedin&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/free-brands-svg-icons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we have to add the icons to the &lt;strong&gt;Chakra&lt;/strong&gt; plugin inside the &lt;strong&gt;config object&lt;/strong&gt;.&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%2Fi%2Fz2jl5mkdkksh0uhpeibl.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%2Fi%2Fz2jl5mkdkksh0uhpeibl.png" alt="Code of the config object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There it is! 🎉 Now we are ready to use the icons inside our templates!&lt;/p&gt;

&lt;p&gt;We will use the &lt;a href="https://vue.chakra-ui.com/icon" rel="noopener noreferrer"&gt;&lt;strong&gt;CIcon&lt;/strong&gt;&lt;/a&gt; component of Chakra UI to easily render the SVG Icons in our template. &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%2Fi%2Fdb679hj2tg3yyav1ag1f.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%2Fi%2Fdb679hj2tg3yyav1ag1f.png" alt="Code of icons in template"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;name&lt;/strong&gt; prop we have to pass the &lt;strong&gt;icon key&lt;/strong&gt;. Which is is the icon name (faTwitter) without fa and lower case for &lt;strong&gt;Font Awesome&lt;/strong&gt; icons.&lt;/p&gt;

&lt;p&gt;I would suggest to check out the documentation &lt;a href="https://vue.chakra-ui.com/icon" rel="noopener noreferrer"&gt;here&lt;/a&gt; for more info on the props.&lt;/p&gt;

&lt;p&gt;I really love how easy it is to use Icons in &lt;strong&gt;Chakra UI Vue&lt;/strong&gt; and &lt;strong&gt;Nuxt.js&lt;/strong&gt;. Thanks for reading and I do hope it will help you with your next project!&lt;/p&gt;

&lt;h1&gt;
  
  
  ❤️ Contribute to this blog
&lt;/h1&gt;

&lt;p&gt;Having any questions, caught a mistake, or have tips? Please reach out to me!&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>vue</category>
      <category>webdev</category>
      <category>chakraui</category>
    </item>
    <item>
      <title>The one with Chakra UI Vue and color palette switching</title>
      <dc:creator>Sybren W</dc:creator>
      <pubDate>Fri, 18 Sep 2020 18:56:10 +0000</pubDate>
      <link>https://dev.to/carwack/the-one-with-chakra-ui-vue-and-color-palette-switching-68e</link>
      <guid>https://dev.to/carwack/the-one-with-chakra-ui-vue-and-color-palette-switching-68e</guid>
      <description>&lt;h3&gt;
  
  
  Let's start with a new small fun project with Chakra UI Vue!
&lt;/h3&gt;

&lt;p&gt;I'm going to build a Vue.js project where it's possible to switch between color palettes defined in a custom theme object.&lt;/p&gt;

&lt;p&gt;I picked a few palettes from &lt;a href="https://www.canva.com/colors/color-palettes" rel="noopener noreferrer"&gt;www.canva.com/colors/color-palettes&lt;/a&gt; to use them in the project later on.&lt;/p&gt;

&lt;p&gt;Visually the project will not contain much besides a nice grid showing the colors. This is how the end result will look like.&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%2Fi%2Fqxqc47sy8uces5c1q99j.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%2Fi%2Fqxqc47sy8uces5c1q99j.png" alt="The Project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Aight let's roll 🚗 with the Vue CLI and start a new project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue create my-project
&lt;span class="c"&gt;# OR&lt;/span&gt;
vue ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After waiting a few seconds I can add Chakra UI Vue into this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue add chakra-ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do like some magic ✨ you can enable the auto import of the Chakra UI components during the setup of the &lt;strong&gt;vue add chakra-ui&lt;/strong&gt; run, like I did.&lt;/p&gt;

&lt;p&gt;Now we have a clean project, inside the &lt;strong&gt;App.vue&lt;/strong&gt;. We have a template with the &lt;code&gt;&amp;lt;c-theme-provide/&amp;gt;&lt;/code&gt; tag and the &lt;code&gt;&amp;lt;c-reset /&amp;gt;&lt;/code&gt; tag. &lt;/p&gt;

&lt;p&gt;Just to have a start we will add a &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; in there for some content.&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%2Fi%2Fi1cvbwrhxruk2vu64mpr.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%2Fi%2Fi1cvbwrhxruk2vu64mpr.png" alt="Basic code of the project with cThemeProvide, CReset and H1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need the &lt;strong&gt;CThemeProvide&lt;/strong&gt; component so that all the Chakra UI components inside the tag can access the theme object.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;CReset&lt;/strong&gt; component will provide all the needed css reset styles to make sure all the Chakra UI components work correctly.&lt;/p&gt;

&lt;p&gt;Boot up the project using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎉 Awesome job so far! Let's take a moment to check out this beautiful project!&lt;/p&gt;

&lt;h3&gt;
  
  
  The real work starts now by adding a custom theme! 💅
&lt;/h3&gt;

&lt;p&gt;Inside the &lt;strong&gt;assets&lt;/strong&gt; folder we have created a new folder for our &lt;strong&gt;themes&lt;/strong&gt; and created a Javascript file for the custom theme. We can call it whatever we want or be boring and use &lt;strong&gt;custom-theme.js&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Since we only will play around with custom colors, we only added those to the &lt;strong&gt;theme object&lt;/strong&gt;.&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%2Fi%2Fythf3r9sihbyu3xhwaos.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%2Fi%2Fythf3r9sihbyu3xhwaos.png" alt="Code of the custom theme object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When defining a palette we have to consider to keep the same object structure (primary-1, ..., primary-4) to have it interchangeable later on in the project.&lt;/p&gt;

&lt;p&gt;Now that we have some pretty palettes inside the new custom theme object we have to let Chakra UI know we want to extend its default theme with our custom theme.&lt;/p&gt;

&lt;p&gt;Inside the &lt;strong&gt;main.js&lt;/strong&gt; file we have to pass our custom theme object in the &lt;strong&gt;extend theme&lt;/strong&gt; option.&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%2Fi%2Foc7wtbhtle1ysnp2en2l.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%2Fi%2Foc7wtbhtle1ysnp2en2l.png" alt="Code of adding the custom theme in the extend theme option"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's build the grid displaying our custom palettes now! 🎉
&lt;/h3&gt;

&lt;p&gt;As we dive into Charka UI we find two interesting components for grid building. We will keep it simple and use the &lt;strong&gt;simpleGrid&lt;/strong&gt; (&lt;a href="https://vue.chakra-ui.com/simplegrid" rel="noopener noreferrer"&gt;https://vue.chakra-ui.com/simplegrid&lt;/a&gt;) component.&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%2Fi%2Fitvv44cwtegocfdk89xh.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%2Fi%2Fitvv44cwtegocfdk89xh.png" alt="Updated grid view"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yaay now everything is green... Don't worry it's what we need for now! &lt;br&gt;
So this grid makes 4 columns of a full screen height. &lt;br&gt;
Let's now change this green screen and add a palette in there.&lt;/p&gt;

&lt;p&gt;The only thing we do have to change is the &lt;strong&gt;style prop background&lt;/strong&gt;. We can shorten background to &lt;strong&gt;bg&lt;/strong&gt; if you would prefer to type less.&lt;/p&gt;

&lt;p&gt;The value for this prop will be our first color palette added as following.&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%2Fi%2F1xydc11lv8izhcsrzx4x.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%2Fi%2F1xydc11lv8izhcsrzx4x.png" alt="Code of grid with our first color palette"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's check out our grid, got to say it looks amazing right?!&lt;/p&gt;

&lt;h3&gt;
  
  
  Toggle please?
&lt;/h3&gt;

&lt;p&gt;Ok, now we should see how we can dynamically change the &lt;strong&gt;style props&lt;/strong&gt; value, so we can toggle between the pallets.&lt;/p&gt;

&lt;p&gt;First, we put our grid to the background and place a button to switch palettes on top of it. &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%2Fi%2Fwavwjwt7zf0200d64hp8.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%2Fi%2Fwavwjwt7zf0200d64hp8.png" alt="Code of the template with the button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we now have a blue button on top of our palette grid. I'm sure there are other ways to get that blue button in the center of the screen, but this is the way I'm sticking with now. Feel free to add your own implementation here! 💪&lt;/p&gt;

&lt;p&gt;When the user clicks the button it should change to a new palette.&lt;/p&gt;

&lt;p&gt;Inside the template we add the &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/click"&gt;@click&lt;/a&gt;&lt;/strong&gt; directive and call a newly added &lt;strong&gt;changePalette&lt;/strong&gt; method.&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%2Fi%2F9jlt89hyko68oo62ers0.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%2Fi%2F9jlt89hyko68oo62ers0.png" alt="Code of the button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside this method we start with setting the &lt;strong&gt;currentPalette&lt;/strong&gt; to another one, for example bamboo beach. 🐼&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%2Fi%2Fen7icrwxisq377yh09ll.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%2Fi%2Fen7icrwxisq377yh09ll.png" alt="Code of the method to change palette"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we now press our blue button we see that value of &lt;strong&gt;currentPalette&lt;/strong&gt; has been changed to 'bambooBeach'. Now we only have to make sure this also changes in the &lt;strong&gt;Styled props&lt;/strong&gt; of the grid!&lt;/p&gt;

&lt;p&gt;This can be done by dynamically binding our value of &lt;strong&gt;currentPalette&lt;/strong&gt; to the &lt;strong&gt;bg&lt;/strong&gt; styled prop.&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%2Fi%2Fapxnguqrl2x3w3qnilfg.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%2Fi%2Fapxnguqrl2x3w3qnilfg.png" alt="Code of the template with dynamic styled prop of the background"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may notice the string concatenation in there, this is added since only the &lt;strong&gt;currentPalette&lt;/strong&gt; is different.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's make the palette picking random for the fun! 🤪
&lt;/h3&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%2Fi%2Fop1rip5mzl4t2jckaext.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%2Fi%2Fop1rip5mzl4t2jckaext.png" alt="Code of with the random number generator"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Firstly we need a list of all our palettes to pick a random palette from. &lt;/p&gt;

&lt;p&gt;Then we need a random number between 0 and the last index of the &lt;strong&gt;paletteList&lt;/strong&gt;, so we can pick a palette at a random index in the array.&lt;/p&gt;

&lt;p&gt;Who wants to see the same palette twice? Not me! 🙅‍♂️ To avoid this we have to add a little check.&lt;/p&gt;

&lt;p&gt;If the random number obtained is less than the &lt;strong&gt;lastRandom&lt;/strong&gt;, it can be used as is. Otherwise it has to be incremented by one, so that the &lt;strong&gt;lastRandom&lt;/strong&gt; has been skipped.&lt;/p&gt;

&lt;p&gt;It's really interesting that it's is possible for any &lt;strong&gt;styled prop&lt;/strong&gt; value that can be set inside the &lt;strong&gt;custom theme&lt;/strong&gt;. So we can make for example our own "black &amp;amp; white" mode.&lt;/p&gt;

&lt;p&gt;Now let's smash that button and have fun! 🎉&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;❤️ Contribute to this blog&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Having any questions, caught a mistake or have tips? Please reach out to me!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>chakraui</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
