{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-52",
  "title": "Avatar upload button",
  "description": "A round button that shows the chosen avatar, with a remove badge.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "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/button/button-52.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { useFileUpload } from '@/registry/ndeko/hooks/use-file-upload';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { CircleUserRoundIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport {\n  Avatar,\n  AvatarFallback,\n  AvatarImage,\n} from '@/registry/ndeko/ui/avatar';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst ROW_ENTER_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\nconst ROW_EXIT_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.23, 1, 0.32, 1],\n};\n\nconst POP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst ROW_VARIANTS: Variants = {\n  hidden: { height: 0, opacity: 0, transition: ROW_EXIT_TRANSITION },\n  shown: { height: 'auto', opacity: 1, transition: ROW_ENTER_TRANSITION },\n};\n\nconst ROW_FADE_VARIANTS: Variants = {\n  hidden: { opacity: 0, transition: ROW_EXIT_TRANSITION },\n  shown: { opacity: 1, transition: ROW_ENTER_TRANSITION },\n};\n\nfunction popVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return POP_VARIANTS;\n}\n\nfunction rowVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return ROW_FADE_VARIANTS;\n  }\n  return ROW_VARIANTS;\n}\n\nfunction avatarActionOf(hasImage: boolean) {\n  if (hasImage) {\n    return 'Change image';\n  }\n  return 'Upload image';\n}\n\nexport default function Button52() {\n  const [{ files }, { removeFile, openFileDialog, getInputProps }] =\n    useFileUpload({\n      accept: 'image/*',\n    });\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const popVariants = popVariantsOf(shouldReduceMotion);\n  const rowVariants = rowVariantsOf(shouldReduceMotion);\n\n  const image = files[0];\n  const previewUrl = image?.preview;\n  const fileName = image?.file.name;\n  const hasImage = Boolean(image);\n\n  function removeImage() {\n    if (!image) {\n      return;\n    }\n    removeFile(image.id);\n  }\n\n  return (\n    <div className='flex flex-col items-center'>\n      <div className='relative inline-flex'>\n        <Button\n          variant='outline'\n          className='size-16 overflow-hidden p-0'\n          onClick={openFileDialog}\n          aria-label={avatarActionOf(hasImage)}\n        >\n          <Avatar className='size-full bg-transparent ring-0'>\n            {previewUrl && (\n              <AvatarImage src={previewUrl} alt='Preview of uploaded image' />\n            )}\n            <AvatarFallback className='bg-transparent'>\n              <CircleUserRoundIcon className='opacity-60' />\n            </AvatarFallback>\n          </Avatar>\n        </Button>\n        <AnimatePresence initial={false}>\n          {hasImage && (\n            <motion.span\n              key='remove'\n              className='absolute -end-1 -top-1 flex'\n              variants={popVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n            >\n              <Button\n                size='icon'\n                onClick={removeImage}\n                aria-label='Remove image'\n                className='border-background size-6 border-2 ring-0'\n              >\n                <XIcon className='size-3.5' />\n              </Button>\n            </motion.span>\n          )}\n        </AnimatePresence>\n        <input\n          {...getInputProps()}\n          className='sr-only'\n          aria-label='Upload image file'\n          tabIndex={-1}\n        />\n      </div>\n      <AnimatePresence initial={false}>\n        {fileName && (\n          <motion.p\n            key='file-name'\n            className='text-muted-foreground overflow-hidden text-xs'\n            variants={rowVariants}\n            initial='hidden'\n            animate='shown'\n            exit='hidden'\n          >\n            <span className='block pt-2'>{fileName}</span>\n          </motion.p>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "button"
  ],
  "type": "registry:component"
}