{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "groups",
  "type": "registry:ui",
  "title": "Groups",
  "description": "Pairs, small groups and teams. `GroupCard` is what one person's phone shows: which group they are in, who they are with, what to talk about and for how long. `GroupGrid` is the shared screen: every group with its people, where a reshuffle glides each name…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "games",
    "game"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/flip-group.json",
    "https://ds.interlace.tools/r/motion-token.json",
    "https://ds.interlace.tools/r/timer-ring.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/games/groups.tsx",
      "target": "components/ui/games/groups.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/groups v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/groups\n// What changed since: https://ds.interlace.tools/c/groups#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — GroupCard and GroupGrid\n *\n * Pairs, small groups and teams. `GroupCard` is what one person's phone\n * shows: which group they are in, who they are with, what to talk about and\n * for how long. `GroupGrid` is the shared screen: every group with its\n * people, where a reshuffle glides each name to its new group, so the room\n * can follow who moved.\n *\n * Build the groups with `games/groups-model` (`makeGroups`, `joinGroups`,\n * `leaveGroups`); for team standings, pass `teamTotals` to `Leaderboard`.\n *\n * ## Anatomy\n *\n *   GroupCard                    (section — data-slot=\"group-card\", data-state=grouped|waiting)\n *     ├─ p                       (data-slot=\"group-card-label\": \"Team 2\", \"Your pair\")\n *     ├─ ul                      (data-slot=\"group-card-members\": the others, as chips)\n *     ├─ p                       (data-slot=\"group-card-prompt\")\n *     ├─ TimerRing (deadline)    (data-slot=\"timer-ring\")\n *     └─ span sr-only aria-live  (data-slot=\"group-card-announce\": \"You're with Dana and Sam.\")\n *   GroupGrid                    (div @container — data-slot=\"group-grid\")\n *     └─ ul (FlipGroup) > li × n                  (data-slot=\"group-grid-group\", aria-current on the viewer's group)\n *          └─ ul > li × m        (data-flip-id per person: names glide between groups)\n *\n * ## Motion\n *\n * A changed group on the phone rises in (200ms; the first one is simply there) and its names follow within\n * 150ms in total. On the screen, a reshuffle glides each name from its old\n * group to its new one (FlipGroup, 400ms). Under reduced motion everything\n * is simply in place.\n *\n * ## MIN_VIEWPORT — 320\n *\n * | Rule | Concept                   | Where in this file                              |\n * | ---- | ------------------------- | ----------------------------------------------- |\n * | R4   | Extends native el         | `section` / `div` props                         |\n * | R6   | data-slot per part        | group-card / -label / -members / -prompt / -announce; group-grid / -group |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`               |\n * | R8   | Enums, not booleans       | `size`                                          |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const            |\n * | R26  | A11y                      | names read as a list; group change announced once |\n */\n\nimport { FlipGroup } from '@/components/ui/effects/flip-group';\nimport { cn } from '@/lib/utils';\nimport { motionEase } from '@/lib/motion-token';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\nimport { TimerRing } from '@/components/ui/games/timer-ring';\n\nexport const MIN_VIEWPORT = 320 as const;\n\n// --- GroupCard (phone) -----------------------------------------------------------\n\ninterface GroupCardLabels {\n  /** Read when the group is set. @default (names) => `You're with ${names}.` */\n  with?: (names: string) => string;\n  /** No one else in the group yet. @default 'Waiting for someone to join you.' */\n  waiting?: string;\n  /** Names the timer. @default 'Time to talk' */\n  timer?: string;\n}\n\ntype GroupCardProps = Omit<React.ComponentProps<'section'>, 'children'> & {\n  /** What the group is called: \"Team 2\", \"Your pair\", a colour. */\n  label: React.ReactNode;\n  /** The other people in the group, by name. */\n  members: readonly string[];\n  /** What to talk about or do. */\n  prompt?: React.ReactNode;\n  /** When the talk ends, as a timestamp; shows a TimerRing. */\n  deadline?: number | null;\n  /** The talk's whole length, in seconds, for the ring. @default 120 */\n  seconds?: number;\n  onExpire?: () => void;\n  locale?: string;\n  labels?: GroupCardLabels;\n};\n\nfunction useRiseIn(key: string, reduced: boolean) {\n  const ref = React.useRef<HTMLElement | null>(null);\n  // The group shown on mount is already the state: only a change rises in.\n  const shown = React.useRef(key);\n  React.useEffect(() => {\n    if (shown.current === key) return;\n    shown.current = key;\n    const el = ref.current;\n    if (!el || reduced || typeof el.animate !== 'function') return;\n    el.animate(\n      [\n        { transform: 'translateY(8px)', opacity: 0 },\n        { transform: 'translateY(0)', opacity: 1 },\n      ],\n      {\n        duration: 200,\n        easing: motionEase(el, 'enter'),\n      },\n    );\n    const chips = el.querySelectorAll<HTMLElement>('[data-slot=\"group-card-member\"]');\n    // 150ms in total across the names, however many there are.\n    const step = chips.length > 1 ? 150 / (chips.length - 1) : 0;\n    chips.forEach((chip, i) => {\n      if (typeof chip.animate !== 'function') return;\n      chip.animate(\n        [\n          { transform: 'scale(0.9)', opacity: 0 },\n          { transform: 'scale(1)', opacity: 1 },\n        ],\n        {\n          duration: 200,\n          delay: Math.round(i * step),\n          easing: motionEase(chip, 'enter'),\n          fill: 'backwards',\n        },\n      );\n    });\n  }, [key, reduced]);\n  return ref;\n}\n\nfunction GroupCard({\n  label,\n  members,\n  prompt,\n  deadline,\n  seconds = 120,\n  onExpire,\n  locale,\n  labels,\n  className,\n  ...props\n}: GroupCardProps) {\n  const reduced = useReducedMotion();\n  const key = members.join('\\u0000');\n  const ref = useRiseIn(key, reduced);\n  const list = React.useMemo(() => new Intl.ListFormat(locale, { type: 'conjunction' }), [locale]);\n  const waiting = members.length === 0;\n  const sentence = waiting\n    ? (labels?.waiting ?? 'Waiting for someone to join you.')\n    : (labels?.with ?? ((n: string) => `You're with ${n}.`))(list.format(members));\n\n  return (\n    <section\n      ref={ref as React.Ref<HTMLElement>}\n      data-slot=\"group-card\"\n      data-state={waiting ? 'waiting' : 'grouped'}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('bg-card text-card-foreground grid gap-4 rounded-xl border p-5', className)}\n      {...props}\n    >\n      <div className=\"flex items-start justify-between gap-4\">\n        <p data-slot=\"group-card-label\" className=\"font-heading text-2xl font-semibold text-balance\">\n          {label}\n        </p>\n        {deadline !== undefined ? (\n          <TimerRing\n            seconds={seconds}\n            deadline={deadline}\n            onExpire={onExpire}\n            labels={{ name: labels?.timer ?? 'Time to talk' }}\n          />\n        ) : null}\n      </div>\n      {waiting ? (\n        <p className=\"text-muted-foreground text-sm\">{sentence}</p>\n      ) : (\n        <ul data-slot=\"group-card-members\" className=\"flex flex-wrap gap-2\">\n          {members.map((name) => (\n            <li\n              key={name}\n              data-slot=\"group-card-member\"\n              className=\"bg-primary/10 text-foreground rounded-full px-3 py-1 text-sm font-medium\"\n            >\n              {name}\n            </li>\n          ))}\n        </ul>\n      )}\n      {prompt ? (\n        <p data-slot=\"group-card-prompt\" className=\"text-lg text-pretty\">\n          {prompt}\n        </p>\n      ) : null}\n      <span data-slot=\"group-card-announce\" aria-live=\"polite\" className=\"sr-only\">\n        {waiting ? '' : sentence}\n      </span>\n    </section>\n  );\n}\nGroupCard.displayName = 'GroupCard';\n\n// --- GroupGrid (screen) ----------------------------------------------------------\n\ninterface GridGroup {\n  id: string;\n  label: React.ReactNode;\n  /** People in the group, as `{ id, name }` so a name can glide when it moves. */\n  members: readonly { id: string; name: string }[];\n}\n\ntype GroupGridProps = Omit<React.ComponentProps<'div'>, 'children'> & {\n  groups: readonly GridGroup[];\n  /** The viewer's group, marked. */\n  current?: string;\n  /** `stage` for a shared screen. @default 'default' */\n  size?: 'default' | 'stage';\n};\n\nfunction GroupGrid({ groups, current, size = 'default', className, ...props }: GroupGridProps) {\n  const stage = size === 'stage';\n  return (\n    <div\n      data-slot=\"group-grid\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('@container', className)}\n      {...props}\n    >\n      <FlipGroup render={<ul />} className={cn('grid gap-3 @md:grid-cols-2 @4xl:grid-cols-3', stage && 'gap-4')}>\n        {groups.map((g) => (\n          <li\n            key={g.id}\n            data-slot=\"group-grid-group\"\n            aria-current={current === g.id ? 'true' : undefined}\n            className={cn(\n              'grid content-start gap-2 rounded-lg border p-4',\n              current === g.id ? 'border-primary bg-primary/5' : 'bg-card',\n            )}\n          >\n            <p className={cn('font-heading font-semibold', stage ? 'text-xl' : 'text-base')}>{g.label}</p>\n            <ul className=\"flex flex-wrap gap-1.5\">\n              {g.members.map((m) => (\n                <li\n                  key={m.id}\n                  data-flip-id={m.id}\n                  className={cn('bg-muted rounded-full px-2.5 py-0.5', stage ? 'text-base' : 'text-sm')}\n                >\n                  {m.name}\n                </li>\n              ))}\n            </ul>\n          </li>\n        ))}\n      </FlipGroup>\n    </div>\n  );\n}\nGroupGrid.displayName = 'GroupGrid';\n\nexport { GroupCard, GroupGrid };\nexport type { GroupCardProps, GroupCardLabels, GroupGridProps, GridGroup };\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/groups\n\nInstalled to `components/ui/games/groups.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/groups';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/groups\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
