@alepha/ui 0.25.1 → 0.25.2
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/package.json +3 -3
- package/src/components/account/__tests__/account-router.spec.ts +201 -0
- package/src/components/account/account-connections.tsx +103 -0
- package/src/components/account/account-delete-dialog.tsx +184 -0
- package/src/components/account/account-header.tsx +57 -0
- package/src/components/account/account-keys.tsx +221 -0
- package/src/components/account/account-layout.tsx +63 -0
- package/src/components/account/account-password-dialog.tsx +152 -0
- package/src/components/account/account-profile.tsx +229 -0
- package/src/components/account/account-router-options.tsx +74 -0
- package/src/components/account/account-router-page.tsx +69 -0
- package/src/components/account/account-router.tsx +214 -0
- package/src/components/account/account-security.tsx +150 -0
- package/src/components/account/account-sessions.tsx +140 -0
- package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +62 -0
- package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +82 -0
- package/src/components/admin/__tests__/admin-router-page.spec.ts +54 -0
- package/src/components/admin/__tests__/admin-router.spec.ts +208 -0
- package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +99 -0
- package/src/components/admin/__tests__/admin-user-detail.spec.ts +29 -0
- package/src/components/admin/admin-analytics-query-panel.tsx +149 -0
- package/src/components/admin/admin-analytics-results.tsx +95 -0
- package/src/components/admin/admin-analytics.tsx +104 -0
- package/src/components/admin/admin-audits.tsx +12 -15
- package/src/components/admin/admin-files.tsx +10 -18
- package/src/components/admin/admin-jobs-executions-panel.tsx +2 -1
- package/src/components/admin/admin-jobs.tsx +3 -1
- package/src/components/admin/admin-keys-token-dialog.tsx +123 -0
- package/src/components/admin/admin-keys.tsx +54 -3
- package/src/components/admin/admin-layout.tsx +107 -0
- package/src/components/admin/admin-payments.tsx +4 -5
- package/src/components/admin/admin-router-options.tsx +130 -0
- package/src/components/admin/admin-router-page.tsx +74 -0
- package/src/components/admin/admin-router.tsx +379 -0
- package/src/components/admin/admin-sessions.tsx +2 -16
- package/src/components/admin/admin-user-cell.tsx +70 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +28 -0
- package/src/components/admin/admin-user-detail-profile-policy.spec.ts +146 -0
- package/src/components/admin/admin-user-detail-profile-policy.ts +147 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +1 -1
- package/src/components/admin/admin-user-detail.tsx +76 -32
- package/src/components/admin/admin-users-status-filter.tsx +2 -0
- package/src/components/admin/admin-workflows-execution-sheet.tsx +277 -0
- package/src/components/admin/admin-workflows-executions-panel.tsx +170 -0
- package/src/components/admin/admin-workflows-status-badge.tsx +40 -0
- package/src/components/admin/admin-workflows.tsx +207 -0
- package/src/components/alepha-table/alepha-table.tsx +73 -17
- package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +79 -0
- package/src/components/app-actions/app-actions.tsx +113 -0
- package/src/components/app-shell/app-shell.tsx +122 -0
- package/src/components/auth/auth-reset-password.tsx +81 -8
- package/src/components/button-user/button-user.tsx +58 -1
- package/src/components/control/control.tsx +14 -71
- package/src/components/control-password/control-password.tsx +87 -0
- package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +101 -0
- package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +142 -0
- package/src/components/control-select/control-select.tsx +78 -111
- package/src/components/control-upload/control-upload.tsx +27 -1
- package/src/components/markdown-view/markdown-view.tsx +6 -0
- package/src/components/nav-shell/nav-page.tsx +3 -3
- package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
- package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
- package/src/components/settings/settings-danger-section.tsx +59 -0
- package/src/components/settings/settings-layout.tsx +56 -0
- package/src/components/settings/settings-nav.tsx +131 -0
- package/src/components/settings/settings-row.tsx +81 -0
- package/src/components/settings/settings-section.tsx +64 -0
- package/src/components/ui/dropdown-menu.tsx +9 -1
- package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
- package/src/lib/i18n-fr.ts +68 -0
- package/src/lib/rehype-safe-img.ts +150 -0
- package/src/lib/resize-image.ts +135 -0
- package/src/styles.css +126 -1
- /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "alepha/react/router";
|
|
9
9
|
import { $secure } from "alepha/security";
|
|
10
10
|
|
|
11
|
-
export interface
|
|
11
|
+
export interface PageNavOptions<
|
|
12
12
|
TConfig extends PageConfigSchema = PageConfigSchema,
|
|
13
13
|
TProps extends object = TPropsDefault,
|
|
14
14
|
TPropsParent extends object = TPropsParentDefault,
|
|
@@ -34,12 +34,12 @@ export interface NavPageOptions<
|
|
|
34
34
|
* Pages declared this way are picked up by {@link useNavTree} /
|
|
35
35
|
* {@link NavShell} purely from their `nav` field — no separate nav list.
|
|
36
36
|
*/
|
|
37
|
-
export const
|
|
37
|
+
export const $pageNav = <
|
|
38
38
|
TConfig extends PageConfigSchema = PageConfigSchema,
|
|
39
39
|
TProps extends object = TPropsDefault,
|
|
40
40
|
TPropsParent extends object = TPropsParentDefault,
|
|
41
41
|
>(
|
|
42
|
-
options:
|
|
42
|
+
options: PageNavOptions<TConfig, TProps, TPropsParent>,
|
|
43
43
|
): PagePrimitive<TConfig, TProps, TPropsParent> => {
|
|
44
44
|
const { permission, use, nav, ...rest } = options;
|
|
45
45
|
const permissions = permission
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { Alepha } from "alepha";
|
|
3
|
+
import { AlephaContext } from "alepha/react";
|
|
4
|
+
import { AlephaReactRouter } from "alepha/react/router";
|
|
5
|
+
import { setupJsdomMocks } from "alepha/react/testing";
|
|
6
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
7
|
+
import { SettingsNav, type SettingsNavItem } from "../settings-nav.tsx";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The rail's contract is narrow but easy to break silently: it must group by
|
|
11
|
+
* first appearance rather than alphabetically (the caller has already sorted),
|
|
12
|
+
* it must render hrefs verbatim (the reason it takes resolved items at all),
|
|
13
|
+
* and a disabled entry must stop being a link rather than merely look muted.
|
|
14
|
+
*/
|
|
15
|
+
describe("SettingsNav", () => {
|
|
16
|
+
let alepha: Alepha | undefined;
|
|
17
|
+
|
|
18
|
+
beforeAll(() => {
|
|
19
|
+
setupJsdomMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await alepha?.stop();
|
|
24
|
+
alepha = undefined;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const mount = async (items: SettingsNavItem[]) => {
|
|
28
|
+
alepha = Alepha.create().with(AlephaReactRouter);
|
|
29
|
+
await alepha.start();
|
|
30
|
+
return render(
|
|
31
|
+
<AlephaContext.Provider value={alepha}>
|
|
32
|
+
<SettingsNav items={items} />
|
|
33
|
+
</AlephaContext.Provider>,
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const item = (over: Partial<SettingsNavItem> = {}): SettingsNavItem => ({
|
|
38
|
+
name: "profile",
|
|
39
|
+
href: "/account",
|
|
40
|
+
label: "Profile",
|
|
41
|
+
active: false,
|
|
42
|
+
...over,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("renders each entry as a link to its resolved href", async () => {
|
|
46
|
+
await mount([
|
|
47
|
+
item(),
|
|
48
|
+
item({ name: "sessions", href: "/account/sessions", label: "Sessions" }),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
expect(
|
|
52
|
+
screen.getByRole("link", { name: "Profile" }).getAttribute("href"),
|
|
53
|
+
).toBe("/account");
|
|
54
|
+
expect(
|
|
55
|
+
screen.getByRole("link", { name: "Sessions" }).getAttribute("href"),
|
|
56
|
+
).toBe("/account/sessions");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("passes hrefs through untouched instead of resolving them", async () => {
|
|
60
|
+
// The whole reason the component takes resolved items: it must not try to
|
|
61
|
+
// be clever about a pattern it was handed. Garbage in, same garbage out —
|
|
62
|
+
// visible to the caller rather than silently half-substituted.
|
|
63
|
+
await mount([item({ href: "/:projectSlug/settings" })]);
|
|
64
|
+
|
|
65
|
+
expect(
|
|
66
|
+
screen.getByRole("link", { name: "Profile" }).getAttribute("href"),
|
|
67
|
+
).toBe("/:projectSlug/settings");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("groups by first appearance, not alphabetically", async () => {
|
|
71
|
+
await mount([
|
|
72
|
+
item({ name: "profile", group: "Account" }),
|
|
73
|
+
item({
|
|
74
|
+
name: "sessions",
|
|
75
|
+
href: "/a/s",
|
|
76
|
+
label: "Sessions",
|
|
77
|
+
group: "Security",
|
|
78
|
+
}),
|
|
79
|
+
item({ name: "keys", href: "/a/k", label: "Keys", group: "Security" }),
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const headings = screen
|
|
83
|
+
.getAllByText(/^(Account|Security)$/)
|
|
84
|
+
.map((el) => el.textContent);
|
|
85
|
+
expect(headings).toEqual(["Account", "Security"]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("renders ungrouped entries without a heading", async () => {
|
|
89
|
+
const { container } = await mount([
|
|
90
|
+
item(),
|
|
91
|
+
item({ name: "b", label: "B" }),
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
expect(container.querySelectorAll("nav > div")).toHaveLength(1);
|
|
95
|
+
expect(screen.getAllByRole("link")).toHaveLength(2);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("marks the active entry with aria-current", async () => {
|
|
99
|
+
await mount([
|
|
100
|
+
item({ active: true }),
|
|
101
|
+
item({ name: "sessions", href: "/account/sessions", label: "Sessions" }),
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
screen
|
|
106
|
+
.getByRole("link", { name: "Profile" })
|
|
107
|
+
.getAttribute("aria-current"),
|
|
108
|
+
).toBe("page");
|
|
109
|
+
expect(
|
|
110
|
+
screen
|
|
111
|
+
.getByRole("link", { name: "Sessions" })
|
|
112
|
+
.getAttribute("aria-current"),
|
|
113
|
+
).toBeNull();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("renders a disabled entry as inert text, not a link", async () => {
|
|
117
|
+
await mount([item({ disabled: true })]);
|
|
118
|
+
|
|
119
|
+
expect(screen.queryByRole("link")).toBeNull();
|
|
120
|
+
const entry = screen.getByText("Profile");
|
|
121
|
+
expect(entry.getAttribute("aria-disabled")).toBe("true");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { SettingsDangerSection } from "../settings-danger-section.tsx";
|
|
4
|
+
import { SettingsRow } from "../settings-row.tsx";
|
|
5
|
+
import { SettingsSection } from "../settings-section.tsx";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* These pin the padding contract, which is the one thing about this kit that
|
|
9
|
+
* is invisible in a screenshot review and has already gone wrong four times
|
|
10
|
+
* by hand in `apps/lore`: the card must carry `py-0` and each row its own
|
|
11
|
+
* `py-3`. Doubling them produces a thick blank band top and bottom.
|
|
12
|
+
*/
|
|
13
|
+
describe("SettingsSection", () => {
|
|
14
|
+
it("opts the card out of vertical padding so rows own it", () => {
|
|
15
|
+
const { container } = render(
|
|
16
|
+
<SettingsSection title="General">
|
|
17
|
+
<SettingsRow label="Name">control</SettingsRow>
|
|
18
|
+
</SettingsSection>,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const card = container.querySelector('[data-slot="card"]');
|
|
22
|
+
expect(card?.className).toContain("py-0");
|
|
23
|
+
// A numeric py-* on the card is the anti-pattern, not a smaller variant.
|
|
24
|
+
expect(card?.className).not.toMatch(/\bpy-[1-9]/);
|
|
25
|
+
|
|
26
|
+
const row = container.querySelector('[data-slot="card-content"]');
|
|
27
|
+
expect(row?.className).toContain("py-3");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("divides rows and keeps the card gapless", () => {
|
|
31
|
+
const { container } = render(
|
|
32
|
+
<SettingsSection>
|
|
33
|
+
<SettingsRow label="One" />
|
|
34
|
+
<SettingsRow label="Two" />
|
|
35
|
+
</SettingsSection>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const card = container.querySelector('[data-slot="card"]');
|
|
39
|
+
expect(card?.className).toContain("divide-y");
|
|
40
|
+
expect(card?.className).toContain("gap-0");
|
|
41
|
+
expect(
|
|
42
|
+
container.querySelectorAll('[data-slot="card-content"]'),
|
|
43
|
+
).toHaveLength(2);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("renders no heading block when given neither title nor description", () => {
|
|
47
|
+
const { container } = render(
|
|
48
|
+
<SettingsSection>
|
|
49
|
+
<SettingsRow label="Only" />
|
|
50
|
+
</SettingsSection>,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// Heading block + card would be two children; without a heading, one.
|
|
54
|
+
expect(container.firstElementChild?.children).toHaveLength(1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("renders title and description when both are given", () => {
|
|
58
|
+
render(
|
|
59
|
+
<SettingsSection title="General" description="Who you are">
|
|
60
|
+
<SettingsRow label="Name" />
|
|
61
|
+
</SettingsSection>,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(screen.getByText("General")).toBeTruthy();
|
|
65
|
+
expect(screen.getByText("Who you are")).toBeTruthy();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("SettingsRow", () => {
|
|
70
|
+
it("keeps the label column shrinkable so a long label cannot push the control out", () => {
|
|
71
|
+
const { container } = render(
|
|
72
|
+
<SettingsRow label="Name">control</SettingsRow>,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const row = container.querySelector('[data-slot="card-content"]');
|
|
76
|
+
expect(row?.className).toContain("sm:grid-cols-[minmax(0,1fr)_auto]");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("omits the description line entirely when not given", () => {
|
|
80
|
+
const { container } = render(<SettingsRow label="Name" />);
|
|
81
|
+
|
|
82
|
+
// An empty <span> would still occupy a grid row and add a gap under the
|
|
83
|
+
// label, so "absent" has to mean absent, not blank.
|
|
84
|
+
const labelColumn = container.querySelector(
|
|
85
|
+
'[data-slot="card-content"] > div',
|
|
86
|
+
);
|
|
87
|
+
expect(labelColumn?.children).toHaveLength(1);
|
|
88
|
+
expect(labelColumn?.textContent).toBe("Name");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("renders the control when given", () => {
|
|
92
|
+
render(
|
|
93
|
+
<SettingsRow label="Name" description="Your display name">
|
|
94
|
+
<button type="button">Edit</button>
|
|
95
|
+
</SettingsRow>,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(screen.getByRole("button", { name: "Edit" })).toBeTruthy();
|
|
99
|
+
expect(screen.getByText("Your display name")).toBeTruthy();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("SettingsDangerSection", () => {
|
|
104
|
+
it("defaults its title and tints the border without shouting", () => {
|
|
105
|
+
const { container } = render(
|
|
106
|
+
<SettingsDangerSection>
|
|
107
|
+
<SettingsRow label="Delete account" />
|
|
108
|
+
</SettingsDangerSection>,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
expect(screen.getByText("Danger zone")).toBeTruthy();
|
|
112
|
+
|
|
113
|
+
const card = container.querySelector('[data-slot="card"]');
|
|
114
|
+
expect(card?.className).toContain("border-destructive/30");
|
|
115
|
+
// Full-strength destructive reads as "this page is broken".
|
|
116
|
+
expect(card?.className).not.toMatch(/border-destructive(?![/-])/);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("keeps the same padding contract as a normal section", () => {
|
|
120
|
+
const { container } = render(
|
|
121
|
+
<SettingsDangerSection title="Danger">
|
|
122
|
+
<SettingsRow label="Delete account" />
|
|
123
|
+
</SettingsDangerSection>,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const card = container.querySelector('[data-slot="card"]');
|
|
127
|
+
expect(card?.className).toContain("py-0");
|
|
128
|
+
expect(card?.className).not.toMatch(/\bpy-[1-9]/);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Card } from "@alepha/ui/components/ui/card";
|
|
2
|
+
import { cn } from "@alepha/ui/lib/utils";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
export interface SettingsDangerSectionProps {
|
|
6
|
+
/**
|
|
7
|
+
* Heading above the card.
|
|
8
|
+
*
|
|
9
|
+
* @default "Danger zone"
|
|
10
|
+
*/
|
|
11
|
+
title?: ReactNode;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One line under the title.
|
|
15
|
+
*/
|
|
16
|
+
description?: ReactNode;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* {@link SettingsRow}s, each holding a `variant="destructive"` control.
|
|
20
|
+
*/
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* {@link SettingsSection} for irreversible actions — delete, leave, revoke
|
|
28
|
+
* everything.
|
|
29
|
+
*
|
|
30
|
+
* Identical in structure, with a destructive-tinted border and title. The
|
|
31
|
+
* colour is doing real work rather than decorating: these rows sit in the
|
|
32
|
+
* same visual rhythm as every harmless row above them, and without a boundary
|
|
33
|
+
* the only thing separating "change your display name" from "delete your
|
|
34
|
+
* account" is the button colour at the moment of the click.
|
|
35
|
+
*
|
|
36
|
+
* The tint stays at 30–40% opacity on purpose. A full-strength destructive
|
|
37
|
+
* border reads as *"something is wrong"* rather than *"be careful here"*, and
|
|
38
|
+
* a settings page that looks like it is erroring every time you open it
|
|
39
|
+
* teaches people to ignore the colour.
|
|
40
|
+
*/
|
|
41
|
+
export const SettingsDangerSection = (props: SettingsDangerSectionProps) => {
|
|
42
|
+
const { title = "Danger zone" } = props;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className={cn("flex flex-col gap-2", props.className)}>
|
|
46
|
+
<div className="flex flex-col gap-0.5">
|
|
47
|
+
<span className="text-destructive text-sm">{title}</span>
|
|
48
|
+
{props.description != null ? (
|
|
49
|
+
<span className="text-muted-foreground text-xs">
|
|
50
|
+
{props.description}
|
|
51
|
+
</span>
|
|
52
|
+
) : null}
|
|
53
|
+
</div>
|
|
54
|
+
<Card className="gap-0 divide-y divide-destructive/20 rounded-lg border border-destructive/30 bg-card py-0">
|
|
55
|
+
{props.children}
|
|
56
|
+
</Card>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { cn } from "@alepha/ui/lib/utils";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
export interface SettingsLayoutProps {
|
|
5
|
+
/**
|
|
6
|
+
* The left rail — normally a {@link SettingsNav}. Omit for a settings page
|
|
7
|
+
* with a single screen and nothing to navigate between.
|
|
8
|
+
*/
|
|
9
|
+
nav?: ReactNode;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Full-width block above both columns: an identity card, a page title, a
|
|
13
|
+
* back link. Rendered inside the centred container, so it lines up with the
|
|
14
|
+
* content rather than the viewport.
|
|
15
|
+
*/
|
|
16
|
+
header?: ReactNode;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The routed content — normally a `NestedView`.
|
|
20
|
+
*/
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Centred two-column shell for a settings area: sticky rail on the left,
|
|
28
|
+
* content on the right, stacked on small screens.
|
|
29
|
+
*
|
|
30
|
+
* `min-w-0` on the content column is load-bearing. A grid/flex child defaults
|
|
31
|
+
* to `min-width: auto`, which is the *content's* intrinsic width — so one
|
|
32
|
+
* unbreakable string (an API key, a long email, a `<pre>` block) makes the
|
|
33
|
+
* column refuse to shrink and pushes the whole page into horizontal scroll,
|
|
34
|
+
* rail included. `min-w-0` lets it shrink and lets the child's own
|
|
35
|
+
* `overflow` handle it.
|
|
36
|
+
*
|
|
37
|
+
* There is no scroll container here on purpose: the page scrolls. A nested
|
|
38
|
+
* `overflow-auto` would clip the flush left/right card borders that
|
|
39
|
+
* {@link SettingsSection} depends on, and would strand the sticky rail
|
|
40
|
+
* against the wrong scroll root.
|
|
41
|
+
*/
|
|
42
|
+
export const SettingsLayout = (props: SettingsLayoutProps) => {
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
className={cn("mx-auto w-full max-w-5xl p-4 md:pt-10", props.className)}
|
|
46
|
+
>
|
|
47
|
+
{props.header ? <div className="mb-6">{props.header}</div> : null}
|
|
48
|
+
<div className="flex flex-col gap-6 md:flex-row md:items-start">
|
|
49
|
+
{props.nav}
|
|
50
|
+
<div className="flex min-w-0 flex-1 flex-col gap-8">
|
|
51
|
+
{props.children}
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { cn } from "@alepha/ui/lib/utils";
|
|
2
|
+
import { Link } from "alepha/react/router";
|
|
3
|
+
import { type ReactNode, useMemo } from "react";
|
|
4
|
+
|
|
5
|
+
export interface SettingsNavItem {
|
|
6
|
+
/**
|
|
7
|
+
* Stable key. The route name when these come from `useNavEntries`.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fully resolved href — every `:param` already substituted. See
|
|
13
|
+
* {@link SettingsNav} for why this component refuses to resolve them itself.
|
|
14
|
+
*/
|
|
15
|
+
href: string;
|
|
16
|
+
|
|
17
|
+
label: ReactNode;
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Heading this entry sits under. Entries with no group render first, in a
|
|
22
|
+
* block of their own, without a heading.
|
|
23
|
+
*/
|
|
24
|
+
group?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The current route is on or under this entry.
|
|
28
|
+
*/
|
|
29
|
+
active: boolean;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Visible but not reachable — rendered muted and inert rather than hidden,
|
|
33
|
+
* so the entry can explain a capability the viewer does not currently have.
|
|
34
|
+
*/
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SettingsNavProps {
|
|
39
|
+
/**
|
|
40
|
+
* Entries in final display order. Grouping preserves first appearance, so
|
|
41
|
+
* sort before passing — `useNavEntries` already returns them sorted by
|
|
42
|
+
* group order then item order.
|
|
43
|
+
*/
|
|
44
|
+
items: SettingsNavItem[];
|
|
45
|
+
|
|
46
|
+
className?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The left-hand rail of a settings page: a sticky, grouped list of links.
|
|
51
|
+
*
|
|
52
|
+
* ⚠️ **It takes resolved `items`, not a `root` route name, and that is the
|
|
53
|
+
* whole design.** Deriving entries internally from `useNavEntries({ root })`
|
|
54
|
+
* would be a smaller API and works fine for a static subtree such as
|
|
55
|
+
* `/account/*` — but `NavEntry.href` is `page.match`, the raw route
|
|
56
|
+
* *pattern*. Point it at a parameterised subtree like
|
|
57
|
+
* `/:projectSlug/settings/...` and every href in the rail comes out
|
|
58
|
+
* containing a literal `:projectSlug`, which is a dead link that renders
|
|
59
|
+
* perfectly.
|
|
60
|
+
*
|
|
61
|
+
* So resolution is the caller's job and presentation is this component's. A
|
|
62
|
+
* static subtree passes `useNavEntries({ root: "account" })` straight through
|
|
63
|
+
* ({@link SettingsNavItem} is structurally a subset of `NavEntry`, so no
|
|
64
|
+
* mapping is needed); a parameterised one passes its own
|
|
65
|
+
* `router.path(name, { params })` list.
|
|
66
|
+
*/
|
|
67
|
+
export const SettingsNav = (props: SettingsNavProps) => {
|
|
68
|
+
const groups = useMemo(() => {
|
|
69
|
+
const ordered: Array<{ key: string; label?: string }> = [];
|
|
70
|
+
const byKey = new Map<string, SettingsNavItem[]>();
|
|
71
|
+
|
|
72
|
+
for (const item of props.items) {
|
|
73
|
+
const key = item.group ?? "";
|
|
74
|
+
let bucket = byKey.get(key);
|
|
75
|
+
if (!bucket) {
|
|
76
|
+
bucket = [];
|
|
77
|
+
byKey.set(key, bucket);
|
|
78
|
+
ordered.push({ key, label: item.group });
|
|
79
|
+
}
|
|
80
|
+
bucket.push(item);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return ordered.map((g) => ({ ...g, items: byKey.get(g.key) ?? [] }));
|
|
84
|
+
}, [props.items]);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<nav
|
|
88
|
+
className={cn(
|
|
89
|
+
"flex shrink-0 flex-col gap-4 md:sticky md:top-0 md:w-48 md:self-start",
|
|
90
|
+
props.className,
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
{groups.map((group) => (
|
|
94
|
+
<div key={group.key} className="flex flex-col gap-1">
|
|
95
|
+
{group.label ? (
|
|
96
|
+
<span className="px-3 font-semibold text-[11px] text-muted-foreground uppercase tracking-wider">
|
|
97
|
+
{group.label}
|
|
98
|
+
</span>
|
|
99
|
+
) : null}
|
|
100
|
+
{group.items.map((item) =>
|
|
101
|
+
item.disabled ? (
|
|
102
|
+
<span
|
|
103
|
+
key={item.name}
|
|
104
|
+
aria-disabled="true"
|
|
105
|
+
className="flex items-center gap-2 whitespace-nowrap rounded-md px-3 py-2 text-left text-muted-foreground/50 text-sm"
|
|
106
|
+
>
|
|
107
|
+
{item.icon}
|
|
108
|
+
{item.label}
|
|
109
|
+
</span>
|
|
110
|
+
) : (
|
|
111
|
+
<Link
|
|
112
|
+
key={item.name}
|
|
113
|
+
href={item.href}
|
|
114
|
+
aria-current={item.active ? "page" : undefined}
|
|
115
|
+
className={cn(
|
|
116
|
+
"flex items-center gap-2 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm transition-colors",
|
|
117
|
+
item.active
|
|
118
|
+
? "bg-muted font-medium"
|
|
119
|
+
: "text-muted-foreground hover:bg-muted/60",
|
|
120
|
+
)}
|
|
121
|
+
>
|
|
122
|
+
{item.icon}
|
|
123
|
+
{item.label}
|
|
124
|
+
</Link>
|
|
125
|
+
),
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
))}
|
|
129
|
+
</nav>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CardContent } from "@alepha/ui/components/ui/card";
|
|
2
|
+
import { cn } from "@alepha/ui/lib/utils";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
export interface SettingsRowProps {
|
|
6
|
+
/**
|
|
7
|
+
* What the row is about. Rendered as the emphasised left-hand text.
|
|
8
|
+
*/
|
|
9
|
+
label: ReactNode;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* One line of explanation under the label. Omit when the label says it all
|
|
13
|
+
* — an empty helper line is worse than none.
|
|
14
|
+
*/
|
|
15
|
+
description?: ReactNode;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `id` of the form control this row labels. Set it whenever `children` is an
|
|
19
|
+
* input: the label then renders as a real `<label htmlFor>` rather than a
|
|
20
|
+
* `<span>`, which is what gives the control an accessible name and makes
|
|
21
|
+
* clicking the label focus it.
|
|
22
|
+
*
|
|
23
|
+
* Without it the row is a `<span>` — correct for a row whose control is a
|
|
24
|
+
* button or a read-only value, where the button carries its own name and a
|
|
25
|
+
* `<label>` pointing at nothing would be worse than none.
|
|
26
|
+
*/
|
|
27
|
+
htmlFor?: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The control this row exists for: a button, a switch, a badge, a value.
|
|
31
|
+
* Sits right of the label on `sm` and up, and underneath it below that.
|
|
32
|
+
*/
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* One line of a settings card: label and optional help on the left, a single
|
|
40
|
+
* control on the right.
|
|
41
|
+
*
|
|
42
|
+
* The grid is `minmax(0,1fr) auto`, not `justify-between`. The difference
|
|
43
|
+
* matters when the label is long: `minmax(0,…)` lets the text column shrink
|
|
44
|
+
* and wrap, where a flex row would let it push the control off the card. It
|
|
45
|
+
* collapses to a stacked `flex-col` below `sm`, because a button crushed into
|
|
46
|
+
* a 90px column is worse than a button on its own line.
|
|
47
|
+
*
|
|
48
|
+
* Rows carry all the vertical padding (`py-3`) and {@link SettingsSection}'s
|
|
49
|
+
* card carries none (`py-0`) — see that component for why the two must not
|
|
50
|
+
* both have it.
|
|
51
|
+
*/
|
|
52
|
+
export const SettingsRow = (props: SettingsRowProps) => {
|
|
53
|
+
return (
|
|
54
|
+
<CardContent
|
|
55
|
+
className={cn(
|
|
56
|
+
"flex flex-col gap-3 px-4 py-3 sm:grid sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center sm:gap-6",
|
|
57
|
+
props.className,
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
<div className="flex flex-col gap-0.5">
|
|
61
|
+
{props.htmlFor ? (
|
|
62
|
+
<label htmlFor={props.htmlFor} className="font-medium text-sm">
|
|
63
|
+
{props.label}
|
|
64
|
+
</label>
|
|
65
|
+
) : (
|
|
66
|
+
<span className="font-medium text-sm">{props.label}</span>
|
|
67
|
+
)}
|
|
68
|
+
{props.description ? (
|
|
69
|
+
<span className="text-muted-foreground text-xs">
|
|
70
|
+
{props.description}
|
|
71
|
+
</span>
|
|
72
|
+
) : null}
|
|
73
|
+
</div>
|
|
74
|
+
{props.children ? (
|
|
75
|
+
<div className="flex justify-start sm:justify-end">
|
|
76
|
+
{props.children}
|
|
77
|
+
</div>
|
|
78
|
+
) : null}
|
|
79
|
+
</CardContent>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Card } from "@alepha/ui/components/ui/card";
|
|
2
|
+
import { cn } from "@alepha/ui/lib/utils";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
export interface SettingsSectionProps {
|
|
6
|
+
/**
|
|
7
|
+
* Heading above the card. Optional — a page whose first section needs no
|
|
8
|
+
* heading (because the page title already says it) omits it.
|
|
9
|
+
*/
|
|
10
|
+
title?: ReactNode;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* One line under the title, for context the rows themselves should not
|
|
14
|
+
* each repeat.
|
|
15
|
+
*/
|
|
16
|
+
description?: ReactNode;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* {@link SettingsRow}s. Anything else works too, but the divider and the
|
|
20
|
+
* padding contract below assume rows.
|
|
21
|
+
*/
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A titled group of settings rows in one bordered card — the GitHub-settings
|
|
29
|
+
* shape.
|
|
30
|
+
*
|
|
31
|
+
* ⚠️ **The card is `py-0` and that is deliberate.** `Card` ships its own
|
|
32
|
+
* vertical padding (`py-(--card-spacing)`), and every {@link SettingsRow}
|
|
33
|
+
* brings `py-3`. Leave both on and the two stack into a visibly thick blank
|
|
34
|
+
* band at the top and bottom of the card. `py-0` opts the card out so each
|
|
35
|
+
* row's own padding is the only vertical space, which is also what makes
|
|
36
|
+
* `divide-y` land flush between rows.
|
|
37
|
+
*
|
|
38
|
+
* The rule is one or the other, never both — so do **not** "fix" this to a
|
|
39
|
+
* numeric `py-4` / `py-3`. Several pages in `apps/lore`'s project settings did
|
|
40
|
+
* exactly that and they are the ones that look wrong next to these.
|
|
41
|
+
*/
|
|
42
|
+
export const SettingsSection = (props: SettingsSectionProps) => {
|
|
43
|
+
const hasHeading = props.title != null || props.description != null;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div className={cn("flex flex-col gap-2", props.className)}>
|
|
47
|
+
{hasHeading ? (
|
|
48
|
+
<div className="flex flex-col gap-0.5">
|
|
49
|
+
{props.title != null ? (
|
|
50
|
+
<span className="text-sm">{props.title}</span>
|
|
51
|
+
) : null}
|
|
52
|
+
{props.description != null ? (
|
|
53
|
+
<span className="text-muted-foreground text-xs">
|
|
54
|
+
{props.description}
|
|
55
|
+
</span>
|
|
56
|
+
) : null}
|
|
57
|
+
</div>
|
|
58
|
+
) : null}
|
|
59
|
+
<Card className="gap-0 divide-y rounded-lg border bg-card py-0">
|
|
60
|
+
{props.children}
|
|
61
|
+
</Card>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
};
|