{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dynamic-island",
  "title": "Dynamic Island",
  "description": "An iPhone-style pill that morphs between an idle pill, a compact live activity, and an expanded card, with a liquid spring, a sound and a haptic per morph, and swipe up to dismiss.",
  "dependencies": [
    "@rexa-developer/tiks",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/dynamic-island/dynamic-island.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport {\n\tAnimatePresence,\n\tanimate,\n\tmotion,\n\tuseIsPresent,\n\tuseMotionValue,\n\tuseReducedMotion,\n} from \"motion/react\";\nimport {\n\tChildren,\n\tisValidElement,\n\ttype KeyboardEvent,\n\ttype PointerEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\ttype Ref,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\n/** The shell's liquid morph between views. */\nconst shellSpring = { type: \"spring\", bounce: 0.3, duration: 0.55 } as const;\nconst shellReduced = { duration: 0.15, ease: \"easeOut\" } as const;\nconst pressSpring = { type: \"spring\", stiffness: 600, damping: 30 } as const;\nconst releaseSpring = { type: \"spring\", bounce: 0.3, duration: 0.45 } as const;\n\n/** Corner radius of an expanded card, in px. */\nconst CARD_RADIUS = 28;\n/** Size of the empty idle pill, in px. */\nconst IDLE_WIDTH = 120;\nconst IDLE_HEIGHT = 36;\n/** Minimum ms between view-change sounds and haptics. */\nconst CUE_THROTTLE_MS = 80;\n/** Ms after a tap, key, or swipe in which a view change counts as the user's. */\nconst USER_INTENT_MS = 1000;\n/** Ms of quiet before the live region announces a new view. */\nconst ANNOUNCE_DELAY = 150;\n/** Pointer travel, in px, before a press on an expanded view becomes a swipe. */\nconst DRAG_SLOP = 4;\n/** Upward travel, in px, that dismisses an expanded view on release. */\nconst DISMISS_DISTANCE = 24;\n/** Upward speed, in px/ms, that dismisses an expanded view as a flick. */\nconst FLICK_VELOCITY = 0.5;\n/** Px the shell can stretch before the rubber band hits its limit. */\nconst RUBBER_LIMIT = 16;\n/** Px of drag the rubber band resists against. */\nconst RUBBER_DIMENSION = 60;\n\nconst FOCUSABLE =\n\t'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\nconst INTERACTIVE = `${FOCUSABLE}, label, [role=\"button\"]`;\n\nconst viewSizes = {\n\tcompact:\n\t\t\"flex min-h-9 min-w-30 items-center justify-between gap-3 px-3 py-1.5 font-medium text-sm\",\n\texpanded: \"flex w-80 max-w-full flex-col gap-3 p-4 text-sm\",\n} as const;\n\ntype Tier = \"idle\" | \"compact\" | \"expanded\";\n\nexport interface DynamicIslandProps {\n\t/** Id of the `DynamicIslandView` to show. `null` shows the idle pill. */\n\tview: string | null;\n\t/** Content of the pill while `view` is `null`. Omit it for an empty pill. */\n\tcompact?: ReactNode;\n\t/** `DynamicIslandView` elements. */\n\tchildren?: ReactNode;\n\t/** Called when a compact view is tapped, with its id, or the idle pill with `null`. Makes them buttons. */\n\tonExpand?: (id: string | null) => void;\n\t/** Called on Escape, a click outside, or a swipe up on an expanded view. */\n\tonDismiss?: () => void;\n\t/** `top` fixes the island to the top centre of the viewport. */\n\tposition?: \"inline\" | \"top\";\n\t/** Play a sound per view change. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\t/** Mute sounds and haptics for view changes the user didn't cause. */\n\tquiet?: boolean;\n\t/** Let a swipe up dismiss an expanded view. */\n\tswipeToDismiss?: boolean;\n\t/** Accessible name of the idle pill when it is a button. */\n\tlabel?: string;\n\t/** Classes for the island shell. */\n\tclassName?: string;\n\tclassNames?: { root?: string; content?: string };\n}\n\nexport interface DynamicIslandViewProps {\n\tid: string;\n\t/** Text summary for screen readers, announced once each time the view opens. */\n\tlabel: string;\n\t/** `expanded` gives a card with 28px corners and a pop when it opens. */\n\tsize?: \"compact\" | \"expanded\";\n\t/** Open this view without a sound or haptic. */\n\tsilent?: boolean;\n\tclassName?: string;\n\tchildren?: ReactNode;\n}\n\nexport function DynamicIslandView({\n\tid,\n\tsize = \"compact\",\n\tclassName,\n\tchildren,\n}: DynamicIslandViewProps) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"dynamic-island-view\"\n\t\t\tdata-view={id}\n\t\t\tdata-size={size}\n\t\t\tclassName={cn(viewSizes[size], className)}\n\t\t>\n\t\t\t{children}\n\t\t</div>\n\t);\n}\n\n/** Soft resistance past a boundary. */\nfunction rubberband(distance: number) {\n\tconst constant = 0.55;\n\treturn (\n\t\t(distance * RUBBER_DIMENSION * constant) /\n\t\t(RUBBER_DIMENSION + constant * Math.abs(distance))\n\t);\n}\n\nfunction findView(children: ReactNode, id: string | null) {\n\tif (id === null) return null;\n\tfor (const child of Children.toArray(children)) {\n\t\tif (\n\t\t\tisValidElement<DynamicIslandViewProps>(child) &&\n\t\t\tchild.props.id === id\n\t\t) {\n\t\t\treturn child as ReactElement<DynamicIslandViewProps>;\n\t\t}\n\t}\n\treturn null;\n}\n\ninterface IslandContentProps {\n\tref?: Ref<HTMLDivElement>;\n\treduceMotion: boolean;\n\tariaHidden: boolean;\n\tclassName?: string;\n\tonSize: (width: number, height: number) => void;\n\tonNode: (node: HTMLDivElement | null) => void;\n\tchildren: ReactNode;\n}\n\n/**\n * One view's content. It keeps its natural size so it never squashes while\n * the shell resizes around it, and reports that size while it is present.\n */\nfunction IslandContent({\n\tref,\n\treduceMotion,\n\tariaHidden,\n\tclassName,\n\tonSize,\n\tonNode,\n\tchildren,\n}: IslandContentProps) {\n\tconst isPresent = useIsPresent();\n\tconst nodeRef = useRef<HTMLDivElement | null>(null);\n\n\tconst setNode = (node: HTMLDivElement | null) => {\n\t\tnodeRef.current = node;\n\t\tif (typeof ref === \"function\") ref(node);\n\t\telse if (ref) ref.current = node;\n\t};\n\n\tuseLayoutEffect(() => {\n\t\tconst node = nodeRef.current;\n\t\tif (!node || !isPresent) return;\n\t\tonNode(node);\n\t\t// offsetWidth ignores the enter scale.\n\t\tconst report = () => onSize(node.offsetWidth, node.offsetHeight);\n\t\treport();\n\t\tconst observer = new ResizeObserver(report);\n\t\tobserver.observe(node);\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t\tonNode(null);\n\t\t};\n\t}, [isPresent, onNode, onSize]);\n\n\t// Same keys either way, so the server render matches under reduced motion.\n\tconst hidden = reduceMotion\n\t\t? { opacity: 0, filter: \"blur(0px)\", scale: 1 }\n\t\t: { opacity: 0, filter: \"blur(4px)\", scale: 0.96 };\n\tconst shown = { opacity: 1, filter: \"blur(0px)\", scale: 1 };\n\n\treturn (\n\t\t<motion.div\n\t\t\tref={setNode}\n\t\t\tdata-slot=\"dynamic-island-content\"\n\t\t\taria-hidden={ariaHidden || undefined}\n\t\t\tinert={!isPresent}\n\t\t\tinitial={hidden}\n\t\t\tanimate={{\n\t\t\t\t...shown,\n\t\t\t\t// Enter once the shell has started to move.\n\t\t\t\ttransition: {\n\t\t\t\t\tdelay: reduceMotion ? 0 : 0.08,\n\t\t\t\t\tduration: reduceMotion ? 0.15 : 0.28,\n\t\t\t\t\tease: [0.2, 0.8, 0.2, 1],\n\t\t\t\t},\n\t\t\t}}\n\t\t\texit={{ ...hidden, transition: { duration: 0.12, ease: \"easeOut\" } }}\n\t\t\tclassName={cn(\"w-max max-w-[100cqw] shrink-0 origin-top\", className)}\n\t\t>\n\t\t\t{children}\n\t\t</motion.div>\n\t);\n}\n\nexport function DynamicIsland({\n\tview,\n\tcompact,\n\tchildren,\n\tonExpand,\n\tonDismiss,\n\tposition = \"inline\",\n\tsound = true,\n\thaptics = true,\n\tquiet = false,\n\tswipeToDismiss = true,\n\tlabel = \"Status\",\n\tclassName,\n\tclassNames,\n}: DynamicIslandProps) {\n\tconst activeView = findView(children, view);\n\tconst activeId = activeView ? activeView.props.id : null;\n\tconst activeSize = activeView?.props.size ?? \"compact\";\n\tconst tier: Tier = activeView\n\t\t? activeSize === \"expanded\"\n\t\t\t? \"expanded\"\n\t\t\t: \"compact\"\n\t\t: \"idle\";\n\tconst pressable = tier !== \"expanded\" && onExpand !== undefined;\n\tconst swipeable = tier === \"expanded\" && swipeToDismiss && !!onDismiss;\n\n\tconst shouldReduceMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\tconst {\n\t\tclick: playClick,\n\t\thover: playTick,\n\t\tpop: playPop,\n\t} = useTiks({\n\t\t// Sound stays on under reduced motion; only movement is reduced.\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst [size, setSize] = useState<{\n\t\twidth: number;\n\t\theight: number;\n\t\tinstant: boolean;\n\t} | null>(null);\n\tconst [announcement, setAnnouncement] = useState(\"\");\n\n\tconst shellRef = useRef<HTMLDivElement>(null);\n\tconst contentRef = useRef<HTMLDivElement | null>(null);\n\tconst scale = useMotionValue(1);\n\tconst y = useMotionValue(0);\n\tconst lastCueAtRef = useRef(Number.NEGATIVE_INFINITY);\n\tconst userIntentAtRef = useRef(Number.NEGATIVE_INFINITY);\n\tconst expandIntentAtRef = useRef(Number.NEGATIVE_INFINITY);\n\tconst shownRef = useRef<{ id: string | null; tier: Tier } | null>(null);\n\tconst pressedRef = useRef(false);\n\tconst suppressClickRef = useRef(false);\n\tconst dragRef = useRef<{\n\t\tpointerId: number;\n\t\tstartY: number;\n\t\tlastY: number;\n\t\tlastT: number;\n\t\tvelocity: number;\n\t\tdragging: boolean;\n\t\thitLimit: boolean;\n\t} | null>(null);\n\n\tconst handleSize = useCallback((width: number, height: number) => {\n\t\tsetSize((previous) =>\n\t\t\tprevious && previous.width === width && previous.height === height\n\t\t\t\t? previous\n\t\t\t\t: // The first size lands at once so the server render never animates.\n\t\t\t\t\t{ width, height, instant: previous === null },\n\t\t);\n\t}, []);\n\n\tconst handleNode = useCallback((node: HTMLDivElement | null) => {\n\t\tcontentRef.current = node;\n\t}, []);\n\n\tconst markUser = (expanding = false) => {\n\t\tconst now = performance.now();\n\t\tuserIntentAtRef.current = now;\n\t\tif (expanding) expandIntentAtRef.current = now;\n\t};\n\n\tconst expand = () => {\n\t\tif (!onExpand) return;\n\t\tmarkUser(true);\n\t\tonExpand(activeId);\n\t};\n\n\tconst dismiss = () => {\n\t\tif (!onDismiss) return;\n\t\tmarkUser();\n\t\tonDismiss();\n\t};\n\n\t// Cues and focus follow the resolved view, so an unknown id acts as idle.\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: runs once per view change.\n\tuseLayoutEffect(() => {\n\t\tconst previous = shownRef.current;\n\t\tshownRef.current = { id: activeId, tier };\n\t\t// The first render is silent.\n\t\tif (!previous || previous.id === activeId) return;\n\n\t\tconst now = performance.now();\n\t\tconst byUser = now - userIntentAtRef.current < USER_INTENT_MS;\n\t\tconst expandIntent = now - expandIntentAtRef.current < USER_INTENT_MS;\n\t\tuserIntentAtRef.current = Number.NEGATIVE_INFINITY;\n\t\texpandIntentAtRef.current = Number.NEGATIVE_INFINITY;\n\n\t\tconst shell = shellRef.current;\n\t\tconst focusInside = !!shell && shell.contains(document.activeElement);\n\n\t\t// Move focus in only when the user opened it; never steal it otherwise.\n\t\tif (tier === \"expanded\" && expandIntent && shell) {\n\t\t\tconst target =\n\t\t\t\tcontentRef.current?.querySelector<HTMLElement>(FOCUSABLE) ?? shell;\n\t\t\ttarget.focus({ preventScroll: true });\n\t\t} else if (previous.tier === \"expanded\" && focusInside && shell) {\n\t\t\tshell.focus({ preventScroll: true });\n\t\t}\n\n\t\tconst unknown = view !== null && activeView === null;\n\t\tconst muted =\n\t\t\tunknown ||\n\t\t\tactiveView?.props.silent === true ||\n\t\t\t(quiet && !byUser) ||\n\t\t\t(!sound && !haptics) ||\n\t\t\tnow - lastCueAtRef.current < CUE_THROTTLE_MS;\n\t\tif (muted) return;\n\t\tlastCueAtRef.current = now;\n\n\t\tif (tier === \"expanded\" && previous.tier !== \"expanded\") {\n\t\t\tif (sound) playPop();\n\t\t\tif (haptics) void haptic(\"soft\");\n\t\t} else if (tier === \"idle\") {\n\t\t\t// A quieter tick for settling back to rest.\n\t\t\tif (sound) playTick();\n\t\t\tif (haptics) void haptic(\"light\");\n\t\t} else {\n\t\t\tif (sound) playClick();\n\t\t\tif (haptics) {\n\t\t\t\tvoid haptic(previous.tier === \"expanded\" ? \"light\" : \"selection\");\n\t\t\t}\n\t\t}\n\t}, [activeId]);\n\n\t// Announce the label once per view change, after rapid changes settle.\n\tconst announcedIdRef = useRef(activeId);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: the label may tick; only the id matters.\n\tuseEffect(() => {\n\t\tif (announcedIdRef.current === activeId) return;\n\t\tannouncedIdRef.current = activeId;\n\t\tconst next = activeView?.props.label ?? \"\";\n\t\tconst timer = setTimeout(() => setAnnouncement(next), ANNOUNCE_DELAY);\n\t\treturn () => clearTimeout(timer);\n\t}, [activeId]);\n\n\t// Escape and a click outside dismiss an expanded view.\n\tconst dismissRef = useRef(dismiss);\n\tuseLayoutEffect(() => {\n\t\tdismissRef.current = dismiss;\n\t});\n\tconst canDismiss = tier === \"expanded\" && onDismiss !== undefined;\n\tuseEffect(() => {\n\t\tif (!canDismiss) return;\n\t\tconst onKeyDown = (event: globalThis.KeyboardEvent) => {\n\t\t\tif (event.key !== \"Escape\" || event.defaultPrevented) return;\n\t\t\tevent.preventDefault();\n\t\t\tdismissRef.current();\n\t\t};\n\t\tconst onPointerDown = (event: globalThis.PointerEvent) => {\n\t\t\tconst shell = shellRef.current;\n\t\t\tif (!shell || shell.contains(event.target as Node)) return;\n\t\t\tdismissRef.current();\n\t\t};\n\t\tdocument.addEventListener(\"keydown\", onKeyDown);\n\t\tdocument.addEventListener(\"pointerdown\", onPointerDown, true);\n\t\treturn () => {\n\t\t\tdocument.removeEventListener(\"keydown\", onKeyDown);\n\t\t\tdocument.removeEventListener(\"pointerdown\", onPointerDown, true);\n\t\t};\n\t}, [canDismiss]);\n\n\tconst press = () => {\n\t\tif (shouldReduceMotion) return;\n\t\tpressedRef.current = true;\n\t\tanimate(scale, 0.97, pressSpring);\n\t};\n\n\tconst release = () => {\n\t\tif (!pressedRef.current) return;\n\t\tpressedRef.current = false;\n\t\tanimate(scale, 1, releaseSpring);\n\t};\n\n\tconst endDrag = (cancelled: boolean) => {\n\t\tconst drag = dragRef.current;\n\t\tdragRef.current = null;\n\t\trelease();\n\t\tif (!drag?.dragging) return;\n\t\tsuppressClickRef.current = true;\n\t\tanimate(y, 0, releaseSpring);\n\t\tif (cancelled) return;\n\t\tconst distance = drag.startY - drag.lastY;\n\t\tif (distance > DISMISS_DISTANCE || -drag.velocity > FLICK_VELOCITY) {\n\t\t\tdismiss();\n\t\t}\n\t};\n\n\tconst handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {\n\t\tif (event.button !== 0) return;\n\t\tsuppressClickRef.current = false;\n\t\tif (pressable) {\n\t\t\tpress();\n\t\t\treturn;\n\t\t}\n\t\tif (tier !== \"expanded\") return;\n\t\t// Buttons inside the card keep their own press; the card squishes when grabbed.\n\t\tconst onControl = (event.target as Element).closest(INTERACTIVE);\n\t\tif (!onControl || !event.currentTarget.contains(onControl)) press();\n\t\tif (!swipeable) return;\n\t\tdragRef.current = {\n\t\t\tpointerId: event.pointerId,\n\t\t\tstartY: event.clientY,\n\t\t\tlastY: event.clientY,\n\t\t\tlastT: event.timeStamp,\n\t\t\tvelocity: 0,\n\t\t\tdragging: false,\n\t\t\thitLimit: false,\n\t\t};\n\t};\n\n\tconst handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\tconst dt = event.timeStamp - drag.lastT;\n\t\tif (dt > 0) drag.velocity = (event.clientY - drag.lastY) / dt;\n\t\tdrag.lastY = event.clientY;\n\t\tdrag.lastT = event.timeStamp;\n\t\tconst delta = event.clientY - drag.startY;\n\t\tif (!drag.dragging) {\n\t\t\tif (Math.abs(delta) < DRAG_SLOP) return;\n\t\t\tdrag.dragging = true;\n\t\t\tevent.currentTarget.setPointerCapture(event.pointerId);\n\t\t}\n\t\t// Reduced motion keeps the swipe but not the stretch.\n\t\tif (shouldReduceMotion) return;\n\t\tconst offset = rubberband(delta);\n\t\ty.set(offset);\n\t\tif (!drag.hitLimit && -offset >= RUBBER_LIMIT) {\n\t\t\tdrag.hitLimit = true;\n\t\t\tif (haptics) void haptic(\"rigid\");\n\t\t}\n\t};\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n\t\tif (!pressable || event.target !== event.currentTarget) return;\n\t\tif (event.key === \"Enter\") {\n\t\t\tevent.preventDefault();\n\t\t\texpand();\n\t\t} else if (event.key === \" \") {\n\t\t\t// Space activates on release, like a native button.\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst handleKeyUp = (event: KeyboardEvent<HTMLDivElement>) => {\n\t\tif (!pressable || event.target !== event.currentTarget) return;\n\t\tif (event.key === \" \") expand();\n\t};\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tscale.stop();\n\t\t\ty.stop();\n\t\t},\n\t\t[scale, y],\n\t);\n\n\t// A pill is fully round at any height; a card has fixed corners.\n\tconst radius =\n\t\ttier === \"expanded\" ? CARD_RADIUS : (size?.height ?? IDLE_HEIGHT) / 2;\n\tconst top = position === \"top\";\n\n\tlet content: ReactNode;\n\tif (activeView) {\n\t\tcontent = activeView;\n\t} else if (compact !== undefined && compact !== null) {\n\t\tcontent = <div className={viewSizes.compact}>{compact}</div>;\n\t} else {\n\t\tcontent = (\n\t\t\t<div style={{ width: IDLE_WIDTH, height: IDLE_HEIGHT }} aria-hidden />\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"dynamic-island-root\"\n\t\t\tdata-position={position}\n\t\t\tclassName={cn(\n\t\t\t\t\"@container flex justify-center\",\n\t\t\t\ttop\n\t\t\t\t\t? \"pointer-events-none fixed top-[max(0.5rem,env(safe-area-inset-top))] left-1/2 z-50 w-[min(360px,calc(100vw-1rem))] -translate-x-1/2\"\n\t\t\t\t\t: \"w-full\",\n\t\t\t\tclassNames?.root,\n\t\t\t)}\n\t\t>\n\t\t\t<motion.div\n\t\t\t\tref={shellRef}\n\t\t\t\tdata-slot=\"dynamic-island\"\n\t\t\t\tdata-tier={tier}\n\t\t\t\tdata-view={activeId ?? undefined}\n\t\t\t\trole={pressable ? \"button\" : tier === \"expanded\" ? \"region\" : undefined}\n\t\t\t\ttabIndex={pressable ? 0 : -1}\n\t\t\t\taria-label={\n\t\t\t\t\tpressable || tier === \"expanded\"\n\t\t\t\t\t\t? (activeView?.props.label ?? label)\n\t\t\t\t\t\t: undefined\n\t\t\t\t}\n\t\t\t\tinitial={false}\n\t\t\t\tanimate={{\n\t\t\t\t\tborderRadius: radius,\n\t\t\t\t\t...(size ? { width: size.width, height: size.height } : {}),\n\t\t\t\t}}\n\t\t\t\ttransition={\n\t\t\t\t\tsize?.instant\n\t\t\t\t\t\t? { duration: 0 }\n\t\t\t\t\t\t: shouldReduceMotion\n\t\t\t\t\t\t\t? shellReduced\n\t\t\t\t\t\t\t: shellSpring\n\t\t\t\t}\n\t\t\t\tstyle={{\n\t\t\t\t\tscale,\n\t\t\t\t\ty,\n\t\t\t\t\tborderRadius: radius,\n\t\t\t\t\ttouchAction: swipeable ? \"none\" : undefined,\n\t\t\t\t}}\n\t\t\t\tonClick={() => {\n\t\t\t\t\tif (pressable) expand();\n\t\t\t\t}}\n\t\t\t\t// A swipe ends without clicking the button it started on.\n\t\t\t\tonClickCapture={(event) => {\n\t\t\t\t\tif (!suppressClickRef.current) return;\n\t\t\t\t\tsuppressClickRef.current = false;\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t}}\n\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\tonKeyUp={handleKeyUp}\n\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\tonPointerMove={handlePointerMove}\n\t\t\t\tonPointerUp={() => endDrag(false)}\n\t\t\t\tonPointerCancel={() => endDrag(true)}\n\t\t\t\tonPointerLeave={() => {\n\t\t\t\t\tif (!dragRef.current?.dragging) release();\n\t\t\t\t}}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"pointer-events-auto relative flex max-w-full select-none items-start justify-center overflow-hidden bg-foreground text-background shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n\t\t\t\t\tpressable && \"cursor-pointer\",\n\t\t\t\t\tswipeable && \"cursor-grab active:cursor-grabbing\",\n\t\t\t\t\tclassName,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<AnimatePresence mode=\"popLayout\" initial={false}>\n\t\t\t\t\t<IslandContent\n\t\t\t\t\t\tkey={activeId ?? \"\\u0000idle\"}\n\t\t\t\t\t\treduceMotion={shouldReduceMotion}\n\t\t\t\t\t\tariaHidden={pressable}\n\t\t\t\t\t\tclassName={classNames?.content}\n\t\t\t\t\t\tonSize={handleSize}\n\t\t\t\t\t\tonNode={handleNode}\n\t\t\t\t\t>\n\t\t\t\t\t\t{content}\n\t\t\t\t\t</IslandContent>\n\t\t\t\t</AnimatePresence>\n\t\t\t</motion.div>\n\t\t\t<span role=\"status\" aria-live=\"polite\" aria-atomic className=\"sr-only\">\n\t\t\t\t{announcement}\n\t\t\t</span>\n\t\t</div>\n\t);\n}\n\nexport interface DynamicIslandShowOptions {\n\t/** Ms to show the view before returning to the previous one. Omit to keep it. */\n\tduration?: number;\n}\n\ntype QueuedView = { key: number; id: string; duration: number };\n\n/**\n * Drives a `DynamicIsland`. `show(id)` sets the resting view; with a\n * `duration` it shows the view for that long and then returns, queueing\n * timed views first in, first out. `hide()` drops the timed view on screen,\n * or clears the resting view when none is queued.\n */\nexport function useDynamicIsland(initial: string | null = null) {\n\tconst [state, setState] = useState<{\n\t\tbase: string | null;\n\t\tqueue: QueuedView[];\n\t}>({ base: initial, queue: [] });\n\tconst keyRef = useRef(0);\n\tconst head = state.queue[0];\n\n\tuseEffect(() => {\n\t\tif (!head) return;\n\t\tconst timer = setTimeout(() => {\n\t\t\tsetState((current) =>\n\t\t\t\tcurrent.queue[0]?.key === head.key\n\t\t\t\t\t? { ...current, queue: current.queue.slice(1) }\n\t\t\t\t\t: current,\n\t\t\t);\n\t\t}, head.duration);\n\t\treturn () => clearTimeout(timer);\n\t}, [head]);\n\n\tconst show = useCallback((id: string, options?: DynamicIslandShowOptions) => {\n\t\tconst duration = options?.duration;\n\t\tif (duration === undefined) {\n\t\t\tsetState((current) => ({ ...current, base: id }));\n\t\t\treturn;\n\t\t}\n\t\tkeyRef.current += 1;\n\t\tconst entry = { key: keyRef.current, id, duration };\n\t\tsetState((current) => ({ ...current, queue: [...current.queue, entry] }));\n\t}, []);\n\n\tconst hide = useCallback(() => {\n\t\tsetState((current) =>\n\t\t\tcurrent.queue.length > 0\n\t\t\t\t? { ...current, queue: current.queue.slice(1) }\n\t\t\t\t: { ...current, base: null },\n\t\t);\n\t}, []);\n\n\treturn { view: head ? head.id : state.base, show, hide };\n}\n\nexport default DynamicIsland;\n",
      "type": "registry:component",
      "target": "@components/dynamic-island.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-01",
    "image": "https://cdn.tentui.com/images/components/dynamic-island",
    "video": "https://cdn.tentui.com/videos/components/dynamic-island"
  },
  "docs": "https://tentui.com/components/dynamic-island",
  "categories": [
    "overlays"
  ],
  "type": "registry:component"
}