@krak-stack/registry 0.8.3 → 0.10.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 (45) hide show
  1. package/CHANGELOG.md +16 -5
  2. package/dist/components/ui/animated-list.js +5 -0
  3. package/dist/components/ui/app-switcher.d.ts +2 -1
  4. package/dist/components/ui/app-switcher.js +5 -1
  5. package/dist/components/ui/async-action-button.d.ts +2 -1
  6. package/dist/components/ui/async-action-button.js +3 -1
  7. package/dist/components/ui/bulk-list-input.d.ts +2 -1
  8. package/dist/components/ui/bulk-list-input.js +6 -1
  9. package/dist/components/ui/calendar.d.ts +10 -0
  10. package/dist/components/ui/choice-cards.d.ts +1 -0
  11. package/dist/components/ui/choice-cards.js +7 -1
  12. package/dist/components/ui/color-picker.d.ts +2 -1
  13. package/dist/components/ui/color-picker.js +4 -1
  14. package/dist/components/ui/cron-expression-editor.d.ts +3 -1
  15. package/dist/components/ui/cron-expression-editor.js +13 -3
  16. package/dist/components/ui/danger-confirmation.d.ts +1 -0
  17. package/dist/components/ui/danger-confirmation.js +5 -1
  18. package/dist/components/ui/date-picker.d.ts +33 -0
  19. package/dist/components/ui/date-picker.js +470 -0
  20. package/dist/components/ui/date-picker.schema.d.ts +9 -0
  21. package/dist/components/ui/editable-text.js +8 -1
  22. package/dist/components/ui/form.d.ts +5 -5
  23. package/dist/components/ui/image-crop-editor.js +10 -1
  24. package/dist/components/ui/phone-number-input.d.ts +3 -1
  25. package/dist/components/ui/phone-number-input.js +53 -13
  26. package/dist/components/ui/phone-number-input.schema.d.ts +7 -0
  27. package/dist/components/ui/{copy-value.d.ts → secret-value.d.ts} +4 -6
  28. package/dist/components/ui/secret-value.js +222 -0
  29. package/dist/components/ui/select-with-custom-input.d.ts +36 -0
  30. package/dist/components/ui/select-with-custom-input.js +275 -0
  31. package/dist/components/ui/sidebar-layout.js +1 -0
  32. package/dist/components/ui/stepper.js +8 -0
  33. package/dist/components/ui/time-picker.d.ts +41 -0
  34. package/dist/components/ui/time-picker.js +488 -0
  35. package/dist/components/ui/time-picker.schema.d.ts +14 -0
  36. package/dist/components/ui/timezone-select.d.ts +2 -1
  37. package/dist/components/ui/timezone-select.js +5 -1
  38. package/dist/components/ui/toast.d.ts +18 -0
  39. package/dist/components/ui/toast.js +121 -0
  40. package/dist/components/ui/unsaved-changes-guard.d.ts +2 -1
  41. package/dist/components/ui/unsaved-changes-guard.js +4 -1
  42. package/dist/components/ui/upload-attachment.js +3 -0
  43. package/dist/lib/docs.js +1 -0
  44. package/package.json +23 -5
  45. package/dist/components/ui/copy-value.js +0 -319
@@ -0,0 +1,121 @@
1
+ // ../../src/components/ui/toast.tsx
2
+ import { Toast as ToastPrimitive } from "@base-ui/react/toast";
3
+ import {
4
+ CircleCheck,
5
+ CircleAlert,
6
+ Info,
7
+ TriangleAlert,
8
+ LoaderCircle,
9
+ X
10
+ } from "lucide-react";
11
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
12
+
13
+ // ../../src/lib/utils.ts
14
+ import { cn } from "cn";
15
+
16
+ // ../../src/components/ui/toast.tsx
17
+ import { jsx, jsxs } from "react/jsx-runtime";
18
+ "use client";
19
+ var useToast = ToastPrimitive.useToastManager;
20
+ var createToastManager = ToastPrimitive.createToastManager;
21
+ var positions = {
22
+ "top-left": "top-4 left-4",
23
+ "top-center": "top-4 left-1/2 -translate-x-1/2",
24
+ "top-right": "top-4 right-4",
25
+ "bottom-left": "bottom-4 left-4",
26
+ "bottom-center": "bottom-4 left-1/2 -translate-x-1/2",
27
+ "bottom-right": "bottom-4 right-4"
28
+ };
29
+ var ToastViewport = ({
30
+ position,
31
+ locale,
32
+ messages,
33
+ classNames
34
+ }) => {
35
+ const language = useKrakstackLocale(locale);
36
+ const copy = {
37
+ ...language.startsWith("fr") ? { notifications: "Notifications", dismiss: "Fermer la notification" } : { notifications: "Notifications", dismiss: "Dismiss notification" },
38
+ ...messages?.[language.split("-")[0] ?? language],
39
+ ...messages?.[language]
40
+ };
41
+ const { toasts } = useToast();
42
+ return /* @__PURE__ */ jsx(ToastPrimitive.Portal, {
43
+ children: /* @__PURE__ */ jsx(ToastPrimitive.Viewport, {
44
+ "data-slot": "toast-viewport",
45
+ "data-position": position,
46
+ "aria-label": copy.notifications,
47
+ className: cn("pointer-events-none fixed z-[100] flex max-h-[calc(100dvh-2rem)] w-96 max-w-[calc(100vw-2rem)] [scrollbar-width:none] flex-col gap-3 overflow-y-auto overscroll-contain outline-none [&::-webkit-scrollbar]:hidden", positions[position], classNames?.viewport),
48
+ children: toasts.map((toast) => {
49
+ const Icon = toast.type === "success" ? CircleCheck : toast.type === "error" ? CircleAlert : toast.type === "warning" ? TriangleAlert : toast.type === "loading" ? LoaderCircle : Info;
50
+ return /* @__PURE__ */ jsx(ToastPrimitive.Root, {
51
+ "data-slot": "toast",
52
+ toast,
53
+ swipeDirection: position.endsWith("left") ? ["left"] : position.endsWith("right") ? ["right"] : [position.startsWith("top") ? "up" : "down"],
54
+ className: cn("bg-popover text-popover-foreground focus-visible:ring-ring pointer-events-auto relative shrink-0 touch-pan-y rounded-lg border p-4 shadow-lg transition-[opacity,transform] duration-150 outline-none focus-visible:ring-2 data-ending-style:translate-y-2 data-ending-style:opacity-0 data-limited:hidden data-starting-style:translate-y-2 data-starting-style:opacity-0 motion-reduce:transition-none", classNames?.toast),
55
+ children: /* @__PURE__ */ jsxs(ToastPrimitive.Content, {
56
+ "data-slot": "toast-content",
57
+ className: cn("flex min-w-0 items-start gap-3", classNames?.content),
58
+ children: [
59
+ /* @__PURE__ */ jsx(Icon, {
60
+ "data-slot": "toast-icon",
61
+ "aria-hidden": "true",
62
+ className: cn("mt-0.5 size-4 shrink-0", toast.type === "success" && "text-emerald-600 dark:text-emerald-400", toast.type === "error" && "text-destructive", toast.type === "warning" && "text-amber-600 dark:text-amber-400", toast.type === "loading" && "motion-safe:animate-spin", classNames?.icon)
63
+ }),
64
+ /* @__PURE__ */ jsxs("div", {
65
+ "data-slot": "toast-body",
66
+ className: cn("grid min-w-0 flex-1 gap-1 [overflow-wrap:anywhere]", classNames?.body),
67
+ children: [
68
+ /* @__PURE__ */ jsx(ToastPrimitive.Title, {
69
+ "data-slot": "toast-title",
70
+ className: cn("text-sm leading-5 font-medium", classNames?.title)
71
+ }),
72
+ /* @__PURE__ */ jsx(ToastPrimitive.Description, {
73
+ "data-slot": "toast-description",
74
+ className: cn("text-muted-foreground text-sm leading-5", classNames?.description)
75
+ }),
76
+ /* @__PURE__ */ jsx(ToastPrimitive.Action, {
77
+ "data-slot": "toast-action",
78
+ className: cn("text-foreground mt-2 w-fit rounded-sm text-sm font-medium underline underline-offset-4 outline-offset-4 disabled:opacity-50", classNames?.action)
79
+ })
80
+ ]
81
+ }),
82
+ /* @__PURE__ */ jsx(ToastPrimitive.Close, {
83
+ "data-slot": "toast-close",
84
+ "aria-label": copy.dismiss,
85
+ className: cn("text-muted-foreground hover:bg-muted hover:text-foreground -mt-1 -mr-1 inline-flex size-7 shrink-0 items-center justify-center rounded-md outline-offset-2", classNames?.close),
86
+ children: /* @__PURE__ */ jsx(X, {
87
+ "aria-hidden": "true",
88
+ className: "size-4"
89
+ })
90
+ })
91
+ ]
92
+ })
93
+ }, toast.id);
94
+ })
95
+ })
96
+ });
97
+ };
98
+ var ToastProvider = ({
99
+ children,
100
+ position = "bottom-right",
101
+ locale,
102
+ messages,
103
+ classNames,
104
+ ...props
105
+ }) => /* @__PURE__ */ jsxs(ToastPrimitive.Provider, {
106
+ ...props,
107
+ children: [
108
+ children,
109
+ /* @__PURE__ */ jsx(ToastViewport, {
110
+ position,
111
+ locale,
112
+ messages,
113
+ classNames
114
+ })
115
+ ]
116
+ });
117
+ export {
118
+ ToastProvider,
119
+ createToastManager,
120
+ useToast
121
+ };
@@ -10,6 +10,7 @@ export type UnsavedChangesGuardProps = {
10
10
  protectBeforeUnload?: boolean;
11
11
  locale?: string;
12
12
  messages?: Partial<Record<string, Partial<UnsavedChangesGuardMessages>>>;
13
+ className?: string;
13
14
  };
14
15
  /** Mount once per editing route, inside a TanStack Router provider. */
15
- export declare const UnsavedChangesGuard: ({ dirty, enabled, protectBeforeUnload, locale: override, messages, }: UnsavedChangesGuardProps) => import("react").JSX.Element;
16
+ export declare const UnsavedChangesGuard: ({ dirty, enabled, protectBeforeUnload, locale: override, messages, className, }: UnsavedChangesGuardProps) => import("react").JSX.Element;
@@ -181,7 +181,8 @@ var UnsavedChangesGuard = ({
181
181
  enabled = true,
182
182
  protectBeforeUnload = true,
183
183
  locale: override,
184
- messages
184
+ messages,
185
+ className
185
186
  }) => {
186
187
  const locale = useKrakstackLocale(override);
187
188
  const copy = {
@@ -201,6 +202,8 @@ var UnsavedChangesGuard = ({
201
202
  blocker.reset?.();
202
203
  },
203
204
  children: /* @__PURE__ */ jsxs2(AlertDialogContent, {
205
+ "data-component": "unsaved-changes-guard",
206
+ className,
204
207
  children: [
205
208
  /* @__PURE__ */ jsxs2(AlertDialogHeader, {
206
209
  children: [
@@ -203,6 +203,7 @@ var UploadAttachment = ({
203
203
  const progress = state.status === "uploading" && state.progress !== undefined && Number.isFinite(state.progress) ? Math.min(100, Math.max(0, state.progress)) : undefined;
204
204
  const status = state.status === "error" ? state.message : copy[state.status];
205
205
  return /* @__PURE__ */ jsxs(Attachment, {
206
+ "data-component": "upload-attachment",
206
207
  state: state.status === "cancelled" ? "idle" : state.status,
207
208
  className,
208
209
  "aria-labelledby": `${id}-name`,
@@ -229,11 +230,13 @@ var UploadAttachment = ({
229
230
  children: description
230
231
  }) : null,
231
232
  /* @__PURE__ */ jsx3("p", {
233
+ "data-slot": "upload-attachment-status",
232
234
  role: state.status === "error" ? "alert" : "status",
233
235
  className: "text-muted-foreground mt-1 text-xs",
234
236
  children: status
235
237
  }),
236
238
  state.status === "uploading" ? /* @__PURE__ */ jsx3("progress", {
239
+ "data-slot": "upload-attachment-progress",
237
240
  className: "accent-primary mt-2 h-1.5 w-full",
238
241
  "aria-label": `${copy.uploading}: ${name}`,
239
242
  max: 100,
package/dist/lib/docs.js CHANGED
@@ -1348,6 +1348,7 @@ function AppSidebar({ collapsible, footer, groups, header }) {
1348
1348
  });
1349
1349
  return /* @__PURE__ */ jsx13(SidebarMenuItem, {
1350
1350
  children: /* @__PURE__ */ jsxs10(SidebarMenuButton, {
1351
+ className: "h-auto min-h-8",
1351
1352
  onClick: closeMobileSidebar,
1352
1353
  render,
1353
1354
  tooltip: item.label(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.8.3",
3
+ "version": "0.10.0",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,6 +17,22 @@
17
17
  "type": "module",
18
18
  "sideEffects": false,
19
19
  "exports": {
20
+ "./time-picker": {
21
+ "types": "./dist/components/ui/time-picker.d.ts",
22
+ "import": "./dist/components/ui/time-picker.js"
23
+ },
24
+ "./date-picker": {
25
+ "types": "./dist/components/ui/date-picker.d.ts",
26
+ "import": "./dist/components/ui/date-picker.js"
27
+ },
28
+ "./select-with-custom-input": {
29
+ "types": "./dist/components/ui/select-with-custom-input.d.ts",
30
+ "import": "./dist/components/ui/select-with-custom-input.js"
31
+ },
32
+ "./toast": {
33
+ "types": "./dist/components/ui/toast.d.ts",
34
+ "import": "./dist/components/ui/toast.js"
35
+ },
20
36
  "./cron-expression-editor": {
21
37
  "types": "./dist/components/ui/cron-expression-editor.d.ts",
22
38
  "import": "./dist/components/ui/cron-expression-editor.js"
@@ -69,9 +85,9 @@
69
85
  "types": "./dist/components/ui/app-switcher.d.ts",
70
86
  "import": "./dist/components/ui/app-switcher.js"
71
87
  },
72
- "./copy-value": {
73
- "types": "./dist/components/ui/copy-value.d.ts",
74
- "import": "./dist/components/ui/copy-value.js"
88
+ "./secret-value": {
89
+ "types": "./dist/components/ui/secret-value.d.ts",
90
+ "import": "./dist/components/ui/secret-value.js"
75
91
  },
76
92
  "./bulk-list-input": {
77
93
  "types": "./dist/components/ui/bulk-list-input.d.ts",
@@ -379,7 +395,9 @@
379
395
  "@oxlint/plugins": "1.78.0",
380
396
  "bowser": "^2.14.1",
381
397
  "cron-parser": "^5.10.4",
398
+ "date-fns": "^4.4.0",
382
399
  "react-colorful": "^5.8.1",
400
+ "react-day-picker": "^10.0.2",
383
401
  "web-vitals": "^5.1.0"
384
402
  },
385
403
  "peerDependencies": {
@@ -402,8 +420,8 @@
402
420
  "cn": "^0.3.0",
403
421
  "drizzle-orm": "^1.0.0-rc.4-5d5b77c",
404
422
  "effect": "^4.1.0",
405
- "libphonenumber-js": "^1.13.16",
406
423
  "lucide-react": "^1.18.0",
424
+ "libphonenumber-js": "^1.13.16",
407
425
  "motion": "^14.12.0",
408
426
  "react": "^19.2.0",
409
427
  "react-dom": "^19.2.0"
@@ -1,319 +0,0 @@
1
- // ../../src/components/ui/copy-value.tsx
2
- import { Eye, EyeOff } from "lucide-react";
3
- import { useEffect as useEffect2, useState as useState2 } from "react";
4
-
5
- // ../../src/components/ui/input-group.tsx
6
- import { cva as cva2 } from "class-variance-authority";
7
-
8
- // ../../src/components/ui/button.tsx
9
- import { Button as ButtonPrimitive } from "@base-ui/react/button";
10
- import { cva } from "class-variance-authority";
11
-
12
- // ../../src/lib/utils.ts
13
- import { cn } from "cn";
14
-
15
- // ../../src/components/ui/button.tsx
16
- import { jsx } from "react/jsx-runtime";
17
- 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", {
18
- variants: {
19
- variant: {
20
- default: "bg-primary text-primary-foreground hover:bg-primary/80",
21
- 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",
22
- 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",
23
- ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
24
- 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",
25
- link: "text-primary underline-offset-4 hover:underline"
26
- },
27
- size: {
28
- 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",
29
- 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",
30
- 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",
31
- lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
32
- icon: "size-9",
33
- "icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
34
- "icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
35
- "icon-lg": "size-10"
36
- }
37
- },
38
- defaultVariants: {
39
- variant: "default",
40
- size: "default"
41
- }
42
- });
43
- function Button({
44
- className,
45
- variant = "default",
46
- size = "default",
47
- ...props
48
- }) {
49
- return /* @__PURE__ */ jsx(ButtonPrimitive, {
50
- "data-slot": "button",
51
- className: cn(buttonVariants({ variant, size, className })),
52
- ...props
53
- });
54
- }
55
-
56
- // ../../src/components/ui/input.tsx
57
- import { Input as InputPrimitive } from "@base-ui/react/input";
58
- import { jsx as jsx2 } from "react/jsx-runtime";
59
- function Input({ className, type, ...props }) {
60
- return /* @__PURE__ */ jsx2(InputPrimitive, {
61
- type,
62
- "data-slot": "input",
63
- 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),
64
- ...props
65
- });
66
- }
67
-
68
- // ../../src/components/ui/input-group.tsx
69
- import { jsx as jsx3 } from "react/jsx-runtime";
70
- function InputGroup({ className, ...props }) {
71
- return /* @__PURE__ */ jsx3("div", {
72
- "data-slot": "input-group",
73
- role: "group",
74
- className: cn("group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", className),
75
- ...props
76
- });
77
- }
78
- var inputGroupAddonVariants = cva2("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4", {
79
- variants: {
80
- align: {
81
- "inline-start": "order-first pl-2 has-[>button]:-ml-1 has-[>kbd]:ml-[-0.15rem]",
82
- "inline-end": "order-last pr-2 has-[>button]:-mr-1 has-[>kbd]:mr-[-0.15rem]",
83
- "block-start": "order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
84
- "block-end": "order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2"
85
- }
86
- },
87
- defaultVariants: { align: "inline-start" }
88
- });
89
- function InputGroupAddon({
90
- className,
91
- align = "inline-start",
92
- ...props
93
- }) {
94
- return /* @__PURE__ */ jsx3("div", {
95
- role: "group",
96
- "data-slot": "input-group-addon",
97
- "data-align": align,
98
- className: cn(inputGroupAddonVariants({ align }), className),
99
- onClick: (event) => {
100
- if (event.target instanceof HTMLElement && event.target.closest("button")) {
101
- return;
102
- }
103
- event.currentTarget.parentElement?.querySelector("input")?.focus();
104
- },
105
- ...props
106
- });
107
- }
108
- var inputGroupButtonVariants = cva2("flex items-center gap-2 text-sm shadow-none", {
109
- variants: {
110
- size: {
111
- xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
112
- sm: "",
113
- "icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
114
- "icon-sm": "size-8 p-0 has-[>svg]:p-0"
115
- }
116
- },
117
- defaultVariants: { size: "xs" }
118
- });
119
- function InputGroupButton({
120
- className,
121
- type = "button",
122
- variant = "ghost",
123
- size = "xs",
124
- ...props
125
- }) {
126
- return /* @__PURE__ */ jsx3(Button, {
127
- type,
128
- "data-size": size,
129
- variant,
130
- className: cn(inputGroupButtonVariants({ size }), className),
131
- ...props
132
- });
133
- }
134
- function InputGroupInput({
135
- className,
136
- ...props
137
- }) {
138
- return /* @__PURE__ */ jsx3(Input, {
139
- "data-slot": "input-group-control",
140
- className: cn("flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent", className),
141
- ...props
142
- });
143
- }
144
-
145
- // ../../src/components/ui/copy-button.tsx
146
- import { Check, Copy, TriangleAlert } from "lucide-react";
147
- import { useEffect, useRef, useState } from "react";
148
- import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
149
- import { jsx as jsx4, jsxs } from "react/jsx-runtime";
150
- var messages = {
151
- en: { copy: "Copy", copied: "Copied", copyFailed: "Copy failed" },
152
- fr: { copy: "Copier", copied: "Copié", copyFailed: "Échec de la copie" }
153
- };
154
- var copyButtonMessages = (locale = "en", translations) => ({
155
- ...locale.startsWith("fr") ? messages.fr : messages.en,
156
- ...translations?.[locale.split("-")[0] ?? locale],
157
- ...translations?.[locale]
158
- });
159
- function CopyButton({
160
- value,
161
- valueDescription,
162
- copyVariant = "default",
163
- locale: localeOverride,
164
- messages,
165
- onCopied,
166
- onCopyError,
167
- resetDelay = 1500,
168
- disabled,
169
- size,
170
- "aria-label": ariaLabel,
171
- ...props
172
- }) {
173
- const locale = useKrakstackLocale(localeOverride);
174
- const [copyState, setCopyState] = useState("idle");
175
- const copyTimeout = useRef(undefined);
176
- const labels = copyButtonMessages(locale, messages);
177
- const accessibleLabel = ariaLabel ?? (valueDescription ? `${labels.copy} ${valueDescription}` : labels.copy);
178
- const isLarge = copyVariant === "large";
179
- const defaultSize = copyVariant === "sm" ? "icon-xs" : isLarge ? "sm" : "icon-sm";
180
- useEffect(() => {
181
- return () => {
182
- if (copyTimeout.current)
183
- clearTimeout(copyTimeout.current);
184
- };
185
- }, []);
186
- const resetCopyState = () => {
187
- if (copyTimeout.current)
188
- clearTimeout(copyTimeout.current);
189
- copyTimeout.current = setTimeout(() => setCopyState("idle"), resetDelay);
190
- };
191
- const copy = async () => {
192
- try {
193
- await navigator.clipboard.writeText(value);
194
- setCopyState("copied");
195
- onCopied?.();
196
- } catch (error) {
197
- setCopyState("failed");
198
- onCopyError?.(error instanceof Error ? error : new Error(labels.copyFailed, { cause: error }));
199
- }
200
- resetCopyState();
201
- };
202
- const status = copyState === "copied" ? valueDescription ? `${labels.copied}: ${valueDescription}` : labels.copied : copyState === "failed" ? valueDescription ? `${labels.copyFailed}: ${valueDescription}` : labels.copyFailed : "";
203
- return /* @__PURE__ */ jsxs(Button, {
204
- "aria-label": accessibleLabel,
205
- disabled,
206
- onClick: copy,
207
- size: size ?? defaultSize,
208
- ...props,
209
- children: [
210
- /* @__PURE__ */ jsx4("span", {
211
- "aria-live": "polite",
212
- className: "sr-only",
213
- role: "status",
214
- children: status
215
- }),
216
- copyState === "copied" ? /* @__PURE__ */ jsx4(Check, {
217
- "aria-hidden": "true"
218
- }) : null,
219
- copyState === "failed" ? /* @__PURE__ */ jsx4(TriangleAlert, {
220
- "aria-hidden": "true"
221
- }) : null,
222
- copyState === "idle" ? /* @__PURE__ */ jsx4(Copy, {
223
- "aria-hidden": "true"
224
- }) : null,
225
- isLarge ? /* @__PURE__ */ jsx4("span", {
226
- children: labels.copy
227
- }) : null
228
- ]
229
- });
230
- }
231
-
232
- // ../../src/components/ui/copy-value.tsx
233
- import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
234
- import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
235
- var labels = {
236
- en: { show: "Show", hide: "Hide", hidden: "Hidden value" },
237
- fr: { show: "Afficher", hide: "Masquer", hidden: "Valeur masquée" }
238
- };
239
- var CopyValue = ({
240
- value,
241
- label,
242
- secret = false,
243
- variant = "outline",
244
- disabled,
245
- copyable = true,
246
- autoHideDelay = 0,
247
- className,
248
- locale: override,
249
- messages,
250
- copyMessages
251
- }) => {
252
- const locale = useKrakstackLocale2(override);
253
- const copy = {
254
- ...locale.startsWith("fr") ? labels.fr : labels.en,
255
- ...messages?.[locale.split("-")[0] ?? locale],
256
- ...messages?.[locale]
257
- };
258
- const [revealedValue, setRevealedValue] = useState2(null);
259
- const [previous, setPrevious] = useState2({ value, disabled, secret });
260
- if (previous.value !== value || previous.disabled !== disabled || previous.secret !== secret) {
261
- setPrevious({ value, disabled, secret });
262
- setRevealedValue(null);
263
- }
264
- const revealed = secret && !disabled && revealedValue === value;
265
- useEffect2(() => {
266
- if (!revealed || autoHideDelay <= 0)
267
- return;
268
- const timer = setTimeout(() => setRevealedValue(null), autoHideDelay);
269
- return () => clearTimeout(timer);
270
- }, [revealed, autoHideDelay, value]);
271
- return /* @__PURE__ */ jsxs2(InputGroup, {
272
- className: cn("min-w-0", variant === "ghost" && "border-0 bg-transparent shadow-none dark:bg-transparent", className),
273
- children: [
274
- /* @__PURE__ */ jsx5(InputGroupInput, {
275
- className: variant === "ghost" ? "pl-0 font-mono" : undefined,
276
- "aria-label": secret && !revealed ? `${label}: ${copy.hidden}` : label,
277
- value,
278
- type: secret && !revealed ? "password" : "text",
279
- autoComplete: secret ? "off" : undefined,
280
- readOnly: true,
281
- disabled,
282
- onFocus: (event) => event.currentTarget.select()
283
- }),
284
- /* @__PURE__ */ jsxs2(InputGroupAddon, {
285
- align: "inline-end",
286
- className: "gap-0",
287
- children: [
288
- secret ? /* @__PURE__ */ jsx5(InputGroupButton, {
289
- type: "button",
290
- size: "icon-sm",
291
- variant: "ghost",
292
- disabled,
293
- "aria-label": `${revealed ? copy.hide : copy.show} ${label}`,
294
- "aria-pressed": revealed,
295
- onClick: () => setRevealedValue(revealed ? null : value),
296
- children: revealed ? /* @__PURE__ */ jsx5(EyeOff, {
297
- "aria-hidden": "true"
298
- }) : /* @__PURE__ */ jsx5(Eye, {
299
- "aria-hidden": "true"
300
- })
301
- }) : null,
302
- copyable ? /* @__PURE__ */ jsx5(CopyButton, {
303
- type: "button",
304
- value,
305
- valueDescription: label,
306
- disabled,
307
- variant: "ghost",
308
- copyVariant: variant === "ghost" ? "default" : "large",
309
- locale,
310
- messages: copyMessages
311
- }) : null
312
- ]
313
- })
314
- ]
315
- });
316
- };
317
- export {
318
- CopyValue
319
- };