@fldr/ui 0.3.6 → 0.3.8
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 +2 -6
- 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/dist/styles/theme-fldr.css +0 -11
- package/dist/theming.d.ts +4 -24
- package/dist/theming.js +4 -15
- package/package.json +5 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Checkbox } from "../../components/checkbox";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
import {
|
|
5
|
+
FileKindIcon,
|
|
6
|
+
ItemActionsMenu,
|
|
7
|
+
formatFileDate,
|
|
8
|
+
formatFileSize,
|
|
9
|
+
useControllable,
|
|
10
|
+
type FileActions,
|
|
11
|
+
type FileItem,
|
|
12
|
+
} from "../file-table/file-item";
|
|
13
|
+
|
|
14
|
+
export interface FolderGridLabels {
|
|
15
|
+
itemCount: (count: number) => string;
|
|
16
|
+
selectItem: (name: string) => string;
|
|
17
|
+
actions: (name: string) => string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DEFAULT_LABELS: FolderGridLabels = {
|
|
21
|
+
itemCount: (count) => `${count} ${count === 1 ? "file" : "files"}`,
|
|
22
|
+
selectItem: (name) => `Select ${name}`,
|
|
23
|
+
actions: (name) => `Actions for ${name}`,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface FolderGridProps<T extends FileItem = FileItem> {
|
|
27
|
+
items: T[];
|
|
28
|
+
/** Show a checkbox on each card. @default false */
|
|
29
|
+
selectable?: boolean;
|
|
30
|
+
selectedIds?: string[];
|
|
31
|
+
defaultSelectedIds?: string[];
|
|
32
|
+
onSelectionChange?: (ids: string[]) => void;
|
|
33
|
+
/** Called when a card is clicked or its name activated. */
|
|
34
|
+
onOpen?: (item: T) => void;
|
|
35
|
+
/** Per-card actions menu: an items array or a render prop returning `DropdownMenu.Item`s. */
|
|
36
|
+
actions?: FileActions<T>;
|
|
37
|
+
/** Override the meta line. Defaults to "48 files · 12 MB" for folders, "12 MB · Nov 3, 2026" for files. */
|
|
38
|
+
meta?: (item: T) => ReactNode;
|
|
39
|
+
/** Rendered instead of the grid when `items` is empty. */
|
|
40
|
+
empty?: ReactNode;
|
|
41
|
+
labels?: Partial<FolderGridLabels>;
|
|
42
|
+
/** Locale for size and date formatting. Defaults to the runtime locale. */
|
|
43
|
+
locale?: string;
|
|
44
|
+
className?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* FolderGrid — responsive grid of folder and file cards.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <FolderGrid
|
|
53
|
+
* items={[{ id: "1", name: "Receipts", kind: "folder", itemCount: 48, size: 12_400_000 }]}
|
|
54
|
+
* onOpen={(folder) => navigate(folder.id)}
|
|
55
|
+
* actions={[{ label: "Share", onSelect: share }]}
|
|
56
|
+
* />
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function FolderGrid<T extends FileItem = FileItem>({
|
|
60
|
+
items,
|
|
61
|
+
selectable = false,
|
|
62
|
+
selectedIds,
|
|
63
|
+
defaultSelectedIds = [],
|
|
64
|
+
onSelectionChange,
|
|
65
|
+
onOpen,
|
|
66
|
+
actions,
|
|
67
|
+
meta,
|
|
68
|
+
empty,
|
|
69
|
+
labels: labelsProp,
|
|
70
|
+
locale,
|
|
71
|
+
className,
|
|
72
|
+
}: FolderGridProps<T>) {
|
|
73
|
+
const labels = { ...DEFAULT_LABELS, ...labelsProp };
|
|
74
|
+
const [selected, setSelected] = useControllable(
|
|
75
|
+
selectedIds,
|
|
76
|
+
defaultSelectedIds,
|
|
77
|
+
onSelectionChange,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
if (items.length === 0 && empty) return <>{empty}</>;
|
|
81
|
+
|
|
82
|
+
const defaultMeta = (item: T) =>
|
|
83
|
+
[
|
|
84
|
+
item.kind === "folder" && item.itemCount !== undefined
|
|
85
|
+
? labels.itemCount(item.itemCount)
|
|
86
|
+
: undefined,
|
|
87
|
+
item.size === undefined ? undefined : formatFileSize(item.size, locale),
|
|
88
|
+
item.kind !== "folder" && item.modifiedAt !== undefined
|
|
89
|
+
? formatFileDate(item.modifiedAt, locale)
|
|
90
|
+
: undefined,
|
|
91
|
+
]
|
|
92
|
+
.filter(Boolean)
|
|
93
|
+
.join(" · ");
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<ul
|
|
97
|
+
className={cn(
|
|
98
|
+
"grid grid-cols-[repeat(auto-fill,minmax(14rem,1fr))] gap-2",
|
|
99
|
+
className,
|
|
100
|
+
)}
|
|
101
|
+
>
|
|
102
|
+
{items.map((item) => {
|
|
103
|
+
const isSelected = selected.includes(item.id);
|
|
104
|
+
return (
|
|
105
|
+
<li
|
|
106
|
+
key={item.id}
|
|
107
|
+
data-selected={isSelected || undefined}
|
|
108
|
+
onClick={onOpen && (() => onOpen(item))}
|
|
109
|
+
className={cn(
|
|
110
|
+
"flex flex-col overflow-hidden rounded-lg bg-kumo-elevated hover:bg-kumo-tint",
|
|
111
|
+
isSelected ? "bg-kumo-tint" : "hover:bg-kumo-tint",
|
|
112
|
+
onOpen && "cursor-pointer",
|
|
113
|
+
)}
|
|
114
|
+
>
|
|
115
|
+
{item.thumbnailUrl && (
|
|
116
|
+
<img
|
|
117
|
+
src={item.thumbnailUrl}
|
|
118
|
+
alt=""
|
|
119
|
+
className="aspect-[4/3] w-full bg-kumo-recessed object-cover"
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
<div className="flex items-center gap-2 px-2.5 py-2">
|
|
123
|
+
{selectable && (
|
|
124
|
+
<span onClick={(e) => e.stopPropagation()}>
|
|
125
|
+
<Checkbox
|
|
126
|
+
aria-label={labels.selectItem(item.name)}
|
|
127
|
+
checked={isSelected}
|
|
128
|
+
onCheckedChange={(checked) =>
|
|
129
|
+
setSelected(
|
|
130
|
+
checked
|
|
131
|
+
? [...selected, item.id]
|
|
132
|
+
: selected.filter((id) => id !== item.id),
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
/>
|
|
136
|
+
</span>
|
|
137
|
+
)}
|
|
138
|
+
<FileKindIcon kind={item.kind} size={22} />
|
|
139
|
+
<div className="min-w-0 flex-1">
|
|
140
|
+
{onOpen ? (
|
|
141
|
+
<button
|
|
142
|
+
type="button"
|
|
143
|
+
className="block w-full cursor-pointer truncate text-left text-base font-medium text-kumo-default"
|
|
144
|
+
>
|
|
145
|
+
{item.name}
|
|
146
|
+
</button>
|
|
147
|
+
) : (
|
|
148
|
+
<p className="truncate text-base font-medium text-kumo-default">
|
|
149
|
+
{item.name}
|
|
150
|
+
</p>
|
|
151
|
+
)}
|
|
152
|
+
<p className="truncate text-sm text-kumo-subtle">
|
|
153
|
+
{meta ? meta(item) : defaultMeta(item)}
|
|
154
|
+
</p>
|
|
155
|
+
</div>
|
|
156
|
+
{actions && (
|
|
157
|
+
<ItemActionsMenu
|
|
158
|
+
item={item}
|
|
159
|
+
actions={actions}
|
|
160
|
+
label={labels.actions(item.name)}
|
|
161
|
+
className="-mr-1"
|
|
162
|
+
/>
|
|
163
|
+
)}
|
|
164
|
+
</div>
|
|
165
|
+
</li>
|
|
166
|
+
);
|
|
167
|
+
})}
|
|
168
|
+
</ul>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { cn } from "../../utils/cn";
|
|
3
|
+
import { AuthCard, type AuthCardProps } from "../auth-card";
|
|
4
|
+
|
|
5
|
+
export interface LoginPageProps extends Omit<
|
|
6
|
+
AuthCardProps,
|
|
7
|
+
"className" | "logo"
|
|
8
|
+
> {
|
|
9
|
+
/** Product mark, shown above the card. */
|
|
10
|
+
logo?: ReactNode;
|
|
11
|
+
/** Small print under the card, e.g. terms and privacy links. */
|
|
12
|
+
legal?: ReactNode;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* LoginPage: a full-screen sign-in or sign-up page around `AuthCard`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <LoginPage
|
|
22
|
+
* logo={<FldrMark />}
|
|
23
|
+
* providers={[{ id: "google", label: "Continue with Google", icon: <GoogleLogoIcon /> }]}
|
|
24
|
+
* onProvider={startOAuth}
|
|
25
|
+
* onSubmit={({ email, password }) => signIn(email, password)}
|
|
26
|
+
* legal={<>By continuing you agree to the <a href="/terms">Terms</a>.</>}
|
|
27
|
+
* />
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function LoginPage({ logo, legal, className, ...card }: LoginPageProps) {
|
|
31
|
+
return (
|
|
32
|
+
<main
|
|
33
|
+
className={cn(
|
|
34
|
+
"flex min-h-dvh w-full flex-col items-center justify-center gap-6 bg-kumo-canvas px-4 py-12 text-kumo-default",
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
>
|
|
38
|
+
{logo && <div className="flex items-center justify-center">{logo}</div>}
|
|
39
|
+
<AuthCard {...card} />
|
|
40
|
+
{legal && (
|
|
41
|
+
<p className="m-0 max-w-[360px] text-center text-xs text-kumo-subtle [&_a]:text-kumo-default [&_a]:underline">
|
|
42
|
+
{legal}
|
|
43
|
+
</p>
|
|
44
|
+
)}
|
|
45
|
+
</main>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vite-plus/test";
|
|
3
|
+
import {
|
|
4
|
+
OnboardingChecklist,
|
|
5
|
+
type OnboardingStep,
|
|
6
|
+
} from "./onboarding-checklist";
|
|
7
|
+
|
|
8
|
+
const steps: OnboardingStep[] = [
|
|
9
|
+
{ id: "folder", title: "Create your first folder", done: true },
|
|
10
|
+
{ id: "upload", title: "Upload a receipt", done: true },
|
|
11
|
+
{
|
|
12
|
+
id: "forward",
|
|
13
|
+
title: "Forward an email to inbox@fldr.zip",
|
|
14
|
+
description: "Attachments land in your inbox folder.",
|
|
15
|
+
actionLabel: "Copy address",
|
|
16
|
+
},
|
|
17
|
+
{ id: "invite", title: "Invite a teammate", actionLabel: "Invite" },
|
|
18
|
+
{ id: "share", title: "Share a folder" },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
describe("OnboardingChecklist", () => {
|
|
22
|
+
it("shows progress and expands the first incomplete step", () => {
|
|
23
|
+
render(<OnboardingChecklist steps={steps} />);
|
|
24
|
+
expect(screen.getByText("2 of 5 done")).toBeDefined();
|
|
25
|
+
const current = screen
|
|
26
|
+
.getByText("Forward an email to inbox@fldr.zip")
|
|
27
|
+
.closest("li");
|
|
28
|
+
expect(current?.getAttribute("aria-current")).toBe("step");
|
|
29
|
+
expect(
|
|
30
|
+
screen.getByText("Attachments land in your inbox folder."),
|
|
31
|
+
).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("calls onStepAction and onDismiss", () => {
|
|
35
|
+
const onStepAction = vi.fn();
|
|
36
|
+
const onDismiss = vi.fn();
|
|
37
|
+
render(
|
|
38
|
+
<OnboardingChecklist
|
|
39
|
+
steps={steps}
|
|
40
|
+
onStepAction={onStepAction}
|
|
41
|
+
onDismiss={onDismiss}
|
|
42
|
+
/>,
|
|
43
|
+
);
|
|
44
|
+
fireEvent.click(screen.getByRole("button", { name: "Copy address" }));
|
|
45
|
+
fireEvent.click(screen.getByRole("button", { name: "Invite" }));
|
|
46
|
+
expect(onStepAction.mock.calls).toEqual([["forward"], ["invite"]]);
|
|
47
|
+
fireEvent.click(screen.getByRole("button", { name: "Dismiss checklist" }));
|
|
48
|
+
expect(onDismiss).toHaveBeenCalledOnce();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { CheckCircleIcon, CircleIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
+
import { Button } from "../../components/button";
|
|
4
|
+
import { Meter } from "../../components/meter";
|
|
5
|
+
import { cn } from "../../utils/cn";
|
|
6
|
+
|
|
7
|
+
export interface OnboardingStep {
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
description?: ReactNode;
|
|
11
|
+
done?: boolean;
|
|
12
|
+
/** Label for the step's action button; omit for no button. */
|
|
13
|
+
actionLabel?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OnboardingChecklistLabels {
|
|
17
|
+
title: string;
|
|
18
|
+
/** Formats the progress text, e.g. "2 of 5 done". */
|
|
19
|
+
progress: (done: number, total: number) => string;
|
|
20
|
+
progressLabel: string;
|
|
21
|
+
dismiss: string;
|
|
22
|
+
done: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DEFAULT_LABELS: OnboardingChecklistLabels = {
|
|
26
|
+
title: "Get started with fldr",
|
|
27
|
+
progress: (done, total) => `${done} of ${total} done`,
|
|
28
|
+
progressLabel: "Setup progress",
|
|
29
|
+
dismiss: "Dismiss checklist",
|
|
30
|
+
done: "Done",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export interface OnboardingChecklistProps {
|
|
34
|
+
steps: OnboardingStep[];
|
|
35
|
+
/** Called when a step's action button is clicked. */
|
|
36
|
+
onStepAction?: (id: string) => void;
|
|
37
|
+
/** Shows a dismiss button when provided. */
|
|
38
|
+
onDismiss?: () => void;
|
|
39
|
+
/** Overrides `labels.title`. */
|
|
40
|
+
title?: ReactNode;
|
|
41
|
+
description?: ReactNode;
|
|
42
|
+
/** Overridable strings for i18n. */
|
|
43
|
+
labels?: Partial<OnboardingChecklistLabels>;
|
|
44
|
+
className?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Getting-started card with progress and a list of steps. The first
|
|
49
|
+
* incomplete step is expanded; others show only their title.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* <OnboardingChecklist
|
|
54
|
+
* steps={[
|
|
55
|
+
* { id: "folder", title: "Create your first folder", done: true },
|
|
56
|
+
* { id: "forward", title: "Forward an email to inbox@fldr.zip", actionLabel: "Copy address" },
|
|
57
|
+
* ]}
|
|
58
|
+
* onStepAction={(id) => run(id)}
|
|
59
|
+
* onDismiss={() => hide()}
|
|
60
|
+
* />
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function OnboardingChecklist({
|
|
64
|
+
steps,
|
|
65
|
+
onStepAction,
|
|
66
|
+
onDismiss,
|
|
67
|
+
title,
|
|
68
|
+
description,
|
|
69
|
+
labels: labelOverrides,
|
|
70
|
+
className,
|
|
71
|
+
}: OnboardingChecklistProps) {
|
|
72
|
+
const labels = { ...DEFAULT_LABELS, ...labelOverrides };
|
|
73
|
+
const doneCount = steps.filter((s) => s.done).length;
|
|
74
|
+
const total = steps.length;
|
|
75
|
+
const currentId = steps.find((s) => !s.done)?.id;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<section
|
|
79
|
+
className={cn(
|
|
80
|
+
"flex w-full flex-col gap-3 rounded-xl bg-kumo-elevated p-4",
|
|
81
|
+
className,
|
|
82
|
+
)}
|
|
83
|
+
>
|
|
84
|
+
<div className="flex items-start justify-between gap-3">
|
|
85
|
+
<div className="flex flex-col gap-1">
|
|
86
|
+
<h2 className="text-base font-semibold text-kumo-default">
|
|
87
|
+
{title ?? labels.title}
|
|
88
|
+
</h2>
|
|
89
|
+
{description && (
|
|
90
|
+
<p className="text-sm text-kumo-subtle">{description}</p>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
{onDismiss && (
|
|
94
|
+
<Button
|
|
95
|
+
variant="ghost"
|
|
96
|
+
shape="square"
|
|
97
|
+
size="sm"
|
|
98
|
+
aria-label={labels.dismiss}
|
|
99
|
+
icon={XIcon}
|
|
100
|
+
onClick={onDismiss}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<Meter
|
|
106
|
+
label={labels.progressLabel}
|
|
107
|
+
value={total ? (doneCount / total) * 100 : 0}
|
|
108
|
+
customValue={labels.progress(doneCount, total)}
|
|
109
|
+
/>
|
|
110
|
+
|
|
111
|
+
<ol className="-mx-2 flex flex-col">
|
|
112
|
+
{steps.map((step) => {
|
|
113
|
+
const current = step.id === currentId;
|
|
114
|
+
return (
|
|
115
|
+
<li
|
|
116
|
+
key={step.id}
|
|
117
|
+
aria-current={current ? "step" : undefined}
|
|
118
|
+
className={cn(
|
|
119
|
+
"flex gap-3 rounded-lg px-2 py-2",
|
|
120
|
+
current && "bg-kumo-tint",
|
|
121
|
+
)}
|
|
122
|
+
>
|
|
123
|
+
{step.done ? (
|
|
124
|
+
<CheckCircleIcon
|
|
125
|
+
size={18}
|
|
126
|
+
weight="fill"
|
|
127
|
+
className="mt-px shrink-0 text-kumo-success"
|
|
128
|
+
aria-label={labels.done}
|
|
129
|
+
/>
|
|
130
|
+
) : (
|
|
131
|
+
<CircleIcon
|
|
132
|
+
size={18}
|
|
133
|
+
className="mt-px shrink-0 text-kumo-subtle"
|
|
134
|
+
aria-hidden
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
138
|
+
<span
|
|
139
|
+
className={cn(
|
|
140
|
+
"text-sm",
|
|
141
|
+
step.done
|
|
142
|
+
? "text-kumo-subtle line-through"
|
|
143
|
+
: "text-kumo-default",
|
|
144
|
+
current && "font-medium",
|
|
145
|
+
)}
|
|
146
|
+
>
|
|
147
|
+
{step.title}
|
|
148
|
+
</span>
|
|
149
|
+
{current && step.description && (
|
|
150
|
+
<p className="text-sm text-kumo-subtle">{step.description}</p>
|
|
151
|
+
)}
|
|
152
|
+
{current && step.actionLabel && (
|
|
153
|
+
<Button
|
|
154
|
+
variant="primary"
|
|
155
|
+
size="sm"
|
|
156
|
+
className="mt-1 self-start"
|
|
157
|
+
onClick={() => onStepAction?.(step.id)}
|
|
158
|
+
>
|
|
159
|
+
{step.actionLabel}
|
|
160
|
+
</Button>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
{!current && !step.done && step.actionLabel && (
|
|
164
|
+
<Button
|
|
165
|
+
variant="ghost"
|
|
166
|
+
size="sm"
|
|
167
|
+
onClick={() => onStepAction?.(step.id)}
|
|
168
|
+
>
|
|
169
|
+
{step.actionLabel}
|
|
170
|
+
</Button>
|
|
171
|
+
)}
|
|
172
|
+
</li>
|
|
173
|
+
);
|
|
174
|
+
})}
|
|
175
|
+
</ol>
|
|
176
|
+
</section>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
OnboardingChecklist.displayName = "OnboardingChecklist";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vite-plus/test";
|
|
3
|
+
import {
|
|
4
|
+
SettingsRow,
|
|
5
|
+
SettingsSaveBar,
|
|
6
|
+
SettingsSection,
|
|
7
|
+
} from "./settings-section";
|
|
8
|
+
|
|
9
|
+
describe("SettingsSection", () => {
|
|
10
|
+
it("renders a labelled section with rows", () => {
|
|
11
|
+
render(
|
|
12
|
+
<SettingsSection title="Folder" description="How this folder behaves.">
|
|
13
|
+
<SettingsRow
|
|
14
|
+
label="Auto-file receipts"
|
|
15
|
+
control={<input type="checkbox" />}
|
|
16
|
+
/>
|
|
17
|
+
</SettingsSection>,
|
|
18
|
+
);
|
|
19
|
+
expect(screen.getByRole("region", { name: "Folder" })).toBeDefined();
|
|
20
|
+
expect(screen.getByText("Auto-file receipts")).toBeDefined();
|
|
21
|
+
expect(screen.getByRole("checkbox")).toBeDefined();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("SettingsSaveBar", () => {
|
|
26
|
+
it("renders nothing when not dirty", () => {
|
|
27
|
+
render(
|
|
28
|
+
<SettingsSaveBar dirty={false} onSave={vi.fn()} onDiscard={vi.fn()} />,
|
|
29
|
+
);
|
|
30
|
+
expect(screen.queryByText("Unsaved changes")).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("calls onSave and onDiscard when dirty", () => {
|
|
34
|
+
const onSave = vi.fn();
|
|
35
|
+
const onDiscard = vi.fn();
|
|
36
|
+
render(<SettingsSaveBar dirty onSave={onSave} onDiscard={onDiscard} />);
|
|
37
|
+
expect(screen.getByText("Unsaved changes")).toBeDefined();
|
|
38
|
+
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
|
39
|
+
fireEvent.click(screen.getByRole("button", { name: "Discard" }));
|
|
40
|
+
expect(onSave).toHaveBeenCalledOnce();
|
|
41
|
+
expect(onDiscard).toHaveBeenCalledOnce();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { useId, type ReactNode } from "react";
|
|
2
|
+
import { Button } from "../../components/button";
|
|
3
|
+
import { cn } from "../../utils/cn";
|
|
4
|
+
|
|
5
|
+
export type SettingsSectionVariant = "default" | "danger";
|
|
6
|
+
|
|
7
|
+
export interface SettingsSectionProps {
|
|
8
|
+
title: ReactNode;
|
|
9
|
+
description?: ReactNode;
|
|
10
|
+
/** `danger` tints the heading and border for destructive settings. */
|
|
11
|
+
variant?: SettingsSectionVariant;
|
|
12
|
+
/** `SettingsRow` elements. */
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A titled group of settings rows.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <SettingsSection title="Folder" description="How this folder behaves.">
|
|
23
|
+
* <SettingsRow label="Auto-file receipts" control={<Switch />} />
|
|
24
|
+
* </SettingsSection>
|
|
25
|
+
* <SettingsSection title="Danger zone" variant="danger">
|
|
26
|
+
* <SettingsRow label="Delete folder" control={<Button variant="destructive">Delete</Button>} />
|
|
27
|
+
* </SettingsSection>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function SettingsSection({
|
|
31
|
+
title,
|
|
32
|
+
description,
|
|
33
|
+
variant = "default",
|
|
34
|
+
children,
|
|
35
|
+
className,
|
|
36
|
+
}: SettingsSectionProps) {
|
|
37
|
+
const headingId = useId();
|
|
38
|
+
const danger = variant === "danger";
|
|
39
|
+
return (
|
|
40
|
+
<section
|
|
41
|
+
aria-labelledby={headingId}
|
|
42
|
+
className={cn("flex flex-col gap-2", className)}
|
|
43
|
+
>
|
|
44
|
+
<div className="flex flex-col gap-0.5">
|
|
45
|
+
<h2
|
|
46
|
+
id={headingId}
|
|
47
|
+
className={cn(
|
|
48
|
+
"text-base font-semibold",
|
|
49
|
+
danger ? "text-kumo-danger" : "text-kumo-default",
|
|
50
|
+
)}
|
|
51
|
+
>
|
|
52
|
+
{title}
|
|
53
|
+
</h2>
|
|
54
|
+
{description && (
|
|
55
|
+
<p className="text-sm text-kumo-subtle">{description}</p>
|
|
56
|
+
)}
|
|
57
|
+
</div>
|
|
58
|
+
<div
|
|
59
|
+
className={cn(
|
|
60
|
+
"divide-y border-y",
|
|
61
|
+
danger
|
|
62
|
+
? "divide-kumo-danger/20 border-kumo-danger/20"
|
|
63
|
+
: "divide-kumo-hairline border-kumo-hairline",
|
|
64
|
+
)}
|
|
65
|
+
>
|
|
66
|
+
{children}
|
|
67
|
+
</div>
|
|
68
|
+
</section>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface SettingsRowProps {
|
|
73
|
+
label: ReactNode;
|
|
74
|
+
description?: ReactNode;
|
|
75
|
+
/** Control rendered on the right (below on mobile). */
|
|
76
|
+
control?: ReactNode;
|
|
77
|
+
/** Associates the label with a control's `id`. */
|
|
78
|
+
htmlFor?: string;
|
|
79
|
+
className?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A single setting: label and description on the left, control on the right. */
|
|
83
|
+
export function SettingsRow({
|
|
84
|
+
label,
|
|
85
|
+
description,
|
|
86
|
+
control,
|
|
87
|
+
htmlFor,
|
|
88
|
+
className,
|
|
89
|
+
}: SettingsRowProps) {
|
|
90
|
+
const Label = htmlFor ? "label" : "div";
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
className={cn(
|
|
94
|
+
"flex flex-col gap-2 py-2.5 sm:flex-row sm:items-center sm:justify-between sm:gap-6",
|
|
95
|
+
className,
|
|
96
|
+
)}
|
|
97
|
+
>
|
|
98
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
99
|
+
<Label
|
|
100
|
+
htmlFor={htmlFor}
|
|
101
|
+
className="text-sm font-medium text-kumo-default"
|
|
102
|
+
>
|
|
103
|
+
{label}
|
|
104
|
+
</Label>
|
|
105
|
+
{description && (
|
|
106
|
+
<p className="text-sm text-kumo-subtle">{description}</p>
|
|
107
|
+
)}
|
|
108
|
+
</div>
|
|
109
|
+
{control && <div className="shrink-0">{control}</div>}
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface SettingsSaveBarLabels {
|
|
115
|
+
message?: string;
|
|
116
|
+
discard?: string;
|
|
117
|
+
save?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface SettingsSaveBarProps {
|
|
121
|
+
/** The bar renders only when `true`. */
|
|
122
|
+
dirty: boolean;
|
|
123
|
+
onSave: () => void;
|
|
124
|
+
onDiscard: () => void;
|
|
125
|
+
saving?: boolean;
|
|
126
|
+
labels?: SettingsSaveBarLabels;
|
|
127
|
+
className?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Sticky bottom bar shown while a settings form has unsaved changes. */
|
|
131
|
+
export function SettingsSaveBar({
|
|
132
|
+
dirty,
|
|
133
|
+
onSave,
|
|
134
|
+
onDiscard,
|
|
135
|
+
saving = false,
|
|
136
|
+
labels = {},
|
|
137
|
+
className,
|
|
138
|
+
}: SettingsSaveBarProps) {
|
|
139
|
+
if (!dirty) return null;
|
|
140
|
+
const {
|
|
141
|
+
message = "Unsaved changes",
|
|
142
|
+
discard = "Discard",
|
|
143
|
+
save = "Save",
|
|
144
|
+
} = labels;
|
|
145
|
+
return (
|
|
146
|
+
<div
|
|
147
|
+
role="region"
|
|
148
|
+
aria-label={message}
|
|
149
|
+
className={cn(
|
|
150
|
+
"sticky bottom-4 z-10 flex items-center justify-between gap-3 rounded-lg border border-kumo-line bg-kumo-elevated py-2 pr-2 pl-4 shadow-sm",
|
|
151
|
+
className,
|
|
152
|
+
)}
|
|
153
|
+
>
|
|
154
|
+
<span className="text-sm text-kumo-default">{message}</span>
|
|
155
|
+
<div className="flex gap-2">
|
|
156
|
+
<Button variant="ghost" onClick={onDiscard} disabled={saving}>
|
|
157
|
+
{discard}
|
|
158
|
+
</Button>
|
|
159
|
+
<Button variant="primary" onClick={onSave} loading={saving}>
|
|
160
|
+
{save}
|
|
161
|
+
</Button>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|