{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-upload-06",
  "title": "Image grid uploader",
  "description": "Several images in a grid inside the drop zone, each with a remove badge.",
  "dependencies": [
    "motion"
  ],
  "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",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/file-upload/file-upload-06.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport {\n  type FileMetadata,\n  type FileWithPreview,\n  formatBytes,\n  useFileUpload,\n} from '@/registry/ndeko/hooks/use-file-upload';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  CircleAlertIcon,\n  ImageIcon,\n  UploadIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nconst MAX_SIZE = 5 * 1024 * 1024;\nconst MAX_FILES = 6;\nconst ACCEPTED_TYPES = 'image/svg+xml,image/png,image/jpeg,image/jpg,image/gif';\n\nconst INITIAL_FILES: FileMetadata[] = [\n  {\n    name: 'cover-draft.png',\n    size: 1528737,\n    type: 'image/png',\n    url: '',\n    id: 'cover-draft',\n  },\n  {\n    name: 'team-offsite.jpg',\n    size: 2345678,\n    type: 'image/jpeg',\n    url: '',\n    id: 'team-offsite',\n  },\n  {\n    name: 'product-shot.jpg',\n    size: 1874211,\n    type: 'image/jpeg',\n    url: '',\n    id: 'product-shot',\n  },\n  {\n    name: 'office-plan.png',\n    size: 982344,\n    type: 'image/png',\n    url: '',\n    id: 'office-plan',\n  },\n];\n\nconst DROP_ZONE = [\n  'relative flex min-h-52 flex-col items-center overflow-hidden rounded-xl p-4 not-data-files:justify-center',\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  '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].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\nconst COUNT =\n  'keycap-3d inline-flex h-5 min-w-5 items-center justify-center rounded-[5px] px-1 text-[11px] font-medium tabular-nums text-muted-foreground';\n\nconst ENTER_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\nconst EXIT_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.23, 1, 0.32, 1],\n};\nconst LAYOUT_TRANSITION: Transition = {\n  layout: { type: 'spring', bounce: 0, duration: 0.3 },\n};\n\nconst TILE_VARIANTS: Variants = {\n  hidden: { opacity: 0, scale: 0.9, transition: EXIT_TRANSITION },\n  shown: { opacity: 1, scale: 1, transition: ENTER_TRANSITION },\n};\n\nconst FADE_VARIANTS: Variants = {\n  hidden: { opacity: 0, transition: EXIT_TRANSITION },\n  shown: { opacity: 1, transition: ENTER_TRANSITION },\n};\n\nfunction tileVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return TILE_VARIANTS;\n}\n\nfunction presenceOf(isPresent: boolean) {\n  if (isPresent) {\n    return true;\n  }\n  return undefined;\n}\n\nfunction localPreviewOf(file: FileWithPreview) {\n  const isLocalFile = file.file instanceof File;\n  if (!isLocalFile) {\n    return null;\n  }\n  return file.preview ?? null;\n}\n\nfunction Thumbnail({ file }: { file: FileWithPreview }) {\n  const previewUrl = localPreviewOf(file);\n  if (previewUrl) {\n    return (\n      <div\n        role='img'\n        aria-label={file.file.name}\n        className='size-full rounded-[inherit] bg-cover bg-center'\n        style={{ backgroundImage: `url(${previewUrl})` }}\n      />\n    );\n  }\n  return (\n    <div\n      role='img'\n      aria-label={file.file.name}\n      className='bg-primary/15 flex size-full items-center justify-center rounded-[inherit]'\n    >\n      <ImageIcon className='text-primary-ink/70 size-5' />\n    </div>\n  );\n}\n\nexport default function FileUpload06() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const tileVariants = tileVariantsOf(shouldReduceMotion);\n  const shouldAnimateLayout = !shouldReduceMotion;\n\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: ACCEPTED_TYPES,\n    maxSize: MAX_SIZE,\n    multiple: true,\n    maxFiles: MAX_FILES,\n    initialFiles: INITIAL_FILES,\n  });\n\n  const hasFiles = files.length > 0;\n  const isFull = files.length >= MAX_FILES;\n  const firstError = errors[0];\n\n  return (\n    <div className='flex w-full flex-col gap-2'>\n      <div\n        onDragEnter={handleDragEnter}\n        onDragLeave={handleDragLeave}\n        onDragOver={handleDragOver}\n        onDrop={handleDrop}\n        data-dragging={presenceOf(isDragging)}\n        data-files={presenceOf(hasFiles)}\n        className={DROP_ZONE}\n      >\n        <input\n          {...getInputProps()}\n          className='sr-only'\n          aria-label='Upload image files'\n        />\n        {hasFiles && (\n          <div className='flex w-full flex-col gap-3'>\n            <div className='flex items-center justify-between gap-2'>\n              <h3 className='flex items-center gap-2 text-[13px] font-medium'>\n                Uploaded files\n                <span className={COUNT}>{files.length}</span>\n              </h3>\n              <Button\n                variant='outline'\n                size='sm'\n                onClick={openFileDialog}\n                disabled={isFull}\n              >\n                <UploadIcon className='-ms-0.5 size-3.5 opacity-60' />\n                Add more\n              </Button>\n            </div>\n            <div className='grid grid-cols-2 gap-4 md:grid-cols-3'>\n              <AnimatePresence mode='popLayout' initial={false}>\n                {files.map((file) => (\n                  <motion.div\n                    key={file.id}\n                    layout={shouldAnimateLayout}\n                    variants={tileVariants}\n                    initial='hidden'\n                    animate='shown'\n                    exit='hidden'\n                    transition={LAYOUT_TRANSITION}\n                    className='bg-foreground/[0.04] relative aspect-square rounded-lg'\n                  >\n                    <Thumbnail file={file} />\n                    <Button\n                      size='icon'\n                      onClick={() => removeFile(file.id)}\n                      aria-label={`Remove ${file.file.name}`}\n                      className='border-background absolute -end-2 -top-2 size-6 border-2 ring-0'\n                    >\n                      <XIcon className='size-3.5' />\n                    </Button>\n                  </motion.div>\n                ))}\n              </AnimatePresence>\n            </div>\n          </div>\n        )}\n        {!hasFiles && (\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              <ImageIcon className='size-4' />\n            </div>\n            <p className='mb-1 text-[13px] font-medium'>\n              Drop your images here\n            </p>\n            <p className='text-muted-foreground text-xs'>\n              SVG, PNG, JPG or GIF (max. {formatBytes(MAX_SIZE)})\n            </p>\n            <Button variant='outline' className='mt-4' onClick={openFileDialog}>\n              <UploadIcon className='-ms-1 opacity-60' />\n              Select images\n            </Button>\n          </div>\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"
}