Role Preview

Shows what a chosen role can and can't do, the diff from the current role, and a smaller role when the pick adds risky permissions.

StopsGave a teammate admin by mistake

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/role-preview.json

The files land in your project. They're yours to edit.

Usage

role-preview-usage.tsx
import { RolePreview } from "@/components/ui/role-preview"

<RolePreview
  roles={roles}
  capabilities={capabilities}
  matrix={matrix}
  defaultValue="admin"
  currentRole="viewer"
  personName="Priya"
  label="Priya's role in Acme Corp"
/>

What it catches

  • Permissions gained and lost versus the current role
  • Dangerous capabilities (cost money, destroy data, widen access) marked
  • A smaller role that drops the dangerous extras, with one-tap switch

Props

RolePreview props
PropTypeDefault
roles* (required)

Roles in order from least to most access.

RoleOption[]—
capabilities* (required)

Everything a role can grant, in the order to list it.

Capability[]—
matrix* (required)

Permissions matrix: role id to the capability ids it grants.

Record<string, string[]>—
value

The selected role id (controlled).

string—
defaultValue

The initially selected role id when uncontrolled.

string—
onValueChange

Called with the role id the user picks, including from the suggestion.

(roleId: string) => void—
currentRole

The person's role today, used to show what changes. Omit for new invites.

string—
personName

Who you're choosing for, e.g. "Priya".

string—
label

Visible label of the role group.

string"Role"
currentBadge

Badge on the person's current role.

string"Current"
sensitiveBadge

Badge on dangerous capabilities.

string"Sensitive"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Role select has a visible label
  • Diff list has an aria-label and renders in a polite live region
  • Can/Cannot prefixes and "Can no longer" are text, not colour alone; icons are aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Authorize role changes on the server and check permissions per request; this only previews the role.

  • Only as accurate as the role matrix you pass
  • Suggestion is mechanical least-privilege; it doesn't know what the person actually needs

What it stops

Gave a teammate admin by mistake

Also known as

roles · permissions · rbac · team members · invite · admin · access control · member settings

Dependencies

Pairs well with