{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "team-access",
  "type": "registry:block",
  "title": "Team access",
  "description": "A searchable team roster with protected owner roles, pending changes, and save recovery.",
  "categories": [
    "blocks"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [
    "card",
    "input",
    "button"
  ],
  "files": [
    {
      "path": "src/registry/overtrue/team-access.tsx",
      "type": "registry:component",
      "target": "components/overtrue/team-access.tsx",
      "content": "\"use client\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport { IconChevronDown, IconLoader2 } from \"@tabler/icons-react\";\nimport { Button } from \"@/components/ui/button\";\nimport { SectionCard } from \"./section-card\";\nimport { AvatarStack, type TeamMember } from \"./avatar-stack\";\nimport { SearchField } from \"./search-field\";\nimport { cn } from \"@/lib/utils\";\n\nexport type TeamRole = \"Owner\" | \"Admin\" | \"Member\";\nexport interface AccessMember extends TeamMember {\n  email: string;\n  role: TeamRole;\n}\n\n/** Controlled permissions. The caller handles authorization and persistence. */\nexport function TeamAccess({\n  members,\n  onRoleChange,\n  className,\n}: {\n  members: readonly AccessMember[];\n  onRoleChange?: (\n    id: string,\n    role: Exclude<TeamRole, \"Owner\">,\n  ) => void | Promise<void>;\n  className?: string;\n}) {\n  const [query, setQuery] = useState(\"\");\n  const [roleStates, setRoleStates] = useState(\n    new Map<string, \"saving\" | \"failed\">(),\n  );\n  const inFlight = useRef(new Set<string>());\n  const focusAfterSave = useRef<{\n    id: string;\n    control: HTMLSelectElement;\n    anchor: HTMLElement;\n  } | null>(null);\n  const search = useRef<HTMLInputElement>(null);\n  const id = useId();\n  useEffect(() => {\n    const target = focusAfterSave.current;\n    if (!target || roleStates.get(target.id) === \"saving\") return;\n    if (\n      target.control.isConnected &&\n      document.activeElement === target.anchor\n    ) {\n      target.control.focus({ preventScroll: true });\n    }\n    focusAfterSave.current = null;\n  }, [roleStates]);\n  const normalizedQuery = query.trim().toLowerCase();\n  const visible = members.filter((member) =>\n    `${member.name} ${member.email}`.toLowerCase().includes(normalizedQuery),\n  );\n  async function changeRole(\n    member: AccessMember,\n    role: Exclude<TeamRole, \"Owner\">,\n    control: HTMLSelectElement,\n  ) {\n    if (\n      !onRoleChange ||\n      role === member.role ||\n      inFlight.current.has(member.id)\n    )\n      return;\n    inFlight.current.add(member.id);\n    // Keep the keyboard's place while the native select is disabled. Restore\n    // it only if the user has not moved on to another control.\n    if (document.activeElement === control && control.parentElement) {\n      const anchor = control.parentElement;\n      focusAfterSave.current = { id: member.id, control, anchor };\n      anchor.focus({ preventScroll: true });\n    }\n    setRoleStates((current) => new Map(current).set(member.id, \"saving\"));\n    let failed = false;\n    try {\n      await onRoleChange(member.id, role);\n    } catch {\n      failed = true;\n    } finally {\n      inFlight.current.delete(member.id);\n      setRoleStates((current) => {\n        const next = new Map(current);\n        if (failed) next.set(member.id, \"failed\");\n        else next.delete(member.id);\n        return next;\n      });\n    }\n  }\n  return (\n    <SectionCard\n      title={\n        <span className=\"flex flex-wrap items-center justify-between gap-x-3 gap-y-1\">\n          <span>Team access</span>\n          <span className=\"text-xs font-normal tabular-nums text-muted-foreground\">\n            {members.length} {members.length === 1 ? \"person\" : \"people\"}\n          </span>\n        </span>\n      }\n      description=\"The people who can access this workspace.\"\n      className={cn(\"shadow-none\", className)}\n      contentClassName=\"p-0\"\n    >\n      <div className=\"m-5\">\n        <SearchField\n          ref={search}\n          label=\"Search team members\"\n          placeholder=\"Search by name or email…\"\n          value={query}\n          onValueChange={setQuery}\n        />\n      </div>\n      <ul\n        aria-label=\"Workspace members\"\n        className=\"m-0 list-none divide-y divide-border p-0\"\n      >\n        {visible.map((member, index) => {\n          const roleState = roleStates.get(member.id);\n          return (\n            <li\n              key={member.id}\n              className=\"grid grid-cols-[auto_minmax(0,1fr)] items-center gap-x-3 gap-y-2 px-5 py-4 sm:grid-cols-[auto_minmax(0,1fr)_auto]\"\n            >\n              <AvatarStack members={[member]} />\n              <div className=\"min-w-0\">\n                <p className=\"m-0 text-sm font-medium [overflow-wrap:anywhere]\">\n                  {member.name}\n                </p>\n                <p className=\"m-0 mt-0.5 text-xs text-muted-foreground [overflow-wrap:anywhere]\">\n                  {member.email}\n                </p>\n              </div>\n              {member.role === \"Owner\" || !onRoleChange ? (\n                <span className=\"col-start-2 flex h-8 items-center text-xs text-muted-foreground sm:col-start-3 sm:row-start-1 sm:px-3\">\n                  {member.role}\n                </span>\n              ) : (\n                <div\n                  tabIndex={-1}\n                  role=\"group\"\n                  aria-label={`Access for ${member.name}`}\n                  className=\"relative col-start-2 w-fit rounded-md focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring sm:col-start-3 sm:row-start-1\"\n                >\n                  <select\n                    aria-label={`Role for ${member.name}`}\n                    aria-busy={roleState === \"saving\"}\n                    data-error={roleState === \"failed\" || undefined}\n                    aria-describedby={\n                      roleState === \"failed\"\n                        ? `${id}-error-${index}`\n                        : undefined\n                    }\n                    disabled={roleState === \"saving\"}\n                    value={member.role}\n                    onChange={(event) => {\n                      const role = event.target.value;\n                      if (role === \"Admin\" || role === \"Member\")\n                        void changeRole(member, role, event.currentTarget);\n                    }}\n                    className=\"h-8 appearance-none rounded-md border border-input bg-card ps-3 pe-8 text-xs text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-wait disabled:opacity-60 data-[error]:border-destructive\"\n                  >\n                    <option>Admin</option>\n                    <option>Member</option>\n                  </select>\n                  {roleState === \"saving\" ? (\n                    <IconLoader2\n                      aria-hidden=\"true\"\n                      className=\"pointer-events-none absolute end-2.5 top-1/2 size-3 -translate-y-1/2 animate-spin text-muted-foreground motion-reduce:animate-none\"\n                    />\n                  ) : (\n                    <IconChevronDown\n                      aria-hidden=\"true\"\n                      className=\"pointer-events-none absolute end-2.5 top-1/2 size-3 -translate-y-1/2 text-muted-foreground\"\n                    />\n                  )}\n                </div>\n              )}\n              {onRoleChange && roleState === \"failed\" && (\n                <p\n                  id={`${id}-error-${index}`}\n                  role=\"alert\"\n                  className=\"col-start-2 m-0 text-xs leading-5 text-destructive sm:col-span-2\"\n                >\n                  Could not update this role. Please try again.\n                </p>\n              )}\n              {roleState === \"saving\" && (\n                <span role=\"status\" className=\"sr-only\">\n                  Updating role for {member.name}.\n                </span>\n              )}\n            </li>\n          );\n        })}\n      </ul>\n      {!visible.length && (\n        <div role=\"status\" className=\"px-5 pb-6 pt-2 text-center\">\n          <p className=\"m-0 text-sm font-medium\">\n            {members.length\n              ? \"No members match your search.\"\n              : \"No members yet.\"}\n          </p>\n          <p className=\"m-0 mt-1 text-xs leading-5 text-muted-foreground\">\n            {members.length\n              ? \"Try a different name or email address.\"\n              : \"Workspace members will appear here when they join.\"}\n          </p>\n          {query && (\n            <Button\n              type=\"button\"\n              variant=\"outline\"\n              size=\"sm\"\n              className=\"mt-4 shadow-none\"\n              onClick={() => {\n                setQuery(\"\");\n                search.current?.focus();\n              }}\n            >\n              Clear search\n            </Button>\n          )}\n        </div>\n      )}\n      <p className=\"m-0 border-t border-border px-5 py-3 text-xs leading-5 text-muted-foreground\">\n        Owners manage billing and workspace access. Admins manage projects and\n        members.\n      </p>\n    </SectionCard>\n  );\n}\n"
    },
    {
      "path": "src/registry/overtrue/section-card.tsx",
      "type": "registry:component",
      "target": "components/overtrue/section-card.tsx",
      "content": "import type { ComponentProps, ReactNode } from \"react\";\nimport {\n  Card,\n  CardContent,\n  CardHeader,\n  CardTitle,\n  CardDescription,\n} from \"@/components/ui/card\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SectionCardProps extends Omit<\n  ComponentProps<typeof Card>,\n  \"title\"\n> {\n  title?: ReactNode;\n  description?: ReactNode;\n  actions?: ReactNode;\n  contentClassName?: string;\n}\n\n/** A shared heading, actions and content surface for admin panels. */\nexport function SectionCard({\n  title,\n  description,\n  actions,\n  children,\n  className,\n  contentClassName,\n  ...props\n}: SectionCardProps) {\n  return (\n    <Card\n      data-slot=\"section-card\"\n      className={cn(\n        \"min-w-0 gap-0 rounded-2xl border border-border/70 bg-card py-0 text-card-foreground ring-0\",\n        \"shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.5)]\",\n        className,\n      )}\n      {...props}\n    >\n      {(title || description || actions) && (\n        <CardHeader className=\"flex flex-row flex-wrap items-center justify-between gap-x-4 gap-y-3 border-b border-border/60 px-5 py-4 [.border-b]:pb-4\">\n          <div data-slot=\"section-card-heading\" className=\"min-w-0 flex-1\">\n            {title && (\n              <CardTitle className=\"m-0 text-sm leading-6 font-semibold tracking-tight text-card-foreground\">\n                {title}\n              </CardTitle>\n            )}\n            {description && (\n              <CardDescription className=\"m-0 mt-0.5 text-[13px] leading-5 text-muted-foreground\">\n                {description}\n              </CardDescription>\n            )}\n          </div>\n          {actions && (\n            <div\n              data-slot=\"section-card-actions\"\n              className=\"flex shrink-0 items-center gap-2\"\n            >\n              {actions}\n            </div>\n          )}\n        </CardHeader>\n      )}\n      <CardContent className={cn(\"p-5\", contentClassName)}>\n        {children}\n      </CardContent>\n    </Card>\n  );\n}\n"
    },
    {
      "path": "src/registry/overtrue/avatar-stack.tsx",
      "type": "registry:component",
      "target": "components/overtrue/avatar-stack.tsx",
      "content": "\"use client\";\nimport { useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nexport interface TeamMember {\n  id: string;\n  name: string;\n  image?: string;\n}\n\n// Initials take a stable tint from the theme's chart palette.\nconst tints = [\n  \"[--avatar-tint:var(--color-chart-1)]\",\n  \"[--avatar-tint:var(--color-chart-2)]\",\n  \"[--avatar-tint:var(--color-chart-3)]\",\n  \"[--avatar-tint:var(--color-chart-4)]\",\n  \"[--avatar-tint:var(--color-chart-5)]\",\n];\nfunction tintFor(key: string) {\n  let hash = 0;\n  for (const char of key) hash = (hash * 31 + char.charCodeAt(0)) >>> 0;\n  return tints[hash % tints.length];\n}\n\nexport function AvatarStack({\n  members,\n  max = 4,\n  className,\n}: {\n  members: TeamMember[];\n  max?: number;\n  className?: string;\n}) {\n  const visible = members.slice(0, Math.max(0, max));\n  return (\n    <div\n      data-slot=\"avatar-stack\"\n      className={cn(\"flex items-center -space-x-2\", className)}\n      aria-label={members.map((member) => member.name).join(\", \")}\n    >\n      {visible.map((member) => (\n        <MemberAvatar key={member.id} member={member} />\n      ))}\n      {members.length > visible.length && (\n        <span\n          data-slot=\"avatar-stack-more\"\n          className=\"relative flex size-9 shrink-0 items-center justify-center rounded-full border-2 border-background bg-muted text-xs font-medium tracking-tight text-muted-foreground tabular-nums shadow-[0_1px_2px_rgb(0_0_0/0.06)]\"\n        >\n          +{members.length - visible.length}\n        </span>\n      )}\n    </div>\n  );\n}\n\nfunction MemberAvatar({ member }: { member: TeamMember }) {\n  const [failedImage, setFailedImage] = useState<string>();\n  const initials = member.name\n    .trim()\n    .split(/\\s+/)\n    .map((word) => word[0])\n    .slice(0, 2)\n    .join(\"\")\n    .toUpperCase();\n  const showImage = member.image && member.image !== failedImage;\n  return (\n    <span\n      role=\"img\"\n      aria-label={member.name}\n      title={member.name}\n      data-slot=\"avatar-stack-item\"\n      className={cn(\n        \"relative flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-full border-2 border-background text-xs font-semibold tracking-tight shadow-[0_1px_2px_rgb(0_0_0/0.06)] transition-transform duration-150 ease-[cubic-bezier(0.22,1,0.36,1)] hover:z-10 hover:-translate-y-0.5 motion-reduce:transition-none motion-reduce:hover:translate-y-0\",\n        \"after:pointer-events-none after:absolute after:inset-0 after:rounded-full after:ring-1 after:ring-foreground/10 after:ring-inset\",\n        showImage\n          ? \"bg-muted\"\n          : cn(\n              tintFor(member.id || member.name),\n              \"bg-[color-mix(in_oklab,var(--avatar-tint)_16%,var(--color-card))] text-[color-mix(in_oklab,var(--avatar-tint)_72%,var(--color-foreground))]\",\n            ),\n      )}\n    >\n      {showImage ? (\n        <img\n          src={member.image}\n          alt=\"\"\n          className=\"size-full object-cover\"\n          onError={() => setFailedImage(member.image)}\n        />\n      ) : (\n        initials || \"?\"\n      )}\n    </span>\n  );\n}\n"
    },
    {
      "path": "src/registry/overtrue/search-field.tsx",
      "type": "registry:component",
      "target": "components/overtrue/search-field.tsx",
      "content": "\"use client\";\nimport { useId, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { IconSearch, IconX } from \"@tabler/icons-react\";\nimport { Input } from \"@/components/ui/input\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SearchFieldProps extends Omit<\n  ComponentProps<typeof Input>,\n  \"type\" | \"value\" | \"defaultValue\" | \"onChange\"\n> {\n  label: string;\n  value: string;\n  onValueChange: (value: string) => void;\n  containerClassName?: string;\n}\n/** Controlled search input. Filtering and debouncing belong to the caller. */\nexport function SearchField({\n  label,\n  value,\n  onValueChange,\n  id,\n  ref,\n  containerClassName,\n  className,\n  placeholder = \"Search…\",\n  ...props\n}: SearchFieldProps) {\n  const generatedId = useId();\n  const inputId = id ?? generatedId;\n  const inputRef = useRef<HTMLInputElement>(null);\n  useImperativeHandle(ref, () => inputRef.current!, []);\n  return (\n    <div\n      data-slot=\"search-field\"\n      className={cn(\"relative min-w-0\", containerClassName)}\n    >\n      <label htmlFor={inputId} className=\"sr-only\">\n        {label}\n      </label>\n      <IconSearch\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute start-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground\"\n      />\n      <Input\n        {...props}\n        ref={inputRef}\n        id={inputId}\n        type=\"search\"\n        value={value}\n        onChange={(event) => onValueChange(event.target.value)}\n        placeholder={placeholder}\n        className={cn(\n          \"h-10 w-full rounded-md border-input bg-card dark:bg-card ps-9 pe-9 text-base text-foreground shadow-xs placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/20 sm:text-sm [&::-webkit-search-cancel-button]:appearance-none\",\n          className,\n        )}\n      />\n      {value && !props.readOnly && (\n        <button\n          type=\"button\"\n          aria-label={`Clear ${label.toLowerCase()}`}\n          disabled={props.disabled}\n          className=\"absolute end-1 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50\"\n          onClick={() => {\n            onValueChange(\"\");\n            inputRef.current?.focus();\n          }}\n        >\n          <IconX aria-hidden=\"true\" className=\"size-3.5\" />\n        </button>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/blocks/team-access. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
