@tailor-platform/app-shell 1.14.0 → 1.16.0
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/LICENSE.md +21 -0
- package/dist/app-shell-core.css +1 -1
- package/dist/app-shell.d.ts +1203 -316
- package/dist/app-shell.js +4562 -3307
- package/dist/{appshell-CtS8Y3LW.js → appshell-B0wh5Lq0.js} +850 -549
- package/dist/style-entry.d.ts +118 -98
- package/dist/testing.d.ts +118 -98
- package/dist/testing.js +1 -1
- package/dist/themes/_template.css +1 -1
- package/dist/vite-plugin.d.ts +118 -98
- package/package.json +13 -13
- package/skills/app-shell-patterns/SKILL.md +108 -24
- package/skills/app-shell-patterns/references/api/create-ai-gateway-client.md +115 -0
- package/skills/app-shell-patterns/references/api/create-typed-paths.md +117 -0
- package/skills/app-shell-patterns/references/api/define-i18n-labels.md +143 -0
- package/skills/app-shell-patterns/references/api/define-module.md +247 -0
- package/skills/app-shell-patterns/references/api/define-resource.md +307 -0
- package/skills/app-shell-patterns/references/api/guards/hidden.md +202 -0
- package/skills/app-shell-patterns/references/api/guards/overview.md +354 -0
- package/skills/app-shell-patterns/references/api/guards/pass.md +129 -0
- package/skills/app-shell-patterns/references/api/guards/redirect-to.md +307 -0
- package/skills/app-shell-patterns/references/api/router/use-location.md +240 -0
- package/skills/app-shell-patterns/references/api/router/use-navigate.md +138 -0
- package/skills/app-shell-patterns/references/api/router/use-params.md +218 -0
- package/skills/app-shell-patterns/references/api/use-ai-chat.md +110 -0
- package/skills/app-shell-patterns/references/api/use-app-shell-config.md +126 -0
- package/skills/app-shell-patterns/references/api/use-app-shell-data.md +146 -0
- package/skills/app-shell-patterns/references/api/use-app-shell.md +143 -0
- package/skills/app-shell-patterns/references/api/use-auth.md +145 -0
- package/skills/app-shell-patterns/references/api/use-override-breadcrumb.md +74 -0
- package/skills/app-shell-patterns/references/api/use-page-meta.md +96 -0
- package/skills/app-shell-patterns/references/api/use-register-command-palette-actions.md +90 -0
- package/skills/app-shell-patterns/references/api/use-resolved-locale.md +67 -0
- package/skills/app-shell-patterns/references/api/use-route-error.md +214 -0
- package/skills/app-shell-patterns/references/api/use-theme.md +108 -0
- package/skills/app-shell-patterns/references/api/use-time-zone.md +80 -0
- package/skills/app-shell-patterns/references/api/use-toast.md +107 -0
- package/skills/app-shell-patterns/references/components/action-panel.md +168 -0
- package/skills/app-shell-patterns/references/components/activity-card.md +142 -0
- package/skills/app-shell-patterns/references/components/ai-chat.md +315 -0
- package/skills/app-shell-patterns/references/components/alert.md +202 -0
- package/skills/app-shell-patterns/references/components/app-shell.md +530 -0
- package/skills/app-shell-patterns/references/components/appearance-switcher.md +87 -0
- package/skills/app-shell-patterns/references/components/attachment.md +138 -0
- package/skills/app-shell-patterns/references/components/autocomplete.md +278 -0
- package/skills/app-shell-patterns/references/components/avatar.md +80 -0
- package/skills/app-shell-patterns/references/components/badge.md +309 -0
- package/skills/app-shell-patterns/references/components/button.md +164 -0
- package/skills/app-shell-patterns/references/components/card.md +109 -0
- package/skills/app-shell-patterns/references/components/checkbox.md +169 -0
- package/skills/app-shell-patterns/references/components/combobox.md +318 -0
- package/skills/app-shell-patterns/references/components/command-palette.md +413 -0
- package/skills/app-shell-patterns/references/components/csv-importer.md +214 -0
- package/skills/app-shell-patterns/references/components/data-table.md +953 -0
- package/skills/app-shell-patterns/references/components/date-picker.md +248 -0
- package/skills/app-shell-patterns/references/components/default-header.md +75 -0
- package/skills/app-shell-patterns/references/components/default-sidebar.md +136 -0
- package/skills/app-shell-patterns/references/components/description-card.md +569 -0
- package/skills/app-shell-patterns/references/components/dialog.md +164 -0
- package/skills/app-shell-patterns/references/components/document-progress-card.md +154 -0
- package/skills/app-shell-patterns/references/components/form.md +378 -0
- package/skills/app-shell-patterns/references/components/global-header-layout.md +132 -0
- package/skills/app-shell-patterns/references/components/grid.md +184 -0
- package/skills/app-shell-patterns/references/components/input.md +83 -0
- package/skills/app-shell-patterns/references/components/layout.md +539 -0
- package/skills/app-shell-patterns/references/components/menu.md +218 -0
- package/skills/app-shell-patterns/references/components/metric-card.md +94 -0
- package/skills/app-shell-patterns/references/components/select.md +283 -0
- package/skills/app-shell-patterns/references/components/sheet.md +237 -0
- package/skills/app-shell-patterns/references/components/sidebar-group.md +466 -0
- package/skills/app-shell-patterns/references/components/sidebar-item.md +458 -0
- package/skills/app-shell-patterns/references/components/sidebar-layout.md +258 -0
- package/skills/app-shell-patterns/references/components/spinner.md +81 -0
- package/skills/app-shell-patterns/references/components/table.md +188 -0
- package/skills/app-shell-patterns/references/components/tabs.md +158 -0
- package/skills/app-shell-patterns/references/components/textarea.md +122 -0
- package/skills/app-shell-patterns/references/components/timeline.md +317 -0
- package/skills/app-shell-patterns/references/components/toolbar.md +138 -0
- package/skills/app-shell-patterns/references/components/tooltip.md +144 -0
- package/skills/app-shell-patterns/references/components/with-guard.md +445 -0
- package/skills/app-shell-patterns/references/concepts/authentication.md +301 -0
- package/skills/app-shell-patterns/references/concepts/custom-components.md +59 -0
- package/skills/app-shell-patterns/references/concepts/file-based-routing.md +350 -0
- package/skills/app-shell-patterns/references/{fundamental → concepts}/graphql.md +11 -4
- package/skills/app-shell-patterns/references/concepts/modules-and-resources.md +229 -0
- package/skills/app-shell-patterns/references/concepts/routing-navigation.md +387 -0
- package/skills/app-shell-patterns/references/concepts/sidebar-navigation.md +388 -0
- package/skills/app-shell-patterns/references/{fundamental/design-system.md → concepts/styling-theming.md} +260 -105
- package/skills/app-shell-patterns/references/migrations.md +34 -0
- package/skills/app-shell-patterns/references/pages/document-detail.md +1125 -0
- package/skills/app-shell-patterns/references/patterns/form-composer.md +44 -46
- package/skills/app-shell-patterns/references/patterns/form-modal.md +39 -100
- package/skills/app-shell-patterns/references/patterns/form-sectioned.md +12 -38
- package/skills/app-shell-patterns/references/patterns/form-single-page.md +11 -32
- package/skills/app-shell-patterns/references/patterns/form-wizard.md +12 -53
- package/skills/app-shell-patterns/references/patterns/interaction-confirm.md +11 -27
- package/skills/app-shell-patterns/references/patterns/interaction-multi-select.md +14 -28
- package/skills/app-shell-patterns/references/patterns/interaction-toast.md +10 -34
- package/skills/app-shell-patterns/references/patterns/list-dense-scan.md +11 -86
- package/skills/app-shell-patterns/references/fundamental/components.md +0 -981
- package/skills/app-shell-patterns/references/patterns/detail-hero-with-actions.md +0 -201
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useParams
|
|
3
|
+
description: Hook to access dynamic route parameters
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/router/use-params.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useParams
|
|
9
|
+
|
|
10
|
+
React Router hook to access dynamic route parameters from the URL. Re-exported from `react-router` for convenience.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useParams: <T extends Record<string, string>>() => T;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Access Single Parameter
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { useParams } from "@tailor-platform/app-shell";
|
|
24
|
+
|
|
25
|
+
// Route: /products/:id
|
|
26
|
+
function ProductDetail() {
|
|
27
|
+
const { id } = useParams();
|
|
28
|
+
|
|
29
|
+
return <div>Product ID: {id}</div>;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Multiple Parameters
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Route: /categories/:category/products/:id
|
|
37
|
+
function ProductInCategory() {
|
|
38
|
+
const { category, id } = useParams();
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
Category: {category}
|
|
43
|
+
<br />
|
|
44
|
+
Product ID: {id}
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### With Data Fetching
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
function OrderDetail() {
|
|
54
|
+
const { id } = useParams();
|
|
55
|
+
const [order, setOrder] = useState(null);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
fetch(`/api/orders/${id}`)
|
|
59
|
+
.then(r => r.json())
|
|
60
|
+
.then(setOrder);
|
|
61
|
+
}, [id]);
|
|
62
|
+
|
|
63
|
+
return <div>Order #{id}</div>;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### TypeScript with Type Safety
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { useParams } from "@tailor-platform/app-shell";
|
|
71
|
+
|
|
72
|
+
interface ProductParams {
|
|
73
|
+
id: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function ProductDetail() {
|
|
77
|
+
const { id } = useParams<ProductParams>();
|
|
78
|
+
// ^ type: string
|
|
79
|
+
|
|
80
|
+
return <div>Product {id}</div>;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Route Definition
|
|
85
|
+
|
|
86
|
+
Parameters are defined in `defineResource` using `:param` syntax:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { defineModule, defineResource } from "@tailor-platform/app-shell";
|
|
90
|
+
|
|
91
|
+
const productsModule = defineModule({
|
|
92
|
+
path: "products",
|
|
93
|
+
component: ProductsList,
|
|
94
|
+
resources: [
|
|
95
|
+
defineResource({
|
|
96
|
+
path: ":id", // ← Dynamic parameter
|
|
97
|
+
component: () => {
|
|
98
|
+
const { id } = useParams(); // Access here
|
|
99
|
+
return <div>Product {id}</div>;
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Nested Parameters
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
const ordersModule = defineModule({
|
|
110
|
+
path: "orders",
|
|
111
|
+
component: OrdersList,
|
|
112
|
+
resources: [
|
|
113
|
+
defineResource({
|
|
114
|
+
path: ":orderId",
|
|
115
|
+
component: OrderDetail,
|
|
116
|
+
subResources: [
|
|
117
|
+
defineResource({
|
|
118
|
+
path: "items/:itemId",
|
|
119
|
+
component: () => {
|
|
120
|
+
const { orderId, itemId } = useParams();
|
|
121
|
+
return <div>Order {orderId}, Item {itemId}</div>;
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
],
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// URL: /orders/123/items/456
|
|
130
|
+
// useParams() returns: { orderId: "123", itemId: "456" }
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Important Notes
|
|
134
|
+
|
|
135
|
+
### Always Import from AppShell
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// ✅ Correct
|
|
139
|
+
import { useParams } from "@tailor-platform/app-shell";
|
|
140
|
+
|
|
141
|
+
// ❌ Wrong - won't work with AppShell's router
|
|
142
|
+
import { useParams } from "react-router";
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Parameters are Always Strings
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const { id } = useParams();
|
|
149
|
+
// id is always a string, even for numeric IDs
|
|
150
|
+
|
|
151
|
+
// Convert if needed:
|
|
152
|
+
const numericId = parseInt(id, 10);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Optional Parameters
|
|
156
|
+
|
|
157
|
+
For optional parameters, check for undefined:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const { filter } = useParams();
|
|
161
|
+
|
|
162
|
+
if (filter) {
|
|
163
|
+
// Filter is provided
|
|
164
|
+
} else {
|
|
165
|
+
// Filter is optional and not provided
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Examples
|
|
170
|
+
|
|
171
|
+
### Edit Page
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// Route: /products/:id/edit
|
|
175
|
+
function ProductEdit() {
|
|
176
|
+
const { id } = useParams();
|
|
177
|
+
const [product, setProduct] = useState(null);
|
|
178
|
+
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
loadProduct(id).then(setProduct);
|
|
181
|
+
}, [id]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<form>
|
|
185
|
+
<h1>Edit Product {id}</h1>
|
|
186
|
+
{/* form fields */}
|
|
187
|
+
</form>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Delete Confirmation
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
function DeleteConfirmation() {
|
|
196
|
+
const { id } = useParams();
|
|
197
|
+
const navigate = useNavigate();
|
|
198
|
+
|
|
199
|
+
const handleDelete = async () => {
|
|
200
|
+
await deleteProduct(id);
|
|
201
|
+
navigate("/products");
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<div>
|
|
206
|
+
<p>Delete product {id}?</p>
|
|
207
|
+
<button onClick={handleDelete}>Confirm</button>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Related
|
|
214
|
+
|
|
215
|
+
- [useNavigate](./use-navigate.md) - Programmatic navigation
|
|
216
|
+
- [useLocation](./use-location.md) - Access current location
|
|
217
|
+
- [defineResource](../define-resource.md) - Define routes with parameters
|
|
218
|
+
- [Routing & Navigation](../../concepts/routing-navigation.md) - Navigation guide
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useAIChat
|
|
3
|
+
description: Simple text-only chat hook for AI Gateway
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-ai-chat.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useAIChat
|
|
9
|
+
|
|
10
|
+
React hook for simple text-only chat on top of `createAIGatewayClient`.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useAIChat: (config: { client: AIGatewayClient; model: string }) => {
|
|
16
|
+
messages: AIChatMessage[];
|
|
17
|
+
status: "ready" | "submitted" | "streaming" | "error";
|
|
18
|
+
error?: Error;
|
|
19
|
+
sendMessage: (message: string) => Promise<boolean>;
|
|
20
|
+
stop: () => void;
|
|
21
|
+
};
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Return Value
|
|
25
|
+
|
|
26
|
+
### `messages`
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
interface AIChatMessage {
|
|
30
|
+
id: string;
|
|
31
|
+
role: "user" | "assistant";
|
|
32
|
+
content: string;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### `status`
|
|
37
|
+
|
|
38
|
+
- **Type:** `"ready" | "submitted" | "streaming" | "error"`
|
|
39
|
+
- **Description:** Current request state
|
|
40
|
+
|
|
41
|
+
### `error`
|
|
42
|
+
|
|
43
|
+
- **Type:** `Error | undefined`
|
|
44
|
+
- **Description:** Last request error, if any
|
|
45
|
+
|
|
46
|
+
### `sendMessage()`
|
|
47
|
+
|
|
48
|
+
- **Type:** `(message: string) => Promise<boolean>`
|
|
49
|
+
- **Description:** Appends a user message and streams the assistant response
|
|
50
|
+
- **Returns:** `true` when the request completes successfully, `false` when the call is ignored, stopped, or fails
|
|
51
|
+
|
|
52
|
+
### `stop()`
|
|
53
|
+
|
|
54
|
+
- **Type:** `() => void`
|
|
55
|
+
- **Description:** Aborts the current request if one is in progress
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { createAuthClient, createAIGatewayClient, useAIChat } from "@tailor-platform/app-shell";
|
|
61
|
+
|
|
62
|
+
const authClient = createAuthClient({
|
|
63
|
+
clientId: "your-client-id",
|
|
64
|
+
appUri: "https://xyz.erp.dev",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const aiClient = createAIGatewayClient({
|
|
68
|
+
gatewayUri: "https://your-ai-gateway.example.com",
|
|
69
|
+
authClient,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export function ChatScreen() {
|
|
73
|
+
const { messages, sendMessage, status, stop, error } = useAIChat({
|
|
74
|
+
client: aiClient,
|
|
75
|
+
model: "gpt-5-mini",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
{messages.map((message) => (
|
|
81
|
+
<div key={message.id}>
|
|
82
|
+
{message.role}: {message.content}
|
|
83
|
+
</div>
|
|
84
|
+
))}
|
|
85
|
+
|
|
86
|
+
<button
|
|
87
|
+
onClick={() => void sendMessage("Hello")}
|
|
88
|
+
disabled={status === "submitted" || status === "streaming"}
|
|
89
|
+
>
|
|
90
|
+
Send
|
|
91
|
+
</button>
|
|
92
|
+
<button onClick={stop} disabled={status !== "submitted" && status !== "streaming"}>
|
|
93
|
+
Stop
|
|
94
|
+
</button>
|
|
95
|
+
{error ? <div>{error.message}</div> : null}
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Notes
|
|
102
|
+
|
|
103
|
+
- AppShell chooses the appropriate AI Gateway transport automatically
|
|
104
|
+
- The hook is intentionally text-only
|
|
105
|
+
- System prompts and custom history shaping should use the low-level client directly
|
|
106
|
+
- `stop()` keeps any already-streamed assistant text and ignores late chunks from the stopped request
|
|
107
|
+
|
|
108
|
+
## Related
|
|
109
|
+
|
|
110
|
+
- [createAIGatewayClient](./create-ai-gateway-client.md)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useAppShellConfig
|
|
3
|
+
description: Hook to access AppShell configuration data
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-app-shell-config.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useAppShellConfig
|
|
9
|
+
|
|
10
|
+
React hook to access only the AppShell configuration (title, icon, basePath, modules, settingsResources). This is a lighter alternative to `useAppShell` when you only need configuration data.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useAppShellConfig: () => AppShellConfig;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Return Value
|
|
19
|
+
|
|
20
|
+
| Property | Type | Description |
|
|
21
|
+
| ------------------- | ------------------------------ | ------------------------------------------------ |
|
|
22
|
+
| `title` | `string \| undefined` | App title |
|
|
23
|
+
| `icon` | `React.ReactNode \| undefined` | App icon |
|
|
24
|
+
| `basePath` | `string \| undefined` | Base path for all routes |
|
|
25
|
+
| `modules` | `Module[]` | Registered modules |
|
|
26
|
+
| `settingsResources` | `Resource[]` | Resources that appear only in Settings menu |
|
|
27
|
+
| `appInfo` | `AppInfo \| undefined` | Configuration for the built-in `/__appinfo` page |
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Display App Info
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { useAppShellConfig } from "@tailor-platform/app-shell";
|
|
35
|
+
|
|
36
|
+
function AppInfo() {
|
|
37
|
+
const { title, basePath } = useAppShellConfig();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div>
|
|
41
|
+
<h2>{title}</h2>
|
|
42
|
+
<p>Base: {basePath}</p>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Access Modules
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
function ModuleList() {
|
|
52
|
+
const { modules } = useAppShellConfig();
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<ul>
|
|
56
|
+
{modules.map((module) => (
|
|
57
|
+
<li key={module.path}>{module.meta?.title}</li>
|
|
58
|
+
))}
|
|
59
|
+
</ul>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Build Custom Navigation
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
function CustomNav() {
|
|
68
|
+
const { modules } = useAppShellConfig();
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<nav>
|
|
72
|
+
{modules.map((module) => (
|
|
73
|
+
<a key={module.path} href={`/${module.path}`}>
|
|
74
|
+
{module.meta?.title}
|
|
75
|
+
</a>
|
|
76
|
+
))}
|
|
77
|
+
</nav>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Settings Resources
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
function SettingsMenu() {
|
|
86
|
+
const { settingsResources } = useAppShellConfig();
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div>
|
|
90
|
+
<h3>Settings</h3>
|
|
91
|
+
{settingsResources.map((resource) => (
|
|
92
|
+
<button key={resource.path}>
|
|
93
|
+
{resource.meta?.title}
|
|
94
|
+
</button>
|
|
95
|
+
))}
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## When to Use
|
|
102
|
+
|
|
103
|
+
Use `useAppShellConfig` when you only need configuration data:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// ✅ Good - only need config
|
|
107
|
+
const { modules } = useAppShellConfig();
|
|
108
|
+
|
|
109
|
+
// ❌ Overkill - useAppShell returns more data
|
|
110
|
+
const { configurations } = useAppShell();
|
|
111
|
+
const modules = configurations.modules;
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Comparison with Other Hooks
|
|
115
|
+
|
|
116
|
+
| Hook | Returns | Use When |
|
|
117
|
+
| ------------------- | --------------------- | ------------------- |
|
|
118
|
+
| `useAppShellConfig` | Configuration only | Need config data |
|
|
119
|
+
| `useAppShellData` | Context data only | Need custom context |
|
|
120
|
+
| `useAppShell` | Both config + context | Need both |
|
|
121
|
+
|
|
122
|
+
## Related
|
|
123
|
+
|
|
124
|
+
- [useAppShell](./use-app-shell.md) - Full context access
|
|
125
|
+
- [useAppShellData](./use-app-shell-data.md) - Context data only
|
|
126
|
+
- [AppShell Component](../components/app-shell.md) - Root component
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useAppShellData
|
|
3
|
+
description: Hook to access custom context data passed to AppShell
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-app-shell-data.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useAppShellData
|
|
9
|
+
|
|
10
|
+
React hook to access only the custom context data. This is a lighter alternative to `useAppShell` when you only need the contextData.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useAppShellData: () => ContextData;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Return Value
|
|
19
|
+
|
|
20
|
+
| Type | Description |
|
|
21
|
+
| ------------- | ------------------------------------------------------------------------- |
|
|
22
|
+
| `ContextData` | Custom context data passed to AppShell (type-safe via `AppShellRegister`) |
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Basic Access
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { useAppShellData } from "@tailor-platform/app-shell";
|
|
30
|
+
|
|
31
|
+
function UserProfile() {
|
|
32
|
+
const contextData = useAppShellData();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div>
|
|
36
|
+
<p>Welcome, {contextData.currentUser?.name}</p>
|
|
37
|
+
<p>Role: {contextData.currentUser?.role}</p>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Display User Info
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
function UserInfo() {
|
|
47
|
+
const data = useAppShellData();
|
|
48
|
+
|
|
49
|
+
if (!data.currentUser) {
|
|
50
|
+
return <div>Not logged in</div>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div>
|
|
55
|
+
<h2>{data.currentUser.name}</h2>
|
|
56
|
+
<p>{data.currentUser.email}</p>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Check Permissions
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
function AdminPanel() {
|
|
66
|
+
const { permissions } = useAppShellData();
|
|
67
|
+
const canManageUsers = permissions.includes("users:manage");
|
|
68
|
+
|
|
69
|
+
if (!canManageUsers) {
|
|
70
|
+
return <AccessDenied />;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return <UserManagement />;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Feature Flags
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
function BetaFeature() {
|
|
81
|
+
const { featureFlags } = useAppShellData();
|
|
82
|
+
|
|
83
|
+
if (!featureFlags?.newEditor) {
|
|
84
|
+
return <LegacyEditor />;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return <NewEditor />;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Type Safety
|
|
92
|
+
|
|
93
|
+
Define your context type with module augmentation:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// types.d.ts
|
|
97
|
+
declare module "@tailor-platform/app-shell" {
|
|
98
|
+
interface AppShellRegister {
|
|
99
|
+
contextData: {
|
|
100
|
+
currentUser: User | null;
|
|
101
|
+
permissions: string[];
|
|
102
|
+
tenantId: string;
|
|
103
|
+
featureFlags: {
|
|
104
|
+
newEditor: boolean;
|
|
105
|
+
betaDashboard: boolean;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Now `useAppShellData()` returns fully typed data:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
const data = useAppShellData();
|
|
116
|
+
data.currentUser; // Type: User | null
|
|
117
|
+
data.permissions; // Type: string[]
|
|
118
|
+
data.featureFlags; // Type: { newEditor: boolean, betaDashboard: boolean }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## When to Use
|
|
122
|
+
|
|
123
|
+
Use `useAppShellData` when you only need context data:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// ✅ Good - only need context
|
|
127
|
+
const data = useAppShellData();
|
|
128
|
+
|
|
129
|
+
// ❌ Overkill - useAppShell returns more than needed
|
|
130
|
+
const { context } = useAppShell();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Comparison with Other Hooks
|
|
134
|
+
|
|
135
|
+
| Hook | Returns | Use When |
|
|
136
|
+
| ------------------- | --------------------- | ------------------- |
|
|
137
|
+
| `useAppShellData` | Context data only | Need custom context |
|
|
138
|
+
| `useAppShellConfig` | Configuration only | Need config data |
|
|
139
|
+
| `useAppShell` | Both config + context | Need both |
|
|
140
|
+
|
|
141
|
+
## Related
|
|
142
|
+
|
|
143
|
+
- [useAppShell](./use-app-shell.md) - Full context access
|
|
144
|
+
- [useAppShellConfig](./use-app-shell-config.md) - Configuration only
|
|
145
|
+
- [AppShell Component](../components/app-shell.md) - Root component
|
|
146
|
+
- [Guards Overview](./guards/overview.md) - Using context in guards
|