{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "teams-07",
  "title": "Member card that flips",
  "description": "A member card whose Details button turns it over to the email, local time, teams and hours of the week.",
  "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-07.tsx",
      "content": "'use client';\n\nimport { motion, type Transition } from 'motion/react';\nimport { useEffect, useRef, useState, type Ref } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  ArrowLeftIcon,\n  CheckIcon,\n  CopyIcon,\n  InfoIcon,\n  MailIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport { memberById, PRESENCE_META, ROLE_META } from './_parts/people';\nimport { PresenceAvatar } from './_parts/presence-avatar';\nimport { Swap } from './_parts/swap';\nimport { TeamTile } from './_parts/team-tile';\nimport { TEAMS } from './_parts/teams';\n\nconst MEMBER = memberById('leo');\n\nconst MEMBER_TEAMS = TEAMS.filter((team) => team.memberIds.includes(MEMBER.id));\n\nconst WEEK_MINUTES = 1885;\nconst WEEK_TARGET_MINUTES = 2400;\nconst COPIED_RESET_MS = 1600;\n\nconst FLIP: Transition = { type: 'spring', bounce: 0, duration: 0.5 };\nconst FADE: Transition = { duration: 0.15, ease: [0.23, 1, 0.32, 1] };\n\nconst FACE =\n  'bg-card hairline-ring ring-border absolute inset-0 flex flex-col rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)] [backface-visibility:hidden]';\n\nfunction formatMinutes(minutes: number) {\n  const hours = Math.floor(minutes / 60);\n  const rest = minutes % 60;\n  const restText = String(rest);\n  const paddedRest = restText.padStart(2, '0');\n  return `${hours}h ${paddedRest}m`;\n}\n\nfunction weekShareOf(minutes: number, target: number) {\n  const share = minutes / target;\n  return Math.min(1, share);\n}\n\nfunction inertOf(isHidden: boolean) {\n  if (isHidden) {\n    return true;\n  }\n  return undefined;\n}\n\nfunction copyLabelOf(isCopied: boolean) {\n  if (isCopied) {\n    return 'Email copied';\n  }\n  return 'Copy email';\n}\n\ntype FaceMotion = {\n  front: { rotateY: number; opacity: number };\n  back: { rotateY: number; opacity: number };\n  transition: Transition;\n};\n\nfunction faceMotionOf(isFlipped: boolean, shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return reducedFacesOf(isFlipped);\n  }\n  return flippedFacesOf(isFlipped);\n}\n\nfunction flippedFacesOf(isFlipped: boolean): FaceMotion {\n  if (isFlipped) {\n    return {\n      front: { rotateY: -180, opacity: 1 },\n      back: { rotateY: 0, opacity: 1 },\n      transition: FLIP,\n    };\n  }\n  return {\n    front: { rotateY: 0, opacity: 1 },\n    back: { rotateY: 180, opacity: 1 },\n    transition: FLIP,\n  };\n}\n\nfunction reducedFacesOf(isFlipped: boolean): FaceMotion {\n  if (isFlipped) {\n    return {\n      front: { rotateY: 0, opacity: 0 },\n      back: { rotateY: 0, opacity: 1 },\n      transition: FADE,\n    };\n  }\n  return {\n    front: { rotateY: 0, opacity: 1 },\n    back: { rotateY: 0, opacity: 0 },\n    transition: FADE,\n  };\n}\n\ntype FaceProps = {\n  onFlip: () => void;\n  flipButtonRef: Ref<HTMLButtonElement>;\n};\n\nfunction FrontFace({ onFlip, flipButtonRef }: FaceProps) {\n  const role = ROLE_META[MEMBER.role];\n  const roleStyle = { '--chip': role.color } as React.CSSProperties;\n\n  return (\n    <>\n      <div className='flex flex-1 flex-col items-center justify-center gap-2 text-center'>\n        <PresenceAvatar member={MEMBER} size='lg' />\n        <div>\n          <p className='text-sm font-medium'>{MEMBER.name}</p>\n          <p className='text-muted-foreground text-xs'>{MEMBER.title}</p>\n        </div>\n        <span\n          style={roleStyle}\n          className='chip-3d inline-flex h-5 items-center rounded-md px-1.5 text-xs font-medium'\n        >\n          {role.label}\n        </span>\n      </div>\n      <div className='flex gap-2'>\n        <Button\n          size='sm'\n          variant='outline'\n          className='flex-1'\n          render={<a href={`mailto:${MEMBER.email}`} />}\n          nativeButton={false}\n        >\n          <MailIcon />\n          Message\n        </Button>\n        <Button\n          ref={flipButtonRef}\n          size='sm'\n          variant='outline'\n          className='flex-1'\n          onClick={onFlip}\n        >\n          <InfoIcon />\n          Details\n        </Button>\n      </div>\n    </>\n  );\n}\n\nfunction BackFace({ onFlip, flipButtonRef }: FaceProps) {\n  const [isCopied, setIsCopied] = useState(false);\n  const share = weekShareOf(WEEK_MINUTES, WEEK_TARGET_MINUTES);\n  const barStyle = { transform: `scaleX(${share})` };\n  const presence = PRESENCE_META[MEMBER.presence];\n\n  function copyEmail() {\n    setIsCopied(true);\n    window.setTimeout(() => setIsCopied(false), COPIED_RESET_MS);\n  }\n\n  return (\n    <>\n      <div className='flex items-center gap-2'>\n        <Button\n          ref={flipButtonRef}\n          variant='ghost'\n          size='icon-sm'\n          aria-label='Back to the card'\n          onClick={onFlip}\n          className='text-muted-foreground -ms-1.5'\n        >\n          <ArrowLeftIcon />\n        </Button>\n        <p className='text-[13px] font-medium'>{MEMBER.name}</p>\n        <p className='text-muted-foreground ms-auto text-xs'>\n          {presence.label}\n        </p>\n      </div>\n      <dl className='mt-3 flex flex-1 flex-col gap-3 text-[13px]'>\n        <div className='flex items-center justify-between gap-2'>\n          <dt className='text-muted-foreground text-xs'>Email</dt>\n          <dd className='flex min-w-0 items-center gap-1'>\n            <span className='truncate'>{MEMBER.email}</span>\n            <Button\n              variant='ghost'\n              size='icon-sm'\n              aria-label={copyLabelOf(isCopied)}\n              onClick={copyEmail}\n              className='text-muted-foreground size-6'\n            >\n              <Swap swapKey={String(isCopied)}>\n                {isCopied && (\n                  <CheckIcon className='text-success-foreground size-3.5' />\n                )}\n                {!isCopied && <CopyIcon className='size-3.5' />}\n              </Swap>\n            </Button>\n          </dd>\n        </div>\n        <div className='flex items-center justify-between gap-2'>\n          <dt className='text-muted-foreground text-xs'>Local time</dt>\n          <dd className='tabular-nums'>14:32 in Lisbon</dd>\n        </div>\n        <div className='flex items-center justify-between gap-2'>\n          <dt className='text-muted-foreground text-xs'>Teams</dt>\n          <dd className='flex items-center gap-1'>\n            {MEMBER_TEAMS.map((team) => (\n              <span key={team.id} title={team.name} className='flex'>\n                <TeamTile name={team.name} color={team.color} size='sm' />\n                <span className='sr-only'>{team.name}</span>\n              </span>\n            ))}\n          </dd>\n        </div>\n        <div className='flex flex-col gap-1.5'>\n          <div className='flex items-center justify-between gap-2'>\n            <dt className='text-muted-foreground text-xs'>This week</dt>\n            <dd className='tabular-nums'>\n              {formatMinutes(WEEK_MINUTES)}{' '}\n              <span className='text-muted-foreground'>of 40h</span>\n            </dd>\n          </div>\n          <div\n            aria-hidden='true'\n            className='bg-foreground/[0.06] h-1.5 overflow-hidden rounded-full'\n          >\n            <div\n              style={barStyle}\n              className='bg-primary h-full origin-left rounded-full'\n            />\n          </div>\n        </div>\n      </dl>\n    </>\n  );\n}\n\nexport default function Teams07() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [isFlipped, setIsFlipped] = useState(false);\n  const frontButtonRef = useRef<HTMLButtonElement>(null);\n  const backButtonRef = useRef<HTMLButtonElement>(null);\n  const wasFlippedByPerson = useRef(false);\n  const faces = faceMotionOf(isFlipped, shouldReduceMotion);\n\n  useEffect(() => {\n    if (!wasFlippedByPerson.current) {\n      return;\n    }\n    if (isFlipped) {\n      backButtonRef.current?.focus();\n      return;\n    }\n    frontButtonRef.current?.focus();\n  }, [isFlipped]);\n\n  function flip() {\n    wasFlippedByPerson.current = true;\n    setIsFlipped((current) => !current);\n  }\n\n  return (\n    <div className='relative h-[17rem] w-full max-w-[18rem] [perspective:1000px]'>\n      <motion.div\n        initial={false}\n        animate={faces.front}\n        transition={faces.transition}\n        inert={inertOf(isFlipped)}\n        className={FACE}\n      >\n        <FrontFace onFlip={flip} flipButtonRef={frontButtonRef} />\n      </motion.div>\n      <motion.div\n        initial={false}\n        animate={faces.back}\n        transition={faces.transition}\n        inert={inertOf(!isFlipped)}\n        className={FACE}\n      >\n        <BackFace onFlip={flip} flipButtonRef={backButtonRef} />\n      </motion.div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/teams-07.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/presence-avatar.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport { PRESENCE_META, type Member } from './people';\n\nconst SIZE_CLASS = {\n  sm: { avatar: 'size-7', badge: 'size-3.5', glyph: 'size-2' },\n  md: { avatar: 'size-9', badge: 'size-4', glyph: 'size-2.5' },\n  lg: { avatar: 'size-12', badge: 'size-5', glyph: 'size-3' },\n} as const;\n\ntype PresenceAvatarProps = {\n  member: Member;\n  size?: keyof typeof SIZE_CLASS;\n  /** The colour behind the badge's cut-out: the surface the avatar sits on. */\n  surfaceClassName?: string;\n  className?: string;\n};\n\n/** A person's face with their presence as a small glyph on its corner, read out after the name. */\nexport function PresenceAvatar({\n  member,\n  size = 'md',\n  surfaceClassName = 'bg-card',\n  className,\n}: PresenceAvatarProps) {\n  const presence = PRESENCE_META[member.presence];\n  const Glyph = presence.glyph;\n  const badgeStyle = { '--chip': presence.color } as React.CSSProperties;\n  const sizes = SIZE_CLASS[size];\n\n  return (\n    <span className={cn('relative inline-flex shrink-0', className)}>\n      <Avatar className={sizes.avatar} seed={member.name} />\n      <span\n        aria-hidden='true'\n        className={cn(\n          'absolute -end-0.5 -bottom-0.5 flex rounded-full p-px',\n          surfaceClassName\n        )}\n      >\n        <span\n          style={badgeStyle}\n          className={cn(\n            'chip-3d flex items-center justify-center rounded-full',\n            sizes.badge\n          )}\n        >\n          <Glyph className={sizes.glyph} strokeWidth={2.75} />\n        </span>\n      </span>\n      <span className='sr-only'>{presence.label}</span>\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/presence-avatar.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"
}