<?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>Forem: Riflan Ahmed</title>
    <description>The latest articles on Forem by Riflan Ahmed (@riflan0ahmed).</description>
    <link>https://forem.com/riflan0ahmed</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%2F1192437%2Fdae03a7a-9890-4b96-ac23-a4f7948a52b6.jpeg</url>
      <title>Forem: Riflan Ahmed</title>
      <link>https://forem.com/riflan0ahmed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/riflan0ahmed"/>
    <language>en</language>
    <item>
      <title>Applying Dark Mode in Next.js using CSS Variables</title>
      <dc:creator>Riflan Ahmed</dc:creator>
      <pubDate>Sat, 10 Aug 2024 11:34:03 +0000</pubDate>
      <link>https://forem.com/riflan0ahmed/applying-dark-mode-in-nextjs-using-css-variables-1kgn</link>
      <guid>https://forem.com/riflan0ahmed/applying-dark-mode-in-nextjs-using-css-variables-1kgn</guid>
      <description>&lt;p&gt;In today’s web development landscape, offering a dark mode option has become almost essential for a modern user interface. In this article, we’ll explore how to implement a robust dark mode solution in a Next.js project using CSS variables, Tailwind CSS, and some helpful tools and packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS for Utility Classes
&lt;/h2&gt;

&lt;p&gt;First, let’s set up Tailwind CSS in our Next.js project. Tailwind provides a utility-first approach to styling, which can significantly speed up our development process.&lt;/p&gt;

&lt;p&gt;To install Tailwind CSS, run the following commands in your project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, configure your &lt;code&gt;tailwind.config.js&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",

    // Or if using `src` directory:
    "./src/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, configure your &lt;code&gt;globals.css&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Orea Color Generator for Color Palette
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxbi27aaj33bsqc9buc3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxbi27aaj33bsqc9buc3.png" alt="Orea Color Generator for Color Palette" width="800" height="614"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a harmonious color palette for both light and dark modes, we can use the Orea Color Generator. This tool helps in generating a set of colors that work well together and can be easily adapted for different themes.&lt;/p&gt;

&lt;p&gt;Visit the &lt;a href="https://color.oreadigital.com" rel="noopener noreferrer"&gt;Orea Color Generator&lt;/a&gt; and select your base colors. The tool provides a user-friendly interface to create and visualize your color scheme:&lt;/p&gt;

&lt;p&gt;The image above shows the Orea Color Generator interface, where you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose a middle color using the color picker&lt;/li&gt;
&lt;li&gt;View generated colors in various shades&lt;/li&gt;
&lt;li&gt;See a preview of your theme in both light and dark modes&lt;/li&gt;
&lt;li&gt;Copy CSS variables for easy integration into your project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After generating your color palette with the Orea Color Generator, you’ll want to implement these colors in your project. Here’s an example of how you can define your color variables in CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
  /* Initially TailwindCSS bg-opacity */
  --tw-bg-opacity: 1;

  --primary-50: 242, 242, 242;
  --primary-100: 230, 230, 230;
  --primary-200: 204, 204, 204;
  --primary-300: 179, 179, 179;
  --primary-400: 153, 153, 153;
  --primary-500: 128, 128, 128;
  --primary-600: 102, 102, 102;
  --primary-700: 77, 77, 77;
  --primary-800: 51, 51, 51;
  --primary-900: 26, 26, 26;
  --primary-950: 13, 13, 13;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These CSS variables define a range of shades for your primary color, from lighter color ( — primary-50) to dark colors ( — primary-950). By using these variables, you can easily apply consistent colors throughout your application and switch between light and dark modes.&lt;/p&gt;

&lt;p&gt;Now that we have our color variables defined, let’s integrate them into our Tailwind CSS configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  // ... other config
  theme: {
    extend: {
      colors: {
        primary: {
          '50': 'rgba(var(--primary-50), var(--tw-bg-opacity))',
          '100': 'rgba(var(--primary-100), var(--tw-bg-opacity))',
          '200': 'rgba(var(--primary-200), var(--tw-bg-opacity))',
          '300': 'rgba(var(--primary-300), var(--tw-bg-opacity))',
          '400': 'rgba(var(--primary-400), var(--tw-bg-opacity))',
          '500': 'rgba(var(--primary-500), var(--tw-bg-opacity))',
          '600': 'rgba(var(--primary-600), var(--tw-bg-opacity))',
          '700': 'rgba(var(--primary-700), var(--tw-bg-opacity))',
          '800': 'rgba(var(--primary-800), var(--tw-bg-opacity))',
          '900': 'rgba(var(--primary-900), var(--tw-bg-opacity))',
          '950': 'rgba(var(--primary-950), var(--tw-bg-opacity))',
        },
      },
    },
  },
}

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

&lt;/div&gt;



&lt;p&gt;This configuration allows you to use these colors in your Tailwind classes, like &lt;code&gt;bg-primary-500&lt;/code&gt; or &lt;code&gt;text-primary-200&lt;/code&gt;, while still maintaining the ability to apply opacity using Tailwind’s opacity modifiers.&lt;/p&gt;

&lt;h2&gt;
  
  
  next-themes Package for Dark/Light Mode Theme
&lt;/h2&gt;

&lt;p&gt;After installation, we need to set up our basic theme variables. Create a new CSS file (e.g., &lt;code&gt;globals.css&lt;/code&gt;) or add to your existing one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/layout.jsx
:root {
  /* Add your light mode colors */
  --tw-bg-opacity: 1;

  --primary-50: 242, 242, 242;
  --primary-100: 230, 230, 230;
  --primary-200: 204, 204, 204;
  --primary-300: 179, 179, 179;
}

[data-theme='dark'] {

/* Add your dark mode colors */
  --primary-50: 13, 13, 13;
  --primary-100: 26, 26, 26;
  --primary-200: 51, 51, 51;
  --primary-300: 77, 77, 77;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This CSS defines basic color variables for light and dark themes. The &lt;code&gt;[data-theme=’dark’]&lt;/code&gt; selector will be automatically applied by next-themes when the dark mode is active.&lt;/p&gt;

&lt;p&gt;Now, let’s implement the ThemeProvider in your &lt;code&gt;layout.tsx&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/layout.jsx

"use client";

import { ThemeProvider } from 'next-themes'

export default function Layout({ children }) {
  return (
    &amp;lt;html suppressHydrationWarning&amp;gt;
      &amp;lt;head /&amp;gt;
      &amp;lt;body&amp;gt;
        &amp;lt;ThemeProvider&amp;gt;{children}&amp;lt;/ThemeProvider&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your components, you can now use the &lt;code&gt;useTheme&lt;/code&gt; hook to access and change the current theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";

import { useTheme } from 'next-themes'

const ThemeChanger = () =&amp;gt; {
  const { theme, setTheme } = useTheme()

  return (
    &amp;lt;div&amp;gt;
      The current theme is: {theme}
      &amp;lt;button onClick={() =&amp;gt; setTheme('light')}&amp;gt;Light Mode&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setTheme('dark')}&amp;gt;Dark Mode&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default ThemeChanger
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This setup allows for a smooth transition between light and dark modes, with the theme being persisted across page reloads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dropdown for Theme Toggle using shadcn/ui
&lt;/h2&gt;

&lt;p&gt;For a more polished UI, we can use the dropdown component from shadcn/ui to create a theme toggle. First, install the necessary components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx shadcn-ui@latest add dropdown-menu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s implement our theme toggle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useTheme } from "next-themes"
import { Button } from "@/components/ui/button"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Sun, Moon } from "lucide-react"

export function ThemeToggle() {
  const { setTheme } = useTheme()

  return (
    &amp;lt;DropdownMenu&amp;gt;
      &amp;lt;DropdownMenuTrigger asChild&amp;gt;
        &amp;lt;Button variant="outline" size="icon"&amp;gt;
          &amp;lt;Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" /&amp;gt;
          &amp;lt;Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" /&amp;gt;
          &amp;lt;span className="sr-only"&amp;gt;Toggle theme&amp;lt;/span&amp;gt;
        &amp;lt;/Button&amp;gt;
      &amp;lt;/DropdownMenuTrigger&amp;gt;
      &amp;lt;DropdownMenuContent align="end"&amp;gt;
        &amp;lt;DropdownMenuItem onClick={() =&amp;gt; setTheme("light")}&amp;gt;
          Light
        &amp;lt;/DropdownMenuItem&amp;gt;
        &amp;lt;DropdownMenuItem onClick={() =&amp;gt; setTheme("dark")}&amp;gt;
          Dark
        &amp;lt;/DropdownMenuItem&amp;gt;
        &amp;lt;DropdownMenuItem onClick={() =&amp;gt; setTheme("system")}&amp;gt;
          System
        &amp;lt;/DropdownMenuItem&amp;gt;
      &amp;lt;/DropdownMenuContent&amp;gt;
    &amp;lt;/DropdownMenu&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This component creates a dropdown menu with options to switch between light, dark, and system themes. The button uses sun and moon icons to visually represent the current theme.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Implementing dark mode in a Next.js application using CSS variables, Tailwind CSS, and next-themes provides a flexible and maintainable solution. Here’s a summary of what we’ve achieved:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We set up Tailwind CSS for utility-first styling.&lt;/li&gt;
&lt;li&gt;We used the Orea Color Generator to create a consistent color palette for both light and dark modes.&lt;/li&gt;
&lt;li&gt;We implemented theme switching using next-themes, allowing for easy toggling between light and dark modes.&lt;/li&gt;
&lt;li&gt;We created a polished theme toggle component using shadcn/ui, enhancing the user experience.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By leveraging CSS variables, we’ve created a system that’s easy to maintain and extend. The use of next-themes ensures that our theme preference is persisted, providing a seamless experience for users.&lt;/p&gt;

&lt;p&gt;Remember these key points when implementing dark mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always consider accessibility and ensure sufficient contrast in both themes.&lt;/li&gt;
&lt;li&gt;Test your application thoroughly in both light and dark modes.&lt;/li&gt;
&lt;li&gt;Consider using prefers-color-scheme media query to respect the user’s system preferences.&lt;/li&gt;
&lt;li&gt;Be consistent with your theming across all components and pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this setup, you’re well-equipped to provide a modern, user-friendly dark mode option in your Next.js application. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>css</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Orea Color Generator: The Ultimate Tool for Crafting Stunning Palettes</title>
      <dc:creator>Riflan Ahmed</dc:creator>
      <pubDate>Sun, 04 Aug 2024 05:02:28 +0000</pubDate>
      <link>https://forem.com/riflan0ahmed/orea-color-generator-the-ultimate-tool-for-crafting-stunning-palettes-1idc</link>
      <guid>https://forem.com/riflan0ahmed/orea-color-generator-the-ultimate-tool-for-crafting-stunning-palettes-1idc</guid>
      <description>&lt;p&gt;As a web designer or developer, you understand the crucial role color plays in creating captivating and engaging digital experiences. A well-crafted color palette can make the difference between a forgettable website and one that leaves a lasting impression. But let’s face it, creating the perfect color scheme can be a time-consuming and frustrating process. That’s where the Orea Color Generator comes in to save the day!&lt;br&gt;
&lt;a href="https://color.oreadigital.com" rel="noopener noreferrer"&gt;https://color.oreadigital.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Effortless Color Palette Creation&lt;/strong&gt;&lt;br&gt;
With the Orea Color Generator, crafting stunning color palettes has never been easier. Simply input your desired base color, and let the tool work its magic. It intelligently generates a range of lighter and darker shades that perfectly complement your chosen hue, taking the guesswork out of color harmony. Say goodbye to hours spent tweaking color values and hello to effortless palette creation!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unparalleled Customization Options&lt;/strong&gt;&lt;br&gt;
While the generated color palette is already impressive, the Orea Color Generator takes customization to the next level. Using the intuitive color picker, you can fine-tune each shade to perfection, ensuring your palette aligns perfectly with your vision. And when you’re ready to implement your colors, simply copy the provided CSS variables or select from a variety of color formats. You can even rename the variables for enhanced code readability and maintainability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Accessibility and Privacy at the Forefront&lt;/strong&gt;&lt;br&gt;
One of the standout features of the Orea Color Generator is its commitment to accessibility and user privacy. This powerful tool is entirely free to use, and unlike many other online tools, it doesn’t collect any user data. You can focus on creating stunning color schemes without worrying about your information being compromised. Moreover, the Orea Color Generator is a Progressive Web App (PWA), allowing you to download it and use it offline on any device, anytime, anywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elevate Your Designs with Orea&lt;/strong&gt;&lt;br&gt;
Whether you’re a seasoned design professional or just starting your web design journey, the Orea Color Generator is an indispensable tool that will elevate your color palette game. Its simplicity, powerful features, and accessibility make it a must-have in any designer’s toolkit. So why waste another minute struggling with color schemes? Head over to the Orea Color Generator today and unlock a world of vibrant possibilities for your next project!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In the ever-evolving world of web design, having the right tools at your disposal can make all the difference. The Orea Color Generator is a shining example of how technology can simplify and enhance the creative process. By harnessing the power of this innovative tool, you can take your color palette creation to new heights and create digital experiences that captivate and inspire. Embrace the future of color design with the Orea Color Generator and witness the transformative impact it will have on your projects. Start creating today and let your colors tell a story like never before!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>css</category>
      <category>uiux</category>
    </item>
  </channel>
</rss>
