{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "teams-08",
  "title": "Workload per member",
  "description": "Planned hours against capacity for each member, this week or next, with the people over capacity in warning.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle-group.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-08.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport { memberById, type Member } from './_parts/people';\nimport { Segments, type Segment } from './_parts/segments';\nimport { SlidingCount } from './_parts/sliding-count';\n\ntype Week = 'this' | 'next';\n\ntype Load = {\n  memberId: string;\n  capacityHours: number;\n  plannedHours: Record<Week, number>;\n};\n\nconst WEEK_SEGMENTS: Segment<Week>[] = [\n  { value: 'this', label: 'This week' },\n  { value: 'next', label: 'Next week' },\n];\n\nconst LOADS: Load[] = [\n  {\n    memberId: 'amara',\n    capacityHours: 40,\n    plannedHours: { this: 34, next: 30 },\n  },\n  { memberId: 'leo', capacityHours: 40, plannedHours: { this: 38, next: 42 } },\n  { memberId: 'sana', capacityHours: 40, plannedHours: { this: 44, next: 36 } },\n  {\n    memberId: 'tomas',\n    capacityHours: 32,\n    plannedHours: { this: 22, next: 28 },\n  },\n  { memberId: 'mei', capacityHours: 20, plannedHours: { this: 12, next: 18 } },\n];\n\nfunction hoursOf(hours: number) {\n  return `${hours}h`;\n}\n\nfunction shareOf(planned: number, capacity: number) {\n  const share = planned / capacity;\n  return Math.min(1, share);\n}\n\nfunction isOverOf(planned: number, capacity: number) {\n  return planned > capacity;\n}\n\nfunction totalOf(values: number[]) {\n  let total = 0;\n  for (const value of values) {\n    total += value;\n  }\n  return total;\n}\n\nfunction loadLabelOf(member: Member, planned: number, capacity: number) {\n  const isOver = isOverOf(planned, capacity);\n  if (isOver) {\n    return `${member.name}: ${planned} of ${capacity} hours planned, over capacity`;\n  }\n  return `${member.name}: ${planned} of ${capacity} hours planned`;\n}\n\nfunction LoadRow({ load, week }: { load: Load; week: Week }) {\n  const member = memberById(load.memberId);\n  const planned = load.plannedHours[week];\n  const share = shareOf(planned, load.capacityHours);\n  const isOver = isOverOf(planned, load.capacityHours);\n  const fillStyle = { transform: `scaleX(${share})` };\n  const label = loadLabelOf(member, planned, load.capacityHours);\n\n  return (\n    <li className='grid grid-cols-[minmax(0,9rem)_minmax(0,1fr)_4.5rem] items-center gap-3 py-2'>\n      <span className='flex min-w-0 items-center gap-2.5'>\n        <Avatar className='size-7' seed={member.name} />\n        <span className='min-w-0'>\n          <span className='block truncate text-[13px] leading-5 font-medium'>\n            {member.name}\n          </span>\n          <span className='text-muted-foreground block truncate text-xs'>\n            {member.title}\n          </span>\n        </span>\n      </span>\n      <span\n        role='img'\n        aria-label={label}\n        className='bg-foreground/[0.06] block h-1.5 overflow-hidden rounded-full'\n      >\n        <span\n          style={fillStyle}\n          className={cn(\n            'block h-full origin-left rounded-full transition-[transform,background-color] duration-300 ease-(--ease-out-strong)',\n            isOver && 'bg-warning',\n            !isOver && 'bg-primary'\n          )}\n        />\n      </span>\n      <span\n        aria-hidden='true'\n        className='flex justify-end text-[13px] tabular-nums'\n      >\n        <SlidingCount\n          value={planned}\n          format={hoursOf}\n          className={cn(\n            'font-medium transition-colors duration-300',\n            isOver && 'text-warning-foreground'\n          )}\n        />\n        <span className='text-muted-foreground'>\n          &nbsp;/ {load.capacityHours}h\n        </span>\n      </span>\n    </li>\n  );\n}\n\nexport default function Teams08() {\n  const titleId = useId();\n  const [week, setWeek] = useState<Week>('this');\n  const planned = LOADS.map((load) => load.plannedHours[week]);\n  const capacities = LOADS.map((load) => load.capacityHours);\n  const totalPlanned = totalOf(planned);\n  const totalCapacity = totalOf(capacities);\n\n  return (\n    <section\n      aria-labelledby={titleId}\n      className='bg-card hairline-ring ring-border w-full max-w-[34rem] rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <header className='flex flex-wrap items-start justify-between gap-3'>\n        <div>\n          <h3 id={titleId} className='text-sm font-medium'>\n            Workload\n          </h3>\n          <p className='text-muted-foreground text-xs'>\n            Planned hours against each capacity · Illustrative\n          </p>\n        </div>\n        <Segments\n          value={week}\n          segments={WEEK_SEGMENTS}\n          onValueChange={setWeek}\n          label='Week'\n        />\n      </header>\n      <ul aria-label='Members' className='mt-3'>\n        {LOADS.map((load) => (\n          <LoadRow key={load.memberId} load={load} week={week} />\n        ))}\n      </ul>\n      <p className='text-muted-foreground mt-2 flex items-center justify-end gap-1 text-xs'>\n        Team\n        <SlidingCount\n          value={totalPlanned}\n          format={hoursOf}\n          className='text-foreground font-medium'\n        />\n        planned of {totalCapacity}h\n      </p>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/teams-08.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/segments.tsx",
      "content": "'use client';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nexport type Segment<Value extends string> = {\n  value: Value;\n  label: string;\n};\n\nconst THUMB =\n  'bg-card shadow-[0_1px_2px_rgb(0_0_0/0.08)] hairline-ring ring-foreground/10 dark:bg-foreground/[0.09] dark:ring-foreground/15';\n\ntype SegmentsProps<Value extends string> = {\n  value: Value;\n  segments: Segment<Value>[];\n  onValueChange: (value: Value) => void;\n  label: string;\n  className?: string;\n};\n\n/** One choice on a grey track: the raised thumb travels to the segment picked. */\nexport function Segments<Value extends string>({\n  value,\n  segments,\n  onValueChange,\n  label,\n  className,\n}: SegmentsProps<Value>) {\n  const pressedValues = [value];\n\n  function changeValue(nextValues: unknown[]) {\n    const [nextValue] = nextValues;\n    const segment = segments.find((candidate) => candidate.value === nextValue);\n    if (segment) {\n      onValueChange(segment.value);\n    }\n  }\n\n  return (\n    <ToggleGroup\n      aria-label={label}\n      value={pressedValues}\n      onValueChange={changeValue}\n      travel\n      size='sm'\n      indicatorClassName={THUMB}\n      className={cn('bg-foreground/[0.05] rounded-lg p-0.5', className)}\n    >\n      {segments.map((segment) => (\n        <ToggleGroupItem\n          key={segment.value}\n          value={segment.value}\n          className='h-6 flex-1 rounded-md px-2.5 text-xs'\n        >\n          {segment.label}\n        </ToggleGroupItem>\n      ))}\n    </ToggleGroup>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/segments.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"
    }
  ],
  "categories": [
    "components",
    "teams"
  ],
  "type": "registry:component"
}