{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "heroes-10",
  "title": "Waitlist hero",
  "description": "A waitlist hero with an email field that checks the address and morphs into You are on the list, above a stack of avatars where each new member slides in while the oldest tucks under a rolling counter.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/field.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/wash.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/heroes/heroes-10/index.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport {\n  type AutoplayStep,\n  typingSteps,\n  useAutoplay,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport { AvatarStack } from './avatar-stack';\nimport { DEMO_EMAIL, HERO, type Status } from './data';\nimport { EmailForm } from './email-form';\nimport { INITIAL_STACK, type Stack, withDemoJoin, withJoin } from './stack';\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nconst JOIN_DELAY_MS = 900;\n\nconst NEW_MEMBER_EVERY_MS = 2400;\n\nfunction emailErrorOf(value: string) {\n  const trimmed = value.trim();\n  if (trimmed.length === 0) {\n    return HERO.emptyError;\n  }\n  const isEmailShaped = EMAIL_PATTERN.test(trimmed);\n  if (!isEmailShaped) {\n    return HERO.shapeError;\n  }\n  return null;\n}\n\nfunction announcementOf(error: string | null, status: Status) {\n  if (error !== null) {\n    return error;\n  }\n  if (status === 'done') {\n    return HERO.doneAnnouncement;\n  }\n  return '';\n}\n\nexport default function Heroes10() {\n  const [email, setEmail] = useState('');\n  const [status, setStatus] = useState<Status>('idle');\n  const [error, setError] = useState<string | null>(null);\n  const [hasTriedSubmit, setHasTriedSubmit] = useState(false);\n  const [stack, setStack] = useState<Stack>(INITIAL_STACK);\n  const inputRef = useRef<HTMLInputElement>(null);\n  const { pressed, press } = usePress<'join'>();\n\n  useEffect(() => {\n    if (status !== 'busy') {\n      return;\n    }\n    const timeout = window.setTimeout(() => {\n      setStatus('done');\n      setStack((current) => withJoin(current, email));\n    }, JOIN_DELAY_MS);\n    return () => window.clearTimeout(timeout);\n  }, [status, email]);\n\n  function changeEmail(value: string) {\n    setEmail(value);\n    if (hasTriedSubmit) {\n      setError(emailErrorOf(value));\n    }\n  }\n\n  function submit() {\n    const nextError = emailErrorOf(email);\n    setHasTriedSubmit(true);\n    setError(nextError);\n    if (nextError !== null) {\n      inputRef.current?.focus();\n      return;\n    }\n    setStatus('busy');\n  }\n\n  function startOver() {\n    setEmail('');\n    setStatus('idle');\n    setError(null);\n    setHasTriedSubmit(false);\n  }\n\n  function startAnother() {\n    startOver();\n    inputRef.current?.focus();\n  }\n\n  function addDemoMember() {\n    setStack(withDemoJoin);\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: NEW_MEMBER_EVERY_MS, run: addDemoMember },\n    { after: NEW_MEMBER_EVERY_MS, run: addDemoMember },\n    ...typingSteps(DEMO_EMAIL, setEmail, { startAfter: 700, characterMs: 55 }),\n    { after: 500, run: () => press('join') },\n    { after: PRESS_LEAD_MS, run: submit },\n    { after: NEW_MEMBER_EVERY_MS, run: addDemoMember },\n    { after: NEW_MEMBER_EVERY_MS, run: hold },\n  ];\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 600,\n    onReset: startOver,\n  });\n  const hasJoined = stack.count > INITIAL_STACK.count;\n  const announcement = announcementOf(error, status);\n  const message = spokenUnless(isAutoplaying, announcement);\n\n  useKeptHeight(ref);\n\n  return (\n    <section className='@container'>\n      <div ref={ref} className='relative isolate'>\n        <Wash className='h-[28rem]' />\n        <div className='mx-auto flex max-w-3xl flex-col items-center gap-6 px-4 py-16 text-center @2xl:px-6 @2xl:py-24'>\n          <p className='text-primary-ink text-sm font-medium'>{HERO.eyebrow}</p>\n          <h1 className='text-4xl font-semibold text-balance @2xl:text-5xl'>\n            {HERO.title}\n          </h1>\n          <p className='text-muted-foreground max-w-xl text-base text-pretty'>\n            {HERO.description}\n          </p>\n          <EmailForm\n            email={email}\n            status={status}\n            error={error}\n            isPressed={pressed === 'join'}\n            inputRef={inputRef}\n            onEmailChange={changeEmail}\n            onSubmit={submit}\n            onUseAnother={startAnother}\n          />\n          <AvatarStack stack={stack} hasJoined={hasJoined} />\n          <LiveRegion message={message} />\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/heroes-10/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/heroes/heroes-10/email-form.tsx",
      "content": "'use client';\n\nimport type { ChangeEvent, FormEvent, RefObject } from 'react';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Field, FieldError, FieldLabel } from '@/registry/ndeko/ui/field';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { MorphButton } from '@/registry/ndeko/ui/morph-button';\n\nimport { BUTTON_LABELS, HERO, type Status } from './data';\n\nfunction noteKeyOf(isDone: boolean) {\n  if (isDone) {\n    return 'done';\n  }\n  return 'note';\n}\n\ntype EmailFormProps = {\n  email: string;\n  status: Status;\n  error: string | null;\n  isPressed: boolean;\n  inputRef: RefObject<HTMLInputElement | null>;\n  onEmailChange: (value: string) => void;\n  onSubmit: () => void;\n  onUseAnother: () => void;\n};\n\nexport function EmailForm({\n  email,\n  status,\n  error,\n  isPressed,\n  inputRef,\n  onEmailChange,\n  onSubmit,\n  onUseAnother,\n}: EmailFormProps) {\n  const hasError = error !== null;\n  const isIdle = status === 'idle';\n  const isDone = status === 'done';\n  const noteKey = noteKeyOf(isDone);\n\n  function change(event: ChangeEvent<HTMLInputElement>) {\n    onEmailChange(event.target.value);\n  }\n\n  function submit(event: FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onSubmit();\n  }\n\n  return (\n    <form\n      noValidate\n      onSubmit={submit}\n      className='flex w-full max-w-md flex-col gap-2'\n    >\n      <Field invalid={hasError}>\n        <FieldLabel className='sr-only'>{HERO.emailLabel}</FieldLabel>\n        <div className='flex flex-col gap-2 @md:flex-row'>\n          <Input\n            ref={inputRef}\n            type='email'\n            name='email'\n            size='lg'\n            autoComplete='email'\n            placeholder={HERO.emailPlaceholder}\n            value={email}\n            onChange={change}\n            readOnly={!isIdle}\n          />\n          <MorphButton\n            type='submit'\n            size='lg'\n            state={status}\n            labels={BUTTON_LABELS}\n            className={pressedSolidOf(isPressed)}\n          />\n        </div>\n        {hasError && <FieldError match>{error}</FieldError>}\n      </Field>\n      <Swap\n        swapKey={noteKey}\n        className='text-muted-foreground min-h-5 justify-center text-xs'\n      >\n        {!isDone && <span>{HERO.note}</span>}\n        {isDone && (\n          <span className='flex flex-wrap items-center justify-center gap-x-2'>\n            <span>{HERO.doneNote}</span>\n            <Button\n              type='button'\n              variant='link'\n              onClick={onUseAnother}\n              className='h-auto p-0 text-xs'\n            >\n              {HERO.useAnother}\n            </Button>\n          </span>\n        )}\n      </Swap>\n    </form>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/heroes-10/email-form.tsx"
    },
    {
      "path": "registry/ndeko/blocks/heroes/heroes-10/avatar-stack.tsx",
      "content": "import type { CSSProperties } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport { HERO, VISIBLE_COUNT } from './data';\nimport type { Stack } from './stack';\n\ntype SlotStyle = CSSProperties & { '--slot': number };\n\nfunction slotStyleOf(slot: number) {\n  const style: SlotStyle = { '--slot': slot };\n  return style;\n}\n\n/** The newest avatar slides in from beside the stack; the first ones are simply there. */\nfunction arrivalClassOf(isNewest: boolean, hasJoined: boolean) {\n  const isArriving = isNewest && hasJoined;\n  if (isArriving) {\n    return 'starting:opacity-0 starting:translate-x-[calc((var(--slot)_-_1)*1.5rem)]';\n  }\n  return undefined;\n}\n\nfunction tuckClassOf(isTucked: boolean) {\n  if (isTucked) {\n    return 'opacity-0';\n  }\n  return 'opacity-100';\n}\n\ntype AvatarStackProps = {\n  stack: Stack;\n  hasJoined: boolean;\n};\n\n/**\n * Avatars overlap in slots. Each one reads its slot from a custom property and its position\n * follows it with a transition, so a new member shifts the others along without any layout work.\n */\nexport function AvatarStack({ stack, hasJoined }: AvatarStackProps) {\n  return (\n    <div className='flex items-center gap-3'>\n      <div className='flex items-center'>\n        <div aria-hidden='true' className='relative h-9 w-24 shrink-0'>\n          {stack.members.map((member, slot) => (\n            <Avatar\n              key={member.id}\n              seed={member.name}\n              style={slotStyleOf(slot)}\n              className={cn(\n                'outline-background absolute top-0 left-0 size-9 translate-x-[calc(var(--slot)*1.5rem)] outline-2 transition-[translate,opacity] duration-500 ease-(--ease-out-strong) motion-reduce:transition-none',\n                tuckClassOf(slot >= VISIBLE_COUNT),\n                arrivalClassOf(slot === 0, hasJoined)\n              )}\n            />\n          ))}\n        </div>\n        <span className='bg-card hairline-ring ring-border outline-background relative z-10 inline-flex h-9 items-center rounded-full px-3 text-[13px] font-medium outline-2'>\n          <MotionNumber value={stack.count} className='tabular-nums' />\n        </span>\n      </div>\n      <div className='flex flex-col items-start text-start'>\n        <p className='text-[13px]'>{HERO.countCaption}</p>\n        <p className='text-muted-foreground text-xs'>{HERO.countNote}</p>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/heroes-10/avatar-stack.tsx"
    },
    {
      "path": "registry/ndeko/blocks/heroes/heroes-10/stack.ts",
      "content": "import {\n  BASE_COUNT,\n  DEMO_NAMES,\n  INITIAL_NAMES,\n  KEPT_COUNT,\n  type Member,\n} from './data';\n\nexport type Stack = {\n  /** Newest first. */\n  members: Member[];\n  count: number;\n  nextDemo: number;\n};\n\nconst INITIAL_MEMBERS: Member[] = INITIAL_NAMES.map((name, index) => ({\n  id: index,\n  name,\n}));\n\nexport const INITIAL_STACK: Stack = {\n  members: INITIAL_MEMBERS,\n  count: BASE_COUNT,\n  nextDemo: 0,\n};\n\nexport function withJoin(stack: Stack, name: string): Stack {\n  const count = stack.count + 1;\n  const member: Member = { id: count, name };\n  const members = [member, ...stack.members].slice(0, KEPT_COUNT);\n  return { ...stack, members, count };\n}\n\nexport function withDemoJoin(stack: Stack): Stack {\n  const position = stack.nextDemo % DEMO_NAMES.length;\n  const name = DEMO_NAMES[position];\n  const joined = withJoin(stack, name);\n  return { ...joined, nextDemo: stack.nextDemo + 1 };\n}\n",
      "type": "registry:component",
      "target": "components/blocks/heroes-10/stack.ts"
    },
    {
      "path": "registry/ndeko/blocks/heroes/heroes-10/data.ts",
      "content": "export type Member = {\n  id: number;\n  name: string;\n};\n\nexport type Status = 'idle' | 'busy' | 'done';\n\nexport const HERO = {\n  eyebrow: 'Opening in small groups',\n  title: 'A calmer inbox for people who work alone',\n  description:\n    'Your mail sorts itself into what needs a reply today and what can wait. We let people in a few at a time, in the order they joined.',\n  emailLabel: 'Email address',\n  emailPlaceholder: 'you@example.com',\n  emptyError: 'Enter your email address to join the waitlist',\n  shapeError: 'Check the address, it should look like name@example.com',\n  note: 'One email when a seat opens, nothing else',\n  doneNote: 'We will email you when a seat opens',\n  doneAnnouncement: 'You are on the list. We will email you when a seat opens.',\n  useAnother: 'Use another address',\n  countCaption: 'on the waitlist',\n  countNote: 'Illustrative count',\n};\n\nexport const BUTTON_LABELS: Record<Status, string> = {\n  idle: 'Join the waitlist',\n  busy: 'Joining',\n  done: 'You are on the list',\n};\n\nexport const DEMO_EMAIL = 'amara.n@example.com';\n\nexport const INITIAL_NAMES = [\n  'Noor Haddad',\n  'Patrick Kabongo',\n  'Lea Fontaine',\n  'Joseph Kasongo',\n  'Ines Moreau',\n];\n\nexport const DEMO_NAMES = [\n  'Tomas Rivera',\n  'Chantal Mbuyi',\n  'Kwame Boateng',\n  'Sofia Lindqvist',\n  'Daniel Okoye',\n  'Mireille Tshimanga',\n  'Hana Sato',\n  'Rafael Duarte',\n  'Grace Ilunga',\n  'Mateo Bianchi',\n];\n\nexport const BASE_COUNT = 2418;\n\n/** Avatars that show, and one more tucked under the counter while it leaves. */\nexport const VISIBLE_COUNT = 4;\n\nexport const KEPT_COUNT = VISIBLE_COUNT + 1;\n",
      "type": "registry:component",
      "target": "components/blocks/heroes-10/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "heroes"
  ],
  "type": "registry:block"
}