<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>CSS on Aditya Naik | Personal Website</title>
    <link>https://d6cbd428.hugo-blog-e6x.pages.dev/tags/css/</link>
    <description>Recent content in CSS on Aditya Naik | Personal Website</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 12 Dec 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://d6cbd428.hugo-blog-e6x.pages.dev/tags/css/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Material UI | How to easily setup popup notifications</title>
      <link>https://d6cbd428.hugo-blog-e6x.pages.dev/blog/2021/12/12/material-ui-how-to-easily-setup-popup-notifications/</link>
      <pubDate>Sun, 12 Dec 2021 00:00:00 +0000</pubDate>
      <guid>https://d6cbd428.hugo-blog-e6x.pages.dev/blog/2021/12/12/material-ui-how-to-easily-setup-popup-notifications/</guid>
      <description>&lt;p&gt;Using Material UI and React Context to set up global notification system.&lt;/p&gt;&#xA;&lt;h2 id=&#34;need-for-global-notification-system&#34;&gt;Need for global notification system&lt;/h2&gt;&#xA;&lt;p&gt;In your application, you want have good user experience and let the user know if the actions/clicks have resulted in success or failure. We should also show warning and information messages to guide user through the flows.&lt;/p&gt;&#xA;&lt;p&gt;It is of course possible to display a local popup component wherever needed, but it quickly becomes a bloat and irritating to manage. It would be really cool to just set up the whole system once and trigger it from wherever from the app to get consistent experience.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Material UI | How to easily set up dark theme toggle in React</title>
      <link>https://d6cbd428.hugo-blog-e6x.pages.dev/blog/2020/05/20/material-ui-how-to-easily-set-up-dark-theme-toggle-in-react/</link>
      <pubDate>Wed, 20 May 2020 00:00:00 +0000</pubDate>
      <guid>https://d6cbd428.hugo-blog-e6x.pages.dev/blog/2020/05/20/material-ui-how-to-easily-set-up-dark-theme-toggle-in-react/</guid>
      <description>&lt;h3 id=&#34;scaffold-react-application&#34;&gt;Scaffold React Application&lt;/h3&gt;&#xA;&lt;p&gt;A new react app is easily scaffolded using&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-bash&#34; &gt;&lt;code&gt;npx create-react-app my-app&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;install-dependencies&#34;&gt;Install dependencies&lt;/h3&gt;&#xA;&lt;p&gt;I need to install material ui &lt;code&gt;core&lt;/code&gt; package.&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-bash&#34; &gt;&lt;code&gt;// with npm&#xA;$ npm install @material-ui/core&#xA;&#xA;// with yarn&#xA;$ yarn add @material-ui/core&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;wrap-application-in-theme-provider&#34;&gt;Wrap application in Theme Provider&lt;/h3&gt;&#xA;&lt;p&gt;For the purpose of this demo, I will use &lt;code&gt;App.js&lt;/code&gt; to set up everything.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Add &lt;strong&gt;Light&lt;/strong&gt; and &lt;strong&gt;Dark&lt;/strong&gt; themes&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-js&#34; &gt;&lt;code&gt;export const light = {&#xA;  palette: {&#xA;    type: &#34;light&#34;,&#xA;  },&#xA;};&#xA;export const dark = {&#xA;  palette: {&#xA;    type: &#34;dark&#34;,&#xA;  },&#xA;};&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;Import &lt;code&gt;ThemeProvider&lt;/code&gt; and &lt;code&gt;createMuiTheme&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-js&#34; &gt;&lt;code&gt;import { ThemeProvider } from &#34;@material-ui/core&#34;;&#xA;import { createMuiTheme } from &#34;@material-ui/core/styles&#34;;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;ol start=&#34;3&#34;&gt;&#xA;&lt;li&gt;Set up the toggle logic&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-js&#34; &gt;&lt;code&gt;const [theme, setTheme] = useState(true);&#xA;const icon = !theme ? &lt;Brightness7Icon /&gt; : &lt;Brightness3Icon /&gt;; // Icons imported from `@material-ui/icons`&#xA;const appliedTheme = createMuiTheme(theme ? light : dark);&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;ol start=&#34;4&#34;&gt;&#xA;&lt;li&gt;Wrap the render inside &lt;code&gt;ThemeProvider&lt;/code&gt; and pass the &lt;code&gt;appliedTheme&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-js&#34; &gt;&lt;code&gt;return &lt;ThemeProvider theme={appliedTheme}&gt;//rest of the code&lt;/ThemeProvider&gt;;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;ol start=&#34;5&#34;&gt;&#xA;&lt;li&gt;Trigger toggle using &lt;code&gt;onClick&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;figure class=&#34;highlight&#34;&gt;&#xA;  &#xA;  &lt;pre class=&#34;language-js&#34; &gt;&lt;code&gt;onClick={() =&gt; setTheme(!theme)}&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;Now our theme toggle logic is in place.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
