@fldr/ui 0.3.5 → 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/THEMING.md +1 -1
- package/ai/component-registry.json +962 -43
- package/ai/component-registry.md +1 -1
- package/dist/.build-complete +1 -1
- 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/chunks/{tabs-o59bv7348nh2gppm.js → tabs-cja62qojznpj99et.js} +2 -0
- package/dist/components/tabs.js +1 -1
- package/dist/delete-resource-DY-GFy2s.d.ts +48 -0
- package/dist/index.d.ts +4 -50
- package/dist/index.js +2 -147
- package/dist/primitives.d.ts +1 -1
- package/dist/styles/kumo-standalone.css +1 -1
- package/dist/styles/theme-fldr.css +12 -0
- package/dist/theming.d.ts +29 -2
- package/dist/theming.js +19 -4
- package/package.json +5 -1
package/ai/component-registry.md
CHANGED
|
@@ -11922,7 +11922,7 @@ Multi-line textarea input with Input variants and InputArea-specific dimensions
|
|
|
11922
11922
|
## Quick Reference
|
|
11923
11923
|
|
|
11924
11924
|
**Components by Category:**
|
|
11925
|
-
- **Other:** Autocomplete, CloudflareLogo, DatePicker, Label, Link, SensitiveInput, Sidebar, Table, TableOfContents, TagInput, Toolbar, DeleteResource
|
|
11925
|
+
- **Other:** Autocomplete, CloudflareLogo, DatePicker, Label, Link, SensitiveInput, Sidebar, Table, TableOfContents, TagInput, Toolbar, ActivityFeed, AppShell, AuthCard, DashboardPage, DeleteResource, ErrorPage, FileTable, FolderGrid, LoginPage, OnboardingChecklist, SettingsSection, ShareDialog, StatGrid, UploadDropzone
|
|
11926
11926
|
- **Display:** Badge, Breadcrumbs, Code, Collapsible, Empty, LayerCard, Meter, Text
|
|
11927
11927
|
- **Feedback:** Banner, Loader, Toasty
|
|
11928
11928
|
- **Data Visualization:** BubbleMap, Chart, ChoroplethMap, GlobeMap, SankeyChart, TimeseriesChart
|
package/dist/.build-complete
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1795501735681
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vite-plus/test";
|
|
3
|
+
import {
|
|
4
|
+
ActivityFeed,
|
|
5
|
+
formatActivityTime,
|
|
6
|
+
type ActivityEvent,
|
|
7
|
+
} from "./activity-feed";
|
|
8
|
+
|
|
9
|
+
const now = new Date(2026, 10, 23, 12, 0, 0);
|
|
10
|
+
const at = (days: number, hours = 0) =>
|
|
11
|
+
new Date(now.getTime() - days * 86400000 - hours * 3600000);
|
|
12
|
+
|
|
13
|
+
const events: ActivityEvent[] = [
|
|
14
|
+
{
|
|
15
|
+
id: "1",
|
|
16
|
+
actor: { name: "Ada Lovelace" },
|
|
17
|
+
action: "uploaded",
|
|
18
|
+
kind: "upload",
|
|
19
|
+
target: { label: "receipt-0412.pdf", href: "/f/1" },
|
|
20
|
+
timestamp: at(0, 2),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "2",
|
|
24
|
+
actor: { name: "Grace Hopper" },
|
|
25
|
+
action: "shared",
|
|
26
|
+
kind: "share",
|
|
27
|
+
target: { label: "Taxes 2026" },
|
|
28
|
+
timestamp: at(1),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "3",
|
|
32
|
+
actor: { name: "Alan Turing" },
|
|
33
|
+
action: "deleted",
|
|
34
|
+
kind: "delete",
|
|
35
|
+
target: { label: "old.pdf" },
|
|
36
|
+
timestamp: at(5),
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
describe("ActivityFeed", () => {
|
|
41
|
+
it("formats relative time", () => {
|
|
42
|
+
expect(formatActivityTime(at(0, 2), now, "en")).toBe("2 hours ago");
|
|
43
|
+
expect(formatActivityTime(at(1), now, "en")).toBe("yesterday");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("groups events by day", () => {
|
|
47
|
+
render(
|
|
48
|
+
<ActivityFeed events={events} now={now} locale="en-US" groupByDay />,
|
|
49
|
+
);
|
|
50
|
+
expect(screen.getByRole("heading", { name: "Today" })).toBeDefined();
|
|
51
|
+
expect(screen.getByRole("heading", { name: "Yesterday" })).toBeDefined();
|
|
52
|
+
expect(screen.getByRole("heading", { name: "Nov 18" })).toBeDefined();
|
|
53
|
+
expect(
|
|
54
|
+
screen
|
|
55
|
+
.getByRole("link", { name: "receipt-0412.pdf" })
|
|
56
|
+
.getAttribute("href"),
|
|
57
|
+
).toBe("/f/1");
|
|
58
|
+
expect(screen.getByText("AL")).toBeDefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("calls onLoadMore", () => {
|
|
62
|
+
const onLoadMore = vi.fn();
|
|
63
|
+
render(
|
|
64
|
+
<ActivityFeed
|
|
65
|
+
events={events}
|
|
66
|
+
now={now}
|
|
67
|
+
onLoadMore={onLoadMore}
|
|
68
|
+
labels={{ loadMore: "Older" }}
|
|
69
|
+
/>,
|
|
70
|
+
);
|
|
71
|
+
expect(screen.queryByRole("heading")).toBeNull();
|
|
72
|
+
fireEvent.click(screen.getByRole("button", { name: "Older" }));
|
|
73
|
+
expect(onLoadMore).toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import {
|
|
3
|
+
ArrowsLeftRightIcon,
|
|
4
|
+
ChatCircleIcon,
|
|
5
|
+
PencilSimpleIcon,
|
|
6
|
+
ShareNetworkIcon,
|
|
7
|
+
TrashIcon,
|
|
8
|
+
UploadSimpleIcon,
|
|
9
|
+
type Icon,
|
|
10
|
+
} from "@phosphor-icons/react";
|
|
11
|
+
import { Button } from "../../components/button";
|
|
12
|
+
import { cn } from "../../utils/cn";
|
|
13
|
+
|
|
14
|
+
export type ActivityKind =
|
|
15
|
+
| "upload"
|
|
16
|
+
| "share"
|
|
17
|
+
| "comment"
|
|
18
|
+
| "delete"
|
|
19
|
+
| "rename"
|
|
20
|
+
| "move";
|
|
21
|
+
|
|
22
|
+
export interface ActivityTarget {
|
|
23
|
+
label: string;
|
|
24
|
+
href?: string;
|
|
25
|
+
onClick?: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ActivityEvent {
|
|
29
|
+
id: string;
|
|
30
|
+
actor: { name: string; avatarUrl?: string };
|
|
31
|
+
/** Verb phrase, e.g. "uploaded" or "shared". */
|
|
32
|
+
action: string;
|
|
33
|
+
target?: ActivityTarget;
|
|
34
|
+
timestamp: Date | string | number;
|
|
35
|
+
kind?: ActivityKind;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ActivityFeedLabels {
|
|
39
|
+
today: string;
|
|
40
|
+
yesterday: string;
|
|
41
|
+
loadMore: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ActivityFeedProps {
|
|
45
|
+
events: ActivityEvent[];
|
|
46
|
+
/** Group rows under "Today", "Yesterday" and date headings. */
|
|
47
|
+
groupByDay?: boolean;
|
|
48
|
+
/** Shows a "Load more" button when provided. */
|
|
49
|
+
onLoadMore?: () => void;
|
|
50
|
+
loadingMore?: boolean;
|
|
51
|
+
/** Replaces the default "Load more" button. */
|
|
52
|
+
footer?: ReactNode;
|
|
53
|
+
/** Reference time for relative formatting. Defaults to the current time. */
|
|
54
|
+
now?: Date;
|
|
55
|
+
locale?: string;
|
|
56
|
+
labels?: Partial<ActivityFeedLabels>;
|
|
57
|
+
className?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const DEFAULT_LABELS: ActivityFeedLabels = {
|
|
61
|
+
today: "Today",
|
|
62
|
+
yesterday: "Yesterday",
|
|
63
|
+
loadMore: "Load more",
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const KIND_ICONS: Record<ActivityKind, Icon> = {
|
|
67
|
+
upload: UploadSimpleIcon,
|
|
68
|
+
share: ShareNetworkIcon,
|
|
69
|
+
comment: ChatCircleIcon,
|
|
70
|
+
delete: TrashIcon,
|
|
71
|
+
rename: PencilSimpleIcon,
|
|
72
|
+
move: ArrowsLeftRightIcon,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const UNITS: [Intl.RelativeTimeFormatUnit, number][] = [
|
|
76
|
+
["year", 31536000],
|
|
77
|
+
["month", 2592000],
|
|
78
|
+
["week", 604800],
|
|
79
|
+
["day", 86400],
|
|
80
|
+
["hour", 3600],
|
|
81
|
+
["minute", 60],
|
|
82
|
+
["second", 1],
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
/** Formats `date` relative to `now`, e.g. "5 minutes ago". */
|
|
86
|
+
export function formatActivityTime(date: Date, now: Date, locale?: string) {
|
|
87
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
88
|
+
const seconds = Math.round((date.getTime() - now.getTime()) / 1000);
|
|
89
|
+
for (const [unit, size] of UNITS) {
|
|
90
|
+
if (Math.abs(seconds) >= size || unit === "second") {
|
|
91
|
+
return rtf.format(Math.round(seconds / size), unit);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const dayKey = (d: Date) => `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
|
|
98
|
+
|
|
99
|
+
function dayLabel(d: Date, now: Date, l: ActivityFeedLabels, locale?: string) {
|
|
100
|
+
const yesterday = new Date(now);
|
|
101
|
+
yesterday.setDate(now.getDate() - 1);
|
|
102
|
+
if (dayKey(d) === dayKey(now)) return l.today;
|
|
103
|
+
if (dayKey(d) === dayKey(yesterday)) return l.yesterday;
|
|
104
|
+
return d.toLocaleDateString(locale, {
|
|
105
|
+
month: "short",
|
|
106
|
+
day: "numeric",
|
|
107
|
+
year: d.getFullYear() === now.getFullYear() ? undefined : "numeric",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const initials = (name: string) =>
|
|
112
|
+
name
|
|
113
|
+
.split(/\s+/)
|
|
114
|
+
.filter(Boolean)
|
|
115
|
+
.slice(0, 2)
|
|
116
|
+
.map((p) => p[0]?.toUpperCase())
|
|
117
|
+
.join("");
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Compact vertical timeline of file and folder activity.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```tsx
|
|
124
|
+
* <ActivityFeed
|
|
125
|
+
* groupByDay
|
|
126
|
+
* events={[{ id: "1", actor: { name: "Ada Lovelace" }, action: "uploaded",
|
|
127
|
+
* target: { label: "receipt-0412.pdf", href: "/f/1" }, kind: "upload",
|
|
128
|
+
* timestamp: new Date() }]}
|
|
129
|
+
* onLoadMore={fetchOlder}
|
|
130
|
+
* />
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function ActivityFeed({
|
|
134
|
+
events,
|
|
135
|
+
groupByDay = false,
|
|
136
|
+
onLoadMore,
|
|
137
|
+
loadingMore = false,
|
|
138
|
+
footer,
|
|
139
|
+
now = new Date(),
|
|
140
|
+
locale,
|
|
141
|
+
labels,
|
|
142
|
+
className,
|
|
143
|
+
}: ActivityFeedProps) {
|
|
144
|
+
const l = { ...DEFAULT_LABELS, ...labels };
|
|
145
|
+
const groups: { key: string; label?: string; items: ActivityEvent[] }[] = [];
|
|
146
|
+
for (const event of events) {
|
|
147
|
+
const date = new Date(event.timestamp);
|
|
148
|
+
const key = groupByDay ? dayKey(date) : "all";
|
|
149
|
+
const last = groups[groups.length - 1];
|
|
150
|
+
if (last?.key === key) last.items.push(event);
|
|
151
|
+
else
|
|
152
|
+
groups.push({
|
|
153
|
+
key,
|
|
154
|
+
label: groupByDay ? dayLabel(date, now, l, locale) : undefined,
|
|
155
|
+
items: [event],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div className={cn("flex flex-col gap-4", className)}>
|
|
161
|
+
{groups.map((group) => (
|
|
162
|
+
<section key={group.key} className="flex flex-col gap-1">
|
|
163
|
+
{group.label && (
|
|
164
|
+
<h3 className="m-0 px-1 text-xs font-medium text-kumo-subtle">
|
|
165
|
+
{group.label}
|
|
166
|
+
</h3>
|
|
167
|
+
)}
|
|
168
|
+
<ol className="m-0 flex list-none flex-col p-0">
|
|
169
|
+
{group.items.map((event) => {
|
|
170
|
+
const date = new Date(event.timestamp);
|
|
171
|
+
const KindIcon = event.kind ? KIND_ICONS[event.kind] : null;
|
|
172
|
+
const { target } = event;
|
|
173
|
+
const targetClass =
|
|
174
|
+
"font-medium text-kumo-link hover:underline cursor-pointer";
|
|
175
|
+
return (
|
|
176
|
+
<li
|
|
177
|
+
key={event.id}
|
|
178
|
+
className="flex items-center gap-2.5 rounded-md px-1 py-1.5 text-sm"
|
|
179
|
+
>
|
|
180
|
+
{event.actor.avatarUrl ? (
|
|
181
|
+
<img
|
|
182
|
+
src={event.actor.avatarUrl}
|
|
183
|
+
alt=""
|
|
184
|
+
className="size-6 shrink-0 rounded-full bg-kumo-recessed object-cover"
|
|
185
|
+
/>
|
|
186
|
+
) : (
|
|
187
|
+
<span
|
|
188
|
+
aria-hidden
|
|
189
|
+
className="flex size-6 shrink-0 items-center justify-center rounded-full bg-kumo-recessed text-[10px] font-medium text-kumo-subtle"
|
|
190
|
+
>
|
|
191
|
+
{initials(event.actor.name)}
|
|
192
|
+
</span>
|
|
193
|
+
)}
|
|
194
|
+
<span className="min-w-0 grow truncate text-kumo-subtle">
|
|
195
|
+
<span className="font-medium text-kumo-default">
|
|
196
|
+
{event.actor.name}
|
|
197
|
+
</span>{" "}
|
|
198
|
+
{event.action}
|
|
199
|
+
{target && " "}
|
|
200
|
+
{target?.href ? (
|
|
201
|
+
<a
|
|
202
|
+
href={target.href}
|
|
203
|
+
onClick={target.onClick}
|
|
204
|
+
className={targetClass}
|
|
205
|
+
>
|
|
206
|
+
{target.label}
|
|
207
|
+
</a>
|
|
208
|
+
) : target?.onClick ? (
|
|
209
|
+
<button
|
|
210
|
+
type="button"
|
|
211
|
+
onClick={target.onClick}
|
|
212
|
+
className={targetClass}
|
|
213
|
+
>
|
|
214
|
+
{target.label}
|
|
215
|
+
</button>
|
|
216
|
+
) : target ? (
|
|
217
|
+
<span className="font-medium text-kumo-default">
|
|
218
|
+
{target.label}
|
|
219
|
+
</span>
|
|
220
|
+
) : null}
|
|
221
|
+
</span>
|
|
222
|
+
{KindIcon && (
|
|
223
|
+
<KindIcon
|
|
224
|
+
size={14}
|
|
225
|
+
aria-hidden
|
|
226
|
+
className="shrink-0 text-kumo-subtle"
|
|
227
|
+
/>
|
|
228
|
+
)}
|
|
229
|
+
<time
|
|
230
|
+
dateTime={date.toISOString()}
|
|
231
|
+
title={date.toLocaleString(locale)}
|
|
232
|
+
className="shrink-0 text-xs text-kumo-subtle tabular-nums"
|
|
233
|
+
>
|
|
234
|
+
{formatActivityTime(date, now, locale)}
|
|
235
|
+
</time>
|
|
236
|
+
</li>
|
|
237
|
+
);
|
|
238
|
+
})}
|
|
239
|
+
</ol>
|
|
240
|
+
</section>
|
|
241
|
+
))}
|
|
242
|
+
{footer ??
|
|
243
|
+
(onLoadMore && (
|
|
244
|
+
<Button
|
|
245
|
+
size="sm"
|
|
246
|
+
variant="ghost"
|
|
247
|
+
className="self-start"
|
|
248
|
+
loading={loadingMore}
|
|
249
|
+
onClick={onLoadMore}
|
|
250
|
+
>
|
|
251
|
+
{l.loadMore}
|
|
252
|
+
</Button>
|
|
253
|
+
))}
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
if (!HTMLElement.prototype.getAnimations) {
|
|
2
|
+
HTMLElement.prototype.getAnimations = () => [];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
6
|
+
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
|
7
|
+
import { Sidebar } from "../../components/sidebar";
|
|
8
|
+
import { AppShell, type AppShellProps } from "./app-shell";
|
|
9
|
+
|
|
10
|
+
function mockMatchMedia(mobile: boolean) {
|
|
11
|
+
Object.defineProperty(window, "matchMedia", {
|
|
12
|
+
writable: true,
|
|
13
|
+
value: vi.fn().mockImplementation((query: string) => ({
|
|
14
|
+
matches: query.includes("prefers-reduced-motion") ? true : mobile,
|
|
15
|
+
media: query,
|
|
16
|
+
onchange: null,
|
|
17
|
+
addListener: vi.fn(),
|
|
18
|
+
removeListener: vi.fn(),
|
|
19
|
+
addEventListener: vi.fn(),
|
|
20
|
+
removeEventListener: vi.fn(),
|
|
21
|
+
dispatchEvent: vi.fn(),
|
|
22
|
+
})),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function renderShell(props: Partial<AppShellProps> = {}) {
|
|
27
|
+
return render(
|
|
28
|
+
<AppShell
|
|
29
|
+
brand={<span>fldr</span>}
|
|
30
|
+
nav={
|
|
31
|
+
<Sidebar.Menu>
|
|
32
|
+
<Sidebar.MenuButton active>All files</Sidebar.MenuButton>
|
|
33
|
+
<Sidebar.MenuButton>Receipts</Sidebar.MenuButton>
|
|
34
|
+
</Sidebar.Menu>
|
|
35
|
+
}
|
|
36
|
+
sidebarFooter={<span>ada@fldr.app</span>}
|
|
37
|
+
header="All files"
|
|
38
|
+
actions={<button type="button">Upload</button>}
|
|
39
|
+
{...props}
|
|
40
|
+
>
|
|
41
|
+
<p>Folder contents</p>
|
|
42
|
+
</AppShell>,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe("AppShell", () => {
|
|
47
|
+
beforeEach(() => mockMatchMedia(false));
|
|
48
|
+
|
|
49
|
+
it("renders all slots", () => {
|
|
50
|
+
renderShell();
|
|
51
|
+
expect(screen.getByText("fldr")).toBeTruthy();
|
|
52
|
+
expect(screen.getByText("Receipts")).toBeTruthy();
|
|
53
|
+
expect(screen.getByText("ada@fldr.app")).toBeTruthy();
|
|
54
|
+
expect(screen.getByRole("button", { name: "Upload" })).toBeTruthy();
|
|
55
|
+
expect(screen.getByRole("main").textContent).toContain("Folder contents");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("collapses the sidebar from the top-bar toggle", () => {
|
|
59
|
+
const onOpenChange = vi.fn();
|
|
60
|
+
renderShell({ onOpenChange, toggleLabel: "Toggle navigation" });
|
|
61
|
+
const toggle = screen.getByRole("button", { name: "Toggle navigation" });
|
|
62
|
+
fireEvent.click(toggle);
|
|
63
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("opens the sidebar as a drawer on narrow screens", () => {
|
|
67
|
+
mockMatchMedia(true);
|
|
68
|
+
const { container } = renderShell();
|
|
69
|
+
const drawer = container.querySelector('[data-mobile="true"]');
|
|
70
|
+
expect(drawer?.getAttribute("aria-hidden")).toBe("true");
|
|
71
|
+
fireEvent.click(screen.getByRole("button", { name: /sidebar/i }));
|
|
72
|
+
expect(drawer?.getAttribute("aria-hidden")).toBe("false");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -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
|
+
});
|