@fldr/ui 0.3.6 → 0.3.7
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/ai/component-registry.json +962 -43
- package/ai/component-registry.md +1 -1
- package/dist/.build-complete +1 -1
- package/dist/ai/schemas.d.ts +18 -18
- package/dist/blocks-source/activity-feed/activity-feed.test.tsx +75 -0
- package/dist/blocks-source/activity-feed/activity-feed.tsx +256 -0
- package/dist/blocks-source/app-shell/app-shell.test.tsx +74 -0
- package/dist/blocks-source/app-shell/app-shell.tsx +123 -0
- package/dist/blocks-source/auth-card/auth-card.test.tsx +64 -0
- package/dist/blocks-source/auth-card/auth-card.tsx +234 -0
- package/dist/blocks-source/dashboard-page/dashboard-page.tsx +167 -0
- package/dist/blocks-source/error-page/error-page.test.tsx +60 -0
- package/dist/blocks-source/error-page/error-page.tsx +97 -0
- package/dist/blocks-source/file-table/file-item.tsx +164 -0
- package/dist/blocks-source/file-table/file-table.test.tsx +82 -0
- package/dist/blocks-source/file-table/file-table.tsx +292 -0
- package/dist/blocks-source/folder-grid/folder-grid.test.tsx +54 -0
- package/dist/blocks-source/folder-grid/folder-grid.tsx +170 -0
- package/dist/blocks-source/login-page/login-page.tsx +47 -0
- package/dist/blocks-source/onboarding-checklist/onboarding-checklist.test.tsx +50 -0
- package/dist/blocks-source/onboarding-checklist/onboarding-checklist.tsx +180 -0
- package/dist/blocks-source/settings-section/settings-section.test.tsx +43 -0
- package/dist/blocks-source/settings-section/settings-section.tsx +165 -0
- package/dist/blocks-source/share-dialog/share-dialog.test.tsx +69 -0
- package/dist/blocks-source/share-dialog/share-dialog.tsx +307 -0
- package/dist/blocks-source/stat-grid/stat-grid.test.tsx +52 -0
- package/dist/blocks-source/stat-grid/stat-grid.tsx +153 -0
- package/dist/blocks-source/upload-dropzone/upload-dropzone.test.tsx +82 -0
- package/dist/blocks-source/upload-dropzone/upload-dropzone.tsx +264 -0
- package/dist/blocks.d.ts +780 -0
- package/dist/blocks.js +1664 -0
- package/dist/chunks/delete-resource-cmlptb61ih8s84r3.js +151 -0
- package/dist/delete-resource-DY-GFy2s.d.ts +48 -0
- package/dist/index.d.ts +4 -50
- package/dist/index.js +1 -146
- package/dist/primitives.d.ts +1 -1
- package/dist/styles/kumo-standalone.css +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Sidebar, type SidebarCollapsibleType } from "../../components/sidebar";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
export interface AppShellProps {
|
|
6
|
+
/** Brand or logo, rendered in the sidebar header. */
|
|
7
|
+
brand?: ReactNode;
|
|
8
|
+
/** Sidebar navigation, typically `Sidebar.Group` / `Sidebar.Menu` elements. */
|
|
9
|
+
nav?: ReactNode;
|
|
10
|
+
/** Sidebar footer content, e.g. the signed-in account. */
|
|
11
|
+
sidebarFooter?: ReactNode;
|
|
12
|
+
/** Left side of the top bar, e.g. breadcrumbs or a page title. */
|
|
13
|
+
header?: ReactNode;
|
|
14
|
+
/** Right side of the top bar, e.g. search, upload or account actions. */
|
|
15
|
+
actions?: ReactNode;
|
|
16
|
+
/** Main page content. Scrolls independently of the sidebar and top bar. */
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
/** Initial desktop sidebar state when uncontrolled. @default true */
|
|
19
|
+
defaultOpen?: boolean;
|
|
20
|
+
/** Controlled desktop sidebar state. */
|
|
21
|
+
open?: boolean;
|
|
22
|
+
/** Called when the sidebar is opened or collapsed. */
|
|
23
|
+
onOpenChange?: (open: boolean) => void;
|
|
24
|
+
/** How the desktop sidebar collapses. @default "icon" */
|
|
25
|
+
collapsible?: SidebarCollapsibleType;
|
|
26
|
+
/** Viewport width (px) below which the sidebar becomes a drawer. @default 768 */
|
|
27
|
+
mobileBreakpoint?: number;
|
|
28
|
+
/** Keep the shell inside its parent instead of filling the viewport. @default false */
|
|
29
|
+
contained?: boolean;
|
|
30
|
+
/** Accessible label for the sidebar toggle button. */
|
|
31
|
+
toggleLabel?: string;
|
|
32
|
+
/** Classes for the outer shell. */
|
|
33
|
+
className?: string;
|
|
34
|
+
/** Classes for the scrollable content area. */
|
|
35
|
+
contentClassName?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Application frame: sidebar navigation, top bar and a scrollable content area.
|
|
40
|
+
* The sidebar collapses to icons on desktop and becomes a drawer on narrow screens.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <AppShell
|
|
45
|
+
* brand={<span className="font-semibold">fldr</span>}
|
|
46
|
+
* nav={
|
|
47
|
+
* <Sidebar.Group>
|
|
48
|
+
* <Sidebar.Menu>
|
|
49
|
+
* <Sidebar.MenuButton icon={FolderIcon} active>All files</Sidebar.MenuButton>
|
|
50
|
+
* <Sidebar.MenuButton icon={ReceiptIcon}>Receipts</Sidebar.MenuButton>
|
|
51
|
+
* </Sidebar.Menu>
|
|
52
|
+
* </Sidebar.Group>
|
|
53
|
+
* }
|
|
54
|
+
* sidebarFooter={<span>ada@fldr.app</span>}
|
|
55
|
+
* header="All files"
|
|
56
|
+
* actions={<Button variant="primary">Upload</Button>}
|
|
57
|
+
* >
|
|
58
|
+
* <FileList />
|
|
59
|
+
* </AppShell>
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function AppShell({
|
|
63
|
+
brand,
|
|
64
|
+
nav,
|
|
65
|
+
sidebarFooter,
|
|
66
|
+
header,
|
|
67
|
+
actions,
|
|
68
|
+
children,
|
|
69
|
+
defaultOpen = true,
|
|
70
|
+
open,
|
|
71
|
+
onOpenChange,
|
|
72
|
+
collapsible = "icon",
|
|
73
|
+
mobileBreakpoint,
|
|
74
|
+
contained = false,
|
|
75
|
+
toggleLabel,
|
|
76
|
+
className,
|
|
77
|
+
contentClassName,
|
|
78
|
+
}: AppShellProps) {
|
|
79
|
+
return (
|
|
80
|
+
<Sidebar.Provider
|
|
81
|
+
defaultOpen={defaultOpen}
|
|
82
|
+
open={open}
|
|
83
|
+
onOpenChange={onOpenChange}
|
|
84
|
+
collapsible={collapsible}
|
|
85
|
+
mobileBreakpoint={mobileBreakpoint}
|
|
86
|
+
contained={contained}
|
|
87
|
+
className={cn(
|
|
88
|
+
"overflow-hidden bg-kumo-base",
|
|
89
|
+
contained ? "h-full" : "h-svh",
|
|
90
|
+
className,
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
<Sidebar>
|
|
94
|
+
{brand && <Sidebar.Header>{brand}</Sidebar.Header>}
|
|
95
|
+
<Sidebar.Content>{nav}</Sidebar.Content>
|
|
96
|
+
{sidebarFooter && <Sidebar.Footer>{sidebarFooter}</Sidebar.Footer>}
|
|
97
|
+
</Sidebar>
|
|
98
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
99
|
+
<header className="flex h-[58px] shrink-0 items-center gap-2 border-b border-kumo-line px-3">
|
|
100
|
+
{collapsible !== "none" && (
|
|
101
|
+
<Sidebar.Trigger
|
|
102
|
+
{...(toggleLabel ? { "aria-label": toggleLabel } : {})}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
<div className="flex min-w-0 flex-1 items-center truncate font-medium text-kumo-default">
|
|
106
|
+
{header}
|
|
107
|
+
</div>
|
|
108
|
+
{actions && (
|
|
109
|
+
<div className="flex shrink-0 items-center gap-2">{actions}</div>
|
|
110
|
+
)}
|
|
111
|
+
</header>
|
|
112
|
+
<main
|
|
113
|
+
className={cn(
|
|
114
|
+
"min-h-0 flex-1 overflow-y-auto bg-kumo-base",
|
|
115
|
+
contentClassName,
|
|
116
|
+
)}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</main>
|
|
120
|
+
</div>
|
|
121
|
+
</Sidebar.Provider>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vite-plus/test";
|
|
3
|
+
import { AuthCard } from "./auth-card";
|
|
4
|
+
|
|
5
|
+
const fill = (label: string, value: string) =>
|
|
6
|
+
fireEvent.change(screen.getByLabelText(label, { exact: false }), {
|
|
7
|
+
target: { value },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe("AuthCard", () => {
|
|
11
|
+
it("submits email and password", () => {
|
|
12
|
+
const onSubmit = vi.fn();
|
|
13
|
+
render(<AuthCard onSubmit={onSubmit} />);
|
|
14
|
+
expect(screen.queryByLabelText("Name", { exact: false })).toBeNull();
|
|
15
|
+
fill("Email", "ada@fldr.zip");
|
|
16
|
+
fill("Password", "hunter22");
|
|
17
|
+
fireEvent.click(screen.getByRole("button", { name: "Sign in" }));
|
|
18
|
+
expect(onSubmit).toHaveBeenCalledWith({
|
|
19
|
+
email: "ada@fldr.zip",
|
|
20
|
+
password: "hunter22",
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("shows a name field in sign-up mode", () => {
|
|
25
|
+
const onSubmit = vi.fn();
|
|
26
|
+
render(<AuthCard mode="sign-up" onSubmit={onSubmit} />);
|
|
27
|
+
fill("Name", "Ada");
|
|
28
|
+
fill("Email", "ada@fldr.zip");
|
|
29
|
+
fill("Password", "hunter22");
|
|
30
|
+
const input = screen.getByLabelText("Password", { exact: false });
|
|
31
|
+
expect(input.getAttribute("autocomplete")).toBe("new-password");
|
|
32
|
+
fireEvent.click(screen.getByRole("button", { name: "Create account" }));
|
|
33
|
+
expect(onSubmit).toHaveBeenCalledWith({
|
|
34
|
+
email: "ada@fldr.zip",
|
|
35
|
+
password: "hunter22",
|
|
36
|
+
name: "Ada",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("omits password for magic links and renders providers and errors", () => {
|
|
41
|
+
const onSubmit = vi.fn();
|
|
42
|
+
const onProvider = vi.fn();
|
|
43
|
+
render(
|
|
44
|
+
<AuthCard
|
|
45
|
+
method="magic-link"
|
|
46
|
+
providers={[{ id: "google", label: "Continue with Google" }]}
|
|
47
|
+
onProvider={onProvider}
|
|
48
|
+
onSubmit={onSubmit}
|
|
49
|
+
error="Invalid email"
|
|
50
|
+
/>,
|
|
51
|
+
);
|
|
52
|
+
expect(screen.getByRole("alert").textContent).toContain("Invalid email");
|
|
53
|
+
expect(screen.queryByLabelText("Password", { exact: false })).toBeNull();
|
|
54
|
+
fireEvent.click(
|
|
55
|
+
screen.getByRole("button", { name: "Continue with Google" }),
|
|
56
|
+
);
|
|
57
|
+
expect(onProvider).toHaveBeenCalledWith("google");
|
|
58
|
+
fill("Email", "ada@fldr.zip");
|
|
59
|
+
fireEvent.click(
|
|
60
|
+
screen.getByRole("button", { name: "Email me a sign-in link" }),
|
|
61
|
+
);
|
|
62
|
+
expect(onSubmit).toHaveBeenCalledWith({ email: "ada@fldr.zip" });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { type FormEvent, type ReactNode } from "react";
|
|
2
|
+
import { WarningCircleIcon } from "@phosphor-icons/react";
|
|
3
|
+
import { Banner } from "../../components/banner";
|
|
4
|
+
import { Button } from "../../components/button";
|
|
5
|
+
import { Input } from "../../components/input";
|
|
6
|
+
import { cn } from "../../utils/cn";
|
|
7
|
+
|
|
8
|
+
export type AuthCardMode = "sign-in" | "sign-up";
|
|
9
|
+
export type AuthCardMethod = "password" | "magic-link";
|
|
10
|
+
|
|
11
|
+
export interface AuthCardProvider {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AuthCardValues {
|
|
18
|
+
email: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AuthCardLabels {
|
|
24
|
+
signInTitle: string;
|
|
25
|
+
signUpTitle: string;
|
|
26
|
+
name: string;
|
|
27
|
+
email: string;
|
|
28
|
+
password: string;
|
|
29
|
+
signInSubmit: string;
|
|
30
|
+
signUpSubmit: string;
|
|
31
|
+
magicLinkSubmit: string;
|
|
32
|
+
divider: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const DEFAULT_LABELS: AuthCardLabels = {
|
|
36
|
+
signInTitle: "Sign in to fldr",
|
|
37
|
+
signUpTitle: "Create your fldr account",
|
|
38
|
+
name: "Name",
|
|
39
|
+
email: "Email",
|
|
40
|
+
password: "Password",
|
|
41
|
+
signInSubmit: "Sign in",
|
|
42
|
+
signUpSubmit: "Create account",
|
|
43
|
+
magicLinkSubmit: "Email me a sign-in link",
|
|
44
|
+
divider: "or",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export interface AuthCardProps {
|
|
48
|
+
/** @default "sign-in" */
|
|
49
|
+
mode?: AuthCardMode;
|
|
50
|
+
/** `"magic-link"` hides the password field. @default "password" */
|
|
51
|
+
method?: AuthCardMethod;
|
|
52
|
+
/** Called with form values on native form submission. */
|
|
53
|
+
onSubmit: (values: AuthCardValues) => void;
|
|
54
|
+
/** Provider buttons rendered above the "or" divider. */
|
|
55
|
+
providers?: AuthCardProvider[];
|
|
56
|
+
/** Called when a provider button is clicked. */
|
|
57
|
+
onProvider?: (id: string) => void;
|
|
58
|
+
/** Custom provider slot; replaces `providers` when set. */
|
|
59
|
+
providerSlot?: ReactNode;
|
|
60
|
+
/** Logo rendered above the title. */
|
|
61
|
+
logo?: ReactNode;
|
|
62
|
+
/** Overrides the mode's default title. */
|
|
63
|
+
title?: ReactNode;
|
|
64
|
+
/** Secondary text below the title. */
|
|
65
|
+
description?: ReactNode;
|
|
66
|
+
/** Error message shown in a banner above the form. */
|
|
67
|
+
error?: ReactNode;
|
|
68
|
+
/** Disables inputs and shows a spinner on submit. */
|
|
69
|
+
loading?: boolean;
|
|
70
|
+
/** Footer slot, e.g. "Don't have an account? Sign up". */
|
|
71
|
+
footer?: ReactNode;
|
|
72
|
+
/** Overridable strings for i18n. */
|
|
73
|
+
labels?: Partial<AuthCardLabels>;
|
|
74
|
+
className?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Centered sign-in / sign-up card with optional providers and magic-link mode.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* <AuthCard
|
|
83
|
+
* mode="sign-in"
|
|
84
|
+
* providers={[{ id: "google", label: "Continue with Google" }]}
|
|
85
|
+
* onProvider={(id) => startOAuth(id)}
|
|
86
|
+
* onSubmit={({ email, password }) => signIn(email, password)}
|
|
87
|
+
* footer={<>Don't have an account? <a href="/sign-up">Sign up</a></>}
|
|
88
|
+
* />
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export function AuthCard({
|
|
92
|
+
mode = "sign-in",
|
|
93
|
+
method = "password",
|
|
94
|
+
onSubmit,
|
|
95
|
+
providers,
|
|
96
|
+
onProvider,
|
|
97
|
+
providerSlot,
|
|
98
|
+
logo,
|
|
99
|
+
title,
|
|
100
|
+
description,
|
|
101
|
+
error,
|
|
102
|
+
loading = false,
|
|
103
|
+
footer,
|
|
104
|
+
labels: labelOverrides,
|
|
105
|
+
className,
|
|
106
|
+
}: AuthCardProps) {
|
|
107
|
+
const labels = { ...DEFAULT_LABELS, ...labelOverrides };
|
|
108
|
+
const isSignUp = mode === "sign-up";
|
|
109
|
+
const hasPassword = method === "password";
|
|
110
|
+
const providerContent =
|
|
111
|
+
providerSlot ??
|
|
112
|
+
(providers?.length
|
|
113
|
+
? providers.map((p) => (
|
|
114
|
+
<Button
|
|
115
|
+
key={p.id}
|
|
116
|
+
type="button"
|
|
117
|
+
variant="secondary"
|
|
118
|
+
icon={p.icon}
|
|
119
|
+
disabled={loading}
|
|
120
|
+
onClick={() => onProvider?.(p.id)}
|
|
121
|
+
className="w-full justify-center"
|
|
122
|
+
>
|
|
123
|
+
{p.label}
|
|
124
|
+
</Button>
|
|
125
|
+
))
|
|
126
|
+
: null);
|
|
127
|
+
|
|
128
|
+
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
if (loading) return;
|
|
131
|
+
const data = new FormData(event.currentTarget);
|
|
132
|
+
const get = (key: string) => {
|
|
133
|
+
const value = data.get(key);
|
|
134
|
+
return typeof value === "string" ? value : undefined;
|
|
135
|
+
};
|
|
136
|
+
onSubmit({
|
|
137
|
+
email: get("email") ?? "",
|
|
138
|
+
...(hasPassword && { password: get("password") ?? "" }),
|
|
139
|
+
...(isSignUp && { name: get("name") ?? "" }),
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const submitLabel = !hasPassword
|
|
144
|
+
? labels.magicLinkSubmit
|
|
145
|
+
: isSignUp
|
|
146
|
+
? labels.signUpSubmit
|
|
147
|
+
: labels.signInSubmit;
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
className={cn(
|
|
152
|
+
"mx-auto flex w-full max-w-[360px] flex-col gap-4 rounded-xl bg-kumo-elevated p-5",
|
|
153
|
+
className,
|
|
154
|
+
)}
|
|
155
|
+
>
|
|
156
|
+
<div className="flex flex-col gap-1">
|
|
157
|
+
{logo && <div className="mb-3">{logo}</div>}
|
|
158
|
+
<h1 className="text-lg font-semibold text-kumo-default">
|
|
159
|
+
{title ?? (isSignUp ? labels.signUpTitle : labels.signInTitle)}
|
|
160
|
+
</h1>
|
|
161
|
+
{description && (
|
|
162
|
+
<p className="text-sm text-kumo-subtle">{description}</p>
|
|
163
|
+
)}
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
{error && (
|
|
167
|
+
<div role="alert">
|
|
168
|
+
<Banner
|
|
169
|
+
variant="error"
|
|
170
|
+
size="sm"
|
|
171
|
+
icon={<WarningCircleIcon />}
|
|
172
|
+
description={error}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
)}
|
|
176
|
+
|
|
177
|
+
{providerContent && (
|
|
178
|
+
<>
|
|
179
|
+
<div className="flex flex-col gap-2">{providerContent}</div>
|
|
180
|
+
<div className="flex items-center gap-3 text-xs text-kumo-subtle">
|
|
181
|
+
<span className="h-px flex-1 bg-kumo-line" />
|
|
182
|
+
{labels.divider}
|
|
183
|
+
<span className="h-px flex-1 bg-kumo-line" />
|
|
184
|
+
</div>
|
|
185
|
+
</>
|
|
186
|
+
)}
|
|
187
|
+
|
|
188
|
+
<form className="flex flex-col gap-3" onSubmit={handleSubmit}>
|
|
189
|
+
{isSignUp && (
|
|
190
|
+
<Input
|
|
191
|
+
label={labels.name}
|
|
192
|
+
name="name"
|
|
193
|
+
autoComplete="name"
|
|
194
|
+
required
|
|
195
|
+
disabled={loading}
|
|
196
|
+
/>
|
|
197
|
+
)}
|
|
198
|
+
<Input
|
|
199
|
+
label={labels.email}
|
|
200
|
+
name="email"
|
|
201
|
+
type="email"
|
|
202
|
+
autoComplete="email"
|
|
203
|
+
placeholder="you@example.com"
|
|
204
|
+
required
|
|
205
|
+
disabled={loading}
|
|
206
|
+
/>
|
|
207
|
+
{hasPassword && (
|
|
208
|
+
<Input
|
|
209
|
+
label={labels.password}
|
|
210
|
+
name="password"
|
|
211
|
+
type="password"
|
|
212
|
+
autoComplete={isSignUp ? "new-password" : "current-password"}
|
|
213
|
+
required
|
|
214
|
+
disabled={loading}
|
|
215
|
+
/>
|
|
216
|
+
)}
|
|
217
|
+
<Button
|
|
218
|
+
type="submit"
|
|
219
|
+
variant="primary"
|
|
220
|
+
loading={loading}
|
|
221
|
+
className="w-full justify-center"
|
|
222
|
+
>
|
|
223
|
+
{submitLabel}
|
|
224
|
+
</Button>
|
|
225
|
+
</form>
|
|
226
|
+
|
|
227
|
+
{footer && (
|
|
228
|
+
<div className="text-center text-sm text-kumo-subtle">{footer}</div>
|
|
229
|
+
)}
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
AuthCard.displayName = "AuthCard";
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Link } from "../../components/link";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
import { ActivityFeed, type ActivityFeedProps } from "../activity-feed";
|
|
5
|
+
import { FileTable, type FileItem } from "../file-table";
|
|
6
|
+
import {
|
|
7
|
+
OnboardingChecklist,
|
|
8
|
+
type OnboardingChecklistProps,
|
|
9
|
+
} from "../onboarding-checklist";
|
|
10
|
+
import { StatGrid, type StatProps } from "../stat-grid";
|
|
11
|
+
|
|
12
|
+
export interface DashboardPageLabels {
|
|
13
|
+
recent: string;
|
|
14
|
+
activity: string;
|
|
15
|
+
viewAll: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DEFAULT_LABELS: DashboardPageLabels = {
|
|
19
|
+
recent: "Recent files",
|
|
20
|
+
activity: "Activity",
|
|
21
|
+
viewAll: "View all",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface DashboardPageProps {
|
|
25
|
+
/** e.g. "Good morning, Ada". */
|
|
26
|
+
title: ReactNode;
|
|
27
|
+
description?: ReactNode;
|
|
28
|
+
/** Header buttons, e.g. Upload and New folder. */
|
|
29
|
+
actions?: ReactNode;
|
|
30
|
+
stats?: StatProps[];
|
|
31
|
+
/** Shown above the activity feed until the user dismisses it. */
|
|
32
|
+
onboarding?: OnboardingChecklistProps;
|
|
33
|
+
recentFiles?: FileItem[];
|
|
34
|
+
onOpenFile?: (item: FileItem) => void;
|
|
35
|
+
/** "View all" link next to Recent files. */
|
|
36
|
+
allFilesHref?: string;
|
|
37
|
+
activity?: Omit<ActivityFeedProps, "className">;
|
|
38
|
+
/** Extra content under Recent files. */
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
labels?: Partial<DashboardPageLabels>;
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Panel({
|
|
45
|
+
title,
|
|
46
|
+
action,
|
|
47
|
+
children,
|
|
48
|
+
}: {
|
|
49
|
+
title: string;
|
|
50
|
+
action?: ReactNode;
|
|
51
|
+
children: ReactNode;
|
|
52
|
+
}) {
|
|
53
|
+
return (
|
|
54
|
+
<section className="flex min-w-0 flex-col gap-2">
|
|
55
|
+
<header className="flex items-center justify-between gap-2">
|
|
56
|
+
<h2 className="m-0 text-sm font-semibold text-kumo-strong">{title}</h2>
|
|
57
|
+
{action}
|
|
58
|
+
</header>
|
|
59
|
+
{children}
|
|
60
|
+
</section>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* DashboardPage: the first screen after sign-in. A header, stats, recent
|
|
66
|
+
* files, and a side column with onboarding and activity. Render it inside
|
|
67
|
+
* `AppShell`; every section is optional.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <AppShell nav={nav} header="Home">
|
|
72
|
+
* <DashboardPage
|
|
73
|
+
* title="Good morning, Ada"
|
|
74
|
+
* actions={<Button variant="primary">Upload</Button>}
|
|
75
|
+
* stats={[{ label: "Files", value: "1,284" }]}
|
|
76
|
+
* recentFiles={files}
|
|
77
|
+
* activity={{ events }}
|
|
78
|
+
* />
|
|
79
|
+
* </AppShell>
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function DashboardPage({
|
|
83
|
+
title,
|
|
84
|
+
description,
|
|
85
|
+
actions,
|
|
86
|
+
stats,
|
|
87
|
+
onboarding,
|
|
88
|
+
recentFiles,
|
|
89
|
+
onOpenFile,
|
|
90
|
+
allFilesHref,
|
|
91
|
+
activity,
|
|
92
|
+
children,
|
|
93
|
+
labels: labelsProp,
|
|
94
|
+
className,
|
|
95
|
+
}: DashboardPageProps) {
|
|
96
|
+
const labels = { ...DEFAULT_LABELS, ...labelsProp };
|
|
97
|
+
const hasSide = Boolean(onboarding || activity);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
className={cn(
|
|
102
|
+
"@container mx-auto flex w-full max-w-6xl flex-col gap-5 p-4 md:p-6",
|
|
103
|
+
className,
|
|
104
|
+
)}
|
|
105
|
+
>
|
|
106
|
+
<header className="flex flex-wrap items-end justify-between gap-3">
|
|
107
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
108
|
+
<h1 className="m-0 text-xl font-semibold text-kumo-strong">
|
|
109
|
+
{title}
|
|
110
|
+
</h1>
|
|
111
|
+
{description && (
|
|
112
|
+
<p className="m-0 text-sm text-kumo-subtle">{description}</p>
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
|
116
|
+
</header>
|
|
117
|
+
|
|
118
|
+
{stats && stats.length > 0 && (
|
|
119
|
+
<StatGrid
|
|
120
|
+
items={stats}
|
|
121
|
+
columns={Math.min(4, Math.max(2, stats.length)) as 2 | 3 | 4}
|
|
122
|
+
/>
|
|
123
|
+
)}
|
|
124
|
+
|
|
125
|
+
<div
|
|
126
|
+
className={cn(
|
|
127
|
+
"grid grid-cols-1 gap-5",
|
|
128
|
+
// Container query: the side column only appears when the page itself is wide,
|
|
129
|
+
// not just the viewport (it usually sits inside AppShell).
|
|
130
|
+
hasSide && "@4xl:grid-cols-[minmax(0,1fr)_18rem]",
|
|
131
|
+
)}
|
|
132
|
+
>
|
|
133
|
+
<div className="flex min-w-0 flex-col gap-5">
|
|
134
|
+
{recentFiles && (
|
|
135
|
+
<Panel
|
|
136
|
+
title={labels.recent}
|
|
137
|
+
action={
|
|
138
|
+
allFilesHref && (
|
|
139
|
+
<Link href={allFilesHref} className="text-sm">
|
|
140
|
+
{labels.viewAll}
|
|
141
|
+
</Link>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
>
|
|
145
|
+
<FileTable
|
|
146
|
+
items={recentFiles}
|
|
147
|
+
selectable={false}
|
|
148
|
+
onOpen={onOpenFile}
|
|
149
|
+
/>
|
|
150
|
+
</Panel>
|
|
151
|
+
)}
|
|
152
|
+
{children}
|
|
153
|
+
</div>
|
|
154
|
+
{hasSide && (
|
|
155
|
+
<aside className="flex min-w-0 flex-col gap-5">
|
|
156
|
+
{onboarding && <OnboardingChecklist {...onboarding} />}
|
|
157
|
+
{activity && (
|
|
158
|
+
<Panel title={labels.activity}>
|
|
159
|
+
<ActivityFeed {...activity} />
|
|
160
|
+
</Panel>
|
|
161
|
+
)}
|
|
162
|
+
</aside>
|
|
163
|
+
)}
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { DashboardPage } from "../dashboard-page";
|
|
4
|
+
import { LoginPage } from "../login-page";
|
|
5
|
+
import { ErrorPage } from "./error-page";
|
|
6
|
+
|
|
7
|
+
describe("ErrorPage", () => {
|
|
8
|
+
it("uses default copy for the status and links home", () => {
|
|
9
|
+
render(
|
|
10
|
+
<ErrorPage status={404} homeHref="/files" homeLabel="Back to files" />,
|
|
11
|
+
);
|
|
12
|
+
expect(
|
|
13
|
+
screen.getByRole("heading", { name: "Page not found" }),
|
|
14
|
+
).toBeTruthy();
|
|
15
|
+
expect(
|
|
16
|
+
screen.getByRole("link", { name: "Back to files" }).getAttribute("href"),
|
|
17
|
+
).toBe("/files");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("falls back to the 500 copy for unknown statuses and can hide the home link", () => {
|
|
21
|
+
render(<ErrorPage status={502} homeHref={null} />);
|
|
22
|
+
expect(
|
|
23
|
+
screen.getByRole("heading", { name: "Something went wrong" }),
|
|
24
|
+
).toBeTruthy();
|
|
25
|
+
expect(screen.queryByRole("link")).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("LoginPage", () => {
|
|
30
|
+
it("wraps AuthCard with logo and legal text", () => {
|
|
31
|
+
render(
|
|
32
|
+
<LoginPage
|
|
33
|
+
logo={<span>fldr</span>}
|
|
34
|
+
legal="By continuing you agree."
|
|
35
|
+
onSubmit={() => {}}
|
|
36
|
+
/>,
|
|
37
|
+
);
|
|
38
|
+
expect(screen.getByText("fldr")).toBeTruthy();
|
|
39
|
+
expect(screen.getByText("By continuing you agree.")).toBeTruthy();
|
|
40
|
+
expect(screen.getByLabelText(/email/i)).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("DashboardPage", () => {
|
|
45
|
+
it("renders only the sections it is given", () => {
|
|
46
|
+
render(
|
|
47
|
+
<DashboardPage
|
|
48
|
+
title="Good morning, Ada"
|
|
49
|
+
stats={[{ label: "Files", value: "1,284" }]}
|
|
50
|
+
recentFiles={[{ id: "1", name: "w2.pdf", kind: "pdf" }]}
|
|
51
|
+
/>,
|
|
52
|
+
);
|
|
53
|
+
expect(
|
|
54
|
+
screen.getByRole("heading", { name: "Good morning, Ada" }),
|
|
55
|
+
).toBeTruthy();
|
|
56
|
+
expect(screen.getByText("1,284")).toBeTruthy();
|
|
57
|
+
expect(screen.getByText("w2.pdf")).toBeTruthy();
|
|
58
|
+
expect(screen.queryByText("Activity")).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
});
|