ruler-components 0.1.4 → 0.1.6

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.mjs CHANGED
@@ -3344,6 +3344,70 @@ function Tooltip({
3344
3344
  mounted && tooltipNode ? createPortal3(tooltipNode, document.body) : null
3345
3345
  ] });
3346
3346
  }
3347
+
3348
+ // components/theme-provider.tsx
3349
+ import {
3350
+ createContext as createContext6,
3351
+ useCallback as useCallback3,
3352
+ useContext as useContext6,
3353
+ useEffect as useEffect5,
3354
+ useMemo as useMemo3,
3355
+ useState as useState14
3356
+ } from "react";
3357
+
3358
+ // lib/theme.ts
3359
+ var THEME_COOKIE_KEY = "ruler-ui-theme";
3360
+ var THEME_STORAGE_KEY = "ruler-ui-theme";
3361
+ function applyTheme(theme) {
3362
+ document.documentElement.classList.toggle("dark", theme === "dark");
3363
+ }
3364
+ function persistTheme(theme) {
3365
+ localStorage.setItem(THEME_STORAGE_KEY, theme);
3366
+ document.cookie = `${THEME_COOKIE_KEY}=${theme};path=/;max-age=31536000;SameSite=Lax`;
3367
+ }
3368
+ function readStoredTheme() {
3369
+ const fromStorage = localStorage.getItem(THEME_STORAGE_KEY);
3370
+ if (fromStorage === "light" || fromStorage === "dark") {
3371
+ return fromStorage;
3372
+ }
3373
+ const match = document.cookie.match(
3374
+ new RegExp(`(?:^|; )${THEME_COOKIE_KEY}=([^;]*)`)
3375
+ );
3376
+ if ((match == null ? void 0 : match[1]) === "light" || (match == null ? void 0 : match[1]) === "dark") {
3377
+ return match[1];
3378
+ }
3379
+ return null;
3380
+ }
3381
+
3382
+ // components/theme-provider.tsx
3383
+ import { jsx as jsx28 } from "react/jsx-runtime";
3384
+ var ThemeContext = createContext6(null);
3385
+ function ThemeProvider({
3386
+ children,
3387
+ defaultTheme = "light"
3388
+ }) {
3389
+ const [theme, setThemeState] = useState14(defaultTheme);
3390
+ useEffect5(() => {
3391
+ const stored = readStoredTheme();
3392
+ const resolved = stored != null ? stored : defaultTheme;
3393
+ setThemeState(resolved);
3394
+ applyTheme(resolved);
3395
+ }, [defaultTheme]);
3396
+ const setTheme = useCallback3((nextTheme) => {
3397
+ setThemeState(nextTheme);
3398
+ persistTheme(nextTheme);
3399
+ applyTheme(nextTheme);
3400
+ }, []);
3401
+ const value = useMemo3(() => ({ theme, setTheme }), [theme, setTheme]);
3402
+ return /* @__PURE__ */ jsx28(ThemeContext.Provider, { value, children });
3403
+ }
3404
+ function useTheme() {
3405
+ const context = useContext6(ThemeContext);
3406
+ if (!context) {
3407
+ throw new Error("useTheme must be used within ThemeProvider");
3408
+ }
3409
+ return context;
3410
+ }
3347
3411
  export {
3348
3412
  AILoader,
3349
3413
  Accordion,
@@ -3445,6 +3509,7 @@ export {
3445
3509
  TabsContent,
3446
3510
  TabsList,
3447
3511
  TabsTrigger,
3512
+ ThemeProvider,
3448
3513
  ThreeDots,
3449
3514
  TimelineStepper,
3450
3515
  Tooltip,
@@ -3462,6 +3527,7 @@ export {
3462
3527
  menuVariants,
3463
3528
  modalContentVariants,
3464
3529
  overlayVariants,
3465
- radioControlVariants
3530
+ radioControlVariants,
3531
+ useTheme
3466
3532
  };
3467
3533
  //# sourceMappingURL=index.mjs.map