<?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: Emerald RLM</title>
    <description>The latest articles on DEV Community by Emerald RLM (@oyegokepraise).</description>
    <link>https://dev.to/oyegokepraise</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%2F614849%2Fd33adc72-1737-43a4-88be-ffc293ea04aa.png</url>
      <title>DEV Community: Emerald RLM</title>
      <link>https://dev.to/oyegokepraise</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oyegokepraise"/>
    <language>en</language>
    <item>
      <title>The Right Way for Web Apps Theming. Dark-mode, light-mode, system and many more.</title>
      <dc:creator>Emerald RLM</dc:creator>
      <pubDate>Mon, 21 Jun 2021 08:46:18 +0000</pubDate>
      <link>https://dev.to/oyegokepraise/the-right-way-for-web-apps-theming-dark-mode-light-mode-system-and-many-more-4mb</link>
      <guid>https://dev.to/oyegokepraise/the-right-way-for-web-apps-theming-dark-mode-light-mode-system-and-many-more-4mb</guid>
      <description>&lt;p&gt;Recently I experimented with creating themes for my web apps and found many ways to create themes but there was conflict in the execution due to over-rides, so I will run with you through how I solved the issue.&lt;/p&gt;

&lt;h4&gt;
  
  
  So we will cover:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;How to create themes.&lt;/li&gt;
&lt;li&gt;The conflict between theming methods.&lt;/li&gt;
&lt;li&gt;Resolving the conflict.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to create themes
&lt;/h3&gt;

&lt;p&gt;There are three ways to create themes&lt;br&gt;
1.&lt;strong&gt;Using css variables&lt;/strong&gt;: Using both CSS and JavaScript, you define the variables in a parent element and using JavaScript call a function that changes the variable values, it can be reverted by calling a function that does the opposite of the previous function.&lt;br&gt;
2.&lt;strong&gt;Using additional classes&lt;/strong&gt;: Using JavaScript and CSS, you get the parent element and add a class containing the values you want to change and it can also be reverted using another function by removing the class.&lt;br&gt;
3.&lt;strong&gt;Using media queries&lt;/strong&gt;: Using CSS&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="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-color-scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
, you can check mozzila documents to learn more, but what it does is update the elements styles according to the user's operating systems theme;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Theme Conflict
&lt;/h3&gt;

&lt;p&gt;I was learning to use styled-components with next.js so I had both the media queries theme and was using the theme provider to update the theme, I was going for my user's having three themes to choose from i.e light, dark and system but when the user's system was in dark-mode the media query theme clashed with my themes from the theme provider.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resolving the Conflict:
&lt;/h3&gt;

&lt;p&gt;I had to create a new .css file with a .dark class containing the styles I wanted to apply, so whether in dark-mode or light mode the class added takes precedence over&lt;br&gt;
the other theming methods,&lt;br&gt;
&lt;strong&gt;To summarize the order of precedence of theming methods is&lt;/strong&gt; :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Class method&lt;/li&gt;
&lt;li&gt;Media query method&lt;/li&gt;
&lt;li&gt;Themes from theme provider (using styled-components)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Extra:
&lt;/h3&gt;

&lt;p&gt;Remember to save your client's last theme to the local storage or something to prevent bad UX and achieve consistent theme even on reloads.&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>html</category>
      <category>themes</category>
    </item>
  </channel>
</rss>
