@krak-stack/registry 0.4.0 → 0.6.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 (33) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/components/ui/animated-list.d.ts +22 -0
  3. package/dist/components/ui/animated-list.js +219 -0
  4. package/dist/components/ui/animated-number.d.ts +9 -0
  5. package/dist/components/ui/animated-number.js +52 -0
  6. package/dist/components/ui/app-switcher.d.ts +25 -0
  7. package/dist/components/ui/app-switcher.js +233 -0
  8. package/dist/components/ui/async-action-button.d.ts +16 -0
  9. package/dist/components/ui/async-action-button.js +147 -0
  10. package/dist/components/ui/auto-height.d.ts +9 -0
  11. package/dist/components/ui/auto-height.js +45 -0
  12. package/dist/components/ui/bulk-list-input.d.ts +24 -0
  13. package/dist/components/ui/bulk-list-input.js +152 -0
  14. package/dist/components/ui/choice-cards.d.ts +32 -0
  15. package/dist/components/ui/choice-cards.js +88 -0
  16. package/dist/components/ui/color-picker.js +3 -2
  17. package/dist/components/ui/danger-confirmation.d.ts +20 -0
  18. package/dist/components/ui/danger-confirmation.js +394 -0
  19. package/dist/components/ui/editable-text.d.ts +19 -0
  20. package/dist/components/ui/editable-text.js +334 -0
  21. package/dist/components/ui/effect-form.js +2 -2
  22. package/dist/components/ui/form.js +2 -2
  23. package/dist/components/ui/icon-input.js +2 -2
  24. package/dist/components/ui/presence-transition.d.ts +9 -0
  25. package/dist/components/ui/presence-transition.js +41 -0
  26. package/dist/components/ui/secret-value.d.ts +19 -0
  27. package/dist/components/ui/secret-value.js +216 -0
  28. package/dist/components/ui/unsaved-changes-guard.d.ts +15 -0
  29. package/dist/components/ui/unsaved-changes-guard.js +235 -0
  30. package/dist/components/ui/upload-attachment.d.ts +39 -0
  31. package/dist/components/ui/upload-attachment.js +286 -0
  32. package/dist/components/ui/virtualized-combobox.js +2 -2
  33. package/package.json +54 -1
@@ -0,0 +1,334 @@
1
+ // ../../src/components/ui/editable-text.tsx
2
+ import { Pencil } from "lucide-react";
3
+ import { useEffect as useEffect2, useId, useRef as useRef2, useState as useState2 } from "react";
4
+
5
+ // ../../src/components/ui/async-action-button.tsx
6
+ import { Check, LoaderCircle, RotateCcw } from "lucide-react";
7
+ import { useEffect, useRef, useState } from "react";
8
+
9
+ // ../../src/components/ui/button.tsx
10
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
11
+ import { cva } from "class-variance-authority";
12
+
13
+ // ../../src/lib/utils.ts
14
+ import { cn } from "cn";
15
+
16
+ // ../../src/components/ui/button.tsx
17
+ import { jsx } from "react/jsx-runtime";
18
+ var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
19
+ variants: {
20
+ variant: {
21
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
22
+ outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
23
+ secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
24
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
25
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
26
+ link: "text-primary underline-offset-4 hover:underline"
27
+ },
28
+ size: {
29
+ default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
30
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
31
+ sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
32
+ lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
33
+ icon: "size-9",
34
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
35
+ "icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
36
+ "icon-lg": "size-10"
37
+ }
38
+ },
39
+ defaultVariants: {
40
+ variant: "default",
41
+ size: "default"
42
+ }
43
+ });
44
+ function Button({
45
+ className,
46
+ variant = "default",
47
+ size = "default",
48
+ ...props
49
+ }) {
50
+ return /* @__PURE__ */ jsx(ButtonPrimitive, {
51
+ "data-slot": "button",
52
+ className: cn(buttonVariants({ variant, size, className })),
53
+ ...props
54
+ });
55
+ }
56
+
57
+ // ../../src/components/ui/async-action-button.tsx
58
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
59
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
60
+ var labels = {
61
+ en: {
62
+ pending: "Working…",
63
+ success: "Completed",
64
+ retry: "Try again",
65
+ error: "The action failed. Please try again."
66
+ },
67
+ fr: {
68
+ pending: "En cours…",
69
+ success: "Terminé",
70
+ retry: "Réessayer",
71
+ error: "L’action a échoué. Veuillez réessayer."
72
+ }
73
+ };
74
+ var AsyncActionButton = ({
75
+ onAction,
76
+ onPendingChange,
77
+ children,
78
+ disabled,
79
+ locale: override,
80
+ messages,
81
+ ...props
82
+ }) => {
83
+ const locale = useKrakstackLocale(override);
84
+ const copy = {
85
+ ...locale.startsWith("fr") ? labels.fr : labels.en,
86
+ ...messages?.[locale.split("-")[0] ?? locale],
87
+ ...messages?.[locale]
88
+ };
89
+ const [status, setStatus] = useState("idle");
90
+ const locked = useRef(false);
91
+ const mounted = useRef(false);
92
+ useEffect(() => {
93
+ mounted.current = true;
94
+ return () => {
95
+ mounted.current = false;
96
+ };
97
+ }, []);
98
+ const run = async () => {
99
+ if (locked.current || disabled)
100
+ return;
101
+ locked.current = true;
102
+ setStatus("pending");
103
+ onPendingChange?.(true);
104
+ try {
105
+ await onAction();
106
+ if (mounted.current)
107
+ setStatus("success");
108
+ } catch {
109
+ if (mounted.current)
110
+ setStatus("error");
111
+ } finally {
112
+ locked.current = false;
113
+ onPendingChange?.(false);
114
+ }
115
+ };
116
+ return /* @__PURE__ */ jsxs("span", {
117
+ "data-slot": "async-action-button",
118
+ className: "inline-flex min-w-0 flex-col items-start gap-2",
119
+ children: [
120
+ /* @__PURE__ */ jsxs(Button, {
121
+ ...props,
122
+ type: "button",
123
+ disabled: disabled || status === "pending",
124
+ "aria-busy": status === "pending",
125
+ onClick: () => {
126
+ run();
127
+ },
128
+ children: [
129
+ status === "pending" ? /* @__PURE__ */ jsx2(LoaderCircle, {
130
+ "aria-hidden": "true",
131
+ className: "motion-safe:animate-spin"
132
+ }) : status === "success" ? /* @__PURE__ */ jsx2(Check, {
133
+ "aria-hidden": "true"
134
+ }) : status === "error" ? /* @__PURE__ */ jsx2(RotateCcw, {
135
+ "aria-hidden": "true"
136
+ }) : null,
137
+ status === "pending" ? copy.pending : status === "success" ? copy.success : status === "error" ? copy.retry : children
138
+ ]
139
+ }),
140
+ /* @__PURE__ */ jsx2("span", {
141
+ "data-slot": "async-action-feedback",
142
+ role: "status",
143
+ className: status === "error" ? "text-destructive text-sm" : "sr-only",
144
+ children: status === "error" ? copy.error : status === "success" ? copy.success : status === "pending" ? copy.pending : ""
145
+ })
146
+ ]
147
+ });
148
+ };
149
+
150
+ // ../../src/components/ui/input.tsx
151
+ import { Input as InputPrimitive } from "@base-ui/react/input";
152
+ import { jsx as jsx3 } from "react/jsx-runtime";
153
+ function Input({ className, type, ...props }) {
154
+ return /* @__PURE__ */ jsx3(InputPrimitive, {
155
+ type,
156
+ "data-slot": "input",
157
+ className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
158
+ ...props
159
+ });
160
+ }
161
+
162
+ // ../../src/components/ui/label.tsx
163
+ import { jsx as jsx4 } from "react/jsx-runtime";
164
+ "use client";
165
+ function Label({ className, ...props }) {
166
+ return /* @__PURE__ */ jsx4("label", {
167
+ "data-slot": "label",
168
+ className: cn("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", className),
169
+ ...props
170
+ });
171
+ }
172
+
173
+ // ../../src/components/ui/editable-text.tsx
174
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
175
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
176
+ var labels2 = {
177
+ en: {
178
+ edit: "Edit",
179
+ save: "Save",
180
+ cancel: "Cancel",
181
+ empty: "Not set",
182
+ pending: "Saving…",
183
+ error: "Could not save. Check the value and try again."
184
+ },
185
+ fr: {
186
+ edit: "Modifier",
187
+ save: "Enregistrer",
188
+ cancel: "Annuler",
189
+ empty: "Non défini",
190
+ pending: "Enregistrement…",
191
+ error: "Impossible d’enregistrer. Vérifiez la valeur et réessayez."
192
+ }
193
+ };
194
+ var EditableText = ({
195
+ value,
196
+ label,
197
+ onSave,
198
+ disabled,
199
+ maxLength,
200
+ className,
201
+ locale: override,
202
+ messages
203
+ }) => {
204
+ const locale = useKrakstackLocale2(override);
205
+ const copy = {
206
+ ...locale.startsWith("fr") ? labels2.fr : labels2.en,
207
+ ...messages?.[locale.split("-")[0] ?? locale],
208
+ ...messages?.[locale]
209
+ };
210
+ const [editing, setEditing] = useState2(false);
211
+ const trigger = useRef2(null);
212
+ const wasEditing = useRef2(false);
213
+ useEffect2(() => {
214
+ if (wasEditing.current && !editing)
215
+ trigger.current?.focus();
216
+ wasEditing.current = editing;
217
+ }, [editing]);
218
+ return /* @__PURE__ */ jsx5("div", {
219
+ className,
220
+ children: editing ? /* @__PURE__ */ jsx5(EditableTextEditor, {
221
+ value,
222
+ label,
223
+ onSave,
224
+ disabled,
225
+ maxLength,
226
+ locale,
227
+ copy,
228
+ onClose: () => setEditing(false)
229
+ }) : /* @__PURE__ */ jsxs2(Button, {
230
+ ref: trigger,
231
+ type: "button",
232
+ variant: "ghost",
233
+ disabled,
234
+ "aria-label": `${copy.edit} ${label}`,
235
+ className: "h-auto max-w-full text-left whitespace-normal",
236
+ onClick: () => setEditing(true),
237
+ children: [
238
+ /* @__PURE__ */ jsx5("span", {
239
+ className: "break-all",
240
+ children: value || copy.empty
241
+ }),
242
+ /* @__PURE__ */ jsx5(Pencil, {
243
+ "aria-hidden": "true"
244
+ })
245
+ ]
246
+ })
247
+ });
248
+ };
249
+ var EditableTextEditor = ({
250
+ value,
251
+ label,
252
+ onSave,
253
+ disabled,
254
+ maxLength,
255
+ locale,
256
+ copy,
257
+ onClose
258
+ }) => {
259
+ const [draft, setDraft] = useState2(value);
260
+ const [pending, setPending] = useState2(false);
261
+ const input = useRef2(null);
262
+ const save = useRef2(null);
263
+ const id = useId();
264
+ useEffect2(() => {
265
+ input.current?.focus();
266
+ input.current?.select();
267
+ }, []);
268
+ return /* @__PURE__ */ jsxs2("div", {
269
+ className: "grid gap-3",
270
+ onKeyDown: (event) => {
271
+ if (event.nativeEvent.isComposing)
272
+ return;
273
+ if (event.key === "Escape" && !pending) {
274
+ event.preventDefault();
275
+ event.stopPropagation();
276
+ onClose();
277
+ }
278
+ },
279
+ children: [
280
+ /* @__PURE__ */ jsx5(Label, {
281
+ htmlFor: id,
282
+ children: label
283
+ }),
284
+ /* @__PURE__ */ jsx5(Input, {
285
+ ref: input,
286
+ id,
287
+ value: draft,
288
+ maxLength,
289
+ disabled: disabled || pending,
290
+ onChange: (event) => setDraft(event.target.value),
291
+ onKeyDown: (event) => {
292
+ if (event.key === "Enter" && !event.nativeEvent.isComposing) {
293
+ event.preventDefault();
294
+ save.current?.click();
295
+ }
296
+ }
297
+ }),
298
+ /* @__PURE__ */ jsxs2("div", {
299
+ className: "grid grid-cols-[auto_1fr] items-start gap-2 [&_[data-slot=async-action-feedback]]:col-span-full [&_[data-slot=async-action-feedback]]:row-start-2 [&>[data-slot=async-action-button]]:contents",
300
+ children: [
301
+ /* @__PURE__ */ jsx5(AsyncActionButton, {
302
+ ref: save,
303
+ disabled: disabled || draft === value,
304
+ locale,
305
+ messages: {
306
+ [locale ?? "en"]: {
307
+ pending: copy.pending,
308
+ retry: copy.save,
309
+ error: copy.error
310
+ }
311
+ },
312
+ onPendingChange: setPending,
313
+ onAction: async () => {
314
+ await onSave(draft);
315
+ onClose();
316
+ },
317
+ children: copy.save
318
+ }),
319
+ /* @__PURE__ */ jsx5(Button, {
320
+ className: "justify-self-start",
321
+ type: "button",
322
+ variant: "outline",
323
+ disabled: pending,
324
+ onClick: onClose,
325
+ children: copy.cancel
326
+ })
327
+ ]
328
+ })
329
+ ]
330
+ });
331
+ };
332
+ export {
333
+ EditableText
334
+ };
@@ -995,7 +995,7 @@ var VirtualizedComboboxList = ({
995
995
  }));
996
996
  const selectedEntries = itemEntries.filter(({ item }) => selectedValues.has(item.value));
997
997
  const availableEntries = itemEntries.filter(({ item }) => !selectedValues.has(item.value));
998
- const entries = groupSelections ? [
998
+ const entries = filteredItems.length === 0 ? [] : groupSelections ? [
999
999
  ...selectedEntries.length > 0 ? [
1000
1000
  {
1001
1001
  kind: "group",
@@ -1114,7 +1114,7 @@ var VirtualizedComboboxContent = ({
1114
1114
  side: "bottom",
1115
1115
  sideOffset: 6,
1116
1116
  children: /* @__PURE__ */ jsxs5(ComboboxPrimitive.Popup, {
1117
- className: cn("relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95", contentClassName),
1117
+ className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
1118
1118
  children: [
1119
1119
  /* @__PURE__ */ jsx12("div", {
1120
1120
  className: "min-w-0 shrink-0 p-1 pb-0",
@@ -999,7 +999,7 @@ var VirtualizedComboboxList = ({
999
999
  }));
1000
1000
  const selectedEntries = itemEntries.filter(({ item }) => selectedValues.has(item.value));
1001
1001
  const availableEntries = itemEntries.filter(({ item }) => !selectedValues.has(item.value));
1002
- const entries = groupSelections ? [
1002
+ const entries = filteredItems.length === 0 ? [] : groupSelections ? [
1003
1003
  ...selectedEntries.length > 0 ? [
1004
1004
  {
1005
1005
  kind: "group",
@@ -1118,7 +1118,7 @@ var VirtualizedComboboxContent = ({
1118
1118
  side: "bottom",
1119
1119
  sideOffset: 6,
1120
1120
  children: /* @__PURE__ */ jsxs5(ComboboxPrimitive.Popup, {
1121
- className: cn("relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95", contentClassName),
1121
+ className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
1122
1122
  children: [
1123
1123
  /* @__PURE__ */ jsx12("div", {
1124
1124
  className: "min-w-0 shrink-0 p-1 pb-0",
@@ -172,7 +172,7 @@ var VirtualizedComboboxList = ({
172
172
  }));
173
173
  const selectedEntries = itemEntries.filter(({ item }) => selectedValues.has(item.value));
174
174
  const availableEntries = itemEntries.filter(({ item }) => !selectedValues.has(item.value));
175
- const entries = groupSelections ? [
175
+ const entries = filteredItems.length === 0 ? [] : groupSelections ? [
176
176
  ...selectedEntries.length > 0 ? [
177
177
  {
178
178
  kind: "group",
@@ -291,7 +291,7 @@ var VirtualizedComboboxContent = ({
291
291
  side: "bottom",
292
292
  sideOffset: 6,
293
293
  children: /* @__PURE__ */ jsxs(ComboboxPrimitive.Popup, {
294
- className: cn("relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95", contentClassName),
294
+ className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
295
295
  children: [
296
296
  /* @__PURE__ */ jsx4("div", {
297
297
  className: "min-w-0 shrink-0 p-1 pb-0",
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ export type PresenceTransitionProps = {
3
+ open: boolean;
4
+ children: ReactNode;
5
+ duration?: number;
6
+ className?: string;
7
+ };
8
+ /** Exit content becomes inert immediately, then unmounts after its animation. */
9
+ export declare const PresenceTransition: ({ open, ...props }: PresenceTransitionProps) => import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ // ../../src/components/ui/presence-transition.tsx
2
+ import {
3
+ AnimatePresence,
4
+ motion,
5
+ useIsPresent,
6
+ useReducedMotion
7
+ } from "motion/react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var PresenceTransition = ({
10
+ open,
11
+ ...props
12
+ }) => /* @__PURE__ */ jsx(AnimatePresence, {
13
+ initial: false,
14
+ children: open ? /* @__PURE__ */ jsx(PresenceContent, {
15
+ ...props
16
+ }, "content") : null
17
+ });
18
+ var PresenceContent = ({
19
+ children,
20
+ duration = 180,
21
+ className
22
+ }) => {
23
+ const present = useIsPresent();
24
+ const reduced = useReducedMotion();
25
+ return /* @__PURE__ */ jsx(motion.div, {
26
+ "data-slot": "presence-transition",
27
+ className,
28
+ inert: !present,
29
+ "aria-hidden": !present ? true : undefined,
30
+ initial: { opacity: 0, y: reduced !== false ? 0 : 4 },
31
+ animate: { opacity: 1, y: 0 },
32
+ exit: { opacity: 0, y: reduced !== false ? 0 : 4 },
33
+ transition: {
34
+ duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
35
+ },
36
+ children
37
+ });
38
+ };
39
+ export {
40
+ PresenceTransition
41
+ };
@@ -0,0 +1,19 @@
1
+ import { type CopyButtonMessageTranslations } from "./copy-button.js";
2
+ export type SecretValueMessages = {
3
+ show: string;
4
+ hide: string;
5
+ hidden: string;
6
+ };
7
+ export type SecretValueProps = {
8
+ value: string;
9
+ label: string;
10
+ disabled?: boolean;
11
+ copyable?: boolean;
12
+ autoHideDelay?: number;
13
+ className?: string;
14
+ locale?: string;
15
+ messages?: Partial<Record<string, Partial<SecretValueMessages>>>;
16
+ copyMessages?: CopyButtonMessageTranslations;
17
+ };
18
+ /** Masking is presentation, not a security boundary. Never logs the value. */
19
+ export declare const SecretValue: ({ value, label, disabled, copyable, autoHideDelay, className, locale: override, messages, copyMessages, }: SecretValueProps) => import("react").JSX.Element;
@@ -0,0 +1,216 @@
1
+ // ../../src/components/ui/secret-value.tsx
2
+ import { Eye, EyeOff } from "lucide-react";
3
+ import { useEffect as useEffect2, useState as useState2 } from "react";
4
+
5
+ // ../../src/components/ui/button.tsx
6
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
7
+ import { cva } from "class-variance-authority";
8
+
9
+ // ../../src/lib/utils.ts
10
+ import { cn } from "cn";
11
+
12
+ // ../../src/components/ui/button.tsx
13
+ import { jsx } from "react/jsx-runtime";
14
+ var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
15
+ variants: {
16
+ variant: {
17
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
18
+ outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
19
+ secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
20
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
21
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
22
+ link: "text-primary underline-offset-4 hover:underline"
23
+ },
24
+ size: {
25
+ default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
26
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
27
+ sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
28
+ lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
29
+ icon: "size-9",
30
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
31
+ "icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
32
+ "icon-lg": "size-10"
33
+ }
34
+ },
35
+ defaultVariants: {
36
+ variant: "default",
37
+ size: "default"
38
+ }
39
+ });
40
+ function Button({
41
+ className,
42
+ variant = "default",
43
+ size = "default",
44
+ ...props
45
+ }) {
46
+ return /* @__PURE__ */ jsx(ButtonPrimitive, {
47
+ "data-slot": "button",
48
+ className: cn(buttonVariants({ variant, size, className })),
49
+ ...props
50
+ });
51
+ }
52
+
53
+ // ../../src/components/ui/copy-button.tsx
54
+ import { Check, Copy, TriangleAlert } from "lucide-react";
55
+ import { useEffect, useRef, useState } from "react";
56
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
57
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
58
+ var messages = {
59
+ en: { copy: "Copy", copied: "Copied", copyFailed: "Copy failed" },
60
+ fr: { copy: "Copier", copied: "Copié", copyFailed: "Échec de la copie" }
61
+ };
62
+ var copyButtonMessages = (locale = "en", translations) => ({
63
+ ...locale.startsWith("fr") ? messages.fr : messages.en,
64
+ ...translations?.[locale.split("-")[0] ?? locale],
65
+ ...translations?.[locale]
66
+ });
67
+ function CopyButton({
68
+ value,
69
+ valueDescription,
70
+ copyVariant = "default",
71
+ locale: localeOverride,
72
+ messages,
73
+ onCopied,
74
+ onCopyError,
75
+ resetDelay = 1500,
76
+ disabled,
77
+ size,
78
+ "aria-label": ariaLabel,
79
+ ...props
80
+ }) {
81
+ const locale = useKrakstackLocale(localeOverride);
82
+ const [copyState, setCopyState] = useState("idle");
83
+ const copyTimeout = useRef(undefined);
84
+ const labels = copyButtonMessages(locale, messages);
85
+ const accessibleLabel = ariaLabel ?? (valueDescription ? `${labels.copy} ${valueDescription}` : labels.copy);
86
+ const isLarge = copyVariant === "large";
87
+ const defaultSize = copyVariant === "sm" ? "icon-xs" : isLarge ? "sm" : "icon-sm";
88
+ useEffect(() => {
89
+ return () => {
90
+ if (copyTimeout.current)
91
+ clearTimeout(copyTimeout.current);
92
+ };
93
+ }, []);
94
+ const resetCopyState = () => {
95
+ if (copyTimeout.current)
96
+ clearTimeout(copyTimeout.current);
97
+ copyTimeout.current = setTimeout(() => setCopyState("idle"), resetDelay);
98
+ };
99
+ const copy = async () => {
100
+ try {
101
+ await navigator.clipboard.writeText(value);
102
+ setCopyState("copied");
103
+ onCopied?.();
104
+ } catch (error) {
105
+ setCopyState("failed");
106
+ onCopyError?.(error instanceof Error ? error : new Error(labels.copyFailed, { cause: error }));
107
+ }
108
+ resetCopyState();
109
+ };
110
+ const status = copyState === "copied" ? valueDescription ? `${labels.copied}: ${valueDescription}` : labels.copied : copyState === "failed" ? valueDescription ? `${labels.copyFailed}: ${valueDescription}` : labels.copyFailed : "";
111
+ return /* @__PURE__ */ jsxs(Button, {
112
+ "aria-label": accessibleLabel,
113
+ disabled,
114
+ onClick: copy,
115
+ size: size ?? defaultSize,
116
+ ...props,
117
+ children: [
118
+ /* @__PURE__ */ jsx2("span", {
119
+ "aria-live": "polite",
120
+ className: "sr-only",
121
+ role: "status",
122
+ children: status
123
+ }),
124
+ copyState === "copied" ? /* @__PURE__ */ jsx2(Check, {
125
+ "aria-hidden": "true"
126
+ }) : null,
127
+ copyState === "failed" ? /* @__PURE__ */ jsx2(TriangleAlert, {
128
+ "aria-hidden": "true"
129
+ }) : null,
130
+ copyState === "idle" ? /* @__PURE__ */ jsx2(Copy, {
131
+ "aria-hidden": "true"
132
+ }) : null,
133
+ isLarge ? /* @__PURE__ */ jsx2("span", {
134
+ children: labels.copy
135
+ }) : null
136
+ ]
137
+ });
138
+ }
139
+
140
+ // ../../src/components/ui/secret-value.tsx
141
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
142
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
143
+ var labels = {
144
+ en: { show: "Show", hide: "Hide", hidden: "Hidden value" },
145
+ fr: { show: "Afficher", hide: "Masquer", hidden: "Valeur masquée" }
146
+ };
147
+ var SecretValue = ({
148
+ value,
149
+ label,
150
+ disabled,
151
+ copyable = true,
152
+ autoHideDelay = 0,
153
+ className,
154
+ locale: override,
155
+ messages,
156
+ copyMessages
157
+ }) => {
158
+ const locale = useKrakstackLocale2(override);
159
+ const copy = {
160
+ ...locale.startsWith("fr") ? labels.fr : labels.en,
161
+ ...messages?.[locale.split("-")[0] ?? locale],
162
+ ...messages?.[locale]
163
+ };
164
+ const [revealedValue, setRevealedValue] = useState2(null);
165
+ const [previous, setPrevious] = useState2({ value, disabled });
166
+ if (previous.value !== value || previous.disabled !== disabled) {
167
+ setPrevious({ value, disabled });
168
+ setRevealedValue(null);
169
+ }
170
+ const revealed = !disabled && revealedValue === value;
171
+ useEffect2(() => {
172
+ if (!revealed || autoHideDelay <= 0)
173
+ return;
174
+ const timer = setTimeout(() => setRevealedValue(null), autoHideDelay);
175
+ return () => clearTimeout(timer);
176
+ }, [revealed, autoHideDelay, value]);
177
+ return /* @__PURE__ */ jsxs2("div", {
178
+ className: cn("flex min-w-0 items-center gap-2", className),
179
+ children: [
180
+ /* @__PURE__ */ jsx3("code", {
181
+ className: "min-w-0 flex-1 text-sm break-all",
182
+ "aria-label": revealed ? undefined : `${label}: ${copy.hidden}`,
183
+ children: revealed ? value : /* @__PURE__ */ jsx3("span", {
184
+ "aria-hidden": "true",
185
+ children: "••••••••"
186
+ })
187
+ }),
188
+ /* @__PURE__ */ jsx3(Button, {
189
+ type: "button",
190
+ size: "icon-sm",
191
+ variant: "ghost",
192
+ disabled,
193
+ "aria-label": `${revealed ? copy.hide : copy.show} ${label}`,
194
+ "aria-pressed": revealed,
195
+ onClick: () => setRevealedValue(revealed ? null : value),
196
+ children: revealed ? /* @__PURE__ */ jsx3(EyeOff, {
197
+ "aria-hidden": "true"
198
+ }) : /* @__PURE__ */ jsx3(Eye, {
199
+ "aria-hidden": "true"
200
+ })
201
+ }),
202
+ copyable ? /* @__PURE__ */ jsx3(CopyButton, {
203
+ type: "button",
204
+ value,
205
+ valueDescription: label,
206
+ disabled,
207
+ variant: "ghost",
208
+ locale,
209
+ messages: copyMessages
210
+ }) : null
211
+ ]
212
+ });
213
+ };
214
+ export {
215
+ SecretValue
216
+ };