{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal-02",
  "title": "Invite with a seat limit",
  "description": "A seat meter that reserves a seat for each address in the field and flags the ones left without a seat",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/modal/modal-02.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  AlertCircleIcon,\n  CheckIcon,\n  PlusIcon,\n  SendIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Chip } from '@/registry/ndeko/ui/chip';\n\nimport { ActionButton, useTimedAction } from './_parts/action-button';\nimport { AddressField, type FieldChip } from './_parts/address-field';\nimport {\n  ADDRESS_LOOK,\n  mergeAddresses,\n  splitAddresses,\n  stateOfAddress,\n  type AddressLook,\n  type AddressState,\n} from './_parts/invite-emails';\nimport {\n  ModalDescription,\n  ModalHeader,\n  ModalPreview,\n  ModalTitle,\n} from './_parts/modal-frame';\nimport { chipVariantsOf, rowVariantsOf } from './_parts/motion';\nimport { PEOPLE, WORKSPACE_NAME } from './_parts/people';\nimport { PendingAvatar, PersonAvatar } from './_parts/person-avatar';\nimport { Swap } from './_parts/swap';\n\ntype InviteStatus = 'sent' | 'joined';\n\ntype RecentInvite = { email: string; status: InviteStatus };\n\ntype SeatState = 'used' | 'reserved' | 'free';\n\n/** People in the workspace who are not in the recent list, each holding a seat. */\nconst OTHER_MEMBERS = 3;\n\nconst SEATS_PER_STEP = 5;\n\nconst RECENT_INVITES: RecentInvite[] = [\n  { email: 'priya@lattice.example', status: 'joined' },\n  { email: 'noor.haddad@lattice.example', status: 'sent' },\n  { email: 'mateo@lattice.example', status: 'joined' },\n  { email: 'kofi.mensah@lattice.example', status: 'sent' },\n];\n\nconst NO_SEAT_LOOK: AddressLook = {\n  color: 'var(--destructive)',\n  icon: AlertCircleIcon,\n  hint: 'No seat left for this address',\n};\n\nconst MEMBER_EMAILS = new Set(PEOPLE.map((person) => person.email));\n\ntype FieldEntry = { email: string; state: AddressState; hasSeat: boolean };\n\nfunction seatStateOf(index: number, used: number, reserved: number): SeatState {\n  if (index < used) {\n    return 'used';\n  }\n  const reservedEnd = used + reserved;\n  if (index < reservedEnd) {\n    return 'reserved';\n  }\n  return 'free';\n}\n\nconst SEAT_CLASS: Record<SeatState, string> = {\n  used: 'bg-primary border-transparent',\n  reserved: 'hairline-border border-dashed border-primary bg-primary/10',\n  free: 'bg-foreground/[0.08] border-transparent',\n};\n\nfunction lookOf(entry: FieldEntry): AddressLook {\n  const isNew = entry.state === 'new';\n  const lacksSeat = isNew && !entry.hasSeat;\n  if (lacksSeat) {\n    return NO_SEAT_LOOK;\n  }\n  return ADDRESS_LOOK[entry.state];\n}\n\nfunction entriesOf(\n  addresses: string[],\n  pendingEmails: ReadonlySet<string>,\n  freeSeats: number\n) {\n  const context = { memberEmails: MEMBER_EMAILS, pendingEmails };\n  const entries: FieldEntry[] = [];\n  let seatsLeft = freeSeats;\n  for (const email of addresses) {\n    const state = stateOfAddress(email, context);\n    const isNew = state === 'new';\n    const hasSeat = isNew && seatsLeft > 0;\n    if (hasSeat) {\n      seatsLeft -= 1;\n    }\n    entries.push({ email, state, hasSeat });\n  }\n  return entries;\n}\n\nfunction seatLineOf(reserved: number, lacking: number, freeSeats: number) {\n  if (lacking === 1) {\n    return '1 address has no seat left. Add seats or remove it';\n  }\n  if (lacking > 1) {\n    return `${lacking} addresses have no seat left. Add seats or remove them`;\n  }\n  if (reserved === 1) {\n    return 'The address below takes 1 more seat';\n  }\n  if (reserved > 1) {\n    return `The ${reserved} addresses below take ${reserved} more seats`;\n  }\n  if (freeSeats === 1) {\n    return '1 seat left on your plan';\n  }\n  return `${freeSeats} seats left on your plan`;\n}\n\nfunction sendLabelOf(count: number) {\n  if (count > 1) {\n    return `Send ${count} invitations`;\n  }\n  return 'Send invitation';\n}\n\nconst STATUS_LOOK: Record<\n  InviteStatus,\n  { label: string; color: string; hasCheck: boolean }\n> = {\n  sent: {\n    label: 'Invite sent',\n    color: 'var(--muted-foreground)',\n    hasCheck: false,\n  },\n  joined: { label: 'Joined', color: 'var(--success)', hasCheck: true },\n};\n\nfunction RecentRow({ invite }: { invite: RecentInvite }) {\n  const person = PEOPLE.find((candidate) => candidate.email === invite.email);\n  const look = STATUS_LOOK[invite.status];\n\n  return (\n    <div className='flex min-h-12 items-center gap-3 px-3 py-2'>\n      {person && <PersonAvatar person={person} />}\n      {!person && <PendingAvatar />}\n      <p className='min-w-0 flex-1 truncate text-[13px]'>{invite.email}</p>\n      <Chip color={look.color}>\n        {look.hasCheck && <CheckIcon strokeWidth={2.5} />}\n        {look.label}\n      </Chip>\n    </div>\n  );\n}\n\nfunction SeatMeter({\n  capacity,\n  used,\n  reserved,\n  line,\n  isShort,\n  onAddSeats,\n}: {\n  capacity: number;\n  used: number;\n  reserved: number;\n  line: string;\n  isShort: boolean;\n  onAddSeats: () => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const cellVariants = chipVariantsOf(shouldReduceMotion);\n  const allowsLayout = !shouldReduceMotion;\n  const labelId = useId();\n  const addAction = useTimedAction();\n  const seats = Array.from({ length: capacity }, (_, index) => index);\n\n  function addSeats() {\n    addAction.run(onAddSeats);\n  }\n\n  return (\n    <div className='bg-foreground/[0.03] flex flex-col gap-3 rounded-xl p-4'>\n      <div className='flex items-start gap-3'>\n        <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <p id={labelId} className='text-sm font-medium tabular-nums'>\n            <MotionNumber value={used} />\n            {' of '}\n            <MotionNumber value={capacity} />\n            {' seats used'}\n          </p>\n          <Swap\n            swapKey={line}\n            kind='label'\n            className={cn(\n              'flex min-w-0 text-xs',\n              isShort && 'text-destructive-ink',\n              !isShort && 'text-muted-foreground'\n            )}\n            contentClassName='max-w-full min-w-0 whitespace-normal'\n          >\n            {line}\n          </Swap>\n        </div>\n        <ActionButton\n          variant='outline'\n          size='sm'\n          state={addAction.state}\n          onClick={addSeats}\n          idleIcon={<PlusIcon />}\n          labels={{\n            idle: `Add ${SEATS_PER_STEP} seats`,\n            working: 'Adding',\n            done: 'Added',\n          }}\n        />\n      </div>\n      <div\n        role='meter'\n        aria-labelledby={labelId}\n        aria-valuemin={0}\n        aria-valuemax={capacity}\n        aria-valuenow={used}\n        className='flex gap-1'\n      >\n        <AnimatePresence initial={false}>\n          {seats.map((index) => {\n            const seatState = seatStateOf(index, used, reserved);\n\n            return (\n              <motion.span\n                key={index}\n                layout={allowsLayout}\n                variants={cellVariants}\n                initial='hidden'\n                animate='shown'\n                exit='hidden'\n                className={cn(\n                  'h-2 min-w-0 flex-1 rounded-full border transition-[background-color,border-color] duration-300 ease-(--ease-out-strong)',\n                  SEAT_CLASS[seatState]\n                )}\n              />\n            );\n          })}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nfunction InviteWithSeats() {\n  const [capacity, setCapacity] = useState(10);\n  const [recent, setRecent] = useState<RecentInvite[]>(RECENT_INVITES);\n  const [addresses, setAddresses] = useState<string[]>([\n    'ada.lindqvist@lattice.example',\n    'bruno.costa@lattice.example',\n    'lea.martin@lattice.example',\n    'sami.k@lattice.example',\n  ]);\n  const action = useTimedAction();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowVariants = rowVariantsOf(shouldReduceMotion);\n  const used = OTHER_MEMBERS + recent.length;\n  const freeSeats = Math.max(0, capacity - used);\n  const pendingEmails = new Set(recent.map((invite) => invite.email));\n  const entries = entriesOf(addresses, pendingEmails, freeSeats);\n  const seated = entries.filter((entry) => entry.hasSeat);\n  const reserved = seated.length;\n  const lackingEntries = entries.filter((entry) => {\n    const isNew = entry.state === 'new';\n    return isNew && !entry.hasSeat;\n  });\n  const lacking = lackingEntries.length;\n  const isShort = lacking > 0;\n  const line = seatLineOf(reserved, lacking, freeSeats);\n  const chips: FieldChip[] = entries.map((entry) => ({\n    email: entry.email,\n    look: lookOf(entry),\n  }));\n  const canSend = reserved > 0;\n\n  function addAddresses(text: string) {\n    const added = splitAddresses(text);\n    setAddresses((previous) => mergeAddresses(previous, added));\n  }\n\n  function removeAddress(email: string) {\n    setAddresses((previous) => previous.filter((item) => item !== email));\n  }\n\n  function addSeats() {\n    setCapacity((previous) => previous + SEATS_PER_STEP);\n  }\n\n  function commitSend() {\n    const sentEmails = seated.map((entry) => entry.email);\n    const created = sentEmails.map((email) => ({\n      email,\n      status: 'sent' as const,\n    }));\n    setRecent((previous) => [...created, ...previous]);\n    setAddresses((previous) =>\n      previous.filter((email) => !sentEmails.includes(email))\n    );\n  }\n\n  function send(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    if (!canSend) {\n      return;\n    }\n    action.run(commitSend);\n  }\n\n  function sendFromShortcut() {\n    if (!canSend) {\n      return;\n    }\n    action.run(commitSend);\n  }\n\n  return (\n    <>\n      <ModalHeader>\n        <ModalTitle>{`Invite people to ${WORKSPACE_NAME}`}</ModalTitle>\n        <ModalDescription>\n          Everyone who joins or is invited takes one seat of your plan\n        </ModalDescription>\n      </ModalHeader>\n      <SeatMeter\n        capacity={capacity}\n        used={used}\n        reserved={reserved}\n        line={line}\n        isShort={isShort}\n        onAddSeats={addSeats}\n      />\n      <form onSubmit={send} autoComplete='off' className='flex flex-col gap-2'>\n        <AddressField\n          label='E-mail addresses'\n          chips={chips}\n          onAdd={addAddresses}\n          onRemove={removeAddress}\n          onSubmitShortcut={sendFromShortcut}\n          isInvalid={isShort}\n        />\n        <div className='flex justify-end'>\n          <ActionButton\n            type='submit'\n            state={action.state}\n            disabled={!canSend}\n            idleIcon={<SendIcon />}\n            labels={{\n              idle: sendLabelOf(reserved),\n              working: 'Sending',\n              done: 'Sent',\n            }}\n          />\n        </div>\n      </form>\n      <section className='flex flex-col gap-2'>\n        <h3 className='text-muted-foreground text-xs font-medium'>\n          Recent invitations\n        </h3>\n        <ul className='bg-card hairline-ring ring-border flex flex-col overflow-hidden rounded-xl py-1 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n          <AnimatePresence initial={false}>\n            {recent.map((invite) => (\n              <motion.li\n                key={invite.email}\n                variants={rowVariants}\n                initial='hidden'\n                animate='shown'\n                exit='hidden'\n              >\n                <RecentRow invite={invite} />\n              </motion.li>\n            ))}\n          </AnimatePresence>\n        </ul>\n      </section>\n    </>\n  );\n}\n\nexport default function Modal02() {\n  return (\n    <ModalPreview triggerLabel='Open the seat limit dialog' size='lg'>\n      <InviteWithSeats />\n    </ModalPreview>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/modal-02.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/action-button.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { CheckIcon, LoaderCircleIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button, type ButtonProps } from '@/registry/ndeko/ui/button';\n\nimport { Swap } from './swap';\n\nexport type ActionState = 'idle' | 'working' | 'done';\n\nexport type ActionLabels = Record<ActionState, string>;\n\nconst WORKING_MS = 800;\n\nconst DONE_MS = 1600;\n\n/** The life of an action that takes a moment: working, then done for a beat, then ready again. The change is committed when the work ends. */\nexport function useTimedAction() {\n  const [state, setState] = useState<ActionState>('idle');\n  const commitRef = useRef<(() => void) | null>(null);\n\n  useEffect(() => {\n    if (state === 'working') {\n      const timeout = window.setTimeout(() => {\n        const commit = commitRef.current;\n        commitRef.current = null;\n        if (commit) {\n          commit();\n        }\n        setState('done');\n      }, WORKING_MS);\n      return () => window.clearTimeout(timeout);\n    }\n    if (state === 'done') {\n      const timeout = window.setTimeout(() => {\n        setState('idle');\n      }, DONE_MS);\n      return () => window.clearTimeout(timeout);\n    }\n  }, [state]);\n\n  function run(commit: () => void) {\n    if (state !== 'idle') {\n      return;\n    }\n    commitRef.current = commit;\n    setState('working');\n  }\n\n  const isBusy = state !== 'idle';\n\n  return { state, run, isBusy };\n}\n\nfunction iconOf(state: ActionState, idleIcon: React.ReactNode) {\n  if (state === 'working') {\n    return <LoaderCircleIcon className='animate-spin' />;\n  }\n  if (state === 'done') {\n    return <CheckIcon />;\n  }\n  return idleIcon;\n}\n\ntype ActionButtonProps = Omit<ButtonProps, 'children'> & {\n  state: ActionState;\n  labels: ActionLabels;\n  idleIcon?: React.ReactNode;\n};\n\n/** One button that becomes its next state: its icon swaps, its label crossfades and its width follows the new label. */\nexport function ActionButton({\n  state,\n  labels,\n  idleIcon,\n  ...props\n}: ActionButtonProps) {\n  const icon = iconOf(state, idleIcon);\n  const hasIcon = Boolean(icon);\n  const label = labels[state];\n  const isWorking = state === 'working';\n  const isDone = state === 'done';\n\n  return (\n    <>\n      <Button aria-busy={isWorking} {...props}>\n        {hasIcon && <Swap swapKey={state}>{icon}</Swap>}\n        <AnimatedSize axis='width' as='span'>\n          <Swap swapKey={label} kind='label'>\n            {label}\n          </Swap>\n        </AnimatedSize>\n      </Button>\n      <span className='sr-only' role='status'>\n        {isDone && labels.done}\n      </span>\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/action-button.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/address-field.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { XIcon } from '@/registry/ndeko/lib/icons';\nimport { CONTROL_RECIPE } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Chip } from '@/registry/ndeko/ui/chip';\n\nimport {\n  ADDRESS_LOOK,\n  type AddressEntry,\n  type AddressLook,\n} from './invite-emails';\nimport { chipVariantsOf } from './motion';\n\nexport type FieldChip = { email: string; look: AddressLook };\n\nexport function chipsOf(entries: AddressEntry[]): FieldChip[] {\n  return entries.map((entry) => ({\n    email: entry.email,\n    look: ADDRESS_LOOK[entry.state],\n  }));\n}\n\nconst COMMIT_KEYS = new Set(['Enter', ',', ';', ' ', 'Tab']);\n\nfunction placeholderOf(hasChips: boolean, empty: string, more: string) {\n  if (hasChips) {\n    return more;\n  }\n  return empty;\n}\n\nfunction AddressChip({\n  chip,\n  allowsLayout,\n  onRemove,\n}: {\n  chip: FieldChip;\n  allowsLayout: boolean;\n  onRemove: (email: string) => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = chipVariantsOf(shouldReduceMotion);\n  const ChipGlyph = chip.look.icon;\n  const hasHint = chip.look.hint.length > 0;\n\n  function remove() {\n    onRemove(chip.email);\n  }\n\n  return (\n    <motion.li\n      layout={allowsLayout}\n      variants={variants}\n      initial='hidden'\n      animate='shown'\n      exit='hidden'\n      title={chip.look.hint}\n      className='flex max-w-full'\n    >\n      <Chip\n        color={chip.look.color}\n        className='h-6 max-w-full gap-1 pr-0.5 pl-1.5 text-xs'\n      >\n        {ChipGlyph && <ChipGlyph strokeWidth={2.25} />}\n        <span className='truncate'>{chip.email}</span>\n        {hasHint && <span className='sr-only'>{chip.look.hint}</span>}\n        <button\n          type='button'\n          aria-label={`Remove ${chip.email}`}\n          onClick={remove}\n          className='hover:bg-foreground/10 focus-visible:ring-ring/25 flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-[5px] opacity-70 transition-[opacity,background-color] duration-150 outline-none hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-[3px]'\n        >\n          <XIcon className='size-3' />\n        </button>\n      </Chip>\n    </motion.li>\n  );\n}\n\ntype AddressFieldProps = {\n  label: string;\n  chips: FieldChip[];\n  onAdd: (text: string) => void;\n  onRemove: (email: string) => void;\n  /** Enter on an empty line, or Cmd Enter at any time, sends what the field holds. */\n  onSubmitShortcut?: () => void;\n  /** Sits at the right end of the field, such as the role of the batch. */\n  trailing?: React.ReactNode;\n  placeholder?: string;\n  morePlaceholder?: string;\n  describedBy?: string;\n  isInvalid?: boolean;\n  disabled?: boolean;\n  className?: string;\n};\n\n/**\n * One field for many addresses, like the To line of a mail: each address becomes a chip tinted by what sending\n * will do with it, a pasted list fills it at once, Backspace on an empty line takes the last chip back.\n */\nexport function AddressField({\n  label,\n  chips,\n  onAdd,\n  onRemove,\n  onSubmitShortcut,\n  trailing,\n  placeholder = 'name@company.com, another@company.com',\n  morePlaceholder = 'Add another address',\n  describedBy,\n  isInvalid = false,\n  disabled = false,\n  className,\n}: AddressFieldProps) {\n  const inputId = useId();\n  const inputRef = useRef<HTMLInputElement>(null);\n  const [draft, setDraft] = useState('');\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const allowsLayout = !shouldReduceMotion;\n  const hasChips = chips.length > 0;\n  const hasTrailing = Boolean(trailing);\n  const shownPlaceholder = placeholderOf(\n    hasChips,\n    placeholder,\n    morePlaceholder\n  );\n  const lastChip = chips.at(-1);\n\n  function focusInput() {\n    inputRef.current?.focus();\n  }\n\n  function commitDraft() {\n    const typed = draft.trim();\n    if (typed.length === 0) {\n      return false;\n    }\n    onAdd(typed);\n    setDraft('');\n    return true;\n  }\n\n  function changeDraft(event: React.ChangeEvent<HTMLInputElement>) {\n    setDraft(event.target.value);\n  }\n\n  function removeChip(email: string) {\n    onRemove(email);\n    focusInput();\n  }\n\n  function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n    const isEnter = event.key === 'Enter';\n    const hasModifier = event.metaKey || event.ctrlKey;\n    const isDraftEmpty = draft.trim().length === 0;\n    const isSubmitShortcut = isEnter && hasModifier;\n    const isEnterOnEmptyLine = isEnter && isDraftEmpty;\n    const asksToSend = isSubmitShortcut || isEnterOnEmptyLine;\n    if (asksToSend && onSubmitShortcut) {\n      event.preventDefault();\n      commitDraft();\n      onSubmitShortcut();\n      return;\n    }\n    if (COMMIT_KEYS.has(event.key)) {\n      const hasCommitted = commitDraft();\n      const isTab = event.key === 'Tab';\n      const keepsTabMoving = isTab && !hasCommitted;\n      if (!keepsTabMoving) {\n        event.preventDefault();\n      }\n      return;\n    }\n    const isBackspace = event.key === 'Backspace';\n    const takesLastChip = isBackspace && draft.length === 0;\n    if (takesLastChip && lastChip) {\n      onRemove(lastChip.email);\n    }\n  }\n\n  function handlePaste(event: React.ClipboardEvent<HTMLInputElement>) {\n    const pasted = event.clipboardData.getData('text');\n    event.preventDefault();\n    onAdd(`${draft} ${pasted}`);\n    setDraft('');\n  }\n\n  return (\n    <div\n      role='presentation'\n      onClick={focusInput}\n      data-invalid={isInvalid || undefined}\n      className={cn(\n        CONTROL_RECIPE,\n        'flex min-h-9 cursor-text items-start gap-1 p-1',\n        'focus-within:border-foreground/30 focus-within:ring-ring/25 focus-within:ring-[3px]',\n        className\n      )}\n    >\n      <div className='relative flex max-h-[7rem] min-w-0 flex-1 flex-wrap items-center gap-1 overflow-y-auto overscroll-contain'>\n        {hasChips && (\n          <ul aria-label='Addresses to invite' className='contents'>\n            <AnimatePresence initial={false} mode='popLayout'>\n              {chips.map((chip) => (\n                <AddressChip\n                  key={chip.email}\n                  chip={chip}\n                  allowsLayout={allowsLayout}\n                  onRemove={removeChip}\n                />\n              ))}\n            </AnimatePresence>\n          </ul>\n        )}\n        <label htmlFor={inputId} className='sr-only'>\n          {label}\n        </label>\n        <input\n          ref={inputRef}\n          id={inputId}\n          type='text'\n          inputMode='email'\n          autoComplete='off'\n          spellCheck={false}\n          value={draft}\n          disabled={disabled}\n          aria-describedby={describedBy}\n          aria-invalid={isInvalid || undefined}\n          placeholder={shownPlaceholder}\n          onChange={changeDraft}\n          onKeyDown={handleKeyDown}\n          onPaste={handlePaste}\n          onBlur={commitDraft}\n          className='placeholder:text-muted-foreground/75 h-7 min-w-36 flex-1 bg-transparent px-1.5 text-base outline-none disabled:cursor-not-allowed md:text-[13px]'\n        />\n      </div>\n      {hasTrailing && (\n        <div className='flex h-7 shrink-0 items-center'>{trailing}</div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/address-field.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/invite-emails.ts",
      "content": "import {\n  AlertCircleIcon,\n  ClockIcon,\n  UserIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\n\n/** What sending does to an address: a new invitation, the e-mail again for a pending one, nothing for a member or a typo. */\nexport type AddressState = 'new' | 'pending' | 'member' | 'invalid';\n\nexport type AddressEntry = { email: string; state: AddressState };\n\nexport type AddressLook = { color: string; icon: Icon | null; hint: string };\n\nexport const ADDRESS_LOOK: Record<AddressState, AddressLook> = {\n  new: { color: 'var(--muted-foreground)', icon: null, hint: '' },\n  pending: {\n    color: 'var(--warning)',\n    icon: ClockIcon,\n    hint: 'Already invited: they get the e-mail again',\n  },\n  member: {\n    color: 'var(--muted-foreground)',\n    icon: UserIcon,\n    hint: 'Already in the team: not invited again',\n  },\n  invalid: {\n    color: 'var(--destructive)',\n    icon: AlertCircleIcon,\n    hint: 'Not a valid e-mail address',\n  },\n};\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nconst TOKEN_SEPARATORS = /[\\s,;<>\"'()]+/;\n\nexport function isEmail(value: string) {\n  return EMAIL_PATTERN.test(value);\n}\n\nfunction normalizeAddress(value: string) {\n  const trimmed = value.trim();\n  return trimmed.toLowerCase();\n}\n\n/**\n * The addresses in what was typed or pasted, without repeats. When the text holds an address, the words around it\n * are names copied from a mail client and are left out.\n */\nexport function splitAddresses(text: string) {\n  const tokens = text.split(TOKEN_SEPARATORS);\n  const holdsAnAddress = text.includes('@');\n  const addresses: string[] = [];\n  for (const token of tokens) {\n    const address = normalizeAddress(token);\n    const isEmpty = address.length === 0;\n    const isNameAround = holdsAnAddress && !address.includes('@');\n    const isRepeat = addresses.includes(address);\n    if (isEmpty || isNameAround || isRepeat) {\n      continue;\n    }\n    addresses.push(address);\n  }\n  return addresses;\n}\n\nexport function mergeAddresses(current: string[], added: string[]) {\n  const merged = [...current];\n  for (const address of added) {\n    if (!merged.includes(address)) {\n      merged.push(address);\n    }\n  }\n  return merged;\n}\n\nexport type AddressContext = {\n  memberEmails: ReadonlySet<string>;\n  pendingEmails: ReadonlySet<string>;\n};\n\nexport function stateOfAddress(\n  email: string,\n  context: AddressContext\n): AddressState {\n  if (!isEmail(email)) {\n    return 'invalid';\n  }\n  if (context.memberEmails.has(email)) {\n    return 'member';\n  }\n  if (context.pendingEmails.has(email)) {\n    return 'pending';\n  }\n  return 'new';\n}\n\nexport function isSendable(state: AddressState) {\n  const isNew = state === 'new';\n  const isPending = state === 'pending';\n  return isNew || isPending;\n}\n\nexport function countOf(entries: AddressEntry[], state: AddressState) {\n  return entries.filter((entry) => entry.state === state).length;\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/invite-emails.ts"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/modal-frame.tsx",
      "content": "'use client';\n\nimport { createContext, useContext } from 'react';\n\nimport { SquareArrowOutUpRightIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button, type ButtonProps } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\n\n/** Where a modal's content is drawn: open in the page as a preview, or inside the real dialog. */\nexport type ModalHost = 'preview' | 'dialog';\n\nconst ModalHostContext = createContext<ModalHost>('preview');\n\nexport function useModalHost() {\n  return useContext(ModalHostContext);\n}\n\nexport type ModalSize = 'sm' | 'md' | 'lg' | 'xl';\n\nconst SIZE_CLASS: Record<ModalSize, string> = {\n  sm: 'max-w-sm',\n  md: 'max-w-md',\n  lg: 'max-w-lg',\n  xl: 'max-w-[44rem]',\n};\n\nconst TITLE = 'text-lg leading-tight font-semibold text-balance';\n\nconst DESCRIPTION = 'text-muted-foreground text-[13px]';\n\nconst BODY = 'flex flex-col gap-4';\n\ntype ModalTextProps = { className?: string; children: React.ReactNode };\n\nexport function ModalTitle({ className, children }: ModalTextProps) {\n  const host = useModalHost();\n  if (host === 'dialog') {\n    return <DialogTitle className={className}>{children}</DialogTitle>;\n  }\n  return <h2 className={cn(TITLE, className)}>{children}</h2>;\n}\n\nexport function ModalDescription({ className, children }: ModalTextProps) {\n  const host = useModalHost();\n  if (host === 'dialog') {\n    return (\n      <DialogDescription className={className}>{children}</DialogDescription>\n    );\n  }\n  return <p className={cn(DESCRIPTION, className)}>{children}</p>;\n}\n\n/** Leaves room for the dialog's close button, so the preview and the dialog lay out the same. */\nexport function ModalHeader({\n  className,\n  ...props\n}: React.ComponentProps<'div'>) {\n  return (\n    <div className={cn('flex flex-col gap-1.5 pr-8', className)} {...props} />\n  );\n}\n\nexport function ModalFooter({\n  className,\n  ...props\n}: React.ComponentProps<'div'>) {\n  return (\n    <div\n      className={cn(\n        'flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-end',\n        className\n      )}\n      {...props}\n    />\n  );\n}\n\n/** Closes the dialog. In the preview it stays a plain button that runs its own action, if any. */\nexport function ModalCloseButton({ children, ...props }: ButtonProps) {\n  const host = useModalHost();\n  if (host === 'dialog') {\n    return <DialogClose render={<Button {...props} />}>{children}</DialogClose>;\n  }\n  return <Button {...props}>{children}</Button>;\n}\n\ntype ModalPreviewProps = {\n  /** The content, drawn twice: open in the page, and inside the dialog the trigger opens. */\n  children: React.ReactNode;\n  triggerLabel: string;\n  size?: ModalSize;\n  className?: string;\n};\n\n/** Shows a modal open and whole on the page, with a small trigger that opens the same content in the real dialog. */\nexport function ModalPreview({\n  children,\n  triggerLabel,\n  size = 'md',\n  className,\n}: ModalPreviewProps) {\n  const sizeClass = SIZE_CLASS[size];\n\n  return (\n    <div className='flex w-full flex-col items-center gap-4'>\n      <ModalHostContext.Provider value='preview'>\n        <div\n          className={cn(\n            'surface-raised w-full rounded-2xl p-6 text-left',\n            sizeClass,\n            className\n          )}\n        >\n          <AnimatedSize contentClassName={BODY}>{children}</AnimatedSize>\n        </div>\n      </ModalHostContext.Provider>\n      <Dialog>\n        <DialogTrigger render={<Button variant='outline' size='sm' />}>\n          <SquareArrowOutUpRightIcon />\n          {triggerLabel}\n        </DialogTrigger>\n        <DialogContent className={cn(sizeClass, className)}>\n          <ModalHostContext.Provider value='dialog'>\n            {children}\n          </ModalHostContext.Provider>\n        </DialogContent>\n      </Dialog>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/modal-frame.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/motion.ts",
      "content": "import type { Transition, Variants } from 'motion/react';\n\nexport const SWAP_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.2, 0, 0, 1],\n};\n\nconst MORPH_SPRING: Transition = { type: 'spring', bounce: 0, duration: 0.3 };\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst PRESENCE_IN: Transition = { duration: 0.2, ease: [0.23, 1, 0.32, 1] };\n\nconst PRESENCE_OUT: Transition = { duration: 0.14, ease: [0.23, 1, 0.32, 1] };\n\nconst ICON_SWAP: 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 LABEL_SWAP: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst FADE_SWAP: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst ROW_PRESENCE: Variants = {\n  hidden: {\n    height: 0,\n    opacity: 0,\n    overflow: 'hidden',\n    transition: PRESENCE_OUT,\n  },\n  shown: {\n    height: 'auto',\n    opacity: 1,\n    transition: PRESENCE_IN,\n    transitionEnd: { overflow: 'visible' },\n  },\n};\n\nconst ROW_FADE: Variants = {\n  hidden: { opacity: 0, transition: PRESENCE_OUT },\n  shown: { opacity: 1, transition: PRESENCE_IN },\n};\n\nconst CHIP_PRESENCE: Variants = {\n  hidden: { opacity: 0, scale: 0.9, transition: PRESENCE_OUT },\n  shown: { opacity: 1, scale: 1, transition: PRESENCE_IN },\n};\n\nexport type SwapKind = 'icon' | 'label';\n\nexport function swapVariantsOf(\n  shouldReduceMotion: boolean | null,\n  kind: SwapKind = 'icon'\n) {\n  if (shouldReduceMotion) {\n    return FADE_SWAP;\n  }\n  if (kind === 'label') {\n    return LABEL_SWAP;\n  }\n  return ICON_SWAP;\n}\n\n/** A row added to or removed from a list: its height opens or collapses, so the rows after it slide. */\nexport function rowVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return ROW_FADE;\n  }\n  return ROW_PRESENCE;\n}\n\nexport function chipVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return ROW_FADE;\n  }\n  return CHIP_PRESENCE;\n}\n\nexport function morphOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return MORPH_SPRING;\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/motion.ts"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/people.ts",
      "content": "export type Presence = 'tracking' | 'online' | 'away' | 'offline';\n\nexport type Person = {\n  id: string;\n  name: string;\n  email: string;\n  title: string;\n  presence: Presence;\n};\n\nexport const WORKSPACE_NAME = 'Lattice';\n\nexport const TEAM_NAME = 'Product';\n\nexport const PEOPLE: Person[] = [\n  {\n    id: 'amara',\n    name: 'Amara Okafor',\n    email: 'amara@lattice.example',\n    title: 'Product designer',\n    presence: 'tracking',\n  },\n  {\n    id: 'lucas',\n    name: 'Lucas Moreau',\n    email: 'lucas@lattice.example',\n    title: 'Engineering lead',\n    presence: 'online',\n  },\n  {\n    id: 'priya',\n    name: 'Priya Raman',\n    email: 'priya@lattice.example',\n    title: 'Frontend engineer',\n    presence: 'online',\n  },\n  {\n    id: 'mateo',\n    name: 'Mateo Silva',\n    email: 'mateo@lattice.example',\n    title: 'Backend engineer',\n    presence: 'away',\n  },\n  {\n    id: 'hana',\n    name: 'Hana Kobayashi',\n    email: 'hana@lattice.example',\n    title: 'Product manager',\n    presence: 'tracking',\n  },\n  {\n    id: 'jonas',\n    name: 'Jonas Weber',\n    email: 'jonas@lattice.example',\n    title: 'QA engineer',\n    presence: 'offline',\n  },\n  {\n    id: 'zola',\n    name: 'Zola Mbeki',\n    email: 'zola@lattice.example',\n    title: 'Content designer',\n    presence: 'online',\n  },\n  {\n    id: 'theo',\n    name: 'Théo Laurent',\n    email: 'theo@lattice.example',\n    title: 'Data analyst',\n    presence: 'away',\n  },\n  {\n    id: 'sana',\n    name: 'Sana Iqbal',\n    email: 'sana@lattice.example',\n    title: 'Support lead',\n    presence: 'offline',\n  },\n];\n\n/** The person a preview is seen by. */\nexport const CURRENT_USER: Person = PEOPLE[0];\n\nexport function personById(id: string) {\n  return PEOPLE.find((person) => person.id === id);\n}\n\nexport function firstNameOf(person: Person) {\n  const [firstName] = person.name.split(' ');\n  return firstName;\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/people.ts"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/person-avatar.tsx",
      "content": "import {\n  CheckIcon,\n  ClockIcon,\n  type Icon,\n  MailIcon,\n  MinusIcon,\n  MoonIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport type { Person, Presence } from './people';\n\ntype PresenceMeta = { label: string; color: string; icon: Icon };\n\nexport const PRESENCE_META: Record<Presence, PresenceMeta> = {\n  tracking: {\n    label: 'Tracking time',\n    color: 'var(--primary)',\n    icon: ClockIcon,\n  },\n  online: { label: 'Online', color: 'var(--success)', icon: CheckIcon },\n  away: { label: 'Away', color: 'var(--warning)', icon: MoonIcon },\n  offline: {\n    label: 'Offline',\n    color: 'var(--muted-foreground)',\n    icon: MinusIcon,\n  },\n};\n\ntype AvatarSize = 'sm' | 'md' | 'lg';\n\nconst AVATAR_SIZE: Record<AvatarSize, string> = {\n  sm: 'size-6',\n  md: 'size-8',\n  lg: 'size-10',\n};\n\nconst BADGE_SIZE: Record<AvatarSize, string> = {\n  sm: 'size-3 [&_svg]:size-2',\n  md: 'size-3.5 [&_svg]:size-2',\n  lg: 'size-4 [&_svg]:size-2.5',\n};\n\ntype PersonAvatarProps = {\n  person: Pick<Person, 'name'>;\n  size?: AvatarSize;\n  /** Drawn as a small glyph on the avatar; its label is read by screen readers. */\n  presence?: Presence;\n  className?: string;\n};\n\nexport function PersonAvatar({\n  person,\n  size = 'md',\n  presence,\n  className,\n}: PersonAvatarProps) {\n  return (\n    <span className={cn('relative inline-flex shrink-0', className)}>\n      <Avatar className={AVATAR_SIZE[size]} seed={person.name} />\n      {presence && <PresenceBadge presence={presence} size={size} />}\n    </span>\n  );\n}\n\nfunction PresenceBadge({\n  presence,\n  size,\n}: {\n  presence: Presence;\n  size: AvatarSize;\n}) {\n  const meta = PRESENCE_META[presence];\n  const PresenceGlyph = meta.icon;\n  const badgeStyle = { '--chip': meta.color } as React.CSSProperties;\n\n  return (\n    <>\n      <span className='bg-popover absolute -right-0.5 -bottom-0.5 flex rounded-full p-px'>\n        <span\n          style={badgeStyle}\n          className={cn(\n            'chip-3d flex items-center justify-center rounded-full',\n            BADGE_SIZE[size]\n          )}\n        >\n          <PresenceGlyph strokeWidth={2.75} />\n        </span>\n      </span>\n      <span className='sr-only'>{meta.label}</span>\n    </>\n  );\n}\n\ntype PendingAvatarProps = {\n  size?: AvatarSize;\n  className?: string;\n};\n\n/** Someone invited who has not joined yet: an empty dashed slot with an envelope and a clock. */\nexport function PendingAvatar({ size = 'md', className }: PendingAvatarProps) {\n  const clockStyle = { '--chip': 'var(--warning)' } as React.CSSProperties;\n\n  return (\n    <span\n      aria-hidden='true'\n      className={cn('relative inline-flex shrink-0', className)}\n    >\n      <span\n        className={cn(\n          'hairline-border border-foreground/25 text-muted-foreground flex items-center justify-center rounded-full border-dashed',\n          AVATAR_SIZE[size]\n        )}\n      >\n        <MailIcon className='size-[45%]' />\n      </span>\n      <span className='bg-popover absolute -right-0.5 -bottom-0.5 flex rounded-full p-px'>\n        <span\n          style={clockStyle}\n          className={cn(\n            'chip-3d flex items-center justify-center rounded-full',\n            BADGE_SIZE[size]\n          )}\n        >\n          <ClockIcon strokeWidth={2.75} />\n        </span>\n      </span>\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/person-avatar.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/swap.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { SWAP_TRANSITION, swapVariantsOf, type SwapKind } from './motion';\n\ntype SwapProps = {\n  /** Changes when the content becomes another: the old one leaves while the new one arrives in its place. */\n  swapKey: string;\n  kind?: SwapKind;\n  className?: string;\n  /** Classes of the moving content, for example `min-w-0 max-w-full` so a long text can truncate inside. */\n  contentClassName?: string;\n  children: React.ReactNode;\n};\n\nexport function Swap({\n  swapKey,\n  kind = 'icon',\n  className,\n  contentClassName,\n  children,\n}: SwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion, kind);\n\n  return (\n    <span className={cn('relative inline-flex items-center', className)}>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={swapKey}\n          className={cn(\n            'inline-flex items-center gap-[inherit] whitespace-nowrap',\n            contentClassName\n          )}\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP_TRANSITION}\n        >\n          {children}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/swap.tsx"
    }
  ],
  "categories": [
    "components",
    "modal"
  ],
  "type": "registry:component"
}