|
| 1 | +import { jsx, jsxs } from "react/jsx-runtime"; |
| 2 | +import { Head } from "@inertiajs/react"; |
| 3 | +import { useState, useEffect } from "react"; |
| 4 | +import { c as cn } from "./app-logo-icon-CoogQ1E6.js"; |
| 5 | +import { Sun, Moon, Monitor } from "lucide-react"; |
| 6 | +import { S as SettingsLayout, H as HeadingSmall } from "./layout-jPnBvemX.js"; |
| 7 | +import { A as AppLayout } from "./app-layout-D4gdSMSC.js"; |
| 8 | +import "@radix-ui/react-slot"; |
| 9 | +import "class-variance-authority"; |
| 10 | +import "clsx"; |
| 11 | +import "tailwind-merge"; |
| 12 | +import "@radix-ui/react-separator"; |
| 13 | +import "@radix-ui/react-dialog"; |
| 14 | +import "@radix-ui/react-tooltip"; |
| 15 | +import "@radix-ui/react-dropdown-menu"; |
| 16 | +import "@radix-ui/react-avatar"; |
| 17 | +const prefersDark = () => { |
| 18 | + if (typeof window === "undefined") { |
| 19 | + return false; |
| 20 | + } |
| 21 | + return window.matchMedia("(prefers-color-scheme: dark)").matches; |
| 22 | +}; |
| 23 | +const applyTheme = (appearance) => { |
| 24 | + const isDark = appearance === "dark" || appearance === "system" && prefersDark(); |
| 25 | + document.documentElement.classList.toggle("dark", isDark); |
| 26 | +}; |
| 27 | +const mediaQuery = () => { |
| 28 | + if (typeof window === "undefined") { |
| 29 | + return null; |
| 30 | + } |
| 31 | + return window.matchMedia("(prefers-color-scheme: dark)"); |
| 32 | +}; |
| 33 | +const handleSystemThemeChange = () => { |
| 34 | + const currentAppearance = localStorage.getItem("appearance"); |
| 35 | + applyTheme(currentAppearance || "system"); |
| 36 | +}; |
| 37 | +function useAppearance() { |
| 38 | + const [appearance, setAppearance] = useState("system"); |
| 39 | + const updateAppearance = (mode) => { |
| 40 | + setAppearance(mode); |
| 41 | + localStorage.setItem("appearance", mode); |
| 42 | + applyTheme(mode); |
| 43 | + }; |
| 44 | + useEffect(() => { |
| 45 | + const savedAppearance = localStorage.getItem("appearance"); |
| 46 | + updateAppearance(savedAppearance || "system"); |
| 47 | + return () => { |
| 48 | + var _a; |
| 49 | + return (_a = mediaQuery()) == null ? void 0 : _a.removeEventListener("change", handleSystemThemeChange); |
| 50 | + }; |
| 51 | + }, []); |
| 52 | + return { appearance, updateAppearance }; |
| 53 | +} |
| 54 | +function AppearanceToggleTab({ className = "", ...props }) { |
| 55 | + const { appearance, updateAppearance } = useAppearance(); |
| 56 | + const tabs = [ |
| 57 | + { value: "light", icon: Sun, label: "Light" }, |
| 58 | + { value: "dark", icon: Moon, label: "Dark" }, |
| 59 | + { value: "system", icon: Monitor, label: "System" } |
| 60 | + ]; |
| 61 | + return /* @__PURE__ */ jsx("div", { className: cn("inline-flex gap-1 rounded-lg bg-neutral-100 p-1 dark:bg-neutral-800", className), ...props, children: tabs.map(({ value, icon: Icon, label }) => /* @__PURE__ */ jsxs( |
| 62 | + "button", |
| 63 | + { |
| 64 | + onClick: () => updateAppearance(value), |
| 65 | + className: cn( |
| 66 | + "flex items-center rounded-md px-3.5 py-1.5 transition-colors", |
| 67 | + appearance === value ? "bg-white shadow-xs dark:bg-neutral-700 dark:text-neutral-100" : "text-neutral-500 hover:bg-neutral-200/60 hover:text-black dark:text-neutral-400 dark:hover:bg-neutral-700/60" |
| 68 | + ), |
| 69 | + children: [ |
| 70 | + /* @__PURE__ */ jsx(Icon, { className: "-ml-1 h-4 w-4" }), |
| 71 | + /* @__PURE__ */ jsx("span", { className: "ml-1.5 text-sm", children: label }) |
| 72 | + ] |
| 73 | + }, |
| 74 | + value |
| 75 | + )) }); |
| 76 | +} |
| 77 | +const breadcrumbs = [ |
| 78 | + { |
| 79 | + title: "Appearance settings", |
| 80 | + href: "/settings/appearance" |
| 81 | + } |
| 82 | +]; |
| 83 | +function Appearance() { |
| 84 | + return /* @__PURE__ */ jsxs(AppLayout, { breadcrumbs, children: [ |
| 85 | + /* @__PURE__ */ jsx(Head, { title: "Appearance settings" }), |
| 86 | + /* @__PURE__ */ jsx(SettingsLayout, { children: /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [ |
| 87 | + /* @__PURE__ */ jsx(HeadingSmall, { title: "Appearance settings", description: "Update your account's appearance settings" }), |
| 88 | + /* @__PURE__ */ jsx(AppearanceToggleTab, {}) |
| 89 | + ] }) }) |
| 90 | + ] }); |
| 91 | +} |
| 92 | +export { |
| 93 | + Appearance as default |
| 94 | +}; |
0 commit comments