@better-forge/ui 0.0.0-stage → 0.1.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 (234) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/api/client.d.ts +42 -0
  4. package/dist/api/client.d.ts.map +1 -0
  5. package/dist/api/client.js +130 -0
  6. package/dist/api/client.js.map +1 -0
  7. package/dist/components/ConfirmIdentityModal.d.ts +18 -0
  8. package/dist/components/ConfirmIdentityModal.d.ts.map +1 -0
  9. package/dist/components/ConfirmIdentityModal.js +30 -0
  10. package/dist/components/ConfirmIdentityModal.js.map +1 -0
  11. package/dist/components/ConfirmModal.d.ts +18 -0
  12. package/dist/components/ConfirmModal.d.ts.map +1 -0
  13. package/dist/components/ConfirmModal.js +11 -0
  14. package/dist/components/ConfirmModal.js.map +1 -0
  15. package/dist/components/CopyButton.d.ts +11 -0
  16. package/dist/components/CopyButton.d.ts.map +1 -0
  17. package/dist/components/CopyButton.js +44 -0
  18. package/dist/components/CopyButton.js.map +1 -0
  19. package/dist/components/CredentialSection.d.ts +38 -0
  20. package/dist/components/CredentialSection.d.ts.map +1 -0
  21. package/dist/components/CredentialSection.js +69 -0
  22. package/dist/components/CredentialSection.js.map +1 -0
  23. package/dist/components/ErrorBoundary.d.ts +18 -0
  24. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  25. package/dist/components/ErrorBoundary.js +25 -0
  26. package/dist/components/ErrorBoundary.js.map +1 -0
  27. package/dist/components/ModalShell.d.ts +58 -0
  28. package/dist/components/ModalShell.d.ts.map +1 -0
  29. package/dist/components/ModalShell.js +92 -0
  30. package/dist/components/ModalShell.js.map +1 -0
  31. package/dist/components/ResetTwoFactorModal.d.ts +14 -0
  32. package/dist/components/ResetTwoFactorModal.d.ts.map +1 -0
  33. package/dist/components/ResetTwoFactorModal.js +16 -0
  34. package/dist/components/ResetTwoFactorModal.js.map +1 -0
  35. package/dist/components/SidePanel.d.ts +35 -0
  36. package/dist/components/SidePanel.d.ts.map +1 -0
  37. package/dist/components/SidePanel.js +19 -0
  38. package/dist/components/SidePanel.js.map +1 -0
  39. package/dist/components/SingleSignOnModal.d.ts +4 -0
  40. package/dist/components/SingleSignOnModal.d.ts.map +1 -0
  41. package/dist/components/SingleSignOnModal.js +64 -0
  42. package/dist/components/SingleSignOnModal.js.map +1 -0
  43. package/dist/components/SsoConfirmation.d.ts +22 -0
  44. package/dist/components/SsoConfirmation.d.ts.map +1 -0
  45. package/dist/components/SsoConfirmation.js +87 -0
  46. package/dist/components/SsoConfirmation.js.map +1 -0
  47. package/dist/components/VaultTypePicker.d.ts +13 -0
  48. package/dist/components/VaultTypePicker.d.ts.map +1 -0
  49. package/dist/components/VaultTypePicker.js +62 -0
  50. package/dist/components/VaultTypePicker.js.map +1 -0
  51. package/dist/components/WhatsNew.d.ts +18 -0
  52. package/dist/components/WhatsNew.d.ts.map +1 -0
  53. package/dist/components/WhatsNew.js +50 -0
  54. package/dist/components/WhatsNew.js.map +1 -0
  55. package/dist/components/formParts.d.ts +40 -0
  56. package/dist/components/formParts.d.ts.map +1 -0
  57. package/dist/components/formParts.js +31 -0
  58. package/dist/components/formParts.js.map +1 -0
  59. package/dist/components/ui/Alert.d.ts +15 -0
  60. package/dist/components/ui/Alert.d.ts.map +1 -0
  61. package/dist/components/ui/Alert.js +14 -0
  62. package/dist/components/ui/Alert.js.map +1 -0
  63. package/dist/components/ui/DataTable.d.ts +52 -0
  64. package/dist/components/ui/DataTable.d.ts.map +1 -0
  65. package/dist/components/ui/DataTable.js +112 -0
  66. package/dist/components/ui/DataTable.js.map +1 -0
  67. package/dist/components/ui/Field.d.ts +27 -0
  68. package/dist/components/ui/Field.d.ts.map +1 -0
  69. package/dist/components/ui/Field.js +25 -0
  70. package/dist/components/ui/Field.js.map +1 -0
  71. package/dist/components/ui/PageHeader.d.ts +18 -0
  72. package/dist/components/ui/PageHeader.d.ts.map +1 -0
  73. package/dist/components/ui/PageHeader.js +10 -0
  74. package/dist/components/ui/PageHeader.js.map +1 -0
  75. package/dist/components/ui/Pagination.d.ts +21 -0
  76. package/dist/components/ui/Pagination.d.ts.map +1 -0
  77. package/dist/components/ui/Pagination.js +10 -0
  78. package/dist/components/ui/Pagination.js.map +1 -0
  79. package/dist/components/ui/QuickStartPanel.d.ts +21 -0
  80. package/dist/components/ui/QuickStartPanel.d.ts.map +1 -0
  81. package/dist/components/ui/QuickStartPanel.js +11 -0
  82. package/dist/components/ui/QuickStartPanel.js.map +1 -0
  83. package/dist/components/ui/StateViews.d.ts +50 -0
  84. package/dist/components/ui/StateViews.d.ts.map +1 -0
  85. package/dist/components/ui/StateViews.js +33 -0
  86. package/dist/components/ui/StateViews.js.map +1 -0
  87. package/dist/components/ui/Switch.d.ts +16 -0
  88. package/dist/components/ui/Switch.d.ts.map +1 -0
  89. package/dist/components/ui/Switch.js +15 -0
  90. package/dist/components/ui/Switch.js.map +1 -0
  91. package/dist/components/ui/Toast.d.ts +20 -0
  92. package/dist/components/ui/Toast.d.ts.map +1 -0
  93. package/dist/components/ui/Toast.js +46 -0
  94. package/dist/components/ui/Toast.js.map +1 -0
  95. package/dist/components/ui/index.d.ts +10 -0
  96. package/dist/components/ui/index.d.ts.map +1 -0
  97. package/dist/components/ui/index.js +10 -0
  98. package/dist/components/ui/index.js.map +1 -0
  99. package/dist/config.d.ts +46 -0
  100. package/dist/config.d.ts.map +1 -0
  101. package/dist/config.js +12 -0
  102. package/dist/config.js.map +1 -0
  103. package/dist/hooks/useDarkMode.d.ts +2 -0
  104. package/dist/hooks/useDarkMode.d.ts.map +1 -0
  105. package/dist/hooks/useDarkMode.js +37 -0
  106. package/dist/hooks/useDarkMode.js.map +1 -0
  107. package/dist/hooks/useDebouncedValue.d.ts +6 -0
  108. package/dist/hooks/useDebouncedValue.d.ts.map +1 -0
  109. package/dist/hooks/useDebouncedValue.js +19 -0
  110. package/dist/hooks/useDebouncedValue.js.map +1 -0
  111. package/dist/index.d.ts +36 -0
  112. package/dist/index.d.ts.map +1 -0
  113. package/dist/index.js +36 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/lib/changelog.d.ts +32 -0
  116. package/dist/lib/changelog.d.ts.map +1 -0
  117. package/dist/lib/changelog.js +71 -0
  118. package/dist/lib/changelog.js.map +1 -0
  119. package/dist/lib/dateFormat.d.ts +24 -0
  120. package/dist/lib/dateFormat.d.ts.map +1 -0
  121. package/dist/lib/dateFormat.js +67 -0
  122. package/dist/lib/dateFormat.js.map +1 -0
  123. package/dist/navigation.d.ts +5 -0
  124. package/dist/navigation.d.ts.map +1 -0
  125. package/dist/navigation.js +7 -0
  126. package/dist/navigation.js.map +1 -0
  127. package/dist/pages/ApiTokens.d.ts +9 -0
  128. package/dist/pages/ApiTokens.d.ts.map +1 -0
  129. package/dist/pages/ApiTokens.js +116 -0
  130. package/dist/pages/ApiTokens.js.map +1 -0
  131. package/dist/pages/AuditLog.d.ts +14 -0
  132. package/dist/pages/AuditLog.d.ts.map +1 -0
  133. package/dist/pages/AuditLog.js +104 -0
  134. package/dist/pages/AuditLog.js.map +1 -0
  135. package/dist/pages/Backups.d.ts +2 -0
  136. package/dist/pages/Backups.d.ts.map +1 -0
  137. package/dist/pages/Backups.js +118 -0
  138. package/dist/pages/Backups.js.map +1 -0
  139. package/dist/pages/ChangePassword.d.ts +2 -0
  140. package/dist/pages/ChangePassword.d.ts.map +1 -0
  141. package/dist/pages/ChangePassword.js +40 -0
  142. package/dist/pages/ChangePassword.js.map +1 -0
  143. package/dist/pages/Login.d.ts +12 -0
  144. package/dist/pages/Login.d.ts.map +1 -0
  145. package/dist/pages/Login.js +69 -0
  146. package/dist/pages/Login.js.map +1 -0
  147. package/dist/pages/Settings.d.ts +2 -0
  148. package/dist/pages/Settings.d.ts.map +1 -0
  149. package/dist/pages/Settings.js +149 -0
  150. package/dist/pages/Settings.js.map +1 -0
  151. package/dist/pages/Setup.d.ts +2 -0
  152. package/dist/pages/Setup.d.ts.map +1 -0
  153. package/dist/pages/Setup.js +113 -0
  154. package/dist/pages/Setup.js.map +1 -0
  155. package/dist/pages/SsoConfirm.d.ts +3 -0
  156. package/dist/pages/SsoConfirm.d.ts.map +1 -0
  157. package/dist/pages/SsoConfirm.js +20 -0
  158. package/dist/pages/SsoConfirm.js.map +1 -0
  159. package/dist/pages/SsoTestResult.d.ts +2 -0
  160. package/dist/pages/SsoTestResult.d.ts.map +1 -0
  161. package/dist/pages/SsoTestResult.js +49 -0
  162. package/dist/pages/SsoTestResult.js.map +1 -0
  163. package/dist/pages/Users.d.ts +22 -0
  164. package/dist/pages/Users.d.ts.map +1 -0
  165. package/dist/pages/Users.js +124 -0
  166. package/dist/pages/Users.js.map +1 -0
  167. package/dist/pages/Vault.d.ts +2 -0
  168. package/dist/pages/Vault.d.ts.map +1 -0
  169. package/dist/pages/Vault.js +372 -0
  170. package/dist/pages/Vault.js.map +1 -0
  171. package/dist/shell/AdminShell.d.ts +46 -0
  172. package/dist/shell/AdminShell.d.ts.map +1 -0
  173. package/dist/shell/AdminShell.js +76 -0
  174. package/dist/shell/AdminShell.js.map +1 -0
  175. package/dist/shell/guards.d.ts +28 -0
  176. package/dist/shell/guards.d.ts.map +1 -0
  177. package/dist/shell/guards.js +71 -0
  178. package/dist/shell/guards.js.map +1 -0
  179. package/icons.json +170 -0
  180. package/package.json +69 -4
  181. package/src/api/client.ts +139 -0
  182. package/src/components/ConfirmIdentityModal.tsx +82 -0
  183. package/src/components/ConfirmModal.tsx +83 -0
  184. package/src/components/CopyButton.tsx +71 -0
  185. package/src/components/CredentialSection.tsx +270 -0
  186. package/src/components/ErrorBoundary.tsx +47 -0
  187. package/src/components/ModalShell.tsx +160 -0
  188. package/src/components/ResetTwoFactorModal.tsx +74 -0
  189. package/src/components/SidePanel.tsx +96 -0
  190. package/src/components/SingleSignOnModal.tsx +161 -0
  191. package/src/components/SsoConfirmation.tsx +96 -0
  192. package/src/components/VaultTypePicker.tsx +131 -0
  193. package/src/components/WhatsNew.tsx +84 -0
  194. package/src/components/formParts.tsx +59 -0
  195. package/src/components/ui/Alert.tsx +45 -0
  196. package/src/components/ui/DataTable.tsx +225 -0
  197. package/src/components/ui/Field.tsx +63 -0
  198. package/src/components/ui/PageHeader.tsx +36 -0
  199. package/src/components/ui/Pagination.tsx +37 -0
  200. package/src/components/ui/QuickStartPanel.tsx +57 -0
  201. package/src/components/ui/StateViews.tsx +135 -0
  202. package/src/components/ui/Switch.tsx +65 -0
  203. package/src/components/ui/Toast.tsx +104 -0
  204. package/src/components/ui/index.ts +9 -0
  205. package/src/config.ts +46 -0
  206. package/src/hooks/useDarkMode.ts +38 -0
  207. package/src/hooks/useDebouncedValue.ts +22 -0
  208. package/src/index.ts +42 -0
  209. package/src/lib/changelog.ts +93 -0
  210. package/src/lib/dateFormat.ts +90 -0
  211. package/src/navigation.ts +6 -0
  212. package/src/pages/ApiTokens.tsx +361 -0
  213. package/src/pages/AuditLog.tsx +388 -0
  214. package/src/pages/Backups.tsx +170 -0
  215. package/src/pages/ChangePassword.tsx +84 -0
  216. package/src/pages/Login.tsx +275 -0
  217. package/src/pages/Settings.tsx +264 -0
  218. package/src/pages/Setup.tsx +438 -0
  219. package/src/pages/SsoConfirm.tsx +26 -0
  220. package/src/pages/SsoTestResult.tsx +104 -0
  221. package/src/pages/Users.tsx +426 -0
  222. package/src/pages/Vault.tsx +1036 -0
  223. package/src/shell/AdminShell.tsx +256 -0
  224. package/src/shell/guards.tsx +88 -0
  225. package/styles/base.css +521 -0
  226. package/styles/fonts/inter-latin-1.woff2 +0 -0
  227. package/styles/fonts/inter-latin-ext.woff2 +0 -0
  228. package/styles/fonts/jetbrains-mono-latin-3.woff2 +0 -0
  229. package/styles/fonts/jetbrains-mono-latin-ext-2.woff2 +0 -0
  230. package/styles/fonts/manrope-latin-5.woff2 +0 -0
  231. package/styles/fonts/manrope-latin-ext-4.woff2 +0 -0
  232. package/styles/fonts/material-symbols-outlined-fill.woff2 +0 -0
  233. package/styles/icons.css +4 -0
  234. package/tailwind-preset.js +79 -0
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from 'react'
2
+
3
+ type PaginationProps = {
4
+ /** 1-based current page. */
5
+ page: number
6
+ onPageChange: (page: number) => void
7
+ /** Text on the left, e.g. "Page 2 of 5 · 93 entries". Defaults to "Page X of Y" when pageCount is known. */
8
+ summary?: ReactNode | undefined
9
+ /** Hide the whole bar when there is only one page (default true; ignored with hasNext). */
10
+ hideWhenSingle?: boolean | undefined
11
+ } & (
12
+ | { pageCount: number; hasNext?: never }
13
+ /** For cursor/unknown-total lists: whether a next page exists. */
14
+ | { hasNext: boolean; pageCount?: never }
15
+ )
16
+
17
+ export function Pagination({ page, onPageChange, summary, hideWhenSingle = true, pageCount, hasNext }: PaginationProps) {
18
+ const canPrev = page > 1
19
+ const canNext = pageCount !== undefined ? page < pageCount : Boolean(hasNext)
20
+ if (pageCount !== undefined && hideWhenSingle && pageCount <= 1) return null
21
+
22
+ const text = summary ?? (pageCount !== undefined ? `Page ${page} of ${pageCount}` : `Page ${page}`)
23
+
24
+ return (
25
+ <nav aria-label="Pagination" className="flex flex-wrap items-center justify-between gap-3">
26
+ <span className="text-sm" style={{ color: 'var(--m3-secondary)' }}>{text}</span>
27
+ <div className="flex gap-2">
28
+ <button type="button" onClick={() => onPageChange(page - 1)} disabled={!canPrev} aria-label="Previous page" className="btn btn-outline btn-sm text-sm font-normal">
29
+ ← Prev
30
+ </button>
31
+ <button type="button" onClick={() => onPageChange(page + 1)} disabled={!canNext} aria-label="Next page" className="btn btn-outline btn-sm text-sm font-normal">
32
+ Next →
33
+ </button>
34
+ </div>
35
+ </nav>
36
+ )
37
+ }
@@ -0,0 +1,57 @@
1
+ import { useId, type ReactNode } from 'react'
2
+
3
+ export interface QuickStartOption<K extends string> {
4
+ key: K
5
+ label: string
6
+ hint: string
7
+ /** Icon element (a Material Symbol or a brand glyph), rendered inside the tile's icon chip. */
8
+ icon: ReactNode
9
+ }
10
+
11
+ interface QuickStartPanelProps<K extends string> {
12
+ title: string
13
+ description?: ReactNode | undefined
14
+ options: QuickStartOption<K>[]
15
+ onPick: (key: K) => void
16
+ }
17
+
18
+ /**
19
+ * First-run panel shown in place of an empty list when the first step is a choice, e.g. which kind of
20
+ * channel to create. Each tile starts the create flow with that choice already made.
21
+ */
22
+ export function QuickStartPanel<K extends string>({ title, description, options, onPick }: QuickStartPanelProps<K>) {
23
+ const titleId = useId()
24
+ return (
25
+ <section
26
+ aria-labelledby={titleId}
27
+ className="rounded-2xl p-5 space-y-4"
28
+ style={{ background: 'var(--m3-surface-container-low)', border: '1px solid var(--m3-outline-variant)' }}
29
+ >
30
+ <div className="space-y-0.5">
31
+ <h2 id={titleId} className="font-headline font-semibold text-[15px]" style={{ color: 'var(--m3-on-surface)' }}>{title}</h2>
32
+ {description && <p className="text-[13px]" style={{ color: 'var(--m3-secondary)' }}>{description}</p>}
33
+ </div>
34
+ <ul className="grid gap-2.5 grid-cols-[repeat(auto-fill,minmax(150px,1fr))]">
35
+ {options.map((option) => (
36
+ <li key={option.key}>
37
+ <button
38
+ type="button"
39
+ onClick={() => onPick(option.key)}
40
+ className="w-full h-full grid gap-2 content-start text-left rounded-[14px] p-3.5 border border-outline-variant bg-surface text-on-surface hover:border-outline hover:bg-surface-container-lowest motion-safe:transition-colors focus-ring"
41
+ >
42
+ <span
43
+ className="grid place-items-center w-[34px] h-[34px] rounded-[10px]"
44
+ aria-hidden="true"
45
+ style={{ background: 'var(--admin-icon-container)', color: 'var(--admin-icon-color)' }}
46
+ >
47
+ {option.icon}
48
+ </span>
49
+ <span className="text-[13px] font-semibold">{option.label}</span>
50
+ <span className="text-xs" style={{ color: 'var(--m3-secondary)' }}>{option.hint}</span>
51
+ </button>
52
+ </li>
53
+ ))}
54
+ </ul>
55
+ </section>
56
+ )
57
+ }
@@ -0,0 +1,135 @@
1
+ import clsx from 'clsx'
2
+ import type { CSSProperties, ReactNode } from 'react'
3
+
4
+ interface LoadingStateProps {
5
+ label?: string | undefined
6
+ className?: string | undefined
7
+ }
8
+
9
+ /** Centered spinner with a caption for data that is still loading. */
10
+ export function LoadingState({ label = 'Loading…', className }: LoadingStateProps) {
11
+ return (
12
+ <div role="status" aria-live="polite" className={clsx('flex items-center justify-center gap-3 py-12 text-sm', className)} style={{ color: 'var(--m3-secondary)' }}>
13
+ <span className="material-symbols-outlined animate-spin" aria-hidden="true" style={{ fontSize: '20px' }}>progress_activity</span>
14
+ <span>{label}</span>
15
+ </div>
16
+ )
17
+ }
18
+
19
+ interface ErrorStateProps {
20
+ message?: ReactNode | undefined
21
+ /** Renders a "Try again" button. Pass e.g. `() => void query.refetch()`. */
22
+ onRetry?: (() => void) | undefined
23
+ className?: string | undefined
24
+ }
25
+
26
+ /** Failed-to-load panel with an optional retry action. */
27
+ export function ErrorState({ message = 'Something went wrong while loading this data.', onRetry, className }: ErrorStateProps) {
28
+ return (
29
+ <div
30
+ role="alert"
31
+ className={clsx('flex flex-col items-center justify-center gap-3 rounded-2xl px-6 py-10 text-center', className)}
32
+ style={{ background: 'var(--m3-down-bg)', color: 'var(--m3-down)' }}
33
+ >
34
+ <span className="material-symbols-outlined" aria-hidden="true" style={{ fontSize: '28px' }}>error</span>
35
+ <p className="text-sm max-w-md">{message}</p>
36
+ {onRetry && (
37
+ <button type="button" onClick={onRetry} className="btn btn-secondary btn-sm">
38
+ <span className="material-symbols-outlined" aria-hidden="true">refresh</span>
39
+ Try again
40
+ </button>
41
+ )}
42
+ </div>
43
+ )
44
+ }
45
+
46
+ type EmptyStateVariant = 'card' | 'inset' | 'row'
47
+
48
+ interface EmptyStateProps {
49
+ title: ReactNode
50
+ description?: ReactNode | undefined
51
+ /** Material Symbols icon name, e.g. "radio_button_checked". */
52
+ icon?: string | undefined
53
+ /**
54
+ * Optional follow-up action. Leave it out when the page header already offers the same action and
55
+ * put an `EmptyStateLink` in the description instead.
56
+ */
57
+ action?: ReactNode | undefined
58
+ /**
59
+ * - `card` (default): a standalone compact strip, for pages without a table or list container.
60
+ * - `inset`: a row inside a card or list, separated from what is above it by a divider.
61
+ * - `row`: bare content for a table cell; use `EmptyTableRow` rather than this directly.
62
+ */
63
+ variant?: EmptyStateVariant | undefined
64
+ className?: string | undefined
65
+ }
66
+
67
+ const EMPTY_VARIANT_CLASS: Record<EmptyStateVariant, string> = {
68
+ card: 'rounded-2xl px-5 py-4',
69
+ inset: 'px-6 py-5',
70
+ row: '',
71
+ }
72
+
73
+ const EMPTY_VARIANT_STYLE: Record<EmptyStateVariant, CSSProperties | undefined> = {
74
+ card: { background: 'var(--m3-surface-container-low)', border: '1px solid var(--m3-outline-variant)' },
75
+ inset: { borderTop: '1px solid var(--m3-outline-variant)' },
76
+ row: undefined,
77
+ }
78
+
79
+ /** Compact placeholder for an empty list: an icon, a short explanation and an optional action in one row. */
80
+ export function EmptyState({ title, description, icon = 'inbox', action, variant = 'card', className }: EmptyStateProps) {
81
+ return (
82
+ <div
83
+ className={clsx('flex flex-wrap items-center gap-x-3.5 gap-y-3 text-left', EMPTY_VARIANT_CLASS[variant], className)}
84
+ style={EMPTY_VARIANT_STYLE[variant]}
85
+ >
86
+ <span
87
+ className="grid place-items-center w-10 h-10 rounded-xl flex-none"
88
+ aria-hidden="true"
89
+ style={{ background: 'var(--admin-icon-container)', color: 'var(--admin-icon-color)' }}
90
+ >
91
+ <span className="material-symbols-outlined" style={{ fontSize: '20px' }}>{icon}</span>
92
+ </span>
93
+ <div className="min-w-0 flex-[1_1_15rem] space-y-0.5">
94
+ <p className="font-headline font-semibold text-sm" style={{ color: 'var(--m3-on-surface)' }}>{title}</p>
95
+ {description && <p className="text-[13px]" style={{ color: 'var(--m3-secondary)' }}>{description}</p>}
96
+ </div>
97
+ {action && <div className="flex-none sm:ml-auto">{action}</div>}
98
+ </div>
99
+ )
100
+ }
101
+
102
+ interface EmptyTableRowProps extends Omit<EmptyStateProps, 'variant' | 'className'> {
103
+ /** Number of columns in the table, so the message spans the whole row. */
104
+ colSpan: number
105
+ }
106
+
107
+ /** The only `<tbody>` row while a table has no data, so the table and its headers keep their place. */
108
+ export function EmptyTableRow({ colSpan, ...props }: EmptyTableRowProps) {
109
+ return (
110
+ <tr>
111
+ <td colSpan={colSpan} className="px-4 py-7">
112
+ <EmptyState variant="row" {...props} />
113
+ </td>
114
+ </tr>
115
+ )
116
+ }
117
+
118
+ interface EmptyStateLinkProps {
119
+ onClick: () => void
120
+ children: ReactNode
121
+ }
122
+
123
+ /** Inline text action inside an empty-state description, e.g. "Alerts stay silent until you [add a channel]." */
124
+ export function EmptyStateLink({ onClick, children }: EmptyStateLinkProps) {
125
+ return (
126
+ <button
127
+ type="button"
128
+ onClick={onClick}
129
+ className="font-semibold underline underline-offset-[3px] rounded focus-ring"
130
+ style={{ color: 'var(--m3-on-surface)' }}
131
+ >
132
+ {children}
133
+ </button>
134
+ )
135
+ }
@@ -0,0 +1,65 @@
1
+ import clsx from 'clsx'
2
+ import { useId, type ReactNode } from 'react'
3
+
4
+ interface SwitchProps {
5
+ checked: boolean
6
+ onChange: (checked: boolean) => void
7
+ /** Visible label; clicking it toggles the switch. Without it pass `aria-label`. */
8
+ label?: ReactNode | undefined
9
+ description?: ReactNode | undefined
10
+ disabled?: boolean | undefined
11
+ id?: string | undefined
12
+ 'aria-label'?: string | undefined
13
+ className?: string | undefined
14
+ }
15
+
16
+ /** On/off toggle rendered as <button role="switch">, optionally with a clickable label and a description. */
17
+ export function Switch({ checked, onChange, label, description, disabled = false, id, 'aria-label': ariaLabel, className }: SwitchProps) {
18
+ const generatedId = useId()
19
+ const switchId = id ?? generatedId
20
+ const labelId = `${switchId}-label`
21
+ const descriptionId = `${switchId}-description`
22
+
23
+ const control = (
24
+ <button
25
+ id={switchId}
26
+ type="button"
27
+ role="switch"
28
+ aria-checked={checked}
29
+ aria-label={label ? undefined : ariaLabel}
30
+ aria-labelledby={label ? labelId : undefined}
31
+ aria-describedby={description ? descriptionId : undefined}
32
+ disabled={disabled}
33
+ onClick={() => onChange(!checked)}
34
+ className="relative flex-shrink-0 w-12 h-7 rounded-full transition-colors focus-ring disabled:opacity-50 disabled:cursor-not-allowed"
35
+ style={{ background: checked ? 'var(--admin-control-accent)' : 'var(--m3-outline-variant)' }}
36
+ >
37
+ <span
38
+ aria-hidden="true"
39
+ className="absolute top-1 w-5 h-5 rounded-full transition-all"
40
+ style={{ left: checked ? '24px' : '4px', background: checked ? 'var(--admin-control-on)' : 'var(--m3-outline)' }}
41
+ />
42
+ </button>
43
+ )
44
+
45
+ if (!label && !description) return <span className={clsx('inline-flex', className)}>{control}</span>
46
+
47
+ return (
48
+ <div className={clsx('flex items-start justify-between gap-4', className)}>
49
+ <div className="min-w-0">
50
+ {label && (
51
+ <label
52
+ id={labelId}
53
+ htmlFor={switchId}
54
+ className={clsx('block text-sm font-medium', disabled ? 'cursor-not-allowed' : 'cursor-pointer')}
55
+ style={{ color: 'var(--m3-on-surface)' }}
56
+ >
57
+ {label}
58
+ </label>
59
+ )}
60
+ {description && <p id={descriptionId} className="text-xs mt-0.5" style={{ color: 'var(--m3-secondary)' }}>{description}</p>}
61
+ </div>
62
+ {control}
63
+ </div>
64
+ )
65
+ }
@@ -0,0 +1,104 @@
1
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
2
+ import { createPortal } from 'react-dom'
3
+ import { MODAL_Z_INDEX } from '../ModalShell'
4
+
5
+ export type ToastTone = 'success' | 'error' | 'info'
6
+
7
+ export interface ToastOptions {
8
+ /** Milliseconds before it disappears on its own; 0 keeps it until dismissed. Default 4000. */
9
+ duration?: number | undefined
10
+ }
11
+
12
+ export interface ToastApi {
13
+ success: (message: ReactNode, options?: ToastOptions) => number
14
+ error: (message: ReactNode, options?: ToastOptions) => number
15
+ info: (message: ReactNode, options?: ToastOptions) => number
16
+ dismiss: (id: number) => void
17
+ }
18
+
19
+ interface ToastEntry { id: number; tone: ToastTone; message: ReactNode; duration: number }
20
+
21
+ export const TOAST_DURATION = 4000
22
+
23
+ const noop: ToastApi = { success: () => 0, error: () => 0, info: () => 0, dismiss: () => {} }
24
+
25
+ // Outside a provider (isolated component tests) toasts are silently dropped instead of throwing.
26
+ const ToastContext = createContext<ToastApi>(noop)
27
+
28
+ /** `const toast = useToast(); toast.success('Saved')`. The returned object is stable across renders. */
29
+ export function useToast(): ToastApi {
30
+ return useContext(ToastContext)
31
+ }
32
+
33
+ const TONE_STYLE: Record<ToastTone, { icon: string; color: string }> = {
34
+ success: { icon: 'check_circle', color: 'var(--m3-up)' },
35
+ error: { icon: 'error', color: 'var(--m3-down)' },
36
+ info: { icon: 'info', color: 'var(--m3-on-surface-variant)' },
37
+ }
38
+
39
+ function ToastItem({ toast, onDismiss }: { toast: ToastEntry; onDismiss: (id: number) => void }) {
40
+ const [paused, setPaused] = useState(false)
41
+ const { icon, color } = TONE_STYLE[toast.tone]
42
+
43
+ useEffect(() => {
44
+ if (paused || toast.duration <= 0) return
45
+ const timer = setTimeout(() => onDismiss(toast.id), toast.duration)
46
+ return () => clearTimeout(timer)
47
+ }, [paused, toast.duration, toast.id, onDismiss])
48
+
49
+ return (
50
+ <div
51
+ role={toast.tone === 'error' ? 'alert' : 'status'}
52
+ data-tone={toast.tone}
53
+ className="admin-toast pointer-events-auto flex items-start gap-3 rounded-xl px-4 py-3 text-sm w-full"
54
+ style={{ background: 'var(--m3-surface-container-lowest)', color: 'var(--m3-on-surface)', border: '1px solid var(--m3-outline-variant)', borderLeft: `4px solid ${color}`, boxShadow: '0 8px 24px rgba(0,0,0,0.14)' }}
55
+ onMouseEnter={() => setPaused(true)}
56
+ onMouseLeave={() => setPaused(false)}
57
+ onFocus={() => setPaused(true)}
58
+ onBlur={() => setPaused(false)}
59
+ >
60
+ <span className="material-symbols-outlined flex-shrink-0 mt-px" aria-hidden="true" style={{ fontSize: '18px', color }}>{icon}</span>
61
+ <div className="flex-1 min-w-0 break-words">{toast.message}</div>
62
+ <button type="button" onClick={() => onDismiss(toast.id)} aria-label="Dismiss" className="btn-icon -my-1 -mr-2 w-7 h-7">
63
+ <span className="material-symbols-outlined" aria-hidden="true" style={{ fontSize: '16px' }}>close</span>
64
+ </button>
65
+ </div>
66
+ )
67
+ }
68
+
69
+ /** Mount once near the root; renders the bottom-right toast stack above every modal. */
70
+ export function ToastProvider({ children }: { children: ReactNode }) {
71
+ const [toasts, setToasts] = useState<ToastEntry[]>([])
72
+ const nextId = useRef(1)
73
+
74
+ const dismiss = useCallback((id: number) => {
75
+ setToasts((current) => current.filter((toast) => toast.id !== id))
76
+ }, [])
77
+
78
+ const api = useMemo<ToastApi>(() => {
79
+ const push = (tone: ToastTone) => (message: ReactNode, options?: ToastOptions) => {
80
+ const id = nextId.current++
81
+ setToasts((current) => [...current.slice(-4), { id, tone, message, duration: options?.duration ?? TOAST_DURATION }])
82
+ return id
83
+ }
84
+ return { success: push('success'), error: push('error'), info: push('info'), dismiss }
85
+ }, [dismiss])
86
+
87
+ return (
88
+ <ToastContext.Provider value={api}>
89
+ {children}
90
+ {createPortal(
91
+ <div
92
+ role="region"
93
+ aria-live="polite"
94
+ aria-label="Notifications"
95
+ className="fixed bottom-4 right-4 left-4 sm:left-auto sm:w-96 flex flex-col items-end gap-2 pointer-events-none"
96
+ style={{ zIndex: MODAL_Z_INDEX + 1 }}
97
+ >
98
+ {toasts.map((toast) => <ToastItem key={toast.id} toast={toast} onDismiss={dismiss} />)}
99
+ </div>,
100
+ document.body,
101
+ )}
102
+ </ToastContext.Provider>
103
+ )
104
+ }
@@ -0,0 +1,9 @@
1
+ export { Alert, type AlertTone } from './Alert'
2
+ export { Field, type FieldControlProps } from './Field'
3
+ export { PageContainer, PageHeader } from './PageHeader'
4
+ export { QuickStartPanel, type QuickStartOption } from './QuickStartPanel'
5
+ export { Pagination } from './Pagination'
6
+ export { DataTable, DataTh, MAX_COLUMN_WIDTH, MIN_COLUMN_WIDTH, ResizeHandle, useTableSort, type SortDirection, type SortValue, type TableSort } from './DataTable'
7
+ export { EmptyState, EmptyStateLink, EmptyTableRow, ErrorState, LoadingState } from './StateViews'
8
+ export { Switch } from './Switch'
9
+ export { TOAST_DURATION, ToastProvider, useToast, type ToastApi, type ToastOptions, type ToastTone } from './Toast'
package/src/config.ts ADDED
@@ -0,0 +1,46 @@
1
+ export interface UiConfig {
2
+ /** Names what the interface keeps in the browser: keys in storage and window events start with it (`<prefix>-dark-mode`). */
3
+ storagePrefix: string
4
+ /** Where the API answers. */
5
+ apiBase: string
6
+ /** The cookie the server puts the CSRF token in; it is sent back in a header on every change. */
7
+ csrfCookie: string
8
+ /** Where the interface is served, without a trailing slash (`/admin`): the pages to sign in and to change a password are below it. */
9
+ basePath: string
10
+ /** For a user who does not belong in this interface (say, one who may only view a public page): the address to send them to instead. */
11
+ redirectAfterSignIn?: (user: { role: string }) => string | null
12
+ /** The names and pictures the application is known by. */
13
+ brand: { name: string; logoLight: string; logoDark: string }
14
+ /** Wording that names things only the application knows. */
15
+ texts: {
16
+ /** What an API token can never manage, in the sentence "It cannot manage ..." (for example `users, single sign-on, vaults or other tokens`). */
17
+ tokenCannotManage: string
18
+ /** What a token with the vault permission can attach a vault secret to (`a job or channel`). */
19
+ tokenVaultTargets: string
20
+ /** Said when a test sign-in would create an account; `{user}` is replaced by the account. */
21
+ ssoNewAccount: string
22
+ /** Added to the single sign-on settings to say who may sign in; empty adds nothing. */
23
+ ssoSignInHint: string
24
+ /** The name of the application, as the interface calls it in sentences. */
25
+ appName: string
26
+ /** What uses the secrets kept in a vault (`jobs`), in sentences like "... that jobs can use". */
27
+ secretConsumers: string
28
+ /** An example of the path of a secret in an external vault. */
29
+ vaultPathExample: string
30
+ }
31
+ }
32
+
33
+ let current: UiConfig = { storagePrefix: 'better', apiBase: '/api/v1', csrfCookie: 'better_csrf', basePath: '', brand: { name: 'Better', logoLight: '', logoDark: '' }, texts: { ssoNewAccount: 'Creates the account {user} and links this identity-provider account to it.', ssoSignInHint: '', appName: 'This application', secretConsumers: 'the application', vaultPathExample: 'app/database', tokenCannotManage: 'users, single sign-on, vaults or other tokens', tokenVaultTargets: 'an object' } }
34
+
35
+ /**
36
+ * Tells the interface what application it is part of. Call it before anything is rendered; what is read from storage
37
+ * is read on first use, after this.
38
+ */
39
+ export function configureUi(options: Partial<UiConfig>): void {
40
+ current = { ...current, ...options }
41
+ }
42
+
43
+ export const uiConfig = (): UiConfig => current
44
+
45
+ /** The name the interface uses for `name` in storage and in window events. */
46
+ export const storageKey = (name: string): string => `${current.storagePrefix}-${name}`
@@ -0,0 +1,38 @@
1
+ import { useState, useEffect } from 'react'
2
+ import { safeLocalStorage } from '@better-forge/contracts'
3
+ import { storageKey } from '../config'
4
+
5
+ // The public status app keeps a copy of this hook with the same behaviour, since it does not use this package.
6
+
7
+ export function useDarkMode(): [boolean, () => void] {
8
+ const [isDark, setIsDark] = useState(() => {
9
+ if (typeof window === 'undefined') return false
10
+ const stored = safeLocalStorage.get(storageKey('dark-mode'))
11
+ if (stored !== null) return stored === 'true'
12
+ return window.matchMedia('(prefers-color-scheme: dark)').matches
13
+ })
14
+
15
+ useEffect(() => {
16
+ const html = document.documentElement
17
+ if (isDark) {
18
+ html.classList.add('dark')
19
+ } else {
20
+ html.classList.remove('dark')
21
+ }
22
+ safeLocalStorage.set(storageKey('dark-mode'), String(isDark))
23
+ // Every mounted instance (e.g. the sidebar toggle and a page that swaps its logo) listens for this, so one toggle
24
+ // updates them all.
25
+ window.dispatchEvent(new CustomEvent(storageKey('dark-mode-change'), { detail: isDark }))
26
+ }, [isDark])
27
+
28
+ useEffect(() => {
29
+ const handler = (e: Event) => {
30
+ const dark = (e as CustomEvent<boolean>).detail
31
+ setIsDark(dark)
32
+ }
33
+ window.addEventListener(storageKey('dark-mode-change'), handler)
34
+ return () => window.removeEventListener(storageKey('dark-mode-change'), handler)
35
+ }, [])
36
+
37
+ return [isDark, () => setIsDark((d) => !d)]
38
+ }
@@ -0,0 +1,22 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react'
2
+
3
+ /**
4
+ * Returns `value` once it has stopped changing for `delay` ms, plus a `flush` that applies it immediately
5
+ * (e.g. on Enter) or sets an explicit value (e.g. clearing a search box).
6
+ */
7
+ export function useDebouncedValue<T>(value: T, delay = 300): [T, (next?: T) => void] {
8
+ const [debounced, setDebounced] = useState(value)
9
+ const latest = useRef(value)
10
+
11
+ useEffect(() => {
12
+ latest.current = value
13
+ const timer = setTimeout(() => setDebounced(value), delay)
14
+ return () => clearTimeout(timer)
15
+ }, [value, delay])
16
+
17
+ const flush = useCallback((next?: T) => {
18
+ setDebounced(next === undefined ? latest.current : next)
19
+ }, [])
20
+
21
+ return [debounced, flush]
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,42 @@
1
+ export * from './components/ui'
2
+ export { ConfirmModal } from './components/ConfirmModal'
3
+ export { ConfirmIdentityModal } from './components/ConfirmIdentityModal'
4
+ export { ErrorBoundary, isChunkLoadError } from './components/ErrorBoundary'
5
+ export { CopyButton } from './components/CopyButton'
6
+ export { Modal, ModalFooter, ModalHeader, ModalShell, MODAL_BACKDROP, MODAL_Z_INDEX } from './components/ModalShell'
7
+ export { SidePanelFrame, SideTabStrip, type SidePanelLayout, type SidePanelMeta, type SideTab } from './components/SidePanel'
8
+ export { VaultTypePicker, VAULT_TYPE_ICONS, isReferenceVault, type VaultTypeValue } from './components/VaultTypePicker'
9
+ export { useDebouncedValue } from './hooks/useDebouncedValue'
10
+ export { compareVersions, parseChangelog, releasesBetween, summarizeRelease, type ReleaseGroup, type ReleaseItem, type ReleaseNotes, type ReleaseSummary } from './lib/changelog'
11
+ export { configureUi, storageKey } from './config'
12
+ export { useDarkMode } from './hooks/useDarkMode'
13
+ export {
14
+ DATE_FORMATS, TIME_FORMATS, formatClock, formatDate, formatDateTime, formatDayMonth, getDatePrefs, setDatePrefs, useDatePrefs,
15
+ type DateFormat, type DatePrefs, type TimeFormat,
16
+ } from './lib/dateFormat'
17
+ export { uiConfig, type UiConfig } from './config'
18
+ export { navigation } from './navigation'
19
+ export {
20
+ ApiError, api, clearSession, enterAfterSignIn, getCurrentUser, isAuthenticated, mustChangePassword, setSession, type AuthUser,
21
+ } from './api/client'
22
+ export { WhatsNew, markWhatsNewSeen, pendingWhatsNew } from './components/WhatsNew'
23
+ export { createAdminShell, type AdminShellConfig, type ExternalLink, type NavItem, type NavSection } from './shell/AdminShell'
24
+ export { default as BackupsPage } from './pages/Backups'
25
+ export { default as ChangePasswordPage } from './pages/ChangePassword'
26
+ export { default as SettingsPage } from './pages/Settings'
27
+ export { default as SsoConfirmPage } from './pages/SsoConfirm'
28
+ export { default as SsoTestResultPage } from './pages/SsoTestResult'
29
+ export { ResetTwoFactorModal } from './components/ResetTwoFactorModal'
30
+ export { SingleSignOnModal } from './components/SingleSignOnModal'
31
+ export {
32
+ ssoConfirmChannel, SsoConfirmationNote, isSsoConfirmationRequired, isSsoSession, useSsoConfirmation, type SsoConfirmationState,
33
+ } from './components/SsoConfirmation'
34
+ export { default as ApiTokensPage } from './pages/ApiTokens'
35
+ export { default as AuditLogPage, type AuditEntities } from './pages/AuditLog'
36
+ export { default as UsersPage, type UserRole, type UsersPageAction, type UsersPageProps } from './pages/Users'
37
+ export { ConnectionStringSection, CredentialSection } from './components/CredentialSection'
38
+ export { JSON_MAPPING_FIELDS, Note, SectionDivider, toggleInSet, type SecretSummary, type VaultPickerProps, type VaultSummary } from './components/formParts'
39
+ export { default as VaultPage } from './pages/Vault'
40
+ export { default as LoginPage, type LoginPageProps } from './pages/Login'
41
+ export { default as SetupPage } from './pages/Setup'
42
+ export { RequireAuth, RequirePasswordChanged, SetupGate, createRoleGuard } from './shell/guards'
@@ -0,0 +1,93 @@
1
+ export interface ReleaseItem {
2
+ title: string
3
+ summary: string
4
+ }
5
+
6
+ export interface ReleaseGroup {
7
+ heading: string
8
+ items: ReleaseItem[]
9
+ }
10
+
11
+ export interface ReleaseNotes {
12
+ version: string
13
+ date: string
14
+ groups: ReleaseGroup[]
15
+ }
16
+
17
+ const RELEASE_HEADING = /^## \[(\d+\.\d+\.\d+)\](?: - (\S+))?\s*$/
18
+ const GROUP_HEADING = /^### (.+?)\s*$/
19
+ const ITEM = /^- (?:\*\*(.+?)\*\*:?\s*)?(.*)$/
20
+
21
+ function plain(text: string): string {
22
+ return text.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1').replace(/[`*]/g, '').trim()
23
+ }
24
+
25
+ function firstSentence(text: string): string {
26
+ const match = /^(.+?[.!?])(?:\s|$)/.exec(text)
27
+ return plain(match ? match[1]! : text)
28
+ }
29
+
30
+ /**
31
+ * Released sections of docs/changelog.md, newest first; each top-level bullet is cut down to its bold title and
32
+ * the first sentence of its text. The Unreleased section and nested bullets are left out.
33
+ */
34
+ export function parseChangelog(markdown: string): ReleaseNotes[] {
35
+ const releases: ReleaseNotes[] = []
36
+ let release: ReleaseNotes | null = null
37
+ let group: ReleaseGroup | null = null
38
+ for (const line of markdown.split(/\r?\n/)) {
39
+ const releaseMatch = RELEASE_HEADING.exec(line)
40
+ if (releaseMatch) {
41
+ release = { version: releaseMatch[1]!, date: releaseMatch[2] ?? '', groups: [] }
42
+ releases.push(release)
43
+ group = null
44
+ } else if (line.startsWith('## ')) {
45
+ release = null
46
+ } else if (release) {
47
+ const groupMatch = GROUP_HEADING.exec(line)
48
+ if (groupMatch) {
49
+ group = { heading: groupMatch[1]!, items: [] }
50
+ release.groups.push(group)
51
+ continue
52
+ }
53
+ const item = group ? ITEM.exec(line) : null
54
+ if (item && group) group.items.push({ title: plain(item[1] ?? ''), summary: firstSentence(item[2] ?? '') })
55
+ }
56
+ }
57
+ return releases.map((r) => ({ ...r, groups: r.groups.filter((g) => g.items.length > 0) }))
58
+ }
59
+
60
+ /** Negative, zero or positive like a sort comparator; plain x.y.z versions only. */
61
+ export function compareVersions(a: string, b: string): number {
62
+ const left = a.split('.').map(Number)
63
+ const right = b.split('.').map(Number)
64
+ for (let i = 0; i < 3; i++) {
65
+ const diff = (left[i] ?? 0) - (right[i] ?? 0)
66
+ if (diff !== 0) return diff
67
+ }
68
+ return 0
69
+ }
70
+
71
+ /** Releases after `seen` up to and including `current`, newest first. */
72
+ export function releasesBetween(releases: ReleaseNotes[], seen: string, current: string): ReleaseNotes[] {
73
+ return releases.filter((r) => compareVersions(r.version, seen) > 0 && compareVersions(r.version, current) <= 0)
74
+ }
75
+
76
+ export interface ReleaseSummary {
77
+ version: string
78
+ added: ReleaseItem[]
79
+ /** Changed, Removed and any other kind of entry that is not new or a fix. */
80
+ changed: ReleaseItem[]
81
+ fixed: ReleaseItem[]
82
+ }
83
+
84
+ /** One release sorted by the kind of change; fixes are only counted. */
85
+ export function summarizeRelease(release: ReleaseNotes): ReleaseSummary {
86
+ const summary: ReleaseSummary = { version: release.version, added: [], changed: [], fixed: [] }
87
+ for (const group of release.groups) {
88
+ if (group.heading === 'Added') summary.added.push(...group.items)
89
+ else if (group.heading === 'Fixed') summary.fixed.push(...group.items)
90
+ else summary.changed.push(...group.items)
91
+ }
92
+ return summary
93
+ }