UNPKG

nextuiq

Version:

NextUIQ is a modern, lightweight, and developer-friendly UI component library for React and Next.js. Built with TypeScript and Tailwind CSS, it offers customizable, accessible, and performance-optimized components with built-in dark mode, theme customizat

2 lines (1 loc) 1.24 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index46.js");function t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const r=t(require("react")),n=r.createContext(void 0);exports.ThemeClient=({children:t,defaultTheme:o="system"})=>{const[s,c]=r.useState((()=>"undefined"!=typeof window&&localStorage.getItem("theme")||o));r.useEffect((()=>{const e=window.matchMedia("(prefers-color-scheme: dark)"),t=()=>{document.body.setAttribute("data-theme","system"===s?e.matches?"dark":"light":s),localStorage.setItem("theme",s)},r=()=>{"system"===s&&t()};return e.addEventListener("change",r),t(),()=>e.removeEventListener("change",r)}),[s]);const a=r.useCallback((()=>{c((e=>{switch(e){case"light":return"dark";case"dark":return"system";default:return"light"}}))}),[]);return e.jsxRuntimeExports.jsx(n.Provider,{value:{theme:s,toggleTheme:a},children:t})},exports.useTheme=()=>{const e=r.useContext(n);if(!e)throw new Error("useTheme must be used within a ThemeProvider");return e};