<?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: Giorgos Tsiftsis</title>
    <description>The latest articles on DEV Community by Giorgos Tsiftsis (@chief).</description>
    <link>https://dev.to/chief</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%2F353977%2Fea32bb6c-76e0-44bf-9be0-71f2c629685b.jpg</url>
      <title>DEV Community: Giorgos Tsiftsis</title>
      <link>https://dev.to/chief</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chief"/>
    <language>en</language>
    <item>
      <title>The process of upgrading gems</title>
      <dc:creator>Giorgos Tsiftsis</dc:creator>
      <pubDate>Sat, 27 Jun 2020 14:48:28 +0000</pubDate>
      <link>https://dev.to/chief/the-process-of-upgrading-gems-1073</link>
      <guid>https://dev.to/chief/the-process-of-upgrading-gems-1073</guid>
      <description>&lt;p&gt;Through the years, I have contributed to various Rails projects, from huge Rails apps like &lt;a href="https://skroutz.gr"&gt;Skroutz.gr&lt;/a&gt; to fresh Rails 6 projects like &lt;a href="https://tefter.io"&gt;Tefter.io&lt;/a&gt; and I have come to the following rules regarding Ruby gems and their upgrade process.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Let &lt;a href="https://bundler.io/"&gt;Bundler&lt;/a&gt; do its job. Do not use specific versions unless it is really needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you want to set a specific version, be pessimistic. Use the &lt;a href="https://thoughtbot.com/blog/rubys-pessimistic-operator"&gt;twiddle-waka&lt;/a&gt; operator. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do not host forked gems. Prefer to create PRs. If it is absolutely necessary to do this, set a goal to release your work to the public soon.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Be patient when new gem versions are released, except for security updates. Choose monthly or bi-monthly periods for updates and stick with them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use tools like Github's Dependabot alerts and protect your code as fast as possible. Better safe than sorry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do not update your gems blindly. Use tools like &lt;a href="https://github.com/teeparham/gemdiff"&gt;gemdiff&lt;/a&gt; to inspect the changes or at least the commit messages. Try to get an idea of what changes will be introduced to your repo.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>gems</category>
    </item>
    <item>
      <title>Migrate an existing app to Turbolinks</title>
      <dc:creator>Giorgos Tsiftsis</dc:creator>
      <pubDate>Fri, 08 May 2020 21:00:38 +0000</pubDate>
      <link>https://dev.to/chief/migrate-an-existing-app-to-turbolinks-4md3</link>
      <guid>https://dev.to/chief/migrate-an-existing-app-to-turbolinks-4md3</guid>
      <description>&lt;p&gt;A few months ago we decided at &lt;a href="https://tefter.io" rel="noopener noreferrer"&gt;Tefter&lt;/a&gt; to use Turbolinks with our main Ruby on Rails app, so we can take advantage of its features for better SPA look &amp;amp; feel and faster page loading - at least from the user perspective. Back then we had some Javascript files and we relied heavily on jQuery.&lt;/p&gt;

&lt;h2&gt;
  
  
  About Tefter
&lt;/h2&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%2Ftefter.io%2Ftefter.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%2Ftefter.io%2Ftefter.png" alt="Tefter logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before going into more detail about the specifics of the migration, let's talk about Tefter first. It's a tool aiming to optimize your web surfing routine, a combination of personal search-engine, a social bookmarking tool, and a place to archive stuff to read later and write notes. One would interact with Tefter through the &lt;a href="https://tefter.io/" rel="noopener noreferrer"&gt;Web app&lt;/a&gt;, &lt;a href="https://chrome.google.com/webstore/detail/tefter/eldofalegbgagpenjjcapjaogpioldoh" rel="noopener noreferrer"&gt;the browser extension&lt;/a&gt;, the &lt;a href="https://twitter.com/Tefter_io/status/1106145149019742210" rel="noopener noreferrer"&gt;mobile&lt;/a&gt;, and the &lt;a href="https://github.com/tefter/desktop" rel="noopener noreferrer"&gt;desktop apps&lt;/a&gt; or &lt;a href="https://slack.com/apps/AFBC4A147-tefter" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;The main &lt;a href="https://github.com/turbolinks/turbolinks" rel="noopener noreferrer"&gt;repo&lt;/a&gt; has a ton of documentation that explains everything. Also, &lt;a href="https://www.honeybadger.io/blog/turbolinks/" rel="noopener noreferrer"&gt;this&lt;/a&gt; post from the Hobeybadger team help us a lot at the beginning of the migration.&lt;/p&gt;

&lt;p&gt;In our &lt;code&gt;Gemfile&lt;/code&gt; we added:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'turbolinks'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And installed it with Yarn:&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 turbolinks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in our &lt;code&gt;packs/application.js&lt;/code&gt; file we import and start Turbolinks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Turbolinks&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;turbolinks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;Turbolinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Migration
&lt;/h2&gt;

&lt;p&gt;The steps we did for migration to work were the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We changed all &lt;code&gt;document.ready&lt;/code&gt; with &lt;code&gt;turbolinks:load&lt;/code&gt; events.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Old&lt;/span&gt;
&lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&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="c1"&gt;// New&lt;/span&gt;
&lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;turbolinks:load&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&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;ul&gt;
&lt;li&gt;&lt;p&gt;And all &lt;code&gt;DOMContentLoaded&lt;/code&gt; events with &lt;code&gt;turbolinks:load&lt;/code&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We moved all logic from &lt;code&gt;window.onload&lt;/code&gt; events to &lt;code&gt;turbolinks:load&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We did the same with &lt;code&gt;window.resize&lt;/code&gt; events.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We made sure to clear Turbolinks cache before ajax requests&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Clear Turbolinks cache before ajax requests&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ajax:before [data-remote]&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Turbolinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clearCache&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;ul&gt;
&lt;li&gt;&lt;p&gt;We disabled Turbolinks for Facebook, Google, Slack, and Github omni-oauth sign up pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We disabled Turbolinks from other 3rd parties calls like Pocket authorization and Slack installation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We noticed that we had problems with rendering some Javascript components like modals or tooltips (we use for example &lt;a href="https://micromodal.now.sh/" rel="noopener noreferrer"&gt;Micromodal&lt;/a&gt; and &lt;a href="https://github.com/atomiks/tippyjs" rel="noopener noreferrer"&gt;tippy&lt;/a&gt;). For those cases, we explicitly opted out from Turbolinks:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"modal"&lt;/span&gt; &lt;span class="na"&gt;data-turbolinks=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= link_to '#', class: 'tippy', data: { turbolinks: false } do %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We experienced some rendering issues with views with different layouts. We should investigate these issues further but because there was only a simple case (our Readable view) we decided to opt out Turbolinks from it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We had some hard times dealing with event listeners loaded inside &lt;code&gt;turbolinks:load&lt;/code&gt; functions. We ended up using &lt;a href="https://stimulusjs.org/" rel="noopener noreferrer"&gt;Stimulus&lt;/a&gt; and handle them inside &lt;code&gt;connect()&lt;/code&gt; functions &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In one case we wanted to make an ajax call and we discovered that we should add the security token.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;someUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;beforeSend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
                     &lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequestHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;X-CSRF-Token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                     &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;meta[name="csrf-token"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We found some inconsistencies when we use &lt;code&gt;turbolinks:onload&lt;/code&gt; and async javascript loading. We switched to &lt;code&gt;defer&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Feelings
&lt;/h2&gt;

&lt;p&gt;We have a small JavaScript codebase but the overall migration and bug fixing took us some time mainly due to our inexperiences with the Turbolinks architecture and its expectations. Overall the sign is positive. If you have an existing codebase be patient, there will be plenty of small bugs. Fortunately, one should get quickly familiar with solving them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you should consider next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stimulusjs.org/" rel="noopener noreferrer"&gt;StimulusJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.tefter.io/chief/lists/turbolinks" rel="noopener noreferrer"&gt;My Tefter list for Turbolinks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.tefter.io/chief/lists/stimulusjs" rel="noopener noreferrer"&gt;My Tefter list for StimulusJS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>turbolinks</category>
      <category>javascript</category>
      <category>rails</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Dealing with hex colors</title>
      <dc:creator>Giorgos Tsiftsis</dc:creator>
      <pubDate>Tue, 21 Apr 2020 11:24:56 +0000</pubDate>
      <link>https://dev.to/chief/dealing-with-hex-colors-464g</link>
      <guid>https://dev.to/chief/dealing-with-hex-colors-464g</guid>
      <description>&lt;p&gt;At &lt;a href="https://tefter.io"&gt;Tefter&lt;/a&gt; we are a small team of two, mainly backend developers. Our &lt;a href="https://twitter.com/VangelTzo"&gt;good friend&lt;/a&gt; built the design of our service and a few months later we ended up with various hex colors here and there without knowing which one to choose for the next element. Of course, we have &lt;a href="https://sass-lang.com/"&gt;Sass&lt;/a&gt; so we started grouping our colors in &lt;a href="https://sass-lang.com/documentation/variables"&gt;variables&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;We decided to name our codes using &lt;a href="https://www.colorhexa.com/"&gt;Colorhexa&lt;/a&gt;. We extracted all colors in a file named &lt;code&gt;themes.scss&lt;/code&gt;, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nv"&gt;$cyan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#5fbec9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// etc&lt;/span&gt;
&lt;span class="c1"&gt;// etc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When we found more than one color with the same name we took the approach of adding an inc number suffix without special order or hierarchy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#474747&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$very-dark-grey2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#666666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After a couple of hours, we ended up with a list of our colors. First of all, we got a better understanding of our color palette. We found some colors that did not fit in our design, for example, we had a vivid blue somewhere in an input focus. From all 77 color variations, the most used are variations of grey and we took the opportunity to reduce some of them.&lt;/p&gt;

&lt;p&gt;The next step was to start working on theming our product. We took a very simple approach. We had the named color variations and we wanted to associate the main components with these colors. So we used a hash map like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nv"&gt;$colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="c1"&gt;// General&lt;/span&gt;
  &lt;span class="na"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$mostly-white&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;hr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$light-greyish-blue3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;

  &lt;span class="c1"&gt;// This is the default link color&lt;/span&gt;
  &lt;span class="na"&gt;link&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$black&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;link-before&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;link-hover&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;link-span&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$dark-grey3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;

  &lt;span class="c1"&gt;// Secondary link element&lt;/span&gt;
  &lt;span class="na"&gt;secondary-link&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;secondary-link-hover&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$very-dark-grey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;...&lt;/span&gt;
  &lt;span class="nc"&gt;...&lt;/span&gt;
  &lt;span class="nc"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We took a simple approach of converting these colors to css variables and providing a simple function to get the right color for each component using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme"&gt;prefers-colors-scheme&lt;/a&gt;. We decided to do this in order to prepare for dark mode theme in the near future. So in the same &lt;code&gt;themes.scss&lt;/code&gt; file we added the following two functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Converts scss variable into css variable&lt;/span&gt;
&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@each&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$color&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$colors&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;--color-&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="nd"&gt;:&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$color&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;--theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'light'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Creates a function to get color instead of using css varible&lt;/span&gt;
&lt;span class="k"&gt;@function&lt;/span&gt; &lt;span class="nf"&gt;getColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color-name&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;@return&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;color-&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$color-name&lt;/span&gt;&lt;span class="si"&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;And all we had to do is for each element that we have in our &lt;code&gt;$colors&lt;/code&gt; map to associate it with the corresponding color. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;getColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;background&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nc"&gt;...&lt;/span&gt;
  &lt;span class="nc"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that we did this only for the main components that have meaning to be part of the theme. This is not always straightforward and we did some back and forths in order to have a balance and a smaller color map to handle. &lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusions
&lt;/h1&gt;

&lt;p&gt;I am not a front-end developer and this was my first try of such CSS refactoring. In the end, we have all our colors in one file, we could start playing with different variations and provide different themes or working on dark theme easier and we could decide immediately which color to experiment with for our next component. &lt;/p&gt;

&lt;p&gt;Maybe in larger codebases, this process will be endless but in smaller ones, it seems to work just fine!&lt;/p&gt;

</description>
      <category>css</category>
      <category>design</category>
      <category>sideprojects</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
