{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-19",
  "title": "Profile dialog",
  "description": "Cover, picture and profile fields between a fixed title and fixed actions.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/textarea.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-character-limit.json",
    "https://ui.ndekocode.dev/r/use-file-upload.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/dialog/dialog-19.tsx",
      "content": "'use client';\n\nimport { useId } from 'react';\n\nimport { useCharacterLimit } from '@/registry/ndeko/hooks/use-character-limit';\nimport { useFileUpload } from '@/registry/ndeko/hooks/use-file-upload';\nimport { CheckIcon, ImagePlusIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { Avatar, AvatarImage } from '@/registry/ndeko/ui/avatar';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogFooter,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\n\nconst BIO_MAX_LENGTH = 180;\nconst INITIAL_BIO =\n  'Product designer at Fernhill Studio. I draw interfaces, then the systems behind them.';\n\nfunction remainingLabelOf(remaining: number) {\n  if (remaining === 0) {\n    return 'No characters left';\n  }\n  if (remaining === 1) {\n    return '1 character left';\n  }\n  return `${remaining} characters left`;\n}\n\nfunction coverActionLabelOf(hasImage: boolean) {\n  if (hasImage) {\n    return 'Change cover image';\n  }\n  return 'Upload cover image';\n}\n\nfunction CoverImage() {\n  const [{ files }, { removeFile, openFileDialog, getInputProps }] =\n    useFileUpload({ accept: 'image/*' });\n  const currentFile = files[0];\n  const preview = currentFile?.preview;\n  const hasImage = Boolean(preview);\n  const coverStyle = { backgroundImage: `url(${preview})` };\n\n  function removeCover() {\n    removeFile(currentFile.id);\n  }\n\n  return (\n    <div className='bg-foreground/[0.05] relative h-32 overflow-hidden'>\n      {hasImage && (\n        <div\n          role='img'\n          aria-label='Cover image'\n          style={coverStyle}\n          className='size-full bg-cover bg-center'\n        />\n      )}\n      <div className='absolute inset-0 flex items-center justify-center gap-2'>\n        <Button\n          type='button'\n          variant='outline'\n          size='icon'\n          onClick={openFileDialog}\n          aria-label={coverActionLabelOf(hasImage)}\n        >\n          <ImagePlusIcon />\n        </Button>\n        {hasImage && (\n          <Button\n            type='button'\n            variant='outline'\n            size='icon'\n            onClick={removeCover}\n            aria-label='Remove cover image'\n          >\n            <XIcon />\n          </Button>\n        )}\n      </div>\n      <input\n        {...getInputProps()}\n        className='sr-only'\n        aria-label='Upload cover image file'\n      />\n    </div>\n  );\n}\n\nfunction ProfilePicture() {\n  const [{ files }, { openFileDialog, getInputProps }] = useFileUpload({\n    accept: 'image/*',\n  });\n  const preview = files[0]?.preview;\n\n  return (\n    <div className='relative -mt-10 size-20'>\n      <Avatar seed='Amara Okafor' className='ring-card size-20 ring-4'>\n        <AvatarImage src={preview} alt='Profile picture' />\n      </Avatar>\n      <Button\n        type='button'\n        variant='outline'\n        size='icon'\n        onClick={openFileDialog}\n        aria-label='Change profile picture'\n        className='absolute inset-0 m-auto'\n      >\n        <ImagePlusIcon />\n      </Button>\n      <input\n        {...getInputProps()}\n        className='sr-only'\n        aria-label='Upload profile picture file'\n      />\n    </div>\n  );\n}\n\nexport default function Dialog19() {\n  const id = useId();\n  const firstNameId = `${id}-first-name`;\n  const lastNameId = `${id}-last-name`;\n  const usernameId = `${id}-username`;\n  const websiteId = `${id}-website`;\n  const bioId = `${id}-bio`;\n  const counterId = `${id}-counter`;\n  const { value, characterCount, handleChange, maxLength } = useCharacterLimit({\n    maxLength: BIO_MAX_LENGTH,\n    initialValue: INITIAL_BIO,\n  });\n  const remaining = maxLength - characterCount;\n\n  return (\n    <Dialog>\n      <DialogTrigger render={<Button variant='outline' />}>\n        Edit profile\n      </DialogTrigger>\n      <DialogContent\n        animateSize={false}\n        className='overflow-hidden p-0'\n        contentClassName='max-h-[calc(100dvh-2rem)] gap-0'\n      >\n        <DialogHeader className='px-6 pt-6 pr-12 pb-4'>\n          <DialogTitle>Edit profile</DialogTitle>\n          <DialogDescription className='sr-only'>\n            Change your pictures, your name, your username and your biography.\n          </DialogDescription>\n        </DialogHeader>\n        <div className='min-h-0 flex-1 overflow-y-auto'>\n          <CoverImage />\n          <div className='px-6'>\n            <ProfilePicture />\n          </div>\n          <form className='flex flex-col gap-4 px-6 pt-4 pb-6'>\n            <div className='flex flex-col gap-4 sm:flex-row'>\n              <div className='grid flex-1 gap-2'>\n                <Label htmlFor={firstNameId}>First name</Label>\n                <Input\n                  id={firstNameId}\n                  autoComplete='given-name'\n                  defaultValue='Amara'\n                  required\n                />\n              </div>\n              <div className='grid flex-1 gap-2'>\n                <Label htmlFor={lastNameId}>Last name</Label>\n                <Input\n                  id={lastNameId}\n                  autoComplete='family-name'\n                  defaultValue='Okafor'\n                  required\n                />\n              </div>\n            </div>\n            <div className='grid gap-2'>\n              <Label htmlFor={usernameId}>Username</Label>\n              <div className='relative'>\n                <Input\n                  id={usernameId}\n                  autoComplete='username'\n                  defaultValue='amara-okafor'\n                  aria-describedby={`${usernameId}-status`}\n                  className='peer pe-8'\n                  required\n                />\n                <span className='pointer-events-none absolute inset-y-0 end-0 flex items-center pe-2.5 peer-disabled:opacity-50'>\n                  <CheckIcon className='text-success-foreground size-4' />\n                </span>\n                <span id={`${usernameId}-status`} className='sr-only'>\n                  This username is available.\n                </span>\n              </div>\n            </div>\n            <div className='grid gap-2'>\n              <Label htmlFor={websiteId}>Website</Label>\n              <div className='flex'>\n                <span className='text-muted-foreground bg-foreground/[0.03] hairline-ring ring-foreground/12 dark:ring-foreground/15 inline-flex items-center rounded-s-md px-2.5 text-[13px]'>\n                  https://\n                </span>\n                <Input\n                  id={websiteId}\n                  type='text'\n                  autoComplete='url'\n                  defaultValue='amara.design'\n                  placeholder='yourwebsite.com'\n                  className='-ms-px rounded-s-none shadow-none focus-visible:z-10'\n                />\n              </div>\n            </div>\n            <div className='grid gap-2'>\n              <Label htmlFor={bioId}>Biography</Label>\n              <Textarea\n                id={bioId}\n                placeholder='A few sentences about you'\n                value={value}\n                maxLength={maxLength}\n                onChange={handleChange}\n                aria-describedby={counterId}\n              />\n              <p\n                id={counterId}\n                role='status'\n                className='text-muted-foreground text-end text-xs tabular-nums'\n              >\n                {remainingLabelOf(remaining)}\n              </p>\n            </div>\n          </form>\n        </div>\n        <DialogFooter className='px-6 pt-4 pb-6'>\n          <DialogClose render={<Button variant='outline' size='lg' />}>\n            Cancel\n          </DialogClose>\n          <DialogClose render={<Button size='lg' />}>Save changes</DialogClose>\n        </DialogFooter>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "dialog"
  ],
  "type": "registry:component"
}