UI

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

Permission
View projects
Create projects
Edit project settings
Delete projects
Invite members
Change member roles
Remove members
View invoices
Manage payment methods
Change plan
Configure single sign-on
View audit log
Manage API keys
Locked roles always have every permissionUnsaved change

Loading interactive preview…

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.

Permission
Push feature branchesCreate and update non-protected branches
Merge to mainApprove and merge pull requests after CI passes
Edit branch protectionModify required reviewers and status checks
Deploy preview buildsTrigger staging environments for pull requests
Promote to productionShip verified builds to customer traffic
Rollback productionRevert active traffic to a previous release
Locked roles always have every permissionUnsaved change

Matrix controls and review workflow

Column and cell states

ControlRole / stateBehavior
Role column menuDropdownMenuOpens Duplicate role, Revert changes (when dirty), and Delete role (custom roles).
Group togglerole="checkbox" (true / mixed / false)Toggles every permission in the group with a staggered downward wave ripple.
Permission cellrole="switch" (true / false)Flips one grant and places an unsaved warning dot beside modified cells.
Locked role cellaria-disabled="true"Always granted; pressing nudges the box gently and announces that permissions are fixed.

Sticky review bar

StateTriggerActions
HiddenZero unsaved edits and idle phase.Collapses smoothly; restores focus to the active grid cell if the bar held focus.
PendingAny cell toggle, duplicated role, or delete.Shows rolling diff count, affected role names and member count, Discard, and Save changes.
SavingSave changes activated.Locks actions and holds loading state until onSave settles (or local simulation completes).
SavedSave resolves cleanly.Confirms Permissions saved briefly before dismissing the bar.

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
titlestringDefault: "Roles and permissions"Heading and accessible section name.
descriptionstring—Supporting line below the heading. Pass an empty string (or null in React) to hide it.
rolesRbacRole[]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.
groupsRbacPermissionGroup[]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.
defaultGrantsRecord<string, string[]>—Initially granted permissionIds keyed by roleId. Omitted with the sample data, the sample grants apply. Edits do not reset a mounted instance.
allowDuplicatebooleanDefault: trueOffer Duplicate role in each role menu. Duplicated columns appear beside their source and count as unsaved changes.
saveActionstring—Registered host action requested when the user activates Save changes.
recipestudio | softDefault: "studio"Visual treatment. Both recipes preserve interaction behavior.
themeRolesPermissionsThemeDefault: {}Color mode, accent, and typed semantic token overrides.
motionnone | subtle | expressiveDefault: "subtle"Animation preset. System reduced-motion preferences take precedence.
motionOptionsRolesPermissionsMotionOptionsDefault: {}Matrix ripple, column glide, and review bar timing overrides in milliseconds.
dirltr | rtl—Reading direction; inherited from the page when omitted.
  • RbacRole accepts { id, name, description?, memberCount?, locked? }. Role IDs must be unique.
  • RbacPermissionGroup accepts { id, name, permissions }, where each RbacPermission is { id, label, description? }. Group IDs and permission IDs must be unique across the matrix.
  • defaultGrants maps roleId to an array of granted permissionIds; all referenced role and permission IDs are validated against roles and groups.

React integration

PropPurpose
descriptionAlso accepts "" or null in React to hide the optional subtitle below the summary line.
grantsControlled 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.
portalContainerPortal target forwarded to each role header’s dropdown menu.
presetApplication defaults overridden by explicit instance arguments.
tokensCSS variables applied after the typed theme, forwarded to the root card and portalled role menus.
ref, className, styleApplied to the root <section> element.
Native attributesid, aria-*, data-*, and remaining <section> props forwarded to the root element.

Keyboard & accessibility

KeyAction
TabEnters or exits the matrix on the single active cell, then moves into the review bar.
ArrowUp / ArrowDownMoves focus to the nearest cell in the previous or next visible row.
ArrowLeft / ArrowRightMoves focus to the previous or next column in the same row (respects RTL).
Home / EndJumps to the first or last interactive control in the current row.
Ctrl+Home / Ctrl+EndJumps to the first or last interactive control in the entire grid.
Enter / SpaceToggles 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", and role="gridcell" with a single roving tab stop (tabIndex={0} on the active cell, -1 on all others). Exiting collapsed groups and deleted columns are marked inert so arrow keys skip them.
  • Group toggles expose role="checkbox" with aria-checked="mixed" when partially granted; individual cells expose role="switch"; locked cells use aria-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 (200px label / 92px column), 540px (148px / 80px, hiding group counts and header chevrons), and 400px (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 groupCSS 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": []
}

On this page