{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-28",
  "title": "Stack of notifications",
  "description": "Toasts stacked one behind the other that spread out on hover, focus or a pinned toggle.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/status-orb.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/notification/notification-28.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  ChevronsUpDownIcon,\n  PlusIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { StatusOrb, type StatusOrbTone } from '@/registry/ndeko/ui/status-orb';\n\ntype StackToast = {\n  id: number;\n  tone: StatusOrbTone;\n  title: string;\n  description: string;\n};\n\ntype ToastMessage = Omit<StackToast, 'id'>;\n\nconst MESSAGES: ToastMessage[] = [\n  {\n    tone: 'success',\n    title: 'Invite sent to priya@example.com',\n    description: 'She joins Atlas Redesign as a member',\n  },\n  {\n    tone: 'info',\n    title: 'Weekly digest is ready',\n    description: '12 tasks closed across 3 teams',\n  },\n  {\n    tone: 'warning',\n    title: 'Last week is still open',\n    description: 'Submit the timesheet before Friday',\n  },\n  {\n    tone: 'error',\n    title: 'The export did not finish',\n    description: 'The file went past the 50 MB limit',\n  },\n];\n\nconst INITIAL_TOASTS: StackToast[] = [\n  { id: 3, ...MESSAGES[2] },\n  { id: 2, ...MESSAGES[1] },\n  { id: 1, ...MESSAGES[0] },\n];\n\nconst TOAST_HEIGHT = 64;\nconst TOAST_GAP = 8;\nconst PEEK = 10;\nconst STACKED_LAYERS = 3;\nconst MAX_TOASTS = 4;\nconst LAYER_SCALE_STEP = 0.05;\n\nconst SPRING: Transition = { type: 'spring', bounce: 0, duration: 0.35 };\nconst INSTANT: Transition = { duration: 0 };\nconst LEAVE: Transition = { duration: 0.12, ease: [0.23, 1, 0.32, 1] };\n\ntype Placement = { y: number; scale: number; opacity: number };\n\nfunction placementOf(index: number, isExpanded: boolean): Placement {\n  if (isExpanded) {\n    const step = TOAST_HEIGHT + TOAST_GAP;\n    const y = index * step;\n    return { y, scale: 1, opacity: 1 };\n  }\n  const deepestLayer = STACKED_LAYERS - 1;\n  const layer = Math.min(index, deepestLayer);\n  const y = layer * PEEK;\n  const shrink = layer * LAYER_SCALE_STEP;\n  const scale = 1 - shrink;\n  const isBuried = index >= STACKED_LAYERS;\n  if (isBuried) {\n    return { y, scale, opacity: 0 };\n  }\n  return { y, scale, opacity: 1 };\n}\n\nfunction stackHeightOf(count: number, isExpanded: boolean) {\n  if (count === 0) {\n    return TOAST_HEIGHT;\n  }\n  if (isExpanded) {\n    const gapCount = count - 1;\n    const gaps = gapCount * TOAST_GAP;\n    const toastsHeight = count * TOAST_HEIGHT;\n    return toastsHeight + gaps;\n  }\n  const layers = Math.min(count, STACKED_LAYERS);\n  const peekCount = layers - 1;\n  const peeks = peekCount * PEEK;\n  return TOAST_HEIGHT + peeks;\n}\n\nfunction motionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return SPRING;\n}\n\nfunction arrivalOffsetOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return 0;\n  }\n  return -16;\n}\n\nfunction focusStaysInside(event: React.FocusEvent<HTMLElement>) {\n  const nextTarget = event.relatedTarget;\n  if (!(nextTarget instanceof Node)) {\n    return false;\n  }\n  return event.currentTarget.contains(nextTarget);\n}\n\nfunction withNewest(toasts: StackToast[], toast: StackToast) {\n  const next = [toast, ...toasts];\n  return next.slice(0, MAX_TOASTS);\n}\n\nexport default function Notification28() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [toasts, setToasts] = useState(INITIAL_TOASTS);\n  const [nextId, setNextId] = useState(4);\n  const [isHovered, setIsHovered] = useState(false);\n  const [isFocusWithin, setIsFocusWithin] = useState(false);\n  const [isPinnedOpen, setIsPinnedOpen] = useState(false);\n  const isExpanded = isHovered || isFocusWithin || isPinnedOpen;\n  const hasToasts = toasts.length > 0;\n  const stackHeight = stackHeightOf(toasts.length, isExpanded);\n  const transition = motionOf(shouldReduceMotion);\n  const arrivalOffset = arrivalOffsetOf(shouldReduceMotion);\n\n  function sendToast() {\n    const position = nextId - 1;\n    const messageIndex = position % MESSAGES.length;\n    const toast = { id: nextId, ...MESSAGES[messageIndex] };\n    setToasts((current) => withNewest(current, toast));\n    setNextId((current) => current + 1);\n  }\n\n  function dismiss(toastId: number) {\n    setToasts((current) => current.filter((toast) => toast.id !== toastId));\n  }\n\n  function togglePinned() {\n    setIsPinnedOpen((current) => !current);\n  }\n\n  function hoverStarts(event: React.PointerEvent<HTMLElement>) {\n    if (event.pointerType === 'mouse') {\n      setIsHovered(true);\n    }\n  }\n\n  function hoverEnds() {\n    setIsHovered(false);\n  }\n\n  function focusEnters() {\n    setIsFocusWithin(true);\n  }\n\n  function focusLeaves(event: React.FocusEvent<HTMLElement>) {\n    if (focusStaysInside(event)) {\n      return;\n    }\n    setIsFocusWithin(false);\n  }\n\n  return (\n    <div className='flex w-full max-w-[22rem] flex-col gap-4'>\n      <motion.ol\n        aria-label='Notifications'\n        aria-live='polite'\n        initial={false}\n        animate={{ height: stackHeight }}\n        transition={transition}\n        onPointerEnter={hoverStarts}\n        onPointerLeave={hoverEnds}\n        onFocus={focusEnters}\n        onBlur={focusLeaves}\n        className='relative'\n      >\n        <AnimatePresence initial={false}>\n          {toasts.map((toast, index) => {\n            const placement = placementOf(index, isExpanded);\n            const layerStyle = { zIndex: toasts.length - index };\n            return (\n              <motion.li\n                key={toast.id}\n                initial={{ y: arrivalOffset, scale: 1, opacity: 0 }}\n                animate={placement}\n                exit={{ opacity: 0, transition: LEAVE }}\n                transition={transition}\n                style={layerStyle}\n                className='surface-raised absolute inset-x-0 top-0 flex h-16 origin-bottom items-center gap-3 rounded-xl ps-3.5 pe-2'\n              >\n                <StatusOrb tone={toast.tone} size='sm' />\n                <div className='min-w-0 flex-1'>\n                  <p className='truncate text-[13px] leading-5 font-medium'>\n                    {toast.title}\n                  </p>\n                  <p className='text-muted-foreground truncate text-xs'>\n                    {toast.description}\n                  </p>\n                </div>\n                <Button\n                  variant='ghost'\n                  size='icon-sm'\n                  aria-label={`Dismiss ${toast.title}`}\n                  onClick={() => dismiss(toast.id)}\n                  className='text-muted-foreground'\n                >\n                  <XIcon />\n                </Button>\n              </motion.li>\n            );\n          })}\n        </AnimatePresence>\n        <AnimatePresence initial={false}>\n          {!hasToasts && (\n            <motion.li\n              key='empty'\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={{ opacity: 0, transition: LEAVE }}\n              className='hairline-border border-border text-muted-foreground absolute inset-0 flex items-center justify-center rounded-xl border-dashed text-[13px]'\n            >\n              No notifications, send one to fill the stack\n            </motion.li>\n          )}\n        </AnimatePresence>\n      </motion.ol>\n      <div className='flex items-center gap-2'>\n        <Button size='sm' variant='outline' onClick={sendToast}>\n          <PlusIcon />\n          Send a notification\n        </Button>\n        <Button\n          size='sm'\n          variant='ghost'\n          aria-pressed={isPinnedOpen}\n          disabled={!hasToasts}\n          onClick={togglePinned}\n          className='text-muted-foreground'\n        >\n          <ChevronsUpDownIcon />\n          Keep expanded\n        </Button>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "notification"
  ],
  "type": "registry:component"
}