{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "team",
  "title": "Team",
  "description": "Primitives for people: avatars with initials and a colour picked from the name, presence as a dot on the avatar and a coloured word, an avatar stack with a \"+N\" overflow, and a workload bar of what someone has against what they can take.",
  "registryDependencies": [
    "avatar",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/team.tsx",
      "content": "'use client'\n\nimport {\n  StatusLabel,\n  type StatusLabelProps,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport type { ComponentProps } from 'react'\n\nimport {\n  Avatar,\n  AvatarBadge,\n  AvatarFallback,\n  AvatarGroup,\n  AvatarGroupCount,\n  AvatarImage,\n} from '@/components/ui/avatar'\n\nimport { cn } from '@/lib/utils'\n\ntype Presence = 'online' | 'away' | 'offline'\n\ninterface Person {\n  avatar?: string\n  id: string\n  name: string\n  presence?: Presence\n}\n\ninterface PresenceConfig {\n  dot: string\n  label: string\n  tone: StatusTone\n}\n\nconst presenceConfig: Record<Presence, PresenceConfig> = {\n  away: { dot: 'bg-orange-500', label: 'Away', tone: 'warning' },\n  offline: {\n    dot: 'border-muted-foreground bg-background border-2',\n    label: 'Offline',\n    tone: 'neutral',\n  },\n  online: {\n    dot: 'bg-emerald-600 dark:bg-emerald-500',\n    label: 'Online',\n    tone: 'good',\n  },\n}\n\nconst presenceOrder: Presence[] = ['online', 'away', 'offline']\n\nconst avatarColors = [\n  'bg-[color-mix(in_oklab,var(--color-chart-2)_25%,var(--color-card))] text-foreground',\n  'bg-[color-mix(in_oklab,var(--color-chart-3)_25%,var(--color-card))] text-foreground',\n  'bg-[color-mix(in_oklab,var(--color-chart-4)_25%,var(--color-card))] text-foreground',\n  'bg-[color-mix(in_oklab,var(--color-chart-5)_25%,var(--color-card))] text-foreground',\n  'bg-[color-mix(in_oklab,var(--color-chart-1)_25%,var(--color-card))] text-foreground',\n]\n\nfunction fnv1a(text: string) {\n  let hash = 2_166_136_261\n  for (const char of text) hash = Math.imul(hash ^ char.charCodeAt(0), 16_777_619) >>> 0\n  return hash\n}\n\nfunction getAvatarColor(name: string) {\n  return avatarColors[fnv1a(name) % avatarColors.length]\n}\n\nfunction getInitials(name: string) {\n  const parts = name.trim().split(/\\s+/).filter(Boolean)\n  if (parts.length === 0) return '?'\n  const first = parts[0][0]\n  const last = parts.length > 1 ? parts[parts.length - 1][0] : ''\n  return `${first}${last}`.toUpperCase()\n}\n\ntype AvatarSize = 'sm' | 'default' | 'lg'\n\nconst initialsSize: Record<AvatarSize, string> = {\n  default: 'text-xs',\n  lg: 'text-sm',\n  sm: 'text-xs',\n}\n\ninterface PersonAvatarProps extends Omit<ComponentProps<typeof Avatar>, 'size'> {\n  person: Pick<Person, 'avatar' | 'name' | 'presence'>\n  showPresence?: boolean\n  /** @default 'default' */\n  size?: AvatarSize\n}\n\n/** Decorative: always show the person's name beside it, or in `sr-only` text. */\nfunction PersonAvatar({\n  children,\n  className,\n  person,\n  showPresence = false,\n  size = 'default',\n  ...props\n}: PersonAvatarProps) {\n  return (\n    <Avatar aria-hidden size={size} className={className} {...props}>\n      {person.avatar && <AvatarImage src={person.avatar} alt='' />}\n      <AvatarFallback\n        // Not the primitive's colour: each person's initials take their own chart tint\n        className={cn('font-medium', initialsSize[size], getAvatarColor(person.name))}\n      >\n        {getInitials(person.name)}\n      </AvatarFallback>\n      {showPresence && person.presence && (\n        <AvatarBadge\n          // Not the primitive's colour: the presence dot is the block's own, coloured for status, and its ring cuts it out of the page behind it\n          className={cn('ring-background', presenceConfig[person.presence].dot)}\n        />\n      )}\n      {children}\n    </Avatar>\n  )\n}\n\ninterface PresenceLabelProps extends Omit<StatusLabelProps, 'tone'> {\n  presence: Presence\n}\n\nfunction PresenceLabel({ children, presence, ...props }: PresenceLabelProps) {\n  const config = presenceConfig[presence]\n  return (\n    <StatusLabel tone={config.tone} {...props}>\n      {children ?? config.label}\n    </StatusLabel>\n  )\n}\n\ninterface AvatarStackProps {\n  className?: string\n  label: string\n  /** Avatars shown before \"+N\", 4 by default. */\n  max?: number\n  people: Pick<Person, 'avatar' | 'id' | 'name'>[]\n  /** @default 'default' */\n  size?: AvatarSize\n}\n\nfunction AvatarStack({\n  className,\n  label,\n  max = 4,\n  people,\n  size = 'default',\n}: AvatarStackProps) {\n  const shown = people.slice(0, max)\n  const hidden = people.length - shown.length\n\n  return (\n    <AvatarGroup\n      role='list'\n      aria-label={label}\n      className={cn(size === 'sm' && '-space-x-1', className)}\n    >\n      {shown.map((person) => (\n        <PersonAvatar\n          key={person.id}\n          role='listitem'\n          title={person.name}\n          person={person}\n          size={size}\n        >\n          <span className='sr-only'>{person.name}</span>\n        </PersonAvatar>\n      ))}\n      {hidden > 0 && (\n        <AvatarGroupCount role='listitem' className='tabular-nums'>\n          <span aria-hidden>+{hidden}</span>\n          <span className='sr-only'>and {hidden} more</span>\n        </AvatarGroupCount>\n      )}\n    </AvatarGroup>\n  )\n}\n\nconst workloadFill = 'var(--color-chart-2)'\nconst workloadOpenFill = 'color-mix(in oklab, var(--color-chart-2) 35%, transparent)'\nconst workloadOverFill =\n  'repeating-linear-gradient(135deg, var(--color-orange-500) 0 3px, color-mix(in oklab, var(--color-orange-500) 45%, var(--color-background)) 3px 6px)'\n\ninterface WorkloadBarPart {\n  /** Finished work: it keeps its fill past `capacity`, where only open work is hatched. */\n  done?: boolean\n  /** A colour, such as `workloadFill` or a lighter mix of it. */\n  fill: string\n  value: number\n}\n\ninterface WorkloadBarProps {\n  /** What the person has, in the bar's unit. */\n  assigned: number\n  /** What they can take, drawn as a tick. What's past it is hatched in orange. */\n  capacity?: number\n  className?: string\n  /** Of `assigned`, what's finished: drawn solid, and the rest lighter. Leave out to draw all of `assigned` solid. */\n  done?: number\n  /** A tick that marks a point on the bar without hatching past it, such as where a pace lands. */\n  mark?: number\n  /** The value the full width stands for, so bars one above another share a scale. */\n  max: number\n  /** `assigned` split into parts, drawn in order in place of `done` and the rest, such as done, in review and in progress. */\n  parts?: WorkloadBarPart[]\n  /** Grows the bar in from zero once true, as `useReveal` gives. */\n  revealed: boolean\n}\n\n/** Cuts the open parts at `limit`, and gives the open work past it as one more amount. */\nfunction splitAt(parts: WorkloadBarPart[], limit: number) {\n  const within: WorkloadBarPart[] = []\n  let used = 0\n  let over = 0\n  for (const part of parts) {\n    const value = part.done ? part.value : Math.max(0, Math.min(part.value, limit - used))\n    if (value > 0) within.push({ fill: part.fill, value })\n    over += part.value - value\n    used += part.value\n  }\n  return { over, within }\n}\n\nfunction WorkloadTick({ at }: { at: string }) {\n  return (\n    <span\n      className='bg-foreground ring-background absolute top-1/2 h-[calc(100%+8px)] w-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2'\n      style={{ left: at }}\n    />\n  )\n}\n\n/** One person's load: what they have against what they can take. Decorative: write the numbers beside it. */\nfunction WorkloadBar({\n  assigned,\n  capacity,\n  className,\n  done,\n  mark,\n  max,\n  parts,\n  revealed,\n}: WorkloadBarProps) {\n  const solid = done === undefined ? assigned : Math.min(done, assigned)\n  const { over, within } = splitAt(\n    parts ?? [\n      { done: done !== undefined, fill: workloadFill, value: solid },\n      { fill: workloadOpenFill, value: assigned - solid },\n    ],\n    capacity ?? assigned,\n  )\n  const toPercent = (value: number) =>\n    `${max > 0 ? Math.min(100, (value / max) * 100) : 0}%`\n  return (\n    <div\n      aria-hidden\n      data-slot='workload-bar'\n      className={cn('relative h-2 w-full', className)}\n    >\n      <div className='bg-muted flex h-full w-full overflow-hidden rounded-full'>\n        <div\n          data-slot='workload-bar-parts'\n          className='flex h-full origin-left transition-transform duration-700 ease-out motion-reduce:transition-none'\n          style={{\n            transform: revealed ? 'scaleX(1)' : 'scaleX(0)',\n            width: toPercent(assigned),\n          }}\n        >\n          {within.map((part, index) => (\n            <div\n              key={index}\n              className='h-full'\n              style={{ backgroundColor: part.fill, flexGrow: part.value }}\n            />\n          ))}\n          {over > 0 && (\n            <div\n              className='h-full'\n              style={{ backgroundImage: workloadOverFill, flexGrow: over }}\n            />\n          )}\n        </div>\n      </div>\n      {capacity !== undefined && <WorkloadTick at={toPercent(capacity)} />}\n      {mark !== undefined && <WorkloadTick at={toPercent(mark)} />}\n    </div>\n  )\n}\n\ninterface WorkloadLegendItem {\n  /** The part's fill on the bar, shown as a swatch. */\n  fill: string\n  key: string\n  /** What follows the amount, such as `pts done`. */\n  label: string\n  value: number\n}\n\n/** The key under a `WorkloadBar`: each part's swatch, amount and what it is. */\nfunction WorkloadLegend({\n  className,\n  items,\n}: {\n  className?: string\n  items: WorkloadLegendItem[]\n}) {\n  return (\n    <ul\n      data-slot='workload-legend'\n      className={cn(\n        'text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1 text-xs',\n        className,\n      )}\n    >\n      {items.map((item) => (\n        <li key={item.key} className='flex items-center gap-1.5'>\n          <span aria-hidden className='bg-muted size-2 overflow-hidden rounded-full'>\n            <span className='block size-full' style={{ backgroundColor: item.fill }} />\n          </span>\n          <span>\n            <span className='text-foreground font-medium tabular-nums'>\n              {formatNumber(item.value)}\n            </span>{' '}\n            {item.label}\n          </span>\n        </li>\n      ))}\n    </ul>\n  )\n}\n\nexport {\n  AvatarStack,\n  PersonAvatar,\n  PresenceLabel,\n  getAvatarColor,\n  getInitials,\n  presenceConfig,\n  presenceOrder,\n  WorkloadBar,\n  WorkloadLegend,\n  workloadFill,\n  workloadOpenFill,\n  workloadOverFill,\n}\n\nexport type {\n  AvatarSize,\n  AvatarStackProps,\n  Person,\n  PersonAvatarProps,\n  Presence,\n  PresenceConfig,\n  PresenceLabelProps,\n  WorkloadBarPart,\n  WorkloadLegendItem,\n  WorkloadBarProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/team.tsx"
    }
  ],
  "type": "registry:component"
}
