@alepha/ui 0.25.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/README.md +12 -0
- package/components.json +20 -0
- package/package.json +85 -0
- package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
- package/src/components/admin/admin-audits.tsx +247 -0
- package/src/components/admin/admin-files.tsx +346 -0
- package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
- package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
- package/src/components/admin/admin-jobs.tsx +294 -0
- package/src/components/admin/admin-keys.tsx +162 -0
- package/src/components/admin/admin-notifications.tsx +130 -0
- package/src/components/admin/admin-page.tsx +24 -0
- package/src/components/admin/admin-parameters.tsx +864 -0
- package/src/components/admin/admin-payments.tsx +93 -0
- package/src/components/admin/admin-sessions.tsx +174 -0
- package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
- package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
- package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
- package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
- package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
- package/src/components/admin/admin-user-detail.tsx +606 -0
- package/src/components/admin/admin-users-roles-picker.tsx +126 -0
- package/src/components/admin/admin-users-status-filter.tsx +51 -0
- package/src/components/admin/admin-users.tsx +518 -0
- package/src/components/admin/diff-lines.spec.ts +58 -0
- package/src/components/admin/diff-lines.ts +58 -0
- package/src/components/admin/parameter-diff-dialog.tsx +119 -0
- package/src/components/admin/parameter-history-item.tsx +252 -0
- package/src/components/admin/parameter-json-dialog.tsx +93 -0
- package/src/components/admin/parameter-save-dialog.tsx +126 -0
- package/src/components/admin/use-confirmed-action.tsx +93 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
- package/src/components/alepha-table/alepha-table.tsx +1158 -0
- package/src/components/alepha-table/use-table-selection.ts +95 -0
- package/src/components/app-shell/app-shell.tsx +568 -0
- package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
- package/src/components/auth/auth-login.tsx +382 -0
- package/src/components/auth/auth-register.tsx +786 -0
- package/src/components/auth/auth-reset-password.tsx +349 -0
- package/src/components/auth/auth-router.tsx +126 -0
- package/src/components/auth/auth-verify-email.tsx +179 -0
- package/src/components/auto-form/auto-form.tsx +867 -0
- package/src/components/brand-icon/brand-icon.tsx +104 -0
- package/src/components/button-dark/button-dark.tsx +78 -0
- package/src/components/button-language/button-language.tsx +98 -0
- package/src/components/button-theme/button-theme.tsx +148 -0
- package/src/components/button-user/button-user.tsx +214 -0
- package/src/components/captcha/turnstile-widget.tsx +157 -0
- package/src/components/control/control.tsx +735 -0
- package/src/components/control-array/control-array.tsx +700 -0
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
- package/src/components/control-base/field-i18n.ts +60 -0
- package/src/components/control-base/form-field.tsx +275 -0
- package/src/components/control-base/grid.tsx +59 -0
- package/src/components/control-base/icon-hint.tsx +64 -0
- package/src/components/control-date/control-date.tsx +190 -0
- package/src/components/control-number/control-number.tsx +136 -0
- package/src/components/control-object/control-object.tsx +200 -0
- package/src/components/control-select/control-select.tsx +774 -0
- package/src/components/control-upload/control-upload.tsx +475 -0
- package/src/components/file-image/file-image.tsx +52 -0
- package/src/components/language-toggle/language-toggle.tsx +66 -0
- package/src/components/markdown-view/markdown-view.css +114 -0
- package/src/components/markdown-view/markdown-view.tsx +92 -0
- package/src/components/nav-shell/nav-page.tsx +56 -0
- package/src/components/nav-shell/nav-shell.tsx +72 -0
- package/src/components/nav-shell/nav-tree-util.ts +62 -0
- package/src/components/nav-shell/spotlight.tsx +163 -0
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
- package/src/components/nav-shell/use-nav-entries.ts +101 -0
- package/src/components/nav-shell/use-nav-tree.ts +61 -0
- package/src/components/ui/accordion.tsx +77 -0
- package/src/components/ui/alert-dialog.tsx +186 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +121 -0
- package/src/components/ui/button-group.tsx +86 -0
- package/src/components/ui/button.tsx +83 -0
- package/src/components/ui/calendar.tsx +235 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +241 -0
- package/src/components/ui/chart.tsx +370 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +19 -0
- package/src/components/ui/combobox.tsx +298 -0
- package/src/components/ui/command.tsx +196 -0
- package/src/components/ui/context-menu.tsx +271 -0
- package/src/components/ui/dialog.tsx +153 -0
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +130 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +100 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +157 -0
- package/src/components/ui/input-otp.tsx +83 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +200 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +283 -0
- package/src/components/ui/navigation-menu.tsx +170 -0
- package/src/components/ui/pagination.tsx +133 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/radio-group.tsx +35 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +51 -0
- package/src/components/ui/segmented.tsx +232 -0
- package/src/components/ui/select.tsx +201 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/sheet.tsx +133 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/sonner.tsx +46 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/components/use-dialog/use-dialog.tsx +244 -0
- package/src/components/use-toast/use-toast.tsx +89 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
- package/src/lib/i18n-fr.ts +500 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles.css +129 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export interface TableSelection<T> {
|
|
4
|
+
/**
|
|
5
|
+
* Selected rows across every page, keyed by `rowKey`. `size` and `has`
|
|
6
|
+
* are what the table renders against.
|
|
7
|
+
*/
|
|
8
|
+
selection: ReadonlyMap<string, T>;
|
|
9
|
+
/**
|
|
10
|
+
* The selected row objects across every page — always consistent with
|
|
11
|
+
* `selection.size`, so a bulk action can never receive fewer rows than
|
|
12
|
+
* the count shown to the user.
|
|
13
|
+
*/
|
|
14
|
+
selectedItems: T[];
|
|
15
|
+
/**
|
|
16
|
+
* Whether every row of the current page is selected.
|
|
17
|
+
*/
|
|
18
|
+
allSelected: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether some (but not all) rows of the current page are selected.
|
|
21
|
+
*/
|
|
22
|
+
someSelected: boolean;
|
|
23
|
+
toggleRow: (item: T) => void;
|
|
24
|
+
toggleAll: () => void;
|
|
25
|
+
clearSelection: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cross-page row selection for AlephaTable.
|
|
30
|
+
*
|
|
31
|
+
* Selected rows are cached as full objects (not just keys) so paging away
|
|
32
|
+
* and back never desynchronizes the selection count from the items handed
|
|
33
|
+
* to bulk actions. `toggleAll` operates on the current page only;
|
|
34
|
+
* `clearSelection` drops everything.
|
|
35
|
+
*/
|
|
36
|
+
export const useTableSelection = <T>(
|
|
37
|
+
data: T[],
|
|
38
|
+
rowKey: (item: T) => string,
|
|
39
|
+
): TableSelection<T> => {
|
|
40
|
+
const [selection, setSelection] = useState<Map<string, T>>(new Map());
|
|
41
|
+
|
|
42
|
+
const clearSelection = useCallback(() => setSelection(new Map()), []);
|
|
43
|
+
|
|
44
|
+
const selectedItems = useMemo(
|
|
45
|
+
() => Array.from(selection.values()),
|
|
46
|
+
[selection],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const allSelected =
|
|
50
|
+
data.length > 0 && data.every((it) => selection.has(rowKey(it)));
|
|
51
|
+
const someSelected =
|
|
52
|
+
!allSelected && data.some((it) => selection.has(rowKey(it)));
|
|
53
|
+
|
|
54
|
+
const toggleRow = useCallback(
|
|
55
|
+
(item: T) => {
|
|
56
|
+
setSelection((prev) => {
|
|
57
|
+
const next = new Map(prev);
|
|
58
|
+
const key = rowKey(item);
|
|
59
|
+
if (next.has(key)) {
|
|
60
|
+
next.delete(key);
|
|
61
|
+
} else {
|
|
62
|
+
next.set(key, item);
|
|
63
|
+
}
|
|
64
|
+
return next;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
[rowKey],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const toggleAll = useCallback(() => {
|
|
71
|
+
setSelection((prev) => {
|
|
72
|
+
const next = new Map(prev);
|
|
73
|
+
const pageFullySelected =
|
|
74
|
+
data.length > 0 && data.every((it) => prev.has(rowKey(it)));
|
|
75
|
+
for (const it of data) {
|
|
76
|
+
if (pageFullySelected) {
|
|
77
|
+
next.delete(rowKey(it));
|
|
78
|
+
} else {
|
|
79
|
+
next.set(rowKey(it), it);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
}, [data, rowKey]);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
selection,
|
|
88
|
+
selectedItems,
|
|
89
|
+
allSelected,
|
|
90
|
+
someSelected,
|
|
91
|
+
toggleRow,
|
|
92
|
+
toggleAll,
|
|
93
|
+
clearSelection,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ActionErrorToaster,
|
|
7
|
+
type ActionErrorToasterProps,
|
|
8
|
+
} from "@alepha/ui/components/action-error-toaster/action-error-toaster";
|
|
9
|
+
import {
|
|
10
|
+
Breadcrumb,
|
|
11
|
+
BreadcrumbItem,
|
|
12
|
+
BreadcrumbLink,
|
|
13
|
+
BreadcrumbList,
|
|
14
|
+
BreadcrumbPage,
|
|
15
|
+
BreadcrumbSeparator,
|
|
16
|
+
} from "@alepha/ui/components/ui/breadcrumb";
|
|
17
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
18
|
+
import {
|
|
19
|
+
HoverCard,
|
|
20
|
+
HoverCardContent,
|
|
21
|
+
HoverCardTrigger,
|
|
22
|
+
} from "@alepha/ui/components/ui/hover-card";
|
|
23
|
+
import { Separator } from "@alepha/ui/components/ui/separator";
|
|
24
|
+
import {
|
|
25
|
+
Sidebar,
|
|
26
|
+
SidebarContent,
|
|
27
|
+
SidebarFooter,
|
|
28
|
+
SidebarGroup,
|
|
29
|
+
SidebarGroupContent,
|
|
30
|
+
SidebarGroupLabel,
|
|
31
|
+
SidebarHeader,
|
|
32
|
+
SidebarInset,
|
|
33
|
+
SidebarMenu,
|
|
34
|
+
SidebarMenuBadge,
|
|
35
|
+
SidebarMenuButton,
|
|
36
|
+
SidebarMenuItem,
|
|
37
|
+
SidebarMenuSub,
|
|
38
|
+
SidebarMenuSubButton,
|
|
39
|
+
SidebarMenuSubItem,
|
|
40
|
+
SidebarProvider,
|
|
41
|
+
useSidebar,
|
|
42
|
+
} from "@alepha/ui/components/ui/sidebar";
|
|
43
|
+
import { Toaster } from "@alepha/ui/components/ui/sonner";
|
|
44
|
+
import {
|
|
45
|
+
Tooltip,
|
|
46
|
+
TooltipContent,
|
|
47
|
+
TooltipProvider,
|
|
48
|
+
TooltipTrigger,
|
|
49
|
+
} from "@alepha/ui/components/ui/tooltip";
|
|
50
|
+
import { DialogProvider } from "@alepha/ui/components/use-dialog/use-dialog";
|
|
51
|
+
import { useEvents } from "alepha/react";
|
|
52
|
+
import { Link, NestedView } from "alepha/react/router";
|
|
53
|
+
import { useSidebarState } from "alepha/react/ui";
|
|
54
|
+
import {
|
|
55
|
+
ChevronRight,
|
|
56
|
+
Lock,
|
|
57
|
+
PanelLeftClose,
|
|
58
|
+
PanelLeftOpen,
|
|
59
|
+
} from "lucide-react";
|
|
60
|
+
import type { ComponentType, ReactNode, SVGProps } from "react";
|
|
61
|
+
import { Fragment, useEffect, useRef, useState } from "react";
|
|
62
|
+
|
|
63
|
+
export interface NavigationProgressOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Tailwind classes applied to the bar. Defaults to `bg-primary`.
|
|
66
|
+
*/
|
|
67
|
+
className?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Bar height in pixels. Defaults to 2.
|
|
70
|
+
*/
|
|
71
|
+
height?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function NavigationProgress(options: NavigationProgressOptions) {
|
|
75
|
+
const [progress, setProgress] = useState(0);
|
|
76
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
77
|
+
const [visible, setVisible] = useState(false);
|
|
78
|
+
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
|
79
|
+
|
|
80
|
+
useEvents(
|
|
81
|
+
{
|
|
82
|
+
"react:transition:begin": () => {
|
|
83
|
+
setProgress(0);
|
|
84
|
+
setVisible(true);
|
|
85
|
+
setIsLoading(true);
|
|
86
|
+
let current = 0;
|
|
87
|
+
intervalRef.current = setInterval(() => {
|
|
88
|
+
current += (90 - current) * 0.1;
|
|
89
|
+
setProgress(Math.min(90, current));
|
|
90
|
+
}, 100);
|
|
91
|
+
},
|
|
92
|
+
"react:transition:end": () => {
|
|
93
|
+
if (intervalRef.current) {
|
|
94
|
+
clearInterval(intervalRef.current);
|
|
95
|
+
intervalRef.current = null;
|
|
96
|
+
}
|
|
97
|
+
setProgress(100);
|
|
98
|
+
setIsLoading(false);
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
setVisible(false);
|
|
101
|
+
setProgress(0);
|
|
102
|
+
}, 200);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
[],
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (!visible) return null;
|
|
109
|
+
const height = options.height ?? 2;
|
|
110
|
+
const barClassName = options.className ?? "bg-primary";
|
|
111
|
+
return (
|
|
112
|
+
<div
|
|
113
|
+
className="fixed top-0 left-0 right-0 z-50 pointer-events-none"
|
|
114
|
+
style={{ height }}
|
|
115
|
+
>
|
|
116
|
+
<div
|
|
117
|
+
className={`h-full ${barClassName}`}
|
|
118
|
+
style={{
|
|
119
|
+
width: `${progress}%`,
|
|
120
|
+
transition: isLoading
|
|
121
|
+
? "width 0.1s ease-out"
|
|
122
|
+
: "width 0.2s ease-out, opacity 0.2s ease-out",
|
|
123
|
+
opacity: isLoading ? 1 : 0,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function StatefulSidebarTrigger() {
|
|
131
|
+
const { toggleSidebar, isMobile, openMobile, state } = useSidebar();
|
|
132
|
+
const open = isMobile ? openMobile : state === "expanded";
|
|
133
|
+
const Icon = open ? PanelLeftClose : PanelLeftOpen;
|
|
134
|
+
return (
|
|
135
|
+
<Button
|
|
136
|
+
variant="ghost"
|
|
137
|
+
size="icon"
|
|
138
|
+
onClick={toggleSidebar}
|
|
139
|
+
aria-label={open ? "Collapse sidebar" : "Expand sidebar"}
|
|
140
|
+
className="size-8"
|
|
141
|
+
>
|
|
142
|
+
<Icon className="size-4" />
|
|
143
|
+
</Button>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
type IconType = ComponentType<SVGProps<SVGSVGElement>>;
|
|
148
|
+
|
|
149
|
+
export interface NavItem {
|
|
150
|
+
label: ReactNode;
|
|
151
|
+
/**
|
|
152
|
+
* Required for leaf items. Ignored when `children` is provided (the parent becomes a toggle group).
|
|
153
|
+
*/
|
|
154
|
+
href?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Either an icon *component* (e.g. a lucide `Users`) which is instantiated
|
|
157
|
+
* with the row's sizing className, or an already-rendered ReactNode element
|
|
158
|
+
* (e.g. `<Users />`). The latter lets nav metadata declared on a `$page`
|
|
159
|
+
* (which is pure React) carry its icon as a node — see `useNavTree`.
|
|
160
|
+
*/
|
|
161
|
+
icon?: IconType | ReactNode;
|
|
162
|
+
/**
|
|
163
|
+
* When provided, renders as the active marker. Compare against current path.
|
|
164
|
+
*/
|
|
165
|
+
active?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Nested items. When set, the parent becomes a collapsible group.
|
|
168
|
+
*/
|
|
169
|
+
children?: NavItem[];
|
|
170
|
+
/**
|
|
171
|
+
* Initial open state for groups. Defaults to true if any descendant is active.
|
|
172
|
+
*/
|
|
173
|
+
defaultOpen?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Optional trailing badge (e.g. unread count). Hidden when the sidebar is collapsed to icons.
|
|
176
|
+
*/
|
|
177
|
+
badge?: ReactNode;
|
|
178
|
+
/**
|
|
179
|
+
* When true the item is rendered muted, navigation is blocked, and the
|
|
180
|
+
* `tooltip` (if any) explains why. Use for paywalled / unavailable entries.
|
|
181
|
+
*/
|
|
182
|
+
disabled?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Hover tooltip shown on the row regardless of sidebar state. When the
|
|
185
|
+
* item is `disabled`, this is the explanation surface (HoverCard, with
|
|
186
|
+
* room to breathe). When the item is enabled, it surfaces as a regular
|
|
187
|
+
* Tooltip on the trigger.
|
|
188
|
+
*/
|
|
189
|
+
tooltip?: ReactNode;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function hasActiveDescendant(item: NavItem): boolean {
|
|
193
|
+
if (item.active) return true;
|
|
194
|
+
return (item.children ?? []).some(hasActiveDescendant);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Render a NavItem icon. An already-created element (e.g. `<Users />`, which
|
|
199
|
+
* `React.isValidElement` recognises) is returned as-is; anything else is
|
|
200
|
+
* treated as a component *type* — including lucide's `forwardRef` icons, which
|
|
201
|
+
* are objects rather than plain functions — and instantiated with the row's
|
|
202
|
+
* sizing className.
|
|
203
|
+
*/
|
|
204
|
+
function renderNavIcon(icon: NavItem["icon"], className: string): ReactNode {
|
|
205
|
+
if (icon == null || icon === false) return null;
|
|
206
|
+
if (React.isValidElement(icon)) {
|
|
207
|
+
// Already an element (e.g. `<Users />`): clone it to apply the row's sizing
|
|
208
|
+
// className so element icons render at the same size as component icons,
|
|
209
|
+
// merging with any className the caller already set.
|
|
210
|
+
const existing = (icon.props as { className?: string })?.className;
|
|
211
|
+
return React.cloneElement(
|
|
212
|
+
icon as React.ReactElement<{ className?: string }>,
|
|
213
|
+
{
|
|
214
|
+
className: existing ? `${existing} ${className}` : className,
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
const Icon = icon as IconType;
|
|
219
|
+
return <Icon className={className} />;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function SidebarNavItem(props: { item: NavItem }) {
|
|
223
|
+
const { item } = props;
|
|
224
|
+
const children = item.children;
|
|
225
|
+
const isGroup = !!children && children.length > 0;
|
|
226
|
+
const hasActive = isGroup && hasActiveDescendant(item);
|
|
227
|
+
const [open, setOpen] = useState(item.defaultOpen ?? hasActive);
|
|
228
|
+
// Reveal a collapsed group when navigation makes one of its descendants
|
|
229
|
+
// active — SPA nav, spotlight (⌘K), breadcrumb, or a deep-link that doesn't
|
|
230
|
+
// remount this item (useState's initializer runs only at mount, so without
|
|
231
|
+
// this the group stays stuck closed and the active page is hidden — petition
|
|
232
|
+
// #4). Only OPENS; never auto-collapses, so a manual toggle is preserved.
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
if (hasActive) setOpen(true);
|
|
235
|
+
}, [hasActive]);
|
|
236
|
+
|
|
237
|
+
if (!isGroup) {
|
|
238
|
+
// Disabled rows render with a muted, dashed-border treatment plus a
|
|
239
|
+
// Lock affordance on the trailing edge. Clicks are swallowed. When a
|
|
240
|
+
// `tooltip` is provided, the row opens a HoverCard dropdown on hover
|
|
241
|
+
// so the explanation has space to breathe regardless of sidebar
|
|
242
|
+
// state.
|
|
243
|
+
if (item.disabled) {
|
|
244
|
+
// Bypass SidebarMenuButton — it self-wraps in a Tooltip when given
|
|
245
|
+
// a `tooltip` prop, which would swallow the HoverCard pointer
|
|
246
|
+
// events. A plain styled <div> keeps cursor-not-allowed and lets
|
|
247
|
+
// the row act as the HoverCard trigger.
|
|
248
|
+
const row = (
|
|
249
|
+
<div
|
|
250
|
+
aria-disabled="true"
|
|
251
|
+
className="flex h-8 w-full items-center gap-2 rounded-md border border-dashed border-muted-foreground/40 bg-muted/40 px-2 text-sm text-muted-foreground"
|
|
252
|
+
style={{ cursor: "not-allowed" }}
|
|
253
|
+
>
|
|
254
|
+
{renderNavIcon(item.icon, "size-4 shrink-0")}
|
|
255
|
+
<span className="flex-1 truncate text-left">{item.label}</span>
|
|
256
|
+
<Lock className="size-3.5 shrink-0 opacity-70" />
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
return (
|
|
260
|
+
<SidebarMenuItem>
|
|
261
|
+
{item.tooltip ? (
|
|
262
|
+
<HoverCard>
|
|
263
|
+
<HoverCardTrigger render={row} />
|
|
264
|
+
<HoverCardContent side="right" align="start" className="text-sm">
|
|
265
|
+
{item.tooltip}
|
|
266
|
+
</HoverCardContent>
|
|
267
|
+
</HoverCard>
|
|
268
|
+
) : (
|
|
269
|
+
row
|
|
270
|
+
)}
|
|
271
|
+
</SidebarMenuItem>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const link = (
|
|
276
|
+
<SidebarMenuButton
|
|
277
|
+
isActive={item.active}
|
|
278
|
+
tooltip={typeof item.label === "string" ? item.label : undefined}
|
|
279
|
+
render={<Link href={item.href ?? "#"} />}
|
|
280
|
+
>
|
|
281
|
+
{renderNavIcon(item.icon, "size-4")}
|
|
282
|
+
<span>{item.label}</span>
|
|
283
|
+
</SidebarMenuButton>
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
const row = item.tooltip ? (
|
|
287
|
+
<Tooltip>
|
|
288
|
+
<TooltipTrigger render={link} />
|
|
289
|
+
<TooltipContent side="right">{item.tooltip}</TooltipContent>
|
|
290
|
+
</Tooltip>
|
|
291
|
+
) : (
|
|
292
|
+
link
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
<SidebarMenuItem>
|
|
297
|
+
{row}
|
|
298
|
+
{item.badge != null && item.badge !== false && (
|
|
299
|
+
<SidebarMenuBadge>{item.badge}</SidebarMenuBadge>
|
|
300
|
+
)}
|
|
301
|
+
</SidebarMenuItem>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<SidebarMenuItem>
|
|
307
|
+
<SidebarMenuButton
|
|
308
|
+
onClick={() => setOpen((v) => !v)}
|
|
309
|
+
isActive={item.active}
|
|
310
|
+
tooltip={typeof item.label === "string" ? item.label : undefined}
|
|
311
|
+
>
|
|
312
|
+
{renderNavIcon(item.icon, "size-4")}
|
|
313
|
+
<span className="flex-1 text-left">{item.label}</span>
|
|
314
|
+
<ChevronRight
|
|
315
|
+
className={`size-4 transition-transform ${open ? "rotate-90" : ""}`}
|
|
316
|
+
/>
|
|
317
|
+
</SidebarMenuButton>
|
|
318
|
+
{open && (
|
|
319
|
+
<SidebarMenuSub>
|
|
320
|
+
{children.map((child, ci) => (
|
|
321
|
+
<SidebarMenuSubItem key={child.href ?? ci}>
|
|
322
|
+
{child.children && child.children.length > 0 ? (
|
|
323
|
+
<SidebarNavItem item={child} />
|
|
324
|
+
) : (
|
|
325
|
+
<SidebarMenuSubButton
|
|
326
|
+
isActive={child.active}
|
|
327
|
+
render={<Link href={child.href ?? "#"} />}
|
|
328
|
+
>
|
|
329
|
+
{renderNavIcon(child.icon, "size-4")}
|
|
330
|
+
<span>{child.label}</span>
|
|
331
|
+
</SidebarMenuSubButton>
|
|
332
|
+
)}
|
|
333
|
+
</SidebarMenuSubItem>
|
|
334
|
+
))}
|
|
335
|
+
</SidebarMenuSub>
|
|
336
|
+
)}
|
|
337
|
+
</SidebarMenuItem>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface NavGroup {
|
|
342
|
+
label?: string;
|
|
343
|
+
items: NavItem[];
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export interface AppShellProps {
|
|
347
|
+
/**
|
|
348
|
+
* Branding shown at the top of the sidebar.
|
|
349
|
+
*/
|
|
350
|
+
brand?: ReactNode;
|
|
351
|
+
/**
|
|
352
|
+
* Sidebar navigation groups.
|
|
353
|
+
*/
|
|
354
|
+
nav?: NavGroup[];
|
|
355
|
+
/**
|
|
356
|
+
* Content rendered at the bottom of the sidebar (user menu, etc.).
|
|
357
|
+
*/
|
|
358
|
+
sidebarFooter?: ReactNode;
|
|
359
|
+
/**
|
|
360
|
+
* Breadcrumb crumbs (last one is rendered as the current page).
|
|
361
|
+
*/
|
|
362
|
+
breadcrumbs?: { label: ReactNode; href?: string }[];
|
|
363
|
+
/**
|
|
364
|
+
* Top-bar right-side content (search, theme toggle, user menu).
|
|
365
|
+
*/
|
|
366
|
+
topbarActions?: ReactNode;
|
|
367
|
+
/**
|
|
368
|
+
* Layout variant.
|
|
369
|
+
* - `sidebar` (default): sidebar and page sit flush side-by-side.
|
|
370
|
+
* - `inset`: sidebar uses the global background; the page is a rounded card with margin.
|
|
371
|
+
* - `floating`: the page uses the global background; the sidebar is a rounded card with margin.
|
|
372
|
+
*/
|
|
373
|
+
variant?: "sidebar" | "floating" | "inset";
|
|
374
|
+
/**
|
|
375
|
+
* When `variant="inset"`, lift the header out of the floating card so it
|
|
376
|
+
* sits on the sidebar background — only the main page becomes the card.
|
|
377
|
+
* Has no effect on other variants.
|
|
378
|
+
*/
|
|
379
|
+
headerOutside?: boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Top loading bar shown during route transitions.
|
|
382
|
+
* `true` (default) enables it with default styling, `false` disables it,
|
|
383
|
+
* or pass an options object to customize.
|
|
384
|
+
*/
|
|
385
|
+
progress?: boolean | NavigationProgressOptions;
|
|
386
|
+
/**
|
|
387
|
+
* Page content. Defaults to `<NestedView />` (renders the active route).
|
|
388
|
+
*/
|
|
389
|
+
children?: ReactNode;
|
|
390
|
+
/**
|
|
391
|
+
* Surface failed `useAction` / `useQuery` calls as a toast (via the
|
|
392
|
+
* `react:action:error` event). `true` (default) enables it, `false`
|
|
393
|
+
* disables it, or pass an options object to configure
|
|
394
|
+
* (see {@link ActionErrorToasterProps}). Ignored when `embedded` (the
|
|
395
|
+
* parent layout owns the toaster).
|
|
396
|
+
*/
|
|
397
|
+
actionErrorToaster?: boolean | ActionErrorToasterProps;
|
|
398
|
+
/**
|
|
399
|
+
* When `true`, the shell assumes it is mounted inside an outer provider tree
|
|
400
|
+
* and skips its own `<DialogProvider>` and `<Toaster />` wrappers. Use this
|
|
401
|
+
* when a parent layout already provides them.
|
|
402
|
+
*/
|
|
403
|
+
embedded?: boolean;
|
|
404
|
+
/**
|
|
405
|
+
* When `true`, the shell fills its parent container instead of the viewport
|
|
406
|
+
* (`min-h-svh`). Use when a parent layout owns the height (e.g. when a
|
|
407
|
+
* sticky footer sits below the shell).
|
|
408
|
+
*/
|
|
409
|
+
fill?: boolean;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Standard SaaS layout: collapsible sidebar + topbar with breadcrumbs.
|
|
414
|
+
* Built on shadcn `<Sidebar>` + `<Breadcrumb>`.
|
|
415
|
+
*/
|
|
416
|
+
export function AppShell(props: AppShellProps) {
|
|
417
|
+
const { collapsed, setCollapsed } = useSidebarState();
|
|
418
|
+
const nav = props.nav ?? [];
|
|
419
|
+
const variant = props.variant ?? "sidebar";
|
|
420
|
+
const progress = props.progress ?? true;
|
|
421
|
+
const headerOutside = !!props.headerOutside && variant === "inset";
|
|
422
|
+
|
|
423
|
+
const headerNode = (
|
|
424
|
+
<header
|
|
425
|
+
className={
|
|
426
|
+
headerOutside
|
|
427
|
+
? "bg-sidebar flex h-14 shrink-0 items-center gap-2 px-4"
|
|
428
|
+
: "bg-background flex h-14 shrink-0 items-center gap-2 border-b px-4"
|
|
429
|
+
}
|
|
430
|
+
>
|
|
431
|
+
<StatefulSidebarTrigger />
|
|
432
|
+
<Separator orientation="vertical" className="mx-2" />
|
|
433
|
+
{props.breadcrumbs && props.breadcrumbs.length > 0 && (
|
|
434
|
+
<Breadcrumb>
|
|
435
|
+
<BreadcrumbList>
|
|
436
|
+
{props.breadcrumbs.map((crumb, i) => {
|
|
437
|
+
const last = i === props.breadcrumbs!.length - 1;
|
|
438
|
+
return (
|
|
439
|
+
<Fragment key={i}>
|
|
440
|
+
<BreadcrumbItem>
|
|
441
|
+
{last || !crumb.href ? (
|
|
442
|
+
<BreadcrumbPage>{crumb.label}</BreadcrumbPage>
|
|
443
|
+
) : (
|
|
444
|
+
<BreadcrumbLink render={<Link href={crumb.href} />}>
|
|
445
|
+
{crumb.label}
|
|
446
|
+
</BreadcrumbLink>
|
|
447
|
+
)}
|
|
448
|
+
</BreadcrumbItem>
|
|
449
|
+
{!last && <BreadcrumbSeparator />}
|
|
450
|
+
</Fragment>
|
|
451
|
+
);
|
|
452
|
+
})}
|
|
453
|
+
</BreadcrumbList>
|
|
454
|
+
</Breadcrumb>
|
|
455
|
+
)}
|
|
456
|
+
<div className="flex-1" />
|
|
457
|
+
{props.topbarActions}
|
|
458
|
+
</header>
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
const mainNode = (
|
|
462
|
+
// Layout contract for `fill: true` pages:
|
|
463
|
+
// parent (`h-svh`) → SidebarProvider (`h-full`) → SidebarInset → main
|
|
464
|
+
// - main is `flex flex-col min-h-0 flex-1` so its children can
|
|
465
|
+
// claim the leftover height via `flex-1 min-h-0`.
|
|
466
|
+
// - main itself is `overflow-hidden` (not `overflow-auto`) so the
|
|
467
|
+
// table's inner `overflow-auto` is the actual scroll surface —
|
|
468
|
+
// header stays sticky, body scrolls, no page-level scrollbar.
|
|
469
|
+
// - For non-fill pages there's no height bound, so this collapses
|
|
470
|
+
// to "scroll whatever overflows" without further config.
|
|
471
|
+
<main
|
|
472
|
+
className={
|
|
473
|
+
props.fill
|
|
474
|
+
? "flex min-h-0 flex-1 flex-col overflow-hidden"
|
|
475
|
+
: "flex-1 overflow-auto"
|
|
476
|
+
}
|
|
477
|
+
>
|
|
478
|
+
{props.children ?? <NestedView />}
|
|
479
|
+
</main>
|
|
480
|
+
);
|
|
481
|
+
const renderBody = () => (
|
|
482
|
+
<>
|
|
483
|
+
{progress !== false && (
|
|
484
|
+
<NavigationProgress {...(progress === true ? {} : progress)} />
|
|
485
|
+
)}
|
|
486
|
+
<SidebarProvider
|
|
487
|
+
open={!collapsed}
|
|
488
|
+
onOpenChange={(o: boolean) => setCollapsed(!o)}
|
|
489
|
+
// `fill` = a parent owns the height (e.g. a full-width banner above
|
|
490
|
+
// the shell). The desktop sidebar is `fixed inset-y-0 h-svh` (pinned
|
|
491
|
+
// to the VIEWPORT), so it would overlap whatever sits above the
|
|
492
|
+
// shell — re-anchor it to this wrapper instead (absolute within the
|
|
493
|
+
// now-relative provider, height from the wrapper). The arbitrary
|
|
494
|
+
// selectors out-specify the base `.fixed`/`.h-svh` utilities.
|
|
495
|
+
className={
|
|
496
|
+
props.fill
|
|
497
|
+
? "relative min-h-0 h-full [&_[data-slot=sidebar-container]]:absolute [&_[data-slot=sidebar-container]]:h-auto"
|
|
498
|
+
: undefined
|
|
499
|
+
}
|
|
500
|
+
>
|
|
501
|
+
<Sidebar collapsible="icon" variant={variant}>
|
|
502
|
+
<SidebarHeader>{props.brand}</SidebarHeader>
|
|
503
|
+
<SidebarContent>
|
|
504
|
+
{nav.map((group, gi) => (
|
|
505
|
+
<SidebarGroup key={gi}>
|
|
506
|
+
{group.label && (
|
|
507
|
+
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
|
|
508
|
+
)}
|
|
509
|
+
<SidebarGroupContent>
|
|
510
|
+
<SidebarMenu>
|
|
511
|
+
{group.items.map((item, ii) => (
|
|
512
|
+
<SidebarNavItem
|
|
513
|
+
key={item.href ?? `${gi}-${ii}`}
|
|
514
|
+
item={item}
|
|
515
|
+
/>
|
|
516
|
+
))}
|
|
517
|
+
</SidebarMenu>
|
|
518
|
+
</SidebarGroupContent>
|
|
519
|
+
</SidebarGroup>
|
|
520
|
+
))}
|
|
521
|
+
</SidebarContent>
|
|
522
|
+
{props.sidebarFooter && (
|
|
523
|
+
<SidebarFooter>{props.sidebarFooter}</SidebarFooter>
|
|
524
|
+
)}
|
|
525
|
+
</Sidebar>
|
|
526
|
+
{headerOutside ? (
|
|
527
|
+
<div className="bg-sidebar flex flex-1 flex-col">
|
|
528
|
+
{headerNode}
|
|
529
|
+
<div className="bg-background m-2 mt-0 flex flex-1 flex-col overflow-hidden rounded-xl border shadow-sm">
|
|
530
|
+
{mainNode}
|
|
531
|
+
</div>
|
|
532
|
+
</div>
|
|
533
|
+
) : (
|
|
534
|
+
<SidebarInset
|
|
535
|
+
className={
|
|
536
|
+
variant === "inset"
|
|
537
|
+
? "md:peer-data-[variant=inset]:overflow-hidden border"
|
|
538
|
+
: undefined
|
|
539
|
+
}
|
|
540
|
+
>
|
|
541
|
+
{headerNode}
|
|
542
|
+
{mainNode}
|
|
543
|
+
</SidebarInset>
|
|
544
|
+
)}
|
|
545
|
+
</SidebarProvider>
|
|
546
|
+
</>
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
if (props.embedded) {
|
|
550
|
+
return renderBody();
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const errorToaster = props.actionErrorToaster ?? true;
|
|
554
|
+
|
|
555
|
+
return (
|
|
556
|
+
<DialogProvider>
|
|
557
|
+
<TooltipProvider>
|
|
558
|
+
{renderBody()}
|
|
559
|
+
<Toaster />
|
|
560
|
+
{errorToaster !== false && (
|
|
561
|
+
<ActionErrorToaster
|
|
562
|
+
{...(typeof errorToaster === "object" ? errorToaster : {})}
|
|
563
|
+
/>
|
|
564
|
+
)}
|
|
565
|
+
</TooltipProvider>
|
|
566
|
+
</DialogProvider>
|
|
567
|
+
);
|
|
568
|
+
}
|