@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
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
|
package/dist/ai/schemas.d.ts
CHANGED
|
@@ -224,8 +224,8 @@ export declare const ButtonPropsSchema: z.ZodObject<{
|
|
|
224
224
|
}>>;
|
|
225
225
|
size: z.ZodOptional<z.ZodEnum<{
|
|
226
226
|
base: "base";
|
|
227
|
-
xs: "xs";
|
|
228
227
|
sm: "sm";
|
|
228
|
+
xs: "xs";
|
|
229
229
|
lg: "lg";
|
|
230
230
|
}>>;
|
|
231
231
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -675,8 +675,8 @@ export declare const CollapsiblePropsSchema: z.ZodObject<{
|
|
|
675
675
|
export declare const ComboboxPropsSchema: z.ZodObject<{
|
|
676
676
|
size: z.ZodOptional<z.ZodEnum<{
|
|
677
677
|
base: "base";
|
|
678
|
-
xs: "xs";
|
|
679
678
|
sm: "sm";
|
|
679
|
+
xs: "xs";
|
|
680
680
|
lg: "lg";
|
|
681
681
|
}>>;
|
|
682
682
|
inputSide: z.ZodOptional<z.ZodEnum<{
|
|
@@ -888,8 +888,8 @@ export declare const InputPropsSchema: z.ZodObject<{
|
|
|
888
888
|
passwordManagerIgnore: z.ZodOptional<z.ZodBoolean>;
|
|
889
889
|
size: z.ZodOptional<z.ZodEnum<{
|
|
890
890
|
base: "base";
|
|
891
|
-
xs: "xs";
|
|
892
891
|
sm: "sm";
|
|
892
|
+
xs: "xs";
|
|
893
893
|
lg: "lg";
|
|
894
894
|
}>>;
|
|
895
895
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -900,8 +900,8 @@ export declare const InputPropsSchema: z.ZodObject<{
|
|
|
900
900
|
export declare const InputAreaPropsSchema: z.ZodObject<{
|
|
901
901
|
size: z.ZodOptional<z.ZodEnum<{
|
|
902
902
|
base: "base";
|
|
903
|
-
xs: "xs";
|
|
904
903
|
sm: "sm";
|
|
904
|
+
xs: "xs";
|
|
905
905
|
lg: "lg";
|
|
906
906
|
}>>;
|
|
907
907
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -944,8 +944,8 @@ export declare const InputGroupPropsSchema: z.ZodObject<{
|
|
|
944
944
|
title: z.ZodOptional<z.ZodString>;
|
|
945
945
|
size: z.ZodOptional<z.ZodEnum<{
|
|
946
946
|
base: "base";
|
|
947
|
-
xs: "xs";
|
|
948
947
|
sm: "sm";
|
|
948
|
+
xs: "xs";
|
|
949
949
|
lg: "lg";
|
|
950
950
|
}>>;
|
|
951
951
|
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1145,8 +1145,8 @@ export declare const SelectPropsSchema: z.ZodObject<{
|
|
|
1145
1145
|
}, z.core.$strip>]>]>>;
|
|
1146
1146
|
size: z.ZodOptional<z.ZodEnum<{
|
|
1147
1147
|
base: "base";
|
|
1148
|
-
xs: "xs";
|
|
1149
1148
|
sm: "sm";
|
|
1149
|
+
xs: "xs";
|
|
1150
1150
|
lg: "lg";
|
|
1151
1151
|
}>>;
|
|
1152
1152
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodObject<{
|
|
@@ -1196,8 +1196,8 @@ export declare const SensitiveInputPropsSchema: z.ZodObject<{
|
|
|
1196
1196
|
value: z.ZodOptional<z.ZodString>;
|
|
1197
1197
|
size: z.ZodOptional<z.ZodEnum<{
|
|
1198
1198
|
base: "base";
|
|
1199
|
-
xs: "xs";
|
|
1200
1199
|
sm: "sm";
|
|
1200
|
+
xs: "xs";
|
|
1201
1201
|
lg: "lg";
|
|
1202
1202
|
}>>;
|
|
1203
1203
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -1410,8 +1410,8 @@ export declare const TextPropsSchema: z.ZodObject<{
|
|
|
1410
1410
|
}>>;
|
|
1411
1411
|
size: z.ZodOptional<z.ZodEnum<{
|
|
1412
1412
|
base: "base";
|
|
1413
|
-
xs: "xs";
|
|
1414
1413
|
sm: "sm";
|
|
1414
|
+
xs: "xs";
|
|
1415
1415
|
lg: "lg";
|
|
1416
1416
|
}>>;
|
|
1417
1417
|
bold: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1502,8 +1502,8 @@ export declare const ToolbarPropsSchema: z.ZodObject<{
|
|
|
1502
1502
|
}, z.core.$strip>]>]>>;
|
|
1503
1503
|
size: z.ZodOptional<z.ZodEnum<{
|
|
1504
1504
|
base: "base";
|
|
1505
|
-
xs: "xs";
|
|
1506
1505
|
sm: "sm";
|
|
1506
|
+
xs: "xs";
|
|
1507
1507
|
lg: "lg";
|
|
1508
1508
|
}>>;
|
|
1509
1509
|
}, z.core.$strip>;
|
|
@@ -1712,8 +1712,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
1712
1712
|
}>>;
|
|
1713
1713
|
size: z.ZodOptional<z.ZodEnum<{
|
|
1714
1714
|
base: "base";
|
|
1715
|
-
xs: "xs";
|
|
1716
1715
|
sm: "sm";
|
|
1716
|
+
xs: "xs";
|
|
1717
1717
|
lg: "lg";
|
|
1718
1718
|
}>>;
|
|
1719
1719
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -2163,8 +2163,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2163
2163
|
readonly Combobox: z.ZodObject<{
|
|
2164
2164
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2165
2165
|
base: "base";
|
|
2166
|
-
xs: "xs";
|
|
2167
2166
|
sm: "sm";
|
|
2167
|
+
xs: "xs";
|
|
2168
2168
|
lg: "lg";
|
|
2169
2169
|
}>>;
|
|
2170
2170
|
inputSide: z.ZodOptional<z.ZodEnum<{
|
|
@@ -2376,8 +2376,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2376
2376
|
passwordManagerIgnore: z.ZodOptional<z.ZodBoolean>;
|
|
2377
2377
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2378
2378
|
base: "base";
|
|
2379
|
-
xs: "xs";
|
|
2380
2379
|
sm: "sm";
|
|
2380
|
+
xs: "xs";
|
|
2381
2381
|
lg: "lg";
|
|
2382
2382
|
}>>;
|
|
2383
2383
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -2388,8 +2388,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2388
2388
|
readonly InputArea: z.ZodObject<{
|
|
2389
2389
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2390
2390
|
base: "base";
|
|
2391
|
-
xs: "xs";
|
|
2392
2391
|
sm: "sm";
|
|
2392
|
+
xs: "xs";
|
|
2393
2393
|
lg: "lg";
|
|
2394
2394
|
}>>;
|
|
2395
2395
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -2432,8 +2432,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2432
2432
|
title: z.ZodOptional<z.ZodString>;
|
|
2433
2433
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2434
2434
|
base: "base";
|
|
2435
|
-
xs: "xs";
|
|
2436
2435
|
sm: "sm";
|
|
2436
|
+
xs: "xs";
|
|
2437
2437
|
lg: "lg";
|
|
2438
2438
|
}>>;
|
|
2439
2439
|
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -2633,8 +2633,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2633
2633
|
}, z.core.$strip>]>]>>;
|
|
2634
2634
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2635
2635
|
base: "base";
|
|
2636
|
-
xs: "xs";
|
|
2637
2636
|
sm: "sm";
|
|
2637
|
+
xs: "xs";
|
|
2638
2638
|
lg: "lg";
|
|
2639
2639
|
}>>;
|
|
2640
2640
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodObject<{
|
|
@@ -2684,8 +2684,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2684
2684
|
value: z.ZodOptional<z.ZodString>;
|
|
2685
2685
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2686
2686
|
base: "base";
|
|
2687
|
-
xs: "xs";
|
|
2688
2687
|
sm: "sm";
|
|
2688
|
+
xs: "xs";
|
|
2689
2689
|
lg: "lg";
|
|
2690
2690
|
}>>;
|
|
2691
2691
|
variant: z.ZodOptional<z.ZodEnum<{
|
|
@@ -2898,8 +2898,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2898
2898
|
}>>;
|
|
2899
2899
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2900
2900
|
base: "base";
|
|
2901
|
-
xs: "xs";
|
|
2902
2901
|
sm: "sm";
|
|
2902
|
+
xs: "xs";
|
|
2903
2903
|
lg: "lg";
|
|
2904
2904
|
}>>;
|
|
2905
2905
|
bold: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -2990,8 +2990,8 @@ export declare const ComponentPropsSchemas: {
|
|
|
2990
2990
|
}, z.core.$strip>]>]>>;
|
|
2991
2991
|
size: z.ZodOptional<z.ZodEnum<{
|
|
2992
2992
|
base: "base";
|
|
2993
|
-
xs: "xs";
|
|
2994
2993
|
sm: "sm";
|
|
2994
|
+
xs: "xs";
|
|
2995
2995
|
lg: "lg";
|
|
2996
2996
|
}>>;
|
|
2997
2997
|
}, z.core.$strip>;
|
|
@@ -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
|
+
});
|