@krak-stack/registry 0.5.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.
@@ -0,0 +1,394 @@
1
+ // ../../src/components/ui/danger-confirmation.tsx
2
+ import { useId, useState as useState2 } from "react";
3
+
4
+ // ../../src/components/ui/alert-dialog.tsx
5
+ import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
6
+
7
+ // ../../src/lib/utils.ts
8
+ import { cn } from "cn";
9
+
10
+ // ../../src/components/ui/button.tsx
11
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
12
+ import { cva } from "class-variance-authority";
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/alert-dialog.tsx
54
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
55
+ "use client";
56
+ function AlertDialog({ ...props }) {
57
+ return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Root, {
58
+ "data-slot": "alert-dialog",
59
+ ...props
60
+ });
61
+ }
62
+ function AlertDialogPortal({ ...props }) {
63
+ return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Portal, {
64
+ "data-slot": "alert-dialog-portal",
65
+ ...props
66
+ });
67
+ }
68
+ function AlertDialogOverlay({
69
+ className,
70
+ ...props
71
+ }) {
72
+ return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Backdrop, {
73
+ "data-slot": "alert-dialog-overlay",
74
+ className: cn("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0", className),
75
+ ...props
76
+ });
77
+ }
78
+ function AlertDialogContent({
79
+ className,
80
+ size = "default",
81
+ ...props
82
+ }) {
83
+ return /* @__PURE__ */ jsxs(AlertDialogPortal, {
84
+ children: [
85
+ /* @__PURE__ */ jsx2(AlertDialogOverlay, {}),
86
+ /* @__PURE__ */ jsx2(AlertDialogPrimitive.Popup, {
87
+ "data-slot": "alert-dialog-content",
88
+ "data-size": size,
89
+ className: cn("group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-6 rounded-xl bg-popover p-6 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-lg 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-out-95", className),
90
+ ...props
91
+ })
92
+ ]
93
+ });
94
+ }
95
+ function AlertDialogHeader({
96
+ className,
97
+ ...props
98
+ }) {
99
+ return /* @__PURE__ */ jsx2("div", {
100
+ "data-slot": "alert-dialog-header",
101
+ className: cn("grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]", className),
102
+ ...props
103
+ });
104
+ }
105
+ function AlertDialogFooter({
106
+ className,
107
+ ...props
108
+ }) {
109
+ return /* @__PURE__ */ jsx2("div", {
110
+ "data-slot": "alert-dialog-footer",
111
+ className: cn("flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end", className),
112
+ ...props
113
+ });
114
+ }
115
+ function AlertDialogTitle({
116
+ className,
117
+ ...props
118
+ }) {
119
+ return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Title, {
120
+ "data-slot": "alert-dialog-title",
121
+ className: cn("text-lg font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2", className),
122
+ ...props
123
+ });
124
+ }
125
+ function AlertDialogDescription({
126
+ className,
127
+ ...props
128
+ }) {
129
+ return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Description, {
130
+ "data-slot": "alert-dialog-description",
131
+ className: cn("text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground", className),
132
+ ...props
133
+ });
134
+ }
135
+ function AlertDialogCancel({
136
+ className,
137
+ variant = "outline",
138
+ size = "default",
139
+ ...props
140
+ }) {
141
+ return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Close, {
142
+ "data-slot": "alert-dialog-cancel",
143
+ className: cn(className),
144
+ render: /* @__PURE__ */ jsx2(Button, {
145
+ variant,
146
+ size
147
+ }),
148
+ ...props
149
+ });
150
+ }
151
+
152
+ // ../../src/components/ui/async-action-button.tsx
153
+ import { Check, LoaderCircle, RotateCcw } from "lucide-react";
154
+ import { useEffect, useRef, useState } from "react";
155
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
156
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
157
+ var labels = {
158
+ en: {
159
+ pending: "Working…",
160
+ success: "Completed",
161
+ retry: "Try again",
162
+ error: "The action failed. Please try again."
163
+ },
164
+ fr: {
165
+ pending: "En cours…",
166
+ success: "Terminé",
167
+ retry: "Réessayer",
168
+ error: "L’action a échoué. Veuillez réessayer."
169
+ }
170
+ };
171
+ var AsyncActionButton = ({
172
+ onAction,
173
+ onPendingChange,
174
+ children,
175
+ disabled,
176
+ locale: override,
177
+ messages,
178
+ ...props
179
+ }) => {
180
+ const locale = useKrakstackLocale(override);
181
+ const copy = {
182
+ ...locale.startsWith("fr") ? labels.fr : labels.en,
183
+ ...messages?.[locale.split("-")[0] ?? locale],
184
+ ...messages?.[locale]
185
+ };
186
+ const [status, setStatus] = useState("idle");
187
+ const locked = useRef(false);
188
+ const mounted = useRef(false);
189
+ useEffect(() => {
190
+ mounted.current = true;
191
+ return () => {
192
+ mounted.current = false;
193
+ };
194
+ }, []);
195
+ const run = async () => {
196
+ if (locked.current || disabled)
197
+ return;
198
+ locked.current = true;
199
+ setStatus("pending");
200
+ onPendingChange?.(true);
201
+ try {
202
+ await onAction();
203
+ if (mounted.current)
204
+ setStatus("success");
205
+ } catch {
206
+ if (mounted.current)
207
+ setStatus("error");
208
+ } finally {
209
+ locked.current = false;
210
+ onPendingChange?.(false);
211
+ }
212
+ };
213
+ return /* @__PURE__ */ jsxs2("span", {
214
+ "data-slot": "async-action-button",
215
+ className: "inline-flex min-w-0 flex-col items-start gap-2",
216
+ children: [
217
+ /* @__PURE__ */ jsxs2(Button, {
218
+ ...props,
219
+ type: "button",
220
+ disabled: disabled || status === "pending",
221
+ "aria-busy": status === "pending",
222
+ onClick: () => {
223
+ run();
224
+ },
225
+ children: [
226
+ status === "pending" ? /* @__PURE__ */ jsx3(LoaderCircle, {
227
+ "aria-hidden": "true",
228
+ className: "motion-safe:animate-spin"
229
+ }) : status === "success" ? /* @__PURE__ */ jsx3(Check, {
230
+ "aria-hidden": "true"
231
+ }) : status === "error" ? /* @__PURE__ */ jsx3(RotateCcw, {
232
+ "aria-hidden": "true"
233
+ }) : null,
234
+ status === "pending" ? copy.pending : status === "success" ? copy.success : status === "error" ? copy.retry : children
235
+ ]
236
+ }),
237
+ /* @__PURE__ */ jsx3("span", {
238
+ "data-slot": "async-action-feedback",
239
+ role: "status",
240
+ className: status === "error" ? "text-destructive text-sm" : "sr-only",
241
+ children: status === "error" ? copy.error : status === "success" ? copy.success : status === "pending" ? copy.pending : ""
242
+ })
243
+ ]
244
+ });
245
+ };
246
+
247
+ // ../../src/components/ui/input.tsx
248
+ import { Input as InputPrimitive } from "@base-ui/react/input";
249
+ import { jsx as jsx4 } from "react/jsx-runtime";
250
+ function Input({ className, type, ...props }) {
251
+ return /* @__PURE__ */ jsx4(InputPrimitive, {
252
+ type,
253
+ "data-slot": "input",
254
+ 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),
255
+ ...props
256
+ });
257
+ }
258
+
259
+ // ../../src/components/ui/label.tsx
260
+ import { jsx as jsx5 } from "react/jsx-runtime";
261
+ "use client";
262
+ function Label({ className, ...props }) {
263
+ return /* @__PURE__ */ jsx5("label", {
264
+ "data-slot": "label",
265
+ 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),
266
+ ...props
267
+ });
268
+ }
269
+
270
+ // ../../src/components/ui/danger-confirmation.tsx
271
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
272
+ import { jsx as jsx6, jsxs as jsxs3, Fragment } from "react/jsx-runtime";
273
+ var labels2 = {
274
+ en: {
275
+ confirm: "Confirm deletion",
276
+ cancel: "Cancel",
277
+ typeToConfirm: "Type the following text to confirm",
278
+ pending: "Deleting…",
279
+ error: "Could not complete the action. Check its status before trying again."
280
+ },
281
+ fr: {
282
+ confirm: "Confirmer la suppression",
283
+ cancel: "Annuler",
284
+ typeToConfirm: "Saisissez le texte suivant pour confirmer",
285
+ pending: "Suppression…",
286
+ error: "Impossible de terminer l’action. Vérifiez son état avant de réessayer."
287
+ }
288
+ };
289
+ var DangerConfirmation = (props) => {
290
+ const locale = useKrakstackLocale2(props.locale);
291
+ const copy = {
292
+ ...locale.startsWith("fr") ? labels2.fr : labels2.en,
293
+ ...props.messages?.[locale.split("-")[0] ?? locale],
294
+ ...props.messages?.[locale]
295
+ };
296
+ const [pending, setPending] = useState2(false);
297
+ return /* @__PURE__ */ jsx6(AlertDialog, {
298
+ open: props.open,
299
+ onOpenChange: (open) => {
300
+ if (!pending)
301
+ props.onOpenChange(open);
302
+ },
303
+ children: /* @__PURE__ */ jsx6(AlertDialogContent, {
304
+ children: /* @__PURE__ */ jsx6(DangerConfirmationBody, {
305
+ ...props,
306
+ locale,
307
+ copy,
308
+ pending,
309
+ onPendingChange: setPending
310
+ }, props.open ? "open" : "closed")
311
+ })
312
+ });
313
+ };
314
+ var DangerConfirmationBody = ({
315
+ title,
316
+ description,
317
+ confirmation,
318
+ onConfirm,
319
+ onOpenChange,
320
+ locale,
321
+ copy,
322
+ pending,
323
+ onPendingChange
324
+ }) => {
325
+ const id = useId();
326
+ const [text, setText] = useState2("");
327
+ return /* @__PURE__ */ jsxs3(Fragment, {
328
+ children: [
329
+ /* @__PURE__ */ jsxs3(AlertDialogHeader, {
330
+ children: [
331
+ /* @__PURE__ */ jsx6(AlertDialogTitle, {
332
+ children: title
333
+ }),
334
+ /* @__PURE__ */ jsx6(AlertDialogDescription, {
335
+ children: description
336
+ })
337
+ ]
338
+ }),
339
+ confirmation !== undefined ? /* @__PURE__ */ jsxs3("div", {
340
+ className: "grid gap-2",
341
+ children: [
342
+ /* @__PURE__ */ jsx6(Label, {
343
+ htmlFor: id,
344
+ children: copy.typeToConfirm
345
+ }),
346
+ /* @__PURE__ */ jsx6("code", {
347
+ id: `${id}-phrase`,
348
+ className: "text-sm break-all",
349
+ children: confirmation
350
+ }),
351
+ /* @__PURE__ */ jsx6(Input, {
352
+ id,
353
+ "aria-describedby": `${id}-phrase`,
354
+ value: text,
355
+ onChange: (event) => setText(event.target.value),
356
+ disabled: pending,
357
+ autoComplete: "off",
358
+ spellCheck: false
359
+ })
360
+ ]
361
+ }) : null,
362
+ /* @__PURE__ */ jsxs3(AlertDialogFooter, {
363
+ children: [
364
+ /* @__PURE__ */ jsx6(AlertDialogCancel, {
365
+ type: "button",
366
+ disabled: pending,
367
+ children: copy.cancel
368
+ }),
369
+ /* @__PURE__ */ jsx6(AsyncActionButton, {
370
+ variant: "destructive",
371
+ disabled: confirmation !== undefined && text !== confirmation,
372
+ locale,
373
+ messages: {
374
+ [locale ?? "en"]: {
375
+ pending: copy.pending,
376
+ retry: copy.confirm,
377
+ error: copy.error
378
+ }
379
+ },
380
+ onPendingChange,
381
+ onAction: async () => {
382
+ await onConfirm();
383
+ onOpenChange(false);
384
+ },
385
+ children: copy.confirm
386
+ })
387
+ ]
388
+ })
389
+ ]
390
+ });
391
+ };
392
+ export {
393
+ DangerConfirmation
394
+ };
@@ -0,0 +1,19 @@
1
+ export type EditableTextMessages = {
2
+ edit: string;
3
+ save: string;
4
+ cancel: string;
5
+ empty: string;
6
+ pending: string;
7
+ error: string;
8
+ };
9
+ export type EditableTextProps = {
10
+ value: string;
11
+ label: string;
12
+ onSave: (value: string) => Promise<void>;
13
+ disabled?: boolean;
14
+ maxLength?: number;
15
+ className?: string;
16
+ locale?: string;
17
+ messages?: Partial<Record<string, Partial<EditableTextMessages>>>;
18
+ };
19
+ export declare const EditableText: ({ value, label, onSave, disabled, maxLength, className, locale: override, messages, }: EditableTextProps) => import("react").JSX.Element;