@eifi1/ui-kit 0.40.1 → 0.42.0
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/README.md +19 -6
- package/dist/admin/admin-area-labels.d.ts +55 -0
- package/dist/admin/admin-area-labels.js +33 -0
- package/dist/admin/admin-area-labels.js.map +1 -0
- package/dist/admin/admin-forbidden.d.ts +35 -0
- package/dist/admin/admin-forbidden.js +36 -0
- package/dist/admin/admin-forbidden.js.map +1 -0
- package/dist/admin/admin-overview.d.ts +93 -0
- package/dist/admin/admin-overview.js +69 -0
- package/dist/admin/admin-overview.js.map +1 -0
- package/dist/admin/admin-sections.d.ts +63 -0
- package/dist/admin/admin-sections.js +64 -0
- package/dist/admin/admin-sections.js.map +1 -0
- package/dist/admin/admin-tool-links.d.ts +48 -0
- package/dist/admin/admin-tool-links.js +31 -0
- package/dist/admin/admin-tool-links.js.map +1 -0
- package/dist/billing/billing-banner.d.ts +25 -2
- package/dist/billing/billing-banner.js +5 -2
- package/dist/billing/billing-banner.js.map +1 -1
- package/dist/billing/billing-labels.d.ts +32 -0
- package/dist/billing/billing-labels.js +9 -0
- package/dist/billing/billing-labels.js.map +1 -1
- package/dist/billing/billing-overview.d.ts +33 -0
- package/dist/billing/billing-overview.js +6 -0
- package/dist/billing/billing-overview.js.map +1 -1
- package/dist/billing/billing-standing.d.ts +8 -0
- package/dist/billing/billing-standing.js.map +1 -1
- package/dist/billing/cancel-subscription.d.ts +46 -0
- package/dist/billing/cancel-subscription.js +57 -0
- package/dist/billing/cancel-subscription.js.map +1 -0
- package/dist/billing/plan-card.d.ts +45 -1
- package/dist/billing/plan-card.js +53 -2
- package/dist/billing/plan-card.js.map +1 -1
- package/dist/billing/plan-switch.d.ts +10 -1
- package/dist/billing/plan-switch.js +22 -13
- package/dist/billing/plan-switch.js.map +1 -1
- package/dist/billing/subscription-actions.d.ts +37 -4
- package/dist/billing/subscription-actions.js +10 -3
- package/dist/billing/subscription-actions.js.map +1 -1
- package/dist/components/account-chips.d.ts +42 -1
- package/dist/components/account-chips.js +33 -0
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/empty-state.d.ts +2 -1
- package/dist/components/empty-state.js.map +1 -1
- package/dist/components/nav-pills.d.ts +2 -2
- package/dist/components/nav-pills.js.map +1 -1
- package/dist/components/tabs.d.ts +4 -32
- package/dist/components/tabs.js +30 -66
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/translation-review-parts.d.ts +2 -2
- package/dist/components/translation-review-parts.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/feedback/feedback-menu-labels.js +0 -2
- package/dist/feedback/feedback-menu-labels.js.map +1 -1
- package/dist/feedback/feedback-menu.d.ts +0 -6
- package/dist/feedback/feedback-menu.js.map +1 -1
- package/dist/i18n/defaults.js +5 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.js +79 -2
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +9 -0
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/en.js +93 -3
- package/dist/i18n/locales/en.js.map +3 -3
- package/dist/i18n/locales/es.js +76 -2
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +75 -2
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +76 -2
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +76 -2
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +75 -2
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +20 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +18 -2
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/dist/settings/settings-layout.d.ts +7 -1
- package/dist/settings/settings-layout.js +35 -27
- package/dist/settings/settings-layout.js.map +1 -1
- package/dist/shell/account-menu-language.d.ts +46 -0
- package/dist/shell/account-menu-language.js +64 -0
- package/dist/shell/account-menu-language.js.map +1 -0
- package/dist/shell/admin-menu.d.ts +46 -0
- package/dist/shell/admin-menu.js +60 -0
- package/dist/shell/admin-menu.js.map +1 -0
- package/dist/shell/app-shell.d.ts +10 -0
- package/dist/shell/app-shell.js +22 -4
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/dev-switchers.d.ts +53 -0
- package/dist/shell/dev-switchers.js +102 -0
- package/dist/shell/dev-switchers.js.map +1 -0
- package/dist/shell/sync-status-indicator.d.ts +86 -0
- package/dist/shell/sync-status-indicator.js +170 -0
- package/dist/shell/sync-status-indicator.js.map +1 -0
- package/dist/shell/top-bar-actions.d.ts +49 -0
- package/dist/shell/top-bar-actions.js +31 -0
- package/dist/shell/top-bar-actions.js.map +1 -0
- package/dist/shell/top-bar-parts-labels.d.ts +84 -0
- package/dist/shell/top-bar-parts-labels.js +48 -0
- package/dist/shell/top-bar-parts-labels.js.map +1 -0
- package/dist/shell/topbar-action-menu.d.ts +13 -1
- package/dist/shell/topbar-action-menu.js +5 -2
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell/topbar-controls.d.ts +16 -3
- package/dist/shell/topbar-controls.js +5 -1
- package/dist/shell/topbar-controls.js.map +1 -1
- package/dist/shell/tour-menu.d.ts +58 -0
- package/dist/shell/tour-menu.js +73 -0
- package/dist/shell/tour-menu.js.map +1 -0
- package/dist/shell.d.ts +14 -0
- package/dist/shell.js +19 -0
- package/dist/shell.js.map +1 -1
- package/package.json +1 -1
- package/src/admin/admin-area-labels.ts +85 -0
- package/src/admin/admin-forbidden.tsx +75 -0
- package/src/admin/admin-overview.tsx +166 -0
- package/src/admin/admin-sections.tsx +137 -0
- package/src/admin/admin-tool-links.tsx +84 -0
- package/src/billing/billing-banner.tsx +32 -4
- package/src/billing/billing-labels.ts +53 -0
- package/src/billing/billing-overview.ts +37 -0
- package/src/billing/billing-standing.ts +8 -0
- package/src/billing/cancel-subscription.tsx +102 -0
- package/src/billing/plan-card.tsx +97 -1
- package/src/billing/plan-switch.tsx +16 -0
- package/src/billing/subscription-actions.tsx +64 -15
- package/src/components/account-chips.tsx +81 -1
- package/src/components/empty-state.tsx +2 -1
- package/src/components/nav-pills.tsx +2 -2
- package/src/components/tabs.tsx +19 -110
- package/src/components/translation-review-parts.tsx +2 -2
- package/src/feedback/feedback-menu-labels.ts +0 -2
- package/src/feedback/feedback-menu.tsx +0 -6
- package/src/i18n/defaults.ts +4 -0
- package/src/i18n/german.ts +92 -2
- package/src/i18n/kit-labels.tsx +9 -0
- package/src/i18n/locales/en.ts +19 -0
- package/src/i18n/locales/es.ts +86 -2
- package/src/i18n/locales/fr.ts +86 -2
- package/src/i18n/locales/hu.ts +84 -2
- package/src/i18n/locales/it.ts +87 -2
- package/src/i18n/locales/zh.ts +79 -2
- package/src/i18n/review.ts +19 -0
- package/src/index.ts +30 -2
- package/src/settings/settings-layout.tsx +58 -34
- package/src/shell/account-menu-language.tsx +116 -0
- package/src/shell/admin-menu.tsx +117 -0
- package/src/shell/app-shell.tsx +44 -3
- package/src/shell/dev-switchers.tsx +171 -0
- package/src/shell/sync-status-indicator.tsx +301 -0
- package/src/shell/top-bar-actions.tsx +79 -0
- package/src/shell/top-bar-parts-labels.ts +133 -0
- package/src/shell/topbar-action-menu.tsx +15 -2
- package/src/shell/topbar-controls.tsx +20 -3
- package/src/shell/tour-menu.tsx +144 -0
- package/src/shell.ts +24 -0
|
@@ -40,6 +40,9 @@ export type SettingsLayoutWidth = "6xl" | "7xl";
|
|
|
40
40
|
* about twelve, keksdose 26; a page of six needs none. */
|
|
41
41
|
export const SETTINGS_SEARCH_THRESHOLD = 8;
|
|
42
42
|
|
|
43
|
+
/** The desktop sidebar's column: sticky beside a long group (§3.2). */
|
|
44
|
+
const SIDEBAR_COLUMN = "mb-4 md:sticky md:top-6 md:mb-0 md:self-start";
|
|
45
|
+
|
|
43
46
|
export interface SettingsLayoutProps<G extends string> {
|
|
44
47
|
/** The page's `h1`: "Settings", "Administration". Default: `labels.title`. */
|
|
45
48
|
title?: ReactNode;
|
|
@@ -72,6 +75,12 @@ export interface SettingsLayoutProps<G extends string> {
|
|
|
72
75
|
* own navigation carries them.
|
|
73
76
|
*/
|
|
74
77
|
phoneFooter?: ReactNode;
|
|
78
|
+
/**
|
|
79
|
+
* 0.42.0 (docs/admin-harmonization.md §2.5 decision 16): content under the section
|
|
80
|
+
* list on a desktop, in the same sticky column — the admin area's Tools list
|
|
81
|
+
* (`AdminToolLinks`). Not shown on a phone, where `phoneFooter` carries the same links.
|
|
82
|
+
*/
|
|
83
|
+
sidebarFooter?: ReactNode;
|
|
75
84
|
/** Prop > `<UiKitProvider labels={{ settings }}>` > English. */
|
|
76
85
|
labels?: LabelOverride<SettingsLabels>;
|
|
77
86
|
/** See {@link SettingsLayoutMode}. Default `"auto"`: the screen decides. */
|
|
@@ -151,6 +160,7 @@ export function SettingsLayout<G extends string>({
|
|
|
151
160
|
width = "6xl",
|
|
152
161
|
renderGroup,
|
|
153
162
|
phoneFooter,
|
|
163
|
+
sidebarFooter,
|
|
154
164
|
labels: labelsProp,
|
|
155
165
|
layout = "auto",
|
|
156
166
|
appName,
|
|
@@ -376,45 +386,59 @@ export function SettingsLayout<G extends string>({
|
|
|
376
386
|
);
|
|
377
387
|
} else {
|
|
378
388
|
const open = group === null ? undefined : groupById.get(group);
|
|
389
|
+
// The section list alone, or (0.42) with the app's `sidebarFooter` under it in one
|
|
390
|
+
// sticky column.
|
|
391
|
+
const withSidebarFooter = (tabs: ReactNode) =>
|
|
392
|
+
sidebarFooter == null ? (
|
|
393
|
+
tabs
|
|
394
|
+
) : (
|
|
395
|
+
<div className={cn(SIDEBAR_COLUMN, "space-y-6")}>
|
|
396
|
+
{tabs}
|
|
397
|
+
<div data-slot="settings-sidebar-footer">{sidebarFooter}</div>
|
|
398
|
+
</div>
|
|
399
|
+
);
|
|
379
400
|
body = (
|
|
380
401
|
<div className={pageClass} data-settings-view="desktop">
|
|
381
402
|
<PageHeader size="compact" title={pageTitle} />
|
|
382
403
|
{searchField}
|
|
383
404
|
<div className="md:grid md:grid-cols-[14rem_minmax(0,1fr)] md:gap-6">
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
<
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
405
|
+
{withSidebarFooter(
|
|
406
|
+
<Tabs<G>
|
|
407
|
+
orientation="vertical"
|
|
408
|
+
aria-label={labels.sections}
|
|
409
|
+
// Sticky (new in the harmonisation, §3.2): keksdose's notifications group
|
|
410
|
+
// scrolls for screens, and the list should stay in view beside it. With a
|
|
411
|
+
// `sidebarFooter` the column round both is the sticky one.
|
|
412
|
+
className={sidebarFooter == null ? SIDEBAR_COLUMN : undefined}
|
|
413
|
+
panelId={open && !searching ? panelId : undefined}
|
|
414
|
+
tabs={route.groups.map((g) => {
|
|
415
|
+
const count = hitsByGroup.get(g.id) ?? 0;
|
|
416
|
+
// While searching, the groups with nothing to show step back (keksdose).
|
|
417
|
+
const dim = searching && count === 0;
|
|
418
|
+
return {
|
|
419
|
+
id: g.id,
|
|
420
|
+
href: `${root}${settingsHref(base, g.id)}`,
|
|
421
|
+
name: g.title,
|
|
422
|
+
label: <span className={cn(dim && "opacity-40")}>{g.title}</span>,
|
|
423
|
+
icon: <span className={cn("inline-flex [&_svg]:size-4", dim && "opacity-40")}>{g.icon}</span>,
|
|
424
|
+
badge:
|
|
425
|
+
searching && count > 0 ? (
|
|
426
|
+
<Chip size="sm" tone="brand">
|
|
427
|
+
<span aria-hidden>{count}</span>
|
|
428
|
+
<span className="sr-only-fixed">{labels.matchCount(count)}</span>
|
|
429
|
+
</Chip>
|
|
430
|
+
) : undefined,
|
|
431
|
+
};
|
|
432
|
+
})}
|
|
433
|
+
active={(open?.id ?? route.groups[0]?.id) as G}
|
|
434
|
+
onChange={(id) => {
|
|
435
|
+
// While searching the hits stand where the group would; a click on a group
|
|
436
|
+
// means "go there", so the search makes way (keksdose).
|
|
437
|
+
setQuery("");
|
|
438
|
+
select(id);
|
|
439
|
+
}}
|
|
440
|
+
/>,
|
|
441
|
+
)}
|
|
418
442
|
<div className="min-w-0 space-y-4">
|
|
419
443
|
{searching ? (
|
|
420
444
|
results
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { Globe } from "lucide-react";
|
|
4
|
+
import { Disclosure } from "../components/disclosure";
|
|
5
|
+
import { MenuItem } from "../components/menu-item";
|
|
6
|
+
import { DEFAULT_TOP_BAR_LABELS, useKitLabels } from "../i18n/kit-labels";
|
|
7
|
+
|
|
8
|
+
/** One offered language in the account menu's sub-list. */
|
|
9
|
+
export interface AccountMenuLanguageOption {
|
|
10
|
+
code: string;
|
|
11
|
+
/** Its name, in its own language ("Deutsch", "Français"). */
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* A flag before the name, as the app draws it — keksdose's flag-icons span
|
|
15
|
+
* (`<span aria-hidden className="fi fi-ch …" />`). A node rather than a country code, so
|
|
16
|
+
* the kit ships no flag set; decorative, so give it `aria-hidden`.
|
|
17
|
+
*/
|
|
18
|
+
flag?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Or the ISO 3166-1 alpha-2 country (lowercase) whose flag-icons flag to draw, as
|
|
21
|
+
* `LanguageMenu`'s `LanguageOption` takes it — so one language list feeds both
|
|
22
|
+
* (Kurvenschmiede's `LANGUAGES`). Needs the app's flag-icons CSS, as `LanguageMenu`
|
|
23
|
+
* does. `flag` wins when both are given.
|
|
24
|
+
*/
|
|
25
|
+
country?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The option's flag: its own node, else the flag-icons flag of its country. */
|
|
29
|
+
function flagOf(lang: AccountMenuLanguageOption): ReactNode {
|
|
30
|
+
if (lang.flag !== undefined) return lang.flag;
|
|
31
|
+
if (!lang.country) return undefined;
|
|
32
|
+
return (
|
|
33
|
+
<span
|
|
34
|
+
aria-hidden
|
|
35
|
+
data-country={lang.country}
|
|
36
|
+
className={`fi fi-${lang.country} inline-block h-[0.9375rem] w-5 shrink-0 rounded-sm shadow-[0_0_0_1px_rgba(0,0,0,0.08)]`}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AccountMenuLanguageProps {
|
|
42
|
+
languages: readonly AccountMenuLanguageOption[];
|
|
43
|
+
/** The active language's code. */
|
|
44
|
+
value: string | undefined;
|
|
45
|
+
/** A pick: the app sets the device's language and, signed in, the account's
|
|
46
|
+
* (settings §6.2). */
|
|
47
|
+
onPick: (code: string) => void;
|
|
48
|
+
/** The account menu's `close` (from `TopBarActionMenu`'s `children`): a pick shuts it. */
|
|
49
|
+
close?: () => void;
|
|
50
|
+
/** The row's name. Default: `topBar.language` ("Language"). */
|
|
51
|
+
label?: string;
|
|
52
|
+
/** Open the sub-list at first. Default `false`. */
|
|
53
|
+
defaultOpen?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The language choice INSIDE the account menu (docs/top-bar-harmonization.md §2.3),
|
|
58
|
+
* keksdose's sub-list: a `Disclosure variant="menu"` row — the globe, "Language", the
|
|
59
|
+
* active language's flag and the chevron — that opens in place onto one checked
|
|
60
|
+
* `MenuItem` per language. Inline rather than a nested popover: a popover inside a
|
|
61
|
+
* popover fights the outside click and has nowhere to go on a phone (keksdose #140).
|
|
62
|
+
*
|
|
63
|
+
* It renders its own `<li>`: drop it into `TopBarActionMenu`'s `children` first after the
|
|
64
|
+
* app's context rows (§6.5). Signed out there is no account menu; `LanguageMenu` stays
|
|
65
|
+
* the bar's button (§2.3).
|
|
66
|
+
*/
|
|
67
|
+
export function AccountMenuLanguage({
|
|
68
|
+
languages,
|
|
69
|
+
value,
|
|
70
|
+
onPick,
|
|
71
|
+
close,
|
|
72
|
+
label,
|
|
73
|
+
defaultOpen = false,
|
|
74
|
+
}: AccountMenuLanguageProps) {
|
|
75
|
+
const words = useKitLabels("topBar", DEFAULT_TOP_BAR_LABELS);
|
|
76
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
77
|
+
const active = languages.find((l) => l.code === value);
|
|
78
|
+
return (
|
|
79
|
+
<li>
|
|
80
|
+
<Disclosure
|
|
81
|
+
variant="menu"
|
|
82
|
+
open={open}
|
|
83
|
+
onOpenChange={setOpen}
|
|
84
|
+
title={
|
|
85
|
+
<span className="flex items-center justify-between gap-3">
|
|
86
|
+
<span className="flex items-center gap-2">
|
|
87
|
+
<Globe aria-hidden className="size-4" />
|
|
88
|
+
{label ?? words.language}
|
|
89
|
+
</span>
|
|
90
|
+
{active && flagOf(active)}
|
|
91
|
+
</span>
|
|
92
|
+
}
|
|
93
|
+
>
|
|
94
|
+
<ul>
|
|
95
|
+
{languages.map((lang) => (
|
|
96
|
+
<li key={lang.code}>
|
|
97
|
+
<MenuItem
|
|
98
|
+
checked={lang.code === value}
|
|
99
|
+
onClick={() => {
|
|
100
|
+
onPick(lang.code);
|
|
101
|
+
setOpen(false);
|
|
102
|
+
close?.();
|
|
103
|
+
}}
|
|
104
|
+
leading={flagOf(lang)}
|
|
105
|
+
// Under the row's own text, past the globe.
|
|
106
|
+
className="ps-9"
|
|
107
|
+
>
|
|
108
|
+
{lang.label}
|
|
109
|
+
</MenuItem>
|
|
110
|
+
</li>
|
|
111
|
+
))}
|
|
112
|
+
</ul>
|
|
113
|
+
</Disclosure>
|
|
114
|
+
</li>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Link } from "react-router";
|
|
2
|
+
import { ShieldCheck } from "lucide-react";
|
|
3
|
+
import { Chip } from "../components/chip";
|
|
4
|
+
import { MenuItem } from "../components/menu-item";
|
|
5
|
+
import { useKitLabels, type LabelOverride } from "../i18n/kit-labels";
|
|
6
|
+
import { DEFAULT_ADMIN_AREA_LABELS } from "../admin/admin-area-labels";
|
|
7
|
+
import type { AdminAreaLabels } from "../admin/admin-area-labels";
|
|
8
|
+
import type { TopBarMenuEntry } from "./topbar-action-menu";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The account menu's "Administration" row (0.42.0, docs/admin-harmonization.md §2.1, §6.6,
|
|
12
|
+
* §7): the way into the admin area everyone finds, in every app, for an admin only. Two
|
|
13
|
+
* forms of one row — {@link adminMenuEntry} for `TopBarActionMenu`'s `entries`, and
|
|
14
|
+
* {@link AdminMenuRow} for a menu built from `HoverMenu` children (Kurvenschmiede's).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The badge's text: nothing for none or 0, "99+" past 99. */
|
|
18
|
+
function badgeText(badge: number | null | undefined): string | null {
|
|
19
|
+
if (typeof badge !== "number" || !(badge > 0)) return null;
|
|
20
|
+
return badge > 99 ? "99+" : String(Math.floor(badge));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The waiting count at the row's end: the `solid` count pill of {@link Chip}, in the
|
|
25
|
+
* pending count's tone, with the number for the eye and `adminArea.waiting` for a reader
|
|
26
|
+
* ("Administration, 3 waiting"). `null` for no count.
|
|
27
|
+
*/
|
|
28
|
+
function WaitingBadge({ badge, labels }: { badge: number | null | undefined; labels: AdminAreaLabels }) {
|
|
29
|
+
const text = badgeText(badge);
|
|
30
|
+
if (text === null) return null;
|
|
31
|
+
return (
|
|
32
|
+
<Chip size="sm" variant="solid" tone="warning" data-slot="admin-badge">
|
|
33
|
+
<span aria-hidden>{text}</span>
|
|
34
|
+
{/* The comma parts it from the row's label in the name: "Administration, 3 waiting". */}
|
|
35
|
+
<span className="sr-only-fixed">, {labels.waiting(badge as number)}</span>
|
|
36
|
+
</Chip>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AdminMenuEntryOptions {
|
|
41
|
+
/** The admin area. Default `/admin`. */
|
|
42
|
+
href?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The waiting count (§2.4 decision 15, §6.3): only work that waits on this admin —
|
|
45
|
+
* `adminWaitingCount(attention, […])`. `0`, `null` or none shows no badge.
|
|
46
|
+
*/
|
|
47
|
+
badge?: number | null;
|
|
48
|
+
/** The resolved `adminArea` words (`useAdminAreaLabels()`); default English. Builds no
|
|
49
|
+
* hook, so the entry can be made in the list of entries. */
|
|
50
|
+
labels?: AdminAreaLabels;
|
|
51
|
+
/** The entry's `key`. Default `"administration"`. */
|
|
52
|
+
key?: string;
|
|
53
|
+
/** The page already open: `aria-current` and a check mark. */
|
|
54
|
+
current?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The "Administration" {@link TopBarMenuEntry}: a link row with the `ShieldCheck` icon,
|
|
59
|
+
* the kit's word and the waiting count as its badge. Put it in the entries for an admin
|
|
60
|
+
* only — the menu closes on the way, as any link row:
|
|
61
|
+
*
|
|
62
|
+
* entries={[…, ...(isAdmin ? [adminMenuEntry({ badge: waiting, labels })] : []), …]}
|
|
63
|
+
*/
|
|
64
|
+
export function adminMenuEntry({
|
|
65
|
+
href = "/admin",
|
|
66
|
+
badge,
|
|
67
|
+
labels = DEFAULT_ADMIN_AREA_LABELS,
|
|
68
|
+
key = "administration",
|
|
69
|
+
current,
|
|
70
|
+
}: AdminMenuEntryOptions = {}): TopBarMenuEntry {
|
|
71
|
+
return {
|
|
72
|
+
kind: "link",
|
|
73
|
+
key,
|
|
74
|
+
to: href,
|
|
75
|
+
icon: <ShieldCheck className="size-4" aria-hidden />,
|
|
76
|
+
label: labels.title,
|
|
77
|
+
trailing: badgeText(badge) === null ? undefined : <WaitingBadge badge={badge} labels={labels} />,
|
|
78
|
+
current,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface AdminMenuRowProps {
|
|
83
|
+
/** The admin area. Default `/admin`. */
|
|
84
|
+
href?: string;
|
|
85
|
+
/** As {@link AdminMenuEntryOptions.badge}. */
|
|
86
|
+
badge?: number | null;
|
|
87
|
+
/** Runs on the way — `HoverMenu`'s `close`. */
|
|
88
|
+
onNavigate?: () => void;
|
|
89
|
+
current?: boolean;
|
|
90
|
+
/** Prop > `<UiKitProvider labels={{ adminArea }}>` > English. */
|
|
91
|
+
labels?: LabelOverride<AdminAreaLabels>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The same row as {@link adminMenuEntry} for a menu drawn from `HoverMenu` children: the
|
|
96
|
+
* `<li>` holding the router-link {@link MenuItem} `TopBarActionMenu` draws for a link
|
|
97
|
+
* entry, so the two menus look alike.
|
|
98
|
+
*
|
|
99
|
+
* {(close) => <ul>… {isAdmin && <AdminMenuRow badge={waiting} onNavigate={close} />} …</ul>}
|
|
100
|
+
*/
|
|
101
|
+
export function AdminMenuRow({ href = "/admin", badge, onNavigate, current, labels: labelsProp }: AdminMenuRowProps) {
|
|
102
|
+
const labels = useKitLabels("adminArea", DEFAULT_ADMIN_AREA_LABELS, labelsProp);
|
|
103
|
+
return (
|
|
104
|
+
<li>
|
|
105
|
+
<MenuItem
|
|
106
|
+
href={href}
|
|
107
|
+
renderLink={({ href: to, ...p }) => <Link to={to} {...p} />}
|
|
108
|
+
onClick={onNavigate ? () => onNavigate() : undefined}
|
|
109
|
+
leading={<ShieldCheck className="size-4" aria-hidden />}
|
|
110
|
+
trailing={badgeText(badge) === null ? undefined : <WaitingBadge badge={badge} labels={labels} />}
|
|
111
|
+
current={current}
|
|
112
|
+
>
|
|
113
|
+
{labels.title}
|
|
114
|
+
</MenuItem>
|
|
115
|
+
</li>
|
|
116
|
+
);
|
|
117
|
+
}
|
package/src/shell/app-shell.tsx
CHANGED
|
@@ -91,6 +91,16 @@ export type AppShellSidebarFooterItem =
|
|
|
91
91
|
hint?: string;
|
|
92
92
|
/** Leaves the app: a plain `<a target="_blank" rel="noopener noreferrer">`. */
|
|
93
93
|
external?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* 0.42.0 (docs/admin-harmonization.md §6.9): a count of what waits behind the link —
|
|
96
|
+
* kastlan's "Administration" with its To-triage count. A pill at the end of the
|
|
97
|
+
* expanded link, a corner dot on the collapsed icon; `0`, `null` or none shows
|
|
98
|
+
* nothing, and above 99 it reads "99+". The count joins the link's name, in
|
|
99
|
+
* `badgeLabel`'s words when given ("Administration, 3 waiting").
|
|
100
|
+
*/
|
|
101
|
+
badge?: number | null;
|
|
102
|
+
/** The badge's words for a reader — `adminArea.waiting(count)`. Default: the number. */
|
|
103
|
+
badgeLabel?: string;
|
|
94
104
|
}
|
|
95
105
|
| {
|
|
96
106
|
kind: "links";
|
|
@@ -589,6 +599,17 @@ const plainLink: KitLinkComponent = ({ children, ...p }) => <a {...p}>{children}
|
|
|
589
599
|
const FOOTER_ICON_LINK =
|
|
590
600
|
"flex min-h-8 items-center justify-center rounded-md text-muted hover:bg-hover hover:text-secondary";
|
|
591
601
|
|
|
602
|
+
/** A footer link's count as drawn: nothing for none, "99+" past 99. */
|
|
603
|
+
function footerBadgeText(badge: number | null | undefined): string | null {
|
|
604
|
+
if (typeof badge !== "number" || !(badge > 0)) return null;
|
|
605
|
+
return badge > 99 ? "99+" : String(Math.floor(badge));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** The count's pill — the solid "count" look of `Chip` (warning, the pending count's
|
|
609
|
+
* tone, as `FloatingActionGroup`'s badge), sized for the footer's small text. */
|
|
610
|
+
const FOOTER_BADGE =
|
|
611
|
+
"inline-flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full bg-warning px-1 text-micro font-semibold leading-4 tabular-nums text-warning-contrast";
|
|
612
|
+
|
|
592
613
|
/** Calls the link renderer as a component, so a router link's hooks are its own. */
|
|
593
614
|
function RenderedLink({ render, ...props }: KitLinkProps & { render: KitLinkComponent }) {
|
|
594
615
|
return render(props);
|
|
@@ -627,12 +648,23 @@ function SidebarFooterItems({
|
|
|
627
648
|
const to = item.kind === "links" ? (item.to ?? item.links[0]?.to) : item.to;
|
|
628
649
|
if (!to) return null;
|
|
629
650
|
const external = item.kind === "links" ? item.links.find((l) => l.to === to)?.external : item.external;
|
|
651
|
+
const count = item.kind === "links" ? null : footerBadgeText(item.badge);
|
|
652
|
+
const spoken = count === null || item.kind === "links" ? null : (item.badgeLabel ?? count);
|
|
630
653
|
return (
|
|
631
654
|
<Tooltip key={item.key} label={item.label} side="end" portal className="block">
|
|
632
655
|
{linkTo(to, external, {
|
|
633
|
-
"aria-label": item.label,
|
|
634
|
-
className: FOOTER_ICON_LINK,
|
|
635
|
-
children:
|
|
656
|
+
"aria-label": spoken === null ? item.label : `${item.label}, ${spoken}`,
|
|
657
|
+
className: cn(FOOTER_ICON_LINK, count !== null && "relative"),
|
|
658
|
+
children: (
|
|
659
|
+
<>
|
|
660
|
+
<item.icon className="size-4" aria-hidden />
|
|
661
|
+
{count !== null && (
|
|
662
|
+
<span aria-hidden data-badge="" className={cn(FOOTER_BADGE, "absolute -top-0.5 end-0.5")}>
|
|
663
|
+
{count}
|
|
664
|
+
</span>
|
|
665
|
+
)}
|
|
666
|
+
</>
|
|
667
|
+
),
|
|
636
668
|
})}
|
|
637
669
|
</Tooltip>
|
|
638
670
|
);
|
|
@@ -655,6 +687,7 @@ function SidebarFooterItems({
|
|
|
655
687
|
</nav>
|
|
656
688
|
);
|
|
657
689
|
}
|
|
690
|
+
const count = footerBadgeText(item.badge);
|
|
658
691
|
const link = linkTo(item.to, item.external, {
|
|
659
692
|
className: cn(FOOTER_ICON_LINK, "gap-1.5 text-xs font-medium"),
|
|
660
693
|
children: (
|
|
@@ -663,6 +696,14 @@ function SidebarFooterItems({
|
|
|
663
696
|
{/* Wraps from Large up (text size §10.17, round 0.34 T1): the link is
|
|
664
697
|
`min-h-8`, so it grows a line rather than cut "Feedb…". */}
|
|
665
698
|
<span className="min-w-0 truncate-until-large">{item.text ?? item.label}</span>
|
|
699
|
+
{count !== null && (
|
|
700
|
+
<>
|
|
701
|
+
<span aria-hidden data-badge="" className={FOOTER_BADGE}>
|
|
702
|
+
{count}
|
|
703
|
+
</span>
|
|
704
|
+
<span className="sr-only">, {item.badgeLabel ?? count}</span>
|
|
705
|
+
</>
|
|
706
|
+
)}
|
|
666
707
|
</>
|
|
667
708
|
),
|
|
668
709
|
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { FlaskConical, Undo2 } from "lucide-react";
|
|
4
|
+
import { DEFAULT_TOP_BAR_LABELS, useKitLabels, type LabelOverride } from "../i18n/kit-labels";
|
|
5
|
+
import { TopBarActionMenu, type TopBarMenuEntry } from "./topbar-action-menu";
|
|
6
|
+
import { useTopBarPartsLabels, type DevSwitchersLabels } from "./top-bar-parts-labels";
|
|
7
|
+
|
|
8
|
+
/** Where the role the session started with is kept, unless the app names its own key. */
|
|
9
|
+
export const DEV_ORIGINAL_ROLE_KEY = "ui-kit:dev-original-role";
|
|
10
|
+
|
|
11
|
+
function readKey(key: string): string | null {
|
|
12
|
+
try {
|
|
13
|
+
return sessionStorage.getItem(key);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function writeKey(key: string, value: string | null): void {
|
|
20
|
+
try {
|
|
21
|
+
if (value === null) sessionStorage.removeItem(key);
|
|
22
|
+
else sessionStorage.setItem(key, value);
|
|
23
|
+
} catch {
|
|
24
|
+
/* storage blocked: "Back to" lasts as long as this page */
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DevSwitchersProps<R extends string, P extends string> {
|
|
29
|
+
/** Draw anything at all: the app passes `import.meta.env.DEV`, so a production build
|
|
30
|
+
* tree-shakes the switchers with the constant. */
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
roles?: readonly R[];
|
|
33
|
+
/** The role the server enforces now. Named `currentRole`, not `role`, because `role` on
|
|
34
|
+
* a JSX element is the ARIA role (as `RoleChip`'s `value`). */
|
|
35
|
+
currentRole?: R;
|
|
36
|
+
/** Apply a role — the app calls server-kit's `POST /dev/switch {role}` and re-reads
|
|
37
|
+
* `/auth/me` (§2.7, §6.2). */
|
|
38
|
+
onRole?: (role: R) => void;
|
|
39
|
+
plans?: readonly P[];
|
|
40
|
+
/** The plan the server enforces now. Left out (not known yet — kastlan's overview is a
|
|
41
|
+
* 404 while billing is off), the plan menu still renders, with no row checked; a
|
|
42
|
+
* `GET /dev/switch` answers it. */
|
|
43
|
+
currentPlan?: P;
|
|
44
|
+
/** Apply a plan — `POST /dev/switch {plan}`, then the overview (§6.3). */
|
|
45
|
+
onPlan?: (plan: P) => void;
|
|
46
|
+
/**
|
|
47
|
+
* The role to offer "Back to {role}" for. Left out, the kit keeps it itself: the role
|
|
48
|
+
* before the first switch of this browser session, in `sessionStorage` under
|
|
49
|
+
* `storageKey` — the server answers with the NEW role after a switch, so only the
|
|
50
|
+
* browser still knows the old one.
|
|
51
|
+
*/
|
|
52
|
+
originalRole?: R;
|
|
53
|
+
/** The `sessionStorage` key for the kept role. Default {@link DEV_ORIGINAL_ROLE_KEY};
|
|
54
|
+
* an app with several accounts on one browser may scope it per user. */
|
|
55
|
+
storageKey?: string;
|
|
56
|
+
/** Billing is off locally: the plan menu says plans change nothing, and stays usable
|
|
57
|
+
* (§6.3). */
|
|
58
|
+
billingOff?: boolean;
|
|
59
|
+
/** A role's or a plan's words in the menu. Default: the value itself. */
|
|
60
|
+
roleLabel?: (role: R) => ReactNode;
|
|
61
|
+
planLabel?: (plan: P) => ReactNode;
|
|
62
|
+
/** Prop > `<UiKitProvider labels={{ topBarParts: { dev } }}>` > English. */
|
|
63
|
+
labels?: LabelOverride<DevSwitchersLabels>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const flask = <FlaskConical className="size-5 text-warning" />;
|
|
67
|
+
|
|
68
|
+
/** A label's text for a sentence, or the raw value when the label is not text. */
|
|
69
|
+
const textOf = (label: ReactNode, value: string) =>
|
|
70
|
+
typeof label === "string" || typeof label === "number" ? String(label) : value;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The top bar's local-dev switchers (docs/top-bar-harmonization.md §2.7, §6.2, §6.3): the
|
|
74
|
+
* role, then the plan, each a menu behind `RoleSwitcher`'s amber flask. Nothing renders
|
|
75
|
+
* unless `enabled`; either menu renders only with its list and handler.
|
|
76
|
+
*
|
|
77
|
+
* The role menu ends in "Back to {role}" once the role differs from the one the session
|
|
78
|
+
* started with: the dev route needs only a signed-in user, so a switch to a lesser role
|
|
79
|
+
* can always switch back. With `billingOff` the plan menu notes that plans change nothing
|
|
80
|
+
* while billing is off.
|
|
81
|
+
*/
|
|
82
|
+
export function DevSwitchers<R extends string, P extends string>({
|
|
83
|
+
enabled,
|
|
84
|
+
roles,
|
|
85
|
+
currentRole: role,
|
|
86
|
+
onRole,
|
|
87
|
+
plans,
|
|
88
|
+
currentPlan: plan,
|
|
89
|
+
onPlan,
|
|
90
|
+
originalRole,
|
|
91
|
+
storageKey = DEV_ORIGINAL_ROLE_KEY,
|
|
92
|
+
billingOff = false,
|
|
93
|
+
roleLabel = (r) => r,
|
|
94
|
+
planLabel = (p) => p,
|
|
95
|
+
labels: labelsProp,
|
|
96
|
+
}: DevSwitchersProps<R, P>) {
|
|
97
|
+
const bar = useKitLabels("topBar", DEFAULT_TOP_BAR_LABELS);
|
|
98
|
+
const words = useTopBarPartsLabels(labelsProp ? { dev: labelsProp } : undefined).dev;
|
|
99
|
+
const [kept, setKept] = useState<string | null>(() => (enabled ? readKey(storageKey) : null));
|
|
100
|
+
if (!enabled) return null;
|
|
101
|
+
|
|
102
|
+
const original = (originalRole ?? kept ?? undefined) as R | undefined;
|
|
103
|
+
|
|
104
|
+
const pickRole = (next: R) => {
|
|
105
|
+
if (originalRole === undefined) {
|
|
106
|
+
if (next === original) {
|
|
107
|
+
// Back where the session began: nothing left to go back to.
|
|
108
|
+
writeKey(storageKey, null);
|
|
109
|
+
setKept(null);
|
|
110
|
+
} else if (kept === null && role !== undefined && next !== role) {
|
|
111
|
+
writeKey(storageKey, role);
|
|
112
|
+
setKept(role);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
onRole?.(next);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const roleMenu =
|
|
119
|
+
roles && roles.length > 0 && role !== undefined && onRole ? (
|
|
120
|
+
<TopBarActionMenu
|
|
121
|
+
icon={flask}
|
|
122
|
+
aria-label={`${bar.switchRole} · ${bar.role(role)}`}
|
|
123
|
+
entries={[
|
|
124
|
+
{ kind: "heading", key: "head-role", label: words.roleHeading },
|
|
125
|
+
...roles.map(
|
|
126
|
+
(r): TopBarMenuEntry => ({ key: `role-${r}`, label: roleLabel(r), checked: r === role, onSelect: () => pickRole(r) }),
|
|
127
|
+
),
|
|
128
|
+
...(original !== undefined && original !== role
|
|
129
|
+
? ([
|
|
130
|
+
{ kind: "divider", key: "sep-back" },
|
|
131
|
+
{
|
|
132
|
+
key: "back",
|
|
133
|
+
icon: <Undo2 className="size-4" />,
|
|
134
|
+
label: words.backTo(textOf(roleLabel(original), original)),
|
|
135
|
+
onSelect: () => pickRole(original),
|
|
136
|
+
},
|
|
137
|
+
] satisfies TopBarMenuEntry[])
|
|
138
|
+
: []),
|
|
139
|
+
]}
|
|
140
|
+
/>
|
|
141
|
+
) : null;
|
|
142
|
+
|
|
143
|
+
const planMenu =
|
|
144
|
+
plans && plans.length > 0 && onPlan ? (
|
|
145
|
+
<TopBarActionMenu
|
|
146
|
+
icon={flask}
|
|
147
|
+
aria-label={plan !== undefined ? `${words.switchPlan} · ${words.plan(plan)}` : words.switchPlan}
|
|
148
|
+
entries={[
|
|
149
|
+
{ kind: "heading", key: "head-plan", label: words.planHeading },
|
|
150
|
+
...plans.map(
|
|
151
|
+
(p): TopBarMenuEntry => ({ key: `plan-${p}`, label: planLabel(p), checked: p === plan, onSelect: () => onPlan(p) }),
|
|
152
|
+
),
|
|
153
|
+
]}
|
|
154
|
+
>
|
|
155
|
+
{billingOff
|
|
156
|
+
? () => (
|
|
157
|
+
<li data-dev-billing-off="" className="mt-1 max-w-64 border-t border-subtle px-3 py-2 text-xs text-muted">
|
|
158
|
+
{words.billingOff}
|
|
159
|
+
</li>
|
|
160
|
+
)
|
|
161
|
+
: undefined}
|
|
162
|
+
</TopBarActionMenu>
|
|
163
|
+
) : null;
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<>
|
|
167
|
+
{roleMenu}
|
|
168
|
+
{planMenu}
|
|
169
|
+
</>
|
|
170
|
+
);
|
|
171
|
+
}
|