UNPKG

react18-themes

Version:

Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.

2 lines (1 loc) 810 B
import{b as g,c as v}from"./chunk-OAYIFZXE.mjs";import{b as S,c as n,d as h}from"./chunk-QW5I2FBF.mjs";import{useEffect as C}from"react";var c=[h,n,S],l,k=i=>{let[e,T]=g(i),[f,d]=v(i);C(()=>{l=window.r},[]);let s=o=>r=>T(t=>({...t,[o]:r})),m={theme:e.t,darkTheme:e.d,lightTheme:e.l,colorSchemePref:e.c,systemColorScheme:e.s,resolvedColorScheme:e.c===h||e.c===""?e.s:e.c,resolvedTheme:e.t,setTheme:s("t"),setDarkTheme:s("d"),setLightTheme:s("l"),setThemeSet:({darkTheme:o,lightTheme:r})=>T(t=>({...t,d:o,l:r})),setColorSchemePref:s("c"),toggleColorScheme(o){let r=c.indexOf(e.c),t=c.length;(r===-1||o&&r===t-1)&&(r=0),s("c")(c[(r+1)%t])},setForcedColorScheme:o=>d(r=>({...r,fc:o})),setForcedTheme:o=>d(r=>({...r,f:o}))};if(l){let o=l(e);m.resolvedColorScheme=o[0],m.resolvedTheme=o[1]}return m};export{k as a};