@tailor-platform/app-shell 1.15.0 → 1.17.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/dist/app-shell-core.css +1 -1
- package/dist/app-shell.d.ts +811 -131
- package/dist/app-shell.js +7155 -5797
- package/dist/{appshell-DLVBFo5J.js → appshell-CahhZy7v.js} +656 -524
- package/dist/semantic-contrast.test.ts +154 -0
- package/dist/style-entry.d.ts +147 -92
- package/dist/testing.d.ts +152 -95
- package/dist/testing.js +1 -1
- package/dist/theme-bridge.test.ts +101 -1
- package/dist/theme.bridge.css +91 -0
- package/dist/theme.css +6 -1
- package/dist/themes/_template.css +7 -1
- package/dist/themes/bloom.css +0 -6
- package/dist/themes/cream.css +0 -6
- package/dist/themes/default.css +389 -69
- package/dist/vite-plugin.d.ts +147 -92
- package/package.json +8 -8
- package/skills/app-shell-patterns/SKILL.md +108 -19
- 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 +132 -0
- package/skills/app-shell-patterns/references/api/use-app-shell-data.md +150 -0
- package/skills/app-shell-patterns/references/api/use-app-shell.md +150 -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 +104 -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 +181 -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 +1168 -0
- package/skills/app-shell-patterns/references/components/date-picker.md +259 -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/filter-rail.md +165 -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 +472 -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/sidebar-section.md +114 -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 +356 -0
- package/skills/app-shell-patterns/references/{fundamental → concepts}/graphql.md +31 -18
- package/skills/app-shell-patterns/references/concepts/modules-and-resources.md +229 -0
- package/skills/app-shell-patterns/references/concepts/routing-navigation.md +425 -0
- package/skills/app-shell-patterns/references/concepts/sidebar-navigation.md +420 -0
- package/skills/app-shell-patterns/references/concepts/styling-theming.md +785 -0
- package/skills/app-shell-patterns/references/migrations.md +55 -0
- package/skills/app-shell-patterns/references/pages/{detail.md → document-detail.md} +10 -33
- package/skills/app-shell-patterns/references/patterns/form-composer.md +43 -45
- package/skills/app-shell-patterns/references/patterns/form-modal.md +37 -92
- 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 +136 -139
- package/skills/app-shell-patterns/references/patterns/interaction-toast.md +10 -34
- package/skills/app-shell-patterns/references/patterns/list-dense-scan.md +13 -88
- package/skills/app-shell-patterns/references/fundamental/components.md +0 -1009
- package/skills/app-shell-patterns/references/fundamental/design-system.md +0 -440
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useAppShell
|
|
3
|
+
description: Hook to access AppShell context data and configuration
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-app-shell.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useAppShell
|
|
9
|
+
|
|
10
|
+
React hook to access AppShell context data and configuration within your components.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useAppShell: () => {
|
|
16
|
+
contextData: ContextData;
|
|
17
|
+
configurations: {
|
|
18
|
+
modules: ReturnType<typeof defineModule>[];
|
|
19
|
+
settingsResources: ReturnType<typeof defineResource>[];
|
|
20
|
+
basePath?: string;
|
|
21
|
+
locale: string;
|
|
22
|
+
resolvedLocale?: string;
|
|
23
|
+
timeZone?: string;
|
|
24
|
+
errorBoundary: ErrorBoundaryComponent;
|
|
25
|
+
};
|
|
26
|
+
title?: string;
|
|
27
|
+
icon?: React.ReactNode;
|
|
28
|
+
favicon?: string;
|
|
29
|
+
appInfo?: AppInfo;
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The hook merges the results of [`useAppShellConfig`](./use-app-shell-config.md) and [`useAppShellData`](./use-app-shell-data.md). Prefer one of those when you only need configuration or only need context data, so the component does not re-render for changes it does not use.
|
|
34
|
+
|
|
35
|
+
## Return Value
|
|
36
|
+
|
|
37
|
+
### `contextData`
|
|
38
|
+
|
|
39
|
+
- **Type:** `ContextData`
|
|
40
|
+
- **Description:** Custom context data passed to AppShell. Same as the `contextData` prop.
|
|
41
|
+
|
|
42
|
+
### `configurations`
|
|
43
|
+
|
|
44
|
+
- **Type:** object
|
|
45
|
+
- **Description:** Resolved AppShell configuration: `modules`, `settingsResources`, `basePath`, `locale`, `resolvedLocale`, `timeZone`, and `errorBoundary`.
|
|
46
|
+
|
|
47
|
+
### `title`, `icon`, `favicon`, `appInfo`
|
|
48
|
+
|
|
49
|
+
- **Description:** The matching AppShell props, as passed.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### Basic Access
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { useAppShell } from "@tailor-platform/app-shell";
|
|
57
|
+
|
|
58
|
+
function MyComponent() {
|
|
59
|
+
const { contextData } = useAppShell();
|
|
60
|
+
|
|
61
|
+
return <div>Welcome, {contextData.currentUser?.name}</div>;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Access Configuration
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
function LocaleDisplay() {
|
|
69
|
+
const { configurations } = useAppShell();
|
|
70
|
+
|
|
71
|
+
return <div>Current locale: {configurations.locale}</div>;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Context Data
|
|
76
|
+
|
|
77
|
+
Define your context type with module augmentation:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// types.d.ts
|
|
81
|
+
type User = { name: string; email: string; role: string };
|
|
82
|
+
|
|
83
|
+
declare module "@tailor-platform/app-shell" {
|
|
84
|
+
interface AppShellRegister {
|
|
85
|
+
contextData: {
|
|
86
|
+
currentUser: User | null;
|
|
87
|
+
permissions: string[];
|
|
88
|
+
tenantId: string;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// App.tsx
|
|
94
|
+
<AppShell
|
|
95
|
+
modules={modules}
|
|
96
|
+
contextData={{
|
|
97
|
+
currentUser,
|
|
98
|
+
permissions,
|
|
99
|
+
tenantId,
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
|
|
103
|
+
// MyComponent.tsx
|
|
104
|
+
const { contextData } = useAppShell();
|
|
105
|
+
contextData.currentUser // Fully typed!
|
|
106
|
+
contextData.permissions // Fully typed!
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Examples
|
|
110
|
+
|
|
111
|
+
### Display User Info
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
function UserInfo() {
|
|
115
|
+
const { contextData } = useAppShell();
|
|
116
|
+
|
|
117
|
+
if (!contextData.currentUser) {
|
|
118
|
+
return <div>Not logged in</div>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div>
|
|
123
|
+
<h2>{contextData.currentUser.name}</h2>
|
|
124
|
+
<p>{contextData.currentUser.email}</p>
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Check Permissions
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
function DeleteButton() {
|
|
134
|
+
const { contextData } = useAppShell();
|
|
135
|
+
const canDelete = contextData.permissions.includes("users:delete");
|
|
136
|
+
|
|
137
|
+
if (!canDelete) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return <Button variant="destructive">Delete</Button>;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Related
|
|
146
|
+
|
|
147
|
+
- [AppShell Component](../components/app-shell.md) - Root component
|
|
148
|
+
- [useAppShellData](./use-app-shell-data.md) - Context data only
|
|
149
|
+
- [useAppShellConfig](./use-app-shell-config.md) - Configuration only
|
|
150
|
+
- [Guards Overview](./guards/overview.md) - Access control using context
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useAuth
|
|
3
|
+
description: Hook for accessing authentication state and methods
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-auth.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useAuth
|
|
9
|
+
|
|
10
|
+
React hook to access authentication state and methods when using `AuthProvider`.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useAuth: () => {
|
|
16
|
+
error: string | null;
|
|
17
|
+
isAuthenticated: boolean;
|
|
18
|
+
isReady: boolean;
|
|
19
|
+
login: () => Promise<void>;
|
|
20
|
+
logout: () => Promise<void>;
|
|
21
|
+
checkAuthStatus: () => Promise<AuthState>;
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Return Value
|
|
26
|
+
|
|
27
|
+
### `error`
|
|
28
|
+
|
|
29
|
+
- **Type:** `string | null`
|
|
30
|
+
- **Description:** Error message if authentication failed
|
|
31
|
+
|
|
32
|
+
### `isAuthenticated`
|
|
33
|
+
|
|
34
|
+
- **Type:** `boolean`
|
|
35
|
+
- **Description:** Whether the user is currently authenticated
|
|
36
|
+
|
|
37
|
+
### `isReady`
|
|
38
|
+
|
|
39
|
+
- **Type:** `boolean`
|
|
40
|
+
- **Description:** Whether the initial auth check has completed. Always check this before rendering authenticated content to avoid flashing unauthenticated state.
|
|
41
|
+
|
|
42
|
+
### `login()`
|
|
43
|
+
|
|
44
|
+
- **Type:** `() => Promise<void>`
|
|
45
|
+
- **Description:** Initiates the login process. Redirects to Tailor Platform authentication page.
|
|
46
|
+
|
|
47
|
+
### `logout()`
|
|
48
|
+
|
|
49
|
+
- **Type:** `() => Promise<void>`
|
|
50
|
+
- **Description:** Logs out the current user. Clears tokens and session.
|
|
51
|
+
|
|
52
|
+
### `checkAuthStatus()`
|
|
53
|
+
|
|
54
|
+
- **Type:** `() => Promise<AuthState>`
|
|
55
|
+
- **Description:** Checks current auth status. Makes network request to verify and refresh tokens if needed.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
### Basic Authentication Flow
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { useAuth } from "@tailor-platform/app-shell";
|
|
63
|
+
|
|
64
|
+
function MyComponent() {
|
|
65
|
+
const { isAuthenticated, isReady, login, logout } = useAuth();
|
|
66
|
+
|
|
67
|
+
if (!isReady) {
|
|
68
|
+
return <div>Loading...</div>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!isAuthenticated) {
|
|
72
|
+
return <button onClick={login}>Log In</button>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<p>You are logged in!</p>
|
|
78
|
+
<button onClick={logout}>Log Out</button>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Protected Content
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
function ProtectedPage() {
|
|
88
|
+
const { isAuthenticated, isReady } = useAuth();
|
|
89
|
+
|
|
90
|
+
if (!isReady) {
|
|
91
|
+
return <Spinner />;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!isAuthenticated) {
|
|
95
|
+
return <LoginPrompt />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return <SecureContent />;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Handle Auth Errors
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
function AuthStatus() {
|
|
106
|
+
const { isAuthenticated, error, login } = useAuth();
|
|
107
|
+
|
|
108
|
+
if (error) {
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
<p>Authentication failed: {error}</p>
|
|
112
|
+
<button onClick={login}>Retry</button>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return <div>Status: {isAuthenticated ? "Logged in" : "Logged out"}</div>;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## With AuthProvider
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { AuthProvider, AppShell, useAuth } from "@tailor-platform/app-shell";
|
|
125
|
+
|
|
126
|
+
function App() {
|
|
127
|
+
return (
|
|
128
|
+
<AuthProvider
|
|
129
|
+
apiEndpoint="https://api.tailor.tech"
|
|
130
|
+
clientId="your-client-id"
|
|
131
|
+
redirectUri="http://localhost:3000/callback"
|
|
132
|
+
autoLogin={true}
|
|
133
|
+
>
|
|
134
|
+
<AppShell modules={modules}>
|
|
135
|
+
<SidebarLayout />
|
|
136
|
+
</AppShell>
|
|
137
|
+
</AuthProvider>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Related
|
|
143
|
+
|
|
144
|
+
- [Authentication Concept](../concepts/authentication.md) - Authentication guide
|
|
145
|
+
- [AuthProvider](../components/app-shell.md) - Auth provider setup
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useOverrideBreadcrumb
|
|
3
|
+
description: Hook for dynamically overriding breadcrumb titles from within page components
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-override-breadcrumb.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useOverrideBreadcrumb
|
|
9
|
+
|
|
10
|
+
React hook to dynamically override the breadcrumb title for the current page. Useful for displaying data-driven titles (e.g., record names fetched from an API) instead of static route-based titles.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function useOverrideBreadcrumb(title: string | undefined): void;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
### `title`
|
|
21
|
+
|
|
22
|
+
- **Type:** `string | undefined`
|
|
23
|
+
- **Required:** Yes
|
|
24
|
+
- **Description:** The title to display in the breadcrumb for the current path. When `undefined`, any previous override is removed and the default title (from `defineResource`) is restored.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### With `defineResource`
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { useOverrideBreadcrumb } from "@tailor-platform/app-shell";
|
|
32
|
+
|
|
33
|
+
defineResource({
|
|
34
|
+
path: ":id",
|
|
35
|
+
component: () => {
|
|
36
|
+
const { id } = useParams();
|
|
37
|
+
const { data } = useQuery(GET_ORDER, { variables: { id } });
|
|
38
|
+
|
|
39
|
+
// Update breadcrumb with the order name
|
|
40
|
+
useOverrideBreadcrumb(data?.order?.name);
|
|
41
|
+
|
|
42
|
+
return <OrderDetail />;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### With file-based routing
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { useOverrideBreadcrumb, useParams } from "@tailor-platform/app-shell";
|
|
51
|
+
|
|
52
|
+
const OrderDetailPage = () => {
|
|
53
|
+
const { id } = useParams();
|
|
54
|
+
const { data } = useQuery(GET_ORDER, { variables: { id } });
|
|
55
|
+
|
|
56
|
+
// Update breadcrumb with the order name
|
|
57
|
+
useOverrideBreadcrumb(data?.order?.name);
|
|
58
|
+
|
|
59
|
+
return <div>...</div>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default OrderDetailPage;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Notes
|
|
66
|
+
|
|
67
|
+
- The hook updates reactively — pass the result of a data-fetching query directly and the breadcrumb updates when the data resolves.
|
|
68
|
+
- When `title` is `undefined` (e.g., while data is loading), the override is cleared and the default title is shown.
|
|
69
|
+
- The override is automatically cleaned up when the component unmounts.
|
|
70
|
+
|
|
71
|
+
## Related
|
|
72
|
+
|
|
73
|
+
- [defineResource](./define-resource.md) - Define routes and their default breadcrumb titles
|
|
74
|
+
- [Routing and Navigation](../concepts/routing-navigation.md) - Overview of breadcrumb behavior
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: usePageMeta
|
|
3
|
+
description: Hook to resolve page metadata from route path
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-page-meta.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# usePageMeta
|
|
9
|
+
|
|
10
|
+
React hook to resolve page metadata (title, icon) from a route path.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const usePageMeta: (path: string) => {
|
|
16
|
+
title: string;
|
|
17
|
+
icon?: React.ReactNode;
|
|
18
|
+
} | null;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### `path`
|
|
24
|
+
|
|
25
|
+
- **Type:** `string`
|
|
26
|
+
- **Required:** Yes
|
|
27
|
+
- **Description:** Route path to look up metadata for
|
|
28
|
+
|
|
29
|
+
## Return Value
|
|
30
|
+
|
|
31
|
+
Returns an object with `title` and optional `icon`, or `null` when the path is external or does not match any AppShell route.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Resolve Title and Icon
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { usePageMeta } from "@tailor-platform/app-shell";
|
|
39
|
+
|
|
40
|
+
function NavigationItem({ path }: { path: string }) {
|
|
41
|
+
const meta = usePageMeta(path);
|
|
42
|
+
|
|
43
|
+
if (!meta) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div>
|
|
49
|
+
{meta.icon}
|
|
50
|
+
<span>{meta.title}</span>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Custom Link Component
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
function CustomLink({ to }: { to: string }) {
|
|
60
|
+
const meta = usePageMeta(to);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<a href={to}>
|
|
64
|
+
{meta?.icon}
|
|
65
|
+
{meta?.title || to}
|
|
66
|
+
</a>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Breadcrumb Builder
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
function Breadcrumb({ paths }: { paths: string[] }) {
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
{paths.map((path) => {
|
|
78
|
+
const meta = usePageMeta(path);
|
|
79
|
+
return <span key={path}>{meta?.title}</span>;
|
|
80
|
+
})}
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Notes
|
|
87
|
+
|
|
88
|
+
- Used internally by `SidebarItem` to auto-resolve titles and icons
|
|
89
|
+
- Returns `null` for external URLs (`http://...` / `https://...`) and for paths that do not match any defined route
|
|
90
|
+
- Resolves from module and resource `meta` properties
|
|
91
|
+
- Prefers literal routes before dynamic siblings, so `/users/new` resolves that route's metadata instead of `/users/:id`
|
|
92
|
+
|
|
93
|
+
## Related
|
|
94
|
+
|
|
95
|
+
- [SidebarItem](../components/sidebar-item.md) - Uses usePageMeta internally
|
|
96
|
+
- [defineModule](./define-module.md) - Define meta.title and meta.icon
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useRegisterCommandPaletteActions
|
|
3
|
+
description: Hook for registering contextual page actions into the CommandPalette
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-register-command-palette-actions.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useRegisterCommandPaletteActions
|
|
9
|
+
|
|
10
|
+
React hook that declaratively registers page-level actions into the CommandPalette's **Actions** section. Actions are searchable and triggerable via the `Cmd+K` / `Ctrl+K` shortcut. They are automatically unregistered when the calling component unmounts.
|
|
11
|
+
|
|
12
|
+
## Import
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import {
|
|
16
|
+
useRegisterCommandPaletteActions,
|
|
17
|
+
type CommandPaletteAction,
|
|
18
|
+
} from "@tailor-platform/app-shell";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Signature
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
function useRegisterCommandPaletteActions(group: string, actions: CommandPaletteAction[]): void;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Parameters
|
|
28
|
+
|
|
29
|
+
| Parameter | Type | Description |
|
|
30
|
+
| --------- | ------------------------ | --------------------------------------------------------- |
|
|
31
|
+
| `group` | `string` | Display group name shown in the palette for these actions |
|
|
32
|
+
| `actions` | `CommandPaletteAction[]` | List of actions to register |
|
|
33
|
+
|
|
34
|
+
## `CommandPaletteAction`
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
type CommandPaletteAction = {
|
|
38
|
+
key: string;
|
|
39
|
+
label: string;
|
|
40
|
+
icon?: ReactNode;
|
|
41
|
+
group?: string;
|
|
42
|
+
onSelect: () => void | Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Property | Type | Description |
|
|
47
|
+
| ---------- | ----------------------------- | ----------------------------------------------------------------------------- |
|
|
48
|
+
| `key` | `string` | Unique key for React reconciliation |
|
|
49
|
+
| `label` | `string` | Visible label shown in the palette; also used for search matching |
|
|
50
|
+
| `icon` | `ReactNode` | Optional icon rendered next to the label |
|
|
51
|
+
| `group` | `string` | Optional group override; defaults to the `group` parameter passed to the hook |
|
|
52
|
+
| `onSelect` | `() => void \| Promise<void>` | Callback invoked when the user selects the action |
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { useRegisterCommandPaletteActions } from "@tailor-platform/app-shell";
|
|
58
|
+
|
|
59
|
+
function OrderDetailPage() {
|
|
60
|
+
const [loading, setLoading] = useState(false);
|
|
61
|
+
|
|
62
|
+
const handleConfirm = async () => {
|
|
63
|
+
setLoading(true);
|
|
64
|
+
try {
|
|
65
|
+
await confirmOrder(orderId);
|
|
66
|
+
} finally {
|
|
67
|
+
setLoading(false);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
useRegisterCommandPaletteActions("Order Actions", [
|
|
72
|
+
{ key: "confirm", label: "Confirm order", onSelect: handleConfirm },
|
|
73
|
+
{ key: "cancel", label: "Cancel order", icon: <XIcon />, onSelect: handleCancel },
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
return <div>{/* page content */}</div>;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Behavior
|
|
81
|
+
|
|
82
|
+
- Actions are registered while the component is mounted and removed on unmount.
|
|
83
|
+
- Re-rendering with a new `actions` array replaces the previously registered set.
|
|
84
|
+
- `icon` changes alone do not trigger re-registration. If you need to reflect a dynamic icon update, also change the action's `key` or `label`.
|
|
85
|
+
- The hook requires `CommandPaletteProvider`, which is mounted automatically by `AppShell`.
|
|
86
|
+
|
|
87
|
+
## Related
|
|
88
|
+
|
|
89
|
+
- [CommandPalette](../components/command-palette.md) — Keyboard-driven navigation and action palette
|
|
90
|
+
- [ActionPanel](../components/action-panel.md) — Automatically uses this hook to expose its actions in the palette
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useResolvedLocale
|
|
3
|
+
description: Hook to access the full BCP-47 locale and language code from AppShell context
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- GENERATED by docs-kit from docs-src/hooks/use-resolved-locale.docs.outline.md — do not edit by hand. -->
|
|
7
|
+
|
|
8
|
+
# useResolvedLocale
|
|
9
|
+
|
|
10
|
+
React hook that returns the full BCP-47 locale (e.g. `"en-GB"`) and the language code (e.g. `"en"`) from the AppShell context. Use this for `Intl` APIs and date formatting that require a specific locale.
|
|
11
|
+
|
|
12
|
+
## Signature
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const useResolvedLocale: () => {
|
|
16
|
+
locale: string;
|
|
17
|
+
language: string;
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Return Value
|
|
22
|
+
|
|
23
|
+
### `locale`
|
|
24
|
+
|
|
25
|
+
- **Type:** `string`
|
|
26
|
+
- **Description:** Full BCP-47 locale tag (e.g. `"en-GB"`, `"ja-JP"`). Sourced from the `locale` prop passed to `AppShell`, or auto-detected from the browser when omitted.
|
|
27
|
+
|
|
28
|
+
### `language`
|
|
29
|
+
|
|
30
|
+
- **Type:** `string`
|
|
31
|
+
- **Description:** Language subtag only (e.g. `"en"`, `"ja"`). Used for resolving built-in UI label tables.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { useResolvedLocale } from "@tailor-platform/app-shell";
|
|
37
|
+
|
|
38
|
+
function DateDisplay({ date }: { date: Date }) {
|
|
39
|
+
const { locale } = useResolvedLocale();
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<span>
|
|
43
|
+
{new Intl.DateTimeFormat(locale, { dateStyle: "long" }).format(date)}
|
|
44
|
+
</span>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Locale-aware number formatting
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
function PriceDisplay({ amount }: { amount: number }) {
|
|
53
|
+
const { locale } = useResolvedLocale();
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<span>
|
|
57
|
+
{new Intl.NumberFormat(locale, { style: "currency", currency: "USD" }).format(amount)}
|
|
58
|
+
</span>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Related
|
|
64
|
+
|
|
65
|
+
- [AppShell](../components/app-shell.md) — configure locale via the `locale` prop
|
|
66
|
+
- [useTimeZone](./use-time-zone.md) — access the configured IANA timezone
|
|
67
|
+
- [DatePicker](../components/date-picker.md) — date input components that consume this locale automatically
|