{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "teams-05",
  "title": "Empty team that invites",
  "description": "A team with dashed seats that fill with each address invited, the Invite button going through Sending to Sent.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/mesh-tile.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/teams/teams-05.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useEffect, useId, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  CheckIcon,\n  LoaderIcon,\n  PlusIcon,\n  SendIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\n\nimport { rowCollapseOf } from './_parts/collapse';\nimport { SlidingCount } from './_parts/sliding-count';\nimport { Swap } from './_parts/swap';\nimport { TeamTile } from './_parts/team-tile';\n\ntype SendState = 'idle' | 'sending' | 'sent';\n\ntype Invite = { id: string; email: string; initials: string };\n\nconst MIN_SLOTS = 4;\nconst SEND_DELAY_MS = 650;\nconst SENT_RESET_MS = 1400;\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nconst MORPH: Transition = { type: 'spring', bounce: 0, duration: 0.3 };\nconst INSTANT: Transition = { duration: 0 };\nconst SEAT: Transition = { duration: 0.2, ease: [0.23, 1, 0.32, 1] };\n\nfunction morphOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return MORPH;\n}\n\nfunction seatScaleOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return 1;\n  }\n  return 0.85;\n}\n\nfunction sendLabelOf(state: SendState) {\n  if (state === 'sending') {\n    return 'Sending';\n  }\n  if (state === 'sent') {\n    return 'Sent';\n  }\n  return 'Invite';\n}\n\nfunction invitedLabelOf(count: number) {\n  if (count === 0) {\n    return 'No members yet';\n  }\n  if (count === 1) {\n    return '1 invited, waiting to join';\n  }\n  return `${count} invited, waiting to join`;\n}\n\nfunction initialsOf(email: string) {\n  const [localPart] = email.split('@');\n  const letters = localPart.slice(0, 2);\n  return letters.toUpperCase();\n}\n\nfunction emptySlotCountOf(invitedCount: number) {\n  const missing = MIN_SLOTS - invitedCount;\n  return Math.max(1, missing);\n}\n\nfunction errorOf(email: string, invites: Invite[]) {\n  if (!EMAIL_PATTERN.test(email)) {\n    return 'Enter an address like name@example.com';\n  }\n  const isAlreadyInvited = invites.some((invite) => invite.email === email);\n  if (isAlreadyInvited) {\n    return 'This address is already invited';\n  }\n  return null;\n}\n\nfunction useTimer() {\n  const timer = useRef<number | null>(null);\n\n  useEffect(() => {\n    return () => {\n      if (timer.current !== null) {\n        window.clearTimeout(timer.current);\n      }\n    };\n  }, []);\n\n  function schedule(callback: () => void, delay: number) {\n    if (timer.current !== null) {\n      window.clearTimeout(timer.current);\n    }\n    timer.current = window.setTimeout(() => {\n      timer.current = null;\n      callback();\n    }, delay);\n  }\n\n  return schedule;\n}\n\nfunction Seats({ invites }: { invites: Invite[] }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const seatScale = seatScaleOf(shouldReduceMotion);\n  const emptyCount = emptySlotCountOf(invites.length);\n  const emptySlots = Array.from({ length: emptyCount }, (_, index) => index);\n\n  return (\n    <ul aria-label='Seats' className='flex flex-wrap gap-2'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        {invites.map((invite) => (\n          <motion.li\n            key={invite.id}\n            layout\n            initial={{ opacity: 0, scale: seatScale }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0, scale: seatScale }}\n            transition={SEAT}\n          >\n            <Avatar\n              className='hairline-border border-foreground/30 size-9 border-dashed bg-transparent ring-0'\n              seed={invite.email}\n            />\n            <span className='sr-only'>{invite.email}, invited</span>\n          </motion.li>\n        ))}\n        {emptySlots.map((slot) => (\n          <motion.li\n            key={`empty-${slot}`}\n            layout\n            aria-hidden='true'\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={SEAT}\n            className='hairline-border border-foreground/20 text-muted-foreground/60 flex size-9 items-center justify-center rounded-full border-dashed'\n          >\n            <PlusIcon className='size-3.5' />\n          </motion.li>\n        ))}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\nfunction InviteChips({\n  invites,\n  onRemove,\n}: {\n  invites: Invite[];\n  onRemove: (inviteId: string) => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const chipScale = seatScaleOf(shouldReduceMotion);\n\n  return (\n    <ul aria-label='Pending invites' className='flex flex-wrap gap-1.5'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        {invites.map((invite) => (\n          <motion.li\n            key={invite.id}\n            layout\n            initial={{ opacity: 0, scale: chipScale }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0, scale: chipScale }}\n            transition={SEAT}\n            className='bg-foreground/[0.05] inline-flex h-6 items-center gap-1 rounded-md ps-2 pe-0.5 text-xs'\n          >\n            {invite.email}\n            <button\n              type='button'\n              aria-label={`Cancel the invite to ${invite.email}`}\n              onClick={() => onRemove(invite.id)}\n              className='text-muted-foreground hover:text-foreground hover:bg-foreground/5 focus-visible:ring-ring/25 inline-flex size-5 cursor-pointer items-center justify-center rounded-[5px] outline-none focus-visible:ring-[3px]'\n            >\n              <XIcon className='size-3' />\n            </button>\n          </motion.li>\n        ))}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\nexport default function Teams05() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const titleId = useId();\n  const errorId = useId();\n  const [draft, setDraft] = useState('');\n  const [error, setError] = useState<string | null>(null);\n  const [invites, setInvites] = useState<Invite[]>([]);\n  const [sendState, setSendState] = useState<SendState>('idle');\n  const schedule = useTimer();\n  const morph = morphOf(shouldReduceMotion);\n  const hasError = error !== null;\n  const isSending = sendState === 'sending';\n  const hasInvites = invites.length > 0;\n\n  function changeDraft(event: React.ChangeEvent<HTMLInputElement>) {\n    setDraft(event.target.value);\n    setError(null);\n  }\n\n  function addInvite(email: string) {\n    const invite = { id: email, email, initials: initialsOf(email) };\n    setInvites((current) => [...current, invite]);\n    setDraft('');\n    setSendState('sent');\n    schedule(() => setSendState('idle'), SENT_RESET_MS);\n  }\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    if (isSending) {\n      return;\n    }\n    const email = draft.trim();\n    const problem = errorOf(email, invites);\n    if (problem) {\n      setError(problem);\n      return;\n    }\n    setSendState('sending');\n    schedule(() => addInvite(email), SEND_DELAY_MS);\n  }\n\n  function removeInvite(inviteId: string) {\n    setInvites((current) => current.filter((invite) => invite.id !== inviteId));\n  }\n\n  return (\n    <section\n      aria-labelledby={titleId}\n      className='bg-card hairline-ring ring-border flex w-full max-w-[26rem] flex-col gap-4 rounded-xl p-5 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <div className='flex items-center gap-3'>\n        <TeamTile name='Design guild' color='var(--primary)' size='lg' />\n        <div className='min-w-0'>\n          <h3 id={titleId} className='text-sm font-medium'>\n            Design guild\n          </h3>\n          <SlidingCount\n            value={invites.length}\n            format={invitedLabelOf}\n            className='text-muted-foreground text-xs'\n          />\n        </div>\n      </div>\n      <Seats invites={invites} />\n      <p className='text-muted-foreground text-[13px] leading-5'>\n        Invite the people who will work here. They join as members once they\n        accept.\n      </p>\n      <form noValidate onSubmit={submit} className='flex items-start gap-2'>\n        <div className='min-w-0 flex-1'>\n          <Input\n            type='email'\n            value={draft}\n            onChange={changeDraft}\n            placeholder='name@example.com'\n            aria-label='Email address to invite'\n            aria-invalid={hasError}\n            aria-describedby={errorId}\n          />\n          <AnimatePresence initial={false}>\n            {hasError && (\n              <motion.p\n                key='error'\n                id={errorId}\n                variants={rowCollapseOf(shouldReduceMotion)}\n                initial='hidden'\n                animate='shown'\n                exit='hidden'\n                className='text-destructive-ink overflow-hidden text-xs'\n              >\n                <span className='block pt-1.5'>{error}</span>\n              </motion.p>\n            )}\n          </AnimatePresence>\n        </div>\n        <Button type='submit' aria-disabled={isSending}>\n          <Swap swapKey={sendState}>\n            {sendState === 'idle' && <SendIcon />}\n            {isSending && <LoaderIcon className='animate-spin' />}\n            {sendState === 'sent' && <CheckIcon />}\n          </Swap>\n          <motion.span layout transition={morph}>\n            {sendLabelOf(sendState)}\n          </motion.span>\n        </Button>\n      </form>\n      <AnimatePresence initial={false}>\n        {hasInvites && (\n          <motion.div\n            key='chips'\n            variants={rowCollapseOf(shouldReduceMotion)}\n            initial='hidden'\n            animate='shown'\n            exit='hidden'\n            className='-mt-4 overflow-hidden'\n          >\n            <div className='pt-4'>\n              <InviteChips invites={invites} onRemove={removeInvite} />\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/teams-05.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/collapse.ts",
      "content": "import type { Transition, Variants } from 'motion/react';\n\nconst EASE_OUT_STRONG: [number, number, number, number] = [0.23, 1, 0.32, 1];\n\n/**\n * The spring AnimatedSize resizes with. It starts from rest, so the fade leads and the freed space\n * closes after it at the pace the surrounding container follows, instead of snapping shut.\n */\nconst SIZE_SPRING: Transition = { type: 'spring', bounce: 0, duration: 0.32 };\n\nconst ARRIVE: Transition = {\n  ...SIZE_SPRING,\n  opacity: { duration: 0.2, ease: EASE_OUT_STRONG },\n};\n\nconst LEAVE: Transition = {\n  ...SIZE_SPRING,\n  opacity: { duration: 0.12, ease: EASE_OUT_STRONG },\n};\n\nconst ARRIVE_FADE: Transition = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nconst LEAVE_FADE: Transition = { duration: 0.12, ease: EASE_OUT_STRONG };\n\n/** A row whose spacing sits inside it: only its height and opacity change. */\nconst ROW_VARIANTS: Variants = {\n  shown: { height: 'auto', opacity: 1, transition: ARRIVE },\n  hidden: { height: 0, opacity: 0, transition: LEAVE },\n};\n\n/** A padded surface dismissed for good: its padding closes with its height. */\nconst SURFACE_VARIANTS: Variants = {\n  shown: { height: 'auto', opacity: 1, transition: ARRIVE },\n  hidden: {\n    height: 0,\n    opacity: 0,\n    paddingTop: 0,\n    paddingBottom: 0,\n    transition: LEAVE,\n  },\n};\n\nconst FADE_VARIANTS: Variants = {\n  shown: { opacity: 1, transition: ARRIVE_FADE },\n  hidden: { opacity: 0, transition: LEAVE_FADE },\n};\n\nexport function rowCollapseOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return ROW_VARIANTS;\n}\n\nexport function surfaceCollapseOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SURFACE_VARIANTS;\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/collapse.ts"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/sliding-count.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst SHIFT_PX = 8;\n\nconst SLIDE_TRANSITION: Transition = { duration: 0.18, ease: [0.2, 0, 0, 1] };\n\nconst SLIDE_VARIANTS: Variants = {\n  enter: (direction: number) => {\n    const offset = direction * SHIFT_PX;\n    return { opacity: 0, y: offset };\n  },\n  visible: { opacity: 1, y: 0 },\n  exit: (direction: number) => {\n    const offset = direction * SHIFT_PX;\n    return { opacity: 0, y: -offset };\n  },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction variantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SLIDE_VARIANTS;\n}\n\nfunction directionOf(previous: number, next: number) {\n  if (next > previous) {\n    return 1;\n  }\n  return -1;\n}\n\ntype Shown = { value: number; direction: number };\n\ntype SlidingCountProps = {\n  value: number;\n  /** Writes the figure in words, with its singular branch. */\n  format: (value: number) => string;\n  className?: string;\n};\n\n/** A figure the person just changed: it slides in the direction of the change. */\nexport function SlidingCount({ value, format, className }: SlidingCountProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [shown, setShown] = useState<Shown>({ value, direction: 1 });\n  const text = format(value);\n\n  if (shown.value !== value) {\n    const direction = directionOf(shown.value, value);\n    setShown({ value, direction });\n  }\n\n  return (\n    <span\n      className={cn(\n        'relative inline-flex overflow-hidden tabular-nums',\n        className\n      )}\n    >\n      <AnimatePresence\n        mode='popLayout'\n        initial={false}\n        custom={shown.direction}\n      >\n        <motion.span\n          key={text}\n          custom={shown.direction}\n          variants={variantsOf(shouldReduceMotion)}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SLIDE_TRANSITION}\n          className='whitespace-nowrap'\n        >\n          {text}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/sliding-count.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/swap.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_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 variantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\ntype SwapProps = {\n  /** Changes when the content becomes another one. */\n  swapKey: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/** An icon that becomes another: the old one shrinks out of focus while the new one settles. */\nexport function Swap({ swapKey, className, children }: SwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  return (\n    <AnimatePresence mode='popLayout' initial={false}>\n      <motion.span\n        key={swapKey}\n        variants={variantsOf(shouldReduceMotion)}\n        initial='enter'\n        animate='visible'\n        exit='exit'\n        transition={SWAP_TRANSITION}\n        className={cn('flex', className)}\n      >\n        {children}\n      </motion.span>\n    </AnimatePresence>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/swap.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/team-tile.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nconst SIZE_CLASS = {\n  sm: 'size-5 rounded-[5px]',\n  md: 'size-6 rounded-md',\n  lg: 'size-9 rounded-lg',\n} as const;\n\ntype TeamTileProps = {\n  name: string;\n  color: string;\n  size?: keyof typeof SIZE_CLASS;\n  className?: string;\n};\n\n/** A team without a logo: a picture drawn from its name, in its colour. */\nexport function TeamTile({\n  name,\n  color,\n  size = 'md',\n  className,\n}: TeamTileProps) {\n  const sizeClass = SIZE_CLASS[size];\n\n  return (\n    <MeshTile seed={name} color={color} className={cn(sizeClass, className)} />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/team-tile.tsx"
    }
  ],
  "categories": [
    "components",
    "teams"
  ],
  "type": "registry:component"
}