{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contact-01",
  "title": "Contact form with validation",
  "description": "Contact details beside a form that checks each field on submit and as you fix it, shows a sending state and morphs into a confirmation.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/field.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/select.json",
    "https://ui.ndekocode.dev/r/status-orb.json",
    "https://ui.ndekocode.dev/r/textarea.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/contact/contact-01/index.tsx",
      "content": "import { ContactForm } from './contact-form';\nimport { CONTACT_DETAILS, SECTION } from './data';\n\nexport default function Contact01() {\n  return (\n    <section className='px-4 py-16 sm:px-6 sm:py-24 lg:px-8'>\n      <div className='mx-auto grid max-w-6xl gap-10 lg:grid-cols-[minmax(0,2fr)_minmax(0,3fr)] lg:gap-16'>\n        <div className='flex flex-col gap-8'>\n          <div className='flex flex-col gap-3'>\n            <h2 className='text-2xl font-semibold text-balance sm:text-3xl'>\n              {SECTION.title}\n            </h2>\n            <p className='text-muted-foreground max-w-md text-base text-pretty'>\n              {SECTION.description}\n            </p>\n          </div>\n          <dl className='flex flex-col gap-4'>\n            {CONTACT_DETAILS.map((detail) => (\n              <div key={detail.label} className='flex items-center gap-3'>\n                <span className='keycap-3d text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-lg'>\n                  <detail.icon />\n                </span>\n                <div className='flex min-w-0 flex-col'>\n                  <dt className='text-muted-foreground text-xs'>\n                    {detail.label}\n                  </dt>\n                  <dd className='text-[13px] font-medium'>\n                    {detail.href && (\n                      <a\n                        href={detail.href}\n                        className='text-primary-ink focus-visible:ring-ring/25 rounded-sm underline-offset-4 outline-none hover:underline focus-visible:ring-[3px]'\n                      >\n                        {detail.value}\n                      </a>\n                    )}\n                    {!detail.href && detail.value}\n                  </dd>\n                </div>\n              </div>\n            ))}\n          </dl>\n        </div>\n        <ContactForm />\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/contact-01/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/contact/contact-01/contact-form.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useId, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { LoaderCircleIcon, SendIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Field,\n  FieldDescription,\n  FieldError,\n  FieldLabel,\n} from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/registry/ndeko/ui/select';\nimport { StatusOrb } from '@/registry/ndeko/ui/status-orb';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\n\nimport { TEAM_SIZES } from './data';\nimport {\n  type ContactErrors,\n  type ContactField,\n  EMPTY_VALUES,\n  errorsOf,\n  firstInvalidFieldOf,\n  firstNameOf,\n  isContactField,\n  MESSAGE_MAX_LENGTH,\n} from './validation';\n\ntype Status = 'editing' | 'sending' | 'sent';\n\nconst SEND_DELAY_MS = 1200;\n\nconst MESSAGE_COUNT_FORMAT = new Intl.NumberFormat('en');\n\nconst PANEL_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\n\nconst LABEL_TRANSITION: Transition = {\n  type: 'spring',\n  bounce: 0,\n  duration: 0.3,\n};\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst PANEL_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.98, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.98, filter: 'blur(2px)' },\n};\n\nconst ICON_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\nfunction panelVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return PANEL_VARIANTS;\n}\n\nfunction iconVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return ICON_VARIANTS;\n}\n\nfunction labelTransitionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return LABEL_TRANSITION;\n}\n\nfunction sendLabelOf(isSending: boolean) {\n  if (isSending) {\n    return 'Sending';\n  }\n  return 'Send message';\n}\n\nfunction sendGlyphOf(isSending: boolean) {\n  if (isSending) {\n    return {\n      key: 'sending',\n      icon: <LoaderCircleIcon className='animate-spin' />,\n    };\n  }\n  return { key: 'send', icon: <SendIcon /> };\n}\n\nfunction selectedValueOf(value: string) {\n  if (value.length === 0) {\n    return null;\n  }\n  return value;\n}\n\nfunction describedByOf(hintId: string, errorId: string, hasError: boolean) {\n  if (hasError) {\n    return `${errorId} ${hintId}`;\n  }\n  return hintId;\n}\n\nfunction messageCountOf(message: string) {\n  const length = MESSAGE_COUNT_FORMAT.format(message.length);\n  const limit = MESSAGE_COUNT_FORMAT.format(MESSAGE_MAX_LENGTH);\n  return `${length} of ${limit} characters`;\n}\n\nexport function ContactForm() {\n  const [values, setValues] = useState(EMPTY_VALUES);\n  const [errors, setErrors] = useState<ContactErrors>({});\n  const [hasTriedSubmit, setHasTriedSubmit] = useState(false);\n  const [status, setStatus] = useState<Status>('editing');\n  const nameRef = useRef<HTMLInputElement>(null);\n  const emailRef = useRef<HTMLInputElement>(null);\n  const teamSizeRef = useRef<HTMLButtonElement>(null);\n  const messageRef = useRef<HTMLTextAreaElement>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const panelVariants = panelVariantsOf(shouldReduceMotion);\n  const iconVariants = iconVariantsOf(shouldReduceMotion);\n  const labelTransition = labelTransitionOf(shouldReduceMotion);\n  const isSending = status === 'sending';\n  const isSent = status === 'sent';\n  const sendLabel = sendLabelOf(isSending);\n  const sendGlyph = sendGlyphOf(isSending);\n  const selectedTeamSize = selectedValueOf(values.teamSize);\n  const messageCount = messageCountOf(values.message);\n  const firstName = firstNameOf(values.name);\n  const replyEmail = values.email.trim();\n  const messageId = useId();\n  const messageHintId = `${messageId}-hint`;\n  const messageErrorId = `${messageId}-error`;\n  const hasMessageError = Boolean(errors.message);\n  const messageDescribedBy = describedByOf(\n    messageHintId,\n    messageErrorId,\n    hasMessageError\n  );\n\n  useEffect(() => {\n    if (!isSending) {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setStatus('sent');\n    }, SEND_DELAY_MS);\n    return () => window.clearTimeout(timeout);\n  }, [isSending]);\n\n  function focusField(field: ContactField) {\n    if (field === 'name') {\n      nameRef.current?.focus();\n    }\n    if (field === 'email') {\n      emailRef.current?.focus();\n    }\n    if (field === 'teamSize') {\n      teamSizeRef.current?.focus();\n    }\n    if (field === 'message') {\n      messageRef.current?.focus();\n    }\n  }\n\n  function updateValue(field: ContactField, value: string) {\n    const nextValues = { ...values, [field]: value };\n    setValues(nextValues);\n    if (hasTriedSubmit) {\n      const nextErrors = errorsOf(nextValues);\n      setErrors(nextErrors);\n    }\n  }\n\n  function changeText(\n    event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>\n  ) {\n    const { name, value } = event.target;\n    if (isContactField(name)) {\n      updateValue(name, value);\n    }\n  }\n\n  function changeTeamSize(value: string | null) {\n    const nextValue = value ?? '';\n    updateValue('teamSize', nextValue);\n  }\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    const nextErrors = errorsOf(values);\n    const firstInvalidField = firstInvalidFieldOf(nextErrors);\n    setHasTriedSubmit(true);\n    setErrors(nextErrors);\n    if (firstInvalidField) {\n      focusField(firstInvalidField);\n      return;\n    }\n    setStatus('sending');\n  }\n\n  function startOver() {\n    setValues(EMPTY_VALUES);\n    setErrors({});\n    setHasTriedSubmit(false);\n    setStatus('editing');\n  }\n\n  return (\n    <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] rounded-xl p-5 shadow-[0_1px_2px_rgb(0_0_0/0.04)] sm:p-7'>\n      <AnimatedSize contentClassName='relative'>\n        <AnimatePresence mode='popLayout' initial={false}>\n          {isSent && (\n            <motion.div\n              key='sent'\n              role='status'\n              variants={panelVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={PANEL_TRANSITION}\n              className='flex flex-col items-start gap-4 py-6 sm:py-10'\n            >\n              <StatusOrb tone='success' />\n              <div className='flex flex-col gap-1.5'>\n                <p className='text-lg font-semibold'>Message sent</p>\n                <p className='text-muted-foreground max-w-md text-[13px] text-pretty'>\n                  Thanks, {firstName}. Someone from the team replies to{' '}\n                  <span className='text-foreground font-medium break-all'>\n                    {replyEmail}\n                  </span>{' '}\n                  within one working day.\n                </p>\n              </div>\n              <Button variant='outline' onClick={startOver}>\n                Send another message\n              </Button>\n            </motion.div>\n          )}\n          {!isSent && (\n            <motion.form\n              key='form'\n              noValidate\n              onSubmit={submit}\n              variants={panelVariants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={PANEL_TRANSITION}\n              className='flex flex-col gap-5'\n            >\n              <div className='grid gap-5 sm:grid-cols-2'>\n                <Field invalid={Boolean(errors.name)}>\n                  <FieldLabel>Name</FieldLabel>\n                  <Input\n                    ref={nameRef}\n                    name='name'\n                    autoComplete='name'\n                    placeholder='Amara Okafor'\n                    value={values.name}\n                    onChange={changeText}\n                    readOnly={isSending}\n                  />\n                  {errors.name && <FieldError match>{errors.name}</FieldError>}\n                </Field>\n                <Field invalid={Boolean(errors.email)}>\n                  <FieldLabel>Work email</FieldLabel>\n                  <Input\n                    ref={emailRef}\n                    type='email'\n                    name='email'\n                    autoComplete='email'\n                    placeholder='amara@company.com'\n                    value={values.email}\n                    onChange={changeText}\n                    readOnly={isSending}\n                  />\n                  {errors.email && (\n                    <FieldError match>{errors.email}</FieldError>\n                  )}\n                </Field>\n                <Field>\n                  <FieldLabel>\n                    Company\n                    <span className='text-muted-foreground font-normal'>\n                      Optional\n                    </span>\n                  </FieldLabel>\n                  <Input\n                    name='company'\n                    autoComplete='organization'\n                    placeholder='Okafor Bakery'\n                    value={values.company}\n                    onChange={changeText}\n                    readOnly={isSending}\n                  />\n                </Field>\n                <Field invalid={Boolean(errors.teamSize)}>\n                  <FieldLabel>Team size</FieldLabel>\n                  <Select\n                    items={TEAM_SIZES}\n                    value={selectedTeamSize}\n                    onValueChange={changeTeamSize}\n                    readOnly={isSending}\n                    name='teamSize'\n                  >\n                    <SelectTrigger ref={teamSizeRef}>\n                      <SelectValue placeholder='Pick a size' />\n                    </SelectTrigger>\n                    <SelectContent>\n                      {TEAM_SIZES.map((size) => (\n                        <SelectItem key={size.value} value={size.value}>\n                          {size.label}\n                        </SelectItem>\n                      ))}\n                    </SelectContent>\n                  </Select>\n                  {errors.teamSize && (\n                    <FieldError match>{errors.teamSize}</FieldError>\n                  )}\n                </Field>\n              </div>\n              <Field invalid={hasMessageError}>\n                <FieldLabel htmlFor={messageId}>How can we help?</FieldLabel>\n                <Textarea\n                  ref={messageRef}\n                  id={messageId}\n                  name='message'\n                  rows={4}\n                  maxLength={MESSAGE_MAX_LENGTH}\n                  placeholder='We answer about 200 emails a week with four people and want to stop replying twice to the same customer.'\n                  value={values.message}\n                  onChange={changeText}\n                  readOnly={isSending}\n                  aria-invalid={hasMessageError}\n                  aria-describedby={messageDescribedBy}\n                  className='min-h-28'\n                />\n                {hasMessageError && (\n                  <FieldError id={messageErrorId} match>\n                    {errors.message}\n                  </FieldError>\n                )}\n                <FieldDescription id={messageHintId} className='tabular-nums'>\n                  {messageCount}\n                </FieldDescription>\n              </Field>\n              <div className='flex flex-col-reverse gap-3 sm:flex-row sm:items-center sm:justify-between'>\n                <p className='text-muted-foreground text-xs'>\n                  We only use these details to answer you\n                </p>\n                <Button\n                  type='submit'\n                  size='lg'\n                  disabled={isSending}\n                  focusableWhenDisabled\n                  className='data-disabled:opacity-100'\n                >\n                  <AnimatePresence mode='popLayout' initial={false}>\n                    <motion.span\n                      key={sendGlyph.key}\n                      className='flex'\n                      variants={iconVariants}\n                      initial='enter'\n                      animate='visible'\n                      exit='exit'\n                      transition={PANEL_TRANSITION}\n                    >\n                      {sendGlyph.icon}\n                    </motion.span>\n                  </AnimatePresence>\n                  <motion.span layout transition={labelTransition}>\n                    {sendLabel}\n                  </motion.span>\n                </Button>\n              </div>\n            </motion.form>\n          )}\n        </AnimatePresence>\n      </AnimatedSize>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/contact-01/contact-form.tsx"
    },
    {
      "path": "registry/ndeko/blocks/contact/contact-01/validation.ts",
      "content": "export type ContactValues = {\n  name: string;\n  email: string;\n  company: string;\n  teamSize: string;\n  message: string;\n};\n\nexport type ContactField = keyof ContactValues;\n\nexport type ContactErrors = Partial<Record<ContactField, string>>;\n\nexport const MESSAGE_MIN_LENGTH = 20;\n\nexport const MESSAGE_MAX_LENGTH = 1000;\n\nexport const EMPTY_VALUES: ContactValues = {\n  name: '',\n  email: '',\n  company: '',\n  teamSize: '',\n  message: '',\n};\n\nconst FIELD_ORDER: ContactField[] = [\n  'name',\n  'email',\n  'company',\n  'teamSize',\n  'message',\n];\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nexport function isContactField(value: string): value is ContactField {\n  return FIELD_ORDER.some((field) => field === value);\n}\n\nfunction isBlank(value: string) {\n  const trimmed = value.trim();\n  return trimmed.length === 0;\n}\n\nfunction nameErrorOf(value: string) {\n  if (isBlank(value)) {\n    return 'Enter your name so we know who to answer';\n  }\n  return null;\n}\n\nfunction emailErrorOf(value: string) {\n  if (isBlank(value)) {\n    return 'Enter your work email';\n  }\n  const trimmed = value.trim();\n  const isEmailShaped = EMAIL_PATTERN.test(trimmed);\n  if (!isEmailShaped) {\n    return 'Check the address, it should look like name@company.com';\n  }\n  return null;\n}\n\nfunction teamSizeErrorOf(value: string) {\n  if (isBlank(value)) {\n    return 'Pick the size of your team';\n  }\n  return null;\n}\n\nfunction messageErrorOf(value: string) {\n  const trimmed = value.trim();\n  const isTooShort = trimmed.length < MESSAGE_MIN_LENGTH;\n  if (isTooShort) {\n    return `Tell us a little more, at least ${MESSAGE_MIN_LENGTH} characters`;\n  }\n  const isTooLong = trimmed.length > MESSAGE_MAX_LENGTH;\n  if (isTooLong) {\n    return 'Keep the message under 1,000 characters';\n  }\n  return null;\n}\n\nfunction addError(\n  errors: ContactErrors,\n  field: ContactField,\n  error: string | null\n) {\n  if (error) {\n    errors[field] = error;\n  }\n}\n\nexport function errorsOf(values: ContactValues) {\n  const errors: ContactErrors = {};\n  const nameError = nameErrorOf(values.name);\n  const emailError = emailErrorOf(values.email);\n  const teamSizeError = teamSizeErrorOf(values.teamSize);\n  const messageError = messageErrorOf(values.message);\n  addError(errors, 'name', nameError);\n  addError(errors, 'email', emailError);\n  addError(errors, 'teamSize', teamSizeError);\n  addError(errors, 'message', messageError);\n  return errors;\n}\n\nexport function firstInvalidFieldOf(errors: ContactErrors) {\n  const invalidFields = FIELD_ORDER.filter((field) => errors[field]);\n  if (invalidFields.length === 0) {\n    return null;\n  }\n  return invalidFields[0];\n}\n\nexport function firstNameOf(name: string) {\n  const trimmed = name.trim();\n  const words = trimmed.split(' ');\n  return words[0];\n}\n",
      "type": "registry:component",
      "target": "components/blocks/contact-01/validation.ts"
    },
    {
      "path": "registry/ndeko/blocks/contact/contact-01/data.ts",
      "content": "import {\n  ClockIcon,\n  GlobeIcon,\n  type Icon,\n  MailIcon,\n} from '@/registry/ndeko/lib/icons';\n\nexport type ContactDetail = {\n  icon: Icon;\n  label: string;\n  value: string;\n  href?: string;\n};\n\nexport const SECTION = {\n  title: 'Talk to the people who build Driftdesk',\n  description:\n    'Tell us how your team answers customers today. We reply with a setup that fits, and a trial workspace if you want one.',\n};\n\nexport const CONTACT_DETAILS: ContactDetail[] = [\n  {\n    icon: MailIcon,\n    label: 'Email',\n    value: 'sales@driftdesk.example',\n    href: 'mailto:sales@driftdesk.example',\n  },\n  {\n    icon: ClockIcon,\n    label: 'Reply time',\n    value: 'Within one working day, Monday to Friday',\n  },\n  {\n    icon: GlobeIcon,\n    label: 'Team',\n    value: 'Kinshasa, Lisbon and Nairobi',\n  },\n];\n\nexport const TEAM_SIZES = [\n  { value: '1-10', label: '1 to 10 people' },\n  { value: '11-50', label: '11 to 50 people' },\n  { value: '51-200', label: '51 to 200 people' },\n  { value: '201+', label: 'More than 200 people' },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/contact-01/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "contact"
  ],
  "type": "registry:block"
}