{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notifications-02",
  "title": "Toasts in context",
  "description": "Four small forms that each raise a toast through the Toaster of sonner.tsx: a success out of view, a failure with its reason and Retry, a loading toast that becomes its result, and an archive with Undo.",
  "dependencies": [
    "motion",
    "sonner"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.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-02/index.tsx",
      "content": "'use client';\n\nimport { toast } from 'sonner';\n\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport {\n  ArchiveTile,\n  EstimateTile,\n  ExportTile,\n  InviteTile,\n} from './toast-tiles';\n\nexport default function Notifications02() {\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-3xl'>\n        <div className='flex flex-wrap items-end justify-between gap-3'>\n          <div>\n            <h1 className='text-sm font-semibold'>Toasts</h1>\n            <p className='text-muted-foreground mt-0.5 text-[13px]'>\n              Each toast states what happened, and a failure also says why\n            </p>\n          </div>\n          <Button\n            variant='ghost'\n            size='sm'\n            onClick={() => toast.dismiss()}\n            className='text-muted-foreground'\n          >\n            Dismiss all\n          </Button>\n        </div>\n        <div className='mt-6 grid gap-4 sm:grid-cols-2'>\n          <InviteTile />\n          <EstimateTile />\n          <ExportTile />\n          <ArchiveTile />\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-02/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/notifications/notifications-02/toast-tiles.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useState } from 'react';\nimport { toast } from 'sonner';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  ArchiveIcon,\n  DownloadIcon,\n  LoaderIcon,\n  RotateCcwIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\n\nimport {\n  ARCHIVABLE_TASK,\n  ESTIMATE_VALUE,\n  EXPORT_DURATION_MS,\n  INVITE_EMAIL,\n  REPORT_NAME,\n  REPORT_RECIPIENT,\n  TEAM_NAME,\n} from './data';\nimport {\n  fadePresence,\n  heightPresenceOf,\n  MorphText,\n  Swap,\n} from './motion-parts';\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\ntype TileProps = {\n  title: string;\n  line: string;\n  children: React.ReactNode;\n};\n\nfunction Tile({ title, line, children }: TileProps) {\n  return (\n    <section className='bg-card hairline-ring ring-border flex flex-col gap-4 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n      <div>\n        <h2 className='text-sm font-medium'>{title}</h2>\n        <p className='text-muted-foreground mt-0.5 text-[13px] text-pretty'>\n          {line}\n        </p>\n      </div>\n      <div className='mt-auto'>{children}</div>\n    </section>\n  );\n}\n\nexport function InviteTile() {\n  const fieldId = useId();\n  const errorId = useId();\n  const [email, setEmail] = useState(INVITE_EMAIL);\n  const [isInvalid, setIsInvalid] = useState(false);\n\n  function send(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    const trimmed = email.trim();\n    const isEmail = EMAIL_PATTERN.test(trimmed);\n    if (!isEmail) {\n      setIsInvalid(true);\n      return;\n    }\n    setIsInvalid(false);\n    toast.success(`Invite sent to ${trimmed}`, {\n      description: `They can join ${TEAM_NAME} from the email`,\n    });\n  }\n\n  return (\n    <Tile\n      title='Success'\n      line='The invite lands in an inbox the sender cannot see, so a toast confirms it'\n    >\n      <form onSubmit={send} noValidate className='flex flex-col gap-1.5'>\n        <Label htmlFor={fieldId}>Email address</Label>\n        <div className='flex gap-2'>\n          <Input\n            id={fieldId}\n            type='email'\n            value={email}\n            onChange={(event) => setEmail(event.target.value)}\n            aria-invalid={isInvalid}\n            aria-describedby={errorId}\n          />\n          <Button type='submit'>Send invite</Button>\n        </div>\n        <p\n          id={errorId}\n          aria-live='polite'\n          className='text-destructive-ink text-xs'\n        >\n          {isInvalid && 'Enter an email address such as name@example.com'}\n        </p>\n      </form>\n    </Tile>\n  );\n}\n\nexport function EstimateTile() {\n  function save() {\n    toast.error('Couldn’t save the estimate', {\n      description:\n        'The connection dropped while saving, the value stays in the field until you retry',\n      action: {\n        label: 'Retry',\n        onClick: () => toast.success(`Estimate saved as ${ESTIMATE_VALUE}`),\n      },\n    });\n  }\n\n  return (\n    <Tile\n      title='Error with its reason'\n      line='A failure says what went wrong in words and offers the way back'\n    >\n      <div className='flex items-center gap-2'>\n        <span className='text-muted-foreground w-16 shrink-0 text-[13px]'>\n          Estimate\n        </span>\n        <span className='min-w-0 flex-1 text-[13px] font-medium tabular-nums'>\n          {ESTIMATE_VALUE}\n        </span>\n        <Button variant='outline' onClick={save}>\n          Save\n        </Button>\n      </div>\n    </Tile>\n  );\n}\n\nfunction waitForExport() {\n  return new Promise<void>((resolve) => {\n    setTimeout(resolve, EXPORT_DURATION_MS);\n  });\n}\n\nfunction exportLabelOf(isExporting: boolean) {\n  if (isExporting) {\n    return 'Exporting';\n  }\n  return 'Export report';\n}\n\nexport function ExportTile() {\n  const [isExporting, setIsExporting] = useState(false);\n\n  function startExport() {\n    setIsExporting(true);\n    const exporting = waitForExport();\n    toast.promise(exporting, {\n      loading: <MorphText text={`Preparing the ${REPORT_NAME}`} />,\n      success: {\n        message: <MorphText text={`${REPORT_NAME} is ready`} />,\n        description: `Sent to ${REPORT_RECIPIENT} as a PDF`,\n      },\n      finally: () => setIsExporting(false),\n    });\n  }\n\n  return (\n    <Tile\n      title='Loading, then the result'\n      line='One toast follows the work and becomes its outcome when it ends'\n    >\n      <Button variant='outline' disabled={isExporting} onClick={startExport}>\n        <Swap swapKey={String(isExporting)}>\n          {isExporting && <LoaderIcon className='animate-spin' />}\n          {!isExporting && <DownloadIcon />}\n        </Swap>\n        <AnimatedSize axis='width'>\n          <MorphText text={exportLabelOf(isExporting)} />\n        </AnimatedSize>\n      </Button>\n    </Tile>\n  );\n}\n\nexport function ArchiveTile() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [isArchived, setIsArchived] = useState(false);\n  const presence = heightPresenceOf(shouldReduceMotion);\n\n  function restore() {\n    setIsArchived(false);\n  }\n\n  function archive() {\n    setIsArchived(true);\n    toast('Task archived', {\n      description: `${ARCHIVABLE_TASK.key} ${ARCHIVABLE_TASK.title}`,\n      action: { label: 'Undo', onClick: restore },\n    });\n  }\n\n  return (\n    <Tile\n      title='Undo'\n      line='A reversible action runs at once and keeps a way back for a few seconds'\n    >\n      <AnimatedSize>\n        <AnimatePresence mode='popLayout' initial={false}>\n          {!isArchived && (\n            <motion.div key='task' {...presence} className='overflow-hidden'>\n              <div className='hairline-ring ring-border flex h-10 items-center gap-2.5 rounded-lg ps-3 pe-1'>\n                <span className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n                  {ARCHIVABLE_TASK.key}\n                </span>\n                <span className='min-w-0 flex-1 truncate text-[13px]'>\n                  {ARCHIVABLE_TASK.title}\n                </span>\n                <Button variant='ghost' size='sm' onClick={archive}>\n                  <ArchiveIcon />\n                  Archive\n                </Button>\n              </div>\n            </motion.div>\n          )}\n          {isArchived && (\n            <motion.div key='archived' {...fadePresence()}>\n              <div className='hairline-border border-foreground/20 text-muted-foreground flex h-10 items-center justify-between gap-2 rounded-lg border-dashed ps-3 pe-1 text-[13px]'>\n                <span className='truncate'>\n                  {ARCHIVABLE_TASK.key} is archived\n                </span>\n                <Button variant='ghost' size='sm' onClick={restore}>\n                  <RotateCcwIcon />\n                  Restore\n                </Button>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </AnimatedSize>\n    </Tile>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-02/toast-tiles.tsx"
    },
    {
      "path": "registry/ndeko/blocks/notifications/notifications-02/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-02/motion-parts.tsx"
    },
    {
      "path": "registry/ndeko/blocks/notifications/notifications-02/data.ts",
      "content": "export const TEAM_NAME = 'Mossline Web';\n\nexport const INVITE_EMAIL = 'sana@example.com';\n\nexport const REPORT_NAME = 'October report';\n\nexport const REPORT_RECIPIENT = 'amara@example.com';\n\nexport const EXPORT_DURATION_MS = 1800;\n\nexport const ESTIMATE_VALUE = '2h 30m';\n\nexport const ARCHIVABLE_TASK = {\n  key: 'MOS-148',\n  title: 'Booking calendar skips the first week on Safari',\n};\n",
      "type": "registry:component",
      "target": "components/blocks/notifications-02/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "notifications"
  ],
  "type": "registry:block"
}