{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-upload-04",
  "title": "Image drop zone",
  "description": "A zone you click or drop on that fills with the image, within a size limit.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-file-upload.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/file-upload/file-upload-04.tsx",
      "content": "'use client';\n\nimport {\n  formatBytes,\n  useFileUpload,\n} from '@/registry/ndeko/hooks/use-file-upload';\nimport {\n  CircleAlertIcon,\n  ImageUpIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nconst MAX_SIZE = 5 * 1024 * 1024;\n\nconst DROP_ZONE = [\n  'relative flex min-h-52 cursor-pointer flex-col items-center justify-center overflow-hidden rounded-xl p-4',\n  'group hairline-border border-dashed border-foreground/20',\n  'transition-[background-color,border-color,scale] duration-200 ease-(--ease-out-strong)',\n  'data-dragging:scale-[1.01] motion-reduce:data-dragging:scale-100',\n  'hover:bg-foreground/[0.025] data-dragging:border-primary/50 data-dragging:bg-primary/[0.04]',\n  'has-[input:focus-visible]:ring-[3px] has-[input:focus-visible]:ring-ring/25',\n  'has-disabled:pointer-events-none has-disabled:opacity-50',\n  'data-filled:border-solid data-filled:border-border',\n].join(' ');\n\nconst ICON_TILE =\n  'keycap-3d text-muted-foreground mb-3 flex size-10 items-center justify-center rounded-full transition-transform duration-200 ease-(--ease-out-strong) group-data-dragging:-translate-y-0.5 motion-reduce:group-data-dragging:translate-y-0';\n\nfunction presenceOf(isPresent: boolean) {\n  if (isPresent) {\n    return true;\n  }\n  return undefined;\n}\n\nfunction backgroundOf(url: string): React.CSSProperties {\n  return { backgroundImage: `url(${url})` };\n}\n\nexport default function FileUpload04() {\n  const [\n    { files, isDragging, errors },\n    {\n      handleDragEnter,\n      handleDragLeave,\n      handleDragOver,\n      handleDrop,\n      openFileDialog,\n      removeFile,\n      getInputProps,\n    },\n  ] = useFileUpload({\n    accept: 'image/*',\n    maxSize: MAX_SIZE,\n  });\n\n  const image = files[0];\n  const previewUrl = image?.preview;\n  const fileName = image?.file.name;\n  const hasImage = Boolean(previewUrl);\n  const firstError = errors[0];\n\n  function removeImage() {\n    if (!image) {\n      return;\n    }\n    removeFile(image.id);\n  }\n\n  return (\n    <div className='flex w-full flex-col gap-2'>\n      <div className='relative'>\n        <div\n          role='button'\n          onClick={openFileDialog}\n          onDragEnter={handleDragEnter}\n          onDragLeave={handleDragLeave}\n          onDragOver={handleDragOver}\n          onDrop={handleDrop}\n          data-dragging={presenceOf(isDragging)}\n          data-filled={presenceOf(hasImage)}\n          className={DROP_ZONE}\n        >\n          <input\n            {...getInputProps()}\n            className='sr-only'\n            aria-label='Upload image file'\n          />\n          {previewUrl && (\n            <div\n              role='img'\n              aria-label={fileName}\n              className='absolute inset-0 bg-cover bg-center'\n              style={backgroundOf(previewUrl)}\n            />\n          )}\n          {!previewUrl && (\n            <div className='flex flex-col items-center justify-center px-4 py-3 text-center'>\n              <div className={ICON_TILE} aria-hidden='true'>\n                <ImageUpIcon className='size-4' />\n              </div>\n              <p className='mb-1 text-[13px] font-medium'>\n                Drop your image here or click to browse\n              </p>\n              <p className='text-muted-foreground text-xs'>\n                Max size: {formatBytes(MAX_SIZE)}\n              </p>\n            </div>\n          )}\n        </div>\n        {hasImage && (\n          <Button\n            variant='outline'\n            size='icon-sm'\n            onClick={removeImage}\n            aria-label='Remove image'\n            className='absolute end-3 top-3'\n          >\n            <XIcon />\n          </Button>\n        )}\n      </div>\n      {firstError && (\n        <p\n          role='alert'\n          className='text-destructive-ink flex items-center gap-1.5 text-xs'\n        >\n          <CircleAlertIcon className='size-3.5 shrink-0' />\n          <span>{firstError}</span>\n        </p>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "file-upload"
  ],
  "type": "registry:component"
}