# Team members

> Settings → Members, done properly: invited addresses fly out of the field onto their rows, role pills grow into the list of roles, and seats roll.

Members pages are usually a table with a select per row, an "Invite" modal and a toast that says something happened somewhere. Here the invite field sits above the list: paste a list of addresses (repeats fly into their twins), pick the role they join as, and "Invite 3" sends them. Each chip then lifts out of the field and flies down onto its new row, where the name lands as the avatar opens in. "4 of 6 seats" rolls as people come and go, and the field takes no more than the seats that are left. A role pill grows into the list of roles and folds back with the new one, a spinner riding in it while it saves; if your server refuses, the old role morphs back, the pill shakes and the reason lifts in under the name. Pending invites count down to Resend, which says Sending and Sent and starts the clock again. Removing someone stretches the bin into "Remove", draws a check and folds the row away.

## Install

```bash
npx shadcn@latest add @hairline/team-members
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `tag-input`, `text-morph`, `number-roll`, `status-button`
- Docs and live preview: https://hairlineui.com/ui/team-members
- Registry item (source): https://hairlineui.com/r/team-members.json

## Usage

```tsx
import { TeamMembers } from "@/components/team-members";

<TeamMembers
  defaultValue={members}
  roles={[
    { value: "admin", label: "Admin", description: "Members, billing and API keys" },
    { value: "member", label: "Member", description: "Create and edit projects" },
  ]}
  seats={10}
  onInvite={(emails, role) => api.invite(emails, role)}
  onRoleChange={(member, role) => api.setRole(member.id, role)}
  onRemove={(member) => api.remove(member.id)}
  onResend={(member) => api.resend(member.id)}
/>
```

## Organisation members with Better Auth

Members and pending invitations come from the organization plugin and are mapped to plain records. Each callback is one call to its client; what it throws (a seat limit, a missing permission) is what the row or the field says. Clerk Organizations, WorkOS or your own table fit the same way.

```tsx
"use client";
import { TeamMembers, type TeamMember } from "@/components/team-members";
import { authClient } from "@/lib/auth-client";

const roles = [
  { value: "admin", label: "Admin", description: "Members, billing and API keys" },
  { value: "member", label: "Member", description: "Create and edit projects" },
];

const fail = (r: { error?: { message?: string } | null }) => {
  if (r.error) throw new Error(r.error.message ?? "That didn't work.");
};

export function Members({ initial, seats, me }: { initial: TeamMember[]; seats: number; me: string }) {
  return (
    <TeamMembers
      defaultValue={initial.map((m) => ({ ...m, you: m.id === me, locked: m.role === "owner" }))}
      roles={roles}
      seats={seats}
      onInvite={async (emails, role) => {
        const sent = await Promise.all(emails.map((email) => authClient.organization.inviteMember({ email, role })));
        sent.forEach(fail);
        return sent.map((r) => ({ id: r.data!.id, email: r.data!.email, role, status: "invited", invitedAt: new Date() }));
      }}
      onRoleChange={async (m, role) => fail(await authClient.organization.updateMemberRole({ memberId: m.id, role }))}
      onRemove={async (m) =>
        fail(m.status === "invited"
          ? await authClient.organization.cancelInvitation({ invitationId: m.id })
          : await authClient.organization.removeMember({ memberIdOrEmail: m.id }))}
      onResend={async (m) => fail(await authClient.organization.inviteMember({ email: m.email, role: m.role as "admin" | "member", resend: true }))}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `TeamMember[]` | – | Controlled members and invites: { id, email, name?, image?, role, status?, invitedAt?, lastActiveAt?, you?, locked? }. |
| `defaultValue` | `TeamMember[]` | – | Starting members when uncontrolled. |
| `onValueChange` | `(members: TeamMember[]) => void` | – | The list after every invite, role change, resend and removal. New invites come first. |
| `roles` | `{ value, label, description? }[]` | – | Roles people can be given, in menu order. A member whose role isn't listed (an owner) shows it as plain text. |
| `inviteRole` | `string` | – | The role new invites start with. The second role by default. |
| `seats` | `number` | – | Seats on the plan. Members and pending invites each take one; the field takes no more than are left. |
| `onInvite` | `(emails, role) => Promise<TeamMember[]>` | – | Sends invites and returns the new members (status "invited"). Throw to keep the addresses and show the message. Without it there is no invite field. |
| `onRoleChange` | `(member, role) => Promise<unknown>` | – | Saves a role; the pill changes at once and changes back if this throws. Without it roles are plain text. |
| `onRemove` | `(member) => Promise<unknown>` | – | Removes a member or cancels an invite. Never offered for you or locked members. |
| `onResend` | `(member) => Promise<unknown>` | – | Sends an invite again; the clock restarts from now. |
| `resendAfter` | `number` | `30` | Seconds before an invite can be sent again. |
| `suggestions` | `TagInputSuggestion[] \| (query) => …` | – | People to suggest in the invite field, e.g. from your directory. |
| `title` | `string` | `"Members"` | Heading and the list's accessible name. |
| `description` | `string` | – | The line under the heading. |

## States

- **invite**: Addresses become chips in the invite field (tag input): pasted lists spill out of the caret, repeats fly into their twins and anything that isn't an address lands red. The button counts them: "Invite 3".
- **sending**: Invite turns into "Inviting" while onInvite runs; the field holds still. If it throws, the addresses stay, the button says Try again and the reason takes the line under the field.
- **arrive**: Each chip's copy lifts 6px out of the field and flies 680ms onto its row's name, 60ms after the one before, its outline fading as it lands; the name takes over and the avatar scales in from 0.6 out of a blur. The rows below glide down to make room.
- **seats**: "4 of 6 seats" rolls with every invite and removal and turns amber when none are left; the field then refuses more and says how many fit.
- **role**: The role pill's own surface grows from its right edge into the list of roles in 420ms (upward when there's no room below); the highlight glides between rows and a check draws beside the current one. Picking folds it back and the label morphs; a spinner replaces the chevron while onRoleChange runs.
- **refused**: If onRoleChange throws, the old role morphs back, the pill shakes ±4px and the error's message lifts in over the line under the name for 3.6s.
- **resend**: Pending invites say "Resend in 0:28", the seconds rolling down. Then Resend is a link; it morphs to Sending and Sent, the invite's time resets and the countdown opens again.
- **remove**: The bin (or, for an invite, the crossed envelope) stretches into a red Remove / Cancel invite. A check draws, the row dims for 700ms, then folds away while the rest glide up.

## What it handles

Members pages are usually a table with a select per row, an Invite modal and a toast that says something happened somewhere. This puts inviting, roles, seats and removal in one place.

- **Invite many at once**: Paste a list of addresses, pick the role they join as, and “Invite 3” sends them.
- **Invites land on their rows**: Each chip lifts out of the field and flies onto its new row, where the avatar opens in.
- **Seats are counted**: “4 of 6 seats” rolls as people come and go, turns amber when none are left, and the field takes no more than fit.
- **Roles change in place**: A role pill grows into the list of roles. If your server refuses, the old role returns and the reason shows under the name.
- **Pending invites can be resent**: A countdown, “Resend in 0:28”, becomes a Resend link that says Sending and Sent.
- **Removing asks first**: The bin stretches into “Remove”, a check draws, then the row folds away. You and locked members, such as an owner, can’t be removed here.

## Replaces

an invite modal, a members table, a role dropdown per row, a seat counter, a resend timer, a remove confirmation

## Where it fits

- **Settings → Members pages**: Invite people, change roles and remove them, in one place.
- **Workspace administration**: Seats, roles and pending invites for an organisation.
- **Client portals**: Let a client invite their own staff.
- **Plans with seat limits**: Show seats used and stop invites when none are left.

## Notes

- The invite field is a tag input (combobox and chip list, with its keyboard and announcements). The role pills are buttons that open a listbox: arrows move the highlight, Enter picks, Escape folds it back and returns focus to the pill.
- Invites, role changes, refusals, resends and removals are announced in a status region outside the list. The resend countdown is hidden from screen readers; the button says when it can be used.
- You and locked members (an owner) can't be removed here, and a locked member's role is plain text.
- The chips' flight is a copy in an overlay, so the field and the list each settle on their own; rows glide with additive transforms and removed rows fold away as their own detached elements.
- Reduced motion adds, changes and removes in place; the role list opens and closes without growing.

License: MIT (https://hairlineui.com/license#components)
