{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dynamic-island",
  "title": "Dynamic Island",
  "author": "VenusUI",
  "description": "A black pill that morphs into a larger panel on hover or click, like a phone's dynamic island.",
  "files": [
    {
      "path": "registry/default/ui/dynamic-island.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface DynamicIslandProps extends Omit<React.ComponentProps<\"div\">, \"children\"> {\n  /** What the small pill shows. Not interactive: the pill itself is the toggle. */\n  compact: React.ReactNode\n  /** What the island shows when expanded. May include buttons. */\n  expanded: React.ReactNode\n  /** Names the toggle for screen readers, e.g. \"Now playing: Night Drive\". */\n  label: string\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n}\n\ninterface Size {\n  width: number\n  height: number\n}\n\n/**\n * A black pill that morphs into a larger panel, like a phone's dynamic\n * island. It measures both views and animates its size and roundness\n * between them while they crossfade. Hover or click to open; move away,\n * press Escape or click outside to close.\n */\nfunction DynamicIsland({\n  compact,\n  expanded,\n  label,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  className,\n  ...props\n}: DynamicIslandProps) {\n  const [hovered, setHovered] = React.useState(false)\n  const [pinned, setPinned] = React.useState(defaultOpen)\n  const open = openProp ?? (hovered || pinned)\n  const rootRef = React.useRef<HTMLDivElement>(null)\n  const compactRef = React.useRef<HTMLSpanElement>(null)\n  const pillRef = React.useRef<HTMLButtonElement>(null)\n  const expandedRef = React.useRef<HTMLDivElement>(null)\n  const [sizes, setSizes] = React.useState<{ compact: Size; expanded: Size } | null>(null)\n  const panelId = React.useId()\n\n  const setPinnedAndNotify = React.useCallback(\n    (next: boolean) => {\n      setPinned(next)\n      onOpenChange?.(next)\n    },\n    [onOpenChange]\n  )\n\n  // Measure both views, and again whenever their content changes size.\n  React.useLayoutEffect(() => {\n    const c = compactRef.current\n    const e = expandedRef.current\n    if (!c || !e) return\n    const measure = () =>\n      setSizes({\n        compact: { width: c.offsetWidth, height: c.offsetHeight },\n        expanded: { width: e.offsetWidth, height: e.offsetHeight },\n      })\n    measure()\n    const observer = new ResizeObserver(measure)\n    observer.observe(c)\n    observer.observe(e)\n    return () => observer.disconnect()\n  }, [])\n\n  // Escape and clicks outside close an island opened by click.\n  React.useEffect(() => {\n    if (!open) return\n    const onKey = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") {\n        const hadFocus = rootRef.current?.contains(document.activeElement)\n        setHovered(false)\n        setPinnedAndNotify(false)\n        if (hadFocus) requestAnimationFrame(() => pillRef.current?.focus())\n      }\n    }\n    const onPointer = (event: PointerEvent) => {\n      if (pinned && rootRef.current && !rootRef.current.contains(event.target as Node)) setPinnedAndNotify(false)\n    }\n    document.addEventListener(\"keydown\", onKey)\n    document.addEventListener(\"pointerdown\", onPointer)\n    return () => {\n      document.removeEventListener(\"keydown\", onKey)\n      document.removeEventListener(\"pointerdown\", onPointer)\n    }\n  }, [open, pinned, setPinnedAndNotify])\n\n  const size = sizes ? (open ? sizes.expanded : sizes.compact) : undefined\n  const layer = \"absolute top-0 left-1/2 w-max -translate-x-1/2 transition-[opacity,filter,scale] duration-300 motion-reduce:transition-none\"\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot=\"dynamic-island\"\n      data-open={open || undefined}\n      className={cn(\"flex justify-center\", className)}\n      onPointerEnter={(event) => event.pointerType !== \"touch\" && setHovered(true)}\n      onPointerLeave={(event) => event.pointerType !== \"touch\" && setHovered(false)}\n      {...props}\n    >\n      <div\n        className=\"relative overflow-hidden bg-black text-white shadow-[0_10px_30px_-10px_rgb(0_0_0/0.6)] ring-1 ring-white/10 transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.25,0.5,1)] motion-reduce:transition-none\"\n        style={size ? { width: size.width, height: size.height, borderRadius: open ? 32 : size.height / 2 } : { borderRadius: 999 }}\n      >\n        <button\n          ref={pillRef}\n          type=\"button\"\n          aria-label={label}\n          aria-expanded={open}\n          aria-controls={panelId}\n          onClick={() => {\n            setPinnedAndNotify(!pinned)\n            // Opened from the keyboard: move focus to the first control inside.\n            if (!pinned) {\n              requestAnimationFrame(() => expandedRef.current?.querySelector<HTMLElement>(\"button, a[href], input, [tabindex='0']\")?.focus())\n            }\n          }}\n          className={cn(layer, \"cursor-pointer rounded-full outline-none focus-visible:ring-3 focus-visible:ring-white/50\", open && \"pointer-events-none scale-90 opacity-0 blur-sm\")}\n          tabIndex={open ? -1 : 0}\n        >\n          <span ref={compactRef} className=\"block\">\n            {compact}\n          </span>\n        </button>\n        <div\n          ref={expandedRef}\n          id={panelId}\n          inert={!open}\n          className={cn(layer, !open && \"pointer-events-none scale-90 opacity-0 blur-sm\")}\n        >\n          {expanded}\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { DynamicIsland }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "animations"
  ],
  "type": "registry:ui"
}