{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alert",
  "title": "Alert",
  "description": "Soft, solid, outline, left-accent, glass, neo and full-width banner alerts with tone-picked icons, actions, slide, fade, shake or pop entrances, smooth collapse on dismiss and a pausable auto-dismiss countdown.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/core/alert.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { Bell, CircleAlert, CircleCheck, Info, Sparkles, TriangleAlert, X } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, ease as easing } from \"@/lib/goodui-motion\"\n\n/*\n * One alert, independent layers: every axis combines with every other.\n *   variant   soft / solid / outline / left-accent / glass / neo / banner (full-width top bar)\n *   tone      picks the color and the default icon\n *   shadow, shape, size\n *   animation how it enters: none / slide-down / fade / shake / pop\n * plus title, description (children), actions, dismissible (collapses smoothly) and autoDismiss\n * (a countdown bar that pauses on hover or focus).\n */\n\nexport type AlertVariant = \"soft\" | \"solid\" | \"outline\" | \"left-accent\" | \"glass\" | \"neo\" | \"banner\"\nexport type AlertTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type AlertShadow = \"none\" | \"sm\" | \"md\" | \"lg\"\nexport type AlertAnimation = \"none\" | \"slide-down\" | \"fade\" | \"shake\" | \"pop\"\nexport type AlertShape = \"square\" | \"rounded\" | \"pill\"\nexport type AlertSize = \"sm\" | \"md\" | \"lg\"\n\nexport type AlertLabels = { dismiss: string }\nconst DEFAULT_LABELS: AlertLabels = { dismiss: \"Dismiss\" }\n\nexport type AlertProps = Omit<React.ComponentProps<\"div\">, \"title\"> & {\n  /** soft (default), solid, outline, left-accent stripe, frosted glass, neo-brutalist, or banner (full-width bar, centered, ignores size and shape). */\n  variant?: AlertVariant\n  /** Color and default icon. danger and warning use role=\"alert\", the rest role=\"status\". */\n  tone?: AlertTone\n  /** Drop shadow. Ignored by neo, which has its own offset shadow. */\n  shadow?: AlertShadow\n  /** Entrance animation, played on mount. */\n  animation?: AlertAnimation\n  shape?: AlertShape\n  size?: AlertSize\n  /** Bold first line; children render as the description under it. */\n  title?: React.ReactNode\n  /** Replaces the tone's icon. */\n  icon?: React.ReactNode\n  /** Hides the icon entirely. */\n  hideIcon?: boolean\n  /** Buttons or links, shown under the text (inline on the banner). */\n  actions?: React.ReactNode\n  /** Shows a × button. */\n  dismissible?: boolean\n  /** Close automatically after this many ms (true = 5000), with a countdown bar. Pauses on hover and focus. */\n  autoDismiss?: boolean | number\n  /** Controlled visibility. */\n  open?: boolean\n  /** Initial visibility when uncontrolled. */\n  defaultOpen?: boolean\n  /** Called with false when the × button or the auto-dismiss timer closes it. */\n  onOpenChange?: (open: boolean) => void\n  /** Called after the collapse animation finishes. */\n  onDismiss?: () => void\n  /** false shrinks the alert to its content. */\n  fullWidth?: boolean\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<AlertLabels>\n}\n\nconst CSS = `\n.pc-alert{--pc-c:var(--primary);--pc-fg:var(--primary-foreground);isolation:isolate}\n.pc-alert[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.pc-alert[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.pc-alert[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.pc-alert[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.pc-alert[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .pc-alert[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .pc-alert[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .pc-alert[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.pc-alert{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.pc-alert[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n\n.pc-alert{border:1px solid transparent;color:var(--foreground);box-shadow:var(--pc-v,0 0 #0000),var(--pc-sh,0 0 #0000)}\n.pc-alert-icon{color:var(--pc-ink)}\n.pc-alert-desc{color:color-mix(in oklab,var(--foreground) 72%,transparent)}\n.pc-alert[data-variant=soft]{background:color-mix(in oklab,var(--pc-c) 9%,var(--background));border-color:color-mix(in oklab,var(--pc-c) 24%,transparent)}\n.pc-alert[data-variant=soft] .pc-alert-title{color:var(--pc-ink)}\n.pc-alert[data-variant=solid],.pc-alert[data-variant=banner]{background:var(--pc-c);color:var(--pc-fg)}\n.pc-alert[data-variant=solid] .pc-alert-icon,.pc-alert[data-variant=banner] .pc-alert-icon{color:color-mix(in oklab,var(--pc-fg) 88%,transparent)}\n.pc-alert[data-variant=solid] .pc-alert-desc,.pc-alert[data-variant=banner] .pc-alert-desc{color:var(--pc-fg)}\n.pc-alert[data-variant=banner]{border-width:0 0 1px;border-color:color-mix(in oklab,var(--pc-c) 70%,black)}\n.pc-alert[data-variant=outline]{background:var(--background);border-color:color-mix(in oklab,var(--pc-c) 50%,var(--border))}\n.pc-alert[data-variant=left-accent]{background:var(--card);border-color:var(--border);--pc-v:inset 4px 0 0 var(--pc-c)}\n.pc-alert[data-variant=left-accent]:dir(rtl){--pc-v:inset -4px 0 0 var(--pc-c)}\n.pc-alert[data-variant=glass]{background:color-mix(in oklab,var(--background) 50%,transparent);border-color:color-mix(in oklab,var(--foreground) 14%,transparent);-webkit-backdrop-filter:blur(16px) saturate(1.6);backdrop-filter:blur(16px) saturate(1.6);--pc-v:inset 0 1px 0 color-mix(in oklab,white 40%,transparent)}\n.pc-alert[data-variant=neo]{background:color-mix(in oklab,var(--pc-c) 16%,var(--background));border:2px solid var(--foreground);--pc-v:4px 4px 0 var(--foreground)}\n.pc-alert[data-variant=neo] .pc-alert-icon{color:var(--foreground)}\n\n.pc-alert[data-shadow=sm]{--pc-sh:0 1px 3px rgb(0 0 0/.1)}\n.pc-alert[data-shadow=md]{--pc-sh:0 8px 20px -8px rgb(0 0 0/.22)}\n.pc-alert[data-shadow=lg]{--pc-sh:0 18px 40px -14px rgb(0 0 0/.3)}\n\n.pc-alert-x{display:inline-flex;align-items:center;justify-content:center;border-radius:6px;opacity:.6;cursor:pointer;transition:opacity .15s,background-color .15s}\n.pc-alert-x:hover{opacity:1;background:color-mix(in oklab,currentColor 12%,transparent)}\n.pc-alert-bar{position:absolute;left:0;right:0;bottom:0;height:3px;background:color-mix(in oklab,var(--pc-c) 70%,transparent);transform-origin:left;animation:pc-alert-count var(--pc-dur) linear forwards;pointer-events:none}\n.pc-alert[data-variant=solid] .pc-alert-bar,.pc-alert[data-variant=banner] .pc-alert-bar{background:color-mix(in oklab,var(--pc-fg) 75%,transparent)}\n.pc-alert[data-paused] .pc-alert-bar{animation-play-state:paused}\n.pc-alert-bar:dir(rtl){transform-origin:right}\n@keyframes pc-alert-count{from{transform:scaleX(1)}to{transform:scaleX(0)}}\n\n.pc-alert[data-anim=slide-down]{animation:pc-alert-down .35s var(--pc-ease-out) both}\n@keyframes pc-alert-down{from{transform:translateY(-10px);opacity:0}to{transform:none;opacity:1}}\n.pc-alert[data-anim=fade]{animation:pc-alert-fade .35s ease both}\n@keyframes pc-alert-fade{from{opacity:0}to{opacity:1}}\n.pc-alert[data-anim=pop]{animation:pc-alert-pop .4s var(--pc-ease-spring) both}\n@keyframes pc-alert-pop{from{transform:scale(.94);opacity:0}to{transform:none;opacity:1}}\n.pc-alert[data-anim=shake]{animation:pc-alert-shake .5s cubic-bezier(.36,.07,.19,.97) both}\n@keyframes pc-alert-shake{10%,90%{transform:translateX(-1px)}20%,80%{transform:translateX(2px)}30%,50%,70%{transform:translateX(-5px)}40%,60%{transform:translateX(5px)}}\n@media (prefers-reduced-motion:reduce){\n  .pc-alert,.pc-alert *{transition:none!important}\n  .pc-alert[data-anim]{animation:none!important}\n  .pc-alert-bar{animation-duration:0s!important;display:none}\n}\n`\n\nconst ICONS: Record<AlertTone, React.ComponentType<{ className?: string }>> = {\n  primary: Sparkles,\n  neutral: Bell,\n  success: CircleCheck,\n  warning: TriangleAlert,\n  danger: CircleAlert,\n  info: Info,\n}\n\nconst SIZES: Record<AlertSize, string> = {\n  sm: \"gap-2.5 px-3 py-2.5 text-[13px] [&_[data-slot=alert-icon]_svg]:size-4\",\n  md: \"gap-3 px-4 py-3.5 text-sm [&_[data-slot=alert-icon]_svg]:size-[18px]\",\n  lg: \"gap-3.5 px-5 py-4.5 text-[15px] [&_[data-slot=alert-icon]_svg]:size-5\",\n}\nconst SHAPES: Record<AlertShape, string> = { square: \"rounded-none\", rounded: \"rounded-xl\", pill: \"rounded-[1.75rem]\" }\n\nexport function Alert({\n  variant = \"soft\",\n  tone = \"info\",\n  shadow = \"none\",\n  animation = \"none\",\n  shape = \"rounded\",\n  size = \"md\",\n  title,\n  icon,\n  hideIcon,\n  actions,\n  dismissible,\n  autoDismiss,\n  open: openProp,\n  defaultOpen = true,\n  onOpenChange,\n  onDismiss,\n  fullWidth = true,\n  className,\n  children,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  labels,\n  ...props\n}: AlertProps) {\n  const l = useLabels(\"alert\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion()\n  const [innerOpen, setInnerOpen] = React.useState(defaultOpen)\n  const open = openProp ?? innerOpen\n  // \"closing\" keeps it mounted while it collapses.\n  const [phase, setPhase] = React.useState<\"open\" | \"closing\" | \"closed\">(open ? \"open\" : \"closed\")\n  const [hover, setHover] = React.useState(false)\n  const [focus, setFocus] = React.useState(false)\n  const paused = hover || focus\n\n  React.useEffect(() => {\n    setPhase((p) => (open ? \"open\" : p === \"open\" ? \"closing\" : p))\n  }, [open])\n\n  // Uncontrolled: a new message brings a dismissed alert back.\n  const duration = autoDismiss === true ? 5000 : typeof autoDismiss === \"number\" ? autoDismiss : 0\n  const content = typeof title === \"string\" || typeof children === \"string\" ? `${variant}|${tone}|${duration}|${String(title)}|${String(children)}` : null\n  const first = React.useRef(true)\n  React.useEffect(() => {\n    if (first.current) {\n      first.current = false\n      return\n    }\n    if (openProp === undefined && content !== null) setInnerOpen(true)\n  }, [content, openProp])\n\n  const close = React.useCallback(() => {\n    if (openProp === undefined) setInnerOpen(false)\n    onOpenChange?.(false)\n  }, [openProp, onOpenChange])\n\n  // Auto-dismiss timer with pause: tracks the remaining time across hovers.\n  const remaining = React.useRef(duration)\n  const [run, setRun] = React.useState(0)\n  React.useEffect(() => {\n    remaining.current = duration\n    setRun((r) => r + 1)\n  }, [duration, content])\n  React.useEffect(() => {\n    if (!duration || phase !== \"open\" || paused) return\n    const start = Date.now()\n    const t = setTimeout(close, remaining.current)\n    return () => {\n      clearTimeout(t)\n      remaining.current = Math.max(0, remaining.current - (Date.now() - start))\n    }\n  }, [duration, phase, paused, close, run])\n\n  if (phase === \"closed\") return null\n\n  const Icon = ICONS[tone]\n  const iconEl = hideIcon ? null : (icon ?? <Icon />)\n  const banner = variant === \"banner\"\n  const role = tone === \"danger\" || tone === \"warning\" ? \"alert\" : \"status\"\n\n  const body = (\n    <div\n      data-slot=\"alert\"\n      role={role}\n      data-variant={variant}\n      data-tone={tone}\n      data-shadow={variant === \"neo\" ? \"none\" : shadow}\n      data-anim={animation}\n      data-paused={paused ? \"\" : undefined}\n      onPointerEnter={(e) => {\n        setHover(true)\n        onPointerEnter?.(e)\n      }}\n      onPointerLeave={(e) => {\n        setHover(false)\n        onPointerLeave?.(e)\n      }}\n      onFocus={(e) => {\n        setFocus(true)\n        onFocus?.(e)\n      }}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocus(false)\n        onBlur?.(e)\n      }}\n      className={cn(\n        \"pc-alert relative flex overflow-hidden\",\n        banner ? \"items-center justify-center gap-3 px-4 py-2.5 text-sm\" : cn(\"items-start\", SIZES[size], SHAPES[shape]),\n        className,\n      )}\n      {...props}\n    >\n      {iconEl && (\n        <span data-slot=\"alert-icon\" className={cn(\"pc-alert-icon inline-flex shrink-0 [&_svg]:shrink-0\", banner ? \"[&_svg]:size-4\" : \"mt-px\")} aria-hidden=\"true\">\n          {iconEl}\n        </span>\n      )}\n      <div className={cn(\"min-w-0\", banner ? \"flex flex-wrap items-center justify-center gap-x-3 gap-y-1.5 text-center\" : \"flex flex-1 flex-col gap-1\")}>\n        {title && <div className={cn(\"pc-alert-title leading-snug font-semibold\", banner && \"inline\")}>{title}</div>}\n        {children && <div className={cn(\"pc-alert-desc leading-relaxed\", banner && \"inline\")}>{children}</div>}\n        {actions && <div className={cn(\"flex flex-wrap items-center gap-2\", !banner && \"mt-2\")}>{actions}</div>}\n      </div>\n      {dismissible && (\n        <button\n          type=\"button\"\n          aria-label={l.dismiss}\n          onClick={close}\n          className={cn(\"pc-press pc-alert-x shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-current/40 [&_svg]:size-4\", size === \"sm\" && !banner ? \"size-6 -my-0.5 -me-1\" : \"size-7 -my-1 -me-1.5\")}\n        >\n          <X />\n        </button>\n      )}\n      {duration > 0 && phase === \"open\" && <span key={run} className=\"pc-alert-bar\" style={{ \"--pc-dur\": `${duration}ms` } as React.CSSProperties} aria-hidden=\"true\" />}\n    </div>\n  )\n\n  return (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-alert\" precedence=\"default\">\n        {CSS}\n      </style>\n      <motion.div\n        data-slot=\"alert-collapse\"\n        className={cn(fullWidth ? \"w-full\" : \"w-fit max-w-full\", \"[&>[data-slot=alert]]:w-full\", phase === \"closing\" && \"overflow-hidden\")}\n        initial={false}\n        animate={phase === \"closing\" ? { height: 0, opacity: 0 } : { height: \"auto\", opacity: 1 }}\n        transition={reduce ? { duration: 0 } : { height: { duration: 0.28, ease: easing.inOut, delay: 0.08 }, opacity: { duration: 0.18 } }}\n        onAnimationComplete={() => {\n          if (phase !== \"closing\") return\n          setPhase(\"closed\")\n          onDismiss?.()\n        }}\n      >\n        {body}\n      </motion.div>\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/alert.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}