@eifi1/ui-kit 0.16.1 → 0.18.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.
Files changed (186) hide show
  1. package/README.md +34 -9
  2. package/dist/chart.d.ts +10 -1
  3. package/dist/components/account-chips.d.ts +153 -0
  4. package/dist/components/account-chips.js +135 -0
  5. package/dist/components/account-chips.js.map +1 -0
  6. package/dist/components/account-settings-labels.d.ts +10 -2
  7. package/dist/components/account-settings-labels.js +3 -0
  8. package/dist/components/account-settings-labels.js.map +1 -1
  9. package/dist/components/amount-input.d.ts +18 -1
  10. package/dist/components/amount-input.js.map +1 -1
  11. package/dist/components/button-group.d.ts +10 -1
  12. package/dist/components/calculator.d.ts +10 -1
  13. package/dist/components/chip.d.ts +25 -1
  14. package/dist/components/chip.js +143 -6
  15. package/dist/components/chip.js.map +1 -1
  16. package/dist/components/confirm-dialog.d.ts +42 -1
  17. package/dist/components/confirm-dialog.js +36 -5
  18. package/dist/components/confirm-dialog.js.map +1 -1
  19. package/dist/components/copy-button.d.ts +10 -1
  20. package/dist/components/danger-confirm.d.ts +55 -4
  21. package/dist/components/danger-confirm.js +67 -30
  22. package/dist/components/danger-confirm.js.map +1 -1
  23. package/dist/components/data-table-cells.d.ts +1 -1
  24. package/dist/components/data-table-filter-popover.d.ts +1 -1
  25. package/dist/components/data-table-filters.d.ts +1 -1
  26. package/dist/components/data-table.d.ts +1 -1
  27. package/dist/components/data-table.js +93 -3
  28. package/dist/components/data-table.js.map +1 -1
  29. package/dist/components/facing-pair.d.ts +10 -1
  30. package/dist/components/file-button.d.ts +10 -1
  31. package/dist/components/file-dropzone.d.ts +10 -1
  32. package/dist/components/form-actions.d.ts +10 -1
  33. package/dist/components/form-actions.js +35 -1
  34. package/dist/components/form-actions.js.map +1 -1
  35. package/dist/components/line-items.d.ts +30 -6
  36. package/dist/components/line-items.js +77 -33
  37. package/dist/components/line-items.js.map +1 -1
  38. package/dist/components/list.d.ts +13 -1
  39. package/dist/components/list.js.map +1 -1
  40. package/dist/components/money-field.d.ts +10 -1
  41. package/dist/components/number-field.d.ts +11 -2
  42. package/dist/components/number-field.js +23 -22
  43. package/dist/components/number-field.js.map +1 -1
  44. package/dist/components/number-input.d.ts +10 -1
  45. package/dist/components/numpad-sheet.d.ts +10 -1
  46. package/dist/components/passkeys-setting.d.ts +27 -1
  47. package/dist/components/passkeys-setting.js +31 -5
  48. package/dist/components/passkeys-setting.js.map +1 -1
  49. package/dist/components/progress-bar.d.ts +25 -1
  50. package/dist/components/progress-bar.js +21 -4
  51. package/dist/components/progress-bar.js.map +1 -1
  52. package/dist/components/reauth-dialog.d.ts +90 -0
  53. package/dist/components/reauth-dialog.js +158 -0
  54. package/dist/components/reauth-dialog.js.map +1 -0
  55. package/dist/components/series-chart.d.ts +10 -1
  56. package/dist/components/server-wake.d.ts +58 -0
  57. package/dist/components/server-wake.js +58 -0
  58. package/dist/components/server-wake.js.map +1 -0
  59. package/dist/components/settings-fields.d.ts +10 -1
  60. package/dist/components/share-card.d.ts +61 -0
  61. package/dist/components/share-card.js +350 -0
  62. package/dist/components/share-card.js.map +1 -0
  63. package/dist/components/signed-amount.d.ts +12 -3
  64. package/dist/components/signed-amount.js +6 -4
  65. package/dist/components/signed-amount.js.map +1 -1
  66. package/dist/components/status-dot.d.ts +2 -0
  67. package/dist/components/text-link.d.ts +10 -1
  68. package/dist/components/time-input.d.ts +10 -1
  69. package/dist/components/toast.d.ts +10 -1
  70. package/dist/components/toast.js +42 -2
  71. package/dist/components/toast.js.map +1 -1
  72. package/dist/components/toggle-group.js +5 -2
  73. package/dist/components/toggle-group.js.map +1 -1
  74. package/dist/components/ui.d.ts +10 -1
  75. package/dist/components/ui.js +67 -30
  76. package/dist/components/ui.js.map +1 -1
  77. package/dist/components/use-table-state.d.ts +1 -1
  78. package/dist/components/user-avatar.d.ts +2 -0
  79. package/dist/components/write-lock.d.ts +68 -0
  80. package/dist/components/write-lock.js +33 -0
  81. package/dist/components/write-lock.js.map +1 -0
  82. package/dist/{data-table-CfVXtCeG.d.ts → data-table-3mi2R3so.d.ts} +59 -1
  83. package/dist/data-table.d.ts +1 -1
  84. package/dist/hooks/use-file-drop.d.ts +10 -1
  85. package/dist/hooks/use-overlay-history.js +16 -0
  86. package/dist/hooks/use-overlay-history.js.map +1 -1
  87. package/dist/i18n/defaults.d.ts +10 -1
  88. package/dist/i18n/defaults.js +11 -1
  89. package/dist/i18n/defaults.js.map +1 -1
  90. package/dist/i18n/german.d.ts +78 -0
  91. package/dist/i18n/{locales/de.js → german.js} +59 -9
  92. package/dist/i18n/german.js.map +1 -0
  93. package/dist/i18n/kit-labels.d.ts +10 -1
  94. package/dist/i18n/kit-labels.js +5 -0
  95. package/dist/i18n/kit-labels.js.map +1 -1
  96. package/dist/i18n/locales/de-CH.d.ts +23 -8
  97. package/dist/i18n/locales/de-CH.js +7 -3
  98. package/dist/i18n/locales/de-CH.js.map +1 -1
  99. package/dist/i18n/locales/{de.d.ts → en.d.ts} +24 -10
  100. package/dist/i18n/locales/en.js +95 -0
  101. package/dist/i18n/locales/en.js.map +1 -0
  102. package/dist/i18n/locales/es.d.ts +10 -1
  103. package/dist/i18n/locales/es.js +51 -1
  104. package/dist/i18n/locales/es.js.map +1 -1
  105. package/dist/i18n/locales/fr.d.ts +10 -1
  106. package/dist/i18n/locales/fr.js +51 -1
  107. package/dist/i18n/locales/fr.js.map +1 -1
  108. package/dist/i18n/locales/hu.d.ts +10 -1
  109. package/dist/i18n/locales/hu.js +54 -1
  110. package/dist/i18n/locales/hu.js.map +1 -1
  111. package/dist/i18n/locales/it.d.ts +10 -1
  112. package/dist/i18n/locales/it.js +51 -1
  113. package/dist/i18n/locales/it.js.map +1 -1
  114. package/dist/i18n/locales/zh.d.ts +10 -1
  115. package/dist/i18n/locales/zh.js +50 -1
  116. package/dist/i18n/locales/zh.js.map +1 -1
  117. package/dist/i18n/swiss.d.ts +3 -3
  118. package/dist/i18n/swiss.js.map +1 -1
  119. package/dist/index.d.ts +11 -6
  120. package/dist/index.js +33 -1
  121. package/dist/index.js.map +1 -1
  122. package/dist/{kit-labels-DE--LmCk.d.ts → kit-labels-CPbsjlXr.d.ts} +282 -10
  123. package/dist/lib/server-wake.d.ts +130 -0
  124. package/dist/lib/server-wake.js +121 -0
  125. package/dist/lib/server-wake.js.map +1 -0
  126. package/dist/rhf/fields.d.ts +10 -1
  127. package/dist/rhf/form.d.ts +10 -1
  128. package/dist/rhf/line-items.js.map +1 -1
  129. package/dist/rhf.d.ts +10 -1
  130. package/dist/search/global-search.d.ts +24 -4
  131. package/dist/search/global-search.js +31 -3
  132. package/dist/search/global-search.js.map +1 -1
  133. package/dist/search.d.ts +1 -1
  134. package/dist/shell/app-shell.d.ts +10 -1
  135. package/dist/shell/top-bar-brand.d.ts +10 -1
  136. package/dist/shell/topbar-action-menu.d.ts +2 -0
  137. package/dist/shell.d.ts +10 -1
  138. package/dist/wizard/stepper-nav.d.ts +10 -1
  139. package/dist/wizard.d.ts +10 -1
  140. package/package.json +1 -1
  141. package/src/components/account-chips.tsx +302 -0
  142. package/src/components/account-settings-labels.ts +16 -2
  143. package/src/components/amount-input.tsx +8 -0
  144. package/src/components/chip.tsx +239 -6
  145. package/src/components/confirm-dialog.tsx +82 -7
  146. package/src/components/danger-confirm.tsx +118 -33
  147. package/src/components/data-table.tsx +185 -3
  148. package/src/components/form-actions.tsx +93 -4
  149. package/src/components/line-items.tsx +116 -40
  150. package/src/components/list.tsx +13 -1
  151. package/src/components/number-field.tsx +32 -26
  152. package/src/components/passkeys-setting.tsx +68 -7
  153. package/src/components/progress-bar.tsx +40 -4
  154. package/src/components/reauth-dialog.tsx +273 -0
  155. package/src/components/server-wake.tsx +124 -0
  156. package/src/components/share-card.tsx +615 -0
  157. package/src/components/signed-amount.tsx +16 -5
  158. package/src/components/toast.tsx +72 -2
  159. package/src/components/toggle-group.tsx +5 -2
  160. package/src/components/ui.tsx +145 -34
  161. package/src/components/write-lock.tsx +96 -0
  162. package/src/hooks/use-overlay-history.ts +51 -0
  163. package/src/i18n/defaults.ts +10 -0
  164. package/src/i18n/{locales/de.ts → german.ts} +68 -13
  165. package/src/i18n/kit-labels.tsx +22 -2
  166. package/src/i18n/locales/de-CH.ts +17 -8
  167. package/src/i18n/locales/en.ts +116 -0
  168. package/src/i18n/locales/es.ts +51 -0
  169. package/src/i18n/locales/fr.ts +52 -0
  170. package/src/i18n/locales/hu.ts +55 -0
  171. package/src/i18n/locales/it.ts +51 -0
  172. package/src/i18n/locales/zh.ts +50 -0
  173. package/src/i18n/swiss.ts +3 -3
  174. package/src/index.ts +23 -1
  175. package/src/lib/server-wake.ts +270 -0
  176. package/src/rhf/line-items.tsx +2 -1
  177. package/src/search/global-search.tsx +59 -6
  178. package/dist/i18n/locales/de-CH-informal.d.ts +0 -61
  179. package/dist/i18n/locales/de-CH-informal.js +0 -8
  180. package/dist/i18n/locales/de-CH-informal.js.map +0 -1
  181. package/dist/i18n/locales/de-informal.d.ts +0 -82
  182. package/dist/i18n/locales/de-informal.js +0 -37
  183. package/dist/i18n/locales/de-informal.js.map +0 -1
  184. package/dist/i18n/locales/de.js.map +0 -1
  185. package/src/i18n/locales/de-CH-informal.ts +0 -10
  186. package/src/i18n/locales/de-informal.ts +0 -61
@@ -0,0 +1,615 @@
1
+ import { useState } from "react";
2
+ import type { ReactNode } from "react";
3
+ import { Trash2, UserPlus, UsersRound } from "lucide-react";
4
+
5
+ import { useKitLabels } from "../i18n/kit-labels";
6
+ import { cn } from "../lib/cn";
7
+ import { AlertBanner } from "./alert-banner";
8
+ import { Autocomplete } from "./autocomplete";
9
+ import type { ComboOption } from "./combobox-core";
10
+ import { Chip } from "./chip";
11
+ import { RoleChip } from "./account-chips";
12
+ import type { RoleDefinition } from "./account-chips";
13
+ import { useConfirm } from "./confirm-dialog";
14
+ import { CopyButton } from "./copy-button";
15
+ import { DialogFrame } from "./dialog-frame";
16
+ import type { DialogFrameProps } from "./dialog-frame";
17
+ import { Caption, SectionLabel } from "./text";
18
+ import { ToggleGroup } from "./toggle-group";
19
+ import { Tooltip } from "./tooltip";
20
+ import { Button, Card, IconButton, Spinner } from "./ui";
21
+ import { useWriteLock } from "./write-lock";
22
+ import type { CardProps } from "./ui";
23
+
24
+ /**
25
+ * Who holds one record, and the owner's every way of changing that — Kurvenschmiede's
26
+ * `features/sharing/share-dialog.tsx` and keksdose's `features/budgets/budget-share-card.tsx`,
27
+ * which are the same component twice (Kurvenschmiede's own doc comment says so).
28
+ *
29
+ * Presentational: the kit draws the rows, asks before a removal (the kit's
30
+ * {@link useConfirm}), keeps the field and the busy state, and checks only that an
31
+ * address is SHAPED like one. Everything that is policy stays with the app — who may
32
+ * share, whether an address has an account (that is what makes a grant pending), what
33
+ * a role permits, every request — through the callbacks, which may return a promise.
34
+ */
35
+
36
+ // ── Labels ────────────────────────────────────────────────────────────────────
37
+
38
+ export interface ShareCardLabels {
39
+ /** ShareDialog's heading. */
40
+ dialogTitle: string;
41
+ /** ShareDialog's close button. */
42
+ close: string;
43
+ /** The add field's label. */
44
+ email: string;
45
+ /** The add field's label when `addWithoutEmail` lets it stay empty. */
46
+ emailOptional: string;
47
+ emailPlaceholder: string;
48
+ /** Under the field when what was typed is not an address. */
49
+ invalidEmail: string;
50
+ /** Accessible name of the role choice beside the field. */
51
+ role: string;
52
+ /** Accessible name of one grantee's role choice. */
53
+ roleOf: (name: string) => string;
54
+ /** The add button. */
55
+ add: string;
56
+ /** Heading over the list. */
57
+ whoHasAccess: string;
58
+ /** The list is empty. */
59
+ nobodyYet: string;
60
+ /** Chip on a grant whose address has no account yet. */
61
+ pending: string;
62
+ /** A pending grant with no address — a link anybody holding it can redeem. */
63
+ openInvite: string;
64
+ copyLink: string;
65
+ /** A candidate that is a team (its sublabel, and the line under a team row). */
66
+ team: string;
67
+ /** Under the field while a team is the one named. */
68
+ teamHint: (name: string) => string;
69
+ /** The remove button on a grantee. */
70
+ remove: string;
71
+ removeConfirm: (name: string) => string;
72
+ /** The remove button on a pending grant. */
73
+ revokePending: string;
74
+ revokePendingConfirm: (name: string) => string;
75
+ /** A callback rejected and no `formatError` says better. */
76
+ failed: string;
77
+ /** Shown while `loading`. */
78
+ loading: string;
79
+ }
80
+
81
+ export const DEFAULT_SHARE_CARD_LABELS: ShareCardLabels = {
82
+ dialogTitle: "Share",
83
+ close: "Close",
84
+ email: "Email address",
85
+ emailOptional: "Email address (optional)",
86
+ emailPlaceholder: "name@example.com",
87
+ invalidEmail: "Enter a complete email address.",
88
+ role: "Role",
89
+ roleOf: (name) => `Role of ${name}`,
90
+ add: "Share",
91
+ whoHasAccess: "Who has access",
92
+ nobodyYet: "Nobody else has access yet.",
93
+ pending: "Pending",
94
+ openInvite: "Open invite link",
95
+ copyLink: "Copy link",
96
+ team: "Team",
97
+ teamHint: (name) => `Everyone in ${name} gets access.`,
98
+ remove: "Remove access",
99
+ removeConfirm: (name) => `Remove access for ${name}?`,
100
+ revokePending: "Withdraw invitation",
101
+ revokePendingConfirm: (name) => `Withdraw the invitation for ${name}?`,
102
+ failed: "That did not work. Please try again.",
103
+ loading: "Loading…",
104
+ };
105
+
106
+ // ── Data shapes ───────────────────────────────────────────────────────────────
107
+
108
+ /**
109
+ * One role of the app's vocabulary: Kurvenschmiede's viewer/editor, keksdose's guest.
110
+ *
111
+ * The admin roster's {@link RoleDefinition} (label, tone, icon) plus the key it is
112
+ * filed under — an ARRAY here rather than the keyed `RoleVocabulary` record,
113
+ * because the order is the order of the role choice's segments.
114
+ */
115
+ export type ShareRole = RoleDefinition & {
116
+ key: string;
117
+ /** What the role allows — under the role choice once chosen, and the chip's tooltip. */
118
+ description?: string;
119
+ };
120
+
121
+ /** Somebody (or a team) who holds the record now. */
122
+ export interface ShareGrantee {
123
+ id: string | number;
124
+ name: string;
125
+ /** The second line. A team row says {@link ShareCardLabels.team} instead. */
126
+ email?: string | null;
127
+ /** A {@link ShareRole.key}. */
128
+ role: string;
129
+ /** `team`: the grant reaches everybody in it (Kurvenschmiede). Default `person`. */
130
+ kind?: "person" | "team";
131
+ /** Shown, but neither its role nor its access can be changed here (an owner row). */
132
+ locked?: boolean;
133
+ /** The app's own line under the row — keksdose's per-guest key delivery. */
134
+ extra?: ReactNode;
135
+ }
136
+
137
+ /** A grant waiting for its address to have an account — or, with no address, an
138
+ * open invite link (keksdose). */
139
+ export interface SharePendingGrant {
140
+ id: string | number;
141
+ email?: string | null;
142
+ /** A {@link ShareRole.key}; left out when the app has only one role. */
143
+ role?: string;
144
+ /** The invite link, offered with a copy button. */
145
+ link?: string;
146
+ }
147
+
148
+ /** A completion offered while typing: a past grantee, or one of the sharer's teams. */
149
+ export interface ShareCandidate {
150
+ id: string | number;
151
+ name: string;
152
+ /** A person's address: taking the row fills the field with it, and the grant is
153
+ * then an ordinary address grant. */
154
+ email?: string | null;
155
+ /** `team` (or a person with no address): taking the row names THIS candidate, and
156
+ * `onAdd` receives it instead of an address. */
157
+ kind?: "person" | "team";
158
+ icon?: ReactNode;
159
+ }
160
+
161
+ /** What the add button asks for. Exactly one of `email` / `candidate` is set, except
162
+ * under `addWithoutEmail`, where both may be null (an open invite). */
163
+ export interface ShareAddRequest {
164
+ email: string | null;
165
+ candidate: ShareCandidate | null;
166
+ /** A {@link ShareRole.key}. */
167
+ role: string;
168
+ }
169
+
170
+ type MaybePromise = void | Promise<unknown>;
171
+
172
+ // ── Props ─────────────────────────────────────────────────────────────────────
173
+
174
+ export interface SharePanelProps {
175
+ grantees: ShareGrantee[];
176
+ /** The role vocabulary, in display order. One role: no choice is offered and each
177
+ * row shows its chip. */
178
+ roles: ShareRole[];
179
+ pending?: SharePendingGrant[];
180
+ /** Completions for the field. Left out: the field is a plain address field. */
181
+ candidates?: ShareCandidate[];
182
+ /** The role a new grant starts with. Default: the first of `roles`. */
183
+ defaultRole?: string;
184
+ /** Resolve to clear the field; reject to keep it and show the error. Left out (or
185
+ * `readOnly`): no add form. */
186
+ onAdd?: (request: ShareAddRequest) => MaybePromise;
187
+ /** Left out: roles are shown as chips. */
188
+ onRoleChange?: (grantee: ShareGrantee, role: string) => MaybePromise;
189
+ /** Called after the kit's confirm. Left out: no remove button. */
190
+ onRemove?: (grantee: ShareGrantee) => MaybePromise;
191
+ /** Called after the kit's confirm. Left out: no withdraw button. */
192
+ onRevokePending?: (grant: SharePendingGrant) => MaybePromise;
193
+ /** keksdose: an empty field is a request too — an invite link with no address. */
194
+ addWithoutEmail?: boolean;
195
+ /** Under the add field: whatever the app needs said there (Kurvenschmiede's "your
196
+ * pending grant does not let anybody register"). A function receives the taken
197
+ * candidate, so it can say something else while a team is named. */
198
+ caption?: ReactNode | ((candidate: ShareCandidate | null) => ReactNode);
199
+ /** Above everything — what sharing means here (keksdose's guest explanation). */
200
+ intro?: ReactNode;
201
+ /** The list is being fetched: a spinner instead of the rows. */
202
+ loading?: boolean;
203
+ /** The app's own error, shown in the error box (wins over a caught rejection). */
204
+ error?: ReactNode;
205
+ /** Turns a callback's rejection into words. Default {@link ShareCardLabels.failed}. */
206
+ formatError?: (error: unknown) => ReactNode;
207
+ /** Look, do not touch: no form, chips for roles, no remove buttons. Copying an
208
+ * invite link still works. */
209
+ readOnly?: boolean;
210
+ /** Focus the field on mount — a dialog that exists to add somebody. */
211
+ autoFocus?: boolean;
212
+ labels?: Partial<ShareCardLabels>;
213
+ }
214
+
215
+ // Shape only. Whether the address exists, is allowed, or is the sharer's own is the
216
+ // app's question — the field must never become a way to probe for accounts.
217
+ const EMAIL_SHAPE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
218
+
219
+ /** The kit's {@link RoleChip}, so a role looks the same here as in the admin roster,
220
+ * with the role's description in a tooltip. */
221
+ function ShareRoleChip({ role }: { role: ShareRole | undefined }) {
222
+ if (!role) return null;
223
+ const chip = <RoleChip value={role.key} roles={{ [role.key]: role }} />;
224
+ return role.description ? <Tooltip label={role.description}>{chip}</Tooltip> : chip;
225
+ }
226
+
227
+ /**
228
+ * A row's role choice saves on change, so it is a commit that cannot take `commit`:
229
+ * under a write lock it is disabled, and the lock's reason is put in the kit Tooltip
230
+ * around it — the same sentence the locked buttons beside it give.
231
+ */
232
+ function LockedRoleChoice({ reason, children }: { reason: ReactNode; children: ReactNode }) {
233
+ return reason === undefined ? children : <Tooltip label={reason}>{children}</Tooltip>;
234
+ }
235
+
236
+ /**
237
+ * The body both forms share: the add form, then the list. Exported for an app that
238
+ * frames it itself (a settings section, a sheet).
239
+ */
240
+ export function SharePanel({
241
+ grantees,
242
+ roles,
243
+ pending = [],
244
+ candidates,
245
+ defaultRole,
246
+ onAdd,
247
+ onRoleChange,
248
+ onRemove,
249
+ onRevokePending,
250
+ addWithoutEmail = false,
251
+ caption,
252
+ intro,
253
+ loading = false,
254
+ error,
255
+ formatError,
256
+ readOnly = false,
257
+ autoFocus,
258
+ labels: labelsProp,
259
+ }: SharePanelProps) {
260
+ // The `shareCard` namespace: prop > `<UiKitProvider labels>` > English.
261
+ const labels = useKitLabels("shareCard", DEFAULT_SHARE_CARD_LABELS, labelsProp);
262
+ const confirm = useConfirm();
263
+ // Every commit below opts into the surrounding WriteLockProvider with `commit`; the
264
+ // role choices save on change, cannot take it, and read the lock themselves.
265
+ const lock = useWriteLock();
266
+ const [email, setEmail] = useState("");
267
+ // A candidate taken from the completion. Typing again lets it go: the field then
268
+ // names an address again, and a chosen team beside free text would be two answers
269
+ // to "who" (Kurvenschmiede's rule).
270
+ const [target, setTarget] = useState<ShareCandidate | null>(null);
271
+ const [newRole, setNewRole] = useState(defaultRole ?? roles[0]?.key ?? "");
272
+ const [invalid, setInvalid] = useState(false);
273
+ // One action at a time, for the whole panel: two in flight against one record's
274
+ // grants can answer out of order. The key says which control draws the spinner.
275
+ const [busy, setBusy] = useState<string | null>(null);
276
+ const [failure, setFailure] = useState<ReactNode>(null);
277
+
278
+ const roleOf = (key: string | undefined) => roles.find((r) => r.key === key);
279
+ const choosable = roles.length > 1;
280
+ const canAdd = !readOnly && onAdd !== undefined;
281
+
282
+ const run = async (key: string, action: () => MaybePromise): Promise<boolean> => {
283
+ setBusy(key);
284
+ setFailure(null);
285
+ try {
286
+ await action();
287
+ return true;
288
+ } catch (caught) {
289
+ setFailure(formatError ? formatError(caught) : labels.failed);
290
+ return false;
291
+ } finally {
292
+ setBusy(null);
293
+ }
294
+ };
295
+
296
+ const address = email.trim();
297
+ const empty = !target && address === "";
298
+
299
+ const submit = async () => {
300
+ // Enter in the field is a commit too — the button's lock does not see it.
301
+ if (!onAdd || busy || lock.locked) return;
302
+ if (empty && !addWithoutEmail) return;
303
+ if (!target && address !== "" && !EMAIL_SHAPE.test(address)) {
304
+ setInvalid(true);
305
+ return;
306
+ }
307
+ const request: ShareAddRequest = {
308
+ email: target ? null : address || null,
309
+ candidate: target,
310
+ role: newRole,
311
+ };
312
+ if (await run("add", () => onAdd(request))) {
313
+ setEmail("");
314
+ setTarget(null);
315
+ }
316
+ };
317
+
318
+ const options: ComboOption<string>[] = (candidates ?? []).map((c) => ({
319
+ value: String(c.id),
320
+ label: c.name,
321
+ sublabel: c.kind === "team" ? labels.team : (c.email ?? undefined),
322
+ icon: c.icon ?? (c.kind === "team" ? <UsersRound className="size-4" /> : undefined),
323
+ }));
324
+
325
+ // The completion is a convenience, not a search: an address that matches nobody is
326
+ // the ordinary case (somebody new), so no "No results" box opens over the field —
327
+ // and over its error. The same narrowing Autocomplete applies, asked first.
328
+ const needle = (target ? "" : email).trim().toLowerCase();
329
+ const offers =
330
+ needle !== "" &&
331
+ options.some((o) => o.label.toLowerCase().includes(needle) || (o.sublabel ?? "").toLowerCase().includes(needle));
332
+
333
+ const captionNode = typeof caption === "function" ? caption(target) : caption;
334
+ const shownError = error ?? failure;
335
+ const nobody = grantees.length === 0 && pending.length === 0;
336
+
337
+ return (
338
+ <div className="space-y-3">
339
+ {intro && <div className="text-xs text-[var(--text-muted)]">{intro}</div>}
340
+
341
+ {canAdd && (
342
+ <div className="space-y-2">
343
+ <div
344
+ className={cn(
345
+ "grid grid-cols-1 gap-2",
346
+ choosable && "sm:grid-cols-[minmax(0,1fr)_auto] sm:items-start",
347
+ )}
348
+ >
349
+ <Autocomplete<string>
350
+ label={addWithoutEmail ? labels.emailOptional : labels.email}
351
+ placeholder={labels.emailPlaceholder}
352
+ value={target ? target.name : email}
353
+ options={options}
354
+ open={offers ? undefined : false}
355
+ fillOnSelect={false}
356
+ // eslint-disable-next-line jsx-a11y/no-autofocus -- a documented prop the caller opts into (off by default); the field never takes focus on its own.
357
+ autoFocus={autoFocus}
358
+ inputMode="email"
359
+ autoComplete="off"
360
+ autoCapitalize="none"
361
+ spellCheck={false}
362
+ disabled={busy !== null}
363
+ error={invalid ? labels.invalidEmail : undefined}
364
+ onChange={(text) => {
365
+ setTarget(null);
366
+ setInvalid(false);
367
+ setFailure(null);
368
+ setEmail(text);
369
+ }}
370
+ onSelect={(option) => {
371
+ const chosen = (candidates ?? []).find((c) => String(c.id) === option.value);
372
+ if (!chosen) return;
373
+ setInvalid(false);
374
+ if (chosen.kind !== "team" && chosen.email) {
375
+ setTarget(null);
376
+ setEmail(chosen.email);
377
+ } else {
378
+ setTarget(chosen);
379
+ setEmail("");
380
+ }
381
+ }}
382
+ onKeyDown={(event) => {
383
+ if (event.key === "Enter") void submit();
384
+ }}
385
+ />
386
+ {choosable && (
387
+ <ToggleGroup<string>
388
+ aria-label={labels.role}
389
+ options={roles.map((r) => ({ value: r.key, label: r.label }))}
390
+ value={newRole}
391
+ onChange={setNewRole}
392
+ disabled={busy !== null}
393
+ caption={
394
+ roles.some((r) => r.description) ? (key: string) => roleOf(key)?.description : undefined
395
+ }
396
+ // Level with the floating field beside it, as the two apps do by hand.
397
+ optionClassName="sm:min-h-10"
398
+ />
399
+ )}
400
+ </div>
401
+ <div className="flex flex-wrap items-center justify-between gap-2">
402
+ <div className="min-w-0 flex-1 basis-48 space-y-1">
403
+ {target?.kind === "team" && <Caption>{labels.teamHint(target.name)}</Caption>}
404
+ {captionNode && <Caption as="div">{captionNode}</Caption>}
405
+ </div>
406
+ <Button
407
+ variant="brand"
408
+ commit
409
+ pending={busy === "add"}
410
+ disabled={busy !== null || (empty && !addWithoutEmail)}
411
+ onClick={() => void submit()}
412
+ className="ms-auto"
413
+ >
414
+ <UserPlus className="size-4" aria-hidden />
415
+ {labels.add}
416
+ </Button>
417
+ </div>
418
+ </div>
419
+ )}
420
+
421
+ {shownError && (
422
+ <AlertBanner tone="danger" size="sm">
423
+ {shownError}
424
+ </AlertBanner>
425
+ )}
426
+
427
+ {loading ? (
428
+ <div className="flex justify-center py-3">
429
+ <Spinner label={labels.loading} />
430
+ </div>
431
+ ) : (
432
+ <div className="space-y-2">
433
+ <SectionLabel as="h4">{labels.whoHasAccess}</SectionLabel>
434
+ {nobody && <Caption>{labels.nobodyYet}</Caption>}
435
+ <ul className="divide-y divide-[var(--border)]">
436
+ {grantees.map((g) => {
437
+ const editable = !readOnly && !g.locked;
438
+ const changeable = editable && onRoleChange !== undefined && choosable;
439
+ const key = `grantee:${g.id}`;
440
+ return (
441
+ <li key={key} className="space-y-1.5 py-2 first:pt-0 last:pb-0">
442
+ {/* Wraps rather than squeezes: on a phone the controls drop under
443
+ the name, full row, instead of truncating it to a letter. */}
444
+ <div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5">
445
+ <div className="min-w-0 flex-1 basis-40">
446
+ <div className="flex min-w-0 items-center gap-1.5 text-sm font-medium text-[var(--text-primary)]">
447
+ {g.kind === "team" && <UsersRound className="size-4 shrink-0" aria-hidden />}
448
+ <span data-private className="truncate">
449
+ {g.name}
450
+ </span>
451
+ {!changeable && <ShareRoleChip role={roleOf(g.role)} />}
452
+ </div>
453
+ {(g.kind === "team" || g.email) && (
454
+ <div data-private className="truncate text-xs text-[var(--text-muted)]">
455
+ {g.kind === "team" ? labels.team : g.email}
456
+ </div>
457
+ )}
458
+ </div>
459
+ {(changeable || (editable && onRemove)) && (
460
+ <div className="ms-auto flex shrink-0 items-center gap-1">
461
+ {changeable && (
462
+ <LockedRoleChoice reason={lock.locked ? lock.reason : undefined}>
463
+ <ToggleGroup<string>
464
+ size="sm"
465
+ aria-label={labels.roleOf(g.name)}
466
+ options={roles.map((r) => ({ value: r.key, label: r.label }))}
467
+ value={g.role}
468
+ disabled={busy !== null || lock.locked}
469
+ onChange={(next) => {
470
+ if (next !== g.role) void run(`role:${g.id}`, () => onRoleChange(g, next));
471
+ }}
472
+ />
473
+ </LockedRoleChoice>
474
+ )}
475
+ {editable && onRemove && (
476
+ <IconButton
477
+ tone="danger"
478
+ size="xs"
479
+ commit
480
+ label={labels.remove}
481
+ pending={busy === key}
482
+ disabled={busy !== null}
483
+ onClick={async () => {
484
+ const yes = await confirm({
485
+ title: labels.removeConfirm(g.name),
486
+ confirmLabel: labels.remove,
487
+ tone: "danger",
488
+ });
489
+ if (yes) await run(key, () => onRemove(g));
490
+ }}
491
+ >
492
+ <Trash2 />
493
+ </IconButton>
494
+ )}
495
+ </div>
496
+ )}
497
+ </div>
498
+ {g.extra}
499
+ </li>
500
+ );
501
+ })}
502
+ {pending.map((p) => {
503
+ const key = `pending:${p.id}`;
504
+ const name = p.email || labels.openInvite;
505
+ return (
506
+ <li key={key} className="py-2 first:pt-0 last:pb-0">
507
+ <div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5">
508
+ <div className="min-w-0 flex-1 basis-40">
509
+ <div
510
+ data-private={p.email ? true : undefined}
511
+ className={cn(
512
+ "truncate text-sm",
513
+ p.email ? "text-[var(--text-primary)]" : "text-[var(--text-muted)]",
514
+ )}
515
+ >
516
+ {name}
517
+ </div>
518
+ <div className="mt-0.5 flex flex-wrap items-center gap-1">
519
+ <Chip size="sm" shape="square" tone="warning" caps>
520
+ {labels.pending}
521
+ </Chip>
522
+ <ShareRoleChip role={roleOf(p.role)} />
523
+ </div>
524
+ </div>
525
+ {(p.link || (!readOnly && onRevokePending)) && (
526
+ <div className="ms-auto flex shrink-0 items-center gap-1">
527
+ {p.link && <CopyButton size="xs" tone="muted" text={p.link} label={labels.copyLink} />}
528
+ {!readOnly && onRevokePending && (
529
+ <IconButton
530
+ tone="danger"
531
+ size="xs"
532
+ commit
533
+ label={labels.revokePending}
534
+ pending={busy === key}
535
+ disabled={busy !== null}
536
+ onClick={async () => {
537
+ const yes = await confirm({
538
+ title: labels.revokePendingConfirm(name),
539
+ confirmLabel: labels.revokePending,
540
+ tone: "danger",
541
+ });
542
+ if (yes) await run(key, () => onRevokePending(p));
543
+ }}
544
+ >
545
+ <Trash2 />
546
+ </IconButton>
547
+ )}
548
+ </div>
549
+ )}
550
+ </div>
551
+ </li>
552
+ );
553
+ })}
554
+ </ul>
555
+ </div>
556
+ )}
557
+ </div>
558
+ );
559
+ }
560
+
561
+ // ── The two frames ────────────────────────────────────────────────────────────
562
+
563
+ export interface ShareCardProps extends SharePanelProps {
564
+ /** A heading over the card. */
565
+ title?: ReactNode;
566
+ /** The Card's variant. Default `outline` — a block inside a section, as keksdose's
567
+ * card under a budget row is. */
568
+ variant?: CardProps["variant"];
569
+ className?: string;
570
+ }
571
+
572
+ /** {@link SharePanel} in a card — keksdose's inline form, under the row it shares. */
573
+ export function ShareCard({ title, variant = "outline", className, ...panel }: ShareCardProps) {
574
+ return (
575
+ <Card variant={variant} padding="sm" className={cn("space-y-3", className)}>
576
+ {title && <h3 className="text-sm font-semibold text-[var(--text-primary)]">{title}</h3>}
577
+ <SharePanel {...panel} />
578
+ </Card>
579
+ );
580
+ }
581
+
582
+ export interface ShareDialogProps
583
+ extends SharePanelProps,
584
+ Pick<DialogFrameProps, "open" | "onClose" | "size" | "className"> {
585
+ /** The heading. Default {@link ShareCardLabels.dialogTitle}. */
586
+ title?: ReactNode;
587
+ /** Under the heading — what is being shared (Kurvenschmiede passes its name). */
588
+ description?: ReactNode;
589
+ }
590
+
591
+ /**
592
+ * {@link SharePanel} in the kit's {@link DialogFrame} with a Close button —
593
+ * Kurvenschmiede's form. Sharing commits as it goes, so there is nothing to save or
594
+ * cancel: Close is the only action.
595
+ */
596
+ export function ShareDialog({ open, onClose, size, className, title, description, ...panel }: ShareDialogProps) {
597
+ const labels = useKitLabels("shareCard", DEFAULT_SHARE_CARD_LABELS, panel.labels);
598
+ return (
599
+ <DialogFrame
600
+ open={open}
601
+ onClose={onClose}
602
+ size={size}
603
+ className={className}
604
+ title={title ?? labels.dialogTitle}
605
+ description={description}
606
+ actions={(close) => (
607
+ <Button variant="secondary" onClick={close}>
608
+ {labels.close}
609
+ </Button>
610
+ )}
611
+ >
612
+ <SharePanel {...panel} />
613
+ </DialogFrame>
614
+ );
615
+ }
@@ -106,8 +106,17 @@ export const DEFAULT_SIGNED_AMOUNT_LABELS: SignedAmountLabels = {
106
106
  interface SignedFormatProps {
107
107
  /** ISO 4217 code: format as money. */
108
108
  currency?: string;
109
- /** `"percent"` reads `value` as a RATIO (`0.12` → 12 %), as `StatTile`'s delta does. */
109
+ /** `"percent"` reads `value` as a RATIO (`0.12` → 12 %), as `StatTile`'s delta does
110
+ * — or as percent POINTS with `ratio={false}`. */
110
111
  unit?: "value" | "percent";
112
+ /** With `unit="percent"`: `true` (default) — `value` is a ratio, `0.12` is 12 %.
113
+ * `false` — `value` is already in percent POINTS, `12` is 12 %, as `formatPercent`'s
114
+ * `ratio` option reads it. Backends send points (keksdose's price changes, kastlan's
115
+ * `change_pct`), and without this every site divided by 100 — and wrote its
116
+ * `flatWithin` as a ratio (`0.005`) beside a value it had to convert. With
117
+ * `ratio={false}` the value AND `flatWithin` are in points (`flatWithin={0.5}` is
118
+ * half a point). Ignored for any other unit. */
119
+ ratio?: boolean;
111
120
  /** Compact notation: 12 400 → "12K". */
112
121
  compact?: boolean;
113
122
  /** Fraction digits, as `formatNumber`'s `digits`. */
@@ -118,11 +127,11 @@ interface SignedFormatProps {
118
127
  locale?: string;
119
128
  }
120
129
 
121
- function useMagnitudeFormatter({ currency, unit, compact, digits, format, locale }: SignedFormatProps) {
130
+ function useMagnitudeFormatter({ currency, unit, ratio, compact, digits, format, locale }: SignedFormatProps) {
122
131
  const kitLocale = useKitLocale(locale);
123
132
  return (magnitude: number): string => {
124
133
  if (format) return format(magnitude);
125
- if (unit === "percent") return formatPercent(magnitude, { locale: kitLocale, compact, digits });
134
+ if (unit === "percent") return formatPercent(magnitude, { locale: kitLocale, compact, digits, ratio });
126
135
  if (currency) return formatMoney(magnitude, currency, { locale: kitLocale, compact, digits });
127
136
  return formatNumber(magnitude, { locale: kitLocale, compact, digits });
128
137
  };
@@ -200,6 +209,7 @@ export function SignedAmount({
200
209
  value,
201
210
  currency,
202
211
  unit,
212
+ ratio,
203
213
  compact,
204
214
  digits,
205
215
  format,
@@ -216,7 +226,7 @@ export function SignedAmount({
216
226
  ...rest
217
227
  }: SignedAmountProps) {
218
228
  const text = useKitLabels("signedAmount", DEFAULT_SIGNED_AMOUNT_LABELS, labels);
219
- const fmt = useMagnitudeFormatter({ currency, unit, compact, digits, format, locale });
229
+ const fmt = useMagnitudeFormatter({ currency, unit, ratio, compact, digits, format, locale });
220
230
  const finite = Number.isFinite(value);
221
231
  const dir = finite ? directionOf(value, flatWithin) : "flat";
222
232
  const amount = finite ? fmt(Math.abs(value)) : "—";
@@ -281,6 +291,7 @@ export function Delta({
281
291
  value,
282
292
  currency,
283
293
  unit,
294
+ ratio,
284
295
  compact,
285
296
  digits,
286
297
  format,
@@ -296,7 +307,7 @@ export function Delta({
296
307
  ...rest
297
308
  }: DeltaProps) {
298
309
  const text = useKitLabels("statTile", DEFAULT_STAT_TILE_LABELS, labels);
299
- const fmt = useMagnitudeFormatter({ currency, unit, compact, digits, format, locale });
310
+ const fmt = useMagnitudeFormatter({ currency, unit, ratio, compact, digits, format, locale });
300
311
  if (!Number.isFinite(value)) return null;
301
312
  const amount = fmt(Math.abs(value));
302
313
  const dir = directionOf(value, flatWithin);