{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"shadcn-studio/dialog-12","type":"registry:component","title":"Dialog 12","description":"OTP verification dialog with input-otp component and validation feedback","dependencies":["input-otp","lucide-react"],"registryDependencies":["button","dialog","utils"],"files":[{"path":"src/registry/new-york/components/dialog/dialog-12.tsx","content":"'use client'\n\nimport { useEffect, useRef, useState } from 'react'\n\nimport { CheckIcon, MailIcon } from 'lucide-react'\n\nimport { OTPInput, type SlotProps } from 'input-otp'\n\nimport { Button } from '@/registry/new-york/ui/button'\nimport {\n  Dialog,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger\n} from '@/registry/new-york/ui/dialog'\n\nimport { cn } from '@/registry/new-york/lib/utils'\n\nconst CORRECT_CODE = '11208'\n\nconst DialogOTPVerificationDemo = () => {\n  const [value, setValue] = useState('')\n  const [hasGuessed, setHasGuessed] = useState<undefined | boolean>(undefined)\n  const inputRef = useRef<HTMLInputElement>(null)\n  const closeButtonRef = useRef<HTMLButtonElement>(null)\n\n  useEffect(() => {\n    if (hasGuessed) {\n      closeButtonRef.current?.focus()\n    }\n  }, [hasGuessed])\n\n  async function onSubmit(e?: React.FormEvent<HTMLFormElement>) {\n    e?.preventDefault?.()\n\n    inputRef.current?.select()\n    await new Promise(r => setTimeout(r, 1_00))\n\n    setHasGuessed(value === CORRECT_CODE)\n\n    setValue('')\n    setTimeout(() => {\n      inputRef.current?.blur()\n    }, 20)\n  }\n\n  return (\n    <Dialog>\n      <DialogTrigger asChild>\n        <Button variant='outline'>OTP code</Button>\n      </DialogTrigger>\n      <DialogContent className='sm:max-w-md'>\n        <div className='flex flex-col items-center gap-2'>\n          <div\n            className={cn(\n              'flex size-10 shrink-0 items-center justify-center rounded-full bg-sky-600/10 dark:bg-sky-400/10',\n              { 'bg-green-600/10 dark:bg-green-400/10': hasGuessed }\n            )}\n            aria-hidden='true'\n          >\n            {hasGuessed ? (\n              <CheckIcon className='text-green-600 dark:text-green-400' strokeWidth={1} />\n            ) : (\n              <MailIcon className='text-sky-600 dark:text-sky-400' strokeWidth={1} />\n            )}\n          </div>\n          <DialogHeader>\n            <DialogTitle className='text-center'>{hasGuessed ? 'Account verified!' : 'Check Your Email'}</DialogTitle>\n            <DialogDescription className='text-center'>\n              {hasGuessed ? (\n                <span>\n                  Congratulations! your email account <strong>exa**le@gmail.com</strong> has been verified\n                </span>\n              ) : (\n                <span>\n                  We have sent a verification code to <strong>exa**le@gmail.com</strong>. Please check your inbox and\n                  input the code below to activate your account. Try {CORRECT_CODE}\n                </span>\n              )}\n            </DialogDescription>\n          </DialogHeader>\n        </div>\n\n        {hasGuessed ? (\n          <div className='text-center'>\n            <DialogClose asChild>\n              <Button type='button' ref={closeButtonRef}>\n                Continue\n              </Button>\n            </DialogClose>\n          </div>\n        ) : (\n          <div className='space-y-4'>\n            <div className='flex justify-center'>\n              <OTPInput\n                id='confirmation-code'\n                ref={inputRef}\n                value={value}\n                onChange={setValue}\n                containerClassName='flex items-center gap-3 has-disabled:opacity-50'\n                maxLength={5}\n                onFocus={() => setHasGuessed(undefined)}\n                render={({ slots }) => (\n                  <div className='flex gap-2'>\n                    {slots.map((slot, idx) => (\n                      <Slot key={idx} {...slot} />\n                    ))}\n                  </div>\n                )}\n                onComplete={onSubmit}\n              />\n            </div>\n            {hasGuessed === false && (\n              <p className='text-muted-foreground text-center text-xs' role='alert' aria-live='polite'>\n                Invalid code. Please try again.\n              </p>\n            )}\n            <p className='text-center text-sm'>\n              Didn&apos;t get a code?{' '}\n              <a className='text-sky-600 hover:underline dark:text-sky-400' href='#'>\n                Resend\n              </a>\n            </p>\n          </div>\n        )}\n      </DialogContent>\n    </Dialog>\n  )\n}\n\nfunction Slot(props: SlotProps) {\n  return (\n    <div\n      className={cn(\n        'border-input bg-background text-foreground flex size-9 items-center justify-center rounded-md border font-medium shadow-xs transition-[color,box-shadow]',\n        { 'border-ring ring-ring/50 z-10 ring-[3px]': props.isActive }\n      )}\n    >\n      {props.char !== null && <div>{props.char}</div>}\n    </div>\n  )\n}\n\nexport default DialogOTPVerificationDemo\n","type":"registry:component","target":"components/shadcn-studio/dialog/dialog-12.tsx"}]}