@b1-road/react 0.1.0-alpha.1 → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,6 +148,77 @@ authkit-react). Plan
|
|
|
148
148
|
[10-react-cookie-mode-spec.md](../../../docs/plans/10-react-cookie-mode-spec.md)
|
|
149
149
|
has the detailed rationale.
|
|
150
150
|
|
|
151
|
+
## Widgets
|
|
152
|
+
|
|
153
|
+
Two drop-in UI widgets ship with the SDK. Both must render inside
|
|
154
|
+
`<RoadProvider>` and inherit your [theming](#theming) from the provider's
|
|
155
|
+
`appearance` prop — no extra wiring. They gate themselves on the user's
|
|
156
|
+
permissions, so you don't guard them with `useCan`.
|
|
157
|
+
|
|
158
|
+
### `<BusinessUnitSwitcher />`
|
|
159
|
+
|
|
160
|
+
A sidebar control that shows the active business unit, switches between the
|
|
161
|
+
user's memberships, surfaces pending invitations (accept / reject inline), and
|
|
162
|
+
links into management and "create unit". Built to sit at the top or bottom of
|
|
163
|
+
an app sidebar.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { BusinessUnitSwitcher } from "@b1-road/react";
|
|
167
|
+
|
|
168
|
+
<aside className="sidebar">
|
|
169
|
+
<BusinessUnitSwitcher />
|
|
170
|
+
</aside>;
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| Prop | Type | Default | Description |
|
|
174
|
+
| --- | --- | --- | --- |
|
|
175
|
+
| `collapsed` | `boolean` | _auto_ | Force the compact icon-only trigger (`true`) or the expanded avatar + name + role trigger (`false`). Left unset, it auto-detects via `ResizeObserver` — under 180px wide it collapses. Pass it when your sidebar's collapse state lives in app state. |
|
|
176
|
+
| `className` | `string` | — | Extra classes on the trigger button (for sidebar layout). |
|
|
177
|
+
|
|
178
|
+
The active BU is read from / written to the provider's business-unit context
|
|
179
|
+
(`useCurrentBusinessUnit` / `useSetCurrentBusinessUnit`), so switching here
|
|
180
|
+
re-scopes every `useCan(buId)` and BU-scoped query across your app.
|
|
181
|
+
|
|
182
|
+
### `<BusinessUnitsMgmt />`
|
|
183
|
+
|
|
184
|
+
A dialog for managing business units and their roles: list / create / edit
|
|
185
|
+
BUs, manage members and invitations, and define roles + permissions (the role
|
|
186
|
+
editor with the permission picker lives here). Two tabs: `"business-units"`
|
|
187
|
+
and `"roles"`.
|
|
188
|
+
|
|
189
|
+
It runs in either **uncontrolled** mode (renders its own trigger) or
|
|
190
|
+
**controlled** mode (you own the open state). The prop types enforce the
|
|
191
|
+
pairing at compile time.
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
import { useState } from "react";
|
|
195
|
+
import { BusinessUnitsMgmt } from "@b1-road/react";
|
|
196
|
+
|
|
197
|
+
// Uncontrolled — renders a default trigger (or pass your own):
|
|
198
|
+
<BusinessUnitsMgmt trigger={<button>Manage units</button>} />;
|
|
199
|
+
|
|
200
|
+
// Controlled — you own the open state:
|
|
201
|
+
function Example() {
|
|
202
|
+
const [open, setOpen] = useState(false);
|
|
203
|
+
return <BusinessUnitsMgmt open={open} onOpenChange={setOpen} />;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
| Prop | Type | Default | Description |
|
|
208
|
+
| --- | --- | --- | --- |
|
|
209
|
+
| `trigger` | `ReactNode` | default button | _(uncontrolled only)_ element that opens the dialog. |
|
|
210
|
+
| `open` | `boolean` | — | _(controlled only)_ open state; must be paired with `onOpenChange`. |
|
|
211
|
+
| `onOpenChange` | `(open: boolean) => void` | — | _(controlled only)_ open-state callback. |
|
|
212
|
+
| `initialTab` | `"business-units" \| "roles"` | `"business-units"` | Tab shown each time the dialog opens. |
|
|
213
|
+
| `initialBusinessUnitId` | `string` | — | Deep-link: open straight into this BU's detail view. |
|
|
214
|
+
|
|
215
|
+
> `trigger` and the `open`/`onOpenChange` pair are mutually exclusive —
|
|
216
|
+
> passing `open` without `onOpenChange`, or mixing in `trigger`, is a
|
|
217
|
+
> compile-time type error.
|
|
218
|
+
|
|
219
|
+
`BusinessUnitSwitcher` already embeds this dialog for its manage/settings
|
|
220
|
+
entry, so adding the switcher often covers both.
|
|
221
|
+
|
|
151
222
|
## Permission-gated UI
|
|
152
223
|
|
|
153
224
|
Widgets gate themselves. For your own UI, `useCan(buId)` returns a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b1-road/react",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official React toolkit for integrating with Road — components, hooks, and helpers for embedding Road IAM into platform apps.",
|
|
6
6
|
"main": "./dist/index.cjs",
|