{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glass-panel",
  "title": "Glass Panel",
  "description": "A glass panel that grows out of the button that opens it, its content dropping into place in turn. Parts like shadcn's dialog (GlassPanel, GlassPanelTrigger, GlassPanelContent, GlassPanelTitle, GlassPanelFooter, GlassPanelClose) on a non-modal Base UI dialog: Escape and a press outside close it, focus moves in and back.",
  "dependencies": [
    "@base-ui/react"
  ],
  "files": [
    {
      "path": "registry/mewo/ui/glass-panel.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Dialog as DialogPrimitive } from \"@base-ui/react/dialog\"\nimport { cn } from \"@/lib/utils\"\n\ntype GlassPanelContextValue = {\n  triggerRef: React.RefObject<HTMLElement | null>\n  /** The root's own element: the panel renders into it, beside its trigger. */\n  container: HTMLElement | null\n  /** Whether focus goes back to the trigger when the panel closes. */\n  returnFocusRef: React.RefObject<boolean>\n}\n\nconst GlassPanelContext = React.createContext<GlassPanelContextValue | null>(null)\n\nfunction useGlassPanel() {\n  const context = React.useContext(GlassPanelContext)\n  if (!context) throw new Error(\"GlassPanel parts must be used inside <GlassPanel>\")\n  return context\n}\n\n// The panel's opening runs on a registered number, 0 closed to 1 open, and its clip is worked out from it on every\n// frame. A transition of clip-path itself can be handed to the compositor, which inside a rounded, overflow-clipped\n// box (a demo's frame) draws nothing until it ends, so the panel just appears.\nif (typeof CSS !== \"undefined\" && \"registerProperty\" in CSS) {\n  try {\n    CSS.registerProperty({ name: \"--glass-panel-reveal\", syntax: \"<number>\", inherits: false, initialValue: \"1\" })\n  } catch {}\n}\n\nfunction setRef<T>(ref: React.Ref<T> | undefined, value: T) {\n  if (typeof ref === \"function\") ref(value)\n  else if (ref) ref.current = value\n}\n\n/**\n * A non-modal Base UI dialog: Escape, a press outside or focus leaving closes it. Focus goes back to the trigger\n * only when the panel closed itself (Escape, its close button, its trigger), not when the page closed it to open\n * another panel. Its element takes no space (display: contents) and holds the panel, so a transformed frame that\n * holds the trigger holds the panel too.\n */\nfunction GlassPanel({\n  className,\n  onOpenChange,\n  ...props\n}: Omit<DialogPrimitive.Root.Props, \"modal\"> & { className?: string }) {\n  const [container, setContainer] = React.useState<HTMLDivElement | null>(null)\n  const triggerRef = React.useRef<HTMLElement>(null)\n  const returnFocusRef = React.useRef(false)\n  const value = React.useMemo(() => ({ triggerRef, container, returnFocusRef }), [container])\n  return (\n    <GlassPanelContext.Provider value={value}>\n      <div ref={setContainer} data-slot=\"glass-panel\" className={cn(\"[--story-u:min(2.6667cqw,12px)] min-[901px]:[--story-u:0.625cqw] min-[901px]:@max-[900px]:[--story-u:min(2.6667cqw,12px)] text-[length:var(--story-u)]\", \"contents\", className)}>\n        <DialogPrimitive.Root\n          modal={false}\n          onOpenChange={(open, details) => {\n            returnFocusRef.current = !open && details.reason !== \"outside-press\" && details.reason !== \"focus-out\"\n            onOpenChange?.(open, details)\n          }}\n          {...props}\n        />\n      </div>\n    </GlassPanelContext.Provider>\n  )\n}\n\nfunction GlassPanelTrigger({ className, ref, ...props }: DialogPrimitive.Trigger.Props & React.RefAttributes<HTMLElement>) {\n  const { triggerRef } = useGlassPanel()\n  return (\n    <DialogPrimitive.Trigger\n      ref={(el: HTMLElement | null) => {\n        triggerRef.current = el\n        setRef(ref, el)\n      }}\n      data-slot=\"glass-panel-trigger\"\n      className={cn(\"cursor-pointer\", className)}\n      {...props}\n    />\n  )\n}\n\n/**\n * The panel: glass, at the top inline-end corner (across the screen on phones). It grows out of its trigger: closed,\n * its clip is the trigger's box, measured when it opens, so it starts from wherever the trigger sits. Its children\n * drop into place in turn while it opens. Opened from its trigger, it takes focus: the child marked data-autofocus,\n * else the first control (the close button). Opened without one (defaultOpen, or by the page), it leaves focus where\n * it is, so a page never scrolls to a panel open on load.\n */\nfunction GlassPanelContent({\n  className,\n  children,\n  container,\n  showCloseButton = true,\n  closeLabel = \"Close\",\n  ref,\n  ...props\n}: DialogPrimitive.Popup.Props &\n  React.RefAttributes<HTMLDivElement> & {\n    /** Where the panel renders. Defaults to beside its trigger; pass document.body to lift it out of a clipping parent. */\n    container?: DialogPrimitive.Portal.Props[\"container\"]\n    showCloseButton?: boolean\n    /** The close button's accessible name, in the page's language. */\n    closeLabel?: string\n  }) {\n  const context = useGlassPanel()\n  const popupRef = React.useRef<HTMLDivElement>(null)\n  const stopMeasuringRef = React.useRef<() => void>(undefined)\n\n  const attach = React.useCallback(\n    (el: HTMLDivElement | null) => {\n      setRef(ref, el)\n      if (el === popupRef.current) return\n      popupRef.current = el\n      stopMeasuringRef.current?.()\n      stopMeasuringRef.current = undefined\n      if (!el) return\n      const measure = () => {\n        const trigger = context.triggerRef.current\n        if (!trigger) return\n        const a = trigger.getBoundingClientRect()\n        const b = el.getBoundingClientRect()\n        // the trigger's box inside the panel: the clip when closed\n        el.style.setProperty(\"--glass-panel-t\", `${a.top - b.top}px`)\n        el.style.setProperty(\"--glass-panel-r\", `${b.right - a.right}px`)\n        el.style.setProperty(\"--glass-panel-b\", `${b.bottom - a.bottom}px`)\n        el.style.setProperty(\"--glass-panel-l\", `${a.left - b.left}px`)\n        el.style.setProperty(\"--glass-panel-round\", getComputedStyle(trigger).borderTopLeftRadius)\n      }\n      measure()\n      window.addEventListener(\"resize\", measure)\n      stopMeasuringRef.current = () => window.removeEventListener(\"resize\", measure)\n    },\n    [context.triggerRef, ref]\n  )\n\n  return (\n    <DialogPrimitive.Portal container={container === undefined ? context.container : container}>\n      <DialogPrimitive.Popup\n        ref={attach}\n        data-slot=\"glass-panel-content\"\n        initialFocus={(openType) => !!openType && (popupRef.current?.querySelector<HTMLElement>(\"[data-autofocus]\") ?? true)}\n        finalFocus={() => context.returnFocusRef.current}\n        className={cn(\n          \"fixed top-[calc(var(--story-u)*2)] end-[calc(var(--story-u)*2)] z-[110] grid w-[calc(var(--story-u)*50.8)] content-start gap-[calc(var(--story-u)*2)] rounded-lg px-[calc(var(--story-u)*4)] pt-[calc(var(--story-u)*4)] pb-[calc(var(--story-u)*3.6)] outline-none\",\n          \"max-[900px]:top-[calc(var(--story-u)*1.5)] max-[900px]:start-[calc(var(--story-u)*1.5)] max-[900px]:end-[calc(var(--story-u)*1.5)] max-[900px]:w-auto\",\n          \"bg-[rgba(186,186,186,0.2)] backdrop-blur-[12px]\",\n          // the clip goes from the trigger's box (reveal 0, as it mounts and as it leaves) to the whole panel (reveal 1)\n          \"[clip-path:inset(calc(var(--glass-panel-t,0px)*(1-var(--glass-panel-reveal)))_calc(var(--glass-panel-r,0px)*(1-var(--glass-panel-reveal)))_calc(var(--glass-panel-b,100%)*(1-var(--glass-panel-reveal)))_calc(var(--glass-panel-l,100%)*(1-var(--glass-panel-reveal)))_round_calc(var(--glass-panel-round,0px)+(calc(var(--story-u)*1.2)-var(--glass-panel-round,0px))*var(--glass-panel-reveal)))]\",\n          \"[--glass-panel-reveal:1] [transition:--glass-panel-reveal_0.8s_cubic-bezier(0.455,0.03,0.515,0.955)]\",\n          \"data-starting-style:[--glass-panel-reveal:0] data-ending-style:[--glass-panel-reveal:0]\",\n          // the children (not the close button) drop in from above, 50ms apart, and leave together\n          \"[&>:not([data-slot=glass-panel-close])]:[transition:opacity_0.5s_ease,translate_0.6s_cubic-bezier(0.215,0.61,0.355,1)]\",\n          \"data-starting-style:[&>:not([data-slot=glass-panel-close])]:-translate-y-[calc(var(--story-u)*4)] data-starting-style:[&>:not([data-slot=glass-panel-close])]:opacity-0\",\n          \"data-ending-style:[&>:not([data-slot=glass-panel-close])]:-translate-y-[calc(var(--story-u)*4)] data-ending-style:[&>:not([data-slot=glass-panel-close])]:opacity-0\",\n          \"data-open:[&>:nth-child(3)]:delay-50 data-open:[&>:nth-child(4)]:delay-100 data-open:[&>:nth-child(5)]:delay-150 data-open:[&>:nth-child(n+6)]:delay-200\",\n          // as specific as the children's own transition, so reduced motion wins over it\n          \"motion-reduce:transition-none motion-reduce:[&>:not([data-slot=glass-panel-close])]:transition-none\",\n          className\n        )}\n        {...props}\n      >\n        {showCloseButton && (\n          <GlassPanelClose className=\"absolute top-[calc(var(--story-u)*2.2)] end-[calc(var(--story-u)*2.2)] size-[calc(var(--story-u)*1)]\">\n            <svg viewBox=\"0 0 10 10\" aria-hidden=\"true\">\n              <path d=\"M1 1l8 8M9 1l-8 8\" stroke=\"currentColor\" strokeWidth=\"1.2\" />\n            </svg>\n            <span className=\"sr-only\">{closeLabel}</span>\n          </GlassPanelClose>\n        )}\n        {children}\n      </DialogPrimitive.Popup>\n    </DialogPrimitive.Portal>\n  )\n}\n\nfunction GlassPanelTitle({ className, ...props }: DialogPrimitive.Title.Props) {\n  return (\n    <DialogPrimitive.Title\n      data-slot=\"glass-panel-title\"\n      className={cn(\"text-[length:max(11px,calc(var(--story-u)*1.4))] font-medium tracking-[-0.01em] max-[900px]:text-[length:calc(var(--story-u)*1.4)]\", className)}\n      {...props}\n    />\n  )\n}\n\nfunction GlassPanelFooter({ className, ...props }: React.ComponentProps<\"footer\">) {\n  return <footer data-slot=\"glass-panel-footer\" className={cn(\"grid gap-[calc(var(--story-u)*1)] pt-[calc(var(--story-u)*1.6)]\", className)} {...props} />\n}\n\nfunction GlassPanelClose({ className, ...props }: DialogPrimitive.Close.Props) {\n  return <DialogPrimitive.Close data-slot=\"glass-panel-close\" className={cn(\"cursor-pointer\", className)} {...props} />\n}\n\nexport { GlassPanel, GlassPanelTrigger, GlassPanelContent, GlassPanelTitle, GlassPanelFooter, GlassPanelClose }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "added": "2026-10-27"
  },
  "categories": [
    "card",
    "overlay"
  ],
  "type": "registry:ui"
}