<?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: leslieSie</title>
    <description>The latest articles on DEV Community by leslieSie (@lesliesie).</description>
    <link>https://dev.to/lesliesie</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%2F913428%2F91c7d743-bd3f-4512-a8ec-a2367e828661.jpeg</url>
      <title>DEV Community: leslieSie</title>
      <link>https://dev.to/lesliesie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lesliesie"/>
    <language>en</language>
    <item>
      <title>Recommend A react Library which make you elegant and quickly to create dark mode on react.js</title>
      <dc:creator>leslieSie</dc:creator>
      <pubDate>Mon, 22 Aug 2022 15:49:00 +0000</pubDate>
      <link>https://dev.to/lesliesie/recommend-a-react-library-which-make-you-elegant-and-quickly-to-create-dark-mode-on-reactjs-2k1g</link>
      <guid>https://dev.to/lesliesie/recommend-a-react-library-which-make-you-elegant-and-quickly-to-create-dark-mode-on-reactjs-2k1g</guid>
      <description>&lt;p&gt;We always have a need,use one button to change your company website or system to dark mode theme.It looks easy to deal with it,but actually not.So today, I recommend the Library called &lt;a href="https://github.com/leslieSie/react-dark-mode-lib/tree/main/src"&gt;react-dark-mode-lib&lt;/a&gt; help you easier to handle it.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why recommand react-dark-mode-lib?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We've concluded that there are three ways to do this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change CSS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;this way is easy to understand, you bind variable on React Dom. change variable let className or styles change.then before, you must comfirm define CSS on global. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'
const App= () =&amp;gt; {
    const [status, setStatus] = useState(false)
    return (
       &amp;lt;&amp;gt;
         &amp;lt;button onClick={ () =&amp;gt; setStatus(!status) }&amp;gt;Change color&amp;lt;/button&amp;gt;
         &amp;lt;div className={ status ? 'activeBgColor': 'normalBgColor' }&amp;gt;test&amp;lt;/div&amp;gt;
       &amp;lt;/&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;  &lt;span class="nc"&gt;.activeBgColor&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="no"&gt;black&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;normalBgColor&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="no"&gt;white&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is obvious,you need to maintain multi-css.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Use CSS3 filter
add the follow CSS will deal the problem.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&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;filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;invert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;hue-rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;180deg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;brightness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;115%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;contrast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;95%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this way not allow you custom special element css&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Use CSS3 mix-blend-mode &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;this way can do it,but &lt;em&gt;&lt;strong&gt;github no found a library handle elegant and quickly on react&lt;/strong&gt;&lt;/em&gt;. The reason is why &lt;a href="https://github.com/leslieSie/react-dark-mode-lib"&gt;create react-dark-mode-lib&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to Use&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;First, you should use npm/yarn tool install the library&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="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;dark&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;lib&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then the simplest use is direct import library. For example:&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;DarkMode&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;react-dark-mode-lib&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setVisible&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DarkMode&lt;/span&gt; &lt;span class="nx"&gt;visible&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The biggest feature is that allow use JSX to created any element on dark mode Layer. you can run the example to know more.&lt;/p&gt;

&lt;p&gt;If you have issues and suggestion,called me on github.If help your work,Please give a star on github to me.Thank you.&lt;/p&gt;

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