{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-drop-pulse",
  "title": "File drop zone",
  "description": "Drag-and-drop zone whose border pulses while files hover, then lists files with type icons, springy progress bars, size and type errors, and undo on remove.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/inputs/file-drop-pulse.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { AlertCircle, Check, File, FileArchive, FileImage, FileSpreadsheet, FileText, FileVideo, UploadCloud, X } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n@keyframes pc-file-drop-pulse-ring { 0% { opacity: .9; transform: scale(1) } 100% { opacity: 0; transform: scale(1.035, 1.09) } }\n.pc-file-drop-pulse-zone[data-dragging]::before, .pc-file-drop-pulse-zone[data-dragging]::after {\n  content: \"\"; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none;\n  border: 2px solid var(--pc-file-drop-pulse-color, var(--primary));\n  animation: pc-file-drop-pulse-ring 1.3s var(--pc-ease-out) infinite;\n}\n.pc-file-drop-pulse-zone[data-dragging]::after { animation-delay: .65s }\n@media (prefers-reduced-motion: reduce) {\n  .pc-file-drop-pulse-zone[data-dragging]::before { animation: none; opacity: 1 }\n  .pc-file-drop-pulse-zone[data-dragging]::after { display: none }\n}\n`\n\nexport type UploadStatus = \"uploading\" | \"done\" | \"error\"\n\nexport type UploadItem = {\n  id: string\n  file: File\n  progress: number\n  status: UploadStatus\n  error?: string\n}\n\nexport type FileDropPulseHandle = {\n  /** Add files as if they were dropped (validation included). */\n  addFiles: (files: File[]) => void\n  clear: () => void\n}\n\nexport type FileDropPulseLabels = {\n  files: string\n  uploaded: string\n  uploadFailed: string\n  uploading: (name: string) => string\n  cancel: (name: string) => string\n  remove: (name: string) => string\n  /** Default main line of the drop zone (the title prop overrides it). */\n  title: string\n  /** Main line while files hover the zone. */\n  release: string\n  typeNotAllowed: string\n  /** Gets the formatted max size, e.g. \"10 MB\". */\n  tooLarge: (max: string) => string\n  skipped: (count: number, limit: number) => string\n  /** Default hint part for maxSize; gets the formatted size. */\n  upTo: (size: string) => string\n  /** Default hint part for maxFiles. */\n  maxFiles: (count: number) => string\n  /** Undo bar text after a removal. */\n  removed: (name: string) => string\n  undo: string\n}\nconst DEFAULT_LABELS: FileDropPulseLabels = {\n  files: \"Files\",\n  uploaded: \"Uploaded\",\n  uploadFailed: \"Upload failed\",\n  uploading: (name) => `Uploading ${name}`,\n  cancel: (name) => `Cancel ${name}`,\n  remove: (name) => `Remove ${name}`,\n  title: \"Drop files here or browse\",\n  release: \"Release to upload\",\n  typeNotAllowed: \"File type not allowed\",\n  tooLarge: (max) => `Too large · max ${max}`,\n  skipped: (count, limit) => `${count} file${count > 1 ? \"s\" : \"\"} skipped · limit is ${limit}`,\n  upTo: (size) => `up to ${size}`,\n  maxFiles: (count) => `${count} files max`,\n  removed: (name) => `Removed ${name}`,\n  undo: \"Undo\",\n}\n\nexport type FileDropPulseProps = Omit<React.ComponentProps<\"div\">, \"onChange\" | \"ref\"> & {\n  /** Imperative handle with addFiles(files) and clear(). */\n  ref?: React.Ref<FileDropPulseHandle>\n  /** Same format as the input `accept` attribute: \"image/*,.pdf,.csv\". */\n  accept?: string\n  /** Max size per file in bytes. */\n  maxSize?: number\n  /** Max files kept in the list; failed files do not count, extra files are skipped with a notice. */\n  maxFiles?: number\n  /** Allow several files at once; when false a new file replaces the list (and cancels the replaced upload). */\n  multiple?: boolean\n  disabled?: boolean\n  /**\n   * Upload one file and report progress 0–100. Defaults to a simulated upload.\n   * Reject (throw) to mark the file as failed.\n   */\n  upload?: (file: File, onProgress: (percent: number) => void, signal: AbortSignal) => Promise<void>\n  /** Called with the whole list whenever a file is added, progresses, finishes, fails or is removed (not on mount). */\n  onFilesChange?: (items: UploadItem[]) => void\n  /** Main line in the drop zone; defaults to labels.title. */\n  title?: React.ReactNode\n  /** Second line in the drop zone; defaults to accept, max size and max files. */\n  hint?: React.ReactNode\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<FileDropPulseLabels>\n}\n\nexport const formatBytes = (n: number) =>\n  n < 1024 ? `${n} B` : n < 1024 ** 2 ? `${(n / 1024).toFixed(0)} KB` : `${(n / 1024 ** 2).toFixed(n < 10 * 1024 ** 2 ? 1 : 0)} MB`\n\nfunction iconFor(file: File) {\n  const t = file.type\n  const ext = file.name.split(\".\").pop()?.toLowerCase() ?? \"\"\n  if (t.startsWith(\"image/\")) return { Icon: FileImage, tone: \"text-sky-600 bg-sky-500/10 dark:text-sky-400\" }\n  if (t.startsWith(\"video/\")) return { Icon: FileVideo, tone: \"text-violet-600 bg-violet-500/10 dark:text-violet-400\" }\n  if (t === \"application/pdf\" || ext === \"pdf\") return { Icon: FileText, tone: \"text-rose-600 bg-rose-500/10 dark:text-rose-400\" }\n  if ([\"csv\", \"xls\", \"xlsx\", \"numbers\"].includes(ext)) return { Icon: FileSpreadsheet, tone: \"text-emerald-600 bg-emerald-500/10 dark:text-emerald-400\" }\n  if ([\"zip\", \"rar\", \"7z\", \"gz\"].includes(ext)) return { Icon: FileArchive, tone: \"text-amber-600 bg-amber-500/10 dark:text-amber-400\" }\n  if ([\"doc\", \"docx\", \"txt\", \"md\", \"rtf\"].includes(ext)) return { Icon: FileText, tone: \"text-blue-600 bg-blue-500/10 dark:text-blue-400\" }\n  return { Icon: File, tone: \"text-muted-foreground bg-muted\" }\n}\n\nfunction matches(file: File, accept?: string) {\n  if (!accept) return true\n  const name = file.name.toLowerCase()\n  return accept\n    .split(\",\")\n    .map((a) => a.trim().toLowerCase())\n    .some((a) => (a.startsWith(\".\") ? name.endsWith(a) : a.endsWith(\"/*\") ? file.type.startsWith(a.slice(0, -1)) : file.type === a))\n}\n\n/** Simulated upload: random-sized steps, roughly 1–2.5 s per file. */\nconst simulate: NonNullable<FileDropPulseProps[\"upload\"]> = (_file, onProgress, signal) =>\n  new Promise((resolve, reject) => {\n    let p = 0\n    const t = window.setInterval(() => {\n      p = Math.min(100, p + 4 + Math.random() * 11)\n      onProgress(p)\n      if (p >= 100) {\n        window.clearInterval(t)\n        resolve()\n      }\n    }, 140)\n    signal.addEventListener(\"abort\", () => {\n      window.clearInterval(t)\n      reject(new DOMException(\"Aborted\", \"AbortError\"))\n    })\n  })\n\nlet seq = 0\n\n/** Drag-and-drop zone that pulses while files hover it, then lists files with animated progress, errors and undo. */\nexport function FileDropPulse({\n  ref,\n  accept,\n  maxSize,\n  maxFiles,\n  multiple = true,\n  disabled,\n  upload = simulate,\n  onFilesChange,\n  title,\n  hint,\n  className,\n  labels,\n  ...props\n}: FileDropPulseProps) {\n  const l = useLabels(\"file-drop-pulse\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const [items, setItems] = React.useState<UploadItem[]>([])\n  const [dragging, setDragging] = React.useState(false)\n  const [notice, setNotice] = React.useState<string | null>(null)\n  const [removed, setRemoved] = React.useState<{ item: UploadItem; index: number } | null>(null)\n  const depth = React.useRef(0)\n  const inputRef = React.useRef<HTMLInputElement>(null)\n  const controllers = React.useRef(new Map<string, AbortController>())\n  const itemsRef = React.useRef(items)\n  const reported = React.useRef(items)\n  const rootRef = React.useRef<HTMLDivElement>(null)\n  const [rtl, setRtl] = React.useState(false)\n  const uid = React.useId()\n\n  React.useLayoutEffect(() => {\n    if (rootRef.current) setRtl(getComputedStyle(rootRef.current).direction === \"rtl\")\n  }, [])\n\n  React.useEffect(() => {\n    itemsRef.current = items\n    // Skip the initial empty list (and StrictMode's re-run): report real changes only.\n    if (reported.current === items) return\n    reported.current = items\n    onFilesChange?.(items)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [items])\n\n  React.useEffect(() => {\n    const map = controllers.current\n    return () => map.forEach((c) => c.abort())\n  }, [])\n\n  React.useEffect(() => {\n    if (!removed) return\n    const t = window.setTimeout(() => setRemoved(null), 5000)\n    return () => window.clearTimeout(t)\n  }, [removed])\n\n  const patch = (id: string, p: Partial<UploadItem>) => setItems((list) => list.map((it) => (it.id === id ? { ...it, ...p } : it)))\n\n  const start = (item: UploadItem) => {\n    const ctrl = new AbortController()\n    controllers.current.set(item.id, ctrl)\n    upload(item.file, (pct) => patch(item.id, { progress: Math.round(pct) }), ctrl.signal).then(\n      () => {\n        controllers.current.delete(item.id)\n        patch(item.id, { progress: 100, status: \"done\" })\n      },\n      (err: unknown) => {\n        controllers.current.delete(item.id)\n        if (ctrl.signal.aborted) return\n        patch(item.id, { status: \"error\", error: err instanceof Error ? err.message : l.uploadFailed })\n      },\n    )\n  }\n\n  const addFiles = (files: File[]) => {\n    if (disabled || files.length === 0) return\n    // In single mode the new file replaces the list, so the files already there don't use up room.\n    const current = multiple ? itemsRef.current.filter((i) => i.status !== \"error\").length : 0\n    const room = maxFiles ? Math.max(0, maxFiles - current) : Infinity\n    const list = multiple ? files : files.slice(0, 1)\n    const accepted = list.slice(0, room)\n    const skipped = list.length - accepted.length\n    const fresh: UploadItem[] = accepted.map((file) => {\n      const id = `${uid}-${++seq}`\n      if (!matches(file, accept)) return { id, file, progress: 0, status: \"error\", error: l.typeNotAllowed }\n      if (maxSize && file.size > maxSize) return { id, file, progress: 0, status: \"error\", error: l.tooLarge(formatBytes(maxSize)) }\n      return { id, file, progress: 0, status: \"uploading\" }\n    })\n    if (!multiple && fresh.length > 0) {\n      // Cancel the uploads being replaced.\n      controllers.current.forEach((c) => c.abort())\n      controllers.current.clear()\n      setRemoved(null)\n    }\n    setItems((prev) => (multiple ? [...prev, ...fresh] : fresh.length > 0 ? fresh : prev))\n    fresh.filter((f) => f.status === \"uploading\").forEach(start)\n    setNotice(skipped > 0 && maxFiles ? l.skipped(skipped, maxFiles) : null)\n  }\n\n  React.useImperativeHandle(ref, () => ({\n    addFiles,\n    clear: () => {\n      controllers.current.forEach((c) => c.abort())\n      controllers.current.clear()\n      setItems([])\n      setRemoved(null)\n      setNotice(null)\n    },\n  }))\n\n  const remove = (item: UploadItem) => {\n    controllers.current.get(item.id)?.abort()\n    controllers.current.delete(item.id)\n    const index = items.findIndex((i) => i.id === item.id)\n    setItems((l) => l.filter((i) => i.id !== item.id))\n    if (item.status !== \"error\") setRemoved({ item, index })\n  }\n\n  const undo = () => {\n    if (!removed) return\n    const { item, index } = removed\n    // An unfinished upload restarts from zero.\n    const back: UploadItem = item.status === \"done\" ? item : { ...item, progress: 0, status: \"uploading\" }\n    if (!multiple) {\n      // Single mode keeps one file: the restored one replaces whatever is there now.\n      controllers.current.forEach((c) => c.abort())\n      controllers.current.clear()\n    }\n    setItems((prev) => (multiple ? [...prev.slice(0, index), back, ...prev.slice(index)] : [back]))\n    if (back.status === \"uploading\") start(back)\n    setRemoved(null)\n  }\n\n  const hasFiles = (e: React.DragEvent) => Array.from(e.dataTransfer.types).includes(\"Files\")\n\n  return (\n    <div ref={rootRef} className={cn(\"grid w-full gap-3\", className)} {...props}>\n      <GooduiTokens />\n      <style href=\"pc-file-drop-pulse\" precedence=\"default\">\n        {CSS}\n      </style>\n      <div\n        role=\"button\"\n        tabIndex={disabled ? -1 : 0}\n        aria-disabled={disabled || undefined}\n        aria-describedby={`${uid}-hint`}\n        data-dragging={dragging || undefined}\n        onClick={() => !disabled && inputRef.current?.click()}\n        onKeyDown={(e) => {\n          if ((e.key === \"Enter\" || e.key === \" \") && !disabled) {\n            e.preventDefault()\n            inputRef.current?.click()\n          }\n        }}\n        onDragEnter={(e) => {\n          if (!hasFiles(e) || disabled) return\n          e.preventDefault()\n          depth.current++\n          setDragging(true)\n        }}\n        onDragOver={(e) => {\n          if (!hasFiles(e) || disabled) return\n          e.preventDefault()\n          e.dataTransfer.dropEffect = \"copy\"\n        }}\n        onDragLeave={() => {\n          depth.current = Math.max(0, depth.current - 1)\n          if (depth.current === 0) setDragging(false)\n        }}\n        onDrop={(e) => {\n          e.preventDefault()\n          depth.current = 0\n          setDragging(false)\n          addFiles(Array.from(e.dataTransfer.files))\n        }}\n        className={cn(\n          \"pc-file-drop-pulse-zone relative flex cursor-pointer flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-border bg-muted/30 px-4 py-8 text-center transition-[border-color,background-color,box-shadow] duration-200 outline-none\",\n          \"hover:border-foreground/25 hover:bg-muted/50 focus-visible:ring-3 focus-visible:ring-ring/50\",\n          \"data-dragging:border-solid data-dragging:border-primary data-dragging:bg-primary/5 data-dragging:shadow-[0_0_0_6px_color-mix(in_oklab,var(--primary)_12%,transparent),0_0_32px_-4px_color-mix(in_oklab,var(--primary)_35%,transparent)]\",\n          disabled && \"pointer-events-none opacity-50\",\n        )}\n      >\n        <motion.div\n          className=\"grid size-11 place-items-center rounded-full border bg-background shadow-[var(--pc-e1)]\"\n          animate={dragging && !reduce ? { y: -6, scale: 1.08 } : { y: 0, scale: 1 }}\n          transition={spring.play}\n        >\n          <motion.span\n            className=\"grid place-items-center\"\n            animate={dragging && !reduce ? { y: [0, -3, 0] } : { y: 0 }}\n            transition={dragging ? { duration: 0.9, repeat: Infinity, ease: \"easeInOut\" } : { duration: 0.2 }}\n          >\n            <UploadCloud className={cn(\"size-5 transition-colors\", dragging ? \"text-primary\" : \"text-muted-foreground\")} />\n          </motion.span>\n        </motion.div>\n        <div className=\"text-sm font-medium\">{dragging ? l.release : (title ?? l.title)}</div>\n        <div id={`${uid}-hint`} className=\"text-xs text-muted-foreground\">\n          {hint ?? [accept, maxSize && l.upTo(formatBytes(maxSize)), maxFiles && l.maxFiles(maxFiles)].filter(Boolean).join(\" · \")}\n        </div>\n      </div>\n      {/* The native input sits outside the role=\"button\" zone, so the zone has no nested interactive content. */}\n      <input\n          ref={inputRef}\n          type=\"file\"\n          className=\"sr-only\"\n          tabIndex={-1}\n          aria-hidden=\"true\"\n          accept={accept}\n          multiple={multiple}\n          disabled={disabled}\n          onChange={(e) => {\n            addFiles(Array.from(e.target.files ?? []))\n            e.target.value = \"\"\n          }}\n        />\n\n      <AnimatePresence initial={false}>\n        {notice && (\n          <motion.p\n            role=\"alert\"\n            initial={{ opacity: 0, height: 0 }}\n            animate={{ opacity: 1, height: \"auto\" }}\n            exit={{ opacity: 0, height: 0 }}\n            className=\"overflow-hidden text-xs font-medium text-amber-700 dark:text-amber-400\"\n          >\n            {notice}\n          </motion.p>\n        )}\n      </AnimatePresence>\n\n      <ul className=\"grid gap-2\" aria-label={l.files}>\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {items.map((it) => {\n            const { Icon, tone } = iconFor(it.file)\n            return (\n              <motion.li\n                key={it.id}\n                layout={!reduce}\n                initial={reduce ? { opacity: 0 } : { opacity: 0, y: 12, scale: 0.97 }}\n                animate={it.status === \"error\" && !reduce ? { opacity: 1, y: 0, scale: 1, x: [0, -6, 6, -4, 4, 0] } : { opacity: 1, y: 0, scale: 1, x: 0 }}\n                exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.95, x: rtl ? -24 : 24, transition: { duration: 0.18 } }}\n                transition={{ ...spring.ui, x: { duration: 0.4 } }}\n                className={cn(\n                  \"flex items-center gap-3 rounded-lg border bg-card p-2.5 pe-2 shadow-xs\",\n                  it.status === \"error\" && \"border-destructive/40 bg-destructive/5\",\n                )}\n              >\n                <span className={cn(\"grid size-9 shrink-0 place-items-center rounded-md\", it.status === \"error\" ? \"bg-destructive/10 text-destructive\" : tone)}>\n                  {it.status === \"error\" ? <AlertCircle className=\"size-4\" /> : <Icon className=\"size-4\" />}\n                </span>\n                <div className=\"min-w-0 flex-1\">\n                  <div className=\"flex items-baseline justify-between gap-2\">\n                    <span className=\"truncate text-sm font-medium\">{it.file.name}</span>\n                    <span className=\"shrink-0 text-xs text-muted-foreground tabular-nums\">\n                      {it.status === \"uploading\" ? `${it.progress}%` : formatBytes(it.file.size)}\n                    </span>\n                  </div>\n                  {it.status === \"error\" ? (\n                    <p className=\"mt-0.5 text-xs text-destructive\">{it.error}</p>\n                  ) : (\n                    <div className=\"mt-1.5 flex items-center gap-2\">\n                      <div\n                        className=\"h-1.5 flex-1 overflow-hidden rounded-full bg-muted\"\n                        role=\"progressbar\"\n                        aria-label={l.uploading(it.file.name)}\n                        aria-valuemin={0}\n                        aria-valuemax={100}\n                        aria-valuenow={it.progress}\n                      >\n                        <motion.div\n                          className={cn(\"h-full origin-left rounded-full rtl:origin-right\", it.status === \"done\" ? \"bg-emerald-500\" : \"bg-primary\")}\n                          initial={false}\n                          animate={{ scaleX: it.progress / 100 }}\n                          transition={reduce ? { duration: 0 } : spring.morph}\n                        />\n                      </div>\n                      <AnimatePresence initial={false}>\n                        {it.status === \"done\" && (\n                          <motion.span\n                            initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.3 }}\n                            animate={{ opacity: 1, scale: 1 }}\n                            transition={spring.play}\n                            className=\"grid size-4 place-items-center rounded-full bg-emerald-500 text-white\"\n                          >\n                            <Check className=\"size-2.5\" strokeWidth={3.5} />\n                            <span className=\"sr-only\">{l.uploaded}</span>\n                          </motion.span>\n                        )}\n                      </AnimatePresence>\n                    </div>\n                  )}\n                </div>\n                <button\n                  type=\"button\"\n                  aria-label={it.status === \"uploading\" ? l.cancel(it.file.name) : l.remove(it.file.name)}\n                  onClick={() => remove(it)}\n                  className=\"pc-press grid size-7 shrink-0 place-items-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\"\n                >\n                  <X className=\"size-4\" />\n                </button>\n              </motion.li>\n            )\n          })}\n        </AnimatePresence>\n      </ul>\n\n      <AnimatePresence>\n        {removed && (\n          <motion.div\n            role=\"status\"\n            initial={reduce ? { opacity: 0 } : { opacity: 0, y: 8 }}\n            animate={{ opacity: 1, y: 0 }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, y: 8 }}\n            className=\"flex items-center justify-between gap-3 rounded-lg bg-foreground px-3 py-2 text-sm text-background shadow-[var(--pc-e2)]\"\n          >\n            <span className=\"truncate\">{l.removed(removed.item.file.name)}</span>\n            <button\n              type=\"button\"\n              onClick={undo}\n              className=\"pc-press shrink-0 rounded px-1.5 py-0.5 font-medium underline-offset-2 outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50\"\n            >\n              {l.undo}\n            </button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/file-drop-pulse.tsx"
    }
  ],
  "categories": [
    "components",
    "inputs"
  ],
  "type": "registry:component"
}