hazo_ui 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -11391,6 +11391,67 @@ function EntryRow({ entry, on_select, onDelete }) {
11391
11391
  }
11392
11392
  );
11393
11393
  }
11394
+ var ThemeContext = React26__namespace.createContext(void 0);
11395
+ function HazoThemeProvider({
11396
+ children,
11397
+ defaultTheme = "system",
11398
+ storageKey = "theme"
11399
+ }) {
11400
+ const [theme, setTheme] = useLocalStorage(storageKey, defaultTheme);
11401
+ const prefersDark = useMediaQuery("(prefers-color-scheme: dark)");
11402
+ const resolvedTheme = theme === "system" ? prefersDark ? "dark" : "light" : theme;
11403
+ React26__namespace.useEffect(() => {
11404
+ document.documentElement.classList.toggle("dark", resolvedTheme === "dark");
11405
+ }, [resolvedTheme]);
11406
+ const toggleTheme = React26__namespace.useCallback(() => {
11407
+ setTheme(resolvedTheme === "dark" ? "light" : "dark");
11408
+ }, [resolvedTheme, setTheme]);
11409
+ const value = React26__namespace.useMemo(
11410
+ () => ({ theme, setTheme, resolvedTheme, toggleTheme }),
11411
+ [theme, setTheme, resolvedTheme, toggleTheme]
11412
+ );
11413
+ return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value, children });
11414
+ }
11415
+ function useTheme() {
11416
+ const context = React26__namespace.useContext(ThemeContext);
11417
+ if (context === void 0) {
11418
+ throw new Error("useTheme must be used within a <HazoThemeProvider>");
11419
+ }
11420
+ return context;
11421
+ }
11422
+ function ThemeScript({ storageKey = "theme" }) {
11423
+ const script = `(function(){try{var k=${JSON.stringify(
11424
+ storageKey
11425
+ )};var raw=localStorage.getItem(k);var t="system";if(raw){try{t=JSON.parse(raw);}catch(e){t=String(raw).replace(/^"|"$/g,"");}}var m=window.matchMedia("(prefers-color-scheme: dark)").matches;var isDark=t==="dark"||((t==="system"||!t)&&m);var c=document.documentElement.classList;if(isDark){c.add("dark");}else{c.remove("dark");}}catch(e){}})();`;
11426
+ return /* @__PURE__ */ jsxRuntime.jsx("script", { dangerouslySetInnerHTML: { __html: script } });
11427
+ }
11428
+ var ThemeToggle = React26__namespace.forwardRef(
11429
+ ({ className, ...props }, ref) => {
11430
+ const { resolvedTheme, toggleTheme } = useTheme();
11431
+ const [mounted, setMounted] = React26__namespace.useState(false);
11432
+ React26__namespace.useEffect(() => {
11433
+ setMounted(true);
11434
+ }, []);
11435
+ const isDark = mounted && resolvedTheme === "dark";
11436
+ const label = isDark ? "Switch to light theme" : "Switch to dark theme";
11437
+ return /* @__PURE__ */ jsxRuntime.jsx(
11438
+ "button",
11439
+ {
11440
+ type: "button",
11441
+ ref,
11442
+ onClick: toggleTheme,
11443
+ "aria-label": label,
11444
+ className: cn(
11445
+ "inline-flex h-9 w-9 items-center justify-center rounded-full text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
11446
+ className
11447
+ ),
11448
+ ...props,
11449
+ children: isDark ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sun, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Moon, { className: "h-4 w-4" })
11450
+ }
11451
+ );
11452
+ }
11453
+ );
11454
+ ThemeToggle.displayName = "ThemeToggle";
11394
11455
 
11395
11456
  Object.defineProperty(exports, "rawToast", {
11396
11457
  enumerable: true,
@@ -11464,6 +11525,7 @@ exports.ErrorBanner = ErrorBanner;
11464
11525
  exports.ErrorPage = ErrorPage;
11465
11526
  exports.FunnelChart = FunnelChart;
11466
11527
  exports.HazoContextProvider = HazoContextProvider;
11528
+ exports.HazoThemeProvider = HazoThemeProvider;
11467
11529
  exports.HazoUiConfirmDialog = HazoUiConfirmDialog;
11468
11530
  exports.HazoUiDialog = HazoUiDialog;
11469
11531
  exports.HazoUiDialogClose = DialogClose;
@@ -11553,6 +11615,8 @@ exports.TabsContent = TabsContent;
11553
11615
  exports.TabsList = TabsList;
11554
11616
  exports.TabsTrigger = TabsTrigger;
11555
11617
  exports.Textarea = Textarea;
11618
+ exports.ThemeScript = ThemeScript;
11619
+ exports.ThemeToggle = ThemeToggle;
11556
11620
  exports.Toggle = Toggle;
11557
11621
  exports.ToggleGroup = ToggleGroup;
11558
11622
  exports.ToggleGroupItem = ToggleGroupItem;
@@ -11594,6 +11658,7 @@ exports.useLoadingState = useLoadingState;
11594
11658
  exports.useLocalStorage = useLocalStorage;
11595
11659
  exports.useMediaQuery = useMediaQuery;
11596
11660
  exports.useSessionStorage = useSessionStorage;
11661
+ exports.useTheme = useTheme;
11597
11662
  exports.useViewport = useViewport;
11598
11663
  exports.useWakeLock = useWakeLock;
11599
11664
  exports.use_fullscreen = use_fullscreen;