diff --git a/src/collections/sistent/components/permission/code.mdx b/src/collections/sistent/components/permission/code.mdx new file mode 100644 index 00000000000000..6945d22132ddba --- /dev/null +++ b/src/collections/sistent/components/permission/code.mdx @@ -0,0 +1,173 @@ +--- +title: Permission Code +component: permission +description: Integration details, code examples, and API references for the PermissionShield component. +--- + +import { PermissionShield, Button, PermissionSessionContext } from "@sistent/sistent"; + +The `PermissionShield` component acts as a high-level wrapper to restrict and decorate interactive components. + +> **Important Security Note:** UI gating is a presentation-layer control only. Client-side checks must not decide access. The backend server and API routes must always enforce authorization on every request. + + +

Installation

+
+ +```bash +npm install @sistent/sistent +``` + + +

Basic Usage

+
+ +Wrap any standard component (e.g., a `Button`) inside the `PermissionShield` to automatically overlay the lock badge when permissions are restricted. + +
+
+ + + + + +
+ ( + + + +);`} /> +
+ + +

Custom Boundary Padding

+
+ +Use the `boundaryPadding` prop to configure custom offsets if the tooltip overlaps fixed elements (like headers, sidebars, or navbar sections) during scrolling. + +
+
+ + + + + +
+ ( + + + +);`} /> +
+ + +

Permission Session Context

+
+ +Use `PermissionSessionContext` to embed permission details directly inside custom components or full-page 403 authorization layouts without utilizing tooltips. + +
+
+ +
+ +
+
+
+ ( +
+

Access Denied

+ +
+);`} /> +
+ + +

API Reference

+
+ +

PermissionShield Props

+ +| Name | Type | Default | Description | +| :--- | :--- | :--- | :--- | +| `permissionKey` | `PermissionKeySpec` | - | The unique key specification that the gated action requires. | +| `children` | `React.ReactNode` | - | The gated component (e.g., Button, IconButton) to be wrapped. | +| `variant` | `'inline' \| 'badge'` | `'inline'` | The display format of the lock badge. `'inline'` renders the lock icon at the center-right (end adornment), `'badge'` renders it overlaying the bottom-left corner. | +| `boundaryPadding` | `object` | `{ top: 85, left: 16, right: 8, bottom: 8 }` | Optional offsets to prevent tooltips from overlapping headers/menus. The default is responsive: `{ top: 64, left: 8, right: 8, bottom: 8 }` on mobile and `{ top: 85, left: 16, right: 8, bottom: 8 }` on desktop. | + +

PermissionSessionContext Props

+ +| Name | Type | Default | Description | +| :--- | :--- | :--- | :--- | +| `variant` | `'tooltip' \| 'card'` | `'tooltip'` | The layout style for the session context. `'tooltip'` uses compact dark-themed styling, while `'card'` provides theme-aware, scaled-up styling for full-page or card display. | +| `permissionKey` | `PermissionKeySpec` | - | Optional. When supplied, the component resolves the unmet keys, subcategories, and description automatically. | +| `displayedKeys` | `Key[]` | - | Optional. Pre-resolved array of permission keys to display details for when manual key resolution is preferred. | +| `subtitle` | `string` | - | Optional. Pre-resolved subtitle (e.g. "Needs any of: ...") to display below the title. | +| `categories` | `string[]` | - | Optional. Pre-resolved category labels to display as chips. | +| `subcategories` | `string[]` | - | Optional. Pre-resolved subcategory labels to display as chips. | diff --git a/src/collections/sistent/components/permission/guidance.mdx b/src/collections/sistent/components/permission/guidance.mdx new file mode 100644 index 00000000000000..86580fd8aaab5a --- /dev/null +++ b/src/collections/sistent/components/permission/guidance.mdx @@ -0,0 +1,65 @@ +--- +title: Permission Guidance +component: permission +description: Guidance on using the Sistent Permission component and best practices for design system gating. +--- + + +

Usage

+
+ +The `PermissionShield` component should be used to protect actions or affordances that require specific roles, permission keys, or capabilities. + +> **Important Security Note:** UI gating is a presentation-layer control only. Client-side checks must not decide access. The backend server and API routes must always enforce authorization on every request. + + + + +

When to Use

+
+ +

Disable versus Hide

+ +When deciding whether to restrict a feature, follow these design system guidelines: + + + +

Tooltip versus Card Layouts

+ +When displaying permission details using `PermissionSessionContext`, choose the variant based on the integration context: + + + + +

Best Practices

+
+ + diff --git a/src/collections/sistent/components/permission/index.mdx b/src/collections/sistent/components/permission/index.mdx new file mode 100644 index 00000000000000..20a61e34374e4a --- /dev/null +++ b/src/collections/sistent/components/permission/index.mdx @@ -0,0 +1,112 @@ +--- +name: "Permission" +title: "Permission" +published: true +component: permission +description: The PermissionShield component gates and protects interactive actions, buttons, and navigation elements. It displays a visual lock icon overlay or inline badge when a user lacks the necessary permission keys or capabilities. +--- + +import { PermissionShield, Button, PermissionSessionContext } from "@sistent/sistent"; + +The `PermissionShield` component provides a standard design pattern for feature-level permission gating across applications. Rather than silently hiding disabled elements, it keeps them visible (preserving layout continuity) and overlays a visual lock indicator to explain to users why the action is restricted. + +> **Important Security Note:** UI gating is a presentation-layer control only. Client-side checks must not decide access. The backend server and API routes must always enforce authorization on every request. + + +

Inline Shield Overlay

+
+ +The default variant (`'inline'`) wraps any standard action component (like a `Button` or `IconButton`) and places a lock icon badge at the center-right of the target element (serving as an end adornment). When clicked, it shows a detailed explanation of the missing permission. + + + +
+ + + +
+
+
+ + +

Badge Variant

+
+ +The badge variant (`'badge'`) renders the permission badge overlaying the bottom-left corner of the target element. This is useful for list items, settings tables, or static text where placing the shield as an end-adornment on the right is not suitable. + + + +
+ + Audit Logs + +
+
+
+ + +

Permission Session Context

+
+ +The `PermissionSessionContext` component renders the detailed authorization metadata (user identity, organization, assigned roles, and missing keys) that is displayed inside tooltips or cards. It supports two layout variants: + +- **Tooltip Variant (`'tooltip'`):** A compact layout designed to fit inside standard hover/click tooltips (used by default inside `PermissionShield`). +- **Card Variant (`'card'`):** A theme-aware, scaled-up layout designed to be embedded directly into custom cards, sidebars, or full-page 403/Forbidden error screens. + +### Tooltip Layout + + + +
+ +
+
+
+ +### Card Layout + + + +
+ +
+
+
+