{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover-03",
  "title": "Notifications with avatars",
  "description": "The notification list with an avatar for each person.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/popover.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/popover/popover-03.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { BellIcon } from '@/registry/ndeko/lib/icons';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTitle,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\n\ntype Notification = {\n  id: number;\n  user: string;\n  action: string;\n  target: string;\n  timestamp: string;\n  isUnread: boolean;\n};\n\nconst INITIAL_NOTIFICATIONS: Notification[] = [\n  {\n    id: 1,\n    user: 'Chris Tompson',\n    action: 'requested review on',\n    target: 'PR #42: Feature implementation',\n    timestamp: '15 minutes ago',\n    isUnread: true,\n  },\n  {\n    id: 2,\n    user: 'Emma Davis',\n    action: 'shared',\n    target: 'New component library',\n    timestamp: '45 minutes ago',\n    isUnread: true,\n  },\n  {\n    id: 3,\n    user: 'James Wilson',\n    action: 'assigned you to',\n    target: 'API integration task',\n    timestamp: '4 hours ago',\n    isUnread: false,\n  },\n  {\n    id: 4,\n    user: 'Alex Morgan',\n    action: 'replied to your comment in',\n    target: 'Authentication flow',\n    timestamp: '12 hours ago',\n    isUnread: false,\n  },\n  {\n    id: 5,\n    user: 'Sarah Chen',\n    action: 'commented on',\n    target: 'Dashboard redesign',\n    timestamp: '2 days ago',\n    isUnread: false,\n  },\n  {\n    id: 6,\n    user: 'Noah Patel',\n    action: 'mentioned you in',\n    target: 'Launch page open graph image',\n    timestamp: '2 weeks ago',\n    isUnread: false,\n  },\n];\n\nconst MAX_SHOWN_COUNT = 99;\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst POP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction popVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return POP_VARIANTS;\n}\n\nfunction notificationsLabelOf(unreadCount: number) {\n  if (unreadCount === 0) {\n    return 'Open notifications';\n  }\n  if (unreadCount === 1) {\n    return 'Open notifications, 1 unread';\n  }\n  return `Open notifications, ${unreadCount} unread`;\n}\n\nfunction shownCountOf(unreadCount: number) {\n  return Math.min(unreadCount, MAX_SHOWN_COUNT);\n}\n\nfunction overflowMarkOf(unreadCount: number) {\n  if (unreadCount > MAX_SHOWN_COUNT) {\n    return '+';\n  }\n  return undefined;\n}\n\nfunction markAsRead(notification: Notification) {\n  return { ...notification, isUnread: false };\n}\n\nexport default function Popover03() {\n  const [notifications, setNotifications] = useState(INITIAL_NOTIFICATIONS);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const popVariants = popVariantsOf(shouldReduceMotion);\n  const unreadCount = notifications.filter(\n    (notification) => notification.isUnread\n  ).length;\n  const hasUnread = unreadCount > 0;\n  const shownCount = shownCountOf(unreadCount);\n  const overflowMark = overflowMarkOf(unreadCount);\n\n  function markAllAsRead() {\n    setNotifications((current) => current.map(markAsRead));\n  }\n\n  function markOneAsRead(id: number) {\n    setNotifications((current) =>\n      current.map((notification) => {\n        if (notification.id !== id) {\n          return notification;\n        }\n        return markAsRead(notification);\n      })\n    );\n  }\n\n  return (\n    <Popover>\n      <PopoverTrigger\n        render={\n          <Button\n            variant='outline'\n            size='icon'\n            aria-label={notificationsLabelOf(unreadCount)}\n          />\n        }\n      >\n        <BellIcon />\n        <AnimatePresence initial={false}>\n          {hasUnread && (\n            <motion.span\n              key='unread-count'\n              className='absolute -top-2 left-full -translate-x-1/2'\n              variants={popVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              <Badge className='bg-primary text-primary-foreground min-w-5 overflow-hidden px-1 tabular-nums'>\n                <MotionNumber value={shownCount} suffix={overflowMark} />\n              </Badge>\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </PopoverTrigger>\n      <PopoverContent className='w-80 p-1'>\n        <div className='flex items-baseline justify-between gap-4 px-3 py-2'>\n          <PopoverTitle>Notifications</PopoverTitle>\n          <Button\n            variant='link'\n            size='sm'\n            onClick={markAllAsRead}\n            disabled={!hasUnread}\n            focusableWhenDisabled\n            className='h-auto p-0 text-xs'\n          >\n            Mark all as read\n          </Button>\n        </div>\n        <ul className='flex flex-col'>\n          {notifications.map((notification) => (\n            <li\n              key={notification.id}\n              className='has-focus-visible:bg-foreground/5 hover:bg-foreground/5 relative flex items-start gap-3 rounded-md px-3 py-2 transition-colors duration-150'\n            >\n              <Avatar\n                className='size-9'\n                aria-hidden='true'\n                seed={notification.user}\n              />\n              <div className='flex min-w-0 flex-1 flex-col gap-1'>\n                <button\n                  type='button'\n                  onClick={() => markOneAsRead(notification.id)}\n                  className='text-muted-foreground text-left outline-none after:absolute after:inset-0'\n                >\n                  <span className='text-foreground font-medium'>\n                    {notification.user}\n                  </span>{' '}\n                  {notification.action}{' '}\n                  <span className='text-foreground font-medium'>\n                    {notification.target}\n                  </span>\n                  .\n                </button>\n                <span className='text-muted-foreground text-xs'>\n                  {notification.timestamp}\n                </span>\n              </div>\n              <span className='flex size-1.5 shrink-0 self-center'>\n                <AnimatePresence initial={false}>\n                  {notification.isUnread && (\n                    <motion.span\n                      key='unread'\n                      className='bg-primary size-1.5 rounded-full'\n                      variants={popVariants}\n                      initial='enter'\n                      animate='visible'\n                      exit='exit'\n                      transition={SWAP_TRANSITION}\n                    >\n                      <span className='sr-only'>Unread</span>\n                    </motion.span>\n                  )}\n                </AnimatePresence>\n              </span>\n            </li>\n          ))}\n        </ul>\n      </PopoverContent>\n    </Popover>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "popover"
  ],
  "type": "registry:component"
}