{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "teams-01",
  "title": "Team card",
  "description": "A team with its member stack, open tasks and time this week, where Join turns into Joined and your face joins the stack.",
  "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/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-01.tsx",
      "content": "'use client';\n\nimport { 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 { CheckIcon, LoaderIcon, PlusIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport { AvatarStack } from './_parts/avatar-stack';\nimport { MEMBERS, memberById } from './_parts/people';\nimport { SlidingCount } from './_parts/sliding-count';\nimport { Swap } from './_parts/swap';\nimport { TeamTile } from './_parts/team-tile';\nimport { TEAMS, memberCountLabelOf } from './_parts/teams';\n\ntype JoinState = 'idle' | 'joining' | 'joined';\n\nconst JOIN_DELAY_MS = 800;\n\nconst MORPH: Transition = { type: 'spring', bounce: 0, duration: 0.3 };\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst TEAM = TEAMS[1];\n\nconst TEAM_MEMBERS = TEAM.memberIds.map(memberById);\n\nconst YOU = MEMBERS[0];\n\nfunction morphOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return MORPH;\n}\n\nfunction joinLabelOf(state: JoinState) {\n  if (state === 'joining') {\n    return 'Joining';\n  }\n  if (state === 'joined') {\n    return 'Joined';\n  }\n  return 'Join team';\n}\n\nfunction joinVariantOf(state: JoinState) {\n  if (state === 'joined') {\n    return 'outline' as const;\n  }\n  return 'default' as const;\n}\n\nfunction membersOf(isJoined: boolean) {\n  if (isJoined) {\n    return [YOU, ...TEAM_MEMBERS];\n  }\n  return TEAM_MEMBERS;\n}\n\nfunction JoinGlyph({ state }: { state: JoinState }) {\n  return (\n    <Swap swapKey={state}>\n      {state === 'idle' && <PlusIcon />}\n      {state === 'joining' && <LoaderIcon className='animate-spin' />}\n      {state === 'joined' && <CheckIcon />}\n    </Swap>\n  );\n}\n\nfunction useDelayedJoin(onJoined: () => void) {\n  const timer = useRef<number | null>(null);\n  const onJoinedRef = useRef(onJoined);\n\n  useEffect(() => {\n    onJoinedRef.current = onJoined;\n  }, [onJoined]);\n\n  useEffect(() => {\n    return () => {\n      if (timer.current !== null) {\n        window.clearTimeout(timer.current);\n      }\n    };\n  }, []);\n\n  function start() {\n    timer.current = window.setTimeout(() => {\n      timer.current = null;\n      onJoinedRef.current();\n    }, JOIN_DELAY_MS);\n  }\n\n  return start;\n}\n\nexport default function Teams01() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const nameId = useId();\n  const [joinState, setJoinState] = useState<JoinState>('idle');\n  const isJoined = joinState === 'joined';\n  const members = membersOf(isJoined);\n  const extraCount = TEAM.memberCount - TEAM_MEMBERS.length;\n  const memberCount = members.length + extraCount;\n  const morph = morphOf(shouldReduceMotion);\n\n  function markJoined() {\n    setJoinState('joined');\n  }\n\n  const startJoining = useDelayedJoin(markJoined);\n\n  function toggleJoin() {\n    if (joinState === 'joining') {\n      return;\n    }\n    if (isJoined) {\n      setJoinState('idle');\n      return;\n    }\n    setJoinState('joining');\n    startJoining();\n  }\n\n  return (\n    <article\n      aria-labelledby={nameId}\n      className='bg-card hairline-ring ring-border flex w-full max-w-[24rem] flex-col gap-4 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <div className='flex items-start gap-3'>\n        <TeamTile name={TEAM.name} color={TEAM.color} size='lg' />\n        <div className='min-w-0 flex-1'>\n          <h3 id={nameId} className='text-sm font-medium'>\n            {TEAM.name}\n          </h3>\n          <p className='text-muted-foreground text-xs'>Mobile team · Public</p>\n        </div>\n        <Button\n          size='sm'\n          variant={joinVariantOf(joinState)}\n          aria-pressed={isJoined}\n          onClick={toggleJoin}\n        >\n          <JoinGlyph state={joinState} />\n          <motion.span layout transition={morph}>\n            {joinLabelOf(joinState)}\n          </motion.span>\n        </Button>\n      </div>\n      <p className='text-muted-foreground text-[13px] leading-5'>\n        Builds the field app that inspectors use offline, from the visit\n        checklist to the photo sync.\n      </p>\n      <div className='flex flex-wrap items-end justify-between gap-x-6 gap-y-3'>\n        <div className='flex items-center gap-2'>\n          <AvatarStack members={members} limit={4} extraCount={extraCount} />\n          <SlidingCount\n            value={memberCount}\n            format={memberCountLabelOf}\n            className='text-muted-foreground text-xs'\n          />\n        </div>\n        <dl className='flex gap-5'>\n          <div className='flex flex-col'>\n            <dt className='text-muted-foreground text-xs'>Open tasks</dt>\n            <dd className='text-[13px] font-medium tabular-nums'>9</dd>\n          </div>\n          <div className='flex flex-col'>\n            <dt className='text-muted-foreground text-xs'>This week</dt>\n            <dd className='text-[13px] font-medium tabular-nums'>27h 45m</dd>\n          </div>\n        </dl>\n      </div>\n    </article>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/teams-01.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/avatar-stack.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport type { Member } from './people';\n\nconst ARRIVE: Transition = { type: 'spring', bounce: 0, duration: 0.32 };\n\nconst LEAVE: Transition = { duration: 0.12, ease: [0.23, 1, 0.32, 1] };\n\nfunction hiddenScaleOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return 1;\n  }\n  return 0.8;\n}\n\nfunction hiddenWidthOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return 'auto';\n  }\n  return 0;\n}\n\ntype AvatarStackProps = {\n  members: Member[];\n  /** How many faces to draw before the rest becomes a +N chip. */\n  limit: number;\n  /** Members beyond the ones listed, counted in the +N chip. */\n  extraCount?: number;\n  className?: string;\n};\n\n/** Opaque faces overlapping from the start; a face added later slides in and makes room. */\nexport function AvatarStack({\n  members,\n  limit,\n  extraCount = 0,\n  className,\n}: AvatarStackProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const hiddenScale = hiddenScaleOf(shouldReduceMotion);\n  const hiddenWidth = hiddenWidthOf(shouldReduceMotion);\n  const shown = members.slice(0, limit);\n  const hiddenMembers = members.length - shown.length;\n  const restCount = hiddenMembers + extraCount;\n  const hasRest = restCount > 0;\n\n  return (\n    <span className={cn('flex items-center ps-1.5', className)}>\n      <AnimatePresence initial={false}>\n        {shown.map((member) => (\n          <motion.span\n            key={member.id}\n            initial={{ width: hiddenWidth, opacity: 0, scale: hiddenScale }}\n            animate={{\n              width: 'auto',\n              opacity: 1,\n              scale: 1,\n              transition: ARRIVE,\n            }}\n            exit={{\n              width: hiddenWidth,\n              opacity: 0,\n              scale: hiddenScale,\n              transition: LEAVE,\n            }}\n            className='-ms-1.5 flex'\n          >\n            <Avatar className='ring-card size-6 ring-2' seed={member.name} />\n          </motion.span>\n        ))}\n      </AnimatePresence>\n      {hasRest && (\n        <span className='bg-muted text-muted-foreground ring-card relative -ms-1.5 inline-flex h-6 min-w-6 items-center justify-center rounded-full px-1 text-[10px] font-medium tabular-nums ring-2'>\n          +{restCount}\n        </span>\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/avatar-stack.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/people.ts",
      "content": "import {\n  CheckIcon,\n  ClockIcon,\n  MinusIcon,\n  MoonIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\n\nexport type Presence = 'tracking' | 'online' | 'away' | 'offline';\n\nexport type Role = 'manager' | 'member' | 'viewer';\n\nexport type Member = {\n  id: string;\n  name: string;\n  email: string;\n  title: string;\n  role: Role;\n  presence: Presence;\n  isYou: boolean;\n};\n\ntype PresenceMeta = { label: string; color: string; glyph: Icon };\n\nexport const PRESENCE_META: Record<Presence, PresenceMeta> = {\n  tracking: {\n    label: 'Tracking time',\n    color: 'var(--primary)',\n    glyph: ClockIcon,\n  },\n  online: { label: 'Online', color: 'var(--success)', glyph: CheckIcon },\n  away: { label: 'Away', color: 'var(--warning)', glyph: MoonIcon },\n  offline: {\n    label: 'Offline',\n    color: 'var(--muted-foreground)',\n    glyph: MinusIcon,\n  },\n};\n\ntype RoleMeta = { label: string; description: string; color: string };\n\nexport const ROLE_META: Record<Role, RoleMeta> = {\n  manager: {\n    label: 'Manager',\n    description: 'Edits the team, its members and their plans',\n    color: 'var(--primary)',\n  },\n  member: {\n    label: 'Member',\n    description: 'Works on tasks and tracks time',\n    color: 'var(--info)',\n  },\n  viewer: {\n    label: 'Viewer',\n    description: 'Sees tasks and reports, changes nothing',\n    color: 'var(--muted-foreground)',\n  },\n};\n\nexport const ROLE_ORDER: Role[] = ['manager', 'member', 'viewer'];\n\nexport function isRole(value: unknown): value is Role {\n  return ROLE_ORDER.some((role) => role === value);\n}\n\nexport const MEMBERS: Member[] = [\n  {\n    id: 'amara',\n    name: 'Amara Okafor',\n    email: 'amara@example.com',\n    title: 'Product designer',\n    role: 'manager',\n    presence: 'tracking',\n    isYou: true,\n  },\n  {\n    id: 'leo',\n    name: 'Léo Martin',\n    email: 'leo@example.com',\n    title: 'Frontend engineer',\n    role: 'member',\n    presence: 'online',\n    isYou: false,\n  },\n  {\n    id: 'sana',\n    name: 'Sana Iqbal',\n    email: 'sana@example.com',\n    title: 'Backend engineer',\n    role: 'member',\n    presence: 'tracking',\n    isYou: false,\n  },\n  {\n    id: 'tomas',\n    name: 'Tomás Rivera',\n    email: 'tomas@example.com',\n    title: 'QA engineer',\n    role: 'member',\n    presence: 'away',\n    isYou: false,\n  },\n  {\n    id: 'mei',\n    name: 'Mei Lin',\n    email: 'mei@example.com',\n    title: 'Content designer',\n    role: 'viewer',\n    presence: 'offline',\n    isYou: false,\n  },\n  {\n    id: 'jonas',\n    name: 'Jonas Weber',\n    email: 'jonas@example.com',\n    title: 'Data analyst',\n    role: 'member',\n    presence: 'online',\n    isYou: false,\n  },\n];\n\nexport function memberById(memberId: string) {\n  const found = MEMBERS.find((member) => member.id === memberId);\n  if (found) {\n    return found;\n  }\n  return MEMBERS[0];\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/people.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"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/teams.ts",
      "content": "export type Team = {\n  id: string;\n  name: string;\n  /** The colour the team picked for its tile. */\n  color: string;\n  memberIds: string[];\n  memberCount: number;\n};\n\nexport const TEAMS: Team[] = [\n  {\n    id: 'atlas',\n    name: 'Atlas Redesign',\n    color: 'var(--info)',\n    memberIds: ['amara', 'leo', 'sana', 'tomas', 'mei', 'jonas'],\n    memberCount: 6,\n  },\n  {\n    id: 'field',\n    name: 'Field App',\n    color: 'var(--success)',\n    memberIds: ['leo', 'sana', 'jonas'],\n    memberCount: 5,\n  },\n  {\n    id: 'growth',\n    name: 'Growth',\n    color: 'var(--warning)',\n    memberIds: ['mei', 'amara'],\n    memberCount: 4,\n  },\n  {\n    id: 'platform',\n    name: 'Platform',\n    color: 'var(--primary)',\n    memberIds: ['sana', 'tomas', 'jonas'],\n    memberCount: 7,\n  },\n  {\n    id: 'research',\n    name: 'Research',\n    color: 'var(--muted-foreground)',\n    memberIds: ['mei'],\n    memberCount: 1,\n  },\n];\n\nexport function memberCountLabelOf(count: number) {\n  if (count === 1) {\n    return '1 member';\n  }\n  return `${count} members`;\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/teams.ts"
    }
  ],
  "categories": [
    "components",
    "teams"
  ],
  "type": "registry:component"
}