@eifi1/ui-kit 0.17.0 → 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 (167) hide show
  1. package/README.md +29 -4
  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 +10 -1
  10. package/dist/components/button-group.d.ts +10 -1
  11. package/dist/components/calculator.d.ts +10 -1
  12. package/dist/components/chip.d.ts +25 -1
  13. package/dist/components/chip.js +143 -6
  14. package/dist/components/chip.js.map +1 -1
  15. package/dist/components/confirm-dialog.d.ts +42 -1
  16. package/dist/components/confirm-dialog.js +36 -5
  17. package/dist/components/confirm-dialog.js.map +1 -1
  18. package/dist/components/copy-button.d.ts +10 -1
  19. package/dist/components/danger-confirm.d.ts +55 -4
  20. package/dist/components/danger-confirm.js +67 -30
  21. package/dist/components/danger-confirm.js.map +1 -1
  22. package/dist/components/data-table-cells.d.ts +1 -1
  23. package/dist/components/data-table-filter-popover.d.ts +1 -1
  24. package/dist/components/data-table-filters.d.ts +1 -1
  25. package/dist/components/data-table.d.ts +1 -1
  26. package/dist/components/data-table.js +2 -0
  27. package/dist/components/data-table.js.map +1 -1
  28. package/dist/components/facing-pair.d.ts +10 -1
  29. package/dist/components/file-button.d.ts +10 -1
  30. package/dist/components/file-dropzone.d.ts +10 -1
  31. package/dist/components/form-actions.d.ts +10 -1
  32. package/dist/components/form-actions.js +3 -0
  33. package/dist/components/form-actions.js.map +1 -1
  34. package/dist/components/money-field.d.ts +10 -1
  35. package/dist/components/number-field.d.ts +11 -2
  36. package/dist/components/number-field.js +23 -22
  37. package/dist/components/number-field.js.map +1 -1
  38. package/dist/components/number-input.d.ts +10 -1
  39. package/dist/components/numpad-sheet.d.ts +10 -1
  40. package/dist/components/passkeys-setting.d.ts +27 -1
  41. package/dist/components/passkeys-setting.js +31 -5
  42. package/dist/components/passkeys-setting.js.map +1 -1
  43. package/dist/components/progress-bar.d.ts +15 -1
  44. package/dist/components/progress-bar.js +8 -1
  45. package/dist/components/progress-bar.js.map +1 -1
  46. package/dist/components/reauth-dialog.d.ts +90 -0
  47. package/dist/components/reauth-dialog.js +158 -0
  48. package/dist/components/reauth-dialog.js.map +1 -0
  49. package/dist/components/series-chart.d.ts +10 -1
  50. package/dist/components/server-wake.d.ts +58 -0
  51. package/dist/components/server-wake.js +58 -0
  52. package/dist/components/server-wake.js.map +1 -0
  53. package/dist/components/settings-fields.d.ts +10 -1
  54. package/dist/components/share-card.d.ts +61 -0
  55. package/dist/components/share-card.js +350 -0
  56. package/dist/components/share-card.js.map +1 -0
  57. package/dist/components/status-dot.d.ts +2 -0
  58. package/dist/components/text-link.d.ts +10 -1
  59. package/dist/components/time-input.d.ts +10 -1
  60. package/dist/components/toast.d.ts +10 -1
  61. package/dist/components/toast.js +42 -2
  62. package/dist/components/toast.js.map +1 -1
  63. package/dist/components/toggle-group.js +5 -2
  64. package/dist/components/toggle-group.js.map +1 -1
  65. package/dist/components/ui.d.ts +10 -1
  66. package/dist/components/ui.js +43 -28
  67. package/dist/components/ui.js.map +1 -1
  68. package/dist/components/use-table-state.d.ts +1 -1
  69. package/dist/components/user-avatar.d.ts +2 -0
  70. package/dist/components/write-lock.d.ts +68 -0
  71. package/dist/components/write-lock.js +33 -0
  72. package/dist/components/write-lock.js.map +1 -0
  73. package/dist/{data-table-CpkWUJBY.d.ts → data-table-3mi2R3so.d.ts} +19 -1
  74. package/dist/data-table.d.ts +1 -1
  75. package/dist/hooks/use-file-drop.d.ts +10 -1
  76. package/dist/hooks/use-overlay-history.js +16 -0
  77. package/dist/hooks/use-overlay-history.js.map +1 -1
  78. package/dist/i18n/defaults.d.ts +10 -1
  79. package/dist/i18n/defaults.js +11 -1
  80. package/dist/i18n/defaults.js.map +1 -1
  81. package/dist/i18n/german.d.ts +78 -0
  82. package/dist/i18n/{locales/de.js → german.js} +59 -9
  83. package/dist/i18n/german.js.map +1 -0
  84. package/dist/i18n/kit-labels.d.ts +10 -1
  85. package/dist/i18n/kit-labels.js +5 -0
  86. package/dist/i18n/kit-labels.js.map +1 -1
  87. package/dist/i18n/locales/de-CH.d.ts +23 -8
  88. package/dist/i18n/locales/de-CH.js +7 -3
  89. package/dist/i18n/locales/de-CH.js.map +1 -1
  90. package/dist/i18n/locales/en.d.ts +10 -1
  91. package/dist/i18n/locales/es.d.ts +10 -1
  92. package/dist/i18n/locales/es.js +51 -1
  93. package/dist/i18n/locales/es.js.map +1 -1
  94. package/dist/i18n/locales/fr.d.ts +10 -1
  95. package/dist/i18n/locales/fr.js +51 -1
  96. package/dist/i18n/locales/fr.js.map +1 -1
  97. package/dist/i18n/locales/hu.d.ts +10 -1
  98. package/dist/i18n/locales/hu.js +54 -1
  99. package/dist/i18n/locales/hu.js.map +1 -1
  100. package/dist/i18n/locales/it.d.ts +10 -1
  101. package/dist/i18n/locales/it.js +51 -1
  102. package/dist/i18n/locales/it.js.map +1 -1
  103. package/dist/i18n/locales/zh.d.ts +10 -1
  104. package/dist/i18n/locales/zh.js +50 -1
  105. package/dist/i18n/locales/zh.js.map +1 -1
  106. package/dist/i18n/swiss.d.ts +3 -3
  107. package/dist/i18n/swiss.js.map +1 -1
  108. package/dist/index.d.ts +9 -4
  109. package/dist/index.js +33 -1
  110. package/dist/index.js.map +1 -1
  111. package/dist/{kit-labels-C4uB_zmg.d.ts → kit-labels-CPbsjlXr.d.ts} +229 -9
  112. package/dist/lib/server-wake.d.ts +130 -0
  113. package/dist/lib/server-wake.js +121 -0
  114. package/dist/lib/server-wake.js.map +1 -0
  115. package/dist/rhf/fields.d.ts +10 -1
  116. package/dist/rhf/form.d.ts +10 -1
  117. package/dist/rhf.d.ts +10 -1
  118. package/dist/search/global-search.d.ts +3 -1
  119. package/dist/search/global-search.js.map +1 -1
  120. package/dist/shell/app-shell.d.ts +10 -1
  121. package/dist/shell/top-bar-brand.d.ts +10 -1
  122. package/dist/shell/topbar-action-menu.d.ts +2 -0
  123. package/dist/shell.d.ts +10 -1
  124. package/dist/wizard/stepper-nav.d.ts +10 -1
  125. package/dist/wizard.d.ts +10 -1
  126. package/package.json +1 -1
  127. package/src/components/account-chips.tsx +302 -0
  128. package/src/components/account-settings-labels.ts +16 -2
  129. package/src/components/chip.tsx +239 -6
  130. package/src/components/confirm-dialog.tsx +82 -7
  131. package/src/components/danger-confirm.tsx +118 -33
  132. package/src/components/data-table.tsx +20 -0
  133. package/src/components/form-actions.tsx +22 -3
  134. package/src/components/number-field.tsx +32 -26
  135. package/src/components/passkeys-setting.tsx +68 -7
  136. package/src/components/progress-bar.tsx +21 -1
  137. package/src/components/reauth-dialog.tsx +273 -0
  138. package/src/components/server-wake.tsx +124 -0
  139. package/src/components/share-card.tsx +615 -0
  140. package/src/components/toast.tsx +72 -2
  141. package/src/components/toggle-group.tsx +5 -2
  142. package/src/components/ui.tsx +89 -32
  143. package/src/components/write-lock.tsx +96 -0
  144. package/src/hooks/use-overlay-history.ts +51 -0
  145. package/src/i18n/defaults.ts +10 -0
  146. package/src/i18n/{locales/de.ts → german.ts} +68 -13
  147. package/src/i18n/kit-labels.tsx +22 -2
  148. package/src/i18n/locales/de-CH.ts +17 -8
  149. package/src/i18n/locales/es.ts +51 -0
  150. package/src/i18n/locales/fr.ts +52 -0
  151. package/src/i18n/locales/hu.ts +55 -0
  152. package/src/i18n/locales/it.ts +51 -0
  153. package/src/i18n/locales/zh.ts +50 -0
  154. package/src/i18n/swiss.ts +3 -3
  155. package/src/index.ts +23 -1
  156. package/src/lib/server-wake.ts +270 -0
  157. package/src/search/global-search.tsx +3 -1
  158. package/dist/i18n/locales/de-CH-informal.d.ts +0 -61
  159. package/dist/i18n/locales/de-CH-informal.js +0 -8
  160. package/dist/i18n/locales/de-CH-informal.js.map +0 -1
  161. package/dist/i18n/locales/de-informal.d.ts +0 -82
  162. package/dist/i18n/locales/de-informal.js +0 -37
  163. package/dist/i18n/locales/de-informal.js.map +0 -1
  164. package/dist/i18n/locales/de.d.ts +0 -66
  165. package/dist/i18n/locales/de.js.map +0 -1
  166. package/src/i18n/locales/de-CH-informal.ts +0 -10
  167. 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
+ }