@eifi1/ui-kit 0.30.0 → 0.31.1

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.
Files changed (269) hide show
  1. package/README.md +42 -5
  2. package/dist/account/data-export-setting.js +3 -2
  3. package/dist/account/data-export-setting.js.map +1 -1
  4. package/dist/account/delete-account-setting.d.ts +5 -1
  5. package/dist/account/delete-account-setting.js +3 -2
  6. package/dist/account/delete-account-setting.js.map +1 -1
  7. package/dist/account/email-change-setting.js +4 -3
  8. package/dist/account/email-change-setting.js.map +1 -1
  9. package/dist/account/sessions-setting.js +3 -2
  10. package/dist/account/sessions-setting.js.map +1 -1
  11. package/dist/admin/admin-action-confirm.d.ts +5 -1
  12. package/dist/admin/admin-parts.d.ts +8 -1
  13. package/dist/admin/admin-parts.js +1 -1
  14. package/dist/admin/admin-parts.js.map +1 -1
  15. package/dist/admin/invitations-panel.d.ts +5 -1
  16. package/dist/admin/invitations-panel.js +3 -2
  17. package/dist/admin/invitations-panel.js.map +1 -1
  18. package/dist/admin/reviewer-scope-editor.d.ts +5 -1
  19. package/dist/admin/role-select.d.ts +5 -1
  20. package/dist/admin/transfer-ownership-dialog.d.ts +5 -1
  21. package/dist/admin/user-roster.d.ts +5 -1
  22. package/dist/auth/auth-errors.d.ts +24 -6
  23. package/dist/auth/auth-errors.js +7 -1
  24. package/dist/auth/auth-errors.js.map +1 -1
  25. package/dist/auth/register-form.d.ts +5 -1
  26. package/dist/auth/reset-password-form.d.ts +1 -1
  27. package/dist/auth/reset-password-form.js +2 -1
  28. package/dist/auth/reset-password-form.js.map +1 -1
  29. package/dist/auth/sign-in-form.d.ts +15 -1
  30. package/dist/auth/sign-in-form.js +12 -3
  31. package/dist/auth/sign-in-form.js.map +1 -1
  32. package/dist/auth/verify-email.d.ts +4 -0
  33. package/dist/auth/verify-email.js +3 -2
  34. package/dist/auth/verify-email.js.map +1 -1
  35. package/dist/chart.d.ts +5 -1
  36. package/dist/components/account-settings-labels.d.ts +12 -0
  37. package/dist/components/account-settings-labels.js +2 -1
  38. package/dist/components/account-settings-labels.js.map +1 -1
  39. package/dist/components/account-settings.d.ts +8 -2
  40. package/dist/components/account-settings.js +19 -11
  41. package/dist/components/account-settings.js.map +1 -1
  42. package/dist/components/amount-input.d.ts +5 -1
  43. package/dist/components/button-group.d.ts +5 -1
  44. package/dist/components/calculator.d.ts +5 -1
  45. package/dist/components/confirm-dialog.d.ts +5 -1
  46. package/dist/components/confirm-dialog.js +7 -1
  47. package/dist/components/confirm-dialog.js.map +1 -1
  48. package/dist/components/copy-button.d.ts +5 -1
  49. package/dist/components/danger-confirm.d.ts +5 -1
  50. package/dist/components/data-table.js +8 -1
  51. package/dist/components/data-table.js.map +1 -1
  52. package/dist/components/date-picker.js +9 -4
  53. package/dist/components/date-picker.js.map +1 -1
  54. package/dist/components/facing-pair.d.ts +5 -1
  55. package/dist/components/file-button.d.ts +5 -1
  56. package/dist/components/file-dropzone.d.ts +5 -1
  57. package/dist/components/form-actions.d.ts +5 -1
  58. package/dist/components/iban-input.d.ts +5 -1
  59. package/dist/components/language-select.d.ts +5 -1
  60. package/dist/components/legal-page.d.ts +5 -1
  61. package/dist/components/legal.d.ts +5 -1
  62. package/dist/components/money-field.d.ts +5 -1
  63. package/dist/components/number-field.d.ts +5 -1
  64. package/dist/components/number-input.d.ts +5 -1
  65. package/dist/components/numpad-sheet.d.ts +5 -1
  66. package/dist/components/passkeys-setting.js +2 -1
  67. package/dist/components/passkeys-setting.js.map +1 -1
  68. package/dist/components/phone-input.d.ts +5 -1
  69. package/dist/components/series-chart.d.ts +5 -1
  70. package/dist/components/settings-fields.d.ts +40 -3
  71. package/dist/components/settings-fields.js +20 -1
  72. package/dist/components/settings-fields.js.map +1 -1
  73. package/dist/components/share-card.d.ts +5 -1
  74. package/dist/components/text-link.d.ts +5 -1
  75. package/dist/components/time-input.d.ts +5 -1
  76. package/dist/components/ui.d.ts +5 -1
  77. package/dist/{delete-account-setting-CGVMckMw.d.ts → delete-account-setting-CpIhzxxZ.d.ts} +60 -23
  78. package/dist/demo/demo-banner.d.ts +51 -0
  79. package/dist/demo/demo-banner.js +97 -0
  80. package/dist/demo/demo-banner.js.map +1 -0
  81. package/dist/demo/demo-countdown.d.ts +58 -0
  82. package/dist/demo/demo-countdown.js +79 -0
  83. package/dist/demo/demo-countdown.js.map +1 -0
  84. package/dist/demo/demo-ended.d.ts +45 -0
  85. package/dist/demo/demo-ended.js +42 -0
  86. package/dist/demo/demo-ended.js.map +1 -0
  87. package/dist/demo/demo-labels.d.ts +53 -0
  88. package/dist/demo/demo-labels.js +29 -0
  89. package/dist/demo/demo-labels.js.map +1 -0
  90. package/dist/demo/demo-session.d.ts +30 -0
  91. package/dist/demo/demo-session.js +8 -0
  92. package/dist/demo/demo-session.js.map +1 -0
  93. package/dist/demo/demo-start.d.ts +54 -0
  94. package/dist/demo/demo-start.js +68 -0
  95. package/dist/demo/demo-start.js.map +1 -0
  96. package/dist/feedback/feedback-attachment.d.ts +5 -1
  97. package/dist/feedback/feedback-context.d.ts +5 -1
  98. package/dist/feedback/feedback-crash.d.ts +5 -1
  99. package/dist/feedback/feedback-dialog.d.ts +5 -1
  100. package/dist/feedback/feedback-inbox.d.ts +5 -1
  101. package/dist/feedback/feedback-inbox.js +12 -2
  102. package/dist/feedback/feedback-inbox.js.map +1 -1
  103. package/dist/feedback/feedback-labels.d.ts +5 -1
  104. package/dist/feedback/feedback-labels.js +1 -0
  105. package/dist/feedback/feedback-labels.js.map +1 -1
  106. package/dist/feedback/feedback-menu.d.ts +5 -1
  107. package/dist/feedback/feedback-record.d.ts +5 -1
  108. package/dist/feedback/feedback-record.js +2 -0
  109. package/dist/feedback/feedback-record.js.map +1 -1
  110. package/dist/feedback/feedback-row-detail.d.ts +5 -1
  111. package/dist/feedback/feedback-row-detail.js +7 -0
  112. package/dist/feedback/feedback-row-detail.js.map +1 -1
  113. package/dist/feedback/feedback-status-undo.d.ts +5 -1
  114. package/dist/feedback/feedback-submit.d.ts +5 -1
  115. package/dist/feedback/feedback-swipe.d.ts +6 -2
  116. package/dist/feedback/feedback-swipe.js.map +1 -1
  117. package/dist/feedback/feedback-table.d.ts +5 -1
  118. package/dist/feedback/feedback-thread.d.ts +5 -1
  119. package/dist/feedback.d.ts +5 -1
  120. package/dist/hooks/use-file-drop.d.ts +5 -1
  121. package/dist/i18n/defaults.d.ts +5 -1
  122. package/dist/i18n/defaults.js +6 -0
  123. package/dist/i18n/defaults.js.map +1 -1
  124. package/dist/i18n/german.d.ts +5 -1
  125. package/dist/i18n/german.js +85 -2
  126. package/dist/i18n/german.js.map +1 -1
  127. package/dist/i18n/kit-labels.d.ts +5 -1
  128. package/dist/i18n/kit-labels.js.map +1 -1
  129. package/dist/i18n/languages.d.ts +5 -1
  130. package/dist/i18n/locales/de-CH.d.ts +5 -1
  131. package/dist/i18n/locales/en.d.ts +5 -1
  132. package/dist/i18n/locales/es.d.ts +5 -1
  133. package/dist/i18n/locales/es.js +82 -2
  134. package/dist/i18n/locales/es.js.map +1 -1
  135. package/dist/i18n/locales/fr.d.ts +5 -1
  136. package/dist/i18n/locales/fr.js +83 -2
  137. package/dist/i18n/locales/fr.js.map +1 -1
  138. package/dist/i18n/locales/hu.d.ts +5 -1
  139. package/dist/i18n/locales/hu.js +83 -2
  140. package/dist/i18n/locales/hu.js.map +1 -1
  141. package/dist/i18n/locales/it.d.ts +5 -1
  142. package/dist/i18n/locales/it.js +82 -2
  143. package/dist/i18n/locales/it.js.map +1 -1
  144. package/dist/i18n/locales/zh.d.ts +5 -1
  145. package/dist/i18n/locales/zh.js +81 -2
  146. package/dist/i18n/locales/zh.js.map +1 -1
  147. package/dist/i18n/review.d.ts +5 -1
  148. package/dist/i18n/review.js +15 -1
  149. package/dist/i18n/review.js.map +1 -1
  150. package/dist/index.d.ts +25 -3
  151. package/dist/index.js +96 -0
  152. package/dist/index.js.map +1 -1
  153. package/dist/landing/access.d.ts +48 -0
  154. package/dist/landing/access.js +38 -0
  155. package/dist/landing/access.js.map +1 -0
  156. package/dist/landing/landing-actions.d.ts +140 -0
  157. package/dist/landing/landing-actions.js +39 -0
  158. package/dist/landing/landing-actions.js.map +1 -0
  159. package/dist/landing/landing-labels.d.ts +43 -0
  160. package/dist/landing/landing-labels.js +23 -0
  161. package/dist/landing/landing-labels.js.map +1 -0
  162. package/dist/landing/landing-sections.d.ts +218 -0
  163. package/dist/landing/landing-sections.js +167 -0
  164. package/dist/landing/landing-sections.js.map +1 -0
  165. package/dist/landing/page-seo.d.ts +99 -0
  166. package/dist/landing/page-seo.js +121 -0
  167. package/dist/landing/page-seo.js.map +1 -0
  168. package/dist/landing/public-header.d.ts +148 -0
  169. package/dist/landing/public-header.js +49 -0
  170. package/dist/landing/public-header.js.map +1 -0
  171. package/dist/landing/routing.d.ts +231 -0
  172. package/dist/landing/routing.js +84 -0
  173. package/dist/landing/routing.js.map +1 -0
  174. package/dist/rhf/fields.d.ts +5 -1
  175. package/dist/rhf/form.d.ts +5 -1
  176. package/dist/rhf.d.ts +5 -1
  177. package/dist/settings/settings-catalogue.d.ts +84 -0
  178. package/dist/settings/settings-catalogue.js +47 -0
  179. package/dist/settings/settings-catalogue.js.map +1 -0
  180. package/dist/settings/settings-context.d.ts +31 -0
  181. package/dist/settings/settings-context.js +11 -0
  182. package/dist/settings/settings-context.js.map +1 -0
  183. package/dist/settings/settings-heading.d.ts +50 -0
  184. package/dist/settings/settings-heading.js +27 -0
  185. package/dist/settings/settings-heading.js.map +1 -0
  186. package/dist/settings/settings-labels.d.ts +48 -0
  187. package/dist/settings/settings-labels.js +43 -0
  188. package/dist/settings/settings-labels.js.map +1 -0
  189. package/dist/settings/settings-layout.d.ts +77 -0
  190. package/dist/settings/settings-layout.js +242 -0
  191. package/dist/settings/settings-layout.js.map +1 -0
  192. package/dist/settings/settings-section.d.ts +133 -0
  193. package/dist/settings/settings-section.js +63 -0
  194. package/dist/settings/settings-section.js.map +1 -0
  195. package/dist/settings/use-account-language.d.ts +83 -0
  196. package/dist/settings/use-account-language.js +62 -0
  197. package/dist/settings/use-account-language.js.map +1 -0
  198. package/dist/settings/use-settings-focus.d.ts +34 -0
  199. package/dist/settings/use-settings-focus.js +77 -0
  200. package/dist/settings/use-settings-focus.js.map +1 -0
  201. package/dist/settings/use-settings-route.d.ts +118 -0
  202. package/dist/settings/use-settings-route.js +120 -0
  203. package/dist/settings/use-settings-route.js.map +1 -0
  204. package/dist/shell/app-shell.d.ts +11 -1
  205. package/dist/shell/app-shell.js +3 -2
  206. package/dist/shell/app-shell.js.map +1 -1
  207. package/dist/shell/top-bar-brand.d.ts +5 -1
  208. package/dist/shell.d.ts +15 -1
  209. package/dist/shell.js +56 -0
  210. package/dist/shell.js.map +1 -1
  211. package/dist/wizard/stepper-nav.d.ts +5 -1
  212. package/dist/wizard.d.ts +5 -1
  213. package/package.json +2 -1
  214. package/src/account/data-export-setting.tsx +3 -2
  215. package/src/account/delete-account-setting.tsx +3 -2
  216. package/src/account/email-change-setting.tsx +4 -7
  217. package/src/account/sessions-setting.tsx +3 -2
  218. package/src/admin/admin-parts.ts +9 -2
  219. package/src/admin/invitations-panel.tsx +11 -4
  220. package/src/auth/auth-errors.ts +36 -5
  221. package/src/auth/reset-password-form.tsx +6 -2
  222. package/src/auth/sign-in-form.tsx +34 -3
  223. package/src/auth/verify-email.tsx +14 -2
  224. package/src/components/account-settings-labels.ts +13 -0
  225. package/src/components/account-settings.tsx +33 -12
  226. package/src/components/confirm-dialog.tsx +20 -1
  227. package/src/components/data-table.tsx +8 -0
  228. package/src/components/date-picker.tsx +9 -4
  229. package/src/components/passkeys-setting.tsx +2 -1
  230. package/src/components/settings-fields.tsx +50 -1
  231. package/src/demo/demo-banner.tsx +159 -0
  232. package/src/demo/demo-countdown.ts +141 -0
  233. package/src/demo/demo-ended.tsx +89 -0
  234. package/src/demo/demo-labels.ts +78 -0
  235. package/src/demo/demo-session.ts +32 -0
  236. package/src/demo/demo-start.tsx +150 -0
  237. package/src/feedback/feedback-inbox.tsx +21 -8
  238. package/src/feedback/feedback-labels.ts +2 -1
  239. package/src/feedback/feedback-record.ts +10 -7
  240. package/src/feedback/feedback-row-detail.tsx +28 -4
  241. package/src/feedback/feedback-swipe.tsx +1 -1
  242. package/src/i18n/defaults.ts +6 -0
  243. package/src/i18n/german.ts +87 -0
  244. package/src/i18n/kit-labels.tsx +9 -0
  245. package/src/i18n/locales/es.ts +84 -0
  246. package/src/i18n/locales/fr.ts +85 -0
  247. package/src/i18n/locales/hu.ts +85 -0
  248. package/src/i18n/locales/it.ts +84 -0
  249. package/src/i18n/locales/zh.ts +82 -0
  250. package/src/i18n/review.ts +14 -0
  251. package/src/index.ts +98 -1
  252. package/src/landing/access.ts +97 -0
  253. package/src/landing/landing-actions.tsx +96 -0
  254. package/src/landing/landing-labels.ts +59 -0
  255. package/src/landing/landing-sections.tsx +337 -0
  256. package/src/landing/page-seo.ts +251 -0
  257. package/src/landing/public-header.tsx +120 -0
  258. package/src/landing/routing.tsx +226 -0
  259. package/src/settings/settings-catalogue.ts +132 -0
  260. package/src/settings/settings-context.ts +33 -0
  261. package/src/settings/settings-heading.tsx +65 -0
  262. package/src/settings/settings-labels.ts +87 -0
  263. package/src/settings/settings-layout.tsx +379 -0
  264. package/src/settings/settings-section.tsx +108 -0
  265. package/src/settings/use-account-language.ts +146 -0
  266. package/src/settings/use-settings-focus.ts +120 -0
  267. package/src/settings/use-settings-route.ts +258 -0
  268. package/src/shell/app-shell.tsx +10 -2
  269. package/src/shell.ts +51 -0
@@ -1,6 +1,8 @@
1
1
  import type { ReactNode } from "react";
2
2
  import { Select } from "./ui";
3
3
  import type { SelectProps } from "./ui";
4
+ import { ToggleGroup } from "./toggle-group";
5
+ import type { ToggleGroupBaseProps } from "./toggle-group";
4
6
  import type { ThemePreference } from "../theme/theme-store";
5
7
 
6
8
  /**
@@ -20,6 +22,8 @@ import type { ThemePreference } from "../theme/theme-store";
20
22
  */
21
23
  export interface ThemeSettingProps
22
24
  extends Omit<SelectProps, "value" | "onChange" | "children"> {
25
+ /** The `Select` (default). See {@link ThemeSettingToggleProps} for `"toggle"`. */
26
+ variant?: "select";
23
27
  value: ThemePreference;
24
28
  onChange: (value: ThemePreference) => void;
25
29
  label: ReactNode;
@@ -28,7 +32,52 @@ export interface ThemeSettingProps
28
32
  id?: string;
29
33
  }
30
34
 
31
- export function ThemeSetting({ value, onChange, label, optionLabels, id, ...rest }: ThemeSettingProps) {
35
+ /**
36
+ * `variant="toggle"` (0.31.0, docs/settings-harmonization.md §2.8): the three choices as
37
+ * one segmented control instead of a select — system, light and dark side by side, the
38
+ * choice visible without opening anything, in every app (keksdose offered light and dark
39
+ * only; its store already knew "system"). A {@link ToggleGroup}'s props pass through —
40
+ * `labelPlacement`, `disabledReason`, `commit`, `size` — minus the options and the value,
41
+ * which this owns.
42
+ *
43
+ * Bind it to the PREFERENCE (`"system"` included), never to the resolved mode: on a
44
+ * system-dark device a control bound to the mode shows "dark" and cannot say "follow the
45
+ * system" (keksdose's control, §8).
46
+ */
47
+ export interface ThemeSettingToggleProps
48
+ extends Omit<ToggleGroupBaseProps<ThemePreference>, "options" | "label" | "ariaLabel"> {
49
+ variant: "toggle";
50
+ value: ThemePreference;
51
+ onChange: (value: ThemePreference) => void;
52
+ /**
53
+ * Names the group: the field's label, or the label above it (`labelPlacement`). Leave
54
+ * it out inside a card already titled "Theme" and name the group with `aria-label` or
55
+ * `aria-labelledby` instead, so the card does not say "Theme" twice.
56
+ */
57
+ label?: ReactNode;
58
+ /** Translated option labels. */
59
+ optionLabels: { system: string; light: string; dark: string };
60
+ id?: string;
61
+ }
62
+
63
+ export function ThemeSetting(props: ThemeSettingProps | ThemeSettingToggleProps) {
64
+ if (props.variant === "toggle") {
65
+ const { variant: _variant, value, onChange, label, optionLabels, ...rest } = props;
66
+ return (
67
+ <ToggleGroup<ThemePreference>
68
+ {...rest}
69
+ label={label}
70
+ value={value}
71
+ onChange={onChange}
72
+ options={[
73
+ { value: "system", label: optionLabels.system },
74
+ { value: "light", label: optionLabels.light },
75
+ { value: "dark", label: optionLabels.dark },
76
+ ]}
77
+ />
78
+ );
79
+ }
80
+ const { variant: _variant, value, onChange, label, optionLabels, id, ...rest } = props;
32
81
  return (
33
82
  <Select
34
83
  {...rest}
@@ -0,0 +1,159 @@
1
+ import { useState } from "react";
2
+ import type { ComponentPropsWithoutRef } from "react";
3
+ import { ChevronDown, ChevronUp, Timer } from "lucide-react";
4
+
5
+ import { cn } from "../lib/cn";
6
+ import { AlertBanner } from "../components/alert-banner";
7
+ import { Button, IconButton } from "../components/ui";
8
+ import { useAccessAction } from "../landing/access";
9
+ import type { AccessChoice } from "../landing/access";
10
+ import { useLandingLabels } from "../landing/landing-labels";
11
+ import type { LandingLabels } from "../landing/landing-labels";
12
+ import { useDemoCountdown } from "./demo-countdown";
13
+ import type { DemoCountdown, DemoExpiry } from "./demo-countdown";
14
+ import { useDemoLabels } from "./demo-labels";
15
+ import type { DemoLabels } from "./demo-labels";
16
+ import type { DemoModel } from "./demo-session";
17
+
18
+ /** The default `sessionStorage` key of the collapsed state. */
19
+ const COLLAPSE_KEY = "kit.demoBanner.collapsed";
20
+
21
+ /** `sessionStorage`, guarded like `lib/safe-storage`'s `localStorage`: blocked storage
22
+ * reads as "not set" and writes nothing. */
23
+ function readSession(key: string): string | null {
24
+ if (typeof window === "undefined") return null;
25
+ try {
26
+ return window.sessionStorage.getItem(key);
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ function writeSession(key: string, value: string | null): void {
33
+ if (typeof window === "undefined") return;
34
+ try {
35
+ if (value === null) window.sessionStorage.removeItem(key);
36
+ else window.sessionStorage.setItem(key, value);
37
+ } catch {
38
+ // storage blocked: the banner just opens again next time
39
+ }
40
+ }
41
+
42
+ /** "Demo · 23 h 12 min left", "Demo · 50 min left", the end, or plain "Demo". */
43
+ function timeText(countdown: DemoCountdown, labels: DemoLabels): string {
44
+ if (countdown.minutesLeft === null) return labels.badge;
45
+ if (countdown.ended) return labels.endedTitle;
46
+ return countdown.lastHour
47
+ ? labels.minutesLeft(countdown.minutes)
48
+ : labels.hoursLeft(countdown.hours, countdown.minutes);
49
+ }
50
+
51
+ export interface DemoBannerProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "onClick"> {
52
+ /** The demo's end: `expires_at` from the `TokenResponse`, or `demo_expires_at` from
53
+ * `/auth/me` (§5.3). */
54
+ expiresAt: DemoExpiry | null | undefined;
55
+ /** Which line the banner says about the data (§2.3). */
56
+ model: DemoModel;
57
+ /** "Request access". */
58
+ access: AccessChoice;
59
+ /** "Sign in" — let through for a demo session by `RedirectIfAuthed allowDemo`. Default
60
+ * `/login`. */
61
+ signInHref?: string;
62
+ /** The countdown reached zero: clear the session and replace to `/demo/ended` (§5.5). */
63
+ onEnded?: () => void;
64
+ /** Where the collapsed state is kept for the tab's session. Default
65
+ * `kit.demoBanner.collapsed`. */
66
+ collapseKey?: string;
67
+ /** The clock, for tests and previews. Default `Date.now`. Keep it stable. */
68
+ now?: () => number;
69
+ labels?: Partial<DemoLabels>;
70
+ /** The access words (`landing` namespace) for this instance. */
71
+ landingLabels?: Partial<LandingLabels>;
72
+ }
73
+
74
+ /**
75
+ * The demo's strip under the top bar, on every page of a demo session
76
+ * (docs/landing-demo-harmonization.md §5.4) — a kit `AlertBanner` strip:
77
+ *
78
+ * - the time left, "Demo · 23 h 12 min left" — minutes only in the last hour, and the
79
+ * warning tone in the last ten minutes (`useDemoCountdown`);
80
+ * - one line on the model: R "You're looking at sample data. Changes aren't possible.",
81
+ * S "Your own work is deleted when the demo ends.";
82
+ * - "Request access" (the mail) and "Sign in".
83
+ *
84
+ * It collapses to the countdown alone, for the tab's session (`sessionStorage`) — never
85
+ * hidden for good: it is a live state, like keksdose's preview banner, which a demo user
86
+ * gets instead of. At zero it calls `onEnded`.
87
+ *
88
+ * The countdown is no live region: a sentence read out every minute would drown the
89
+ * page. A screen-reader user meets it at the top of the page, and the end page says
90
+ * the rest.
91
+ */
92
+ export function DemoBanner({
93
+ expiresAt,
94
+ model,
95
+ access,
96
+ signInHref = "/login",
97
+ onEnded,
98
+ collapseKey = COLLAPSE_KEY,
99
+ now,
100
+ labels: labelsProp,
101
+ landingLabels,
102
+ className,
103
+ ...rest
104
+ }: DemoBannerProps) {
105
+ const labels = useDemoLabels(labelsProp);
106
+ const landing = useLandingLabels(landingLabels);
107
+ const accessLink = useAccessAction(access, landingLabels);
108
+ const countdown = useDemoCountdown(expiresAt, { now, onEnded });
109
+ const [collapsed, setCollapsed] = useState(() => readSession(collapseKey) === "1");
110
+
111
+ const toggle = () => {
112
+ const next = !collapsed;
113
+ setCollapsed(next);
114
+ writeSession(collapseKey, next ? "1" : null);
115
+ };
116
+
117
+ return (
118
+ <AlertBanner
119
+ {...rest}
120
+ variant="strip"
121
+ size="sm"
122
+ tone={countdown.warning || countdown.ended ? "warning" : "info"}
123
+ icon={<Timer />}
124
+ data-demo-model={model}
125
+ className={cn("sm:text-sm", className)}
126
+ action={
127
+ <>
128
+ {!collapsed && (
129
+ <>
130
+ <Button href={accessLink.href} variant="brand" size="sm">
131
+ {accessLink.label}
132
+ </Button>
133
+ <Button href={signInHref} variant="secondary" size="sm">
134
+ {landing.signIn}
135
+ </Button>
136
+ </>
137
+ )}
138
+ <IconButton
139
+ size="2xs"
140
+ variant="ghost"
141
+ label={labels.details}
142
+ aria-expanded={!collapsed}
143
+ onClick={toggle}
144
+ >
145
+ {collapsed ? <ChevronDown /> : <ChevronUp />}
146
+ </IconButton>
147
+ </>
148
+ }
149
+ >
150
+ <span className="font-semibold">{timeText(countdown, labels)}</span>
151
+ {!collapsed && (
152
+ <>
153
+ {" "}
154
+ <span>{model === "read-only" ? labels.readOnly : labels.sandbox}</span>
155
+ </>
156
+ )}
157
+ </AlertBanner>
158
+ );
159
+ }
@@ -0,0 +1,141 @@
1
+ import { useCallback, useEffect, useEffectEvent, useSyncExternalStore } from "react";
2
+
3
+ /**
4
+ * The demo's countdown (docs/landing-demo-harmonization.md §5.3, §5.4): the time left to
5
+ * the demo account's end, from `expires_at` (the `TokenResponse`) or `demo_expires_at`
6
+ * (`/auth/me`). The client never decodes the JWT.
7
+ */
8
+
9
+ /** When the demo ends: an ISO timestamp from the server, epoch milliseconds, or a
10
+ * `Date`. */
11
+ export type DemoExpiry = string | number | Date;
12
+
13
+ /** The last stretch, in minutes, in which the banner turns to the warning tone (§5.4). */
14
+ export const DEMO_WARNING_MINUTES = 10;
15
+ /** Below this many minutes the countdown shows minutes only (§5.4). */
16
+ export const DEMO_MINUTES_ONLY = 60;
17
+
18
+ const MINUTE = 60_000;
19
+
20
+ export interface DemoCountdown {
21
+ /**
22
+ * Whole minutes left, ROUNDED UP — 30 s left is "1 min", and 0 only once the demo has
23
+ * ended. `null` when `expiresAt` cannot be read: the countdown then shows no time and
24
+ * never ends by itself (a parse slip must not throw a visitor out).
25
+ */
26
+ minutesLeft: number | null;
27
+ /** The display split: whole hours, and the minutes past them. In the last hour
28
+ * (`lastHour`) `hours` is 0 and `minutes` is `minutesLeft`. */
29
+ hours: number;
30
+ minutes: number;
31
+ /** `minutesLeft <= 60`: show minutes only. */
32
+ lastHour: boolean;
33
+ /** `minutesLeft <= 10`: the warning tone. */
34
+ warning: boolean;
35
+ /** The demo's time is up. */
36
+ ended: boolean;
37
+ }
38
+
39
+ /** `expiresAt` as epoch milliseconds, or NaN. */
40
+ function expiryMs(expiresAt: DemoExpiry | null | undefined): number {
41
+ if (expiresAt === null || expiresAt === undefined) return Number.NaN;
42
+ if (typeof expiresAt === "number") return expiresAt;
43
+ if (expiresAt instanceof Date) return expiresAt.getTime();
44
+ return Date.parse(expiresAt);
45
+ }
46
+
47
+ /** Whole minutes left at `now`, rounded up, never below 0; null for an unreadable end. */
48
+ function minutesAt(expiry: number, now: number): number | null {
49
+ if (!Number.isFinite(expiry)) return null;
50
+ return Math.max(0, Math.ceil((expiry - now) / MINUTE));
51
+ }
52
+
53
+ /**
54
+ * The countdown at `now` — pure, for a test or a server-rendered value. See
55
+ * {@link DemoCountdown} for the rounding and the thresholds.
56
+ */
57
+ export function demoCountdown(expiresAt: DemoExpiry | null | undefined, now: number): DemoCountdown {
58
+ return countdownOf(minutesAt(expiryMs(expiresAt), now));
59
+ }
60
+
61
+ function countdownOf(minutesLeft: number | null): DemoCountdown {
62
+ if (minutesLeft === null) {
63
+ return { minutesLeft, hours: 0, minutes: 0, lastHour: false, warning: false, ended: false };
64
+ }
65
+ const lastHour = minutesLeft <= DEMO_MINUTES_ONLY;
66
+ return {
67
+ minutesLeft,
68
+ hours: lastHour ? 0 : Math.floor(minutesLeft / 60),
69
+ minutes: lastHour ? minutesLeft : minutesLeft % 60,
70
+ lastHour,
71
+ warning: minutesLeft <= DEMO_WARNING_MINUTES,
72
+ ended: minutesLeft === 0,
73
+ };
74
+ }
75
+
76
+ export interface DemoCountdownOptions {
77
+ /**
78
+ * The clock, in epoch milliseconds. Default `Date.now`. A test passes its own (or uses
79
+ * fake timers, which move `Date.now` too). Keep it a stable function — a new one each
80
+ * render re-arms the timer each render.
81
+ */
82
+ now?: () => number;
83
+ /** Called once when the countdown reaches zero — also on mount, if it already has.
84
+ * The app clears the session and replaces to `/demo/ended` (§5.5). */
85
+ onEnded?: () => void;
86
+ }
87
+
88
+ /**
89
+ * The time left to `expiresAt`, re-rendering when the shown minute changes — one timer
90
+ * to the next minute boundary, not a tick a second — and once more when the tab comes
91
+ * back from the background (a hidden tab's timers are throttled).
92
+ *
93
+ * `onEnded` fires at zero (§5.5). The countdown is the client's, from `expires_at`; the
94
+ * server's answer to a request after the end (a 401) ends the demo as well — the app's
95
+ * 401 handler, not this hook.
96
+ */
97
+ export function useDemoCountdown(
98
+ expiresAt: DemoExpiry | null | undefined,
99
+ { now = Date.now, onEnded }: DemoCountdownOptions = {},
100
+ ): DemoCountdown {
101
+ const expiry = expiryMs(expiresAt);
102
+ const subscribe = useCallback(
103
+ (notify: () => void) => {
104
+ if (!Number.isFinite(expiry)) return () => {};
105
+ let timer: ReturnType<typeof setTimeout> | undefined;
106
+ const arm = () => {
107
+ const left = expiry - now();
108
+ if (left <= 0) return;
109
+ // The rounded-up minute changes when `left` crosses the next whole minute below.
110
+ const delay = left - (Math.ceil(left / MINUTE) - 1) * MINUTE;
111
+ timer = setTimeout(() => {
112
+ notify();
113
+ arm();
114
+ }, delay);
115
+ };
116
+ const onVisible = () => {
117
+ if (document.visibilityState !== "visible") return;
118
+ clearTimeout(timer);
119
+ notify();
120
+ arm();
121
+ };
122
+ arm();
123
+ document.addEventListener("visibilitychange", onVisible);
124
+ return () => {
125
+ clearTimeout(timer);
126
+ document.removeEventListener("visibilitychange", onVisible);
127
+ };
128
+ },
129
+ [expiry, now],
130
+ );
131
+ const snapshot = () => minutesAt(expiry, now());
132
+ const minutesLeft = useSyncExternalStore(subscribe, snapshot, snapshot);
133
+ const countdown = countdownOf(minutesLeft);
134
+
135
+ const fireEnded = useEffectEvent(() => onEnded?.());
136
+ useEffect(() => {
137
+ if (countdown.ended) fireEnded();
138
+ }, [countdown.ended]);
139
+
140
+ return countdown;
141
+ }
@@ -0,0 +1,89 @@
1
+ import type { ComponentPropsWithoutRef, ReactNode } from "react";
2
+ import { Hourglass } from "lucide-react";
3
+
4
+ import { cn } from "../lib/cn";
5
+ import { Button } from "../components/ui";
6
+ import { useNoIndex } from "../hooks/use-noindex";
7
+ import type { AuthHeadingLevel } from "../auth/status-parts";
8
+ import { useAccessAction } from "../landing/access";
9
+ import type { AccessChoice } from "../landing/access";
10
+ import { useLandingLabels } from "../landing/landing-labels";
11
+ import type { LandingLabels } from "../landing/landing-labels";
12
+ import { useDemoLabels } from "./demo-labels";
13
+ import type { DemoLabels } from "./demo-labels";
14
+ import type { DemoModel } from "./demo-session";
15
+
16
+ export interface DemoEndedProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "title"> {
17
+ /** Which line the page says about the data (§2.3). */
18
+ model: DemoModel;
19
+ /** "Request access". */
20
+ access: AccessChoice;
21
+ /** "Start a new demo". Default `/demo` — a new demo may start after one ends, within
22
+ * the per-IP window (§2.7). */
23
+ restartHref?: string;
24
+ /** "Sign in". Default `/login`. */
25
+ signInHref?: string;
26
+ /** App content under the line. */
27
+ children?: ReactNode;
28
+ /** `false` adds no `noindex` — for a preview. Default `true` (§4.3). */
29
+ noIndex?: boolean;
30
+ /** Default `h2`, under `AuthLayout`'s `h1`. */
31
+ headingAs?: AuthHeadingLevel;
32
+ labels?: Partial<DemoLabels>;
33
+ /** The access words (`landing` namespace) for this instance. */
34
+ landingLabels?: Partial<LandingLabels>;
35
+ }
36
+
37
+ /**
38
+ * The `/demo/ended` page's content (docs/landing-demo-harmonization.md §5.5): "The demo
39
+ * has ended", one line on what became of the data, and three ways on — "Start a new
40
+ * demo", "Request access", "Sign in".
41
+ *
42
+ * Where a demo lands at `expires_at`, or on ANY 401 while the session is a demo: the
43
+ * client clears the session and replaces to `/demo/ended`, never to `/login`. keksdose's
44
+ * expired demo met an unexplained sign-in form. The server deletes the user at the next
45
+ * reap; nothing is kept.
46
+ *
47
+ * Content, like `NotFoundPage`: put it in the app's `AuthLayout` (its logo, language
48
+ * menu and legal footer). It marks the page `noindex`; robots.txt must NOT disallow it,
49
+ * or a crawler could never read that (§10.8).
50
+ */
51
+ export function DemoEnded({
52
+ model,
53
+ access,
54
+ restartHref = "/demo",
55
+ signInHref = "/login",
56
+ children,
57
+ noIndex = true,
58
+ headingAs: Heading = "h2",
59
+ labels: labelsProp,
60
+ landingLabels,
61
+ className,
62
+ ...rest
63
+ }: DemoEndedProps) {
64
+ const labels = useDemoLabels(labelsProp);
65
+ const landing = useLandingLabels(landingLabels);
66
+ const accessLink = useAccessAction(access, landingLabels);
67
+ useNoIndex(noIndex);
68
+ return (
69
+ <div {...rest} className={cn("flex flex-col items-center gap-2 py-4 text-center", className)}>
70
+ <Hourglass aria-hidden className="size-10 text-[var(--text-placeholder)]" />
71
+ <Heading className="mt-2 text-xl font-semibold text-[var(--text-primary)]">{labels.endedTitle}</Heading>
72
+ <p className="max-w-prose text-sm text-[var(--text-secondary)]">
73
+ {model === "sandbox" ? labels.endedSandbox : labels.endedReadOnly}
74
+ </p>
75
+ {children}
76
+ <div className="mt-4 flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-center">
77
+ <Button href={restartHref} variant="brand">
78
+ {labels.restart}
79
+ </Button>
80
+ <Button href={accessLink.href} variant="secondary">
81
+ {accessLink.label}
82
+ </Button>
83
+ <Button href={signInHref} variant="secondary">
84
+ {landing.signIn}
85
+ </Button>
86
+ </div>
87
+ </div>
88
+ );
89
+ }
@@ -0,0 +1,78 @@
1
+ import { useKitLabels } from "../i18n/kit-labels";
2
+
3
+ /**
4
+ * The demo's words (docs/landing-demo-harmonization.md §5) — the `demo` namespace of
5
+ * `<UiKitProvider labels>`: `DemoStart`'s progress and refusals, `DemoBanner`'s
6
+ * countdown and model line, `DemoEnded`, and the reason of the read-only lock.
7
+ *
8
+ * "Demo" means the demo session and the shared demo data it shows (§2.10) — never
9
+ * keksdose's blur toggle, which is "Presentation mode" now. "Request access" and "Sign
10
+ * in" are the `landing` namespace's, so they read the same on every public page.
11
+ */
12
+ export interface DemoLabels {
13
+ /** `DemoStart` while the demo is being created. */
14
+ starting: string;
15
+ /** `demo_rate_limited`: too many demos from one network, given the wait in whole
16
+ * minutes from `Retry-After` — or `undefined` without one. */
17
+ rateLimited: (minutes?: number) => string;
18
+ /** `demo_capacity`: the live cap is reached. */
19
+ capacity: string;
20
+ /** `demo_disabled` and `demo_not_ready`: the demo is off, or its data isn't there. */
21
+ unavailable: string;
22
+ /** Any other failure — the network, a 500. */
23
+ failed: string;
24
+ /** `DemoStart`'s way out after a refusal, to the landing. */
25
+ backToStart: string;
26
+ /** The banner's countdown with an hour or more left: "Demo · 23 h 12 min left". */
27
+ hoursLeft: (hours: number, minutes: number) => string;
28
+ /** …and in the last hour, minutes only: "Demo · 50 min left". */
29
+ minutesLeft: (minutes: number) => string;
30
+ /** The banner's word when the end is unknown (no readable `expiresAt`). */
31
+ badge: string;
32
+ /** The banner's line for model R, shared read-only data. */
33
+ readOnly: string;
34
+ /** The banner's line for model S, a sandbox of one's own. */
35
+ sandbox: string;
36
+ /** The name of the banner's show/hide toggle (`aria-expanded` says which). */
37
+ details: string;
38
+ /** The reason a locked commit shows in a read-only demo (model R) — for the app's
39
+ * `<WriteLockProvider locked reason={…}>` (§5.4). */
40
+ writeLocked: string;
41
+ /** `DemoEnded`'s heading; also the banner's text at zero. */
42
+ endedTitle: string;
43
+ /** `DemoEnded`'s line for model R. */
44
+ endedReadOnly: string;
45
+ /** `DemoEnded`'s line for model S. */
46
+ endedSandbox: string;
47
+ /** `DemoEnded`'s first action, to `/demo`. */
48
+ restart: string;
49
+ }
50
+
51
+ export const DEFAULT_DEMO_LABELS: DemoLabels = {
52
+ starting: "Starting the demo…",
53
+ rateLimited: (minutes) =>
54
+ minutes
55
+ ? `Too many demos from this network. Try again in ${minutes} min.`
56
+ : "Too many demos from this network. Try again later.",
57
+ capacity: "The demo is full right now. Try again later.",
58
+ unavailable: "The demo isn’t available right now.",
59
+ failed: "The demo could not be started. Please try again.",
60
+ backToStart: "Back to the start page",
61
+ hoursLeft: (hours, minutes) => `Demo · ${hours} h ${minutes} min left`,
62
+ minutesLeft: (minutes) => `Demo · ${minutes} min left`,
63
+ badge: "Demo",
64
+ readOnly: "You’re looking at sample data. Changes aren’t possible.",
65
+ sandbox: "Your own work is deleted when the demo ends.",
66
+ details: "Demo details",
67
+ writeLocked: "Not possible in the demo.",
68
+ endedTitle: "The demo has ended",
69
+ endedReadOnly: "Sample data is reset regularly.",
70
+ endedSandbox: "Sample data is reset regularly; your own work from the demo is deleted.",
71
+ restart: "Start a new demo",
72
+ };
73
+
74
+ /** The `demo` namespace, resolved: English, then the provider, then `labels`. The app
75
+ * reads `writeLocked` from here for its `WriteLockProvider`. */
76
+ export function useDemoLabels(labels?: Partial<DemoLabels>): DemoLabels {
77
+ return useKitLabels("demo", DEFAULT_DEMO_LABELS, labels);
78
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The two demo models (docs/landing-demo-harmonization.md §2.3):
3
+ *
4
+ * - `read-only` (R) — keksdose and kastlan: one pre-filled shared dataset a throwaway
5
+ * demo user may look at but not change;
6
+ * - `sandbox` (S) — Kurvenschmiede: the demo user reads system-owned worked examples and
7
+ * may create or copy work of its own, deleted with the demo account.
8
+ */
9
+ export type DemoModel = "read-only" | "sandbox";
10
+
11
+ /** The fields of an `/auth/me` answer {@link isDemoSession} reads — server-kit's
12
+ * `UserResponse.is_demo` (0.5: and `demo_expires_at`), or a client's camel-cased copy. */
13
+ export interface DemoSessionUser {
14
+ is_demo?: boolean | null;
15
+ isDemo?: boolean | null;
16
+ }
17
+
18
+ /**
19
+ * Whether the signed-in user is a demo (§5, §6.5): server-kit's `is_demo` on
20
+ * `/auth/me`, or a client's `isDemo`. `false` for no user at all.
21
+ *
22
+ * What the client branches on: the demo banner instead of keksdose's preview banner, the
23
+ * header's "Continue the demo", a 401 that ends at `/demo/ended` instead of `/login`, and
24
+ * the crash reporter, which files nothing for a demo:
25
+ *
26
+ * ```ts
27
+ * createCrashReporter({ …, suppress: () => isDemoSession(useAuth.getState().user) });
28
+ * ```
29
+ */
30
+ export function isDemoSession(me: DemoSessionUser | null | undefined): boolean {
31
+ return me?.is_demo === true || me?.isDemo === true;
32
+ }