{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "teams-02",
  "title": "Team switcher",
  "description": "A pill with the current team that opens every team with its tile and member count, the picked one marked.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/dropdown-menu.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-02.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport {\n  ChevronsUpDownIcon,\n  PlusIcon,\n  SettingsIcon,\n  UsersIcon,\n} from '@/registry/ndeko/lib/icons';\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuGroupLabel,\n  DropdownMenuItem,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuSeparator,\n  DropdownMenuTrigger,\n} from '@/registry/ndeko/ui/dropdown-menu';\n\nimport { MorphLabel } from './_parts/morph-label';\nimport { SlidingCount } from './_parts/sliding-count';\nimport { Swap } from './_parts/swap';\nimport { TeamTile } from './_parts/team-tile';\nimport { TEAMS, memberCountLabelOf, type Team } from './_parts/teams';\n\nconst TRIGGER =\n  'inline-flex h-8 max-w-full cursor-pointer items-center gap-2 rounded-full bg-card ps-1 pe-2.5 text-[13px] font-medium outline-none hairline-ring ring-foreground/12 shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-colors duration-150 hover:bg-foreground/[0.03] focus-visible:ring-[3px] focus-visible:ring-ring/25 data-popup-open:bg-foreground/[0.04] dark:bg-foreground/[0.04]';\n\nfunction countOf(count: number) {\n  return String(count);\n}\n\nfunction isTeamId(value: unknown): value is string {\n  return TEAMS.some((team) => team.id === value);\n}\n\nfunction triggerLabelOf(team: Team) {\n  const members = memberCountLabelOf(team.memberCount);\n  return `Team: ${team.name}, ${members}. Switch team`;\n}\n\nfunction teamById(teamId: string) {\n  const found = TEAMS.find((team) => team.id === teamId);\n  if (found) {\n    return found;\n  }\n  return TEAMS[0];\n}\n\nfunction TeamRow({ team }: { team: Team }) {\n  return (\n    <>\n      <TeamTile name={team.name} color={team.color} />\n      <span className='min-w-0 flex-1 truncate'>{team.name}</span>\n      <span className='text-muted-foreground text-xs tabular-nums'>\n        {team.memberCount}\n        <span className='sr-only'> members</span>\n      </span>\n    </>\n  );\n}\n\nexport default function Teams02() {\n  const [currentId, setCurrentId] = useState(TEAMS[0].id);\n  const current = teamById(currentId);\n  const triggerLabel = triggerLabelOf(current);\n\n  function switchTeam(value: unknown) {\n    if (isTeamId(value)) {\n      setCurrentId(value);\n    }\n  }\n\n  return (\n    <DropdownMenu>\n      <DropdownMenuTrigger aria-label={triggerLabel} className={TRIGGER}>\n        <Swap swapKey={current.id}>\n          <TeamTile name={current.name} color={current.color} />\n        </Swap>\n        <MorphLabel value={current.id}>{current.name}</MorphLabel>\n        <SlidingCount\n          value={current.memberCount}\n          format={countOf}\n          className='text-muted-foreground text-xs font-normal'\n        />\n        <ChevronsUpDownIcon className='text-muted-foreground size-3.5 shrink-0' />\n      </DropdownMenuTrigger>\n      <DropdownMenuContent className='w-72'>\n        <DropdownMenuGroup>\n          <DropdownMenuGroupLabel>Teams</DropdownMenuGroupLabel>\n          <DropdownMenuRadioGroup value={currentId} onValueChange={switchTeam}>\n            {TEAMS.map((team) => (\n              <DropdownMenuRadioItem\n                key={team.id}\n                value={team.id}\n                closeOnClick\n                className='h-9'\n              >\n                <TeamRow team={team} />\n              </DropdownMenuRadioItem>\n            ))}\n          </DropdownMenuRadioGroup>\n        </DropdownMenuGroup>\n        <DropdownMenuSeparator />\n        <DropdownMenuItem>\n          <SettingsIcon />\n          Settings of {current.name}\n        </DropdownMenuItem>\n        <DropdownMenuItem>\n          <UsersIcon />\n          All teams\n        </DropdownMenuItem>\n        <DropdownMenuItem>\n          <PlusIcon />\n          Create team\n        </DropdownMenuItem>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/teams-02.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/morph-label.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';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\n\nconst ARRIVE: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst LEAVE: Transition = { duration: 0.1, ease: [0.2, 0, 0, 1] };\n\nconst BLUR_VARIANTS: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)', transition: ARRIVE },\n  exit: { opacity: 0, filter: 'blur(2px)', transition: LEAVE },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1, transition: ARRIVE },\n  exit: { opacity: 0, transition: LEAVE },\n};\n\nfunction variantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return BLUR_VARIANTS;\n}\n\ntype MorphLabelProps = {\n  /** Changes when the label becomes another one. */\n  value: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/** A label that becomes another: the text crossfades through a light blur while its width follows. */\nexport function MorphLabel({ value, className, children }: MorphLabelProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  return (\n    <AnimatedSize as='span' axis='width' contentClassName='relative flex'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={value}\n          variants={variantsOf(shouldReduceMotion)}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          className={cn('flex whitespace-nowrap', className)}\n        >\n          {children}\n        </motion.span>\n      </AnimatePresence>\n    </AnimatedSize>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/morph-label.tsx"
    },
    {
      "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"
}