{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notifications-03",
  "title": "In-page notices",
  "description": "Notices in the flow of a page, each with a status orb, one line, an action that resolves it in place and a quiet link to the source it is about.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.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/status-orb.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/notifications/notifications-03/index.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { RotateCcwIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport {\n  NOTICES,\n  SOURCES,\n  TEAM_NAME,\n  WORKING_DURATION_MS,\n  type Source,\n  type SourceId,\n} from './data';\nimport { fadePresence, Swap } from './motion-parts';\nimport { Notice, type NoticePhase } from './notice';\n\nconst SOURCES_ANCHOR = 'sources';\n\ntype Phases = Record<string, NoticePhase>;\n\nfunction phaseOf(phases: Phases, noticeId: string): NoticePhase {\n  return phases[noticeId] ?? 'open';\n}\n\nfunction isSourceResolved(phases: Phases, sourceId: SourceId) {\n  const notice = NOTICES.find((item) => item.sourceId === sourceId);\n  if (!notice) {\n    return false;\n  }\n  return phaseOf(phases, notice.id) === 'resolved';\n}\n\nfunction sourceStateOf(source: Source, isResolved: boolean) {\n  if (isResolved) {\n    return source.resolved;\n  }\n  return source.open;\n}\n\nexport default function Notifications03() {\n  const [dismissedIds, setDismissedIds] = useState<string[]>([]);\n  const [phases, setPhases] = useState<Phases>({});\n  const timers = useRef(new Set<ReturnType<typeof setTimeout>>());\n  const shownNotices = NOTICES.filter(\n    (notice) => !dismissedIds.includes(notice.id)\n  );\n  const hasNotices = shownNotices.length > 0;\n\n  useEffect(() => {\n    const pending = timers.current;\n    return () => {\n      pending.forEach((timer) => clearTimeout(timer));\n    };\n  }, []);\n\n  function setPhase(noticeId: string, phase: NoticePhase) {\n    setPhases((current) => ({ ...current, [noticeId]: phase }));\n  }\n\n  function act(noticeId: string) {\n    setPhase(noticeId, 'working');\n    const timer = setTimeout(() => {\n      timers.current.delete(timer);\n      setPhase(noticeId, 'resolved');\n    }, WORKING_DURATION_MS);\n    timers.current.add(timer);\n  }\n\n  function dismiss(noticeId: string) {\n    setDismissedIds((current) => [...current, noticeId]);\n  }\n\n  function showDismissed() {\n    setDismissedIds([]);\n  }\n\n  return (\n    <div className='bg-background text-foreground min-h-svh px-4 py-8 sm:px-8 sm:py-10'>\n      <div className='mx-auto max-w-2xl'>\n        <h1 className='text-2xl font-semibold text-balance'>\n          Imports and sync\n        </h1>\n        <p className='text-muted-foreground mt-1 text-[13px]'>\n          Where {TEAM_NAME} gets its members and its calendar\n        </p>\n        <AnimatedSize className='mt-6'>\n          <div className='relative'>\n            <AnimatePresence mode='popLayout' initial={false}>\n              {hasNotices && (\n                <motion.ul\n                  key='notices'\n                  aria-label='Notices'\n                  aria-live='polite'\n                  {...fadePresence()}\n                >\n                  <AnimatePresence initial={false}>\n                    {shownNotices.map((notice) => (\n                      <Notice\n                        key={notice.id}\n                        notice={notice}\n                        phase={phaseOf(phases, notice.id)}\n                        recoveryHref={`#${SOURCES_ANCHOR}`}\n                        onAction={act}\n                        onDismiss={dismiss}\n                      />\n                    ))}\n                  </AnimatePresence>\n                </motion.ul>\n              )}\n              {!hasNotices && (\n                <motion.div\n                  key='no-notices'\n                  {...fadePresence()}\n                  className='flex flex-wrap items-center justify-between gap-2 pb-3'\n                >\n                  <p className='text-muted-foreground text-[13px]'>\n                    No notices, a source that needs you will show one here\n                  </p>\n                  <Button\n                    variant='ghost'\n                    size='sm'\n                    onClick={showDismissed}\n                    className='text-muted-foreground'\n                  >\n                    <RotateCcwIcon />\n                    Show dismissed notices\n                  </Button>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n        </AnimatedSize>\n        <section id={SOURCES_ANCHOR} className='mt-7 scroll-mt-6'>\n          <h2 className='text-sm font-medium'>Sources</h2>\n          <ul className='bg-card hairline-ring ring-border hairline-divide-y divide-border mt-3 overflow-clip rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n            {SOURCES.map((source) => {\n              const isResolved = isSourceResolved(phases, source.id);\n              const state = sourceStateOf(source, isResolved);\n              return (\n                <li\n                  key={source.id}\n                  className='flex min-h-14 items-center justify-between gap-3 px-4 py-3'\n                >\n                  <div className='min-w-0'>\n                    <p className='truncate text-[13px] font-medium'>\n                      {source.name}\n                    </p>\n                    <p className='text-muted-foreground truncate text-xs'>\n                      {source.detail}\n                    </p>\n                  </div>\n                  <Swap swapKey={state.label}>\n                    <Badge variant={state.variant}>{state.label}</Badge>\n                  </Swap>\n                </li>\n              );\n            })}\n          </ul>\n        </section>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-03/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/notifications/notifications-03/notice.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { LoaderIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { StatusOrb, type StatusOrbTone } from '@/registry/ndeko/ui/status-orb';\n\nimport type { NoticeData, NoticeTone } from './data';\nimport { fadePresence, heightPresenceOf, MorphText } from './motion-parts';\n\nexport type NoticePhase = 'open' | 'working' | 'resolved';\n\nconst ORB_TONE: Record<NoticeTone, StatusOrbTone> = {\n  warning: 'warning',\n  error: 'error',\n  info: 'info',\n};\n\nfunction orbToneOf(tone: NoticeTone, phase: NoticePhase): StatusOrbTone {\n  if (phase === 'resolved') {\n    return 'success';\n  }\n  return ORB_TONE[tone];\n}\n\nfunction textOf(notice: NoticeData, isResolved: boolean) {\n  if (isResolved) {\n    return notice.resolved;\n  }\n  return notice.open;\n}\n\nfunction actionLabelOf(notice: NoticeData, isWorking: boolean) {\n  if (isWorking) {\n    return notice.workingAction;\n  }\n  return notice.action;\n}\n\ntype NoticeProps = {\n  notice: NoticeData;\n  phase: NoticePhase;\n  recoveryHref: string;\n  onAction: (noticeId: string) => void;\n  onDismiss: (noticeId: string) => void;\n};\n\nexport function Notice({\n  notice,\n  phase,\n  recoveryHref,\n  onAction,\n  onDismiss,\n}: NoticeProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const isResolved = phase === 'resolved';\n  const isWorking = phase === 'working';\n  const text = textOf(notice, isResolved);\n\n  return (\n    <motion.li\n      {...heightPresenceOf(shouldReduceMotion)}\n      className='overflow-hidden'\n    >\n      <div className='pb-3'>\n        <div className='bg-card hairline-ring ring-border flex items-start gap-3 rounded-xl py-3 ps-3.5 pe-2 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n          <StatusOrb\n            tone={orbToneOf(notice.tone, phase)}\n            size='sm'\n            className='mt-px'\n          />\n          <AnimatedSize className='min-w-0 flex-1'>\n            <div className='relative'>\n              <AnimatePresence mode='popLayout' initial={false}>\n                <motion.div key={String(isResolved)} {...fadePresence()}>\n                  <p className='text-[13px] font-medium'>{text.title}</p>\n                  <p className='text-muted-foreground mt-0.5 text-[13px] text-pretty'>\n                    {text.line}\n                  </p>\n                </motion.div>\n              </AnimatePresence>\n            </div>\n            {!isResolved && (\n              <div className='mt-3 flex flex-wrap items-center gap-x-4 gap-y-2'>\n                <Button\n                  size='sm'\n                  variant='outline'\n                  disabled={isWorking}\n                  onClick={() => onAction(notice.id)}\n                >\n                  <AnimatedSize axis='width'>\n                    <span className='flex items-center gap-1.5'>\n                      {isWorking && (\n                        <LoaderIcon className='size-3.5 animate-spin' />\n                      )}\n                      <MorphText text={actionLabelOf(notice, isWorking)} />\n                    </span>\n                  </AnimatedSize>\n                </Button>\n                <a\n                  href={recoveryHref}\n                  className='text-muted-foreground hover:text-foreground focus-visible:ring-ring/25 rounded-sm text-xs underline-offset-4 outline-none hover:underline focus-visible:ring-[3px]'\n                >\n                  {notice.recoveryLink}\n                </a>\n              </div>\n            )}\n          </AnimatedSize>\n          <Button\n            variant='ghost'\n            size='icon-sm'\n            aria-label={`Dismiss: ${text.title}`}\n            onClick={() => onDismiss(notice.id)}\n            className='text-muted-foreground -mt-0.5'\n          >\n            <XIcon />\n          </Button>\n        </div>\n      </div>\n    </motion.li>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-03/notice.tsx"
    },
    {
      "path": "registry/ndeko/blocks/notifications/notifications-03/motion-parts.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type MotionProps,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst EASE_OUT_STRONG: [number, number, number, number] = [0.23, 1, 0.32, 1];\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: EASE_OUT_STRONG };\n\nconst SWAP_VARIANTS: Variants = {\n  hidden: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  shown: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  hidden: { opacity: 0 },\n  shown: { opacity: 1 },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\ntype SwapProps = {\n  swapKey: string;\n  children: React.ReactNode;\n  className?: string;\n};\n\nexport function Swap({ swapKey, children, className }: SwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion);\n\n  return (\n    <span className={cn('relative inline-flex', className)}>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={swapKey}\n          variants={variants}\n          initial='hidden'\n          animate='shown'\n          exit='hidden'\n          transition={SWAP_TRANSITION}\n          className='inline-flex items-center gap-[inherit]'\n        >\n          {children}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nexport function MorphText({ text }: { text: string }) {\n  return <Swap swapKey={text}>{text}</Swap>;\n}\n\nconst ENTER: Transition = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nconst EXIT: Transition = { duration: 0.12, ease: EASE_OUT_STRONG };\n\n/**\n * The spring AnimatedSize resizes with. It starts from rest, so the fade leads and the freed space\n * closes after it at the pace the surrounding layout follows, instead of snapping shut.\n */\nconst SIZE_SPRING: Transition = { type: 'spring', bounce: 0, duration: 0.32 };\n\nconst HEIGHT_ENTER: Transition = {\n  ...SIZE_SPRING,\n  opacity: ENTER,\n};\n\nconst HEIGHT_EXIT: Transition = {\n  ...SIZE_SPRING,\n  opacity: EXIT,\n};\n\ntype PresenceProps = Pick<\n  MotionProps,\n  'initial' | 'animate' | 'exit' | 'transition'\n>;\n\nconst HEIGHT_PRESENCE: PresenceProps = {\n  initial: { height: 0, opacity: 0 },\n  animate: { height: 'auto', opacity: 1 },\n  exit: { height: 0, opacity: 0, transition: HEIGHT_EXIT },\n  transition: HEIGHT_ENTER,\n};\n\nconst FADE_PRESENCE: PresenceProps = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\nexport function heightPresenceOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_PRESENCE;\n  }\n  return HEIGHT_PRESENCE;\n}\n\nexport function fadePresence() {\n  return FADE_PRESENCE;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-03/motion-parts.tsx"
    },
    {
      "path": "registry/ndeko/blocks/notifications/notifications-03/data.ts",
      "content": "export type NoticeTone = 'warning' | 'error' | 'info';\n\nexport type SourceId = 'calendar' | 'import' | 'invites';\n\nexport type NoticeText = {\n  title: string;\n  line: string;\n};\n\nexport type NoticeData = {\n  id: string;\n  sourceId: SourceId;\n  tone: NoticeTone;\n  open: NoticeText;\n  resolved: NoticeText;\n  action: string;\n  workingAction: string;\n  recoveryLink: string;\n};\n\nexport type SourceState = {\n  label: string;\n  variant: 'success' | 'warning' | 'info' | 'destructive';\n};\n\nexport type Source = {\n  id: SourceId;\n  name: string;\n  detail: string;\n  open: SourceState;\n  resolved: SourceState;\n};\n\nexport const TEAM_NAME = 'Mossline Web';\n\nexport const WORKING_DURATION_MS = 1400;\n\nexport const NOTICES: NoticeData[] = [\n  {\n    id: 'calendar-paused',\n    sourceId: 'calendar',\n    tone: 'warning',\n    open: {\n      title: 'Calendar feed paused',\n      line: 'The feed stopped answering at 09:40, so later events are missing from plans',\n    },\n    resolved: {\n      title: 'Calendar feed reconnected',\n      line: 'Events from 09:40 onward are back in plans',\n    },\n    action: 'Reconnect',\n    workingAction: 'Reconnecting',\n    recoveryLink: 'Check the calendar feed',\n  },\n  {\n    id: 'import-failed',\n    sourceId: 'import',\n    tone: 'error',\n    open: {\n      title: 'Member import failed',\n      line: 'Row 214 of members.csv has no email address, so nobody was imported',\n    },\n    resolved: {\n      title: 'Members imported',\n      line: '47 members joined Mossline Web and row 214 was skipped',\n    },\n    action: 'Import without row 214',\n    workingAction: 'Importing',\n    recoveryLink: 'Check the import',\n  },\n  {\n    id: 'invites-pending',\n    sourceId: 'invites',\n    tone: 'info',\n    open: {\n      title: 'Two invitations are still pending',\n      line: 'Tomás and Mei have not joined Mossline Web yet',\n    },\n    resolved: {\n      title: 'Invitations sent again',\n      line: 'Tomás and Mei will get a new email in a minute',\n    },\n    action: 'Resend invites',\n    workingAction: 'Sending',\n    recoveryLink: 'Check the invitations',\n  },\n];\n\nexport const SOURCES: Source[] = [\n  {\n    id: 'calendar',\n    name: 'Calendar feed',\n    detail: 'Studio bookings, every 5 minutes',\n    open: { label: 'Paused', variant: 'warning' },\n    resolved: { label: 'Connected', variant: 'success' },\n  },\n  {\n    id: 'import',\n    name: 'Member import',\n    detail: 'members.csv, uploaded today',\n    open: { label: 'Failed', variant: 'destructive' },\n    resolved: { label: 'Finished', variant: 'success' },\n  },\n  {\n    id: 'invites',\n    name: 'Invitations',\n    detail: 'Sent on Monday',\n    open: { label: '2 pending', variant: 'info' },\n    resolved: { label: 'Sent again', variant: 'info' },\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-03/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "notifications"
  ],
  "type": "registry:block"
}