Skip to content

ayoolaao/daisy-theme

Repository files navigation

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

  • Install Daisy UI
  • Add custom themes in src/app/globals.css
    • Can generate DaisyUI themes Here
  • Create util functions to get and set theme as cookies
    • check here 👉🏾src/utils/theme.ts
  • Add HTML data-theme attribute in root layout *
    • Use getThemeCookie() from src/utils/theme.ts to get current theme
    • src/app/layout.tsx
      • theme() - Line 24 -ish
      • <html lang="en" data-theme={ currentTheme }> - Line 35 -ish
  • Create component to update appearance and change theme
    • <AppearanceSettings /> in this case.
    • See 👉🏾 src/components/appearanceSettings
  • Import and use <AppearanceSettings />
    • src/app/page.tsx in this case.

Notes

  • blurElementOnClick() in src/components/appearanceSettings/AppearanceSettings.tsx helps to dismiss DaisyUI's Dropdown onClick
  • Can also add logic to update to appropriate appearance (Light / Dark) on theme change
  • Improvement and optimization comments are always welcomed

About

Daisy-UI - Next.JS theme and appearance selector using Cookies

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors