Roles and permissions
Workspace RBAC permissions matrix with 2D roving keyboard navigation, tri-state group toggles that ripple across rows, locked owner columns, role duplication, unsaved change indicators, and a sticky review bar.
import { RolesPermissions } from '@uthereal/ui/roles-permissions'Roles permissions playground
Roles and permissions
28 members across 5 roles
Overview
RolesPermissions renders an interactive role-based access control (RBAC) matrix for workspace settings. Each column represents a role with optional member counts and a column menu to duplicate custom roles, revert unsaved edits for that column, or delete custom roles. Locked columns (such as Owner) keep every permission enabled and answer presses with a brief horizontal nudge without altering grants.
Permission rows are organized into collapsible groups with tri-state group checkboxes (on, mixed, off) that ripple down their permissions when toggled. Any cell edit, group toggle, role duplication, or deletion marks affected cells and headers with an unsaved indicator dot and raises a sticky Review & Save bar showing the exact change count, affected roles and member count, Discard, and Save changes.
Use RolesPermissions for workspace authorization editors and grouped RBAC matrices that require review before persisting changes. For managing individual team members and invitations, use Team members or Invite people.
Usage
'use client'
import {
RolesPermissions,
type RbacGrants,
type RbacRole,
} from '@uthereal/ui/roles-permissions'
export function WorkspaceRoles({
roles,
defaultGrants,
}: {
roles: RbacRole[]
defaultGrants: RbacGrants
}) {
return (
<RolesPermissions
title="Roles and permissions"
description="Changes apply immediately to every member assigned to a modified role."
roles={roles}
defaultGrants={defaultGrants}
onSave={async (grants, updatedRoles) => {
const res = await fetch('/api/workspace/roles', {
method: 'PUT',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ grants, roles: updatedRoles }),
})
if (!res.ok) throw new Error('Save failed')
}}
/>
)
}Omit roles, groups, defaultGrants, and onSave to render the five-role sample matrix (Owner, Admin, Editor, Viewer, Billing) across four permission groups with a locally simulated save lifecycle.
Examples
Use <SchemaPlayground /> above to inspect recipe="soft" and dark mode tokens.
Compact engineering matrix with descriptions
Supply custom roles, groups with optional per-permission description lines, defaultGrants, and allowDuplicate={false} for a fixed-role authorization policy.
Engineering access
16 members across 3 roles
Fixed workspace roles for source control and production releases.
Matrix controls and review workflow
Column and cell states
| Control | Role / state | Behavior |
|---|---|---|
| Role column menu | DropdownMenu | Opens Duplicate role, Revert changes (when dirty), and Delete role (custom roles). |
| Group toggle | role="checkbox" (true / mixed / false) | Toggles every permission in the group with a staggered downward wave ripple. |
| Permission cell | role="switch" (true / false) | Flips one grant and places an unsaved warning dot beside modified cells. |
| Locked role cell | aria-disabled="true" | Always granted; pressing nudges the box gently and announces that permissions are fixed. |
Sticky review bar
| State | Trigger | Actions |
|---|---|---|
| Hidden | Zero unsaved edits and idle phase. | Collapses smoothly; restores focus to the active grid cell if the bar held focus. |
| Pending | Any cell toggle, duplicated role, or delete. | Shows rolling diff count, affected role names and member count, Discard, and Save changes. |
| Saving | Save changes activated. | Locks actions and holds loading state until onSave settles (or local simulation completes). |
| Saved | Save resolves cleanly. | Confirms Permissions saved briefly before dismissing the bar. |
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Roles and permissions" | Heading and accessible section name. |
description | string— | Supporting line below the heading. Pass an empty string (or null in React) to hide it. |
roles | RbacRole[]Default: [{"id":"owner","name":"Owner","description":"Emma Collins","memberCount":1,"locked":true},{"id":"admin","name":"Admin","description":"Jasmine Brooks and 2 others","memberCount":3},{"id":"editor","name":"Editor","description":"Marcus Johnson and 7 others","memberCount":8},{"id":"viewer","name":"Viewer","description":"14 people, including 9 guests","memberCount":14},{"id":"billing","name":"Billing","description":"Sofia Ramirez and 1 other","memberCount":2}] | Role columns in order: id, name, optional description, memberCount, and locked (Owner keeps every permission). Defaults to five sample roles. |
groups | RbacPermissionGroup[]Default: [{"id":"projects","name":"Projects","permissions":[{"id":"view-projects","label":"View projects"},{"id":"create-projects","label":"Create projects"},{"id":"edit-settings","label":"Edit project settings"},{"id":"delete-projects","label":"Delete projects"}]},{"id":"members","name":"Members","permissions":[{"id":"invite","label":"Invite members"},{"id":"change-roles","label":"Change member roles"},{"id":"remove-members","label":"Remove members"}]},{"id":"billing","name":"Billing","permissions":[{"id":"invoices","label":"View invoices"},{"id":"payment","label":"Manage payment methods"},{"id":"plan","label":"Change plan"}]},{"id":"security","name":"Security","permissions":[{"id":"sso","label":"Configure single sign-on"},{"id":"audit-log","label":"View audit log"},{"id":"api-keys","label":"Manage API keys"}]}] | Collapsible permission groups: id, name, and 1 to 50 permissions (id, label, optional description). Defaults to four sample groups. |
defaultGrants | Record<string, string[]>— | Initially granted permissionIds keyed by roleId. Omitted with the sample data, the sample grants apply. Edits do not reset a mounted instance. |
allowDuplicate | booleanDefault: true | Offer Duplicate role in each role menu. Duplicated columns appear beside their source and count as unsaved changes. |
saveAction | string— | Registered host action requested when the user activates Save changes. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | RolesPermissionsThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | RolesPermissionsMotionOptionsDefault: {} | Matrix ripple, column glide, and review bar timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
RbacRoleaccepts{ id, name, description?, memberCount?, locked? }. Role IDs must be unique.RbacPermissionGroupaccepts{ id, name, permissions }, where eachRbacPermissionis{ id, label, description? }. Group IDs and permission IDs must be unique across the matrix.defaultGrantsmapsroleIdto an array of grantedpermissionIds; all referenced role and permission IDs are validated againstrolesandgroups.
React integration
| Prop | Purpose |
|---|---|
description | Also accepts "" or null in React to hide the optional subtitle below the summary line. |
grants | Controlled grant map (Record<string, string[]>). Omit for uncontrolled editing seeded by defaultGrants. |
onGrantsChange(grants) | Called with the updated RbacGrants map on every cell toggle, group toggle, revert, or discard. |
onSave(grants, roles) | Called on Save changes with the live grants and role list (including duplicated roles). Return a Promise to hold the saving phase. |
onAction(action) | Called with saveAction when the user activates Save changes. |
portalContainer | Portal target forwarded to each role header’s dropdown menu. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme, forwarded to the root card and portalled role menus. |
ref, className, style | Applied to the root <section> element. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Tab | Enters or exits the matrix on the single active cell, then moves into the review bar. |
ArrowUp / ArrowDown | Moves focus to the nearest cell in the previous or next visible row. |
ArrowLeft / ArrowRight | Moves focus to the previous or next column in the same row (respects RTL). |
Home / End | Jumps to the first or last interactive control in the current row. |
Ctrl+Home / Ctrl+End | Jumps to the first or last interactive control in the entire grid. |
Enter / Space | Toggles a permission cell, expands/collapses a group, or opens a role column action menu. |
- The matrix uses
role="grid",role="row",role="columnheader",role="rowheader", androle="gridcell"with a single roving tab stop (tabIndex={0}on the active cell,-1on all others). Exiting collapsed groups and deleted columns are markedinertso arrow keys skip them. - Group toggles expose
role="checkbox"witharia-checked="mixed"when partially granted; individual cells exposerole="switch"; locked cells usearia-disabled="true"so keyboard users can inspect them without losing grid navigation. - A pre-mounted polite
role="status"live region announces cell toggles, group ripples, role duplication, reverts, discards, and save outcomes. - Container queries keep permission labels pinned on horizontal scroll and adapt column widths at
760px(200pxlabel /92pxcolumn),540px(148px/80px, hiding group counts and header chevrons), and400px(stacking the review bar summary above full-width actions).
Motion & theming
Toggling a group ripples its cell fills and checkmark strokes downward (waveStepMs), while Discard and Revert changes sweep across affected rows (sweepStepMs, capped at 360ms). Hovering or keyboard-focusing a column glides a subtle crosshair band on the morph spring (420ms), duplicated columns grow horizontally from behind their source on the smooth spring (400ms), and the review bar slides up while rolling change counts (RollingNumber) and crossfading copy (BlurSwap).
Under prefers-reduced-motion: reduce, ripples, column glides, locked-cell nudges, and springs turn off while copy swaps use a 120ms opacity crossfade. Setting motion="none" makes every transition immediate (0ms).
theme accepts mode, accent, and typed tokens across these groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-shadow, --ui-disabled-opacity, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-track, --ui-info, --ui-success, --ui-warning, --ui-tone-foreground, --ui-overlay, --ui-tint-strength |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
selectionControl | --ui-control-on, --ui-control-glyph, --ui-track, --ui-control-track-hover, --ui-control-thumb, --ui-control-thumb-on, --ui-control-fill, --ui-shadow-thumb |
elevation | --ui-shadow-resting, --ui-shadow-raised |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, RolesPermissions is a leaf block. Supply unique role, group, and permission IDs, mark the owner role locked: true, match defaultGrants to those IDs, and wire saveAction to a registered host action. See Building with agents.
{
"type": "RolesPermissions",
"props": {
"title": "Roles and permissions",
"allowDuplicate": true,
"saveAction": "save_workspace_roles"
},
"children": []
}