@premieroctet/next-admin
Version:
Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje
49 lines (48 loc) • 1.66 kB
JavaScript
"use client";
import { jsx } from "react/jsx-runtime";
import { ComputerDesktopIcon, MoonIcon, SunIcon } from "@heroicons/react/24/outline";
import { useTheme } from "next-themes";
import { createContext, useContext, useEffect, useState } from "react";
import { colorSchemes } from "../types.mjs";
const basicColorSchemeIcons = {
light: /*#__PURE__*/ jsx(SunIcon, {
className: "h-4 w-4"
}),
dark: /*#__PURE__*/ jsx(MoonIcon, {
className: "h-4 w-4"
}),
system: /*#__PURE__*/ jsx(ComputerDesktopIcon, {
className: "h-4 w-4"
})
};
const ColorSchemeContext = /*#__PURE__*/ createContext({
colorScheme: "system",
colorSchemeIcon: void 0,
setColorScheme: ()=>{},
toggleColorScheme: ()=>{}
});
const ColorSchemeProvider = ({ children })=>{
const { theme: colorScheme, setTheme: setColorScheme } = useTheme();
const [colorSchemeIcon, setColorSchemeIcon] = useState(()=>basicColorSchemeIcons[colorScheme]);
useEffect(()=>{
setColorSchemeIcon(basicColorSchemeIcons[colorScheme]);
}, [
colorScheme
]);
const toggleColorScheme = ()=>{
const index = colorSchemes.indexOf(colorScheme);
const nextIndex = (index + 1) % colorSchemes.length;
setColorScheme(colorSchemes[nextIndex]);
};
return /*#__PURE__*/ jsx(ColorSchemeContext.Provider, {
value: {
colorScheme: colorScheme,
colorSchemeIcon,
setColorScheme,
toggleColorScheme
},
children: children
});
};
const useColorScheme = ()=>useContext(ColorSchemeContext);
export { ColorSchemeProvider, useColorScheme };