{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dropzone",
  "type": "registry:component",
  "title": "Dropzone",
  "description": "A file upload area with an animated dashed drag-over border, type and size checks, inline errors and a file list with simulated progress. It never uploads anything.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "site",
    "dropzone",
    "upload",
    "file",
    "drag and drop",
    "input",
    "progress"
  ],
  "docs": "https://hyperblur.dev/effects/dropzone",
  "files": [
    {
      "path": "registry/hyperblur/dropzone.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/dropzone.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface DropzoneFile {\n  id: string;\n  name: string;\n  size: number;\n  progress: number;\n  status: \"uploading\" | \"done\";\n  live: boolean;\n}\n\nexport interface DropzoneRejection {\n  name: string;\n  reason: string;\n}\n\nexport interface DropzoneInitialFile {\n  name: string;\n  size: number;\n  progress?: number;\n}\n\nexport interface DropzoneProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onDrop\" | \"children\"> {\n  accept?: string;\n  maxSize?: number;\n  maxFiles?: number;\n  multiple?: boolean;\n  simulate?: boolean;\n  disabled?: boolean;\n  title?: string;\n  hint?: string;\n  size?: \"md\" | \"sm\";\n  accent?: string;\n  defaultFiles?: DropzoneInitialFile[];\n  onFiles?: (files: File[]) => void;\n  onReject?: (rejections: DropzoneRejection[]) => void;\n  onRemove?: (file: DropzoneFile) => void;\n}\n\nconst css = `\n.hb-drz {\n  --hb-drz-accent: #2f7bff;\n  display: flex;\n  flex-direction: column;\n  gap: 8px;\n  width: 100%;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  text-align: left;\n}\n.hb-drz *, .hb-drz *::before, .hb-drz *::after { box-sizing: border-box; }\n.hb-drz-zone {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 10px;\n  width: 100%;\n  min-height: 148px;\n  padding: 24px 20px;\n  border-radius: 16px;\n  background: #0f0f0f;\n  text-align: center;\n  cursor: pointer;\n  outline: none;\n  transition: background-color 0.2s ease, transform 0.2s ease;\n}\n.hb-drz[data-size=\"sm\"] .hb-drz-zone {\n  flex-direction: row;\n  justify-content: flex-start;\n  gap: 12px;\n  min-height: 0;\n  padding: 12px 14px;\n  text-align: left;\n}\n.hb-drz-zone:hover { background: #131313; }\n.hb-drz-zone[data-drag=\"true\"] {\n  background: color-mix(in srgb, var(--hb-drz-accent) 9%, #0f0f0f);\n  transform: scale(1.01);\n}\n.hb-drz-zone[aria-disabled=\"true\"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }\n.hb-drz-zone:focus-visible { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-drz-accent); }\n.hb-drz-border {\n  position: absolute;\n  inset: 0.75px;\n  width: calc(100% - 1.5px);\n  height: calc(100% - 1.5px);\n  overflow: visible;\n  pointer-events: none;\n}\n.hb-drz-border rect {\n  fill: none;\n  stroke: #333333;\n  stroke-width: 1.5;\n  stroke-dasharray: 6 6;\n  transition: stroke 0.2s ease;\n}\n.hb-drz-zone:hover .hb-drz-border rect { stroke: #4a4a4a; }\n.hb-drz-zone[data-drag=\"true\"] .hb-drz-border rect {\n  stroke: var(--hb-drz-accent);\n  animation: hb-drz-march 0.7s linear infinite;\n}\n.hb-drz-icon {\n  display: inline-flex;\n  flex: none;\n  align-items: center;\n  justify-content: center;\n  width: 40px;\n  height: 40px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #171717;\n  color: #a1a1a1;\n  transition: color 0.2s ease, border-color 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-drz[data-size=\"sm\"] .hb-drz-icon { width: 34px; height: 34px; border-radius: 10px; }\n.hb-drz-icon svg { width: 20px; height: 20px; }\n.hb-drz-zone[data-drag=\"true\"] .hb-drz-icon {\n  border-color: var(--hb-drz-accent);\n  color: var(--hb-drz-accent);\n  transform: translateY(-3px);\n}\n.hb-drz-copy { min-width: 0; }\n.hb-drz-title { margin: 0; color: #ededed; font-size: 14px; font-weight: 500; line-height: 1.35; }\n.hb-drz[data-size=\"sm\"] .hb-drz-title { font-size: 13px; }\n.hb-drz-title u { color: var(--hb-drz-accent); text-decoration: none; }\n.hb-drz-hint { margin: 2px 0 0; color: #8f8f8f; font-size: 12px; line-height: 1.4; }\n.hb-drz-errors {\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n  margin: 0;\n  padding: 0;\n  list-style: none;\n}\n.hb-drz-error {\n  display: flex;\n  align-items: flex-start;\n  gap: 6px;\n  color: #ff6369;\n  font-size: 12px;\n  line-height: 1.4;\n  animation: hb-drz-rise 0.2s ease both;\n}\n.hb-drz-error svg { flex: none; width: 13px; height: 13px; margin-top: 1px; }\n.hb-drz-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }\n.hb-drz-file {\n  display: grid;\n  grid-template-columns: 30px minmax(0, 1fr) auto;\n  align-items: center;\n  gap: 10px;\n  padding: 8px 8px 8px 10px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #111111;\n  animation: hb-drz-rise 0.24s ease both;\n}\n.hb-drz-ext {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 30px;\n  height: 30px;\n  border-radius: 8px;\n  background: color-mix(in srgb, var(--hb-drz-accent) 14%, #171717);\n  color: var(--hb-drz-accent);\n  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 9px;\n  font-weight: 600;\n  letter-spacing: 0.04em;\n  text-transform: uppercase;\n}\n.hb-drz-main { display: flex; flex-direction: column; gap: 5px; min-width: 0; }\n.hb-drz-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }\n.hb-drz-name { flex: 1; min-width: 0; overflow: hidden; color: #ededed; font-size: 12.5px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }\n.hb-drz-size { flex: none; color: #8f8f8f; font-size: 11.5px; font-variant-numeric: tabular-nums; }\n.hb-drz-bar { position: relative; height: 4px; overflow: hidden; border-radius: 999px; background: #232323; }\n.hb-drz-fill {\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: var(--hb-drz-accent);\n  transform: scaleX(var(--hb-drz-p, 0));\n  transform-origin: 0 50%;\n  transition: transform 0.25s ease, background-color 0.3s ease;\n}\n.hb-drz-fill[data-live=\"true\"]::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);\n  transform: translateX(-100%);\n  animation: hb-drz-sweep 1.2s ease-in-out infinite;\n}\n.hb-drz-file[data-status=\"done\"] .hb-drz-fill { background: #3dd68c; }\n.hb-drz-side { display: flex; align-items: center; gap: 2px; }\n.hb-drz-pct { min-width: 32px; color: #a1a1a1; font-size: 11.5px; font-variant-numeric: tabular-nums; text-align: right; }\n.hb-drz-check { width: 18px; height: 18px; margin-right: 6px; color: #3dd68c; }\n.hb-drz-check circle { fill: rgba(61, 214, 140, 0.14); stroke: none; }\n.hb-drz-check path { stroke-dasharray: 14; stroke-dashoffset: 14; animation: hb-drz-draw 0.35s 0.05s ease forwards; }\n.hb-drz-rm {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 26px;\n  height: 26px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #6f6f6f;\n  cursor: pointer;\n  transition: background-color 0.15s ease, color 0.15s ease;\n}\n.hb-drz-rm:hover { background: rgba(255, 255, 255, 0.08); color: #ededed; }\n.hb-drz-rm:focus-visible { outline: 2px solid var(--hb-drz-accent); outline-offset: 1px; }\n.hb-drz-rm svg { width: 13px; height: 13px; }\n@keyframes hb-drz-march { to { stroke-dashoffset: -24; } }\n@keyframes hb-drz-sweep { to { transform: translateX(100%); } }\n@keyframes hb-drz-draw { to { stroke-dashoffset: 0; } }\n@keyframes hb-drz-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-drz-zone, .hb-drz-icon, .hb-drz-fill, .hb-drz-rm, .hb-drz-border rect { transition: none; }\n  .hb-drz-zone[data-drag=\"true\"] .hb-drz-border rect, .hb-drz-fill[data-live=\"true\"]::after, .hb-drz-file, .hb-drz-error { animation: none; }\n  .hb-drz-check path { animation: none; stroke-dashoffset: 0; }\n}\n`;\n\nfunction formatBytes(bytes: number) {\n  if (bytes < 1024) return `${bytes} B`;\n  if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;\n  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n\nfunction hashText(text: string) {\n  let h = 0;\n  for (let i = 0; i < text.length; i += 1) h = (h * 31 + text.charCodeAt(i)) >>> 0;\n  return h;\n}\n\nfunction matchesAccept(file: File, accept: string) {\n  const tokens = accept\n    .split(\",\")\n    .map((t) => t.trim().toLowerCase())\n    .filter(Boolean);\n  if (tokens.length === 0) return true;\n  const name = file.name.toLowerCase();\n  const type = file.type.toLowerCase();\n  return tokens.some((token) => {\n    if (token.startsWith(\".\")) return name.endsWith(token);\n    if (token.includes(\"/\")) {\n      const [group, sub] = token.split(\"/\");\n      return sub === \"*\" ? type.startsWith(`${group}/`) : type === token;\n    }\n    return false;\n  });\n}\n\nfunction describeAccept(accept: string) {\n  return accept\n    .split(\",\")\n    .map((t) => t.trim())\n    .filter(Boolean)\n    .map((t) => (t.startsWith(\".\") ? t.slice(1).toUpperCase() : t.split(\"/\")[0]))\n    .join(\", \");\n}\n\nfunction extOf(name: string) {\n  const dot = name.lastIndexOf(\".\");\n  return dot > 0 ? name.slice(dot + 1, dot + 5) : \"file\";\n}\n\nconst uploadIcon = (\n  <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"M12 16V4m0 0L7.5 8.5M12 4l4.5 4.5\" />\n    <path d=\"M4 15v2a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3v-2\" />\n  </svg>\n);\n\nconst alertIcon = (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <circle cx=\"8\" cy=\"8\" r=\"6.25\" />\n    <path d=\"M8 4.75v3.5M8 11h.01\" />\n  </svg>\n);\n\nexport function Dropzone({\n  accept = \"\",\n  maxSize = 10 * 1024 * 1024,\n  maxFiles = 6,\n  multiple = true,\n  simulate = false,\n  disabled = false,\n  title = \"Drop files here or browse\",\n  hint,\n  size = \"md\",\n  accent = \"#2f7bff\",\n  defaultFiles,\n  onFiles,\n  onReject,\n  onRemove,\n  className = \"\",\n  style,\n  ...rest\n}: DropzoneProps) {\n  const [files, setFiles] = React.useState<DropzoneFile[]>(() =>\n    (defaultFiles ?? []).map((f, i) => {\n      const progress = Math.min(100, Math.max(0, f.progress ?? 100));\n      return {\n        id: `initial-${i}`,\n        name: f.name,\n        size: f.size,\n        progress,\n        status: progress >= 100 ? \"done\" : \"uploading\",\n        live: false,\n      };\n    }),\n  );\n  const [errors, setErrors] = React.useState<string[]>([]);\n  const [dragging, setDragging] = React.useState(false);\n  const input = React.useRef<HTMLInputElement>(null);\n  const depth = React.useRef(0);\n  const seq = React.useRef(0);\n  const hintId = React.useId();\n\n  const running = simulate && files.some((f) => f.live && f.status === \"uploading\");\n\n  React.useEffect(() => {\n    if (!running) return;\n    const timer = window.setInterval(() => {\n      setFiles((prev) =>\n        prev.map((f) => {\n          if (!f.live || f.status !== \"uploading\") return f;\n          const step = 2 + (hashText(f.id) % 5) + (hashText(`${f.id}${Math.floor(f.progress)}`) % 7);\n          const progress = Math.min(100, f.progress + step);\n          return { ...f, progress, status: progress >= 100 ? \"done\" : \"uploading\" };\n        }),\n      );\n    }, 120);\n    return () => window.clearInterval(timer);\n  }, [running]);\n\n  function ingest(list: FileList | File[] | null) {\n    if (!list || disabled) return;\n    let incoming = Array.from(list);\n    if (incoming.length === 0) return;\n    const problems: string[] = [];\n    const rejected: DropzoneRejection[] = [];\n    const reject = (name: string, reason: string) => {\n      rejected.push({ name, reason });\n      problems.push(`${name}: ${reason}`);\n    };\n    let base = files;\n    if (!multiple) {\n      incoming = incoming.slice(0, 1);\n      base = [];\n    }\n    const accepted: File[] = [];\n    for (const file of incoming) {\n      if (accept && !matchesAccept(file, accept)) {\n        reject(file.name, `type not accepted${describeAccept(accept) ? `, use ${describeAccept(accept)}` : \"\"}`);\n      } else if (file.size > maxSize) {\n        reject(file.name, `${formatBytes(file.size)} is over the ${formatBytes(maxSize)} limit`);\n      } else if (base.length + accepted.length >= maxFiles) {\n        reject(file.name, `only ${maxFiles} ${maxFiles === 1 ? \"file is\" : \"files are\"} allowed`);\n      } else {\n        accepted.push(file);\n      }\n    }\n    setErrors(problems);\n    if (rejected.length) onReject?.(rejected);\n    if (accepted.length === 0) return;\n    const entries: DropzoneFile[] = accepted.map((file) => {\n      seq.current += 1;\n      return {\n        id: `file-${seq.current}-${file.name}`,\n        name: file.name,\n        size: file.size,\n        progress: simulate ? 0 : 100,\n        status: simulate ? \"uploading\" : \"done\",\n        live: true,\n      };\n    });\n    setFiles([...base, ...entries]);\n    onFiles?.(accepted);\n  }\n\n  function remove(file: DropzoneFile) {\n    setFiles((prev) => prev.filter((f) => f.id !== file.id));\n    onRemove?.(file);\n  }\n\n  const limits = [\n    accept ? describeAccept(accept) : \"Any file type\",\n    `up to ${formatBytes(maxSize)}`,\n  ].join(\", \");\n  const vars = { \"--hb-drz-accent\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-drz ${className}`} style={vars} data-size={size} {...rest}>\n      <style href=\"hb-dropzone\" precedence=\"default\">{css}</style>\n      <div\n        role=\"button\"\n        tabIndex={disabled ? -1 : 0}\n        aria-disabled={disabled || undefined}\n        aria-describedby={hintId}\n        className=\"hb-drz-zone\"\n        data-drag={dragging}\n        onClick={() => input.current?.click()}\n        onKeyDown={(e) => {\n          if (e.key === \"Enter\" || e.key === \" \") {\n            e.preventDefault();\n            input.current?.click();\n          }\n        }}\n        onDragEnter={(e) => {\n          e.preventDefault();\n          depth.current += 1;\n          if (!disabled) setDragging(true);\n        }}\n        onDragOver={(e) => {\n          e.preventDefault();\n          e.dataTransfer.dropEffect = \"copy\";\n        }}\n        onDragLeave={(e) => {\n          e.preventDefault();\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          ingest(e.dataTransfer.files);\n        }}\n      >\n        <svg className=\"hb-drz-border\" aria-hidden=\"true\">\n          <rect width=\"100%\" height=\"100%\" rx=\"15\" />\n        </svg>\n        <span className=\"hb-drz-icon\">{uploadIcon}</span>\n        <div className=\"hb-drz-copy\">\n          <p className=\"hb-drz-title\">{title}</p>\n          <p id={hintId} className=\"hb-drz-hint\">\n            {hint ?? limits}\n          </p>\n        </div>\n        <input\n          ref={input}\n          type=\"file\"\n          hidden\n          tabIndex={-1}\n          accept={accept || undefined}\n          multiple={multiple}\n          disabled={disabled}\n          onClick={(e) => e.stopPropagation()}\n          onChange={(e) => {\n            ingest(e.target.files);\n            e.target.value = \"\";\n          }}\n        />\n      </div>\n      {errors.length > 0 && (\n        <ul className=\"hb-drz-errors\" role=\"alert\">\n          {errors.slice(0, 3).map((message) => (\n            <li key={message} className=\"hb-drz-error\">\n              {alertIcon}\n              <span>{message}</span>\n            </li>\n          ))}\n        </ul>\n      )}\n      {files.length > 0 && (\n        <ul className=\"hb-drz-list\" aria-label=\"Selected files\">\n          {files.map((file) => (\n            <li key={file.id} className=\"hb-drz-file\" data-status={file.status}>\n              <span className=\"hb-drz-ext\" aria-hidden=\"true\">\n                {extOf(file.name)}\n              </span>\n              <div className=\"hb-drz-main\">\n                <div className=\"hb-drz-line\">\n                  <span className=\"hb-drz-name\" title={file.name}>\n                    {file.name}\n                  </span>\n                  <span className=\"hb-drz-size\">{formatBytes(file.size)}</span>\n                </div>\n                <div\n                  className=\"hb-drz-bar\"\n                  role=\"progressbar\"\n                  aria-label={`Upload progress for ${file.name}`}\n                  aria-valuemin={0}\n                  aria-valuemax={100}\n                  aria-valuenow={Math.round(file.progress)}\n                >\n                  <span\n                    className=\"hb-drz-fill\"\n                    data-live={file.status === \"uploading\"}\n                    style={{ \"--hb-drz-p\": (file.progress / 100).toFixed(3) } as React.CSSProperties}\n                  />\n                </div>\n              </div>\n              <div className=\"hb-drz-side\">\n                {file.status === \"done\" ? (\n                  <svg className=\"hb-drz-check\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" role=\"img\" aria-label=\"Uploaded\">\n                    <circle cx=\"10\" cy=\"10\" r=\"9\" />\n                    <path d=\"m6 10.3 2.7 2.7L14 7.6\" />\n                  </svg>\n                ) : (\n                  <span className=\"hb-drz-pct\">{Math.round(file.progress)}%</span>\n                )}\n                <button type=\"button\" className=\"hb-drz-rm\" aria-label={`Remove ${file.name}`} onClick={() => remove(file)}>\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"m3.5 3.5 9 9m0-9-9 9\" />\n                  </svg>\n                </button>\n              </div>\n            </li>\n          ))}\n        </ul>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}