@krak-stack/registry 0.5.0 → 0.7.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.
- package/CHANGELOG.md +14 -0
- package/dist/components/ui/animated-list.d.ts +22 -0
- package/dist/components/ui/animated-list.js +219 -0
- package/dist/components/ui/animated-number.d.ts +9 -0
- package/dist/components/ui/animated-number.js +52 -0
- package/dist/components/ui/async-action-button.d.ts +16 -0
- package/dist/components/ui/async-action-button.js +147 -0
- package/dist/components/ui/auto-height.d.ts +9 -0
- package/dist/components/ui/auto-height.js +45 -0
- package/dist/components/ui/danger-confirmation.d.ts +20 -0
- package/dist/components/ui/danger-confirmation.js +394 -0
- package/dist/components/ui/editable-text.d.ts +19 -0
- package/dist/components/ui/editable-text.js +334 -0
- package/dist/components/ui/image-crop-editor.d.ts +41 -0
- package/dist/components/ui/image-crop-editor.js +408 -0
- package/dist/components/ui/presence-transition.d.ts +9 -0
- package/dist/components/ui/presence-transition.js +41 -0
- package/dist/components/ui/timezone-select.d.ts +56 -0
- package/dist/components/ui/timezone-select.js +898 -0
- package/dist/components/ui/timezone-select.schema.d.ts +9 -0
- package/dist/components/ui/unsaved-changes-guard.d.ts +15 -0
- package/dist/components/ui/unsaved-changes-guard.js +235 -0
- package/package.json +42 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @krak-stack/registry
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8d543bf: Add Image Crop Editor and Timezone Select as standalone components with English/French guides and interactive previews. Timezone Select composes the existing Virtualized Combobox with a code-only continent prop (North America by default), local times, UTC offsets and browser-time comparisons. Existing registry entries remain unchanged.
|
|
8
|
+
|
|
9
|
+
## 0.6.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 5c9f4c2: Add Async Action Button, Unsaved Changes Guard, Danger Confirmation, Editable Text, Presence Transition, Auto Height, Animated List, and Animated Number as standalone components with bilingual documentation and reduced-motion-aware previews.
|
|
14
|
+
|
|
15
|
+
Animated List includes controlled vertical drag reordering and accessible keyboard handles.
|
|
16
|
+
|
|
3
17
|
## 0.5.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type AnimatedListProps<T> = {
|
|
3
|
+
items: readonly T[];
|
|
4
|
+
getKey: (item: T) => string;
|
|
5
|
+
children: (item: T) => ReactNode;
|
|
6
|
+
duration?: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
itemClassName?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
onReorder?: (items: T[]) => void;
|
|
11
|
+
dragOverflow?: number;
|
|
12
|
+
getItemLabel?: (item: T) => string;
|
|
13
|
+
locale?: string;
|
|
14
|
+
messages?: Partial<Record<string, Partial<AnimatedListMessages>>>;
|
|
15
|
+
};
|
|
16
|
+
export type AnimatedListMessages = {
|
|
17
|
+
reorder: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
position: (label: string, position: number, total: number) => string;
|
|
20
|
+
};
|
|
21
|
+
/** Stable entity keys preserve child state across inserts and reordering. */
|
|
22
|
+
export declare const AnimatedList: <T>({ items, getKey, children, duration, className, itemClassName, label, onReorder, dragOverflow, getItemLabel, locale: override, messages, }: AnimatedListProps<T>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// ../../src/components/ui/animated-list.tsx
|
|
2
|
+
import {
|
|
3
|
+
AnimatePresence,
|
|
4
|
+
Reorder,
|
|
5
|
+
motion,
|
|
6
|
+
useDragControls,
|
|
7
|
+
useIsPresent,
|
|
8
|
+
useReducedMotion
|
|
9
|
+
} from "motion/react";
|
|
10
|
+
import { GripVertical } from "lucide-react";
|
|
11
|
+
import { useId, useRef, useState } from "react";
|
|
12
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
13
|
+
|
|
14
|
+
// ../../src/lib/utils.ts
|
|
15
|
+
import { cn } from "cn";
|
|
16
|
+
|
|
17
|
+
// ../../src/components/ui/animated-list.tsx
|
|
18
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
19
|
+
var labels = {
|
|
20
|
+
en: {
|
|
21
|
+
reorder: "Reorder",
|
|
22
|
+
instructions: "Drag to reorder, or use Arrow Up, Arrow Down, Home and End on the handle.",
|
|
23
|
+
position: (label, position, total) => `${label}, position ${position} of ${total}.`
|
|
24
|
+
},
|
|
25
|
+
fr: {
|
|
26
|
+
reorder: "Réordonner",
|
|
27
|
+
instructions: "Faites glisser pour réordonner, ou utilisez les flèches haut et bas, Début et Fin sur la poignée.",
|
|
28
|
+
position: (label, position, total) => `${label}, position ${position} sur ${total}.`
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var AnimatedList = ({
|
|
32
|
+
items,
|
|
33
|
+
getKey,
|
|
34
|
+
children,
|
|
35
|
+
duration = 180,
|
|
36
|
+
className,
|
|
37
|
+
itemClassName,
|
|
38
|
+
label,
|
|
39
|
+
onReorder,
|
|
40
|
+
dragOverflow = 12,
|
|
41
|
+
getItemLabel,
|
|
42
|
+
locale: override,
|
|
43
|
+
messages
|
|
44
|
+
}) => {
|
|
45
|
+
const locale = useKrakstackLocale(override);
|
|
46
|
+
const copy = {
|
|
47
|
+
...locale.startsWith("fr") ? labels.fr : labels.en,
|
|
48
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
49
|
+
...messages?.[locale]
|
|
50
|
+
};
|
|
51
|
+
const instructions = useId();
|
|
52
|
+
const container = useRef(null);
|
|
53
|
+
const [announcedKey, setAnnouncedKey] = useState(null);
|
|
54
|
+
const keys = items.map(getKey);
|
|
55
|
+
const announcement = items.map((item, index) => getKey(item) === announcedKey ? copy.position(getItemLabel?.(item) ?? getKey(item), index + 1, items.length) : "").join("");
|
|
56
|
+
const reorder = (nextKeys) => {
|
|
57
|
+
const order = new Map(nextKeys.map((key, index) => [key, index]));
|
|
58
|
+
onReorder?.([...items].sort((a, b) => (order.get(getKey(a)) ?? 0) - (order.get(getKey(b)) ?? 0)));
|
|
59
|
+
};
|
|
60
|
+
if (onReorder)
|
|
61
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsx(Reorder.Group, {
|
|
64
|
+
ref: container,
|
|
65
|
+
as: "ul",
|
|
66
|
+
axis: "y",
|
|
67
|
+
values: keys,
|
|
68
|
+
onReorder: reorder,
|
|
69
|
+
className: cn("grid gap-3", className),
|
|
70
|
+
"aria-label": label,
|
|
71
|
+
children: /* @__PURE__ */ jsx(AnimatePresence, {
|
|
72
|
+
initial: false,
|
|
73
|
+
children: items.map((item, index) => {
|
|
74
|
+
const key = getKey(item);
|
|
75
|
+
const itemLabel = getItemLabel?.(item) ?? key;
|
|
76
|
+
return /* @__PURE__ */ jsx(ReorderableListItem, {
|
|
77
|
+
value: key,
|
|
78
|
+
duration,
|
|
79
|
+
className: itemClassName,
|
|
80
|
+
instructions,
|
|
81
|
+
handleLabel: `${copy.reorder}: ${itemLabel}`,
|
|
82
|
+
disabled: items.length < 2,
|
|
83
|
+
constraints: container,
|
|
84
|
+
dragOverflow,
|
|
85
|
+
onMove: (direction) => {
|
|
86
|
+
const target = direction === "Home" ? 0 : direction === "End" ? items.length - 1 : Math.max(0, Math.min(items.length - 1, index + (direction === "ArrowUp" ? -1 : 1)));
|
|
87
|
+
if (index === target)
|
|
88
|
+
return;
|
|
89
|
+
const nextKeys = [...keys];
|
|
90
|
+
nextKeys.splice(index, 1);
|
|
91
|
+
nextKeys.splice(target, 0, key);
|
|
92
|
+
setAnnouncedKey(key);
|
|
93
|
+
reorder(nextKeys);
|
|
94
|
+
},
|
|
95
|
+
onDragEnd: () => setAnnouncedKey(key),
|
|
96
|
+
children: children(item)
|
|
97
|
+
}, key);
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ jsx("span", {
|
|
102
|
+
id: instructions,
|
|
103
|
+
className: "sr-only",
|
|
104
|
+
children: copy.instructions
|
|
105
|
+
}),
|
|
106
|
+
/* @__PURE__ */ jsx("span", {
|
|
107
|
+
role: "status",
|
|
108
|
+
className: "sr-only",
|
|
109
|
+
children: announcement
|
|
110
|
+
})
|
|
111
|
+
]
|
|
112
|
+
});
|
|
113
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
114
|
+
className: cn("grid gap-3", className),
|
|
115
|
+
"aria-label": label,
|
|
116
|
+
children: /* @__PURE__ */ jsx(AnimatePresence, {
|
|
117
|
+
initial: false,
|
|
118
|
+
children: items.map((item) => /* @__PURE__ */ jsx(AnimatedListItem, {
|
|
119
|
+
duration,
|
|
120
|
+
className: itemClassName,
|
|
121
|
+
children: children(item)
|
|
122
|
+
}, getKey(item)))
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
var ReorderableListItem = ({
|
|
127
|
+
children,
|
|
128
|
+
value,
|
|
129
|
+
duration,
|
|
130
|
+
className,
|
|
131
|
+
instructions,
|
|
132
|
+
handleLabel,
|
|
133
|
+
disabled,
|
|
134
|
+
constraints,
|
|
135
|
+
dragOverflow,
|
|
136
|
+
onMove,
|
|
137
|
+
onDragEnd
|
|
138
|
+
}) => {
|
|
139
|
+
const present = useIsPresent();
|
|
140
|
+
const reduced = useReducedMotion();
|
|
141
|
+
const controls = useDragControls();
|
|
142
|
+
return /* @__PURE__ */ jsxs(Reorder.Item, {
|
|
143
|
+
as: "li",
|
|
144
|
+
value,
|
|
145
|
+
dragListener: false,
|
|
146
|
+
dragControls: controls,
|
|
147
|
+
dragMomentum: false,
|
|
148
|
+
dragConstraints: constraints,
|
|
149
|
+
dragElastic: 0,
|
|
150
|
+
onMeasureDragConstraints: (bounds) => ({
|
|
151
|
+
...bounds,
|
|
152
|
+
top: bounds.top - Math.max(0, dragOverflow),
|
|
153
|
+
bottom: bounds.bottom + Math.max(0, dragOverflow)
|
|
154
|
+
}),
|
|
155
|
+
tabIndex: -1,
|
|
156
|
+
layout: "position",
|
|
157
|
+
className: cn("relative", className),
|
|
158
|
+
inert: !present,
|
|
159
|
+
"aria-hidden": !present ? true : undefined,
|
|
160
|
+
initial: { opacity: 0 },
|
|
161
|
+
animate: { opacity: 1 },
|
|
162
|
+
exit: { opacity: 0 },
|
|
163
|
+
transition: {
|
|
164
|
+
duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
|
|
165
|
+
},
|
|
166
|
+
onDragEnd,
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ jsx("button", {
|
|
169
|
+
type: "button",
|
|
170
|
+
disabled: disabled || !present,
|
|
171
|
+
"aria-label": handleLabel,
|
|
172
|
+
"aria-describedby": instructions,
|
|
173
|
+
className: "text-muted-foreground focus-visible:ring-ring inline-flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-md outline-none select-none focus-visible:ring-2 active:cursor-grabbing disabled:cursor-default disabled:opacity-50",
|
|
174
|
+
onPointerDown: (event) => {
|
|
175
|
+
if (!disabled && present)
|
|
176
|
+
controls.start(event);
|
|
177
|
+
},
|
|
178
|
+
onKeyDown: (event) => {
|
|
179
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
180
|
+
return;
|
|
181
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End") {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
onMove(event.key);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
children: /* @__PURE__ */ jsx(GripVertical, {
|
|
188
|
+
className: "size-4",
|
|
189
|
+
"aria-hidden": "true"
|
|
190
|
+
})
|
|
191
|
+
}),
|
|
192
|
+
children
|
|
193
|
+
]
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
var AnimatedListItem = ({
|
|
197
|
+
children,
|
|
198
|
+
duration,
|
|
199
|
+
className
|
|
200
|
+
}) => {
|
|
201
|
+
const present = useIsPresent();
|
|
202
|
+
const reduced = useReducedMotion();
|
|
203
|
+
return /* @__PURE__ */ jsx(motion.li, {
|
|
204
|
+
layout: reduced === false ? "position" : false,
|
|
205
|
+
className,
|
|
206
|
+
inert: !present,
|
|
207
|
+
"aria-hidden": !present ? true : undefined,
|
|
208
|
+
initial: { opacity: 0 },
|
|
209
|
+
animate: { opacity: 1 },
|
|
210
|
+
exit: { opacity: 0 },
|
|
211
|
+
transition: {
|
|
212
|
+
duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
|
|
213
|
+
},
|
|
214
|
+
children
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
export {
|
|
218
|
+
AnimatedList
|
|
219
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type AnimatedNumberProps = {
|
|
2
|
+
value: number;
|
|
3
|
+
duration?: number;
|
|
4
|
+
format?: Intl.NumberFormatOptions;
|
|
5
|
+
locale?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
/** Assistive technology receives the target, not a stream of intermediate values. */
|
|
9
|
+
export declare const AnimatedNumber: ({ value, duration, format, locale: override, className, }: AnimatedNumberProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ../../src/components/ui/animated-number.tsx
|
|
2
|
+
import {
|
|
3
|
+
animate,
|
|
4
|
+
motion,
|
|
5
|
+
useMotionValue,
|
|
6
|
+
useReducedMotion,
|
|
7
|
+
useTransform
|
|
8
|
+
} from "motion/react";
|
|
9
|
+
import { useEffect, useMemo } from "react";
|
|
10
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
var AnimatedNumber = ({
|
|
13
|
+
value,
|
|
14
|
+
duration = 350,
|
|
15
|
+
format,
|
|
16
|
+
locale: override,
|
|
17
|
+
className
|
|
18
|
+
}) => {
|
|
19
|
+
const locale = useKrakstackLocale(override);
|
|
20
|
+
const formatter = useMemo(() => new Intl.NumberFormat(locale, format), [locale, format]);
|
|
21
|
+
const displayed = useMotionValue(value);
|
|
22
|
+
const text = useTransform(() => formatter.format(displayed.get()));
|
|
23
|
+
const reduced = useReducedMotion();
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (reduced !== false || duration <= 0 || !Number.isFinite(value) || !Number.isFinite(displayed.get())) {
|
|
26
|
+
displayed.set(value);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const controls = animate(displayed, value, {
|
|
30
|
+
duration: duration / 1000,
|
|
31
|
+
ease: "easeOut"
|
|
32
|
+
});
|
|
33
|
+
return () => controls.stop();
|
|
34
|
+
}, [displayed, duration, reduced, value]);
|
|
35
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
36
|
+
"data-slot": "animated-number",
|
|
37
|
+
className,
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsx("span", {
|
|
40
|
+
className: "sr-only",
|
|
41
|
+
children: formatter.format(value)
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx(motion.span, {
|
|
44
|
+
"aria-hidden": "true",
|
|
45
|
+
children: text
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
AnimatedNumber
|
|
52
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
import { Button } from "./button.js";
|
|
3
|
+
export type AsyncActionButtonMessages = {
|
|
4
|
+
pending: string;
|
|
5
|
+
success: string;
|
|
6
|
+
retry: string;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
export type AsyncActionButtonProps = Omit<ComponentProps<typeof Button>, "onClick" | "type" | "render" | "nativeButton" | "aria-busy"> & {
|
|
10
|
+
onAction: () => Promise<void>;
|
|
11
|
+
onPendingChange?: (pending: boolean) => void;
|
|
12
|
+
locale?: string;
|
|
13
|
+
messages?: Partial<Record<string, Partial<AsyncActionButtonMessages>>>;
|
|
14
|
+
};
|
|
15
|
+
/** Runs only on activation. Failures stay local; raw error details are never rendered. */
|
|
16
|
+
export declare const AsyncActionButton: ({ onAction, onPendingChange, children, disabled, locale: override, messages, ...props }: AsyncActionButtonProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// ../../src/components/ui/async-action-button.tsx
|
|
2
|
+
import { Check, LoaderCircle, RotateCcw } from "lucide-react";
|
|
3
|
+
import { useEffect, useRef, useState } 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/async-action-button.tsx
|
|
54
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
55
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
56
|
+
var labels = {
|
|
57
|
+
en: {
|
|
58
|
+
pending: "Working…",
|
|
59
|
+
success: "Completed",
|
|
60
|
+
retry: "Try again",
|
|
61
|
+
error: "The action failed. Please try again."
|
|
62
|
+
},
|
|
63
|
+
fr: {
|
|
64
|
+
pending: "En cours…",
|
|
65
|
+
success: "Terminé",
|
|
66
|
+
retry: "Réessayer",
|
|
67
|
+
error: "L’action a échoué. Veuillez réessayer."
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var AsyncActionButton = ({
|
|
71
|
+
onAction,
|
|
72
|
+
onPendingChange,
|
|
73
|
+
children,
|
|
74
|
+
disabled,
|
|
75
|
+
locale: override,
|
|
76
|
+
messages,
|
|
77
|
+
...props
|
|
78
|
+
}) => {
|
|
79
|
+
const locale = useKrakstackLocale(override);
|
|
80
|
+
const copy = {
|
|
81
|
+
...locale.startsWith("fr") ? labels.fr : labels.en,
|
|
82
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
83
|
+
...messages?.[locale]
|
|
84
|
+
};
|
|
85
|
+
const [status, setStatus] = useState("idle");
|
|
86
|
+
const locked = useRef(false);
|
|
87
|
+
const mounted = useRef(false);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
mounted.current = true;
|
|
90
|
+
return () => {
|
|
91
|
+
mounted.current = false;
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
const run = async () => {
|
|
95
|
+
if (locked.current || disabled)
|
|
96
|
+
return;
|
|
97
|
+
locked.current = true;
|
|
98
|
+
setStatus("pending");
|
|
99
|
+
onPendingChange?.(true);
|
|
100
|
+
try {
|
|
101
|
+
await onAction();
|
|
102
|
+
if (mounted.current)
|
|
103
|
+
setStatus("success");
|
|
104
|
+
} catch {
|
|
105
|
+
if (mounted.current)
|
|
106
|
+
setStatus("error");
|
|
107
|
+
} finally {
|
|
108
|
+
locked.current = false;
|
|
109
|
+
onPendingChange?.(false);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
113
|
+
"data-slot": "async-action-button",
|
|
114
|
+
className: "inline-flex min-w-0 flex-col items-start gap-2",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
117
|
+
...props,
|
|
118
|
+
type: "button",
|
|
119
|
+
disabled: disabled || status === "pending",
|
|
120
|
+
"aria-busy": status === "pending",
|
|
121
|
+
onClick: () => {
|
|
122
|
+
run();
|
|
123
|
+
},
|
|
124
|
+
children: [
|
|
125
|
+
status === "pending" ? /* @__PURE__ */ jsx2(LoaderCircle, {
|
|
126
|
+
"aria-hidden": "true",
|
|
127
|
+
className: "motion-safe:animate-spin"
|
|
128
|
+
}) : status === "success" ? /* @__PURE__ */ jsx2(Check, {
|
|
129
|
+
"aria-hidden": "true"
|
|
130
|
+
}) : status === "error" ? /* @__PURE__ */ jsx2(RotateCcw, {
|
|
131
|
+
"aria-hidden": "true"
|
|
132
|
+
}) : null,
|
|
133
|
+
status === "pending" ? copy.pending : status === "success" ? copy.success : status === "error" ? copy.retry : children
|
|
134
|
+
]
|
|
135
|
+
}),
|
|
136
|
+
/* @__PURE__ */ jsx2("span", {
|
|
137
|
+
"data-slot": "async-action-feedback",
|
|
138
|
+
role: "status",
|
|
139
|
+
className: status === "error" ? "text-destructive text-sm" : "sr-only",
|
|
140
|
+
children: status === "error" ? copy.error : status === "success" ? copy.success : status === "pending" ? copy.pending : ""
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
export {
|
|
146
|
+
AsyncActionButton
|
|
147
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type AutoHeightProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
duration?: number;
|
|
5
|
+
className?: string;
|
|
6
|
+
contentClassName?: string;
|
|
7
|
+
};
|
|
8
|
+
/** Measures content, not the animated container. SSR and observer-less browsers stay auto-sized. */
|
|
9
|
+
export declare const AutoHeight: ({ children, duration, className, contentClassName, }: AutoHeightProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// ../../src/components/ui/auto-height.tsx
|
|
2
|
+
import { motion, useReducedMotion } from "motion/react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var AutoHeight = ({
|
|
6
|
+
children,
|
|
7
|
+
duration = 200,
|
|
8
|
+
className,
|
|
9
|
+
contentClassName
|
|
10
|
+
}) => {
|
|
11
|
+
const content = useRef(null);
|
|
12
|
+
const [height, setHeight] = useState();
|
|
13
|
+
const reduced = useReducedMotion();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const element = content.current;
|
|
16
|
+
if (!element || !globalThis.ResizeObserver)
|
|
17
|
+
return;
|
|
18
|
+
const observer = new ResizeObserver(() => {
|
|
19
|
+
if (element.getClientRects().length === 0)
|
|
20
|
+
return;
|
|
21
|
+
setHeight(element.getBoundingClientRect().height);
|
|
22
|
+
});
|
|
23
|
+
observer.observe(element);
|
|
24
|
+
return () => observer.disconnect();
|
|
25
|
+
}, []);
|
|
26
|
+
return /* @__PURE__ */ jsx(motion.div, {
|
|
27
|
+
"data-slot": "auto-height",
|
|
28
|
+
className,
|
|
29
|
+
initial: false,
|
|
30
|
+
animate: { height: height ?? "auto" },
|
|
31
|
+
transition: {
|
|
32
|
+
duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
|
|
33
|
+
},
|
|
34
|
+
style: { overflow: "clip", boxSizing: "content-box" },
|
|
35
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
36
|
+
ref: content,
|
|
37
|
+
className: contentClassName,
|
|
38
|
+
style: { display: "flow-root" },
|
|
39
|
+
children
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
AutoHeight
|
|
45
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type DangerConfirmationMessages = {
|
|
3
|
+
confirm: string;
|
|
4
|
+
cancel: string;
|
|
5
|
+
typeToConfirm: string;
|
|
6
|
+
pending: string;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
export type DangerConfirmationProps = {
|
|
10
|
+
open: boolean;
|
|
11
|
+
onOpenChange: (open: boolean) => void;
|
|
12
|
+
title: ReactNode;
|
|
13
|
+
description: ReactNode;
|
|
14
|
+
confirmation?: string;
|
|
15
|
+
onConfirm: () => Promise<void>;
|
|
16
|
+
locale?: string;
|
|
17
|
+
messages?: Partial<Record<string, Partial<DangerConfirmationMessages>>>;
|
|
18
|
+
};
|
|
19
|
+
/** Confirmation is a UI safeguard, never an authorization boundary. */
|
|
20
|
+
export declare const DangerConfirmation: (props: DangerConfirmationProps) => import("react").JSX.Element;
|