import { createContext, useContext, useLayoutEffect, useState, type ReactNode } from "react"; import { Button } from "@/components/ui/button"; import { FlyoutAppearanceProvider } from "@/components/ui/flyout"; import { AvatarInitialProvider } from "@/components/ui/avatar-initials"; const storageKey = "paperclip.design-proposals.sandbox"; const DesignSandboxContext = createContext(false); export function useDesignSandbox() { return useContext(DesignSandboxContext); } /** Local integration experiment. Neither production builds nor ordinary dev * instances enable this through browser storage alone. */ export function DesignSandboxProvider({ children }: { children: ReactNode }) { const available = import.meta.env.DEV && import.meta.env.VITE_PAPERCLIP_DESIGN_SANDBOX === "true"; const [selected, setSelected] = useState(() => { try { return localStorage.getItem(storageKey) !== "off"; } catch { return true; } }); const enabled = available && selected; useLayoutEffect(() => { if (!enabled) return; // Use the exact Storybook proposal marker, including its document-wide // token propagation to portals. Broad propagation is intentional here. const hadMarker = document.body.classList.contains("design-proposal-theme"); document.body.classList.add("design-proposal-theme"); return () => { if (!hadMarker) document.body.classList.remove("design-proposal-theme"); }; }, [enabled]); return {children} {available ?
: null}
; }