{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-team-members",
  "type": "registry:block",
  "title": "App, member list",
  "description": "The people on a team: avatar, name, email and a role select per member, a locked owner row, Remove with a confirmation that keeps focus in the list, role changes and removals announced by name, a count that follows, and an empty state.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/avatar.json",
    "https://ui.klarhimmel.com/r/badge.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/empty-state.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/native-select.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-team-members/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-team-members/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t, req } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  /** Follows the number of members: \"4 members\". */\n  summaryWord: t(20),\n  /** The roles a member can have. Each row's select offers all of them. */\n  roles: z.array(t(20)).min(2).max(5),\n  /** Read by screen readers before the member's name: \"Role for Maja Lindqvist\". */\n  roleLabel: t(30),\n  members: z\n    .array(\n      z.object({\n        name: t(40),\n        email: t(60),\n        /** The role the member starts with: one of `roles`. Not editable copy. */\n        sample: t(20),\n        /** A locked row shows its role as a badge, not a select (the owner). */\n        locked: z.boolean(),\n      }),\n    )\n    .min(1)\n    .max(8),\n  /** Remove: the button's text (the member's name follows it for screen readers) and the question asked first. */\n  remove: z.object({ label: req(20), question: req(40), yes: req(24), no: req(24) }),\n  /** Said after an action, with the person's name: \"Nils Berg is now Viewer\", \"Nils Berg removed\". */\n  notices: z.object({ roleNow: t(24), removed: t(24) }),\n  state: z.enum(['filled', 'empty']),\n  messages: z.object({ emptyTitle: req(80), emptyBody: t(160) }),\n});\n\nexport const spec = defineSpec({\n  type: 'app-team-members',\n  aliases: ['app/team-members'],\n  name: 'App, member list',\n  category: 'app',\n  role: 'body',\n  description: 'The people on a team: avatar, name, email and a role select per member, a locked owner row, Remove with a confirmation that keeps focus in the list, role changes and removals announced by name, a count that follows, and an empty state.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Team\",\n    \"title\": \"Name the group of people\",\n    \"description\": \"Say who is listed and who can change roles.\",\n    \"summaryWord\": \"members\",\n    \"roles\": [\n      \"Owner\",\n      \"Admin\",\n      \"Member\",\n      \"Viewer\"\n    ],\n    \"roleLabel\": \"Role for\",\n    \"members\": [\n      {\n        \"name\": \"Person one\",\n        \"email\": \"one@example.com\",\n        \"sample\": \"Owner\",\n        \"locked\": true\n      },\n      {\n        \"name\": \"Person two\",\n        \"email\": \"two@example.com\",\n        \"sample\": \"Admin\",\n        \"locked\": false\n      },\n      {\n        \"name\": \"Person three\",\n        \"email\": \"three@example.com\",\n        \"sample\": \"Member\",\n        \"locked\": false\n      },\n      {\n        \"name\": \"Person four\",\n        \"email\": \"four@example.com\",\n        \"sample\": \"Viewer\",\n        \"locked\": false\n      }\n    ],\n    \"remove\": {\n      \"label\": \"Remove\",\n      \"question\": \"Remove this one?\",\n      \"yes\": \"Yes, remove\",\n      \"no\": \"Keep\"\n    },\n    \"notices\": {\n      \"roleNow\": \"is now\",\n      \"removed\": \"removed\"\n    },\n    \"state\": \"filled\",\n    \"messages\": {\n      \"emptyTitle\": \"Say you are alone here\",\n      \"emptyBody\": \"Say how to add a person and where they appear.\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-team-members/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-team-members/index.tsx",
      "content": "import { useEffect, useId, useRef } from 'react';\nimport { Users } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Avatar } from '../../ui/avatar';\nimport { Badge } from '../../ui/badge';\nimport { Button } from '../../ui/button';\nimport { EmptyState } from '../../ui/empty-state';\nimport { NativeSelect } from '../../ui/native-select';\nimport { Container, Section, SectionHeader } from '../_shared/kit';\nimport { AppPanel, StateSlot, useSynced } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppTeamMembers({ props }: BlockProps<Props>) {\n  const id = useId();\n  const [gone, setGone] = useSynced<number[]>([], props.members);\n  const [asking, setAsking] = useSynced<number | null>(null, props.members);\n  const [notice, setNotice] = useSynced('', props.members);\n  const left = props.members.map((m, i) => ({ m, i })).filter(({ i }) => !gone.includes(i));\n  const refs = useRef<{ remove: Record<number, HTMLButtonElement | null>; keep: Record<number, HTMLButtonElement | null> }>({ remove: {}, keep: {} });\n  const summary = useRef<HTMLParagraphElement>(null);\n  const next = useRef<{ kind: 'keep' | 'remove' | 'after'; i: number } | null>(null);\n  // Focus follows what the person just did: into the question, back to the button, or on to the next row.\n  useEffect(() => {\n    const n = next.current;\n    next.current = null;\n    if (!n) return;\n    if (n.kind === 'keep') refs.current.keep[n.i]?.focus();\n    else if (n.kind === 'remove') refs.current.remove[n.i]?.focus();\n    else {\n      const rest = props.members.map((_, k) => k).filter((k) => !gone.includes(k));\n      const target = rest.find((k) => k > n.i && refs.current.remove[k]) ?? [...rest].reverse().find((k) => k < n.i && refs.current.remove[k]);\n      (target !== undefined ? refs.current.remove[target] : summary.current)?.focus();\n    }\n  }, [asking, gone, props.members]);\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <AppPanel className=\"mt-10\">\n          <StateSlot show={props.state === 'filled'}>\n            <div className=\"border-b border-kh-line px-6 py-3 text-kh-small text-kh-muted @xl:px-8\">\n              <p ref={summary} tabIndex={-1} className=\"tabular-nums outline-none\">\n                {left.length} <Text path={['summaryWord']} value={props.summaryWord} as=\"span\" />\n              </p>\n              <p role=\"status\" className=\"min-h-5 text-kh-ink\">\n                {notice}\n              </p>\n            </div>\n            <ul className=\"divide-y divide-kh-line\">\n              {left.map(({ m, i }) => {\n                const sid = `${id}-r${i}`;\n                return (\n                  <li key={i} className=\"flex flex-col gap-3 px-6 py-4 @xl:px-8\">\n                    <div className=\"flex flex-col gap-3 @xl:flex-row @xl:items-center @xl:gap-4\">\n                      <div className=\"flex min-w-0 flex-1 items-center gap-3\">\n                        <Avatar name={m.name} decorative />\n                        <div className=\"min-w-0\">\n                          <Text path={['members', i, 'name']} value={m.name} as=\"p\" className=\"truncate text-kh-body font-medium\" />\n                          <Text path={['members', i, 'email']} value={m.email} as=\"p\" className=\"truncate text-kh-small text-kh-muted\" />\n                        </div>\n                      </div>\n                      {m.locked ? (\n                        <Badge tone=\"outline\" className=\"self-start\">\n                          <Text path={['members', i, 'sample']} value={m.sample} as=\"span\" />\n                        </Badge>\n                      ) : (\n                        <div className=\"flex flex-wrap items-center gap-2\">\n                          <div>\n                            <label htmlFor={sid} className=\"sr-only\">\n                              <Text path={['roleLabel']} value={props.roleLabel} as=\"span\" /> {m.name}\n                            </label>\n                            <NativeSelect\n                              id={sid}\n                              name={`role-${i}`}\n                              defaultValue={m.sample}\n                              className=\"w-full @xl:w-auto @xl:min-w-40\"\n                              onChange={(e) => setNotice(`${m.name} ${props.notices.roleNow} ${e.currentTarget.value}`)}\n                            >\n                              {props.roles.map((r, k) => (\n                                <Text key={k} path={['roles', k]} value={r} as=\"option\" />\n                              ))}\n                            </NativeSelect>\n                          </div>\n                          <Button\n                            variant=\"ghost\"\n                            aria-expanded={asking === i}\n                            ref={(el) => {\n                              refs.current.remove[i] = el;\n                            }}\n                            onClick={() => {\n                              next.current = { kind: 'keep', i };\n                              setAsking(asking === i ? null : i);\n                            }}\n                          >\n                            <Text path={['remove', 'label']} value={props.remove.label} as=\"span\" /> <span className=\"sr-only\">{m.name}</span>\n                          </Button>\n                        </div>\n                      )}\n                    </div>\n                    {!m.locked && (\n                      <div\n                        role=\"group\"\n                        aria-label={`${props.remove.question} ${m.name}`}\n                        hidden={asking !== i}\n                        onKeyDown={(e) => {\n                          if (e.key !== 'Escape') return;\n                          next.current = { kind: 'remove', i };\n                          setAsking(null);\n                        }}\n                        className=\"flex flex-wrap items-center gap-3 rounded-kh-lg border border-kh-line bg-kh-surface-2 p-3\"\n                      >\n                        <p className=\"text-kh-small\">\n                          <Text path={['remove', 'question']} value={props.remove.question} as=\"span\" /> <strong>{m.name}</strong>\n                        </p>\n                        <div className=\"flex flex-wrap gap-2\">\n                          <Button\n                            variant=\"secondary\"\n                            ref={(el) => {\n                              refs.current.keep[i] = el;\n                            }}\n                            onClick={() => {\n                              next.current = { kind: 'remove', i };\n                              setAsking(null);\n                            }}\n                          >\n                            <Text path={['remove', 'no']} value={props.remove.no} as=\"span\" />\n                          </Button>\n                          <Button\n                            onClick={() => {\n                              next.current = { kind: 'after', i };\n                              setAsking(null);\n                              setGone((g) => [...g, i]);\n                              setNotice(`${m.name} ${props.notices.removed}`);\n                            }}\n                          >\n                            <Text path={['remove', 'yes']} value={props.remove.yes} as=\"span\" />\n                          </Button>\n                        </div>\n                      </div>\n                    )}\n                  </li>\n                );\n              })}\n            </ul>\n          </StateSlot>\n          <StateSlot show={false}>\n            <Text path={['notices', 'roleNow']} value={props.notices.roleNow} as=\"p\" />\n            <Text path={['notices', 'removed']} value={props.notices.removed} as=\"p\" />\n          </StateSlot>\n          <StateSlot show={props.state === 'empty'}>\n            <EmptyState icon={<Users />} title={<Text path={['messages', 'emptyTitle']} value={props.messages.emptyTitle} as=\"span\" />} level={3}>\n              <Text path={['messages', 'emptyBody']} value={props.messages.emptyBody} as=\"span\" />\n            </EmptyState>\n          </StateSlot>\n        </AppPanel>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppTeamMembers);\n"
    }
  ]
}
