@digvation/ui 1.1.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/README.md +15 -0
- package/dist/index.cjs +4477 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +977 -0
- package/dist/index.d.ts +977 -0
- package/dist/index.js +4397 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +2 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4397 @@
|
|
|
1
|
+
// src/cn.ts
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
function cn(...inputs) {
|
|
5
|
+
return twMerge(clsx(inputs));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/alert/alert.tsx
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var alertClasses = {
|
|
11
|
+
neutral: "border-[var(--color-border)] bg-[var(--color-surface-muted)]/60 text-[var(--color-text)]",
|
|
12
|
+
info: "border-[var(--color-info)]/25 bg-[var(--color-info)]/10 text-[var(--color-text)]",
|
|
13
|
+
success: "border-[var(--color-success)]/25 bg-[var(--color-success)]/10 text-[var(--color-text)]",
|
|
14
|
+
warning: "border-[var(--color-warning)]/30 bg-[var(--color-warning)]/10 text-[var(--color-text)]",
|
|
15
|
+
danger: "border-[var(--color-danger)]/30 bg-[var(--color-danger)]/10 text-[var(--color-text)]"
|
|
16
|
+
};
|
|
17
|
+
function DAlert({ variant = "info", title, icon, className, children, ...props }) {
|
|
18
|
+
return /* @__PURE__ */ jsxs("div", { role: "alert", className: cn("flex gap-3 rounded-[var(--radius-control)] border p-3 text-sm", alertClasses[variant], className), ...props, children: [
|
|
19
|
+
icon ? /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0", children: icon }) : null,
|
|
20
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
21
|
+
title ? /* @__PURE__ */ jsx("p", { className: "font-semibold", children: title }) : null,
|
|
22
|
+
children ? /* @__PURE__ */ jsx("div", { className: title ? "mt-1 text-xs leading-5" : "text-xs leading-5", children }) : null
|
|
23
|
+
] })
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/badge/badge.tsx
|
|
28
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
29
|
+
var variantClasses = {
|
|
30
|
+
default: "bg-[var(--color-surface-muted)] text-[var(--color-text-muted)]",
|
|
31
|
+
primary: "bg-[var(--color-brand)]/10 text-[var(--color-brand)]",
|
|
32
|
+
secondary: "bg-[var(--color-text)]/7 text-[var(--color-text)]",
|
|
33
|
+
info: "bg-[var(--color-info)]/10 text-[var(--color-info)]",
|
|
34
|
+
success: "bg-[var(--color-success)]/10 text-[var(--color-success)]",
|
|
35
|
+
warning: "bg-[var(--color-warning)]/10 text-[var(--color-warning)]",
|
|
36
|
+
danger: "bg-[var(--color-danger)]/10 text-[var(--color-danger)]",
|
|
37
|
+
outline: "border border-[var(--color-border)] bg-transparent text-[var(--color-text)]"
|
|
38
|
+
};
|
|
39
|
+
function DBadge({ className, variant = "default", dot = false, dotClassName, children, ...props }) {
|
|
40
|
+
return /* @__PURE__ */ jsxs2("span", { className: cn("inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-xs font-medium", variantClasses[variant], className), ...props, children: [
|
|
41
|
+
dot ? /* @__PURE__ */ jsx2("span", { className: cn("size-1.5 rounded-full bg-current", dotClassName), "aria-hidden": "true" }) : null,
|
|
42
|
+
children
|
|
43
|
+
] });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/button/button.tsx
|
|
47
|
+
import { forwardRef } from "react";
|
|
48
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
49
|
+
var variantClasses2 = {
|
|
50
|
+
primary: "bg-[var(--color-brand)] text-[var(--color-brand-foreground)] shadow-[var(--shadow-sm)] hover:bg-[var(--color-brand-hover)] active:bg-[var(--color-brand-active)]",
|
|
51
|
+
secondary: "bg-[var(--color-secondary)] text-[var(--color-secondary-foreground)] hover:bg-[var(--color-secondary-hover)] active:bg-[var(--color-secondary-active)]",
|
|
52
|
+
outline: "border border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-text)] hover:bg-[var(--color-surface-muted)]",
|
|
53
|
+
ghost: "bg-transparent text-[var(--color-text)] hover:bg-[var(--color-surface-muted)]",
|
|
54
|
+
soft: "bg-[var(--color-brand)]/10 text-[var(--color-brand)] hover:bg-[var(--color-brand)]/15 active:bg-[var(--color-brand)]/20",
|
|
55
|
+
info: "bg-[var(--color-info)] text-white shadow-[var(--shadow-sm)] hover:brightness-95 active:brightness-90",
|
|
56
|
+
success: "bg-[var(--color-success)] text-white shadow-[var(--shadow-sm)] hover:brightness-95 active:brightness-90",
|
|
57
|
+
warning: "bg-[var(--color-warning)] text-white shadow-[var(--shadow-sm)] hover:brightness-95 active:brightness-90",
|
|
58
|
+
danger: "bg-[var(--color-danger)] text-white shadow-[var(--shadow-sm)] hover:brightness-95 active:brightness-90",
|
|
59
|
+
link: "h-auto bg-transparent px-0 text-[var(--color-brand)] underline-offset-4 hover:underline active:opacity-80"
|
|
60
|
+
};
|
|
61
|
+
var sizeClasses = {
|
|
62
|
+
sm: "h-8 gap-1.5 px-3 text-xs",
|
|
63
|
+
md: "h-10 gap-2 px-4 text-sm",
|
|
64
|
+
lg: "h-12 gap-2 px-6 text-base",
|
|
65
|
+
icon: "size-10 p-0"
|
|
66
|
+
};
|
|
67
|
+
var DButton = forwardRef(function DButton2({ className, variant = "primary", size = "md", loading = false, leftIcon, rightIcon, fullWidth = false, disabled, type = "button", children, ...props }, ref) {
|
|
68
|
+
return /* @__PURE__ */ jsxs3(
|
|
69
|
+
"button",
|
|
70
|
+
{
|
|
71
|
+
ref,
|
|
72
|
+
"data-ds-component": "button",
|
|
73
|
+
type,
|
|
74
|
+
disabled: disabled || loading,
|
|
75
|
+
"aria-busy": loading || void 0,
|
|
76
|
+
className: cn(
|
|
77
|
+
"inline-flex items-center justify-center rounded-[var(--radius-control)] font-medium transition-[background-color,color,border-color,box-shadow,transform,opacity] duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25 focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--color-background)] active:scale-[0.98] motion-reduce:transform-none disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
78
|
+
variantClasses2[variant],
|
|
79
|
+
variant !== "link" && sizeClasses[size],
|
|
80
|
+
variant === "link" && size === "sm" && "text-xs",
|
|
81
|
+
variant === "link" && size === "md" && "text-sm",
|
|
82
|
+
variant === "link" && size === "lg" && "text-base",
|
|
83
|
+
fullWidth && "w-full",
|
|
84
|
+
className
|
|
85
|
+
),
|
|
86
|
+
...props,
|
|
87
|
+
children: [
|
|
88
|
+
loading ? /* @__PURE__ */ jsx3("span", { className: "size-4 animate-spin rounded-full border-2 border-current border-t-transparent", "aria-hidden": "true" }) : leftIcon,
|
|
89
|
+
children ? /* @__PURE__ */ jsx3("span", { children }) : null,
|
|
90
|
+
!loading ? rightIcon : null
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// src/card/card.tsx
|
|
97
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
98
|
+
var variants = {
|
|
99
|
+
default: "border border-[var(--color-border)] bg-[var(--color-surface)] shadow-[var(--shadow-sm)]",
|
|
100
|
+
outlined: "border border-[var(--color-border)] bg-[var(--color-surface)]",
|
|
101
|
+
elevated: "border border-transparent bg-[var(--color-surface)] shadow-[var(--shadow-md)]",
|
|
102
|
+
interactive: "border border-[var(--color-border)] bg-[var(--color-surface)] shadow-[var(--shadow-sm)] transition-[transform,box-shadow,border-color] hover:-translate-y-0.5 hover:border-[var(--color-brand)]/30 hover:shadow-[var(--shadow-md)]"
|
|
103
|
+
};
|
|
104
|
+
function DCard({ className, variant = "default", ...props }) {
|
|
105
|
+
return /* @__PURE__ */ jsx4("section", { className: cn("rounded-[var(--radius-card)]", variants[variant], className), ...props });
|
|
106
|
+
}
|
|
107
|
+
function DCardHeader({ className, ...props }) {
|
|
108
|
+
return /* @__PURE__ */ jsx4("div", { className: cn("border-b border-[var(--color-border)] px-4 py-3", className), ...props });
|
|
109
|
+
}
|
|
110
|
+
function DCardContent({ className, ...props }) {
|
|
111
|
+
return /* @__PURE__ */ jsx4("div", { className: cn("p-4", className), ...props });
|
|
112
|
+
}
|
|
113
|
+
function DCardFooter({ className, ...props }) {
|
|
114
|
+
return /* @__PURE__ */ jsx4("div", { className: cn("border-t border-[var(--color-border)] px-4 py-3", className), ...props });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/checkbox/checkbox.tsx
|
|
118
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
119
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
120
|
+
var DCheckbox = forwardRef2(function DCheckbox2({ className, ...props }, ref) {
|
|
121
|
+
return /* @__PURE__ */ jsxs4("span", { "data-ds-component": "checkbox", className: cn("inline-flex size-4 shrink-0", className), children: [
|
|
122
|
+
/* @__PURE__ */ jsx5("input", { ref, type: "checkbox", className: "peer sr-only", ...props }),
|
|
123
|
+
/* @__PURE__ */ jsx5("span", { className: "grid size-4 place-items-center rounded-[var(--radius-control)] border border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-brand-foreground)] transition-colors peer-checked:border-[var(--color-brand)] peer-checked:bg-[var(--color-brand)] peer-checked:[&>svg]:opacity-100 peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-brand)]/20 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", children: /* @__PURE__ */ jsx5("svg", { viewBox: "0 0 12 12", className: "size-3 opacity-0", "aria-hidden": "true", children: /* @__PURE__ */ jsx5(
|
|
124
|
+
"path",
|
|
125
|
+
{
|
|
126
|
+
d: "m2 6 2.4 2.4L10 2.8",
|
|
127
|
+
fill: "none",
|
|
128
|
+
stroke: "currentColor",
|
|
129
|
+
strokeLinecap: "round",
|
|
130
|
+
strokeWidth: "1.8"
|
|
131
|
+
}
|
|
132
|
+
) }) })
|
|
133
|
+
] });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// src/combobox/combobox.tsx
|
|
137
|
+
import {
|
|
138
|
+
useEffect as useEffect2,
|
|
139
|
+
useId,
|
|
140
|
+
useMemo as useMemo3,
|
|
141
|
+
useRef as useRef3,
|
|
142
|
+
useState as useState3
|
|
143
|
+
} from "react";
|
|
144
|
+
|
|
145
|
+
// src/dropdown/dropdown.tsx
|
|
146
|
+
import {
|
|
147
|
+
useCallback as useCallback2,
|
|
148
|
+
useEffect,
|
|
149
|
+
useMemo,
|
|
150
|
+
useRef as useRef2,
|
|
151
|
+
useState as useState2
|
|
152
|
+
} from "react";
|
|
153
|
+
import { createPortal } from "react-dom";
|
|
154
|
+
|
|
155
|
+
// src/internal/floating/use-floating-position.ts
|
|
156
|
+
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
157
|
+
|
|
158
|
+
// src/internal/scroll-lock.ts
|
|
159
|
+
var lockCount = 0;
|
|
160
|
+
var restore = null;
|
|
161
|
+
function lockDocumentScroll() {
|
|
162
|
+
if (typeof document === "undefined" || typeof window === "undefined") return () => {
|
|
163
|
+
};
|
|
164
|
+
lockCount += 1;
|
|
165
|
+
if (lockCount === 1) {
|
|
166
|
+
const body = document.body;
|
|
167
|
+
const previousOverflow = body.style.overflow;
|
|
168
|
+
const previousPaddingRight = body.style.paddingRight;
|
|
169
|
+
const previousCompensation = body.style.getPropertyValue("--ds-scrollbar-compensation");
|
|
170
|
+
const computedPaddingRight = Number.parseFloat(window.getComputedStyle(body).paddingRight) || 0;
|
|
171
|
+
const scrollbarWidth = Math.max(0, window.innerWidth - document.documentElement.clientWidth);
|
|
172
|
+
body.style.overflow = "hidden";
|
|
173
|
+
body.style.setProperty("--ds-scrollbar-compensation", `${scrollbarWidth}px`);
|
|
174
|
+
if (scrollbarWidth > 0) body.style.paddingRight = `${computedPaddingRight + scrollbarWidth}px`;
|
|
175
|
+
restore = () => {
|
|
176
|
+
body.style.overflow = previousOverflow;
|
|
177
|
+
body.style.paddingRight = previousPaddingRight;
|
|
178
|
+
if (previousCompensation) body.style.setProperty("--ds-scrollbar-compensation", previousCompensation);
|
|
179
|
+
else body.style.removeProperty("--ds-scrollbar-compensation");
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
let released = false;
|
|
183
|
+
return () => {
|
|
184
|
+
if (released) return;
|
|
185
|
+
released = true;
|
|
186
|
+
lockCount = Math.max(0, lockCount - 1);
|
|
187
|
+
if (lockCount === 0) {
|
|
188
|
+
restore?.();
|
|
189
|
+
restore = null;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/internal/floating/use-floating-position.ts
|
|
195
|
+
var HIDDEN_STYLE = {
|
|
196
|
+
position: "fixed",
|
|
197
|
+
visibility: "hidden",
|
|
198
|
+
pointerEvents: "none",
|
|
199
|
+
zIndex: 9999
|
|
200
|
+
};
|
|
201
|
+
var CLIPPING_OVERFLOW = /(auto|scroll|hidden|clip)/;
|
|
202
|
+
var MIN_REFERENCE_VISIBLE_RATIO = 0.5;
|
|
203
|
+
function intersectionArea(rect, bounds) {
|
|
204
|
+
const width = Math.max(0, Math.min(rect.right, bounds.right) - Math.max(rect.left, bounds.left));
|
|
205
|
+
const height = Math.max(0, Math.min(rect.bottom, bounds.bottom) - Math.max(rect.top, bounds.top));
|
|
206
|
+
return width * height;
|
|
207
|
+
}
|
|
208
|
+
function isReferenceVisible(reference, viewportPadding) {
|
|
209
|
+
if (typeof window === "undefined" || typeof document === "undefined") return true;
|
|
210
|
+
if (!reference.isConnected) return false;
|
|
211
|
+
const referenceStyle = window.getComputedStyle(reference);
|
|
212
|
+
if (referenceStyle.display === "none" || referenceStyle.visibility === "hidden") return false;
|
|
213
|
+
const rect = reference.getBoundingClientRect();
|
|
214
|
+
if (rect.width === 0 && rect.height === 0) return true;
|
|
215
|
+
let bounds = {
|
|
216
|
+
top: viewportPadding,
|
|
217
|
+
left: viewportPadding,
|
|
218
|
+
right: window.innerWidth - viewportPadding,
|
|
219
|
+
bottom: window.innerHeight - viewportPadding
|
|
220
|
+
};
|
|
221
|
+
let ancestor = reference.parentElement;
|
|
222
|
+
while (ancestor && ancestor !== document.body && ancestor !== document.documentElement) {
|
|
223
|
+
const styles = window.getComputedStyle(ancestor);
|
|
224
|
+
const overflow = `${styles.overflow} ${styles.overflowX} ${styles.overflowY}`;
|
|
225
|
+
if (CLIPPING_OVERFLOW.test(overflow)) {
|
|
226
|
+
const ancestorRect = ancestor.getBoundingClientRect();
|
|
227
|
+
bounds = {
|
|
228
|
+
top: Math.max(bounds.top, ancestorRect.top),
|
|
229
|
+
left: Math.max(bounds.left, ancestorRect.left),
|
|
230
|
+
right: Math.min(bounds.right, ancestorRect.right),
|
|
231
|
+
bottom: Math.min(bounds.bottom, ancestorRect.bottom)
|
|
232
|
+
};
|
|
233
|
+
if (bounds.right <= bounds.left || bounds.bottom <= bounds.top) return false;
|
|
234
|
+
}
|
|
235
|
+
ancestor = ancestor.parentElement;
|
|
236
|
+
}
|
|
237
|
+
const referenceArea = Math.max(1, rect.width * rect.height);
|
|
238
|
+
return intersectionArea(rect, bounds) / referenceArea >= MIN_REFERENCE_VISIBLE_RATIO;
|
|
239
|
+
}
|
|
240
|
+
function useFloatingPosition({
|
|
241
|
+
open,
|
|
242
|
+
referenceRef,
|
|
243
|
+
floatingRef,
|
|
244
|
+
placement = "bottom-start",
|
|
245
|
+
matchWidth = false,
|
|
246
|
+
offset = 6,
|
|
247
|
+
minWidth = 140,
|
|
248
|
+
viewportPadding = 8,
|
|
249
|
+
scrollBehavior = "reposition",
|
|
250
|
+
onRequestClose
|
|
251
|
+
}) {
|
|
252
|
+
const [style, setStyle] = useState(HIDDEN_STYLE);
|
|
253
|
+
const [positioned, setPositioned] = useState(false);
|
|
254
|
+
const animationFrameRef = useRef(null);
|
|
255
|
+
const updatePosition = useCallback(() => {
|
|
256
|
+
if (typeof window === "undefined") return;
|
|
257
|
+
const reference = referenceRef.current;
|
|
258
|
+
const floating = floatingRef.current;
|
|
259
|
+
if (!reference || !floating) return;
|
|
260
|
+
if (!isReferenceVisible(reference, viewportPadding)) {
|
|
261
|
+
onRequestClose?.();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const rect = reference.getBoundingClientRect();
|
|
265
|
+
const measuredWidth = matchWidth ? rect.width : Math.max(floating.offsetWidth, minWidth);
|
|
266
|
+
const measuredHeight = floating.offsetHeight;
|
|
267
|
+
const roomBelow = Math.max(0, window.innerHeight - rect.bottom - offset - viewportPadding);
|
|
268
|
+
const roomAbove = Math.max(0, rect.top - offset - viewportPadding);
|
|
269
|
+
const wantsTop = placement.startsWith("top");
|
|
270
|
+
const alignEnd = placement.endsWith("end");
|
|
271
|
+
const placeTop = wantsTop ? roomAbove >= measuredHeight || roomAbove > roomBelow : roomBelow < measuredHeight && roomAbove > roomBelow;
|
|
272
|
+
const availableHeight = placeTop ? roomAbove : roomBelow;
|
|
273
|
+
let left = alignEnd ? rect.right - measuredWidth : rect.left;
|
|
274
|
+
left = Math.max(viewportPadding, Math.min(left, window.innerWidth - Math.min(measuredWidth, window.innerWidth - viewportPadding * 2) - viewportPadding));
|
|
275
|
+
const next = {
|
|
276
|
+
position: "fixed",
|
|
277
|
+
zIndex: 9999,
|
|
278
|
+
minWidth,
|
|
279
|
+
visibility: "visible",
|
|
280
|
+
pointerEvents: "auto",
|
|
281
|
+
left,
|
|
282
|
+
maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
|
|
283
|
+
maxHeight: Math.max(0, availableHeight),
|
|
284
|
+
overflowY: "auto",
|
|
285
|
+
overscrollBehavior: "contain",
|
|
286
|
+
...matchWidth ? { width: rect.width } : {}
|
|
287
|
+
};
|
|
288
|
+
if (placeTop) {
|
|
289
|
+
next.bottom = window.innerHeight - rect.top + offset;
|
|
290
|
+
next.top = "auto";
|
|
291
|
+
} else {
|
|
292
|
+
next.top = rect.bottom + offset;
|
|
293
|
+
next.bottom = "auto";
|
|
294
|
+
}
|
|
295
|
+
setStyle(next);
|
|
296
|
+
setPositioned(true);
|
|
297
|
+
}, [floatingRef, matchWidth, minWidth, offset, onRequestClose, placement, referenceRef, viewportPadding]);
|
|
298
|
+
const schedulePositionUpdate = useCallback(() => {
|
|
299
|
+
if (typeof window === "undefined" || animationFrameRef.current !== null) return;
|
|
300
|
+
animationFrameRef.current = window.requestAnimationFrame(() => {
|
|
301
|
+
animationFrameRef.current = null;
|
|
302
|
+
updatePosition();
|
|
303
|
+
});
|
|
304
|
+
}, [updatePosition]);
|
|
305
|
+
useLayoutEffect(() => {
|
|
306
|
+
if (!open) {
|
|
307
|
+
setPositioned(false);
|
|
308
|
+
setStyle(HIDDEN_STYLE);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
setPositioned(false);
|
|
312
|
+
setStyle(HIDDEN_STYLE);
|
|
313
|
+
updatePosition();
|
|
314
|
+
const handleResize = () => schedulePositionUpdate();
|
|
315
|
+
const handleScroll = (event) => {
|
|
316
|
+
const target = event.target;
|
|
317
|
+
if (typeof Node !== "undefined" && target instanceof Node && floatingRef.current?.contains(target)) return;
|
|
318
|
+
if (scrollBehavior === "close") {
|
|
319
|
+
onRequestClose?.();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
schedulePositionUpdate();
|
|
323
|
+
};
|
|
324
|
+
window.addEventListener("resize", handleResize);
|
|
325
|
+
window.addEventListener("scroll", handleScroll, true);
|
|
326
|
+
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(schedulePositionUpdate) : null;
|
|
327
|
+
if (observer) {
|
|
328
|
+
if (referenceRef.current) observer.observe(referenceRef.current);
|
|
329
|
+
if (floatingRef.current) observer.observe(floatingRef.current);
|
|
330
|
+
}
|
|
331
|
+
const unlock = scrollBehavior === "lock" ? lockDocumentScroll() : () => {
|
|
332
|
+
};
|
|
333
|
+
return () => {
|
|
334
|
+
window.removeEventListener("resize", handleResize);
|
|
335
|
+
window.removeEventListener("scroll", handleScroll, true);
|
|
336
|
+
observer?.disconnect();
|
|
337
|
+
unlock();
|
|
338
|
+
if (animationFrameRef.current !== null) {
|
|
339
|
+
window.cancelAnimationFrame(animationFrameRef.current);
|
|
340
|
+
animationFrameRef.current = null;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}, [floatingRef, onRequestClose, open, referenceRef, schedulePositionUpdate, scrollBehavior, updatePosition]);
|
|
344
|
+
return { style, positioned, updatePosition };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/dropdown/dropdown-context.ts
|
|
348
|
+
import { createContext, useContext } from "react";
|
|
349
|
+
var DropdownContext = createContext(null);
|
|
350
|
+
function useDropdown() {
|
|
351
|
+
const context = useContext(DropdownContext);
|
|
352
|
+
if (!context) throw new Error("useDropdown must be used inside DDropdown");
|
|
353
|
+
return context;
|
|
354
|
+
}
|
|
355
|
+
function useDropdownClose() {
|
|
356
|
+
return useContext(DropdownContext)?.close ?? null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/dropdown/dropdown.tsx
|
|
360
|
+
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
361
|
+
function DDropdown({
|
|
362
|
+
trigger,
|
|
363
|
+
children,
|
|
364
|
+
placement = "bottom-start",
|
|
365
|
+
matchWidth = false,
|
|
366
|
+
onClose,
|
|
367
|
+
closeOnItemClick = false,
|
|
368
|
+
closeOnEsc = true,
|
|
369
|
+
open: controlledOpen,
|
|
370
|
+
onOpenChange,
|
|
371
|
+
contentRole = "menu",
|
|
372
|
+
className,
|
|
373
|
+
contentClassName,
|
|
374
|
+
contentPadding = true,
|
|
375
|
+
offset = 6,
|
|
376
|
+
minWidth = 140,
|
|
377
|
+
viewportPadding = 8,
|
|
378
|
+
scrollBehavior = "reposition"
|
|
379
|
+
}) {
|
|
380
|
+
const referenceRef = useRef2(null);
|
|
381
|
+
const floatingRef = useRef2(null);
|
|
382
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState2(false);
|
|
383
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
384
|
+
const setOpen = useCallback2(
|
|
385
|
+
(next) => {
|
|
386
|
+
const resolved = typeof next === "function" ? next(open) : next;
|
|
387
|
+
if (controlledOpen === void 0) setUncontrolledOpen(resolved);
|
|
388
|
+
onOpenChange?.(resolved);
|
|
389
|
+
},
|
|
390
|
+
[controlledOpen, onOpenChange, open]
|
|
391
|
+
);
|
|
392
|
+
const close = useCallback2(() => {
|
|
393
|
+
if (!open) return;
|
|
394
|
+
setOpen(false);
|
|
395
|
+
onClose?.();
|
|
396
|
+
}, [onClose, open, setOpen]);
|
|
397
|
+
const { style, positioned } = useFloatingPosition({
|
|
398
|
+
open,
|
|
399
|
+
referenceRef,
|
|
400
|
+
floatingRef,
|
|
401
|
+
placement,
|
|
402
|
+
matchWidth,
|
|
403
|
+
offset,
|
|
404
|
+
minWidth,
|
|
405
|
+
viewportPadding,
|
|
406
|
+
scrollBehavior,
|
|
407
|
+
onRequestClose: close
|
|
408
|
+
});
|
|
409
|
+
useEffect(() => {
|
|
410
|
+
if (!open) return;
|
|
411
|
+
const outside = (event) => {
|
|
412
|
+
const target = event.target;
|
|
413
|
+
if (!referenceRef.current?.contains(target) && !floatingRef.current?.contains(target)) close();
|
|
414
|
+
};
|
|
415
|
+
const escape = (event) => {
|
|
416
|
+
if (closeOnEsc && event.key === "Escape") close();
|
|
417
|
+
};
|
|
418
|
+
document.addEventListener("mousedown", outside);
|
|
419
|
+
document.addEventListener("keydown", escape);
|
|
420
|
+
return () => {
|
|
421
|
+
document.removeEventListener("mousedown", outside);
|
|
422
|
+
document.removeEventListener("keydown", escape);
|
|
423
|
+
};
|
|
424
|
+
}, [close, closeOnEsc, open]);
|
|
425
|
+
const context = useMemo(() => ({ close, open }), [close, open]);
|
|
426
|
+
return /* @__PURE__ */ jsxs5(DropdownContext.Provider, { value: context, children: [
|
|
427
|
+
/* @__PURE__ */ jsx6(
|
|
428
|
+
"div",
|
|
429
|
+
{
|
|
430
|
+
ref: referenceRef,
|
|
431
|
+
"data-ds-component": "dropdown-trigger",
|
|
432
|
+
className: cn("inline-block", matchWidth && "w-full", className),
|
|
433
|
+
onClick: (event) => {
|
|
434
|
+
if (event.defaultPrevented) return;
|
|
435
|
+
event.stopPropagation();
|
|
436
|
+
setOpen((value) => !value);
|
|
437
|
+
},
|
|
438
|
+
onKeyDown: (event) => {
|
|
439
|
+
if (event.defaultPrevented) return;
|
|
440
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
441
|
+
const target = event.target;
|
|
442
|
+
if (target.tagName === "BUTTON" || target.tagName === "INPUT") return;
|
|
443
|
+
event.preventDefault();
|
|
444
|
+
event.stopPropagation();
|
|
445
|
+
setOpen((value) => !value);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
children: trigger({ open })
|
|
449
|
+
}
|
|
450
|
+
),
|
|
451
|
+
open && typeof document !== "undefined" ? createPortal(
|
|
452
|
+
/* @__PURE__ */ jsx6(
|
|
453
|
+
"div",
|
|
454
|
+
{
|
|
455
|
+
ref: floatingRef,
|
|
456
|
+
role: contentRole,
|
|
457
|
+
tabIndex: -1,
|
|
458
|
+
style,
|
|
459
|
+
"data-ds-component": "dropdown",
|
|
460
|
+
"data-ds-surface": "floating",
|
|
461
|
+
"data-positioned": positioned ? "true" : "false",
|
|
462
|
+
"data-scroll-behavior": scrollBehavior,
|
|
463
|
+
onClick: (event) => {
|
|
464
|
+
if (!closeOnItemClick) return;
|
|
465
|
+
const target = event.target;
|
|
466
|
+
if (target.closest("button, [role='option'], [role='menuitem'], a")) close();
|
|
467
|
+
},
|
|
468
|
+
className: cn(
|
|
469
|
+
"z-[9999] min-w-[140px] overflow-hidden rounded-[var(--radius-panel)] border border-[var(--color-border)] bg-[var(--color-surface)] shadow-[var(--shadow-lg)] outline-none",
|
|
470
|
+
contentPadding && "py-1",
|
|
471
|
+
positioned && "animate-[dropdown-in_150ms_ease-out]",
|
|
472
|
+
contentClassName
|
|
473
|
+
),
|
|
474
|
+
children
|
|
475
|
+
}
|
|
476
|
+
),
|
|
477
|
+
document.body
|
|
478
|
+
) : null
|
|
479
|
+
] });
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/localization/localization.tsx
|
|
483
|
+
import { createContext as createContext2, useContext as useContext2, useMemo as useMemo2 } from "react";
|
|
484
|
+
|
|
485
|
+
// src/localization/messages.ts
|
|
486
|
+
var idMessages = {
|
|
487
|
+
"common.apply": "Terapkan",
|
|
488
|
+
"common.cancel": "Batal",
|
|
489
|
+
"common.optional": "Opsional",
|
|
490
|
+
"common.loading": "Memuat...",
|
|
491
|
+
"common.clear": "Hapus",
|
|
492
|
+
"common.search": "Cari...",
|
|
493
|
+
"common.previousMonth": "Bulan sebelumnya",
|
|
494
|
+
"common.nextMonth": "Bulan berikutnya",
|
|
495
|
+
"common.yes": "Ya",
|
|
496
|
+
"common.no": "Tidak",
|
|
497
|
+
"input.fieldInfo": "Informasi field",
|
|
498
|
+
"input.loading": "Memuat",
|
|
499
|
+
"input.clear": "Hapus input",
|
|
500
|
+
"input.showPassword": "Tampilkan password",
|
|
501
|
+
"input.hidePassword": "Sembunyikan password",
|
|
502
|
+
"textarea.clear": "Hapus textarea",
|
|
503
|
+
"searchInput.placeholder": "Cari...",
|
|
504
|
+
"searchInput.clear": "Hapus pencarian",
|
|
505
|
+
"selectFilter.placeholder": "Pilih...",
|
|
506
|
+
"selectFilter.searchPlaceholder": "Cari...",
|
|
507
|
+
"selectFilter.clear": "Hapus filter",
|
|
508
|
+
"statusFilter.all": "Semua",
|
|
509
|
+
"dateRangeFilter.period": "Periode",
|
|
510
|
+
"dateRangeFilter.from": "Dari",
|
|
511
|
+
"dateRangeFilter.to": "Sampai",
|
|
512
|
+
"dateRangeFilter.reset": "Reset",
|
|
513
|
+
"pagination.label": "Paginasi",
|
|
514
|
+
"pagination.previous": "Halaman sebelumnya",
|
|
515
|
+
"pagination.next": "Halaman berikutnya",
|
|
516
|
+
"pagination.page": "Halaman {page}",
|
|
517
|
+
"dataTable.empty": "Tidak ada data",
|
|
518
|
+
"dataTable.searchPlaceholder": "Cari...",
|
|
519
|
+
"dataTable.toggleFilters": "Tampilkan/sembunyikan filter",
|
|
520
|
+
"dataTable.actions": "Aksi",
|
|
521
|
+
"dataTable.showing": "Menampilkan",
|
|
522
|
+
"dataTable.ofData": "dari {total} data",
|
|
523
|
+
"confirmDialog.title": "Konfirmasi",
|
|
524
|
+
"confirmDialog.message": "Apakah Anda yakin ingin melakukan aksi ini?",
|
|
525
|
+
"confirmDialog.confirm": "Ya, Lanjutkan",
|
|
526
|
+
"confirmDialog.cancel": "Batal",
|
|
527
|
+
"dialog.close": "Tutup dialog",
|
|
528
|
+
"connectionError.title": "Koneksi Gagal",
|
|
529
|
+
"connectionError.message": "Tidak dapat terhubung ke server.",
|
|
530
|
+
"connectionError.detail": "Pastikan server backend sudah berjalan dan koneksi internet Anda stabil.",
|
|
531
|
+
"connectionError.retrying": "Menghubungkan...",
|
|
532
|
+
"connectionError.retry": "Coba Lagi",
|
|
533
|
+
"loading.default": "Memuat...",
|
|
534
|
+
"notification.title": "Notifikasi",
|
|
535
|
+
"notification.empty": "Tidak ada notifikasi",
|
|
536
|
+
"notification.markAllRead": "Tandai semua sudah dibaca",
|
|
537
|
+
"notification.close": "Tutup notifikasi",
|
|
538
|
+
"notification.dismiss": "Tutup {title}",
|
|
539
|
+
"export.label": "Ekspor",
|
|
540
|
+
"export.pdf": "Ekspor PDF",
|
|
541
|
+
"export.excel": "Ekspor Excel",
|
|
542
|
+
"select.placeholder": "Pilih...",
|
|
543
|
+
"select.empty": "Tidak ditemukan",
|
|
544
|
+
"select.asyncError": "Gagal memuat pilihan",
|
|
545
|
+
"select.searchPlaceholder": "Cari...",
|
|
546
|
+
"select.loading": "Memuat...",
|
|
547
|
+
"select.clear": "Hapus pilihan",
|
|
548
|
+
"combobox.placeholder": "Ketik untuk mencari...",
|
|
549
|
+
"combobox.asyncError": "Gagal memuat pilihan",
|
|
550
|
+
"combobox.searching": "Mencari...",
|
|
551
|
+
"combobox.empty": "Tidak ditemukan",
|
|
552
|
+
"combobox.useValue": "Gunakan \u201C{value}\u201D",
|
|
553
|
+
"combobox.clear": "Hapus pilihan",
|
|
554
|
+
"datePicker.placeholder": "Pilih tanggal",
|
|
555
|
+
"datePicker.today": "Hari ini",
|
|
556
|
+
"datePicker.time": "Waktu",
|
|
557
|
+
"datePicker.selectHour": "Pilih jam",
|
|
558
|
+
"datePicker.selectHourMinute": "Pilih jam dan menit",
|
|
559
|
+
"datePicker.clear": "Hapus tanggal",
|
|
560
|
+
"timePicker.placeholder": "Pilih waktu",
|
|
561
|
+
"timePicker.title": "Pilih waktu",
|
|
562
|
+
"timePicker.hourPrecision": "Presisi jam",
|
|
563
|
+
"timePicker.hourMinutePrecision": "Presisi jam dan menit",
|
|
564
|
+
"timePicker.now": "Sekarang",
|
|
565
|
+
"timePicker.hour": "Jam",
|
|
566
|
+
"timePicker.minute": "Menit",
|
|
567
|
+
"timePicker.hourOption": "Jam {value}",
|
|
568
|
+
"timePicker.minuteOption": "Menit {value}",
|
|
569
|
+
"timePicker.clear": "Hapus waktu",
|
|
570
|
+
"rangeDatePicker.placeholder": "Pilih periode",
|
|
571
|
+
"rangeDatePicker.quickRange": "Rentang cepat",
|
|
572
|
+
"rangeDatePicker.summaryAllTime": "Semua waktu",
|
|
573
|
+
"rangeDatePicker.summarySelect": "Pilih tanggal awal dan akhir",
|
|
574
|
+
"rangeDatePicker.today": "Hari ini",
|
|
575
|
+
"rangeDatePicker.yesterday": "Kemarin",
|
|
576
|
+
"rangeDatePicker.thisWeek": "Minggu ini",
|
|
577
|
+
"rangeDatePicker.lastWeek": "Minggu lalu",
|
|
578
|
+
"rangeDatePicker.thisMonth": "Bulan ini",
|
|
579
|
+
"rangeDatePicker.lastMonth": "Bulan lalu",
|
|
580
|
+
"rangeDatePicker.thisYear": "Tahun ini",
|
|
581
|
+
"rangeDatePicker.lastYear": "Tahun lalu",
|
|
582
|
+
"rangeDatePicker.allTime": "Semua waktu",
|
|
583
|
+
"rangeDatePicker.clear": "Hapus rentang tanggal",
|
|
584
|
+
"validation.required": "{label} wajib diisi.",
|
|
585
|
+
"validation.accepted": "{label} harus disetujui.",
|
|
586
|
+
"validation.email": "{label} harus berupa email yang valid.",
|
|
587
|
+
"validation.url": "{label} harus berupa URL yang valid.",
|
|
588
|
+
"validation.minLength": "{label} minimal {min} karakter.",
|
|
589
|
+
"validation.maxLength": "{label} maksimal {max} karakter.",
|
|
590
|
+
"validation.minValue": "{label} minimal {min}.",
|
|
591
|
+
"validation.maxValue": "{label} maksimal {max}.",
|
|
592
|
+
"validation.integer": "{label} harus berupa bilangan bulat.",
|
|
593
|
+
"validation.pattern": "Format {label} tidak valid.",
|
|
594
|
+
"validation.sameAs": "{label} harus sama dengan {otherLabel}.",
|
|
595
|
+
"validation.oneOf": "{label} berisi pilihan yang tidak valid.",
|
|
596
|
+
"validation.date": "{label} harus berupa tanggal yang valid.",
|
|
597
|
+
"validation.time": "{label} harus berupa waktu yang valid.",
|
|
598
|
+
"validation.invalid": "{label} tidak valid.",
|
|
599
|
+
"validation.defaultLabel": "Field"
|
|
600
|
+
};
|
|
601
|
+
var enMessages = {
|
|
602
|
+
"common.apply": "Apply",
|
|
603
|
+
"common.cancel": "Cancel",
|
|
604
|
+
"common.optional": "Optional",
|
|
605
|
+
"common.loading": "Loading...",
|
|
606
|
+
"common.clear": "Clear",
|
|
607
|
+
"common.search": "Search...",
|
|
608
|
+
"common.previousMonth": "Previous month",
|
|
609
|
+
"common.nextMonth": "Next month",
|
|
610
|
+
"common.yes": "Yes",
|
|
611
|
+
"common.no": "No",
|
|
612
|
+
"input.fieldInfo": "Field information",
|
|
613
|
+
"input.loading": "Loading",
|
|
614
|
+
"input.clear": "Clear input",
|
|
615
|
+
"input.showPassword": "Show password",
|
|
616
|
+
"input.hidePassword": "Hide password",
|
|
617
|
+
"textarea.clear": "Clear textarea",
|
|
618
|
+
"searchInput.placeholder": "Search...",
|
|
619
|
+
"searchInput.clear": "Clear search",
|
|
620
|
+
"selectFilter.placeholder": "Select...",
|
|
621
|
+
"selectFilter.searchPlaceholder": "Search...",
|
|
622
|
+
"selectFilter.clear": "Clear filter",
|
|
623
|
+
"statusFilter.all": "All",
|
|
624
|
+
"dateRangeFilter.period": "Period",
|
|
625
|
+
"dateRangeFilter.from": "From",
|
|
626
|
+
"dateRangeFilter.to": "To",
|
|
627
|
+
"dateRangeFilter.reset": "Reset",
|
|
628
|
+
"pagination.label": "Pagination",
|
|
629
|
+
"pagination.previous": "Previous page",
|
|
630
|
+
"pagination.next": "Next page",
|
|
631
|
+
"pagination.page": "Page {page}",
|
|
632
|
+
"dataTable.empty": "No data",
|
|
633
|
+
"dataTable.searchPlaceholder": "Search...",
|
|
634
|
+
"dataTable.toggleFilters": "Toggle filters",
|
|
635
|
+
"dataTable.actions": "Actions",
|
|
636
|
+
"dataTable.showing": "Showing",
|
|
637
|
+
"dataTable.ofData": "of {total} data",
|
|
638
|
+
"confirmDialog.title": "Confirmation",
|
|
639
|
+
"confirmDialog.message": "Are you sure you want to continue with this action?",
|
|
640
|
+
"confirmDialog.confirm": "Yes, Continue",
|
|
641
|
+
"confirmDialog.cancel": "Cancel",
|
|
642
|
+
"dialog.close": "Close dialog",
|
|
643
|
+
"connectionError.title": "Connection Failed",
|
|
644
|
+
"connectionError.message": "Unable to connect to the server.",
|
|
645
|
+
"connectionError.detail": "Make sure the backend server is running and your internet connection is stable.",
|
|
646
|
+
"connectionError.retrying": "Connecting...",
|
|
647
|
+
"connectionError.retry": "Try Again",
|
|
648
|
+
"loading.default": "Loading...",
|
|
649
|
+
"notification.title": "Notifications",
|
|
650
|
+
"notification.empty": "No notifications",
|
|
651
|
+
"notification.markAllRead": "Mark all read",
|
|
652
|
+
"notification.close": "Close notifications",
|
|
653
|
+
"notification.dismiss": "Dismiss {title}",
|
|
654
|
+
"export.label": "Export",
|
|
655
|
+
"export.pdf": "Export PDF",
|
|
656
|
+
"export.excel": "Export Excel",
|
|
657
|
+
"select.placeholder": "Select...",
|
|
658
|
+
"select.empty": "No results found",
|
|
659
|
+
"select.asyncError": "Failed to load options",
|
|
660
|
+
"select.searchPlaceholder": "Search...",
|
|
661
|
+
"select.loading": "Loading...",
|
|
662
|
+
"select.clear": "Clear selection",
|
|
663
|
+
"combobox.placeholder": "Type to search...",
|
|
664
|
+
"combobox.asyncError": "Failed to load options",
|
|
665
|
+
"combobox.searching": "Searching...",
|
|
666
|
+
"combobox.empty": "No results found",
|
|
667
|
+
"combobox.useValue": "Use \u201C{value}\u201D",
|
|
668
|
+
"combobox.clear": "Clear selection",
|
|
669
|
+
"datePicker.placeholder": "Select date",
|
|
670
|
+
"datePicker.today": "Today",
|
|
671
|
+
"datePicker.time": "Time",
|
|
672
|
+
"datePicker.selectHour": "Select hour",
|
|
673
|
+
"datePicker.selectHourMinute": "Select hour and minute",
|
|
674
|
+
"datePicker.clear": "Clear date",
|
|
675
|
+
"timePicker.placeholder": "Select time",
|
|
676
|
+
"timePicker.title": "Select time",
|
|
677
|
+
"timePicker.hourPrecision": "Hour precision",
|
|
678
|
+
"timePicker.hourMinutePrecision": "Hour and minute precision",
|
|
679
|
+
"timePicker.now": "Now",
|
|
680
|
+
"timePicker.hour": "Hour",
|
|
681
|
+
"timePicker.minute": "Minute",
|
|
682
|
+
"timePicker.hourOption": "Hour {value}",
|
|
683
|
+
"timePicker.minuteOption": "Minute {value}",
|
|
684
|
+
"timePicker.clear": "Clear time",
|
|
685
|
+
"rangeDatePicker.placeholder": "Select period",
|
|
686
|
+
"rangeDatePicker.quickRange": "Quick range",
|
|
687
|
+
"rangeDatePicker.summaryAllTime": "All time",
|
|
688
|
+
"rangeDatePicker.summarySelect": "Select start and end dates",
|
|
689
|
+
"rangeDatePicker.today": "Today",
|
|
690
|
+
"rangeDatePicker.yesterday": "Yesterday",
|
|
691
|
+
"rangeDatePicker.thisWeek": "This week",
|
|
692
|
+
"rangeDatePicker.lastWeek": "Last week",
|
|
693
|
+
"rangeDatePicker.thisMonth": "This month",
|
|
694
|
+
"rangeDatePicker.lastMonth": "Last month",
|
|
695
|
+
"rangeDatePicker.thisYear": "This year",
|
|
696
|
+
"rangeDatePicker.lastYear": "Last year",
|
|
697
|
+
"rangeDatePicker.allTime": "All time",
|
|
698
|
+
"rangeDatePicker.clear": "Clear date range",
|
|
699
|
+
"validation.required": "{label} is required.",
|
|
700
|
+
"validation.accepted": "{label} must be accepted.",
|
|
701
|
+
"validation.email": "{label} must be a valid email.",
|
|
702
|
+
"validation.url": "{label} must be a valid URL.",
|
|
703
|
+
"validation.minLength": "{label} must be at least {min} characters.",
|
|
704
|
+
"validation.maxLength": "{label} must be at most {max} characters.",
|
|
705
|
+
"validation.minValue": "{label} must be at least {min}.",
|
|
706
|
+
"validation.maxValue": "{label} must be at most {max}.",
|
|
707
|
+
"validation.integer": "{label} must be an integer.",
|
|
708
|
+
"validation.pattern": "{label} has an invalid format.",
|
|
709
|
+
"validation.sameAs": "{label} must match {otherLabel}.",
|
|
710
|
+
"validation.oneOf": "{label} contains an invalid option.",
|
|
711
|
+
"validation.date": "{label} must be a valid date.",
|
|
712
|
+
"validation.time": "{label} must be a valid time.",
|
|
713
|
+
"validation.invalid": "{label} is invalid.",
|
|
714
|
+
"validation.defaultLabel": "Field"
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// src/localization/localization.tsx
|
|
718
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
719
|
+
function interpolate(template, params) {
|
|
720
|
+
return template.replace(/\{([^}]+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
|
|
721
|
+
}
|
|
722
|
+
function builtInMessages(locale) {
|
|
723
|
+
return locale.toLowerCase().startsWith("en") ? enMessages : idMessages;
|
|
724
|
+
}
|
|
725
|
+
function createDTranslator({
|
|
726
|
+
locale = "id-ID",
|
|
727
|
+
messages,
|
|
728
|
+
translate
|
|
729
|
+
} = {}) {
|
|
730
|
+
const builtIn = builtInMessages(locale);
|
|
731
|
+
return (key, params = {}, explicitFallback) => {
|
|
732
|
+
const fallback = explicitFallback ?? builtIn[key] ?? idMessages[key] ?? key;
|
|
733
|
+
const projectValue = translate?.(key, params, fallback);
|
|
734
|
+
const template = projectValue ?? messages?.[key] ?? builtIn[key] ?? idMessages[key] ?? fallback;
|
|
735
|
+
return interpolate(template, params);
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
var defaultContext = {
|
|
739
|
+
locale: "id-ID",
|
|
740
|
+
t: createDTranslator()
|
|
741
|
+
};
|
|
742
|
+
var LocalizationContext = createContext2(defaultContext);
|
|
743
|
+
function DLocalizationProvider({
|
|
744
|
+
children,
|
|
745
|
+
locale = "id-ID",
|
|
746
|
+
messages,
|
|
747
|
+
translate
|
|
748
|
+
}) {
|
|
749
|
+
const value = useMemo2(() => ({
|
|
750
|
+
locale,
|
|
751
|
+
t: createDTranslator({ locale, messages, translate })
|
|
752
|
+
}), [locale, messages, translate]);
|
|
753
|
+
return /* @__PURE__ */ jsx7(LocalizationContext.Provider, { value, children });
|
|
754
|
+
}
|
|
755
|
+
function useDLocalization() {
|
|
756
|
+
return useContext2(LocalizationContext);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/localization/date-time.ts
|
|
760
|
+
function getLocalizedMonthNames(locale, format = "long") {
|
|
761
|
+
const formatter = new Intl.DateTimeFormat(locale, { month: format });
|
|
762
|
+
return Array.from({ length: 12 }, (_, month) => formatter.format(new Date(2026, month, 1)));
|
|
763
|
+
}
|
|
764
|
+
function getLocalizedWeekdayNames(locale, format = "short") {
|
|
765
|
+
const formatter = new Intl.DateTimeFormat(locale, { weekday: format });
|
|
766
|
+
const sunday = new Date(2026, 0, 4);
|
|
767
|
+
return Array.from({ length: 7 }, (_, day) => {
|
|
768
|
+
const date2 = new Date(sunday);
|
|
769
|
+
date2.setDate(sunday.getDate() + day);
|
|
770
|
+
return formatter.format(date2);
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/shared/field-size.ts
|
|
775
|
+
var INPUT_SIZE_STYLES = {
|
|
776
|
+
sm: {
|
|
777
|
+
input: "box-border h-8 px-2 text-xs [font-family:var(--font-sans)]",
|
|
778
|
+
label: "text-xs",
|
|
779
|
+
icon: "size-3.5",
|
|
780
|
+
iconLeft: "left-2.5 size-3.5",
|
|
781
|
+
iconRight: "right-2",
|
|
782
|
+
clear: "right-1.5"
|
|
783
|
+
},
|
|
784
|
+
md: {
|
|
785
|
+
input: "box-border h-10 px-3 text-sm [font-family:var(--font-sans)]",
|
|
786
|
+
label: "text-sm",
|
|
787
|
+
icon: "size-4",
|
|
788
|
+
iconLeft: "left-3 size-4",
|
|
789
|
+
iconRight: "right-2.5",
|
|
790
|
+
clear: "right-2"
|
|
791
|
+
},
|
|
792
|
+
lg: {
|
|
793
|
+
input: "box-border h-12 px-4 text-base [font-family:var(--font-sans)]",
|
|
794
|
+
label: "text-base",
|
|
795
|
+
icon: "size-4",
|
|
796
|
+
iconLeft: "left-3.5 size-4",
|
|
797
|
+
iconRight: "right-3",
|
|
798
|
+
clear: "right-2.5"
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
// src/combobox/combobox.tsx
|
|
803
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
804
|
+
function SearchIcon({ className }) {
|
|
805
|
+
return /* @__PURE__ */ jsxs6("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className, children: [
|
|
806
|
+
/* @__PURE__ */ jsx8("circle", { cx: "11", cy: "11", r: "7" }),
|
|
807
|
+
/* @__PURE__ */ jsx8("path", { d: "m20 20-4-4" })
|
|
808
|
+
] });
|
|
809
|
+
}
|
|
810
|
+
function ClearIcon() {
|
|
811
|
+
return /* @__PURE__ */ jsx8("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx8("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
812
|
+
}
|
|
813
|
+
function sameValue(left, right) {
|
|
814
|
+
return String(left ?? "") === String(right ?? "");
|
|
815
|
+
}
|
|
816
|
+
function DCombobox({
|
|
817
|
+
label,
|
|
818
|
+
placeholder,
|
|
819
|
+
options = [],
|
|
820
|
+
value,
|
|
821
|
+
size = "md",
|
|
822
|
+
onChange,
|
|
823
|
+
fetchOptions,
|
|
824
|
+
refetchKey,
|
|
825
|
+
onFetchError,
|
|
826
|
+
asyncErrorMessage,
|
|
827
|
+
error,
|
|
828
|
+
hint,
|
|
829
|
+
disabled = false,
|
|
830
|
+
clearable = true,
|
|
831
|
+
containerClassName,
|
|
832
|
+
allowCreate = false,
|
|
833
|
+
onCreateOption,
|
|
834
|
+
renderEmpty,
|
|
835
|
+
renderCreateOption,
|
|
836
|
+
renderOption,
|
|
837
|
+
onSearchChange,
|
|
838
|
+
loading = false,
|
|
839
|
+
idleMessage,
|
|
840
|
+
ariaLabel,
|
|
841
|
+
debounceMs = 300,
|
|
842
|
+
scrollBehavior = "reposition"
|
|
843
|
+
}) {
|
|
844
|
+
const id = useId();
|
|
845
|
+
const { t } = useDLocalization();
|
|
846
|
+
const inputRef = useRef3(null);
|
|
847
|
+
const searchRequestIdRef = useRef3(0);
|
|
848
|
+
const resolveRequestIdRef = useRef3(0);
|
|
849
|
+
const [open, setOpen] = useState3(false);
|
|
850
|
+
const [inputValue, setInputValue] = useState3("");
|
|
851
|
+
const [activeIndex, setActiveIndex] = useState3(0);
|
|
852
|
+
const [asyncOptions, setAsyncOptions] = useState3([]);
|
|
853
|
+
const [isFetching, setFetching] = useState3(false);
|
|
854
|
+
const [fetchError, setFetchError] = useState3(null);
|
|
855
|
+
const [resolvedSelection, setResolvedSelection] = useState3(null);
|
|
856
|
+
const s = INPUT_SIZE_STYLES[size];
|
|
857
|
+
const isAsync = Boolean(fetchOptions);
|
|
858
|
+
const resolvedPlaceholder = placeholder ?? t("combobox.placeholder");
|
|
859
|
+
const resolvedAsyncErrorMessage = asyncErrorMessage ?? t("combobox.asyncError");
|
|
860
|
+
useEffect2(() => {
|
|
861
|
+
if (!fetchOptions || !open) return;
|
|
862
|
+
const requestId = ++searchRequestIdRef.current;
|
|
863
|
+
const timeout = window.setTimeout(() => {
|
|
864
|
+
setFetching(true);
|
|
865
|
+
setFetchError(null);
|
|
866
|
+
void fetchOptions(inputValue).then((result) => {
|
|
867
|
+
if (requestId === searchRequestIdRef.current) setAsyncOptions(result);
|
|
868
|
+
}).catch((nextError) => {
|
|
869
|
+
if (requestId !== searchRequestIdRef.current) return;
|
|
870
|
+
setFetchError(nextError);
|
|
871
|
+
onFetchError?.(nextError);
|
|
872
|
+
}).finally(() => {
|
|
873
|
+
if (requestId === searchRequestIdRef.current) setFetching(false);
|
|
874
|
+
});
|
|
875
|
+
}, debounceMs);
|
|
876
|
+
return () => window.clearTimeout(timeout);
|
|
877
|
+
}, [debounceMs, fetchOptions, inputValue, onFetchError, open, refetchKey]);
|
|
878
|
+
useEffect2(() => {
|
|
879
|
+
if (!fetchOptions || value == null || value === "" || sameValue(resolvedSelection?.value, value)) return;
|
|
880
|
+
const requestId = ++resolveRequestIdRef.current;
|
|
881
|
+
void fetchOptions("").then((result) => {
|
|
882
|
+
if (requestId !== resolveRequestIdRef.current) return;
|
|
883
|
+
const found = result.find((option) => sameValue(option.value, value));
|
|
884
|
+
setResolvedSelection(found ?? null);
|
|
885
|
+
}).catch((nextError) => onFetchError?.(nextError));
|
|
886
|
+
}, [fetchOptions, onFetchError, refetchKey, resolvedSelection?.value, value]);
|
|
887
|
+
const selectedOption = options.find((option) => sameValue(option.value, value)) ?? (sameValue(resolvedSelection?.value, value) ? resolvedSelection : null);
|
|
888
|
+
const source = isAsync ? asyncOptions : options;
|
|
889
|
+
const filtered = useMemo3(
|
|
890
|
+
() => isAsync ? source : source.filter((option) => String(option.label).toLocaleLowerCase().includes(inputValue.toLocaleLowerCase())),
|
|
891
|
+
[inputValue, isAsync, source]
|
|
892
|
+
);
|
|
893
|
+
useEffect2(() => {
|
|
894
|
+
if (!open || inputValue) return;
|
|
895
|
+
const selectedIndex = filtered.findIndex((option) => sameValue(option.value, value));
|
|
896
|
+
setActiveIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
|
897
|
+
}, [filtered, inputValue, open, value]);
|
|
898
|
+
const choose = (option) => {
|
|
899
|
+
if (option.disabled) return;
|
|
900
|
+
setResolvedSelection(option);
|
|
901
|
+
onChange?.(option.value);
|
|
902
|
+
setOpen(false);
|
|
903
|
+
setInputValue("");
|
|
904
|
+
};
|
|
905
|
+
const clear = () => {
|
|
906
|
+
onChange?.(null);
|
|
907
|
+
setResolvedSelection(null);
|
|
908
|
+
setInputValue("");
|
|
909
|
+
setOpen(false);
|
|
910
|
+
};
|
|
911
|
+
const create = () => {
|
|
912
|
+
const next = inputValue.trim();
|
|
913
|
+
if (!next) return;
|
|
914
|
+
onCreateOption?.(next);
|
|
915
|
+
onChange?.(next);
|
|
916
|
+
setResolvedSelection({ label: next, value: next });
|
|
917
|
+
setOpen(false);
|
|
918
|
+
setInputValue("");
|
|
919
|
+
};
|
|
920
|
+
const handleKeyDown = (event) => {
|
|
921
|
+
if (event.key === "Escape") {
|
|
922
|
+
setOpen(false);
|
|
923
|
+
setInputValue("");
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
927
|
+
event.preventDefault();
|
|
928
|
+
setOpen(true);
|
|
929
|
+
setActiveIndex((current) => {
|
|
930
|
+
const count = filtered.length || 1;
|
|
931
|
+
return event.key === "ArrowDown" ? (current + 1) % count : (current - 1 + count) % count;
|
|
932
|
+
});
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (event.key === "Home" && open) {
|
|
936
|
+
event.preventDefault();
|
|
937
|
+
setActiveIndex(0);
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
if (event.key === "End" && open) {
|
|
941
|
+
event.preventDefault();
|
|
942
|
+
setActiveIndex(Math.max(0, filtered.length - 1));
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (event.key === "Enter" && open) {
|
|
946
|
+
const active = filtered[activeIndex];
|
|
947
|
+
if (active && !active.disabled) {
|
|
948
|
+
event.preventDefault();
|
|
949
|
+
choose(active);
|
|
950
|
+
} else if (allowCreate && inputValue.trim()) {
|
|
951
|
+
event.preventDefault();
|
|
952
|
+
create();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
const showIdle = Boolean(idleMessage && !inputValue && !isAsync);
|
|
957
|
+
return /* @__PURE__ */ jsxs6("div", { className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
958
|
+
label ? /* @__PURE__ */ jsx8("label", { htmlFor: id, className: cn(s.label, "w-fit font-medium text-[var(--color-text)]"), children: label }) : null,
|
|
959
|
+
/* @__PURE__ */ jsx8(DDropdown, { matchWidth: true, open, onOpenChange: setOpen, contentRole: "listbox", contentPadding: false, contentClassName: "max-h-60 overflow-y-auto p-1.5", scrollBehavior, onClose: () => {
|
|
960
|
+
setOpen(false);
|
|
961
|
+
setInputValue("");
|
|
962
|
+
}, trigger: () => /* @__PURE__ */ jsxs6("div", { className: "relative", children: [
|
|
963
|
+
/* @__PURE__ */ jsx8(SearchIcon, { className: cn("pointer-events-none absolute top-1/2 -translate-y-1/2 text-[var(--color-text-muted)]", s.iconLeft) }),
|
|
964
|
+
/* @__PURE__ */ jsx8(
|
|
965
|
+
"input",
|
|
966
|
+
{
|
|
967
|
+
ref: inputRef,
|
|
968
|
+
id,
|
|
969
|
+
"aria-label": ariaLabel,
|
|
970
|
+
role: "combobox",
|
|
971
|
+
"aria-autocomplete": "list",
|
|
972
|
+
"aria-expanded": open,
|
|
973
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
974
|
+
"aria-controls": `${id}-listbox`,
|
|
975
|
+
"aria-activedescendant": open && filtered[activeIndex] ? `${id}-option-${activeIndex}` : void 0,
|
|
976
|
+
autoComplete: "off",
|
|
977
|
+
type: "text",
|
|
978
|
+
disabled,
|
|
979
|
+
value: open ? inputValue : String(selectedOption?.label ?? ""),
|
|
980
|
+
placeholder: selectedOption ? String(selectedOption.label) : resolvedPlaceholder,
|
|
981
|
+
onClick: (event) => event.stopPropagation(),
|
|
982
|
+
onFocus: () => {
|
|
983
|
+
setOpen(true);
|
|
984
|
+
const selectedIndex = filtered.findIndex((option) => sameValue(option.value, value));
|
|
985
|
+
setActiveIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
|
986
|
+
},
|
|
987
|
+
onChange: (event) => {
|
|
988
|
+
const next = event.target.value;
|
|
989
|
+
setInputValue(next);
|
|
990
|
+
onSearchChange?.(next);
|
|
991
|
+
setOpen(true);
|
|
992
|
+
setActiveIndex(0);
|
|
993
|
+
},
|
|
994
|
+
onKeyDown: handleKeyDown,
|
|
995
|
+
className: cn("w-full rounded-lg border bg-[var(--color-surface)] text-[var(--color-text)] focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50", s.input, "pl-10 pr-10", error ? "border-[var(--color-danger)] focus:ring-[var(--color-danger)]/20" : "border-[var(--color-border)]")
|
|
996
|
+
}
|
|
997
|
+
),
|
|
998
|
+
clearable && selectedOption && !disabled ? /* @__PURE__ */ jsx8("button", { type: "button", tabIndex: -1, "aria-label": t("combobox.clear"), onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
999
|
+
event.preventDefault();
|
|
1000
|
+
event.stopPropagation();
|
|
1001
|
+
clear();
|
|
1002
|
+
}, className: cn("absolute top-1/2 -translate-y-1/2 rounded-md p-1 text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]", s.clear), children: /* @__PURE__ */ jsx8(ClearIcon, {}) }) : null
|
|
1003
|
+
] }), children: /* @__PURE__ */ jsx8("div", { id: `${id}-listbox`, className: "space-y-0.5", children: loading || isFetching ? /* @__PURE__ */ jsx8("div", { className: "px-3 py-6 text-center text-sm text-[var(--color-text-muted)]", children: t("combobox.searching") }) : fetchError ? /* @__PURE__ */ jsx8("div", { className: "px-3 py-6 text-center text-sm text-[var(--color-danger)]", children: resolvedAsyncErrorMessage }) : showIdle ? /* @__PURE__ */ jsx8("div", { className: "px-3 py-6 text-center text-sm text-[var(--color-text-muted)]", children: idleMessage }) : filtered.length === 0 ? renderEmpty ? renderEmpty(inputValue) : allowCreate && inputValue.trim() ? renderCreateOption ? renderCreateOption(inputValue, create) : /* @__PURE__ */ jsx8("button", { type: "button", onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
1004
|
+
event.stopPropagation();
|
|
1005
|
+
create();
|
|
1006
|
+
}, className: "w-full rounded-lg px-3 py-2 text-left text-sm font-medium text-[var(--color-brand)] hover:bg-[var(--color-surface-muted)]", children: t("combobox.useValue", { value: inputValue.trim() }) }) : /* @__PURE__ */ jsx8("div", { className: "px-3 py-6 text-center text-sm text-[var(--color-text-muted)]", children: t("combobox.empty") }) : filtered.map((option, index) => {
|
|
1007
|
+
const isSelected = sameValue(option.value, value);
|
|
1008
|
+
return /* @__PURE__ */ jsx8("button", { id: `${id}-option-${index}`, type: "button", role: "option", "aria-selected": isSelected, disabled: option.disabled, onMouseEnter: () => setActiveIndex(index), onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
1009
|
+
event.stopPropagation();
|
|
1010
|
+
choose(option);
|
|
1011
|
+
}, className: cn("w-full rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-[var(--color-surface-muted)] disabled:cursor-not-allowed disabled:opacity-50", isSelected && "bg-[var(--color-brand)]/10 font-medium text-[var(--color-brand)]", index === activeIndex && !isSelected && "bg-[var(--color-surface-muted)]"), children: renderOption ? renderOption(option, isSelected) : option.label }, String(option.value));
|
|
1012
|
+
}) }) }),
|
|
1013
|
+
error ? /* @__PURE__ */ jsx8("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
1014
|
+
!error && hint ? /* @__PURE__ */ jsx8("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
1015
|
+
] });
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// src/dialog/dialog.tsx
|
|
1019
|
+
import { useEffect as useEffect3, useLayoutEffect as useLayoutEffect2, useRef as useRef4, useState as useState4 } from "react";
|
|
1020
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
1021
|
+
|
|
1022
|
+
// src/internal/icons.tsx
|
|
1023
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1024
|
+
function baseProps(size, className) {
|
|
1025
|
+
return {
|
|
1026
|
+
viewBox: "0 0 24 24",
|
|
1027
|
+
fill: "none",
|
|
1028
|
+
stroke: "currentColor",
|
|
1029
|
+
strokeWidth: 2,
|
|
1030
|
+
strokeLinecap: "round",
|
|
1031
|
+
strokeLinejoin: "round",
|
|
1032
|
+
width: size,
|
|
1033
|
+
height: size,
|
|
1034
|
+
className,
|
|
1035
|
+
"aria-hidden": true
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
function ChevronDownIcon({ size = 16, className, ...props }) {
|
|
1039
|
+
return /* @__PURE__ */ jsx9("svg", { ...baseProps(size, className), ...props, children: /* @__PURE__ */ jsx9("path", { d: "m6 9 6 6 6-6" }) });
|
|
1040
|
+
}
|
|
1041
|
+
function ChevronLeftIcon({ size = 16, className, ...props }) {
|
|
1042
|
+
return /* @__PURE__ */ jsx9("svg", { ...baseProps(size, className), ...props, children: /* @__PURE__ */ jsx9("path", { d: "m15 18-6-6 6-6" }) });
|
|
1043
|
+
}
|
|
1044
|
+
function ChevronRightIcon({ size = 16, className, ...props }) {
|
|
1045
|
+
return /* @__PURE__ */ jsx9("svg", { ...baseProps(size, className), ...props, children: /* @__PURE__ */ jsx9("path", { d: "m9 18 6-6-6-6" }) });
|
|
1046
|
+
}
|
|
1047
|
+
function ArrowUpIcon({ size = 14, className, ...props }) {
|
|
1048
|
+
return /* @__PURE__ */ jsxs7("svg", { ...baseProps(size, className), ...props, children: [
|
|
1049
|
+
/* @__PURE__ */ jsx9("path", { d: "m18 15-6-6-6 6" }),
|
|
1050
|
+
/* @__PURE__ */ jsx9("path", { d: "M12 21V9" })
|
|
1051
|
+
] });
|
|
1052
|
+
}
|
|
1053
|
+
function ArrowDownIcon({ size = 14, className, ...props }) {
|
|
1054
|
+
return /* @__PURE__ */ jsxs7("svg", { ...baseProps(size, className), ...props, children: [
|
|
1055
|
+
/* @__PURE__ */ jsx9("path", { d: "m6 9 6 6 6-6" }),
|
|
1056
|
+
/* @__PURE__ */ jsx9("path", { d: "M12 3v12" })
|
|
1057
|
+
] });
|
|
1058
|
+
}
|
|
1059
|
+
function MoreHorizontalIcon({ size = 18, className, ...props }) {
|
|
1060
|
+
return /* @__PURE__ */ jsxs7("svg", { ...baseProps(size, className), ...props, children: [
|
|
1061
|
+
/* @__PURE__ */ jsx9("circle", { cx: "5", cy: "12", r: "1", fill: "currentColor", stroke: "none" }),
|
|
1062
|
+
/* @__PURE__ */ jsx9("circle", { cx: "12", cy: "12", r: "1", fill: "currentColor", stroke: "none" }),
|
|
1063
|
+
/* @__PURE__ */ jsx9("circle", { cx: "19", cy: "12", r: "1", fill: "currentColor", stroke: "none" })
|
|
1064
|
+
] });
|
|
1065
|
+
}
|
|
1066
|
+
function XIcon({ size = 18, className, ...props }) {
|
|
1067
|
+
return /* @__PURE__ */ jsx9("svg", { ...baseProps(size, className), ...props, children: /* @__PURE__ */ jsx9("path", { d: "M18 6 6 18M6 6l12 12" }) });
|
|
1068
|
+
}
|
|
1069
|
+
function CheckIcon({ size = 16, className, ...props }) {
|
|
1070
|
+
return /* @__PURE__ */ jsx9("svg", { ...baseProps(size, className), ...props, children: /* @__PURE__ */ jsx9("path", { d: "m5 12 4 4L19 6" }) });
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// src/dialog/dialog.tsx
|
|
1074
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1075
|
+
var FOCUSABLE_SELECTOR = [
|
|
1076
|
+
"a[href]",
|
|
1077
|
+
"button:not([disabled])",
|
|
1078
|
+
"input:not([disabled])",
|
|
1079
|
+
"select:not([disabled])",
|
|
1080
|
+
"textarea:not([disabled])",
|
|
1081
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
1082
|
+
].join(",");
|
|
1083
|
+
function getFocusableElements(container) {
|
|
1084
|
+
return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter(
|
|
1085
|
+
(element) => !element.hasAttribute("hidden") && element.getAttribute("aria-hidden") !== "true"
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
function DialogRoot({
|
|
1089
|
+
open,
|
|
1090
|
+
onClose,
|
|
1091
|
+
children,
|
|
1092
|
+
ariaLabel,
|
|
1093
|
+
ariaLabelledBy,
|
|
1094
|
+
className,
|
|
1095
|
+
overlayClassName,
|
|
1096
|
+
closeOnOverlay = false,
|
|
1097
|
+
closeOnEscape = false
|
|
1098
|
+
}) {
|
|
1099
|
+
const dialogRef = useRef4(null);
|
|
1100
|
+
const previousActiveRef = useRef4(null);
|
|
1101
|
+
const [mounted, setMounted] = useState4(open);
|
|
1102
|
+
useEffect3(() => {
|
|
1103
|
+
if (open) {
|
|
1104
|
+
setMounted(true);
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
const timer = window.setTimeout(() => setMounted(false), 220);
|
|
1108
|
+
return () => window.clearTimeout(timer);
|
|
1109
|
+
}, [open]);
|
|
1110
|
+
useEffect3(() => {
|
|
1111
|
+
if (!mounted) return;
|
|
1112
|
+
return lockDocumentScroll();
|
|
1113
|
+
}, [mounted]);
|
|
1114
|
+
useLayoutEffect2(() => {
|
|
1115
|
+
if (!open || !mounted) return;
|
|
1116
|
+
const active = document.activeElement;
|
|
1117
|
+
if (active instanceof HTMLElement && active !== dialogRef.current) {
|
|
1118
|
+
previousActiveRef.current = active;
|
|
1119
|
+
}
|
|
1120
|
+
dialogRef.current?.focus({ preventScroll: true });
|
|
1121
|
+
}, [mounted, open]);
|
|
1122
|
+
useEffect3(() => () => {
|
|
1123
|
+
previousActiveRef.current?.focus({ preventScroll: true });
|
|
1124
|
+
}, []);
|
|
1125
|
+
useEffect3(() => {
|
|
1126
|
+
if (open || !mounted) return;
|
|
1127
|
+
previousActiveRef.current?.focus({ preventScroll: true });
|
|
1128
|
+
previousActiveRef.current = null;
|
|
1129
|
+
}, [mounted, open]);
|
|
1130
|
+
useEffect3(() => {
|
|
1131
|
+
if (!open || !mounted) return;
|
|
1132
|
+
const handleKeyDown = (event) => {
|
|
1133
|
+
if (event.key === "Escape" && closeOnEscape) {
|
|
1134
|
+
event.preventDefault();
|
|
1135
|
+
onClose();
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
if (event.key !== "Tab" || !dialogRef.current) return;
|
|
1139
|
+
const focusable = getFocusableElements(dialogRef.current);
|
|
1140
|
+
if (focusable.length === 0) {
|
|
1141
|
+
event.preventDefault();
|
|
1142
|
+
dialogRef.current.focus({ preventScroll: true });
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
const index = focusable.indexOf(document.activeElement);
|
|
1146
|
+
if (event.shiftKey && index <= 0) {
|
|
1147
|
+
event.preventDefault();
|
|
1148
|
+
focusable[focusable.length - 1]?.focus();
|
|
1149
|
+
} else if (!event.shiftKey && index === focusable.length - 1) {
|
|
1150
|
+
event.preventDefault();
|
|
1151
|
+
focusable[0]?.focus();
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1155
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
1156
|
+
}, [closeOnEscape, mounted, onClose, open]);
|
|
1157
|
+
if (!mounted || typeof document === "undefined") return null;
|
|
1158
|
+
return createPortal2(
|
|
1159
|
+
/* @__PURE__ */ jsx10(
|
|
1160
|
+
"div",
|
|
1161
|
+
{
|
|
1162
|
+
className: cn(
|
|
1163
|
+
"fixed inset-0 z-50 flex items-end justify-center bg-slate-950/50 p-0 backdrop-blur-[1px] transition-opacity duration-200 motion-reduce:transition-none sm:items-center sm:p-4",
|
|
1164
|
+
open ? "opacity-100" : "pointer-events-none opacity-0",
|
|
1165
|
+
overlayClassName
|
|
1166
|
+
),
|
|
1167
|
+
onMouseDown: (event) => {
|
|
1168
|
+
if (closeOnOverlay && event.target === event.currentTarget) onClose();
|
|
1169
|
+
},
|
|
1170
|
+
children: /* @__PURE__ */ jsx10(
|
|
1171
|
+
"section",
|
|
1172
|
+
{
|
|
1173
|
+
ref: dialogRef,
|
|
1174
|
+
role: "dialog",
|
|
1175
|
+
"aria-modal": "true",
|
|
1176
|
+
"aria-label": ariaLabelledBy ? void 0 : ariaLabel,
|
|
1177
|
+
"aria-labelledby": ariaLabelledBy,
|
|
1178
|
+
"data-ds-component": "dialog",
|
|
1179
|
+
"data-ds-surface": "modal",
|
|
1180
|
+
tabIndex: -1,
|
|
1181
|
+
className,
|
|
1182
|
+
children
|
|
1183
|
+
}
|
|
1184
|
+
)
|
|
1185
|
+
}
|
|
1186
|
+
),
|
|
1187
|
+
document.body
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
var sizeClasses2 = {
|
|
1191
|
+
sm: "sm:max-w-sm",
|
|
1192
|
+
md: "sm:max-w-lg",
|
|
1193
|
+
lg: "sm:max-w-2xl",
|
|
1194
|
+
xl: "sm:max-w-4xl",
|
|
1195
|
+
full: "sm:max-w-[95vw]"
|
|
1196
|
+
};
|
|
1197
|
+
function DDialog({
|
|
1198
|
+
open,
|
|
1199
|
+
onClose,
|
|
1200
|
+
title,
|
|
1201
|
+
description,
|
|
1202
|
+
children,
|
|
1203
|
+
footer,
|
|
1204
|
+
size = "md",
|
|
1205
|
+
closeOnOverlay = true,
|
|
1206
|
+
closeOnEscape = true,
|
|
1207
|
+
showClose = true,
|
|
1208
|
+
noPadding = false,
|
|
1209
|
+
className,
|
|
1210
|
+
overlayClassName,
|
|
1211
|
+
ariaLabel,
|
|
1212
|
+
ariaLabelledBy
|
|
1213
|
+
}) {
|
|
1214
|
+
const { t } = useDLocalization();
|
|
1215
|
+
return /* @__PURE__ */ jsxs8(
|
|
1216
|
+
DialogRoot,
|
|
1217
|
+
{
|
|
1218
|
+
open,
|
|
1219
|
+
onClose,
|
|
1220
|
+
closeOnOverlay,
|
|
1221
|
+
closeOnEscape,
|
|
1222
|
+
ariaLabelledBy,
|
|
1223
|
+
ariaLabel: ariaLabel ?? (typeof title === "string" ? title : "DDialog"),
|
|
1224
|
+
overlayClassName,
|
|
1225
|
+
className: cn(
|
|
1226
|
+
"flex max-h-[90vh] w-full flex-col rounded-t-2xl bg-[var(--color-surface)] shadow-[var(--shadow-lg)] transition-[transform,opacity] duration-200 ease-out motion-reduce:transition-none sm:max-h-[85vh] sm:rounded-[var(--radius-panel)]",
|
|
1227
|
+
open ? "translate-y-0 opacity-100 sm:scale-100" : "translate-y-6 opacity-0 sm:translate-y-0 sm:scale-[0.98]",
|
|
1228
|
+
sizeClasses2[size],
|
|
1229
|
+
className
|
|
1230
|
+
),
|
|
1231
|
+
children: [
|
|
1232
|
+
/* @__PURE__ */ jsx10("div", { className: "flex justify-center pb-1 pt-3 sm:hidden", children: /* @__PURE__ */ jsx10("div", { className: "h-1 w-10 rounded-full bg-[var(--color-border)]" }) }),
|
|
1233
|
+
title || description || showClose ? /* @__PURE__ */ jsxs8("div", { className: "flex min-h-16 items-start justify-between gap-4 border-b border-[var(--color-border)] px-5 py-3 sm:px-5 sm:py-3", children: [
|
|
1234
|
+
/* @__PURE__ */ jsxs8("div", { className: "min-w-0 flex-1 self-center", children: [
|
|
1235
|
+
title ? /* @__PURE__ */ jsx10("h3", { className: "m-0 text-base font-semibold leading-6 text-[var(--color-text)]", children: title }) : null,
|
|
1236
|
+
description ? /* @__PURE__ */ jsx10("p", { className: "mb-0 mt-1 text-xs leading-5 text-[var(--color-text-muted)]", children: description }) : null
|
|
1237
|
+
] }),
|
|
1238
|
+
showClose ? /* @__PURE__ */ jsx10(
|
|
1239
|
+
"button",
|
|
1240
|
+
{
|
|
1241
|
+
type: "button",
|
|
1242
|
+
"aria-label": t("dialog.close"),
|
|
1243
|
+
onClick: onClose,
|
|
1244
|
+
className: "grid size-8 shrink-0 appearance-none place-items-center rounded-lg border-0 bg-transparent p-0 text-[var(--color-text-muted)] outline-none shadow-none transition-colors hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)] focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25",
|
|
1245
|
+
children: /* @__PURE__ */ jsx10(XIcon, { size: 16 })
|
|
1246
|
+
}
|
|
1247
|
+
) : null
|
|
1248
|
+
] }) : null,
|
|
1249
|
+
/* @__PURE__ */ jsx10("div", { className: cn("flex-1 overflow-y-auto", !noPadding && "px-5 py-4 sm:px-5"), children }),
|
|
1250
|
+
footer ? /* @__PURE__ */ jsx10("div", { className: "border-t border-[var(--color-border)] bg-[var(--color-surface-muted)]/30 px-5 py-3 sm:rounded-b-[var(--radius-panel)]", children: footer }) : null
|
|
1251
|
+
]
|
|
1252
|
+
}
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// src/confirm-dialog/confirm-dialog.tsx
|
|
1257
|
+
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1258
|
+
function DConfirmDialog({ open, onClose, onConfirm, title, message, confirmLabel, cancelLabel, variant = "danger", loading = false }) {
|
|
1259
|
+
const { t } = useDLocalization();
|
|
1260
|
+
return /* @__PURE__ */ jsx11(DDialog, { open, onClose, title: title ?? t("confirmDialog.title"), size: "sm", footer: /* @__PURE__ */ jsxs9("div", { className: "flex justify-end gap-2", children: [
|
|
1261
|
+
/* @__PURE__ */ jsx11(DButton, { variant: "outline", onClick: onClose, disabled: loading, children: cancelLabel ?? t("confirmDialog.cancel") }),
|
|
1262
|
+
/* @__PURE__ */ jsx11(DButton, { variant, onClick: onConfirm, loading, children: confirmLabel ?? t("confirmDialog.confirm") })
|
|
1263
|
+
] }), children: /* @__PURE__ */ jsx11("p", { className: "text-sm text-[var(--color-text-muted)]", children: message ?? t("confirmDialog.message") }) });
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// src/connection-error/connection-error.tsx
|
|
1267
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1268
|
+
function OfflineIcon() {
|
|
1269
|
+
return /* @__PURE__ */ jsx12("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-9", children: /* @__PURE__ */ jsx12("path", { d: "M3 3l18 18M8.5 8.5A8 8 0 0 1 20 12M4 12a8 8 0 0 1 1.6-4.8M8.5 16.5A5 5 0 0 1 12 15c1.4 0 2.7.6 3.5 1.5M12 20h.01" }) });
|
|
1270
|
+
}
|
|
1271
|
+
function DConnectionError({ onRetry, isRetrying = false, title, message, detail, diagnostics }) {
|
|
1272
|
+
const { t } = useDLocalization();
|
|
1273
|
+
return /* @__PURE__ */ jsx12("div", { className: "fixed inset-0 z-[99998] flex items-center justify-center bg-[var(--color-background)] px-4", children: /* @__PURE__ */ jsxs10("div", { className: "w-full max-w-sm text-center", children: [
|
|
1274
|
+
/* @__PURE__ */ jsx12("div", { className: "mx-auto mb-6 flex size-20 items-center justify-center rounded-full bg-[var(--color-danger)]/10 text-[var(--color-danger)]", children: /* @__PURE__ */ jsx12(OfflineIcon, {}) }),
|
|
1275
|
+
/* @__PURE__ */ jsx12("h2", { className: "mb-2 text-xl font-bold text-[var(--color-text)]", children: title ?? t("connectionError.title") }),
|
|
1276
|
+
/* @__PURE__ */ jsx12("p", { className: "mb-2 text-sm text-[var(--color-text-muted)]", children: message ?? t("connectionError.message") }),
|
|
1277
|
+
/* @__PURE__ */ jsx12("p", { className: "mb-8 text-xs text-[var(--color-text-muted)]/70", children: detail ?? t("connectionError.detail") }),
|
|
1278
|
+
/* @__PURE__ */ jsx12(DButton, { onClick: onRetry, loading: isRetrying, fullWidth: true, children: isRetrying ? t("connectionError.retrying") : t("connectionError.retry") }),
|
|
1279
|
+
diagnostics ? /* @__PURE__ */ jsx12("div", { className: "mt-6 rounded-lg border border-[var(--color-border)] bg-[var(--color-surface-muted)]/50 p-3 text-left text-[11px] text-[var(--color-text-muted)]", children: diagnostics }) : null
|
|
1280
|
+
] }) });
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// src/date-picker/date-picker.tsx
|
|
1284
|
+
import { useEffect as useEffect5, useId as useId2, useMemo as useMemo4, useState as useState5 } from "react";
|
|
1285
|
+
|
|
1286
|
+
// src/internal/time/time-picker-panel.tsx
|
|
1287
|
+
import { useEffect as useEffect4, useRef as useRef5 } from "react";
|
|
1288
|
+
|
|
1289
|
+
// src/internal/time/time-utils.ts
|
|
1290
|
+
function pad(value) {
|
|
1291
|
+
return String(value).padStart(2, "0");
|
|
1292
|
+
}
|
|
1293
|
+
function parseTimeValue(value) {
|
|
1294
|
+
if (!value) return null;
|
|
1295
|
+
const match = /^(\d{1,2})(?::(\d{2}))?$/.exec(value.trim());
|
|
1296
|
+
if (!match) return null;
|
|
1297
|
+
const hour = Number(match[1]);
|
|
1298
|
+
const minute = Number(match[2] ?? "0");
|
|
1299
|
+
if (!Number.isInteger(hour) || !Number.isInteger(minute) || hour < 0 || hour > 23 || minute < 0 || minute > 59) return null;
|
|
1300
|
+
return { hour, minute };
|
|
1301
|
+
}
|
|
1302
|
+
function formatTimeValue(hour, minute = 0) {
|
|
1303
|
+
return `${pad(hour)}:${pad(minute)}`;
|
|
1304
|
+
}
|
|
1305
|
+
function normalizeTimeValue(value, precision) {
|
|
1306
|
+
const parsed = parseTimeValue(value);
|
|
1307
|
+
if (!parsed) return "";
|
|
1308
|
+
return formatTimeValue(parsed.hour, precision === "hour" ? 0 : parsed.minute);
|
|
1309
|
+
}
|
|
1310
|
+
function getMinuteOptions(step, selectedMinute) {
|
|
1311
|
+
const options = Array.from({ length: Math.ceil(60 / step) }, (_, index) => index * step).filter((minute) => minute < 60);
|
|
1312
|
+
if (selectedMinute !== void 0 && selectedMinute >= 0 && selectedMinute < 60 && !options.includes(selectedMinute)) {
|
|
1313
|
+
options.push(selectedMinute);
|
|
1314
|
+
options.sort((a, b) => a - b);
|
|
1315
|
+
}
|
|
1316
|
+
return options;
|
|
1317
|
+
}
|
|
1318
|
+
function getCurrentTimeValue(precision, minuteStep) {
|
|
1319
|
+
const now = /* @__PURE__ */ new Date();
|
|
1320
|
+
const minute = precision === "hour" ? 0 : Math.floor(now.getMinutes() / minuteStep) * minuteStep;
|
|
1321
|
+
return formatTimeValue(now.getHours(), minute);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// src/internal/time/time-picker-panel.tsx
|
|
1325
|
+
import { Fragment, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1326
|
+
var HOURS = Array.from({ length: 24 }, (_, hour) => hour);
|
|
1327
|
+
var ITEM_HEIGHT = 44;
|
|
1328
|
+
var VISIBLE_ITEMS = 5;
|
|
1329
|
+
var WHEEL_PADDING = ITEM_HEIGHT * Math.floor(VISIBLE_ITEMS / 2);
|
|
1330
|
+
function WheelColumn({ label, optionAriaLabel, options, selected, onSelect }) {
|
|
1331
|
+
const scrollRef = useRef5(null);
|
|
1332
|
+
const settleTimerRef = useRef5(null);
|
|
1333
|
+
const selectedIndex = Math.max(0, options.indexOf(selected));
|
|
1334
|
+
useEffect4(() => {
|
|
1335
|
+
const node = scrollRef.current;
|
|
1336
|
+
if (!node) return;
|
|
1337
|
+
const top = selectedIndex * ITEM_HEIGHT;
|
|
1338
|
+
if (typeof node.scrollTo === "function") node.scrollTo({ top, behavior: "auto" });
|
|
1339
|
+
else node.scrollTop = top;
|
|
1340
|
+
}, [selectedIndex]);
|
|
1341
|
+
useEffect4(() => () => {
|
|
1342
|
+
if (settleTimerRef.current !== null) window.clearTimeout(settleTimerRef.current);
|
|
1343
|
+
}, []);
|
|
1344
|
+
const settleSelection = () => {
|
|
1345
|
+
const node = scrollRef.current;
|
|
1346
|
+
if (!node) return;
|
|
1347
|
+
const index = Math.max(0, Math.min(options.length - 1, Math.round(node.scrollTop / ITEM_HEIGHT)));
|
|
1348
|
+
const next = options[index];
|
|
1349
|
+
if (next !== void 0 && next !== selected) onSelect(next);
|
|
1350
|
+
};
|
|
1351
|
+
return /* @__PURE__ */ jsxs11("div", { className: "relative z-10 min-w-0 flex-1", children: [
|
|
1352
|
+
/* @__PURE__ */ jsx13("span", { className: "sr-only", children: label }),
|
|
1353
|
+
/* @__PURE__ */ jsx13(
|
|
1354
|
+
"div",
|
|
1355
|
+
{
|
|
1356
|
+
ref: scrollRef,
|
|
1357
|
+
role: "group",
|
|
1358
|
+
"aria-label": label,
|
|
1359
|
+
onScroll: () => {
|
|
1360
|
+
if (settleTimerRef.current !== null) window.clearTimeout(settleTimerRef.current);
|
|
1361
|
+
settleTimerRef.current = window.setTimeout(settleSelection, 90);
|
|
1362
|
+
},
|
|
1363
|
+
className: "h-[220px] snap-y snap-mandatory overflow-y-auto overscroll-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
1364
|
+
style: { paddingBlock: WHEEL_PADDING },
|
|
1365
|
+
children: options.map((option, index) => {
|
|
1366
|
+
const active = option === selected;
|
|
1367
|
+
const distance = Math.abs(index - selectedIndex);
|
|
1368
|
+
const text = String(option).padStart(2, "0");
|
|
1369
|
+
return /* @__PURE__ */ jsx13(
|
|
1370
|
+
"button",
|
|
1371
|
+
{
|
|
1372
|
+
type: "button",
|
|
1373
|
+
"aria-label": optionAriaLabel(text),
|
|
1374
|
+
"aria-pressed": active,
|
|
1375
|
+
tabIndex: active ? 0 : -1,
|
|
1376
|
+
onClick: () => onSelect(option),
|
|
1377
|
+
className: cn(
|
|
1378
|
+
"flex h-11 w-full snap-center appearance-none items-center justify-center border-0 bg-transparent px-2 tabular-nums shadow-none outline-none transition-[color,opacity,font-size] duration-150 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--color-focus)]/25",
|
|
1379
|
+
active ? "text-xl font-semibold text-[var(--color-text)] opacity-100" : distance === 1 ? "text-lg font-medium text-[var(--color-text-muted)] opacity-65" : distance === 2 ? "text-base text-[var(--color-text-muted)] opacity-35" : "text-sm text-[var(--color-text-muted)] opacity-20"
|
|
1380
|
+
),
|
|
1381
|
+
children: text
|
|
1382
|
+
},
|
|
1383
|
+
option
|
|
1384
|
+
);
|
|
1385
|
+
})
|
|
1386
|
+
}
|
|
1387
|
+
)
|
|
1388
|
+
] });
|
|
1389
|
+
}
|
|
1390
|
+
function TimePickerPanel({ value, variant, minuteStep, onChange, className }) {
|
|
1391
|
+
const { t } = useDLocalization();
|
|
1392
|
+
const parsed = parseTimeValue(value) ?? { hour: 0, minute: 0 };
|
|
1393
|
+
const minuteOptions = getMinuteOptions(minuteStep, parsed.minute);
|
|
1394
|
+
const hourLabel = t("timePicker.hour");
|
|
1395
|
+
const minuteLabel = t("timePicker.minute");
|
|
1396
|
+
const selectHour = (hour) => {
|
|
1397
|
+
onChange(formatTimeValue(hour, variant === "hour" ? 0 : parsed.minute));
|
|
1398
|
+
};
|
|
1399
|
+
const selectMinute = (minute) => {
|
|
1400
|
+
onChange(formatTimeValue(parsed.hour, minute));
|
|
1401
|
+
};
|
|
1402
|
+
return /* @__PURE__ */ jsxs11(
|
|
1403
|
+
"div",
|
|
1404
|
+
{
|
|
1405
|
+
"data-time-picker-wheel": "true",
|
|
1406
|
+
className: cn(
|
|
1407
|
+
"relative mx-auto overflow-hidden rounded-[var(--radius-panel)] bg-[var(--color-surface)]",
|
|
1408
|
+
variant === "hour-minute" ? "w-full max-w-[244px]" : "w-full max-w-[112px]",
|
|
1409
|
+
className
|
|
1410
|
+
),
|
|
1411
|
+
children: [
|
|
1412
|
+
/* @__PURE__ */ jsx13("div", { className: "pointer-events-none absolute inset-x-0 top-1/2 z-0 h-11 -translate-y-1/2 rounded-[var(--radius-control)] border border-[var(--color-border)] bg-[var(--color-surface-muted)]/55" }),
|
|
1413
|
+
/* @__PURE__ */ jsx13("div", { className: "pointer-events-none absolute inset-x-0 top-0 z-20 h-16 bg-gradient-to-b from-[var(--color-surface)] to-transparent" }),
|
|
1414
|
+
/* @__PURE__ */ jsx13("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 z-20 h-16 bg-gradient-to-t from-[var(--color-surface)] to-transparent" }),
|
|
1415
|
+
/* @__PURE__ */ jsxs11("div", { className: "relative z-10 flex items-center gap-2", children: [
|
|
1416
|
+
/* @__PURE__ */ jsx13(
|
|
1417
|
+
WheelColumn,
|
|
1418
|
+
{
|
|
1419
|
+
label: hourLabel,
|
|
1420
|
+
optionAriaLabel: (text) => t("timePicker.hourOption", { value: text }),
|
|
1421
|
+
options: HOURS,
|
|
1422
|
+
selected: parsed.hour,
|
|
1423
|
+
onSelect: selectHour
|
|
1424
|
+
}
|
|
1425
|
+
),
|
|
1426
|
+
variant === "hour-minute" ? /* @__PURE__ */ jsxs11(Fragment, { children: [
|
|
1427
|
+
/* @__PURE__ */ jsx13("span", { "aria-hidden": "true", className: "relative z-10 -mx-1 text-xl font-semibold text-[var(--color-text-muted)]", children: ":" }),
|
|
1428
|
+
/* @__PURE__ */ jsx13(
|
|
1429
|
+
WheelColumn,
|
|
1430
|
+
{
|
|
1431
|
+
label: minuteLabel,
|
|
1432
|
+
optionAriaLabel: (text) => t("timePicker.minuteOption", { value: text }),
|
|
1433
|
+
options: minuteOptions,
|
|
1434
|
+
selected: parsed.minute,
|
|
1435
|
+
onSelect: selectMinute
|
|
1436
|
+
}
|
|
1437
|
+
)
|
|
1438
|
+
] }) : null
|
|
1439
|
+
] })
|
|
1440
|
+
]
|
|
1441
|
+
}
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// src/date-picker/date-picker.tsx
|
|
1446
|
+
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
1447
|
+
function ChevronLeftIcon2() {
|
|
1448
|
+
return /* @__PURE__ */ jsx14("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: /* @__PURE__ */ jsx14("path", { d: "m15 18-6-6 6-6" }) });
|
|
1449
|
+
}
|
|
1450
|
+
function ChevronRightIcon2() {
|
|
1451
|
+
return /* @__PURE__ */ jsx14("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: /* @__PURE__ */ jsx14("path", { d: "m9 18 6-6-6-6" }) });
|
|
1452
|
+
}
|
|
1453
|
+
function CalendarIcon() {
|
|
1454
|
+
return /* @__PURE__ */ jsxs12("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: [
|
|
1455
|
+
/* @__PURE__ */ jsx14("rect", { x: "3", y: "5", width: "18", height: "16", rx: "2" }),
|
|
1456
|
+
/* @__PURE__ */ jsx14("path", { d: "M16 3v4M8 3v4M3 10h18" })
|
|
1457
|
+
] });
|
|
1458
|
+
}
|
|
1459
|
+
function ClearIcon2() {
|
|
1460
|
+
return /* @__PURE__ */ jsx14("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx14("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
1461
|
+
}
|
|
1462
|
+
function datePart(value) {
|
|
1463
|
+
return value?.split("T")[0] ?? "";
|
|
1464
|
+
}
|
|
1465
|
+
function timePart(value) {
|
|
1466
|
+
const separator = value?.indexOf("T") ?? -1;
|
|
1467
|
+
return separator >= 0 ? value?.slice(separator + 1) ?? "" : "";
|
|
1468
|
+
}
|
|
1469
|
+
function parseDate(value) {
|
|
1470
|
+
const raw = datePart(value);
|
|
1471
|
+
if (!raw) return null;
|
|
1472
|
+
const date2 = /* @__PURE__ */ new Date(`${raw}T00:00:00`);
|
|
1473
|
+
return Number.isNaN(date2.getTime()) ? null : date2;
|
|
1474
|
+
}
|
|
1475
|
+
function toValue(year, month, day) {
|
|
1476
|
+
return `${year}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
1477
|
+
}
|
|
1478
|
+
function compareDateValue(value, boundary) {
|
|
1479
|
+
if (!boundary) return 0;
|
|
1480
|
+
return value.localeCompare(datePart(boundary));
|
|
1481
|
+
}
|
|
1482
|
+
function timePrecision(variant) {
|
|
1483
|
+
return variant === "date-hour" ? "hour" : "hour-minute";
|
|
1484
|
+
}
|
|
1485
|
+
function formatDateDisplay(value, months) {
|
|
1486
|
+
const date2 = parseDate(value);
|
|
1487
|
+
return date2 ? `${date2.getDate()} ${months[date2.getMonth()]} ${date2.getFullYear()}` : "";
|
|
1488
|
+
}
|
|
1489
|
+
function formatDisplayValue(value, variant, months) {
|
|
1490
|
+
const dateDisplay = formatDateDisplay(value, months);
|
|
1491
|
+
if (!dateDisplay) return "";
|
|
1492
|
+
if (variant === "date") return dateDisplay;
|
|
1493
|
+
const timeDisplay = normalizeTimeValue(timePart(value), timePrecision(variant));
|
|
1494
|
+
return timeDisplay ? `${dateDisplay} \xB7 ${timeDisplay}` : dateDisplay;
|
|
1495
|
+
}
|
|
1496
|
+
function DatePickerContent({ value, onChange, minDate, maxDate, variant, minuteStep }) {
|
|
1497
|
+
const close = useDropdownClose();
|
|
1498
|
+
const { locale, t } = useDLocalization();
|
|
1499
|
+
const days = useMemo4(() => getLocalizedWeekdayNames(locale, "short"), [locale]);
|
|
1500
|
+
const months = useMemo4(() => getLocalizedMonthNames(locale), [locale]);
|
|
1501
|
+
const today = /* @__PURE__ */ new Date();
|
|
1502
|
+
const selectedDate = parseDate(value);
|
|
1503
|
+
const selectedDateValue = datePart(value);
|
|
1504
|
+
const precision = timePrecision(variant);
|
|
1505
|
+
const fallbackTime = () => getCurrentTimeValue(precision, minuteStep);
|
|
1506
|
+
const selectedTimeValue = normalizeTimeValue(timePart(value), precision) || fallbackTime();
|
|
1507
|
+
const [viewMonth, setViewMonth] = useState5(selectedDate?.getMonth() ?? today.getMonth());
|
|
1508
|
+
const [viewYear, setViewYear] = useState5(selectedDate?.getFullYear() ?? today.getFullYear());
|
|
1509
|
+
const [draftDate, setDraftDate] = useState5(selectedDateValue);
|
|
1510
|
+
const [draftTime, setDraftTime] = useState5(selectedTimeValue);
|
|
1511
|
+
useEffect5(() => {
|
|
1512
|
+
const nextDate = parseDate(value);
|
|
1513
|
+
setDraftDate(datePart(value));
|
|
1514
|
+
setDraftTime(normalizeTimeValue(timePart(value), precision) || fallbackTime());
|
|
1515
|
+
if (!nextDate) return;
|
|
1516
|
+
setViewMonth(nextDate.getMonth());
|
|
1517
|
+
setViewYear(nextDate.getFullYear());
|
|
1518
|
+
}, [value, variant, minuteStep]);
|
|
1519
|
+
const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
|
|
1520
|
+
const firstDay = new Date(viewYear, viewMonth, 1).getDay();
|
|
1521
|
+
const move = (amount) => {
|
|
1522
|
+
const next = new Date(viewYear, viewMonth + amount, 1);
|
|
1523
|
+
setViewYear(next.getFullYear());
|
|
1524
|
+
setViewMonth(next.getMonth());
|
|
1525
|
+
};
|
|
1526
|
+
const selectDate = (day) => {
|
|
1527
|
+
const next = toValue(viewYear, viewMonth, day);
|
|
1528
|
+
if (minDate && compareDateValue(next, minDate) < 0 || maxDate && compareDateValue(next, maxDate) > 0) return;
|
|
1529
|
+
if (variant === "date") {
|
|
1530
|
+
onChange?.(next);
|
|
1531
|
+
close?.();
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
setDraftDate(next);
|
|
1535
|
+
};
|
|
1536
|
+
const todayValue = toValue(today.getFullYear(), today.getMonth(), today.getDate());
|
|
1537
|
+
const todayDisabled = minDate && compareDateValue(todayValue, minDate) < 0 || maxDate && compareDateValue(todayValue, maxDate) > 0;
|
|
1538
|
+
const selectToday = () => {
|
|
1539
|
+
if (variant === "date") {
|
|
1540
|
+
onChange?.(todayValue);
|
|
1541
|
+
close?.();
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
setDraftDate(todayValue);
|
|
1545
|
+
setViewMonth(today.getMonth());
|
|
1546
|
+
setViewYear(today.getFullYear());
|
|
1547
|
+
};
|
|
1548
|
+
const applyDateTime = () => {
|
|
1549
|
+
if (!draftDate) return;
|
|
1550
|
+
const normalizedTime = normalizeTimeValue(draftTime, precision) || fallbackTime();
|
|
1551
|
+
onChange?.(`${draftDate}T${normalizedTime}`);
|
|
1552
|
+
close?.();
|
|
1553
|
+
};
|
|
1554
|
+
return /* @__PURE__ */ jsxs12("div", { className: cn("p-3", variant === "date" ? "w-[280px]" : "w-[min(320px,calc(100vw-16px))]"), children: [
|
|
1555
|
+
/* @__PURE__ */ jsxs12("div", { className: "mb-2 flex items-center justify-between", children: [
|
|
1556
|
+
/* @__PURE__ */ jsx14("button", { type: "button", "aria-label": t("common.previousMonth"), onClick: () => move(-1), className: "flex size-8 appearance-none items-center justify-center rounded-[var(--radius-menu-item)] border-0 bg-transparent text-[var(--color-text-muted)] shadow-none hover:bg-[var(--color-surface-muted)]", children: /* @__PURE__ */ jsx14(ChevronLeftIcon2, {}) }),
|
|
1557
|
+
/* @__PURE__ */ jsxs12("span", { className: "text-sm font-medium text-[var(--color-text)]", children: [
|
|
1558
|
+
months[viewMonth],
|
|
1559
|
+
" ",
|
|
1560
|
+
viewYear
|
|
1561
|
+
] }),
|
|
1562
|
+
/* @__PURE__ */ jsx14("button", { type: "button", "aria-label": t("common.nextMonth"), onClick: () => move(1), className: "flex size-8 appearance-none items-center justify-center rounded-[var(--radius-menu-item)] border-0 bg-transparent text-[var(--color-text-muted)] shadow-none hover:bg-[var(--color-surface-muted)]", children: /* @__PURE__ */ jsx14(ChevronRightIcon2, {}) })
|
|
1563
|
+
] }),
|
|
1564
|
+
/* @__PURE__ */ jsx14("div", { className: "mb-1 grid grid-cols-7 text-xs", children: days.map((day) => /* @__PURE__ */ jsx14("div", { className: "text-center text-[var(--color-text-muted)]", children: day }, day)) }),
|
|
1565
|
+
/* @__PURE__ */ jsxs12("div", { className: "grid grid-cols-7 gap-1", children: [
|
|
1566
|
+
Array.from({ length: firstDay }).map((_, index) => /* @__PURE__ */ jsx14("div", {}, `empty-${index}`)),
|
|
1567
|
+
Array.from({ length: daysInMonth }, (_, index) => index + 1).map((day) => {
|
|
1568
|
+
const dateValue = toValue(viewYear, viewMonth, day);
|
|
1569
|
+
const selected = (variant === "date" ? selectedDateValue : draftDate) === dateValue;
|
|
1570
|
+
const outside = minDate && compareDateValue(dateValue, minDate) < 0 || maxDate && compareDateValue(dateValue, maxDate) > 0;
|
|
1571
|
+
return /* @__PURE__ */ jsx14("button", { type: "button", disabled: Boolean(outside), onClick: () => selectDate(day), className: cn("aspect-square w-full appearance-none rounded-[var(--radius-control)] border-0 bg-transparent text-sm shadow-none transition-colors hover:bg-[var(--color-surface-muted)] disabled:cursor-not-allowed disabled:opacity-30", selected && "bg-[var(--color-brand)] font-medium text-[var(--color-brand-foreground)] hover:bg-[var(--color-brand)]"), children: day }, day);
|
|
1572
|
+
})
|
|
1573
|
+
] }),
|
|
1574
|
+
variant !== "date" ? /* @__PURE__ */ jsxs12("div", { className: "mt-3 border-t border-[var(--color-border)] pt-3", children: [
|
|
1575
|
+
/* @__PURE__ */ jsxs12("div", { className: "mb-3 flex items-center justify-between gap-3", children: [
|
|
1576
|
+
/* @__PURE__ */ jsxs12("div", { children: [
|
|
1577
|
+
/* @__PURE__ */ jsx14("p", { className: "text-xs font-semibold text-[var(--color-text)]", children: t("datePicker.time") }),
|
|
1578
|
+
/* @__PURE__ */ jsx14("p", { className: "mt-0.5 text-[11px] text-[var(--color-text-muted)]", children: variant === "date-hour" ? t("datePicker.selectHour") : t("datePicker.selectHourMinute") })
|
|
1579
|
+
] }),
|
|
1580
|
+
/* @__PURE__ */ jsx14("span", { className: "rounded-[var(--radius-menu-item)] bg-[var(--color-surface-muted)] px-2 py-1 text-xs font-semibold tabular-nums text-[var(--color-text)]", children: draftTime })
|
|
1581
|
+
] }),
|
|
1582
|
+
/* @__PURE__ */ jsx14(TimePickerPanel, { value: draftTime, variant: precision, minuteStep, onChange: setDraftTime })
|
|
1583
|
+
] }) : null,
|
|
1584
|
+
/* @__PURE__ */ jsxs12("div", { className: "mt-3 flex items-center justify-between gap-2 border-t border-[var(--color-border)] pt-3", children: [
|
|
1585
|
+
/* @__PURE__ */ jsx14("button", { type: "button", disabled: Boolean(todayDisabled), onClick: selectToday, className: "h-8 appearance-none rounded-[var(--radius-menu-item)] border-0 bg-transparent px-2 text-xs font-medium text-[var(--color-brand)] shadow-none hover:bg-[var(--color-surface-muted)] disabled:cursor-not-allowed disabled:opacity-40", children: t("datePicker.today") }),
|
|
1586
|
+
variant !== "date" ? /* @__PURE__ */ jsxs12("div", { className: "flex items-center gap-2", children: [
|
|
1587
|
+
/* @__PURE__ */ jsx14("button", { type: "button", onClick: () => close?.(), className: "h-8 appearance-none rounded-[var(--radius-menu-item)] border-0 bg-transparent px-3 text-xs font-medium text-[var(--color-text-muted)] shadow-none hover:bg-[var(--color-surface-muted)]", children: t("common.cancel") }),
|
|
1588
|
+
/* @__PURE__ */ jsx14("button", { type: "button", disabled: !draftDate, onClick: applyDateTime, className: "h-8 appearance-none rounded-[var(--radius-menu-item)] border-0 bg-[var(--color-brand)] px-3 text-xs font-semibold text-[var(--color-brand-foreground)] shadow-none hover:brightness-95 disabled:cursor-not-allowed disabled:opacity-50", children: t("common.apply") })
|
|
1589
|
+
] }) : null
|
|
1590
|
+
] })
|
|
1591
|
+
] });
|
|
1592
|
+
}
|
|
1593
|
+
function DDatePicker({ label, value, onChange, onClear, placeholder, error, hint, disabled = false, clearable = true, containerClassName, minDate, maxDate, size = "md", variant = "date", minuteStep = 1, scrollBehavior = "reposition" }) {
|
|
1594
|
+
const id = useId2();
|
|
1595
|
+
const { locale, t } = useDLocalization();
|
|
1596
|
+
const months = useMemo4(() => getLocalizedMonthNames(locale), [locale]);
|
|
1597
|
+
const s = INPUT_SIZE_STYLES[size];
|
|
1598
|
+
const display = formatDisplayValue(value, variant, months);
|
|
1599
|
+
const resolvedPlaceholder = placeholder ?? t("datePicker.placeholder");
|
|
1600
|
+
return /* @__PURE__ */ jsxs12("div", { "data-ds-component": "date-picker", "data-date-picker-variant": variant, className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
1601
|
+
label ? /* @__PURE__ */ jsx14("label", { htmlFor: id, className: cn(s.label, "w-fit font-medium text-[var(--color-text)]"), children: label }) : null,
|
|
1602
|
+
/* @__PURE__ */ jsx14(DDropdown, { contentRole: "dialog", contentPadding: false, scrollBehavior, trigger: () => /* @__PURE__ */ jsxs12("div", { className: "relative", children: [
|
|
1603
|
+
/* @__PURE__ */ jsxs12("button", { id, type: "button", disabled, "aria-invalid": Boolean(error) || void 0, className: cn("flex w-full items-center gap-2 rounded-[var(--radius-control)] border bg-[var(--color-surface)] text-left text-[var(--color-text)] transition-colors focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50", s.input, error ? "border-[var(--color-danger)]" : "border-[var(--color-border)]", !display && "text-[var(--color-text-muted)]/60", clearable && display && "pr-10"), children: [
|
|
1604
|
+
/* @__PURE__ */ jsx14("span", { className: "text-[var(--color-text-muted)]", children: /* @__PURE__ */ jsx14(CalendarIcon, {}) }),
|
|
1605
|
+
/* @__PURE__ */ jsx14("span", { className: "min-w-0 flex-1 truncate", children: display || resolvedPlaceholder })
|
|
1606
|
+
] }),
|
|
1607
|
+
clearable && display && !disabled ? /* @__PURE__ */ jsx14("button", { type: "button", "aria-label": t("datePicker.clear"), onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
1608
|
+
event.preventDefault();
|
|
1609
|
+
event.stopPropagation();
|
|
1610
|
+
onChange?.("");
|
|
1611
|
+
onClear?.();
|
|
1612
|
+
}, className: "absolute right-2 top-1/2 -translate-y-1/2 appearance-none rounded-md border-0 bg-transparent p-1 text-[var(--color-text-muted)] shadow-none hover:bg-[var(--color-surface-muted)]", children: /* @__PURE__ */ jsx14(ClearIcon2, {}) }) : null
|
|
1613
|
+
] }), children: /* @__PURE__ */ jsx14(DatePickerContent, { value, onChange, minDate, maxDate, variant, minuteStep }) }),
|
|
1614
|
+
error ? /* @__PURE__ */ jsx14("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
1615
|
+
!error && hint ? /* @__PURE__ */ jsx14("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
1616
|
+
] });
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
// src/time-picker/time-picker.tsx
|
|
1620
|
+
import { useEffect as useEffect6, useId as useId3, useState as useState6 } from "react";
|
|
1621
|
+
import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1622
|
+
function ClockIcon() {
|
|
1623
|
+
return /* @__PURE__ */ jsxs13("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: [
|
|
1624
|
+
/* @__PURE__ */ jsx15("circle", { cx: "12", cy: "12", r: "9" }),
|
|
1625
|
+
/* @__PURE__ */ jsx15("path", { d: "M12 7v5l3 2" })
|
|
1626
|
+
] });
|
|
1627
|
+
}
|
|
1628
|
+
function ClearIcon3() {
|
|
1629
|
+
return /* @__PURE__ */ jsx15("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx15("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
1630
|
+
}
|
|
1631
|
+
function TimePickerContent({
|
|
1632
|
+
value,
|
|
1633
|
+
onChange,
|
|
1634
|
+
variant,
|
|
1635
|
+
minuteStep
|
|
1636
|
+
}) {
|
|
1637
|
+
const close = useDropdownClose();
|
|
1638
|
+
const { t } = useDLocalization();
|
|
1639
|
+
const fallback = () => getCurrentTimeValue(variant, minuteStep);
|
|
1640
|
+
const [draft, setDraft] = useState6(() => normalizeTimeValue(value, variant) || fallback());
|
|
1641
|
+
useEffect6(() => {
|
|
1642
|
+
setDraft(normalizeTimeValue(value, variant) || fallback());
|
|
1643
|
+
}, [value, variant, minuteStep]);
|
|
1644
|
+
const apply = () => {
|
|
1645
|
+
onChange?.(normalizeTimeValue(draft, variant));
|
|
1646
|
+
close?.();
|
|
1647
|
+
};
|
|
1648
|
+
return /* @__PURE__ */ jsxs13("div", { className: cn("p-3", variant === "hour" ? "w-[min(232px,calc(100vw-16px))]" : "w-[min(320px,calc(100vw-16px))]"), children: [
|
|
1649
|
+
/* @__PURE__ */ jsxs13("div", { className: "mb-3 flex items-center justify-between gap-3", children: [
|
|
1650
|
+
/* @__PURE__ */ jsxs13("div", { children: [
|
|
1651
|
+
/* @__PURE__ */ jsx15("p", { className: "text-xs font-semibold text-[var(--color-text)]", children: t("timePicker.title") }),
|
|
1652
|
+
/* @__PURE__ */ jsx15("p", { className: "mt-0.5 text-[11px] text-[var(--color-text-muted)]", children: variant === "hour" ? t("timePicker.hourPrecision") : t("timePicker.hourMinutePrecision") })
|
|
1653
|
+
] }),
|
|
1654
|
+
/* @__PURE__ */ jsx15("span", { className: "rounded-[var(--radius-menu-item)] bg-[var(--color-surface-muted)] px-2 py-1 text-xs font-semibold tabular-nums text-[var(--color-text)]", children: draft })
|
|
1655
|
+
] }),
|
|
1656
|
+
/* @__PURE__ */ jsx15(TimePickerPanel, { value: draft, variant, minuteStep, onChange: setDraft }),
|
|
1657
|
+
/* @__PURE__ */ jsxs13("div", { className: "mt-3 flex items-center justify-between gap-2 border-t border-[var(--color-border)] pt-3", children: [
|
|
1658
|
+
/* @__PURE__ */ jsx15(
|
|
1659
|
+
"button",
|
|
1660
|
+
{
|
|
1661
|
+
type: "button",
|
|
1662
|
+
onClick: () => setDraft(fallback()),
|
|
1663
|
+
className: "h-8 appearance-none rounded-[var(--radius-menu-item)] border-0 bg-transparent px-2 text-xs font-medium text-[var(--color-brand)] shadow-none hover:bg-[var(--color-surface-muted)]",
|
|
1664
|
+
children: t("timePicker.now")
|
|
1665
|
+
}
|
|
1666
|
+
),
|
|
1667
|
+
/* @__PURE__ */ jsxs13("div", { className: "flex items-center gap-2", children: [
|
|
1668
|
+
/* @__PURE__ */ jsx15(
|
|
1669
|
+
"button",
|
|
1670
|
+
{
|
|
1671
|
+
type: "button",
|
|
1672
|
+
onClick: () => close?.(),
|
|
1673
|
+
className: "h-8 appearance-none rounded-[var(--radius-menu-item)] border-0 bg-transparent px-3 text-xs font-medium text-[var(--color-text-muted)] shadow-none hover:bg-[var(--color-surface-muted)]",
|
|
1674
|
+
children: t("common.cancel")
|
|
1675
|
+
}
|
|
1676
|
+
),
|
|
1677
|
+
/* @__PURE__ */ jsx15(
|
|
1678
|
+
"button",
|
|
1679
|
+
{
|
|
1680
|
+
type: "button",
|
|
1681
|
+
onClick: apply,
|
|
1682
|
+
className: "h-8 appearance-none rounded-[var(--radius-menu-item)] border-0 bg-[var(--color-brand)] px-3 text-xs font-semibold text-[var(--color-brand-foreground)] shadow-none hover:brightness-95",
|
|
1683
|
+
children: t("common.apply")
|
|
1684
|
+
}
|
|
1685
|
+
)
|
|
1686
|
+
] })
|
|
1687
|
+
] })
|
|
1688
|
+
] });
|
|
1689
|
+
}
|
|
1690
|
+
function DTimePicker({
|
|
1691
|
+
label,
|
|
1692
|
+
value,
|
|
1693
|
+
onChange,
|
|
1694
|
+
onClear,
|
|
1695
|
+
placeholder,
|
|
1696
|
+
error,
|
|
1697
|
+
hint,
|
|
1698
|
+
disabled = false,
|
|
1699
|
+
clearable = true,
|
|
1700
|
+
containerClassName,
|
|
1701
|
+
size = "md",
|
|
1702
|
+
variant = "hour-minute",
|
|
1703
|
+
minuteStep = 1,
|
|
1704
|
+
scrollBehavior = "reposition"
|
|
1705
|
+
}) {
|
|
1706
|
+
const id = useId3();
|
|
1707
|
+
const { t } = useDLocalization();
|
|
1708
|
+
const s = INPUT_SIZE_STYLES[size];
|
|
1709
|
+
const display = normalizeTimeValue(value, variant);
|
|
1710
|
+
const resolvedPlaceholder = placeholder ?? t("timePicker.placeholder");
|
|
1711
|
+
return /* @__PURE__ */ jsxs13("div", { "data-ds-component": "time-picker", className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
1712
|
+
label ? /* @__PURE__ */ jsx15("label", { htmlFor: id, className: cn(s.label, "w-fit font-medium text-[var(--color-text)]"), children: label }) : null,
|
|
1713
|
+
/* @__PURE__ */ jsx15(DDropdown, { contentRole: "dialog", contentPadding: false, scrollBehavior, trigger: () => /* @__PURE__ */ jsxs13("div", { className: "relative", children: [
|
|
1714
|
+
/* @__PURE__ */ jsxs13(
|
|
1715
|
+
"button",
|
|
1716
|
+
{
|
|
1717
|
+
id,
|
|
1718
|
+
type: "button",
|
|
1719
|
+
disabled,
|
|
1720
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
1721
|
+
className: cn(
|
|
1722
|
+
"flex w-full items-center gap-2 rounded-[var(--radius-control)] border bg-[var(--color-surface)] text-left text-[var(--color-text)] transition-colors focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50",
|
|
1723
|
+
s.input,
|
|
1724
|
+
error ? "border-[var(--color-danger)]" : "border-[var(--color-border)]",
|
|
1725
|
+
!display && "text-[var(--color-text-muted)]/60",
|
|
1726
|
+
clearable && display && "pr-10"
|
|
1727
|
+
),
|
|
1728
|
+
children: [
|
|
1729
|
+
/* @__PURE__ */ jsx15("span", { className: "text-[var(--color-text-muted)]", children: /* @__PURE__ */ jsx15(ClockIcon, {}) }),
|
|
1730
|
+
/* @__PURE__ */ jsx15("span", { className: "min-w-0 flex-1 truncate tabular-nums", children: display || resolvedPlaceholder })
|
|
1731
|
+
]
|
|
1732
|
+
}
|
|
1733
|
+
),
|
|
1734
|
+
clearable && display && !disabled ? /* @__PURE__ */ jsx15(
|
|
1735
|
+
"button",
|
|
1736
|
+
{
|
|
1737
|
+
type: "button",
|
|
1738
|
+
"aria-label": t("timePicker.clear"),
|
|
1739
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
1740
|
+
onClick: (event) => {
|
|
1741
|
+
event.preventDefault();
|
|
1742
|
+
event.stopPropagation();
|
|
1743
|
+
onChange?.("");
|
|
1744
|
+
onClear?.();
|
|
1745
|
+
},
|
|
1746
|
+
className: "absolute right-2 top-1/2 -translate-y-1/2 appearance-none rounded-md border-0 bg-transparent p-1 text-[var(--color-text-muted)] shadow-none hover:bg-[var(--color-surface-muted)]",
|
|
1747
|
+
children: /* @__PURE__ */ jsx15(ClearIcon3, {})
|
|
1748
|
+
}
|
|
1749
|
+
) : null
|
|
1750
|
+
] }), children: /* @__PURE__ */ jsx15(TimePickerContent, { value, onChange, variant, minuteStep }) }),
|
|
1751
|
+
error ? /* @__PURE__ */ jsx15("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
1752
|
+
!error && hint ? /* @__PURE__ */ jsx15("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
1753
|
+
] });
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// src/date-range-filter/date-range-filter.tsx
|
|
1757
|
+
import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1758
|
+
function DDateRangeFilter({ from, to, onFromChange, onToChange, onClear }) {
|
|
1759
|
+
const { t } = useDLocalization();
|
|
1760
|
+
return /* @__PURE__ */ jsxs14("div", { "data-ds-component": "date-range-filter", className: "flex flex-wrap items-center gap-3", children: [
|
|
1761
|
+
/* @__PURE__ */ jsx16("span", { className: "hidden text-xs font-medium text-[var(--color-text-muted)] sm:inline", children: t("dateRangeFilter.period") }),
|
|
1762
|
+
/* @__PURE__ */ jsx16(DDatePicker, { value: from, onChange: onFromChange, containerClassName: "w-[160px]", placeholder: t("dateRangeFilter.from") }),
|
|
1763
|
+
/* @__PURE__ */ jsx16("span", { className: "text-sm text-[var(--color-text-muted)]", children: "\u2014" }),
|
|
1764
|
+
/* @__PURE__ */ jsx16(DDatePicker, { value: to, onChange: onToChange, minDate: from || void 0, containerClassName: "w-[160px]", placeholder: t("dateRangeFilter.to") }),
|
|
1765
|
+
onClear && (from || to) ? /* @__PURE__ */ jsx16(
|
|
1766
|
+
"button",
|
|
1767
|
+
{
|
|
1768
|
+
type: "button",
|
|
1769
|
+
onClick: onClear,
|
|
1770
|
+
className: "h-9 rounded-[var(--radius-control)] border border-[var(--color-border)] bg-[var(--color-surface)] px-3 text-xs font-medium text-[var(--color-text-muted)] hover:bg-[var(--color-danger)]/5 hover:text-[var(--color-danger)]",
|
|
1771
|
+
children: t("dateRangeFilter.reset")
|
|
1772
|
+
}
|
|
1773
|
+
) : null
|
|
1774
|
+
] });
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
// src/empty-state/empty-state.tsx
|
|
1778
|
+
import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1779
|
+
function DEmptyState({
|
|
1780
|
+
title,
|
|
1781
|
+
description,
|
|
1782
|
+
action,
|
|
1783
|
+
icon,
|
|
1784
|
+
className
|
|
1785
|
+
}) {
|
|
1786
|
+
return /* @__PURE__ */ jsxs15(
|
|
1787
|
+
"div",
|
|
1788
|
+
{
|
|
1789
|
+
className: cn(
|
|
1790
|
+
"flex min-h-48 flex-col items-center justify-center rounded-[var(--radius-card)] border border-dashed border-[var(--color-border)] bg-[var(--color-surface-muted)]/20 px-4 py-10 text-center",
|
|
1791
|
+
className
|
|
1792
|
+
),
|
|
1793
|
+
children: [
|
|
1794
|
+
icon ? /* @__PURE__ */ jsx17("div", { className: "mb-3 text-[var(--color-text-muted)]", children: icon }) : null,
|
|
1795
|
+
/* @__PURE__ */ jsx17("p", { className: "text-sm font-semibold", children: title }),
|
|
1796
|
+
description ? /* @__PURE__ */ jsx17("p", { className: "mt-1 max-w-sm text-xs leading-5 text-[var(--color-text-muted)]", children: description }) : null,
|
|
1797
|
+
action ? /* @__PURE__ */ jsx17("div", { className: "mt-4", children: action }) : null
|
|
1798
|
+
]
|
|
1799
|
+
}
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
// src/export-button/export-button.tsx
|
|
1804
|
+
import { useState as useState7 } from "react";
|
|
1805
|
+
import { jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1806
|
+
function DownloadIcon() {
|
|
1807
|
+
return /* @__PURE__ */ jsx18("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx18("path", { d: "M12 3v12m0 0 4-4m-4 4-4-4M5 21h14" }) });
|
|
1808
|
+
}
|
|
1809
|
+
function ExportContent({ onExport, filename, onSuccess, onError, onProcessing, setLoading }) {
|
|
1810
|
+
const close = useDropdownClose();
|
|
1811
|
+
const { t } = useDLocalization();
|
|
1812
|
+
const run = async (format) => {
|
|
1813
|
+
close?.();
|
|
1814
|
+
setLoading(true);
|
|
1815
|
+
try {
|
|
1816
|
+
const result = onExport(format);
|
|
1817
|
+
if (result instanceof Promise) {
|
|
1818
|
+
const blob = await result;
|
|
1819
|
+
const url2 = URL.createObjectURL(blob);
|
|
1820
|
+
const anchor = document.createElement("a");
|
|
1821
|
+
anchor.href = url2;
|
|
1822
|
+
anchor.download = `${filename}.${format === "pdf" ? "pdf" : "xlsx"}`;
|
|
1823
|
+
document.body.appendChild(anchor);
|
|
1824
|
+
anchor.click();
|
|
1825
|
+
anchor.remove();
|
|
1826
|
+
URL.revokeObjectURL(url2);
|
|
1827
|
+
onSuccess?.(format);
|
|
1828
|
+
} else if (result instanceof Blob) {
|
|
1829
|
+
const url2 = URL.createObjectURL(result);
|
|
1830
|
+
const anchor = document.createElement("a");
|
|
1831
|
+
anchor.href = url2;
|
|
1832
|
+
anchor.download = `${filename}.${format === "pdf" ? "pdf" : "xlsx"}`;
|
|
1833
|
+
document.body.appendChild(anchor);
|
|
1834
|
+
anchor.click();
|
|
1835
|
+
anchor.remove();
|
|
1836
|
+
URL.revokeObjectURL(url2);
|
|
1837
|
+
onSuccess?.(format);
|
|
1838
|
+
} else onProcessing?.(format);
|
|
1839
|
+
} catch (error) {
|
|
1840
|
+
onError?.(error, format);
|
|
1841
|
+
} finally {
|
|
1842
|
+
setLoading(false);
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
return /* @__PURE__ */ jsxs16("div", { className: "min-w-[140px] py-1", children: [
|
|
1846
|
+
/* @__PURE__ */ jsx18("button", { type: "button", onClick: () => void run("pdf"), className: "w-full px-3 py-2 text-left text-sm text-[var(--color-text)] hover:bg-[var(--color-surface-muted)]", children: t("export.pdf") }),
|
|
1847
|
+
/* @__PURE__ */ jsx18("button", { type: "button", onClick: () => void run("excel"), className: "w-full px-3 py-2 text-left text-sm text-[var(--color-text)] hover:bg-[var(--color-surface-muted)]", children: t("export.excel") })
|
|
1848
|
+
] });
|
|
1849
|
+
}
|
|
1850
|
+
function DExportButton({ filename = "export", disabled, ...props }) {
|
|
1851
|
+
const [loading, setLoading] = useState7(false);
|
|
1852
|
+
const { t } = useDLocalization();
|
|
1853
|
+
return /* @__PURE__ */ jsx18(DDropdown, { placement: "bottom-end", trigger: () => /* @__PURE__ */ jsx18(DButton, { variant: "outline", size: "sm", leftIcon: /* @__PURE__ */ jsx18(DownloadIcon, {}), loading, disabled, children: t("export.label") }), children: /* @__PURE__ */ jsx18(ExportContent, { ...props, filename, disabled, setLoading }) });
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// src/form-validation/form.tsx
|
|
1857
|
+
import {
|
|
1858
|
+
createContext as createContext3,
|
|
1859
|
+
useCallback as useCallback3,
|
|
1860
|
+
useContext as useContext3,
|
|
1861
|
+
useEffect as useEffect7,
|
|
1862
|
+
useMemo as useMemo5,
|
|
1863
|
+
useRef as useRef6,
|
|
1864
|
+
useState as useState8
|
|
1865
|
+
} from "react";
|
|
1866
|
+
|
|
1867
|
+
// src/form-validation/validation.ts
|
|
1868
|
+
function issue(key, params, message) {
|
|
1869
|
+
return { key, params, message };
|
|
1870
|
+
}
|
|
1871
|
+
function isEmpty(value) {
|
|
1872
|
+
if (value === void 0 || value === null || value === "" || value === false) return true;
|
|
1873
|
+
if (typeof value === "string") return value.trim() === "";
|
|
1874
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
1875
|
+
if (typeof value === "object") {
|
|
1876
|
+
const entries = Object.values(value);
|
|
1877
|
+
return entries.length === 0 || entries.every(isEmpty);
|
|
1878
|
+
}
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
function optionalEmpty(value) {
|
|
1882
|
+
return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
|
|
1883
|
+
}
|
|
1884
|
+
function required(message) {
|
|
1885
|
+
return (value) => isEmpty(value) ? issue("validation.required", void 0, message) : null;
|
|
1886
|
+
}
|
|
1887
|
+
function accepted(message) {
|
|
1888
|
+
return (value) => value === true || value === "true" || value === 1 ? null : issue("validation.accepted", void 0, message);
|
|
1889
|
+
}
|
|
1890
|
+
function email(message) {
|
|
1891
|
+
const pattern2 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
1892
|
+
return (value) => optionalEmpty(value) || pattern2.test(String(value)) ? null : issue("validation.email", void 0, message);
|
|
1893
|
+
}
|
|
1894
|
+
function url(message) {
|
|
1895
|
+
return (value) => {
|
|
1896
|
+
if (optionalEmpty(value)) return null;
|
|
1897
|
+
try {
|
|
1898
|
+
const parsed = new URL(String(value));
|
|
1899
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:" ? null : issue("validation.url", void 0, message);
|
|
1900
|
+
} catch {
|
|
1901
|
+
return issue("validation.url", void 0, message);
|
|
1902
|
+
}
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
function minLength(min, message) {
|
|
1906
|
+
return (value) => optionalEmpty(value) || String(value).length >= min ? null : issue("validation.minLength", { min }, message);
|
|
1907
|
+
}
|
|
1908
|
+
function maxLength(max, message) {
|
|
1909
|
+
return (value) => optionalEmpty(value) || String(value).length <= max ? null : issue("validation.maxLength", { max }, message);
|
|
1910
|
+
}
|
|
1911
|
+
function minValue(min, message) {
|
|
1912
|
+
return (value) => optionalEmpty(value) || Number.isFinite(Number(value)) && Number(value) >= min ? null : issue("validation.minValue", { min }, message);
|
|
1913
|
+
}
|
|
1914
|
+
function maxValue(max, message) {
|
|
1915
|
+
return (value) => optionalEmpty(value) || Number.isFinite(Number(value)) && Number(value) <= max ? null : issue("validation.maxValue", { max }, message);
|
|
1916
|
+
}
|
|
1917
|
+
function integer(message) {
|
|
1918
|
+
return (value) => optionalEmpty(value) || Number.isInteger(Number(value)) ? null : issue("validation.integer", void 0, message);
|
|
1919
|
+
}
|
|
1920
|
+
function pattern(regex, message) {
|
|
1921
|
+
return (value) => {
|
|
1922
|
+
if (optionalEmpty(value)) return null;
|
|
1923
|
+
regex.lastIndex = 0;
|
|
1924
|
+
return regex.test(String(value)) ? null : issue("validation.pattern", void 0, message);
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
function sameAs(otherField, otherLabel = otherField, message) {
|
|
1928
|
+
return (value, context) => Object.is(value, context.values[otherField]) ? null : issue("validation.sameAs", { otherLabel }, message);
|
|
1929
|
+
}
|
|
1930
|
+
function oneOf(values, message) {
|
|
1931
|
+
return (value) => optionalEmpty(value) || values.some((candidate) => Object.is(candidate, value)) ? null : issue("validation.oneOf", void 0, message);
|
|
1932
|
+
}
|
|
1933
|
+
function date(message) {
|
|
1934
|
+
return (value) => {
|
|
1935
|
+
if (optionalEmpty(value)) return null;
|
|
1936
|
+
const raw = String(value).split("T")[0] ?? "";
|
|
1937
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(raw);
|
|
1938
|
+
if (!match) return issue("validation.date", void 0, message);
|
|
1939
|
+
const year = Number(match[1]);
|
|
1940
|
+
const month = Number(match[2]);
|
|
1941
|
+
const day = Number(match[3]);
|
|
1942
|
+
const parsed = new Date(year, month - 1, day);
|
|
1943
|
+
return parsed.getFullYear() === year && parsed.getMonth() === month - 1 && parsed.getDate() === day ? null : issue("validation.date", void 0, message);
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
function time(message) {
|
|
1947
|
+
return (value) => optionalEmpty(value) || /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(String(value).split("T").pop() ?? "") ? null : issue("validation.time", void 0, message);
|
|
1948
|
+
}
|
|
1949
|
+
function customValidation(rule) {
|
|
1950
|
+
return rule;
|
|
1951
|
+
}
|
|
1952
|
+
async function validateValue(value, rules = [], context = { name: "", label: "Field", values: {} }) {
|
|
1953
|
+
for (const rule of rules) {
|
|
1954
|
+
const result = await rule(value, context);
|
|
1955
|
+
if (!result) continue;
|
|
1956
|
+
if (typeof result === "string") return { message: result };
|
|
1957
|
+
return result;
|
|
1958
|
+
}
|
|
1959
|
+
return null;
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
// src/form-validation/form.tsx
|
|
1963
|
+
import { Fragment as Fragment2, jsx as jsx19 } from "react/jsx-runtime";
|
|
1964
|
+
var FormContext = createContext3(null);
|
|
1965
|
+
function normalizeValidateOn(value) {
|
|
1966
|
+
return typeof value === "string" ? [value] : value ?? ["submit"];
|
|
1967
|
+
}
|
|
1968
|
+
function formatIssue(issue2, label, t) {
|
|
1969
|
+
if (!issue2) return void 0;
|
|
1970
|
+
if (issue2.message) return issue2.message;
|
|
1971
|
+
return t(issue2.key ?? "validation.invalid", { label, ...issue2.params });
|
|
1972
|
+
}
|
|
1973
|
+
function DForm({
|
|
1974
|
+
children,
|
|
1975
|
+
values = {},
|
|
1976
|
+
schema,
|
|
1977
|
+
validateOn,
|
|
1978
|
+
onSubmit,
|
|
1979
|
+
onInvalid,
|
|
1980
|
+
className,
|
|
1981
|
+
...props
|
|
1982
|
+
}) {
|
|
1983
|
+
const { t } = useDLocalization();
|
|
1984
|
+
const [errors, setErrors] = useState8({});
|
|
1985
|
+
const [submitted, setSubmitted] = useState8(false);
|
|
1986
|
+
const fieldsRef = useRef6(/* @__PURE__ */ new Map());
|
|
1987
|
+
const modes = useMemo5(() => normalizeValidateOn(validateOn), [validateOn]);
|
|
1988
|
+
const mergedValues = useCallback3(() => {
|
|
1989
|
+
const next = { ...values };
|
|
1990
|
+
fieldsRef.current.forEach((field, name) => {
|
|
1991
|
+
next[name] = field.value;
|
|
1992
|
+
});
|
|
1993
|
+
return next;
|
|
1994
|
+
}, [values]);
|
|
1995
|
+
const register = useCallback3((name, field) => {
|
|
1996
|
+
fieldsRef.current.set(name, field);
|
|
1997
|
+
}, []);
|
|
1998
|
+
const unregister = useCallback3((name) => {
|
|
1999
|
+
fieldsRef.current.delete(name);
|
|
2000
|
+
}, []);
|
|
2001
|
+
const setFieldError = useCallback3((name, error) => {
|
|
2002
|
+
setErrors((current) => {
|
|
2003
|
+
if (current[name] === error) return current;
|
|
2004
|
+
const next = { ...current };
|
|
2005
|
+
if (error) next[name] = error;
|
|
2006
|
+
else delete next[name];
|
|
2007
|
+
return next;
|
|
2008
|
+
});
|
|
2009
|
+
}, []);
|
|
2010
|
+
const validateField = useCallback3(async (name, override) => {
|
|
2011
|
+
const registered = override ?? fieldsRef.current.get(name);
|
|
2012
|
+
const allValues = mergedValues();
|
|
2013
|
+
const label = registered?.label ?? name ?? t("validation.defaultLabel");
|
|
2014
|
+
const rules = [
|
|
2015
|
+
...schema?.[name] ?? [],
|
|
2016
|
+
...registered?.rules ?? []
|
|
2017
|
+
];
|
|
2018
|
+
const issue2 = await validateValue(registered?.value ?? allValues[name], rules, { name, label, values: allValues });
|
|
2019
|
+
const error = formatIssue(issue2, label, t);
|
|
2020
|
+
setFieldError(name, error);
|
|
2021
|
+
return error;
|
|
2022
|
+
}, [mergedValues, schema, setFieldError, t]);
|
|
2023
|
+
const clearErrors = useCallback3(() => setErrors({}), []);
|
|
2024
|
+
const handleSubmit = async (event) => {
|
|
2025
|
+
event.preventDefault();
|
|
2026
|
+
setSubmitted(true);
|
|
2027
|
+
const allValues = mergedValues();
|
|
2028
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(schema ?? {}), ...fieldsRef.current.keys()]);
|
|
2029
|
+
const nextErrors = {};
|
|
2030
|
+
for (const name of names) {
|
|
2031
|
+
const registered = fieldsRef.current.get(name);
|
|
2032
|
+
const label = registered?.label ?? name ?? t("validation.defaultLabel");
|
|
2033
|
+
const rules = [...schema?.[name] ?? [], ...registered?.rules ?? []];
|
|
2034
|
+
const issue2 = await validateValue(registered?.value ?? allValues[name], rules, { name, label, values: allValues });
|
|
2035
|
+
const error = formatIssue(issue2, label, t);
|
|
2036
|
+
if (error) nextErrors[name] = error;
|
|
2037
|
+
}
|
|
2038
|
+
setErrors(nextErrors);
|
|
2039
|
+
if (Object.keys(nextErrors).length > 0) {
|
|
2040
|
+
onInvalid?.(nextErrors, allValues);
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
await onSubmit?.(allValues);
|
|
2044
|
+
};
|
|
2045
|
+
const context = useMemo5(() => ({
|
|
2046
|
+
values: mergedValues(),
|
|
2047
|
+
errors,
|
|
2048
|
+
schema,
|
|
2049
|
+
validateOn: modes,
|
|
2050
|
+
submitted,
|
|
2051
|
+
register,
|
|
2052
|
+
unregister,
|
|
2053
|
+
validateField,
|
|
2054
|
+
setFieldError,
|
|
2055
|
+
clearErrors
|
|
2056
|
+
}), [clearErrors, errors, mergedValues, modes, register, schema, setFieldError, submitted, unregister, validateField]);
|
|
2057
|
+
const renderProps = {
|
|
2058
|
+
errors,
|
|
2059
|
+
isValid: Object.keys(errors).length === 0,
|
|
2060
|
+
clearErrors
|
|
2061
|
+
};
|
|
2062
|
+
return /* @__PURE__ */ jsx19(FormContext.Provider, { value: context, children: /* @__PURE__ */ jsx19("form", { ...props, noValidate: true, onSubmit: handleSubmit, className, "data-ds-component": "form", children: typeof children === "function" ? children(renderProps) : children }) });
|
|
2063
|
+
}
|
|
2064
|
+
function useDFormField({ name, value, label, rules = [], validateOn }) {
|
|
2065
|
+
const form = useContext3(FormContext);
|
|
2066
|
+
const { t } = useDLocalization();
|
|
2067
|
+
const [localError, setLocalError] = useState8(void 0);
|
|
2068
|
+
const mountedRef = useRef6(false);
|
|
2069
|
+
const localModes = useMemo5(() => normalizeValidateOn(validateOn), [validateOn]);
|
|
2070
|
+
const modes = validateOn ? localModes : form?.validateOn ?? localModes;
|
|
2071
|
+
const resolvedLabel = label ?? name ?? t("validation.defaultLabel");
|
|
2072
|
+
useEffect7(() => {
|
|
2073
|
+
form?.register(name, { value, rules, label: resolvedLabel });
|
|
2074
|
+
return () => form?.unregister(name);
|
|
2075
|
+
}, [form, name, resolvedLabel, rules, value]);
|
|
2076
|
+
const validate = useCallback3(async () => {
|
|
2077
|
+
if (form) return form.validateField(name, { value, rules, label: resolvedLabel });
|
|
2078
|
+
const issue2 = await validateValue(value, rules, { name, label: resolvedLabel, values: { [name]: value } });
|
|
2079
|
+
const error2 = formatIssue(issue2, resolvedLabel, t);
|
|
2080
|
+
setLocalError(error2);
|
|
2081
|
+
return error2;
|
|
2082
|
+
}, [form, name, resolvedLabel, rules, t, value]);
|
|
2083
|
+
useEffect7(() => {
|
|
2084
|
+
if (!mountedRef.current) {
|
|
2085
|
+
mountedRef.current = true;
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
if (modes.includes("change")) void validate();
|
|
2089
|
+
}, [form, modes, validate, value]);
|
|
2090
|
+
const clearError = useCallback3(() => {
|
|
2091
|
+
if (form) form.setFieldError(name, void 0);
|
|
2092
|
+
else setLocalError(void 0);
|
|
2093
|
+
}, [form, name]);
|
|
2094
|
+
const error = form?.errors[name] ?? localError;
|
|
2095
|
+
return {
|
|
2096
|
+
error,
|
|
2097
|
+
invalid: Boolean(error),
|
|
2098
|
+
onBlur: () => {
|
|
2099
|
+
if (modes.includes("blur")) void validate();
|
|
2100
|
+
},
|
|
2101
|
+
validate,
|
|
2102
|
+
clearError
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
function DFormField({ children, ...options }) {
|
|
2106
|
+
return /* @__PURE__ */ jsx19(Fragment2, { children: children(useDFormField(options)) });
|
|
2107
|
+
}
|
|
2108
|
+
function DValidationMessage({ error, className }) {
|
|
2109
|
+
return error ? /* @__PURE__ */ jsx19("p", { role: "alert", className: cn("mt-1.5 text-xs text-[var(--color-danger)]", className), children: error }) : null;
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// src/info-note/info-note.tsx
|
|
2113
|
+
import { jsx as jsx20, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
2114
|
+
function Icon({ type }) {
|
|
2115
|
+
if (type === "warning" || type === "danger") return /* @__PURE__ */ jsxs17("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: [
|
|
2116
|
+
/* @__PURE__ */ jsx20("path", { d: "M12 3 2 21h20L12 3Z" }),
|
|
2117
|
+
/* @__PURE__ */ jsx20("path", { d: "M12 9v4M12 17h.01" })
|
|
2118
|
+
] });
|
|
2119
|
+
if (type === "success") return /* @__PURE__ */ jsxs17("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: [
|
|
2120
|
+
/* @__PURE__ */ jsx20("circle", { cx: "12", cy: "12", r: "9" }),
|
|
2121
|
+
/* @__PURE__ */ jsx20("path", { d: "m8 12 3 3 5-6" })
|
|
2122
|
+
] });
|
|
2123
|
+
if (type === "tip") return /* @__PURE__ */ jsx20("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: /* @__PURE__ */ jsx20("path", { d: "M9 18h6M10 22h4M8.5 14.5A7 7 0 1 1 15.5 14.5C14.5 15.5 14 16 14 18h-4c0-2-.5-2.5-1.5-3.5Z" }) });
|
|
2124
|
+
return /* @__PURE__ */ jsxs17("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: [
|
|
2125
|
+
/* @__PURE__ */ jsx20("circle", { cx: "12", cy: "12", r: "9" }),
|
|
2126
|
+
/* @__PURE__ */ jsx20("path", { d: "M12 10v6M12 7h.01" })
|
|
2127
|
+
] });
|
|
2128
|
+
}
|
|
2129
|
+
var variants2 = {
|
|
2130
|
+
neutral: { wrap: "border-[var(--color-border)] bg-[var(--color-surface-muted)]/60", icon: "bg-[var(--color-text)]/7 text-[var(--color-text-muted)]", title: "text-[var(--color-text)]" },
|
|
2131
|
+
info: { wrap: "border-[var(--color-info)]/20 bg-[var(--color-info)]/5", icon: "bg-[var(--color-info)]/10 text-[var(--color-info)]", title: "text-[var(--color-info)]" },
|
|
2132
|
+
warning: { wrap: "border-[var(--color-warning)]/20 bg-[var(--color-warning)]/5", icon: "bg-[var(--color-warning)]/10 text-[var(--color-warning)]", title: "text-[var(--color-warning)]" },
|
|
2133
|
+
success: { wrap: "border-[var(--color-success)]/20 bg-[var(--color-success)]/5", icon: "bg-[var(--color-success)]/10 text-[var(--color-success)]", title: "text-[var(--color-success)]" },
|
|
2134
|
+
danger: { wrap: "border-[var(--color-danger)]/20 bg-[var(--color-danger)]/5", icon: "bg-[var(--color-danger)]/10 text-[var(--color-danger)]", title: "text-[var(--color-danger)]" },
|
|
2135
|
+
tip: { wrap: "border-[var(--color-brand)]/15 bg-[var(--color-surface-muted)]", icon: "bg-[var(--color-brand)]/10 text-[var(--color-brand)]", title: "text-[var(--color-text)]" }
|
|
2136
|
+
};
|
|
2137
|
+
function DInfoNote({ variant = "info", title, icon, children, className }) {
|
|
2138
|
+
const meta = variants2[variant];
|
|
2139
|
+
return /* @__PURE__ */ jsxs17("div", { role: "note", className: cn("flex items-start gap-3 rounded-2xl border p-3.5", meta.wrap, className), children: [
|
|
2140
|
+
/* @__PURE__ */ jsx20("div", { className: cn("flex size-8 shrink-0 items-center justify-center rounded-lg", meta.icon), children: icon ?? /* @__PURE__ */ jsx20(Icon, { type: variant }) }),
|
|
2141
|
+
/* @__PURE__ */ jsxs17("div", { className: "min-w-0 flex-1 space-y-0.5", children: [
|
|
2142
|
+
title ? /* @__PURE__ */ jsx20("p", { className: cn("text-xs font-semibold", meta.title), children: title }) : null,
|
|
2143
|
+
/* @__PURE__ */ jsx20("div", { className: "text-xs leading-relaxed text-[var(--color-text)]/80", children })
|
|
2144
|
+
] })
|
|
2145
|
+
] });
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
// src/input/input.tsx
|
|
2149
|
+
import {
|
|
2150
|
+
forwardRef as forwardRef3,
|
|
2151
|
+
useEffect as useEffect8,
|
|
2152
|
+
useId as useId4,
|
|
2153
|
+
useLayoutEffect as useLayoutEffect3,
|
|
2154
|
+
useRef as useRef7,
|
|
2155
|
+
useState as useState9
|
|
2156
|
+
} from "react";
|
|
2157
|
+
import { jsx as jsx21, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
2158
|
+
function ClearIcon4({ className }) {
|
|
2159
|
+
return /* @__PURE__ */ jsx21("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className, children: /* @__PURE__ */ jsx21("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
2160
|
+
}
|
|
2161
|
+
function EyeIcon({ closed, className }) {
|
|
2162
|
+
return /* @__PURE__ */ jsxs18("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className, children: [
|
|
2163
|
+
closed ? /* @__PURE__ */ jsx21("path", { d: "m3 3 18 18" }) : null,
|
|
2164
|
+
/* @__PURE__ */ jsx21("path", { d: "M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6S2 12 2 12Z" }),
|
|
2165
|
+
/* @__PURE__ */ jsx21("circle", { cx: "12", cy: "12", r: "2.5" })
|
|
2166
|
+
] });
|
|
2167
|
+
}
|
|
2168
|
+
function InfoIcon({ className }) {
|
|
2169
|
+
return /* @__PURE__ */ jsxs18("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className, children: [
|
|
2170
|
+
/* @__PURE__ */ jsx21("circle", { cx: "12", cy: "12", r: "9" }),
|
|
2171
|
+
/* @__PURE__ */ jsx21("path", { d: "M12 10v6M12 7h.01" })
|
|
2172
|
+
] });
|
|
2173
|
+
}
|
|
2174
|
+
function assignRef(ref, value) {
|
|
2175
|
+
if (typeof ref === "function") ref(value);
|
|
2176
|
+
else if (ref) ref.current = value;
|
|
2177
|
+
}
|
|
2178
|
+
function formatLegacyCurrency(value) {
|
|
2179
|
+
const raw = String(value).replace(/\D/g, "");
|
|
2180
|
+
if (!raw || Number(raw) === 0) return "";
|
|
2181
|
+
return raw.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
2182
|
+
}
|
|
2183
|
+
function eventWithValue(value) {
|
|
2184
|
+
return { target: { value }, currentTarget: { value } };
|
|
2185
|
+
}
|
|
2186
|
+
function countDigitsAfterCaret(value, caret) {
|
|
2187
|
+
if (caret === null) return 0;
|
|
2188
|
+
return value.slice(caret).replace(/\D/g, "").length;
|
|
2189
|
+
}
|
|
2190
|
+
function caretFromDigitsAfter(value, digitsAfter) {
|
|
2191
|
+
if (digitsAfter <= 0) return value.length;
|
|
2192
|
+
let remaining = digitsAfter;
|
|
2193
|
+
for (let index = value.length - 1; index >= 0; index -= 1) {
|
|
2194
|
+
if (/\d/.test(value[index] ?? "")) remaining -= 1;
|
|
2195
|
+
if (remaining === 0) return index;
|
|
2196
|
+
}
|
|
2197
|
+
return 0;
|
|
2198
|
+
}
|
|
2199
|
+
var DInput = forwardRef3(function DInput2({
|
|
2200
|
+
label,
|
|
2201
|
+
labelInfo,
|
|
2202
|
+
error,
|
|
2203
|
+
hint,
|
|
2204
|
+
type = "text",
|
|
2205
|
+
clearable = true,
|
|
2206
|
+
size = "md",
|
|
2207
|
+
onClear,
|
|
2208
|
+
onChange,
|
|
2209
|
+
onNativeChange,
|
|
2210
|
+
leftIcon,
|
|
2211
|
+
rightIcon,
|
|
2212
|
+
leftAdornment,
|
|
2213
|
+
rightAdornment,
|
|
2214
|
+
prefix,
|
|
2215
|
+
suffix,
|
|
2216
|
+
format = "plain",
|
|
2217
|
+
loading = false,
|
|
2218
|
+
containerClassName,
|
|
2219
|
+
className,
|
|
2220
|
+
value,
|
|
2221
|
+
defaultValue,
|
|
2222
|
+
disabled,
|
|
2223
|
+
readOnly,
|
|
2224
|
+
id: externalId,
|
|
2225
|
+
...props
|
|
2226
|
+
}, forwardedRef) {
|
|
2227
|
+
const { t } = useDLocalization();
|
|
2228
|
+
const autoId = useId4();
|
|
2229
|
+
const id = externalId ?? autoId;
|
|
2230
|
+
const inputRef = useRef7(null);
|
|
2231
|
+
const pendingCaretDigitsAfterRef = useRef7(null);
|
|
2232
|
+
const [showPassword, setShowPassword] = useState9(false);
|
|
2233
|
+
const [showTooltip, setShowTooltip] = useState9(false);
|
|
2234
|
+
const [internalValue, setInternalValue] = useState9(() => defaultValue == null ? "" : String(defaultValue));
|
|
2235
|
+
const tooltipRef = useRef7(null);
|
|
2236
|
+
const s = INPUT_SIZE_STYLES[size];
|
|
2237
|
+
const isControlled = value !== void 0;
|
|
2238
|
+
const currentValue = isControlled ? value : internalValue;
|
|
2239
|
+
const inputType = type === "password" && showPassword ? "text" : type === "number" ? "text" : type;
|
|
2240
|
+
const isZero = (type === "number" || format === "currency") && currentValue !== "" && currentValue != null && Number(currentValue) === 0;
|
|
2241
|
+
const hasValue = currentValue !== void 0 && currentValue !== null && currentValue !== "" && !isZero;
|
|
2242
|
+
const showClear = clearable && hasValue && !disabled && !readOnly && !loading;
|
|
2243
|
+
const leadingIcon = leftAdornment ?? leftIcon;
|
|
2244
|
+
const trailingIcon = rightAdornment ?? rightIcon;
|
|
2245
|
+
const resolvedPrefix = prefix ?? (format === "currency" ? "Rp" : void 0);
|
|
2246
|
+
const resolvedSuffix = suffix ?? (format === "percentage" ? "%" : void 0);
|
|
2247
|
+
const hasLeading = Boolean(leadingIcon || resolvedPrefix);
|
|
2248
|
+
const hasTrailing = Boolean(trailingIcon || resolvedSuffix || showClear || type === "password" || loading);
|
|
2249
|
+
useEffect8(() => {
|
|
2250
|
+
const handleClickOutside = (event) => {
|
|
2251
|
+
if (!tooltipRef.current?.contains(event.target)) setShowTooltip(false);
|
|
2252
|
+
};
|
|
2253
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2254
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
2255
|
+
}, []);
|
|
2256
|
+
const displayValue = (() => {
|
|
2257
|
+
if (currentValue === void 0 || currentValue === null) return "";
|
|
2258
|
+
if (type === "number" && (currentValue === 0 || currentValue === "0")) return "";
|
|
2259
|
+
if (format === "currency") return formatLegacyCurrency(currentValue);
|
|
2260
|
+
return String(currentValue);
|
|
2261
|
+
})();
|
|
2262
|
+
useLayoutEffect3(() => {
|
|
2263
|
+
const pending = pendingCaretDigitsAfterRef.current;
|
|
2264
|
+
const input = inputRef.current;
|
|
2265
|
+
if (pending === null || !input || document.activeElement !== input) return;
|
|
2266
|
+
const nextCaret = caretFromDigitsAfter(input.value, pending);
|
|
2267
|
+
input.setSelectionRange(nextCaret, nextCaret);
|
|
2268
|
+
pendingCaretDigitsAfterRef.current = null;
|
|
2269
|
+
}, [displayValue]);
|
|
2270
|
+
const handleChange = (event) => {
|
|
2271
|
+
let next = event.target.value;
|
|
2272
|
+
if (format === "currency") {
|
|
2273
|
+
pendingCaretDigitsAfterRef.current = countDigitsAfterCaret(event.target.value, event.target.selectionStart);
|
|
2274
|
+
next = next.replace(/\D/g, "");
|
|
2275
|
+
} else if (format !== "plain") {
|
|
2276
|
+
next = next.replace(/[^0-9.,-]/g, "");
|
|
2277
|
+
}
|
|
2278
|
+
if (!isControlled) setInternalValue(next);
|
|
2279
|
+
onChange?.(next, event);
|
|
2280
|
+
onNativeChange?.(event);
|
|
2281
|
+
};
|
|
2282
|
+
const handleClear = () => {
|
|
2283
|
+
const event = eventWithValue("");
|
|
2284
|
+
if (!isControlled) setInternalValue("");
|
|
2285
|
+
onClear?.();
|
|
2286
|
+
onChange?.("", event);
|
|
2287
|
+
onNativeChange?.(event);
|
|
2288
|
+
pendingCaretDigitsAfterRef.current = null;
|
|
2289
|
+
inputRef.current?.focus();
|
|
2290
|
+
};
|
|
2291
|
+
return /* @__PURE__ */ jsxs18("div", { "data-ds-component": "input", className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
2292
|
+
label ? /* @__PURE__ */ jsxs18("div", { className: "flex w-fit items-center gap-1.5", children: [
|
|
2293
|
+
/* @__PURE__ */ jsx21("label", { htmlFor: id, className: cn(s.label, "font-medium text-[var(--color-text)]"), children: label }),
|
|
2294
|
+
labelInfo ? /* @__PURE__ */ jsxs18("div", { ref: tooltipRef, className: "group relative flex items-center", children: [
|
|
2295
|
+
/* @__PURE__ */ jsx21("button", { type: "button", "aria-label": t("input.fieldInfo"), "aria-expanded": showTooltip, onClick: () => setShowTooltip((v) => !v), className: "text-[var(--color-text-muted)] hover:text-[var(--color-text)]", children: /* @__PURE__ */ jsx21(InfoIcon, { className: "size-3.5" }) }),
|
|
2296
|
+
/* @__PURE__ */ jsx21("div", { role: "tooltip", className: cn("invisible absolute bottom-full left-1/2 z-50 mb-2 w-max max-w-[220px] -translate-x-1/2 opacity-0 transition-all duration-150 group-hover:visible group-hover:opacity-100", showTooltip && "visible opacity-100"), children: /* @__PURE__ */ jsxs18("div", { className: "relative rounded-lg bg-[var(--color-tooltip)] px-3 py-2 text-xs text-white shadow-lg", children: [
|
|
2297
|
+
labelInfo,
|
|
2298
|
+
/* @__PURE__ */ jsx21("div", { className: "absolute left-1/2 top-full size-0 -translate-x-1/2 border-x-4 border-x-transparent border-t-4 border-t-[var(--color-tooltip)]" })
|
|
2299
|
+
] }) })
|
|
2300
|
+
] }) : null
|
|
2301
|
+
] }) : null,
|
|
2302
|
+
/* @__PURE__ */ jsxs18("div", { className: "relative flex min-w-0 items-center", children: [
|
|
2303
|
+
leadingIcon ? /* @__PURE__ */ jsx21("span", { className: cn("pointer-events-none absolute top-1/2 z-10 -translate-y-1/2 text-[var(--color-text-muted)]", size === "sm" ? "left-2.5 [&_svg]:size-3.5" : "left-3 [&_svg]:size-4"), children: leadingIcon }) : null,
|
|
2304
|
+
resolvedPrefix ? /* @__PURE__ */ jsx21("span", { className: cn("pointer-events-none absolute left-3 top-1/2 z-10 -translate-y-1/2 font-medium text-[var(--color-text-muted)]", size === "sm" ? "text-xs" : "text-sm"), children: resolvedPrefix }) : null,
|
|
2305
|
+
/* @__PURE__ */ jsx21(
|
|
2306
|
+
"input",
|
|
2307
|
+
{
|
|
2308
|
+
...props,
|
|
2309
|
+
ref: (node) => {
|
|
2310
|
+
inputRef.current = node;
|
|
2311
|
+
assignRef(forwardedRef, node);
|
|
2312
|
+
},
|
|
2313
|
+
id,
|
|
2314
|
+
autoComplete: props.autoComplete ?? "off",
|
|
2315
|
+
type: inputType,
|
|
2316
|
+
inputMode: props.inputMode ?? (type === "number" || format !== "plain" ? "numeric" : void 0),
|
|
2317
|
+
value: displayValue,
|
|
2318
|
+
onChange: handleChange,
|
|
2319
|
+
disabled: disabled || loading,
|
|
2320
|
+
readOnly,
|
|
2321
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
2322
|
+
"aria-busy": loading || void 0,
|
|
2323
|
+
className: cn(
|
|
2324
|
+
"w-full min-w-0 rounded-[var(--radius-control)] border bg-[var(--color-surface)] text-[var(--color-text)] transition-colors duration-150 placeholder:text-[var(--color-text-muted)]/60 focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50 read-only:bg-[var(--color-surface-muted)]",
|
|
2325
|
+
s.input,
|
|
2326
|
+
error ? "border-[var(--color-danger)] focus:border-[var(--color-danger)] focus:ring-[var(--color-danger)]/20" : "border-[var(--color-border)]",
|
|
2327
|
+
hasLeading && (size === "sm" ? "pl-8" : "pl-10"),
|
|
2328
|
+
hasTrailing && (size === "sm" ? "pr-8" : "pr-10"),
|
|
2329
|
+
className
|
|
2330
|
+
)
|
|
2331
|
+
}
|
|
2332
|
+
),
|
|
2333
|
+
resolvedSuffix ? /* @__PURE__ */ jsx21("span", { className: cn("pointer-events-none absolute top-1/2 -translate-y-1/2 font-medium text-[var(--color-text-muted)]", size === "sm" ? "right-2.5 text-xs" : "right-3 text-sm"), children: resolvedSuffix }) : null,
|
|
2334
|
+
showClear || type === "password" || trailingIcon || loading ? /* @__PURE__ */ jsxs18("div", { className: cn("absolute top-1/2 flex -translate-y-1/2 items-center text-[var(--color-text-muted)]", size === "sm" ? "right-1.5 gap-0.5" : "right-2 gap-1", resolvedSuffix && "pointer-events-none opacity-0"), children: [
|
|
2335
|
+
loading ? /* @__PURE__ */ jsx21("span", { "aria-label": t("input.loading"), className: "size-4 animate-spin rounded-full border-2 border-current border-t-transparent" }) : null,
|
|
2336
|
+
!loading && showClear ? /* @__PURE__ */ jsx21("button", { type: "button", tabIndex: -1, "aria-label": t("input.clear"), onMouseDown: (event) => event.preventDefault(), onClick: handleClear, className: cn("rounded-md hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]", size === "sm" ? "p-0.5" : "p-1"), children: /* @__PURE__ */ jsx21(ClearIcon4, { className: size === "sm" ? "size-3" : "size-3.5" }) }) : null,
|
|
2337
|
+
!loading && type === "password" ? /* @__PURE__ */ jsx21("button", { type: "button", tabIndex: -1, "aria-label": showPassword ? t("input.hidePassword") : t("input.showPassword"), onMouseDown: (event) => event.preventDefault(), onClick: () => setShowPassword((v) => !v), className: cn("rounded-md hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]", size === "sm" ? "p-0.5" : "p-1"), children: /* @__PURE__ */ jsx21(EyeIcon, { closed: showPassword, className: size === "sm" ? "size-3" : "size-3.5" }) }) : null,
|
|
2338
|
+
!loading && trailingIcon ? /* @__PURE__ */ jsx21("span", { className: "flex items-center", children: trailingIcon }) : null
|
|
2339
|
+
] }) : null
|
|
2340
|
+
] }),
|
|
2341
|
+
error ? /* @__PURE__ */ jsx21("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
2342
|
+
!error && hint ? /* @__PURE__ */ jsx21("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
2343
|
+
] });
|
|
2344
|
+
});
|
|
2345
|
+
DInput.displayName = "DInput";
|
|
2346
|
+
function normalizeDecimalInput(input, { scale = 4, integer: integer2 = false } = {}) {
|
|
2347
|
+
const decimalIndex = Math.max(input.lastIndexOf("."), input.lastIndexOf(","));
|
|
2348
|
+
const hasDecimal = !integer2 && decimalIndex >= 0;
|
|
2349
|
+
const rawWhole = (hasDecimal ? input.slice(0, decimalIndex) : input).replace(/\D/g, "");
|
|
2350
|
+
const rawFraction = hasDecimal ? input.slice(decimalIndex + 1).replace(/\D/g, "") : "";
|
|
2351
|
+
const whole = rawWhole.replace(/^0+(?=\d)/, "");
|
|
2352
|
+
if (!hasDecimal) return whole;
|
|
2353
|
+
return `${whole || "0"}.${rawFraction.slice(0, Math.max(0, scale))}`;
|
|
2354
|
+
}
|
|
2355
|
+
var DDecimalInput = forwardRef3(function DDecimalInput2({ value, onValueChange, scale = 4, integer: integer2 = false, ...props }, ref) {
|
|
2356
|
+
return /* @__PURE__ */ jsx21(DInput, { ref, ...props, value, type: "text", inputMode: integer2 ? "numeric" : "decimal", onNativeChange: (event) => onValueChange(normalizeDecimalInput(event.target.value, { scale, integer: integer2 })) });
|
|
2357
|
+
});
|
|
2358
|
+
function formatCurrencyInputValue(value, { groupSeparator = ".", decimalSeparator = "," } = {}) {
|
|
2359
|
+
if (!value) return "";
|
|
2360
|
+
const normalized = normalizeDecimalInput(value);
|
|
2361
|
+
const [whole = "", fraction] = normalized.split(".");
|
|
2362
|
+
const grouped = (whole || "0").replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
|
|
2363
|
+
return fraction === void 0 ? grouped : `${grouped}${decimalSeparator}${fraction}`;
|
|
2364
|
+
}
|
|
2365
|
+
function parseCurrencyInputValue(value, { groupSeparator = ".", decimalSeparator = "," } = {}) {
|
|
2366
|
+
const normalized = String(value).trim();
|
|
2367
|
+
if (!normalized) return "";
|
|
2368
|
+
const decimalIndex = normalized.lastIndexOf(decimalSeparator);
|
|
2369
|
+
const hasDecimal = decimalIndex >= 0;
|
|
2370
|
+
const wholeSource = hasDecimal ? normalized.slice(0, decimalIndex) : normalized;
|
|
2371
|
+
const fractionSource = hasDecimal ? normalized.slice(decimalIndex + decimalSeparator.length) : "";
|
|
2372
|
+
const whole = wholeSource.split(groupSeparator).join("").replace(/\D/g, "").replace(/^0+(?=\d)/, "");
|
|
2373
|
+
const fraction = fractionSource.replace(/\D/g, "");
|
|
2374
|
+
if (!hasDecimal) return whole;
|
|
2375
|
+
return `${whole || "0"}.${fraction}`;
|
|
2376
|
+
}
|
|
2377
|
+
var DCurrencyInput = forwardRef3(function DCurrencyInput2({
|
|
2378
|
+
value,
|
|
2379
|
+
onValueChange,
|
|
2380
|
+
currencySymbol = "Rp",
|
|
2381
|
+
groupSeparator = ".",
|
|
2382
|
+
decimalSeparator = ",",
|
|
2383
|
+
...props
|
|
2384
|
+
}, forwardedRef) {
|
|
2385
|
+
const inputRef = useRef7(null);
|
|
2386
|
+
const pendingCaretDigitsAfterRef = useRef7(null);
|
|
2387
|
+
const displayed = formatCurrencyInputValue(value, { groupSeparator, decimalSeparator });
|
|
2388
|
+
useLayoutEffect3(() => {
|
|
2389
|
+
const pending = pendingCaretDigitsAfterRef.current;
|
|
2390
|
+
const input = inputRef.current;
|
|
2391
|
+
if (pending === null || !input || document.activeElement !== input) return;
|
|
2392
|
+
const nextCaret = caretFromDigitsAfter(input.value, pending);
|
|
2393
|
+
input.setSelectionRange(nextCaret, nextCaret);
|
|
2394
|
+
pendingCaretDigitsAfterRef.current = null;
|
|
2395
|
+
}, [displayed]);
|
|
2396
|
+
return /* @__PURE__ */ jsx21(
|
|
2397
|
+
DInput,
|
|
2398
|
+
{
|
|
2399
|
+
ref: (node) => {
|
|
2400
|
+
inputRef.current = node;
|
|
2401
|
+
assignRef(forwardedRef, node);
|
|
2402
|
+
},
|
|
2403
|
+
...props,
|
|
2404
|
+
value: displayed,
|
|
2405
|
+
type: "text",
|
|
2406
|
+
inputMode: "decimal",
|
|
2407
|
+
prefix: currencySymbol,
|
|
2408
|
+
onNativeChange: (event) => {
|
|
2409
|
+
pendingCaretDigitsAfterRef.current = countDigitsAfterCaret(event.target.value, event.target.selectionStart);
|
|
2410
|
+
onValueChange(parseCurrencyInputValue(event.target.value, { groupSeparator, decimalSeparator }));
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
);
|
|
2414
|
+
});
|
|
2415
|
+
|
|
2416
|
+
// src/loading/loading.tsx
|
|
2417
|
+
import { jsx as jsx22, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
2418
|
+
function DLoadingIndicator({ label, className }) {
|
|
2419
|
+
const { t } = useDLocalization();
|
|
2420
|
+
return /* @__PURE__ */ jsxs19("div", { role: "status", className: cn("inline-flex items-center gap-2 text-sm text-[var(--color-text-muted)]", className), children: [
|
|
2421
|
+
/* @__PURE__ */ jsx22("span", { className: "size-4 animate-spin rounded-full border-2 border-[var(--color-brand)] border-t-transparent" }),
|
|
2422
|
+
label ?? t("loading.default")
|
|
2423
|
+
] });
|
|
2424
|
+
}
|
|
2425
|
+
function DLoadingOverlay({ label }) {
|
|
2426
|
+
return /* @__PURE__ */ jsx22("div", { className: "fixed inset-0 z-[90] grid place-items-center bg-[var(--color-background)]/75 backdrop-blur-sm", children: /* @__PURE__ */ jsx22(DLoadingIndicator, { label }) });
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// src/notification-panel/notification-panel.tsx
|
|
2430
|
+
import { useEffect as useEffect9, useRef as useRef8 } from "react";
|
|
2431
|
+
import { createPortal as createPortal3 } from "react-dom";
|
|
2432
|
+
import { jsx as jsx23, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
2433
|
+
var dotClass = {
|
|
2434
|
+
info: "bg-[var(--color-info)]",
|
|
2435
|
+
success: "bg-[var(--color-success)]",
|
|
2436
|
+
warning: "bg-[var(--color-warning)]",
|
|
2437
|
+
error: "bg-[var(--color-danger)]"
|
|
2438
|
+
};
|
|
2439
|
+
var iconButtonClass = "grid size-8 appearance-none place-items-center rounded-lg border-0 bg-transparent p-0 text-[var(--color-text-muted)] shadow-none outline-none transition-colors hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--color-focus)]/25";
|
|
2440
|
+
function DNotificationPanel({
|
|
2441
|
+
notifications,
|
|
2442
|
+
open,
|
|
2443
|
+
onClose,
|
|
2444
|
+
onMarkRead,
|
|
2445
|
+
onMarkAllRead,
|
|
2446
|
+
onDismiss,
|
|
2447
|
+
anchorRef,
|
|
2448
|
+
title,
|
|
2449
|
+
emptyMessage,
|
|
2450
|
+
className,
|
|
2451
|
+
offset = 8,
|
|
2452
|
+
scrollBehavior = "reposition"
|
|
2453
|
+
}) {
|
|
2454
|
+
const { t } = useDLocalization();
|
|
2455
|
+
const resolvedTitle = title ?? t("notification.title");
|
|
2456
|
+
const resolvedEmptyMessage = emptyMessage ?? t("notification.empty");
|
|
2457
|
+
const floatingRef = useRef8(null);
|
|
2458
|
+
const emptyReference = useRef8(null);
|
|
2459
|
+
const referenceRef = anchorRef ?? emptyReference;
|
|
2460
|
+
const hasAnchor = Boolean(anchorRef);
|
|
2461
|
+
const { style, positioned } = useFloatingPosition({
|
|
2462
|
+
open: open && hasAnchor,
|
|
2463
|
+
referenceRef,
|
|
2464
|
+
floatingRef,
|
|
2465
|
+
placement: "bottom-end",
|
|
2466
|
+
matchWidth: false,
|
|
2467
|
+
minWidth: 320,
|
|
2468
|
+
offset,
|
|
2469
|
+
scrollBehavior,
|
|
2470
|
+
onRequestClose: onClose
|
|
2471
|
+
});
|
|
2472
|
+
useEffect9(() => {
|
|
2473
|
+
if (!open) return;
|
|
2474
|
+
const onPointerDown = (event) => {
|
|
2475
|
+
const target = event.target;
|
|
2476
|
+
if (floatingRef.current?.contains(target) || anchorRef?.current?.contains(target)) return;
|
|
2477
|
+
onClose();
|
|
2478
|
+
};
|
|
2479
|
+
const onKeyDown = (event) => {
|
|
2480
|
+
if (event.key === "Escape") {
|
|
2481
|
+
event.preventDefault();
|
|
2482
|
+
onClose();
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
2486
|
+
document.addEventListener("keydown", onKeyDown);
|
|
2487
|
+
return () => {
|
|
2488
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
2489
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
2490
|
+
};
|
|
2491
|
+
}, [anchorRef, onClose, open]);
|
|
2492
|
+
if (!open || typeof document === "undefined") return null;
|
|
2493
|
+
const unread = notifications.filter((item) => !item.read).length;
|
|
2494
|
+
const fallbackStyle = { position: "fixed", top: 72, right: 24, zIndex: 9999, visibility: "visible" };
|
|
2495
|
+
return createPortal3(
|
|
2496
|
+
/* @__PURE__ */ jsxs20(
|
|
2497
|
+
"div",
|
|
2498
|
+
{
|
|
2499
|
+
ref: floatingRef,
|
|
2500
|
+
role: "dialog",
|
|
2501
|
+
"aria-label": resolvedTitle,
|
|
2502
|
+
"data-ds-component": "notification-panel",
|
|
2503
|
+
"data-ds-surface": "floating",
|
|
2504
|
+
"data-positioned": hasAnchor ? positioned ? "true" : "false" : "fallback",
|
|
2505
|
+
"data-scroll-behavior": scrollBehavior,
|
|
2506
|
+
style: hasAnchor ? style : fallbackStyle,
|
|
2507
|
+
className: cn(
|
|
2508
|
+
"w-[min(24rem,calc(100vw-16px))] overflow-hidden rounded-[var(--radius-panel)] border border-[var(--color-border)] bg-[var(--color-surface)] shadow-[var(--shadow-lg)]",
|
|
2509
|
+
hasAnchor && positioned && "animate-[dropdown-in_150ms_ease-out]",
|
|
2510
|
+
className
|
|
2511
|
+
),
|
|
2512
|
+
children: [
|
|
2513
|
+
/* @__PURE__ */ jsxs20("div", { className: "flex min-h-12 items-center justify-between border-b border-[var(--color-border)] px-4 py-2", children: [
|
|
2514
|
+
/* @__PURE__ */ jsxs20("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
2515
|
+
/* @__PURE__ */ jsx23("span", { className: "truncate text-sm font-semibold text-[var(--color-text)]", children: resolvedTitle }),
|
|
2516
|
+
unread > 0 ? /* @__PURE__ */ jsx23("span", { className: "flex h-5 min-w-5 items-center justify-center rounded-full bg-[var(--color-brand)] px-1.5 text-[10px] font-bold text-[var(--color-brand-foreground)]", children: unread }) : null
|
|
2517
|
+
] }),
|
|
2518
|
+
/* @__PURE__ */ jsxs20("div", { className: "flex shrink-0 items-center gap-0.5", children: [
|
|
2519
|
+
unread > 0 ? /* @__PURE__ */ jsx23("button", { type: "button", "aria-label": t("notification.markAllRead"), onClick: onMarkAllRead, className: iconButtonClass, children: /* @__PURE__ */ jsx23(CheckIcon, { size: 15 }) }) : null,
|
|
2520
|
+
/* @__PURE__ */ jsx23("button", { type: "button", "aria-label": t("notification.close"), onClick: onClose, className: iconButtonClass, children: /* @__PURE__ */ jsx23(XIcon, { size: 15 }) })
|
|
2521
|
+
] })
|
|
2522
|
+
] }),
|
|
2523
|
+
/* @__PURE__ */ jsx23("div", { className: "flex max-h-[min(24rem,60vh)] flex-col gap-1.5 overflow-y-auto p-2", children: notifications.length === 0 ? /* @__PURE__ */ jsx23("div", { className: "px-4 py-10 text-center text-sm text-[var(--color-text-muted)]", children: resolvedEmptyMessage }) : notifications.map((item) => /* @__PURE__ */ jsxs20(
|
|
2524
|
+
"div",
|
|
2525
|
+
{
|
|
2526
|
+
className: cn(
|
|
2527
|
+
"group flex items-start gap-1 rounded-[var(--radius-menu-item)] px-1 py-0.5 transition-colors hover:bg-[var(--color-surface-muted)]/65",
|
|
2528
|
+
!item.read && "bg-[var(--color-brand)]/5"
|
|
2529
|
+
),
|
|
2530
|
+
children: [
|
|
2531
|
+
/* @__PURE__ */ jsxs20(
|
|
2532
|
+
"button",
|
|
2533
|
+
{
|
|
2534
|
+
type: "button",
|
|
2535
|
+
onClick: () => onMarkRead(item.id),
|
|
2536
|
+
className: "flex min-w-0 flex-1 appearance-none items-start gap-3 rounded-[var(--radius-menu-item)] border-0 bg-transparent px-2 py-2 text-left shadow-none outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--color-focus)]/25",
|
|
2537
|
+
children: [
|
|
2538
|
+
/* @__PURE__ */ jsx23("span", { className: cn("mt-1.5 size-2 shrink-0 rounded-full", !item.read ? dotClass[item.type] : "bg-transparent") }),
|
|
2539
|
+
/* @__PURE__ */ jsxs20("span", { className: "min-w-0 flex-1", children: [
|
|
2540
|
+
/* @__PURE__ */ jsx23("span", { className: "block truncate text-sm font-medium text-[var(--color-text)]", children: item.title }),
|
|
2541
|
+
/* @__PURE__ */ jsx23("span", { className: "mt-0.5 line-clamp-2 block text-xs leading-5 text-[var(--color-text-muted)]", children: item.message }),
|
|
2542
|
+
/* @__PURE__ */ jsx23("span", { className: "mt-1 block text-[10px] text-[var(--color-text-muted)]/70", children: item.createdAt })
|
|
2543
|
+
] })
|
|
2544
|
+
]
|
|
2545
|
+
}
|
|
2546
|
+
),
|
|
2547
|
+
/* @__PURE__ */ jsx23(
|
|
2548
|
+
"button",
|
|
2549
|
+
{
|
|
2550
|
+
type: "button",
|
|
2551
|
+
"aria-label": t("notification.dismiss", { title: item.title }),
|
|
2552
|
+
onClick: () => onDismiss(item.id),
|
|
2553
|
+
className: "mt-1 grid size-7 shrink-0 appearance-none place-items-center rounded-md border-0 bg-transparent p-0 text-[var(--color-text-muted)]/55 opacity-65 shadow-none outline-none transition-colors hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--color-focus)]/25 group-hover:opacity-100",
|
|
2554
|
+
children: /* @__PURE__ */ jsx23(XIcon, { size: 13 })
|
|
2555
|
+
}
|
|
2556
|
+
)
|
|
2557
|
+
]
|
|
2558
|
+
},
|
|
2559
|
+
item.id
|
|
2560
|
+
)) })
|
|
2561
|
+
]
|
|
2562
|
+
}
|
|
2563
|
+
),
|
|
2564
|
+
document.body
|
|
2565
|
+
);
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
// src/progress/progress.tsx
|
|
2569
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
2570
|
+
function clampProgress(value) {
|
|
2571
|
+
return Math.min(100, Math.max(0, value));
|
|
2572
|
+
}
|
|
2573
|
+
function DProgress({ value, label, className, ...props }) {
|
|
2574
|
+
const isIndeterminate = value === void 0;
|
|
2575
|
+
const percentage = isIndeterminate ? void 0 : clampProgress(value);
|
|
2576
|
+
return /* @__PURE__ */ jsx24(
|
|
2577
|
+
"div",
|
|
2578
|
+
{
|
|
2579
|
+
role: "progressbar",
|
|
2580
|
+
"aria-label": label,
|
|
2581
|
+
"aria-valuemin": isIndeterminate ? void 0 : 0,
|
|
2582
|
+
"aria-valuemax": isIndeterminate ? void 0 : 100,
|
|
2583
|
+
"aria-valuenow": percentage,
|
|
2584
|
+
className: cn(
|
|
2585
|
+
"relative h-2 w-full overflow-hidden rounded-full bg-[var(--color-surface-muted)]",
|
|
2586
|
+
className
|
|
2587
|
+
),
|
|
2588
|
+
...props,
|
|
2589
|
+
children: /* @__PURE__ */ jsx24(
|
|
2590
|
+
"span",
|
|
2591
|
+
{
|
|
2592
|
+
className: cn(
|
|
2593
|
+
"block h-full rounded-full bg-[var(--color-brand)] transition-[width] duration-200",
|
|
2594
|
+
isIndeterminate && "w-2/5 animate-[boot-progress_1.2s_ease-in-out_infinite]"
|
|
2595
|
+
),
|
|
2596
|
+
style: isIndeterminate ? void 0 : { width: `${percentage}%` }
|
|
2597
|
+
}
|
|
2598
|
+
)
|
|
2599
|
+
}
|
|
2600
|
+
);
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
// src/range-date-picker/range-date-picker.tsx
|
|
2604
|
+
import { useEffect as useEffect10, useId as useId5, useMemo as useMemo6, useState as useState10 } from "react";
|
|
2605
|
+
import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
2606
|
+
var formatDate = (date2) => `${date2.getFullYear()}-${String(date2.getMonth() + 1).padStart(2, "0")}-${String(date2.getDate()).padStart(2, "0")}`;
|
|
2607
|
+
var parseDate2 = (value) => value ? /* @__PURE__ */ new Date(`${value}T00:00:00`) : null;
|
|
2608
|
+
var startOfMonth = (date2) => new Date(date2.getFullYear(), date2.getMonth(), 1);
|
|
2609
|
+
var addMonth = (date2, amount) => new Date(date2.getFullYear(), date2.getMonth() + amount, 1);
|
|
2610
|
+
var isSameDate = (a, b) => Boolean(a && b && formatDate(a) === formatDate(b));
|
|
2611
|
+
var getStartOfWeek = (date2) => {
|
|
2612
|
+
const result = new Date(date2);
|
|
2613
|
+
const day = result.getDay();
|
|
2614
|
+
result.setDate(result.getDate() + (day === 0 ? -6 : 1 - day));
|
|
2615
|
+
result.setHours(0, 0, 0, 0);
|
|
2616
|
+
return result;
|
|
2617
|
+
};
|
|
2618
|
+
var getEndOfWeek = (date2) => {
|
|
2619
|
+
const result = getStartOfWeek(date2);
|
|
2620
|
+
result.setDate(result.getDate() + 6);
|
|
2621
|
+
return result;
|
|
2622
|
+
};
|
|
2623
|
+
var getStartOfMonth = (date2) => new Date(date2.getFullYear(), date2.getMonth(), 1);
|
|
2624
|
+
var getEndOfMonth = (date2) => new Date(date2.getFullYear(), date2.getMonth() + 1, 0);
|
|
2625
|
+
var getStartOfYear = (date2) => new Date(date2.getFullYear(), 0, 1);
|
|
2626
|
+
var getEndOfYear = (date2) => new Date(date2.getFullYear(), 11, 31);
|
|
2627
|
+
var QUICK_RANGE_TYPES = ["today", "yesterday", "this_week", "last_week", "this_month", "last_month", "this_year", "last_year", "all_time"];
|
|
2628
|
+
var QUICK_RANGE_KEYS = {
|
|
2629
|
+
today: "rangeDatePicker.today",
|
|
2630
|
+
yesterday: "rangeDatePicker.yesterday",
|
|
2631
|
+
this_week: "rangeDatePicker.thisWeek",
|
|
2632
|
+
last_week: "rangeDatePicker.lastWeek",
|
|
2633
|
+
this_month: "rangeDatePicker.thisMonth",
|
|
2634
|
+
last_month: "rangeDatePicker.lastMonth",
|
|
2635
|
+
this_year: "rangeDatePicker.thisYear",
|
|
2636
|
+
last_year: "rangeDatePicker.lastYear",
|
|
2637
|
+
all_time: "rangeDatePicker.allTime"
|
|
2638
|
+
};
|
|
2639
|
+
function quickRange(type) {
|
|
2640
|
+
const now = /* @__PURE__ */ new Date();
|
|
2641
|
+
if (type === "today") return { start: now, end: now };
|
|
2642
|
+
if (type === "yesterday") {
|
|
2643
|
+
const date2 = new Date(now);
|
|
2644
|
+
date2.setDate(date2.getDate() - 1);
|
|
2645
|
+
return { start: date2, end: new Date(date2) };
|
|
2646
|
+
}
|
|
2647
|
+
if (type === "this_week") return { start: getStartOfWeek(now), end: getEndOfWeek(now) };
|
|
2648
|
+
if (type === "last_week") {
|
|
2649
|
+
const date2 = new Date(now);
|
|
2650
|
+
date2.setDate(date2.getDate() - 7);
|
|
2651
|
+
return { start: getStartOfWeek(date2), end: getEndOfWeek(date2) };
|
|
2652
|
+
}
|
|
2653
|
+
if (type === "this_month") return { start: getStartOfMonth(now), end: getEndOfMonth(now) };
|
|
2654
|
+
if (type === "last_month") {
|
|
2655
|
+
const date2 = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
2656
|
+
return { start: getStartOfMonth(date2), end: getEndOfMonth(date2) };
|
|
2657
|
+
}
|
|
2658
|
+
if (type === "this_year") return { start: getStartOfYear(now), end: getEndOfYear(now) };
|
|
2659
|
+
if (type === "last_year") {
|
|
2660
|
+
const date2 = new Date(now.getFullYear() - 1, 0, 1);
|
|
2661
|
+
return { start: getStartOfYear(date2), end: getEndOfYear(date2) };
|
|
2662
|
+
}
|
|
2663
|
+
return { start: null, end: null };
|
|
2664
|
+
}
|
|
2665
|
+
function getQuickActive(type, start, end) {
|
|
2666
|
+
if (type === "all_time") return !start && !end;
|
|
2667
|
+
const target = quickRange(type);
|
|
2668
|
+
return isSameDate(start, target.start) && isSameDate(end, target.end);
|
|
2669
|
+
}
|
|
2670
|
+
function ChevronIcon({ direction }) {
|
|
2671
|
+
return /* @__PURE__ */ jsx25("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: /* @__PURE__ */ jsx25("path", { d: direction === "left" ? "m15 18-6-6 6-6" : "m9 18 6-6-6-6" }) });
|
|
2672
|
+
}
|
|
2673
|
+
function CalendarIcon2() {
|
|
2674
|
+
return /* @__PURE__ */ jsxs21("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: [
|
|
2675
|
+
/* @__PURE__ */ jsx25("rect", { x: "3", y: "5", width: "18", height: "16", rx: "2" }),
|
|
2676
|
+
/* @__PURE__ */ jsx25("path", { d: "M16 3v4M8 3v4M3 10h18" })
|
|
2677
|
+
] });
|
|
2678
|
+
}
|
|
2679
|
+
function ChevronDownIcon2({ open }) {
|
|
2680
|
+
return /* @__PURE__ */ jsx25("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: cn("size-3.5 transition-transform", open && "rotate-180"), children: /* @__PURE__ */ jsx25("path", { d: "m6 9 6 6 6-6" }) });
|
|
2681
|
+
}
|
|
2682
|
+
function ClearIcon5() {
|
|
2683
|
+
return /* @__PURE__ */ jsx25("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx25("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
2684
|
+
}
|
|
2685
|
+
function CheckIcon2() {
|
|
2686
|
+
return /* @__PURE__ */ jsx25("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx25("path", { d: "m5 12 4 4L19 6" }) });
|
|
2687
|
+
}
|
|
2688
|
+
function RangeDropdownContent({ value, onChange }) {
|
|
2689
|
+
const close = useDropdownClose();
|
|
2690
|
+
const { locale, t } = useDLocalization();
|
|
2691
|
+
const days = useMemo6(() => getLocalizedWeekdayNames(locale, "short"), [locale]);
|
|
2692
|
+
const months = useMemo6(() => getLocalizedMonthNames(locale), [locale]);
|
|
2693
|
+
const today = useMemo6(() => /* @__PURE__ */ new Date(), []);
|
|
2694
|
+
const selectedStart = useMemo6(() => parseDate2(value?.start), [value?.start]);
|
|
2695
|
+
const selectedEnd = useMemo6(() => parseDate2(value?.end), [value?.end]);
|
|
2696
|
+
const [tempStart, setTempStart] = useState10(selectedStart);
|
|
2697
|
+
const [tempEnd, setTempEnd] = useState10(selectedEnd);
|
|
2698
|
+
const [quickType, setQuickType] = useState10(null);
|
|
2699
|
+
const [leftMonth, setLeftMonth] = useState10(() => startOfMonth(selectedStart || today));
|
|
2700
|
+
const rightMonth = useMemo6(() => addMonth(leftMonth, 1), [leftMonth]);
|
|
2701
|
+
const syncTempFromValue = () => {
|
|
2702
|
+
const nextStart = parseDate2(value?.start);
|
|
2703
|
+
const nextEnd = parseDate2(value?.end);
|
|
2704
|
+
setTempStart(nextStart);
|
|
2705
|
+
setTempEnd(nextEnd);
|
|
2706
|
+
setQuickType(null);
|
|
2707
|
+
setLeftMonth(startOfMonth(nextStart || today));
|
|
2708
|
+
};
|
|
2709
|
+
useEffect10(() => {
|
|
2710
|
+
syncTempFromValue();
|
|
2711
|
+
}, [value?.start, value?.end]);
|
|
2712
|
+
const selectDate = (date2) => {
|
|
2713
|
+
setQuickType(null);
|
|
2714
|
+
if (!tempStart || tempEnd || date2 < tempStart) {
|
|
2715
|
+
setTempStart(date2);
|
|
2716
|
+
setTempEnd(null);
|
|
2717
|
+
setLeftMonth(startOfMonth(date2));
|
|
2718
|
+
return;
|
|
2719
|
+
}
|
|
2720
|
+
setTempEnd(date2);
|
|
2721
|
+
};
|
|
2722
|
+
const selectQuick = (type) => {
|
|
2723
|
+
const range = quickRange(type);
|
|
2724
|
+
setQuickType(type);
|
|
2725
|
+
setTempStart(range.start);
|
|
2726
|
+
setTempEnd(range.end);
|
|
2727
|
+
setLeftMonth(startOfMonth(range.start || today));
|
|
2728
|
+
};
|
|
2729
|
+
const apply = () => {
|
|
2730
|
+
if (quickType === "all_time") {
|
|
2731
|
+
onChange?.({ start: void 0, end: void 0 });
|
|
2732
|
+
close?.();
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2735
|
+
if (!tempStart || !tempEnd) return;
|
|
2736
|
+
onChange?.({ start: formatDate(tempStart), end: formatDate(tempEnd) });
|
|
2737
|
+
close?.();
|
|
2738
|
+
};
|
|
2739
|
+
const renderCalendar = (monthDate, side) => {
|
|
2740
|
+
const year = monthDate.getFullYear();
|
|
2741
|
+
const month = monthDate.getMonth();
|
|
2742
|
+
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
2743
|
+
const firstDay = new Date(year, month, 1).getDay();
|
|
2744
|
+
return /* @__PURE__ */ jsxs21("div", { className: "min-w-0 flex-1", children: [
|
|
2745
|
+
/* @__PURE__ */ jsxs21("div", { className: "mb-2 flex items-center justify-between", children: [
|
|
2746
|
+
side === "left" ? /* @__PURE__ */ jsx25("button", { type: "button", "aria-label": t("common.previousMonth"), onClick: () => setLeftMonth((prev) => addMonth(prev, -1)), className: "flex size-7 items-center justify-center rounded-lg text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]", children: /* @__PURE__ */ jsx25(ChevronIcon, { direction: "left" }) }) : /* @__PURE__ */ jsx25("div", { className: "size-7" }),
|
|
2747
|
+
/* @__PURE__ */ jsxs21("span", { className: "text-xs font-semibold text-[var(--color-text)] sm:text-sm", children: [
|
|
2748
|
+
months[month],
|
|
2749
|
+
" ",
|
|
2750
|
+
year
|
|
2751
|
+
] }),
|
|
2752
|
+
side === "right" ? /* @__PURE__ */ jsx25("button", { type: "button", "aria-label": t("common.nextMonth"), onClick: () => setLeftMonth((prev) => addMonth(prev, 1)), className: "flex size-7 items-center justify-center rounded-lg text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]", children: /* @__PURE__ */ jsx25(ChevronIcon, { direction: "right" }) }) : /* @__PURE__ */ jsx25("button", { type: "button", "aria-label": t("common.nextMonth"), onClick: () => setLeftMonth((prev) => addMonth(prev, 1)), className: "flex size-7 items-center justify-center rounded-lg text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] sm:invisible", children: /* @__PURE__ */ jsx25(ChevronIcon, { direction: "right" }) })
|
|
2753
|
+
] }),
|
|
2754
|
+
/* @__PURE__ */ jsx25("div", { className: "mb-1.5 grid grid-cols-7 gap-0.5 text-[10px] text-[var(--color-text-muted)] sm:text-xs", children: days.map((day) => /* @__PURE__ */ jsx25("div", { className: "text-center font-medium", children: day }, `${side}-${day}`)) }),
|
|
2755
|
+
/* @__PURE__ */ jsxs21("div", { className: "grid grid-cols-7 gap-0.5", children: [
|
|
2756
|
+
Array.from({ length: firstDay }).map((_, index) => /* @__PURE__ */ jsx25("div", {}, `${side}-empty-${index}`)),
|
|
2757
|
+
Array.from({ length: daysInMonth }, (_, index) => {
|
|
2758
|
+
const date2 = new Date(year, month, index + 1);
|
|
2759
|
+
const start = isSameDate(date2, tempStart);
|
|
2760
|
+
const end = isSameDate(date2, tempEnd);
|
|
2761
|
+
const selected = start || end;
|
|
2762
|
+
const inRange = Boolean(tempStart && tempEnd && date2 > tempStart && date2 < tempEnd);
|
|
2763
|
+
const isToday = isSameDate(date2, today);
|
|
2764
|
+
return /* @__PURE__ */ jsx25("button", { type: "button", onClick: () => selectDate(date2), className: cn("h-8 rounded-md text-xs transition-colors sm:h-8 sm:text-sm", selected && "bg-[var(--color-brand)] font-semibold text-white", !selected && inRange && "bg-[var(--color-brand)]/10 text-[var(--color-brand)]", !selected && !inRange && "hover:bg-[var(--color-surface-muted)]", !selected && isToday && "ring-1 ring-[var(--color-brand)]/40"), children: index + 1 }, `${side}-${formatDate(date2)}`);
|
|
2765
|
+
})
|
|
2766
|
+
] })
|
|
2767
|
+
] });
|
|
2768
|
+
};
|
|
2769
|
+
const summary = tempStart && tempEnd ? `${formatDate(tempStart)} \u2014 ${formatDate(tempEnd)}` : quickType === "all_time" ? t("rangeDatePicker.summaryAllTime") : t("rangeDatePicker.summarySelect");
|
|
2770
|
+
return /* @__PURE__ */ jsxs21("div", { className: "w-[min(560px,calc(100vw-16px))] p-3", children: [
|
|
2771
|
+
/* @__PURE__ */ jsxs21("div", { className: "mb-3", children: [
|
|
2772
|
+
/* @__PURE__ */ jsxs21("div", { className: "mb-2 flex items-center justify-between", children: [
|
|
2773
|
+
/* @__PURE__ */ jsx25("p", { className: "text-xs font-semibold text-[var(--color-text)]", children: t("rangeDatePicker.quickRange") }),
|
|
2774
|
+
/* @__PURE__ */ jsx25("span", { className: "text-[10px] text-[var(--color-text-muted)]", children: t("common.optional") })
|
|
2775
|
+
] }),
|
|
2776
|
+
/* @__PURE__ */ jsx25("div", { className: "grid grid-cols-3 gap-1 sm:grid-cols-5", children: QUICK_RANGE_TYPES.map((type) => /* @__PURE__ */ jsx25("button", { type: "button", onClick: () => selectQuick(type), className: cn("min-h-8 rounded-lg px-2 py-1.5 text-center text-[11px] font-medium leading-tight transition-colors", getQuickActive(type, tempStart, tempEnd) ? "bg-[var(--color-brand)]/10 text-[var(--color-brand)]" : "bg-[var(--color-surface-muted)]/55 text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]"), children: t(QUICK_RANGE_KEYS[type]) }, type)) })
|
|
2777
|
+
] }),
|
|
2778
|
+
/* @__PURE__ */ jsxs21("div", { className: "grid gap-3 border-t border-[var(--color-border)] pt-3 sm:grid-cols-2", children: [
|
|
2779
|
+
renderCalendar(leftMonth, "left"),
|
|
2780
|
+
renderCalendar(rightMonth, "right")
|
|
2781
|
+
] }),
|
|
2782
|
+
/* @__PURE__ */ jsxs21("div", { className: "mt-3 flex flex-col gap-2 border-t border-[var(--color-border)] pt-3 sm:flex-row sm:items-center sm:justify-between", children: [
|
|
2783
|
+
/* @__PURE__ */ jsx25("div", { className: "min-w-0 truncate text-[11px] text-[var(--color-text-muted)]", children: summary }),
|
|
2784
|
+
/* @__PURE__ */ jsxs21("div", { className: "flex shrink-0 items-center justify-end gap-2", children: [
|
|
2785
|
+
/* @__PURE__ */ jsx25("button", { type: "button", onClick: () => {
|
|
2786
|
+
syncTempFromValue();
|
|
2787
|
+
close?.();
|
|
2788
|
+
}, className: "h-8 rounded-lg px-3 text-xs font-medium text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]", children: t("common.cancel") }),
|
|
2789
|
+
/* @__PURE__ */ jsxs21("button", { type: "button", disabled: quickType !== "all_time" && (!tempStart || !tempEnd), onClick: apply, className: "inline-flex h-8 items-center gap-1.5 rounded-lg bg-[var(--color-brand)] px-3 text-xs font-semibold text-white hover:brightness-95 disabled:cursor-not-allowed disabled:opacity-50", children: [
|
|
2790
|
+
/* @__PURE__ */ jsx25(CheckIcon2, {}),
|
|
2791
|
+
t("common.apply")
|
|
2792
|
+
] })
|
|
2793
|
+
] })
|
|
2794
|
+
] })
|
|
2795
|
+
] });
|
|
2796
|
+
}
|
|
2797
|
+
function DRangeDatePicker({ label, placeholder, value, size = "md", onChange, error, hint, disabled = false, clearable = true, containerClassName, scrollBehavior = "close" }) {
|
|
2798
|
+
const id = useId5();
|
|
2799
|
+
const { locale, t } = useDLocalization();
|
|
2800
|
+
const months = useMemo6(() => getLocalizedMonthNames(locale), [locale]);
|
|
2801
|
+
const s = INPUT_SIZE_STYLES[size];
|
|
2802
|
+
const formatDisplayDate = (raw) => {
|
|
2803
|
+
const date2 = parseDate2(raw);
|
|
2804
|
+
return date2 ? `${date2.getDate()} ${months[date2.getMonth()]} ${date2.getFullYear()}` : "";
|
|
2805
|
+
};
|
|
2806
|
+
const displayValue = useMemo6(() => value?.start && value?.end ? `${formatDisplayDate(value.start)} - ${formatDisplayDate(value.end)}` : "", [value?.start, value?.end, months]);
|
|
2807
|
+
const resolvedPlaceholder = placeholder ?? t("rangeDatePicker.placeholder");
|
|
2808
|
+
return /* @__PURE__ */ jsxs21("div", { className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
2809
|
+
label ? /* @__PURE__ */ jsx25("label", { htmlFor: id, className: cn(s.label, "inline-block w-fit font-medium text-[var(--color-text)]"), children: label }) : null,
|
|
2810
|
+
/* @__PURE__ */ jsx25(DDropdown, { placement: "bottom-end", contentRole: "dialog", contentPadding: false, contentClassName: "overflow-hidden", scrollBehavior, trigger: ({ open }) => /* @__PURE__ */ jsxs21("div", { className: "relative", children: [
|
|
2811
|
+
/* @__PURE__ */ jsxs21("button", { id, type: "button", disabled, "aria-invalid": Boolean(error) || void 0, className: cn("flex w-full items-center gap-2 rounded-lg border bg-[var(--color-surface)] pr-10 text-left focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50", s.input, error ? "border-[var(--color-danger)]" : "border-[var(--color-border)]", displayValue ? "text-[var(--color-text)]" : "text-[var(--color-text-muted)]/60"), children: [
|
|
2812
|
+
/* @__PURE__ */ jsx25("span", { className: "shrink-0 text-[var(--color-text-muted)]", children: /* @__PURE__ */ jsx25(CalendarIcon2, {}) }),
|
|
2813
|
+
/* @__PURE__ */ jsx25("span", { className: "min-w-0 flex-1 truncate", children: displayValue || resolvedPlaceholder })
|
|
2814
|
+
] }),
|
|
2815
|
+
/* @__PURE__ */ jsxs21("div", { className: cn("absolute top-1/2 flex -translate-y-1/2 items-center gap-1 text-[var(--color-text-muted)]", s.iconRight), children: [
|
|
2816
|
+
clearable && displayValue && !disabled ? /* @__PURE__ */ jsx25("button", { type: "button", "aria-label": t("rangeDatePicker.clear"), onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
2817
|
+
event.preventDefault();
|
|
2818
|
+
event.stopPropagation();
|
|
2819
|
+
onChange?.({ start: void 0, end: void 0 });
|
|
2820
|
+
}, className: "rounded-md p-1 hover:bg-[var(--color-surface-muted)]", children: /* @__PURE__ */ jsx25(ClearIcon5, {}) }) : null,
|
|
2821
|
+
!disabled ? /* @__PURE__ */ jsx25(ChevronDownIcon2, { open }) : null
|
|
2822
|
+
] })
|
|
2823
|
+
] }), children: /* @__PURE__ */ jsx25(RangeDropdownContent, { value, onChange }) }),
|
|
2824
|
+
error ? /* @__PURE__ */ jsx25("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
2825
|
+
!error && hint ? /* @__PURE__ */ jsx25("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
2826
|
+
] });
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
// src/search-input/search-input.tsx
|
|
2830
|
+
import { useEffect as useEffect11, useRef as useRef9, useState as useState11 } from "react";
|
|
2831
|
+
import { jsx as jsx26, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
2832
|
+
function SearchIcon2() {
|
|
2833
|
+
return /* @__PURE__ */ jsxs22("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: [
|
|
2834
|
+
/* @__PURE__ */ jsx26("circle", { cx: "11", cy: "11", r: "7" }),
|
|
2835
|
+
/* @__PURE__ */ jsx26("path", { d: "m20 20-4-4" })
|
|
2836
|
+
] });
|
|
2837
|
+
}
|
|
2838
|
+
function ClearIcon6() {
|
|
2839
|
+
return /* @__PURE__ */ jsx26("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx26("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
2840
|
+
}
|
|
2841
|
+
function DSearchInput({
|
|
2842
|
+
value,
|
|
2843
|
+
onChange,
|
|
2844
|
+
placeholder,
|
|
2845
|
+
debounceMs = 300,
|
|
2846
|
+
className,
|
|
2847
|
+
align = "right",
|
|
2848
|
+
expandedWidth = "280px"
|
|
2849
|
+
}) {
|
|
2850
|
+
const { t } = useDLocalization();
|
|
2851
|
+
const resolvedPlaceholder = placeholder ?? t("searchInput.placeholder");
|
|
2852
|
+
const wrapperRef = useRef9(null);
|
|
2853
|
+
const desktopInputRef = useRef9(null);
|
|
2854
|
+
const debounceRef = useRef9(null);
|
|
2855
|
+
const mountedRef = useRef9(false);
|
|
2856
|
+
const lastEmittedRef = useRef9(value);
|
|
2857
|
+
const [active, setActive] = useState11(Boolean(value));
|
|
2858
|
+
const [localValue, setLocalValue] = useState11(value);
|
|
2859
|
+
useEffect11(() => {
|
|
2860
|
+
if (value === lastEmittedRef.current) return;
|
|
2861
|
+
setLocalValue(value);
|
|
2862
|
+
lastEmittedRef.current = value;
|
|
2863
|
+
if (value) setActive(true);
|
|
2864
|
+
}, [value]);
|
|
2865
|
+
useEffect11(() => {
|
|
2866
|
+
if (!mountedRef.current) {
|
|
2867
|
+
mountedRef.current = true;
|
|
2868
|
+
return;
|
|
2869
|
+
}
|
|
2870
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
2871
|
+
debounceRef.current = setTimeout(() => {
|
|
2872
|
+
if (localValue === lastEmittedRef.current) return;
|
|
2873
|
+
lastEmittedRef.current = localValue;
|
|
2874
|
+
onChange(localValue);
|
|
2875
|
+
}, debounceMs);
|
|
2876
|
+
return () => {
|
|
2877
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
2878
|
+
};
|
|
2879
|
+
}, [debounceMs, localValue, onChange]);
|
|
2880
|
+
useEffect11(() => {
|
|
2881
|
+
if (!active) return;
|
|
2882
|
+
requestAnimationFrame(() => desktopInputRef.current?.focus());
|
|
2883
|
+
}, [active]);
|
|
2884
|
+
useEffect11(() => {
|
|
2885
|
+
const handleClickOutside = (event) => {
|
|
2886
|
+
if (!wrapperRef.current) return;
|
|
2887
|
+
if (!wrapperRef.current.contains(event.target) && !localValue) setActive(false);
|
|
2888
|
+
};
|
|
2889
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2890
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
2891
|
+
}, [localValue]);
|
|
2892
|
+
const emitImmediately = (next) => {
|
|
2893
|
+
if (debounceRef.current) {
|
|
2894
|
+
clearTimeout(debounceRef.current);
|
|
2895
|
+
debounceRef.current = null;
|
|
2896
|
+
}
|
|
2897
|
+
lastEmittedRef.current = next;
|
|
2898
|
+
onChange(next);
|
|
2899
|
+
};
|
|
2900
|
+
const clearSearch = () => {
|
|
2901
|
+
setLocalValue("");
|
|
2902
|
+
emitImmediately("");
|
|
2903
|
+
setActive(false);
|
|
2904
|
+
};
|
|
2905
|
+
return /* @__PURE__ */ jsxs22(
|
|
2906
|
+
"div",
|
|
2907
|
+
{
|
|
2908
|
+
ref: wrapperRef,
|
|
2909
|
+
"data-ds-component": "search-input",
|
|
2910
|
+
className: cn("w-full sm:w-auto", align === "right" ? "sm:mr-3" : "sm:ml-0", className),
|
|
2911
|
+
children: [
|
|
2912
|
+
/* @__PURE__ */ jsxs22("div", { className: "relative block w-full sm:hidden", children: [
|
|
2913
|
+
/* @__PURE__ */ jsx26("span", { className: "pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-muted)]", children: /* @__PURE__ */ jsx26(SearchIcon2, {}) }),
|
|
2914
|
+
/* @__PURE__ */ jsx26(
|
|
2915
|
+
"input",
|
|
2916
|
+
{
|
|
2917
|
+
type: "text",
|
|
2918
|
+
value: localValue,
|
|
2919
|
+
onChange: (event) => {
|
|
2920
|
+
setLocalValue(event.target.value);
|
|
2921
|
+
if (event.target.value) setActive(true);
|
|
2922
|
+
},
|
|
2923
|
+
placeholder: resolvedPlaceholder,
|
|
2924
|
+
className: "h-9 w-full appearance-none rounded-xl border border-[var(--color-border)] bg-[var(--color-background)] pl-9 pr-9 text-sm text-[var(--color-text)] outline-none shadow-sm placeholder:text-[var(--color-text-muted)]/70 focus:border-[var(--color-brand)] focus:ring-2 focus:ring-[var(--color-brand)]/20"
|
|
2925
|
+
}
|
|
2926
|
+
),
|
|
2927
|
+
localValue ? /* @__PURE__ */ jsx26(
|
|
2928
|
+
"button",
|
|
2929
|
+
{
|
|
2930
|
+
type: "button",
|
|
2931
|
+
"aria-label": t("searchInput.clear"),
|
|
2932
|
+
onClick: clearSearch,
|
|
2933
|
+
className: "absolute right-2 top-1/2 -translate-y-1/2 appearance-none rounded-md border-0 bg-transparent p-1 text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]",
|
|
2934
|
+
children: /* @__PURE__ */ jsx26(ClearIcon6, {})
|
|
2935
|
+
}
|
|
2936
|
+
) : null
|
|
2937
|
+
] }),
|
|
2938
|
+
/* @__PURE__ */ jsx26(
|
|
2939
|
+
"div",
|
|
2940
|
+
{
|
|
2941
|
+
className: cn("relative hidden items-center transition-[width] duration-200 ease-out sm:flex", align === "right" ? "justify-end" : "justify-start"),
|
|
2942
|
+
style: { width: active ? expandedWidth : "44px" },
|
|
2943
|
+
children: /* @__PURE__ */ jsxs22(
|
|
2944
|
+
"div",
|
|
2945
|
+
{
|
|
2946
|
+
className: cn(
|
|
2947
|
+
"relative h-9 w-full overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-background)] shadow-sm transition-all duration-200 ease-out focus-within:border-[var(--color-brand)] focus-within:ring-2 focus-within:ring-[var(--color-brand)]/20",
|
|
2948
|
+
active ? "cursor-text" : "cursor-pointer hover:bg-[var(--color-surface-muted)]"
|
|
2949
|
+
),
|
|
2950
|
+
onClick: () => setActive(true),
|
|
2951
|
+
children: [
|
|
2952
|
+
/* @__PURE__ */ jsx26("span", { className: cn("pointer-events-none absolute top-1/2 -translate-y-1/2 text-[var(--color-text-muted)] transition-all duration-200 ease-out", active ? "left-3" : "left-1/2 -translate-x-1/2"), children: /* @__PURE__ */ jsx26(SearchIcon2, {}) }),
|
|
2953
|
+
/* @__PURE__ */ jsx26(
|
|
2954
|
+
"input",
|
|
2955
|
+
{
|
|
2956
|
+
ref: desktopInputRef,
|
|
2957
|
+
type: "text",
|
|
2958
|
+
value: localValue,
|
|
2959
|
+
onChange: (event) => {
|
|
2960
|
+
setLocalValue(event.target.value);
|
|
2961
|
+
if (event.target.value) setActive(true);
|
|
2962
|
+
},
|
|
2963
|
+
onKeyDown: (event) => {
|
|
2964
|
+
if (event.key === "Escape") clearSearch();
|
|
2965
|
+
},
|
|
2966
|
+
placeholder: resolvedPlaceholder,
|
|
2967
|
+
className: cn(
|
|
2968
|
+
"h-full w-full appearance-none border-0 bg-transparent pl-9 pr-9 text-sm text-[var(--color-text)] outline-none placeholder:text-[var(--color-text-muted)]/70 transition-opacity duration-150 ease-out",
|
|
2969
|
+
active ? "opacity-100" : "pointer-events-none opacity-0"
|
|
2970
|
+
)
|
|
2971
|
+
}
|
|
2972
|
+
),
|
|
2973
|
+
active && localValue ? /* @__PURE__ */ jsx26(
|
|
2974
|
+
"button",
|
|
2975
|
+
{
|
|
2976
|
+
type: "button",
|
|
2977
|
+
"aria-label": t("searchInput.clear"),
|
|
2978
|
+
onClick: (event) => {
|
|
2979
|
+
event.preventDefault();
|
|
2980
|
+
event.stopPropagation();
|
|
2981
|
+
clearSearch();
|
|
2982
|
+
},
|
|
2983
|
+
className: "absolute right-2 top-1/2 -translate-y-1/2 appearance-none rounded-md border-0 bg-transparent p-1 text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]",
|
|
2984
|
+
children: /* @__PURE__ */ jsx26(ClearIcon6, {})
|
|
2985
|
+
}
|
|
2986
|
+
) : null
|
|
2987
|
+
]
|
|
2988
|
+
}
|
|
2989
|
+
)
|
|
2990
|
+
}
|
|
2991
|
+
)
|
|
2992
|
+
]
|
|
2993
|
+
}
|
|
2994
|
+
);
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
// src/select/select.tsx
|
|
2998
|
+
import {
|
|
2999
|
+
Children,
|
|
3000
|
+
forwardRef as forwardRef4,
|
|
3001
|
+
isValidElement,
|
|
3002
|
+
useEffect as useEffect12,
|
|
3003
|
+
useId as useId6,
|
|
3004
|
+
useMemo as useMemo7,
|
|
3005
|
+
useRef as useRef10,
|
|
3006
|
+
useState as useState12
|
|
3007
|
+
} from "react";
|
|
3008
|
+
import { jsx as jsx27, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
3009
|
+
function ChevronDownIcon3({ open }) {
|
|
3010
|
+
return /* @__PURE__ */ jsx27("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: cn("size-3.5 transition-transform", open && "rotate-180"), "aria-hidden": "true", children: /* @__PURE__ */ jsx27("path", { d: "m6 9 6 6 6-6" }) });
|
|
3011
|
+
}
|
|
3012
|
+
function ClearIcon7() {
|
|
3013
|
+
return /* @__PURE__ */ jsx27("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx27("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
3014
|
+
}
|
|
3015
|
+
function selectOptionsFromChildren(children) {
|
|
3016
|
+
return Children.toArray(children).flatMap((child) => {
|
|
3017
|
+
if (!isValidElement(child)) return [];
|
|
3018
|
+
if (child.type !== "option" || child.props.value === void 0) return [];
|
|
3019
|
+
return [{ value: child.props.value, label: child.props.children, ...child.props.disabled === void 0 ? {} : { disabled: child.props.disabled } }];
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
function sameValue2(left, right) {
|
|
3023
|
+
return String(left ?? "") === String(right ?? "");
|
|
3024
|
+
}
|
|
3025
|
+
var DSelect = forwardRef4(function DSelect2({
|
|
3026
|
+
className,
|
|
3027
|
+
children,
|
|
3028
|
+
label,
|
|
3029
|
+
hint,
|
|
3030
|
+
error,
|
|
3031
|
+
containerClassName,
|
|
3032
|
+
id: providedId,
|
|
3033
|
+
options,
|
|
3034
|
+
placeholder,
|
|
3035
|
+
clearable = true,
|
|
3036
|
+
searchable = false,
|
|
3037
|
+
loading = false,
|
|
3038
|
+
emptyMessage,
|
|
3039
|
+
asyncErrorMessage,
|
|
3040
|
+
fetchOptions,
|
|
3041
|
+
refetchKey,
|
|
3042
|
+
onFetchError,
|
|
3043
|
+
onValueChange,
|
|
3044
|
+
onChange,
|
|
3045
|
+
value,
|
|
3046
|
+
defaultValue = null,
|
|
3047
|
+
disabled = false,
|
|
3048
|
+
size = "md",
|
|
3049
|
+
debounceMs = 300,
|
|
3050
|
+
scrollBehavior = "reposition",
|
|
3051
|
+
...props
|
|
3052
|
+
}, ref) {
|
|
3053
|
+
const generatedId = useId6();
|
|
3054
|
+
const id = providedId ?? generatedId;
|
|
3055
|
+
const { t } = useDLocalization();
|
|
3056
|
+
const s = INPUT_SIZE_STYLES[size];
|
|
3057
|
+
const requestIdRef = useRef10(0);
|
|
3058
|
+
const resolveRequestIdRef = useRef10(0);
|
|
3059
|
+
const [query, setQuery] = useState12("");
|
|
3060
|
+
const [activeIndex, setActiveIndex] = useState12(0);
|
|
3061
|
+
const [isOpen, setOpen] = useState12(false);
|
|
3062
|
+
const [internalValue, setInternalValue] = useState12(defaultValue);
|
|
3063
|
+
const [resolvedAsyncSelection, setResolvedAsyncSelection] = useState12(null);
|
|
3064
|
+
const [asyncOptions, setAsyncOptions] = useState12([]);
|
|
3065
|
+
const [isFetching, setFetching] = useState12(false);
|
|
3066
|
+
const [fetchError, setFetchError] = useState12(null);
|
|
3067
|
+
const selectedValue = value === void 0 ? internalValue : value;
|
|
3068
|
+
const resolvedPlaceholder = placeholder ?? t("select.placeholder");
|
|
3069
|
+
const resolvedEmptyMessage = emptyMessage ?? t("select.empty");
|
|
3070
|
+
const resolvedAsyncErrorMessage = asyncErrorMessage ?? t("select.asyncError");
|
|
3071
|
+
const staticOptions = useMemo7(() => options?.slice() ?? selectOptionsFromChildren(children), [children, options]);
|
|
3072
|
+
const isAsync = Boolean(fetchOptions);
|
|
3073
|
+
const sourceOptions = isAsync ? asyncOptions : staticOptions;
|
|
3074
|
+
const filteredOptions = useMemo7(
|
|
3075
|
+
() => !isAsync && searchable && query ? sourceOptions.filter((option) => String(option.label).toLocaleLowerCase().includes(query.toLocaleLowerCase())) : sourceOptions,
|
|
3076
|
+
[isAsync, query, searchable, sourceOptions]
|
|
3077
|
+
);
|
|
3078
|
+
const selected = staticOptions.find((option) => sameValue2(option.value, selectedValue)) ?? (sameValue2(resolvedAsyncSelection?.value, selectedValue) ? resolvedAsyncSelection : null);
|
|
3079
|
+
const showClear = Boolean(clearable && selected && !disabled);
|
|
3080
|
+
useEffect12(() => {
|
|
3081
|
+
if (!isAsync || !fetchOptions || !isOpen) return;
|
|
3082
|
+
const requestId = ++requestIdRef.current;
|
|
3083
|
+
const timeout = window.setTimeout(() => {
|
|
3084
|
+
setFetching(true);
|
|
3085
|
+
setFetchError(null);
|
|
3086
|
+
void fetchOptions(query).then((result) => {
|
|
3087
|
+
if (requestId === requestIdRef.current) setAsyncOptions(result);
|
|
3088
|
+
}).catch((nextError) => {
|
|
3089
|
+
if (requestId !== requestIdRef.current) return;
|
|
3090
|
+
setFetchError(nextError);
|
|
3091
|
+
onFetchError?.(nextError);
|
|
3092
|
+
}).finally(() => {
|
|
3093
|
+
if (requestId === requestIdRef.current) setFetching(false);
|
|
3094
|
+
});
|
|
3095
|
+
}, debounceMs);
|
|
3096
|
+
return () => window.clearTimeout(timeout);
|
|
3097
|
+
}, [debounceMs, fetchOptions, isAsync, isOpen, onFetchError, query, refetchKey]);
|
|
3098
|
+
useEffect12(() => {
|
|
3099
|
+
if (!isAsync || !fetchOptions || selectedValue == null || selectedValue === "" || sameValue2(resolvedAsyncSelection?.value, selectedValue)) return;
|
|
3100
|
+
const requestId = ++resolveRequestIdRef.current;
|
|
3101
|
+
void fetchOptions("").then((result) => {
|
|
3102
|
+
if (requestId !== resolveRequestIdRef.current) return;
|
|
3103
|
+
const found = result.find((option) => sameValue2(option.value, selectedValue));
|
|
3104
|
+
if (found) setResolvedAsyncSelection(found);
|
|
3105
|
+
}).catch((nextError) => onFetchError?.(nextError));
|
|
3106
|
+
}, [fetchOptions, isAsync, onFetchError, refetchKey, resolvedAsyncSelection?.value, selectedValue]);
|
|
3107
|
+
const selectedIndex = () => {
|
|
3108
|
+
const index = filteredOptions.findIndex((option) => sameValue2(option.value, selectedValue));
|
|
3109
|
+
return index >= 0 ? index : 0;
|
|
3110
|
+
};
|
|
3111
|
+
const choose = (option) => {
|
|
3112
|
+
if (value === void 0) setInternalValue(option.value);
|
|
3113
|
+
setResolvedAsyncSelection(option);
|
|
3114
|
+
onValueChange?.(option.value);
|
|
3115
|
+
onChange?.(option.value);
|
|
3116
|
+
setOpen(false);
|
|
3117
|
+
setQuery("");
|
|
3118
|
+
};
|
|
3119
|
+
const clear = (event) => {
|
|
3120
|
+
event.preventDefault();
|
|
3121
|
+
event.stopPropagation();
|
|
3122
|
+
if (value === void 0) setInternalValue(null);
|
|
3123
|
+
setResolvedAsyncSelection(null);
|
|
3124
|
+
onValueChange?.(null);
|
|
3125
|
+
onChange?.(null);
|
|
3126
|
+
setQuery("");
|
|
3127
|
+
};
|
|
3128
|
+
const handleTriggerKeyDown = (event) => {
|
|
3129
|
+
if (event.key === "Escape") {
|
|
3130
|
+
setOpen(false);
|
|
3131
|
+
setQuery("");
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
3135
|
+
event.preventDefault();
|
|
3136
|
+
const count = filteredOptions.length || 1;
|
|
3137
|
+
if (!isOpen) {
|
|
3138
|
+
const start = selectedIndex();
|
|
3139
|
+
setOpen(true);
|
|
3140
|
+
setActiveIndex(event.key === "ArrowDown" ? (start + 1) % count : (start - 1 + count) % count);
|
|
3141
|
+
return;
|
|
3142
|
+
}
|
|
3143
|
+
setActiveIndex((index) => event.key === "ArrowDown" ? (index + 1) % count : (index - 1 + count) % count);
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
3146
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
3147
|
+
event.preventDefault();
|
|
3148
|
+
const active = filteredOptions[activeIndex];
|
|
3149
|
+
if (isOpen && active && !active.disabled) choose(active);
|
|
3150
|
+
else {
|
|
3151
|
+
setActiveIndex(selectedIndex());
|
|
3152
|
+
setOpen(true);
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
};
|
|
3156
|
+
return /* @__PURE__ */ jsxs23("div", { "data-ds-component": "select", className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
3157
|
+
label ? /* @__PURE__ */ jsx27("label", { htmlFor: id, className: cn(s.label, "inline-block w-fit font-medium text-[var(--color-text)]"), children: label }) : null,
|
|
3158
|
+
/* @__PURE__ */ jsx27(DDropdown, { matchWidth: true, open: isOpen, onOpenChange: (next) => {
|
|
3159
|
+
setOpen(next);
|
|
3160
|
+
if (next && !query) setActiveIndex(selectedIndex());
|
|
3161
|
+
}, contentRole: "listbox", contentPadding: false, contentClassName: "overflow-hidden", scrollBehavior, onClose: () => {
|
|
3162
|
+
setOpen(false);
|
|
3163
|
+
setQuery("");
|
|
3164
|
+
}, trigger: ({ open }) => /* @__PURE__ */ jsxs23("div", { className: "relative", children: [
|
|
3165
|
+
/* @__PURE__ */ jsx27("button", { ...props, ref, id, type: "button", disabled, "aria-invalid": Boolean(error) || void 0, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": `${id}-listbox`, onKeyDown: handleTriggerKeyDown, className: cn("flex w-full items-center rounded-[var(--radius-control)] border bg-[var(--color-surface)] text-left transition-colors duration-150 focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50", s.input, error ? "border-[var(--color-danger)]" : "border-[var(--color-border)]", selected ? "text-[var(--color-text)]" : "text-[var(--color-text-muted)]/60", showClear ? size === "sm" ? "pr-14" : "pr-16" : "pr-10", className), children: /* @__PURE__ */ jsx27("span", { className: "min-w-0 flex-1 truncate", children: selected ? selected.label : resolvedPlaceholder }) }),
|
|
3166
|
+
/* @__PURE__ */ jsxs23("div", { className: cn("absolute top-1/2 flex -translate-y-1/2 items-center gap-1.5 text-[var(--color-text-muted)]", size === "sm" ? "right-2" : "right-2.5"), children: [
|
|
3167
|
+
showClear ? /* @__PURE__ */ jsx27("button", { type: "button", tabIndex: -1, "aria-label": t("select.clear"), onMouseDown: (event) => event.preventDefault(), onClick: clear, className: "appearance-none rounded-md border-0 bg-transparent p-1 shadow-none hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]", children: /* @__PURE__ */ jsx27(ClearIcon7, {}) }) : null,
|
|
3168
|
+
!disabled ? /* @__PURE__ */ jsx27(ChevronDownIcon3, { open }) : null
|
|
3169
|
+
] })
|
|
3170
|
+
] }), children: /* @__PURE__ */ jsxs23("div", { id: `${id}-listbox`, className: "max-h-60 overflow-hidden", children: [
|
|
3171
|
+
searchable ? /* @__PURE__ */ jsx27("div", { className: "border-b border-[var(--color-border)] p-1.5", children: /* @__PURE__ */ jsx27("input", { autoFocus: true, value: query, onChange: (event) => {
|
|
3172
|
+
setQuery(event.target.value);
|
|
3173
|
+
setActiveIndex(0);
|
|
3174
|
+
}, placeholder: t("select.searchPlaceholder"), className: "h-8 w-full rounded-[var(--radius-control)] border border-[var(--color-border)] bg-[var(--color-background)] px-2.5 text-xs text-[var(--color-text)] outline-none focus:border-[var(--color-brand)] focus:ring-2 focus:ring-[var(--color-brand)]/20" }) }) : null,
|
|
3175
|
+
/* @__PURE__ */ jsx27("div", { className: "max-h-48 space-y-0.5 overflow-y-auto p-1.5", children: loading || isFetching ? /* @__PURE__ */ jsx27("p", { className: "px-3 py-2 text-sm text-[var(--color-text-muted)]", children: t("select.loading") }) : fetchError ? /* @__PURE__ */ jsx27("p", { className: "px-3 py-2 text-sm text-[var(--color-danger)]", children: resolvedAsyncErrorMessage }) : filteredOptions.length === 0 ? /* @__PURE__ */ jsx27("p", { className: "px-3 py-2 text-sm text-[var(--color-text-muted)]", children: resolvedEmptyMessage }) : filteredOptions.map((option, index) => {
|
|
3176
|
+
const isSelected = sameValue2(option.value, selectedValue);
|
|
3177
|
+
return /* @__PURE__ */ jsx27("button", { type: "button", role: "option", "aria-selected": isSelected, disabled: option.disabled, onMouseEnter: () => setActiveIndex(index), onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
3178
|
+
event.stopPropagation();
|
|
3179
|
+
if (!option.disabled) choose(option);
|
|
3180
|
+
}, className: cn("w-full rounded-[var(--radius-menu-item)] px-3 py-2 text-left text-sm text-[var(--color-text)] transition-colors hover:bg-[var(--color-surface-muted)] disabled:cursor-not-allowed disabled:opacity-50", isSelected && "bg-[var(--color-brand)]/10 font-medium text-[var(--color-brand)]", index === activeIndex && !isSelected && "bg-[var(--color-surface-muted)]"), children: option.label }, String(option.value));
|
|
3181
|
+
}) })
|
|
3182
|
+
] }) }),
|
|
3183
|
+
error ? /* @__PURE__ */ jsx27("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
3184
|
+
!error && hint ? /* @__PURE__ */ jsx27("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
3185
|
+
] });
|
|
3186
|
+
});
|
|
3187
|
+
DSelect.displayName = "DSelect";
|
|
3188
|
+
|
|
3189
|
+
// src/select-filter/select-filter.tsx
|
|
3190
|
+
import { useId as useId7, useMemo as useMemo8, useRef as useRef11, useState as useState13 } from "react";
|
|
3191
|
+
import { jsx as jsx28, jsxs as jsxs24 } from "react/jsx-runtime";
|
|
3192
|
+
function ClearIcon8() {
|
|
3193
|
+
return /* @__PURE__ */ jsx28("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx28("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
3194
|
+
}
|
|
3195
|
+
function ChevronIcon2({ open }) {
|
|
3196
|
+
return /* @__PURE__ */ jsx28("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: cn("size-3.5 transition-transform", open && "rotate-180"), children: /* @__PURE__ */ jsx28("path", { d: "m6 9 6 6 6-6" }) });
|
|
3197
|
+
}
|
|
3198
|
+
function DSelectFilter({
|
|
3199
|
+
label,
|
|
3200
|
+
placeholder,
|
|
3201
|
+
options,
|
|
3202
|
+
value,
|
|
3203
|
+
onChange,
|
|
3204
|
+
error,
|
|
3205
|
+
hint,
|
|
3206
|
+
disabled = false,
|
|
3207
|
+
clearable = true,
|
|
3208
|
+
searchable = false,
|
|
3209
|
+
containerClassName,
|
|
3210
|
+
scrollBehavior = "close"
|
|
3211
|
+
}) {
|
|
3212
|
+
const { t } = useDLocalization();
|
|
3213
|
+
const id = useId7();
|
|
3214
|
+
const searchRef = useRef11(null);
|
|
3215
|
+
const [search, setSearch] = useState13("");
|
|
3216
|
+
const selectedOption = options.find((option) => String(option.value) === String(value ?? ""));
|
|
3217
|
+
const resolvedPlaceholder = placeholder ?? t("selectFilter.placeholder");
|
|
3218
|
+
const filtered = useMemo8(() => {
|
|
3219
|
+
if (!searchable || !search) return options;
|
|
3220
|
+
const query = search.toLocaleLowerCase();
|
|
3221
|
+
return options.filter((option) => String(option.label).toLocaleLowerCase().includes(query));
|
|
3222
|
+
}, [options, search, searchable]);
|
|
3223
|
+
return /* @__PURE__ */ jsxs24("div", { "data-ds-component": "select-filter", className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
3224
|
+
/* @__PURE__ */ jsx28(
|
|
3225
|
+
DDropdown,
|
|
3226
|
+
{
|
|
3227
|
+
matchWidth: true,
|
|
3228
|
+
contentPadding: false,
|
|
3229
|
+
contentClassName: "overflow-hidden",
|
|
3230
|
+
scrollBehavior,
|
|
3231
|
+
onOpenChange: (open) => {
|
|
3232
|
+
if (open && searchable) requestAnimationFrame(() => searchRef.current?.focus());
|
|
3233
|
+
if (!open) setSearch("");
|
|
3234
|
+
},
|
|
3235
|
+
trigger: ({ open }) => /* @__PURE__ */ jsxs24(
|
|
3236
|
+
"div",
|
|
3237
|
+
{
|
|
3238
|
+
className: cn(
|
|
3239
|
+
"relative flex h-10 w-full items-center rounded-[var(--radius-control)] border bg-[var(--color-surface)] px-3 pr-8 text-left text-sm transition-colors focus-within:border-[var(--color-brand)] focus-within:ring-2 focus-within:ring-[var(--color-brand)]/20",
|
|
3240
|
+
error ? "border-[var(--color-danger)]" : "border-[var(--color-border)]",
|
|
3241
|
+
disabled && "cursor-not-allowed bg-[var(--color-surface-muted)] opacity-50"
|
|
3242
|
+
),
|
|
3243
|
+
children: [
|
|
3244
|
+
label ? /* @__PURE__ */ jsxs24("div", { className: "flex shrink-0 items-center gap-2 text-[var(--color-text-muted)]", children: [
|
|
3245
|
+
/* @__PURE__ */ jsx28("label", { htmlFor: id, className: "text-sm font-medium", children: label }),
|
|
3246
|
+
/* @__PURE__ */ jsx28("span", { "aria-hidden": "true", className: "opacity-45", children: "|" })
|
|
3247
|
+
] }) : null,
|
|
3248
|
+
/* @__PURE__ */ jsx28(
|
|
3249
|
+
"button",
|
|
3250
|
+
{
|
|
3251
|
+
id,
|
|
3252
|
+
type: "button",
|
|
3253
|
+
disabled,
|
|
3254
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
3255
|
+
className: cn(
|
|
3256
|
+
"min-w-0 flex-1 truncate pl-3 pr-6 text-left outline-none",
|
|
3257
|
+
selectedOption ? "text-[var(--color-text)]" : "text-[var(--color-text-muted)]/60"
|
|
3258
|
+
),
|
|
3259
|
+
children: selectedOption ? selectedOption.label : resolvedPlaceholder
|
|
3260
|
+
}
|
|
3261
|
+
),
|
|
3262
|
+
/* @__PURE__ */ jsxs24("div", { className: "absolute right-2 top-1/2 flex -translate-y-1/2 items-center gap-1 text-[var(--color-text-muted)]", children: [
|
|
3263
|
+
clearable && selectedOption && !disabled ? /* @__PURE__ */ jsx28(
|
|
3264
|
+
"button",
|
|
3265
|
+
{
|
|
3266
|
+
type: "button",
|
|
3267
|
+
"aria-label": t("selectFilter.clear"),
|
|
3268
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
3269
|
+
onClick: (event) => {
|
|
3270
|
+
event.stopPropagation();
|
|
3271
|
+
onChange?.(null);
|
|
3272
|
+
},
|
|
3273
|
+
className: "rounded-md p-0.5 hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]",
|
|
3274
|
+
children: /* @__PURE__ */ jsx28(ClearIcon8, {})
|
|
3275
|
+
}
|
|
3276
|
+
) : null,
|
|
3277
|
+
/* @__PURE__ */ jsx28(ChevronIcon2, { open })
|
|
3278
|
+
] })
|
|
3279
|
+
]
|
|
3280
|
+
}
|
|
3281
|
+
),
|
|
3282
|
+
children: /* @__PURE__ */ jsxs24("div", { className: "max-h-60 overflow-hidden", children: [
|
|
3283
|
+
searchable ? /* @__PURE__ */ jsx28("div", { className: "border-b border-[var(--color-border)] p-1.5", children: /* @__PURE__ */ jsx28(
|
|
3284
|
+
"input",
|
|
3285
|
+
{
|
|
3286
|
+
ref: searchRef,
|
|
3287
|
+
value: search,
|
|
3288
|
+
onChange: (event) => setSearch(event.target.value),
|
|
3289
|
+
placeholder: t("selectFilter.searchPlaceholder"),
|
|
3290
|
+
className: "h-8 w-full rounded-[var(--radius-control)] border border-[var(--color-border)] bg-[var(--color-background)] px-2.5 text-sm text-[var(--color-text)] outline-none focus:border-[var(--color-brand)] focus:ring-2 focus:ring-[var(--color-brand)]/20"
|
|
3291
|
+
}
|
|
3292
|
+
) }) : null,
|
|
3293
|
+
/* @__PURE__ */ jsx28("div", { className: "max-h-48 space-y-0.5 overflow-y-auto p-1.5", children: filtered.map((option) => {
|
|
3294
|
+
const selected = String(option.value) === String(value ?? "");
|
|
3295
|
+
return /* @__PURE__ */ jsx28(
|
|
3296
|
+
"button",
|
|
3297
|
+
{
|
|
3298
|
+
type: "button",
|
|
3299
|
+
role: "option",
|
|
3300
|
+
"aria-selected": selected,
|
|
3301
|
+
disabled: option.disabled,
|
|
3302
|
+
onClick: () => {
|
|
3303
|
+
if (option.disabled) return;
|
|
3304
|
+
onChange?.(option.value);
|
|
3305
|
+
setSearch("");
|
|
3306
|
+
},
|
|
3307
|
+
className: cn(
|
|
3308
|
+
"w-full rounded-[var(--radius-menu-item)] px-3 py-2 text-left text-sm text-[var(--color-text)] transition-colors hover:bg-[var(--color-surface-muted)] disabled:cursor-not-allowed disabled:opacity-50",
|
|
3309
|
+
selected && "bg-[var(--color-brand)]/10 font-medium text-[var(--color-brand)]"
|
|
3310
|
+
),
|
|
3311
|
+
children: option.label
|
|
3312
|
+
},
|
|
3313
|
+
String(option.value)
|
|
3314
|
+
);
|
|
3315
|
+
}) })
|
|
3316
|
+
] })
|
|
3317
|
+
}
|
|
3318
|
+
),
|
|
3319
|
+
error ? /* @__PURE__ */ jsx28("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
3320
|
+
!error && hint ? /* @__PURE__ */ jsx28("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
3321
|
+
] });
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
// src/skeleton/skeleton.tsx
|
|
3325
|
+
import { Fragment as Fragment3, jsx as jsx29, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
3326
|
+
var roundedClasses = { sm: "rounded-sm", md: "rounded-md", lg: "rounded-lg", full: "rounded-full" };
|
|
3327
|
+
function SkeletonBlock({ className, width, height, rounded = "md", style, ...props }) {
|
|
3328
|
+
const dimensions = {
|
|
3329
|
+
...style,
|
|
3330
|
+
...width !== void 0 ? { width: typeof width === "number" ? `${width}px` : width } : {},
|
|
3331
|
+
...height !== void 0 ? { height: typeof height === "number" ? `${height}px` : height } : {}
|
|
3332
|
+
};
|
|
3333
|
+
return /* @__PURE__ */ jsx29("div", { className: cn("animate-pulse bg-[var(--color-surface-muted)]", roundedClasses[rounded], className), style: dimensions, ...props });
|
|
3334
|
+
}
|
|
3335
|
+
function DSkeleton({ height = 16, count = 1, ...props }) {
|
|
3336
|
+
return /* @__PURE__ */ jsx29(Fragment3, { children: Array.from({ length: count }).map((_, index) => /* @__PURE__ */ jsx29(SkeletonBlock, { ...props, height }, index)) });
|
|
3337
|
+
}
|
|
3338
|
+
function DTableSkeleton({ rows = 5, cols = 4 }) {
|
|
3339
|
+
return /* @__PURE__ */ jsxs25("div", { className: "space-y-3", children: [
|
|
3340
|
+
/* @__PURE__ */ jsx29("div", { className: "flex gap-4", children: Array.from({ length: cols }).map((_, i) => /* @__PURE__ */ jsx29(DSkeleton, { height: 14, width: i === 0 ? "30%" : "20%" }, i)) }),
|
|
3341
|
+
Array.from({ length: rows }).map((_, r) => /* @__PURE__ */ jsx29("div", { className: "flex gap-4 border-b border-[var(--color-border)]/50 py-3", children: Array.from({ length: cols }).map((_2, c) => /* @__PURE__ */ jsx29(DSkeleton, { height: 12, width: c === 0 ? "30%" : "20%" }, c)) }, r))
|
|
3342
|
+
] });
|
|
3343
|
+
}
|
|
3344
|
+
function DCardSkeleton() {
|
|
3345
|
+
return /* @__PURE__ */ jsxs25("div", { className: "space-y-3 rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)] p-5", children: [
|
|
3346
|
+
/* @__PURE__ */ jsx29(DSkeleton, { height: 12, width: "40%" }),
|
|
3347
|
+
/* @__PURE__ */ jsx29(DSkeleton, { height: 28, width: "60%" }),
|
|
3348
|
+
/* @__PURE__ */ jsx29(DSkeleton, { height: 10, width: "80%" })
|
|
3349
|
+
] });
|
|
3350
|
+
}
|
|
3351
|
+
function DFormSkeleton({ fields = 4 }) {
|
|
3352
|
+
return /* @__PURE__ */ jsx29("div", { className: "space-y-5", children: Array.from({ length: fields }).map((_, i) => /* @__PURE__ */ jsxs25("div", { className: "space-y-2", children: [
|
|
3353
|
+
/* @__PURE__ */ jsx29(DSkeleton, { height: 12, width: "25%" }),
|
|
3354
|
+
/* @__PURE__ */ jsx29(DSkeleton, { height: 40, width: "100%", rounded: "lg" })
|
|
3355
|
+
] }, i)) });
|
|
3356
|
+
}
|
|
3357
|
+
|
|
3358
|
+
// src/splash-screen/splash-screen.tsx
|
|
3359
|
+
import { useEffect as useEffect13, useState as useState14 } from "react";
|
|
3360
|
+
import { jsx as jsx30, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
3361
|
+
function DSplashScreen({ onFinish, minDuration = 1800, title = "DIGVENT.", subtitle = "Inventory Management System", mark = "D." }) {
|
|
3362
|
+
const [leaving, setLeaving] = useState14(false);
|
|
3363
|
+
useEffect13(() => {
|
|
3364
|
+
if (!onFinish) return;
|
|
3365
|
+
const leaveTimer = setTimeout(() => setLeaving(true), minDuration);
|
|
3366
|
+
const finishTimer = setTimeout(onFinish, minDuration + 500);
|
|
3367
|
+
return () => {
|
|
3368
|
+
clearTimeout(leaveTimer);
|
|
3369
|
+
clearTimeout(finishTimer);
|
|
3370
|
+
};
|
|
3371
|
+
}, [minDuration, onFinish]);
|
|
3372
|
+
return /* @__PURE__ */ jsx30("div", { className: cn("fixed inset-0 z-[99999] grid place-items-center bg-[var(--color-background)] transition-opacity duration-500", leaving && "opacity-0"), children: /* @__PURE__ */ jsxs26("div", { className: cn("flex flex-col items-center transition-all duration-700 ease-out", leaving && "-translate-y-5 scale-95 opacity-0"), children: [
|
|
3373
|
+
/* @__PURE__ */ jsxs26("div", { className: "relative mb-6", children: [
|
|
3374
|
+
/* @__PURE__ */ jsx30("div", { className: "flex size-16 items-center justify-center rounded-2xl bg-[var(--color-brand)] text-2xl font-bold tracking-tight text-white shadow-lg shadow-blue-500/20", children: mark }),
|
|
3375
|
+
/* @__PURE__ */ jsx30("div", { className: "absolute inset-0 animate-ping rounded-2xl bg-[var(--color-brand)]/20 [animation-duration:2s]" })
|
|
3376
|
+
] }),
|
|
3377
|
+
/* @__PURE__ */ jsx30("h1", { className: "mb-2 text-3xl font-bold tracking-tight text-[var(--color-text)]", children: title }),
|
|
3378
|
+
subtitle ? /* @__PURE__ */ jsx30("p", { className: "mb-8 text-sm text-[var(--color-text-muted)]", children: subtitle }) : null,
|
|
3379
|
+
/* @__PURE__ */ jsx30("div", { className: "flex gap-1.5", children: [0, 1, 2].map((index) => /* @__PURE__ */ jsx30("span", { className: "size-2 rounded-full bg-[var(--color-brand)]", style: { animation: "splash-dot 1.4s ease-in-out infinite", animationDelay: `${index * 0.2}s` } }, index)) })
|
|
3380
|
+
] }) });
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
// src/status-filter/status-filter.tsx
|
|
3384
|
+
import { jsx as jsx31, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
3385
|
+
function DStatusFilter({ label, options, value, onChange, allLabel }) {
|
|
3386
|
+
const { t } = useDLocalization();
|
|
3387
|
+
const resolvedAllLabel = allLabel ?? t("statusFilter.all");
|
|
3388
|
+
const button = (active) => cn(
|
|
3389
|
+
"rounded-[var(--radius-control)] px-3 py-1.5 text-xs font-medium transition-all duration-150",
|
|
3390
|
+
active ? "bg-[var(--color-brand)] text-[var(--color-brand-foreground)] shadow-[var(--shadow-sm)]" : "border border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]"
|
|
3391
|
+
);
|
|
3392
|
+
return /* @__PURE__ */ jsxs27("div", { "data-ds-component": "status-filter", className: "flex flex-wrap items-center gap-3", children: [
|
|
3393
|
+
label ? /* @__PURE__ */ jsx31("span", { className: "text-xs font-medium text-[var(--color-text-muted)]", children: label }) : null,
|
|
3394
|
+
/* @__PURE__ */ jsxs27("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
3395
|
+
/* @__PURE__ */ jsx31("button", { type: "button", onClick: () => onChange(""), className: button(!value), children: resolvedAllLabel }),
|
|
3396
|
+
options.map((option) => /* @__PURE__ */ jsxs27("button", { type: "button", onClick: () => onChange(option.value), className: button(value === option.value), children: [
|
|
3397
|
+
option.label,
|
|
3398
|
+
option.count !== void 0 ? /* @__PURE__ */ jsxs27("span", { className: "ml-1 opacity-70", children: [
|
|
3399
|
+
"(",
|
|
3400
|
+
option.count,
|
|
3401
|
+
")"
|
|
3402
|
+
] }) : null
|
|
3403
|
+
] }, option.value))
|
|
3404
|
+
] })
|
|
3405
|
+
] });
|
|
3406
|
+
}
|
|
3407
|
+
|
|
3408
|
+
// src/data-table/data-table.tsx
|
|
3409
|
+
import { useState as useState15 } from "react";
|
|
3410
|
+
import { jsx as jsx32, jsxs as jsxs28 } from "react/jsx-runtime";
|
|
3411
|
+
function getPaginationPages(page, totalPages) {
|
|
3412
|
+
const count = Math.min(Math.max(totalPages, 1), 5);
|
|
3413
|
+
if (totalPages <= 5) return Array.from({ length: count }, (_, index) => index + 1);
|
|
3414
|
+
const start = Math.min(Math.max(page - 2, 1), totalPages - 4);
|
|
3415
|
+
return Array.from({ length: 5 }, (_, index) => start + index);
|
|
3416
|
+
}
|
|
3417
|
+
function rawValue(row, key) {
|
|
3418
|
+
if (row && typeof row === "object") return row[key];
|
|
3419
|
+
return void 0;
|
|
3420
|
+
}
|
|
3421
|
+
function toDisplay(value, t) {
|
|
3422
|
+
if (value === null || value === void 0 || value === "") return "-";
|
|
3423
|
+
if (typeof value === "boolean") return value ? t("common.yes") : t("common.no");
|
|
3424
|
+
if (typeof value === "string" || typeof value === "number") return String(value);
|
|
3425
|
+
return "-";
|
|
3426
|
+
}
|
|
3427
|
+
function toNumber(value) {
|
|
3428
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : 0;
|
|
3429
|
+
const parsed = Number(String(value ?? "").replace(/[^\d.-]/g, ""));
|
|
3430
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
3431
|
+
}
|
|
3432
|
+
function formatValue(column, row, index, locale, t) {
|
|
3433
|
+
const value = rawValue(row, String(column.key));
|
|
3434
|
+
if (column.render) {
|
|
3435
|
+
const render = column.render;
|
|
3436
|
+
return render.length >= 3 ? render(value, row, index) : render(row, index);
|
|
3437
|
+
}
|
|
3438
|
+
let formatted;
|
|
3439
|
+
if (column.type === "currency") formatted = new Intl.NumberFormat(locale, { style: "currency", currency: "IDR", maximumFractionDigits: 0 }).format(toNumber(value));
|
|
3440
|
+
else if (column.type === "number") formatted = new Intl.NumberFormat(locale).format(toNumber(value));
|
|
3441
|
+
else if (column.type === "date") {
|
|
3442
|
+
const date2 = value instanceof Date ? value : typeof value === "string" ? new Date(value) : null;
|
|
3443
|
+
formatted = date2 && !Number.isNaN(date2.getTime()) ? new Intl.DateTimeFormat(locale, { day: "2-digit", month: "short", year: "numeric" }).format(date2) : "-";
|
|
3444
|
+
} else formatted = toDisplay(value, t);
|
|
3445
|
+
const transform = column.transform ?? column.trasform;
|
|
3446
|
+
if (typeof transform === "function") return transform(formatted);
|
|
3447
|
+
if (typeof formatted !== "string") return formatted;
|
|
3448
|
+
if (transform === "uppercase") return formatted.toUpperCase();
|
|
3449
|
+
if (transform === "lowercase") return formatted.toLowerCase();
|
|
3450
|
+
if (transform === "capitalize") return formatted.charAt(0).toUpperCase() + formatted.slice(1);
|
|
3451
|
+
return formatted;
|
|
3452
|
+
}
|
|
3453
|
+
function alignmentClass(column) {
|
|
3454
|
+
return cn(column.align === "center" && "text-center", column.align === "right" && "text-right", (!column.align || column.align === "left") && "text-left");
|
|
3455
|
+
}
|
|
3456
|
+
function FilterIcon() {
|
|
3457
|
+
return /* @__PURE__ */ jsx32("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-4", children: /* @__PURE__ */ jsx32("path", { d: "M4 6h16M7 12h10M10 18h4" }) });
|
|
3458
|
+
}
|
|
3459
|
+
function PageSizeSelect({ value, onChange }) {
|
|
3460
|
+
if (!onChange) return /* @__PURE__ */ jsx32("span", { className: "font-medium text-[var(--color-text)]", children: value });
|
|
3461
|
+
return /* @__PURE__ */ jsx32(DDropdown, { placement: "top-start", closeOnItemClick: true, scrollBehavior: "close", trigger: ({ open }) => /* @__PURE__ */ jsxs28("button", { type: "button", className: "relative flex h-8 appearance-none items-center rounded-lg border border-[var(--color-border)] bg-[var(--color-background)] px-2 pr-6 text-sm text-[var(--color-text)] outline-none hover:bg-[var(--color-surface-muted)] focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25", children: [
|
|
3462
|
+
value,
|
|
3463
|
+
/* @__PURE__ */ jsx32(ChevronDownIcon, { size: 14, className: cn("absolute right-1.5 transition-transform duration-150", open && "rotate-180") })
|
|
3464
|
+
] }), children: /* @__PURE__ */ jsx32("div", { className: "min-w-[72px] py-1", children: [10, 25, 50, 100].map((size) => /* @__PURE__ */ jsx32("button", { type: "button", onClick: () => onChange(size), className: cn("w-full appearance-none rounded-[var(--radius-menu-item)] border-0 bg-transparent px-3 py-1.5 text-left text-sm hover:bg-[var(--color-surface-muted)]", size === value && "bg-[var(--color-brand)]/10 font-medium text-[var(--color-brand)]"), children: size }, size)) }) });
|
|
3465
|
+
}
|
|
3466
|
+
function ActionMenu({ actions, row }) {
|
|
3467
|
+
const visible = actions.filter((action) => !action.show || action.show(row));
|
|
3468
|
+
if (!visible.length) return null;
|
|
3469
|
+
return /* @__PURE__ */ jsx32(DDropdown, { placement: "bottom-end", closeOnItemClick: true, scrollBehavior: "close", trigger: ({ open }) => /* @__PURE__ */ jsx32("span", { className: cn("inline-flex size-8 items-center justify-center rounded-lg border border-[var(--color-border)] bg-[var(--color-background)] text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]", open && "bg-[var(--color-surface-muted)] text-[var(--color-text)]"), children: /* @__PURE__ */ jsx32(MoreHorizontalIcon, { size: 16 }) }), children: /* @__PURE__ */ jsx32("div", { className: "min-w-[180px] py-1", children: visible.map((action, index) => /* @__PURE__ */ jsxs28("button", { type: "button", onClick: () => action.onClick(row), className: cn("flex w-full appearance-none items-center gap-2.5 rounded-[var(--radius-menu-item)] border-0 bg-transparent px-3 py-2.5 text-left text-sm hover:bg-[var(--color-surface-muted)]", action.variant === "danger" ? "text-[var(--color-danger)]" : "text-[var(--color-text)]"), children: [
|
|
3470
|
+
action.icon,
|
|
3471
|
+
action.label
|
|
3472
|
+
] }, index)) }) });
|
|
3473
|
+
}
|
|
3474
|
+
function DDataTable({ columns, data, rowKey = "id", loading = false, emptyMessage, onRowClick, sortBy, sortDirection, sortDir, onSort, pagination, onPageChange, onPageSizeChange, actions, searchable = false, searchPlaceholder, searchValue = "", onSearchChange, headerActions, filters }) {
|
|
3475
|
+
const { locale, t } = useDLocalization();
|
|
3476
|
+
const [showFilters, setShowFilters] = useState15(false);
|
|
3477
|
+
const direction = sortDirection ?? sortDir ?? "asc";
|
|
3478
|
+
const totalPages = pagination ? Math.max(1, Math.ceil(pagination.total / pagination.pageSize)) : 1;
|
|
3479
|
+
const resolvedEmpty = emptyMessage ?? t("dataTable.empty");
|
|
3480
|
+
const resolvedSearch = searchPlaceholder ?? t("dataTable.searchPlaceholder");
|
|
3481
|
+
const getKey = (row, index) => {
|
|
3482
|
+
if (typeof rowKey === "function") return rowKey(row, index);
|
|
3483
|
+
const value = rawValue(row, String(rowKey));
|
|
3484
|
+
return value === null || value === void 0 || value === "" ? String(index) : String(value);
|
|
3485
|
+
};
|
|
3486
|
+
const changeSort = (column) => {
|
|
3487
|
+
if (!column.sortable || !onSort) return;
|
|
3488
|
+
onSort(String(column.key), sortBy === String(column.key) && direction === "asc" ? "desc" : "asc");
|
|
3489
|
+
};
|
|
3490
|
+
const actionArray = Array.isArray(actions) ? actions : null;
|
|
3491
|
+
const actionRenderer = typeof actions === "function" ? actions : null;
|
|
3492
|
+
const hasActions = Boolean(actionArray?.length || actionRenderer);
|
|
3493
|
+
const renderActions = (row, index) => actionRenderer ? actionRenderer(row, index) : actionArray ? /* @__PURE__ */ jsx32(ActionMenu, { actions: actionArray, row }) : null;
|
|
3494
|
+
const renderValue = (column, row, index) => formatValue(column, row, index, locale, t);
|
|
3495
|
+
return /* @__PURE__ */ jsxs28("div", { "data-ds-component": "data-table", className: "overflow-visible rounded-[var(--radius-card)] border border-[var(--color-border)] bg-[var(--color-surface)]", children: [
|
|
3496
|
+
searchable || headerActions || filters ? /* @__PURE__ */ jsx32("div", { className: "space-y-4 border-b border-[var(--color-border)] px-4 py-3", children: /* @__PURE__ */ jsxs28("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between", children: [
|
|
3497
|
+
/* @__PURE__ */ jsxs28("div", { className: "flex w-full items-center gap-2 sm:w-auto", children: [
|
|
3498
|
+
searchable ? /* @__PURE__ */ jsx32(DSearchInput, { value: searchValue, onChange: (query) => onSearchChange?.(query), placeholder: resolvedSearch, debounceMs: 500, align: "left", expandedWidth: "260px" }) : null,
|
|
3499
|
+
filters ? /* @__PURE__ */ jsx32("button", { type: "button", "aria-label": t("dataTable.toggleFilters"), onClick: () => setShowFilters((value) => !value), className: cn("inline-flex h-9 w-11 appearance-none items-center justify-center rounded-xl border text-sm shadow-sm outline-none transition-all focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25", showFilters ? "border-[var(--color-brand)] bg-[var(--color-brand)] text-[var(--color-brand-foreground)]" : "border-[var(--color-border)] bg-[var(--color-background)] text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]"), children: /* @__PURE__ */ jsx32(FilterIcon, {}) }) : null
|
|
3500
|
+
] }),
|
|
3501
|
+
headerActions ? /* @__PURE__ */ jsx32("div", { className: "flex w-full shrink-0 items-center justify-end gap-2 sm:w-auto", children: headerActions }) : null
|
|
3502
|
+
] }) }) : null,
|
|
3503
|
+
filters ? /* @__PURE__ */ jsx32("div", { className: cn("overflow-hidden transition-all duration-300", showFilters ? "max-h-[220px] opacity-100" : "max-h-0 opacity-0"), children: /* @__PURE__ */ jsx32("div", { className: "flex flex-wrap items-center gap-2 border-b border-[var(--color-border)] px-4 py-3", children: filters }) }) : null,
|
|
3504
|
+
/* @__PURE__ */ jsx32("div", { className: "divide-y divide-[var(--color-border)] sm:hidden", children: loading ? Array.from({ length: 3 }, (_, index) => /* @__PURE__ */ jsxs28("div", { className: "space-y-2 p-4", children: [
|
|
3505
|
+
/* @__PURE__ */ jsx32(DSkeleton, { height: 16, width: "70%" }),
|
|
3506
|
+
/* @__PURE__ */ jsx32(DSkeleton, { height: 12, width: "50%" }),
|
|
3507
|
+
/* @__PURE__ */ jsx32(DSkeleton, { height: 12, width: "40%" })
|
|
3508
|
+
] }, index)) : data.length === 0 ? /* @__PURE__ */ jsx32("div", { className: "px-4 py-16 text-center text-sm text-[var(--color-text-muted)]", children: resolvedEmpty }) : data.map((row, index) => /* @__PURE__ */ jsxs28("div", { onClick: () => onRowClick?.(row), className: cn("p-4", onRowClick && "cursor-pointer active:bg-[var(--color-surface-muted)]/30"), children: [
|
|
3509
|
+
/* @__PURE__ */ jsxs28("div", { className: "flex items-start justify-between gap-2", children: [
|
|
3510
|
+
/* @__PURE__ */ jsx32("div", { className: "min-w-0 flex-1", children: columns.slice(0, 2).map((column, columnIndex) => /* @__PURE__ */ jsx32("div", { className: columnIndex === 0 ? "truncate text-sm font-medium text-[var(--color-text)]" : "mt-0.5 truncate text-xs text-[var(--color-text-muted)]", children: renderValue(column, row, index) }, String(column.key))) }),
|
|
3511
|
+
hasActions ? /* @__PURE__ */ jsx32("div", { onClick: (event) => event.stopPropagation(), children: renderActions(row, index) }) : null
|
|
3512
|
+
] }),
|
|
3513
|
+
columns.length > 2 ? /* @__PURE__ */ jsx32("div", { className: "mt-2 flex flex-wrap gap-x-4 gap-y-1", children: columns.slice(2).map((column) => /* @__PURE__ */ jsxs28("div", { className: "text-xs", children: [
|
|
3514
|
+
/* @__PURE__ */ jsxs28("span", { className: "text-[var(--color-text-muted)]", children: [
|
|
3515
|
+
column.label,
|
|
3516
|
+
": "
|
|
3517
|
+
] }),
|
|
3518
|
+
/* @__PURE__ */ jsx32("span", { className: "font-medium text-[var(--color-text)]", children: renderValue(column, row, index) })
|
|
3519
|
+
] }, String(column.key))) }) : null
|
|
3520
|
+
] }, getKey(row, index))) }),
|
|
3521
|
+
/* @__PURE__ */ jsx32("div", { className: "hidden overflow-x-auto sm:block", children: /* @__PURE__ */ jsxs28("table", { className: "w-full text-sm", children: [
|
|
3522
|
+
/* @__PURE__ */ jsx32("thead", { children: /* @__PURE__ */ jsxs28("tr", { className: "border-b border-[var(--color-border)] bg-[var(--color-surface-muted)]/40", children: [
|
|
3523
|
+
columns.map((column) => /* @__PURE__ */ jsx32("th", { style: column.width ? { width: column.width } : void 0, className: cn("whitespace-nowrap px-4 py-3 text-xs font-semibold text-[var(--color-text-muted)]", alignmentClass(column)), children: /* @__PURE__ */ jsxs28("button", { type: "button", disabled: !column.sortable, onClick: () => changeSort(column), className: cn("inline-flex appearance-none items-center gap-1 border-0 bg-transparent p-0 text-inherit outline-none", column.sortable && "cursor-pointer hover:text-[var(--color-text)] focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25"), children: [
|
|
3524
|
+
column.label,
|
|
3525
|
+
column.sortable && sortBy === String(column.key) ? direction === "asc" ? /* @__PURE__ */ jsx32(ArrowUpIcon, {}) : /* @__PURE__ */ jsx32(ArrowDownIcon, {}) : null
|
|
3526
|
+
] }) }, String(column.key))),
|
|
3527
|
+
hasActions ? /* @__PURE__ */ jsx32("th", { className: "w-16 px-4 py-3 text-right text-xs font-semibold text-[var(--color-text-muted)]", children: t("dataTable.actions") }) : null
|
|
3528
|
+
] }) }),
|
|
3529
|
+
/* @__PURE__ */ jsxs28("tbody", { children: [
|
|
3530
|
+
loading ? Array.from({ length: 5 }, (_, rowIndex) => /* @__PURE__ */ jsxs28("tr", { className: "border-b border-[var(--color-border)]/60 last:border-0", children: [
|
|
3531
|
+
columns.map((column, columnIndex) => /* @__PURE__ */ jsx32("td", { className: "px-4 py-3", children: /* @__PURE__ */ jsx32(DSkeleton, { height: 12, width: columnIndex === 0 ? "70%" : "50%" }) }, String(column.key))),
|
|
3532
|
+
hasActions ? /* @__PURE__ */ jsx32("td", { className: "px-4 py-3", children: /* @__PURE__ */ jsx32(DSkeleton, { height: 24, width: 24 }) }) : null
|
|
3533
|
+
] }, rowIndex)) : data.map((row, rowIndex) => /* @__PURE__ */ jsxs28("tr", { onClick: () => onRowClick?.(row), className: cn("border-b border-[var(--color-border)]/60 last:border-0 hover:bg-[var(--color-surface-muted)]/35", onRowClick && "cursor-pointer"), children: [
|
|
3534
|
+
columns.map((column) => /* @__PURE__ */ jsx32("td", { className: cn("px-4 py-3", alignmentClass(column)), children: renderValue(column, row, rowIndex) }, String(column.key))),
|
|
3535
|
+
hasActions ? /* @__PURE__ */ jsx32("td", { className: "px-4 py-3 text-right", onClick: (event) => event.stopPropagation(), children: renderActions(row, rowIndex) }) : null
|
|
3536
|
+
] }, getKey(row, rowIndex))),
|
|
3537
|
+
!loading && data.length === 0 ? /* @__PURE__ */ jsx32("tr", { children: /* @__PURE__ */ jsx32("td", { colSpan: columns.length + (hasActions ? 1 : 0), className: "px-4 py-16 text-center text-sm text-[var(--color-text-muted)]", children: resolvedEmpty }) }) : null
|
|
3538
|
+
] })
|
|
3539
|
+
] }) }),
|
|
3540
|
+
pagination ? /* @__PURE__ */ jsxs28("footer", { className: "flex flex-col items-center justify-between gap-3 border-t border-[var(--color-border)] px-4 py-3 text-xs text-[var(--color-text-muted)] sm:flex-row", children: [
|
|
3541
|
+
/* @__PURE__ */ jsxs28("div", { className: "flex items-center gap-2", children: [
|
|
3542
|
+
/* @__PURE__ */ jsx32("span", { children: t("dataTable.showing") }),
|
|
3543
|
+
/* @__PURE__ */ jsx32(PageSizeSelect, { value: pagination.pageSize, onChange: onPageSizeChange }),
|
|
3544
|
+
/* @__PURE__ */ jsx32("span", { children: t("dataTable.ofData", { total: pagination.total }) })
|
|
3545
|
+
] }),
|
|
3546
|
+
/* @__PURE__ */ jsxs28("div", { className: "flex items-center gap-1", children: [
|
|
3547
|
+
/* @__PURE__ */ jsx32("button", { type: "button", "aria-label": t("pagination.previous"), disabled: pagination.page <= 1, onClick: () => onPageChange?.(pagination.page - 1), className: "grid size-8 appearance-none place-items-center rounded-md border-0 bg-transparent text-[var(--color-text-muted)] outline-none hover:bg-[var(--color-surface-muted)] focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25 disabled:opacity-40", children: /* @__PURE__ */ jsx32(ChevronLeftIcon, { size: 16 }) }),
|
|
3548
|
+
getPaginationPages(pagination.page, totalPages).map((page) => /* @__PURE__ */ jsx32("button", { type: "button", "aria-label": t("pagination.page", { page }), onClick: () => onPageChange?.(page), className: cn("grid size-8 appearance-none place-items-center rounded-md border-0 bg-transparent outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25", page === pagination.page ? "bg-[var(--color-brand)] text-[var(--color-brand-foreground)]" : "text-[var(--color-text)] hover:bg-[var(--color-surface-muted)]"), children: page }, page)),
|
|
3549
|
+
/* @__PURE__ */ jsx32("button", { type: "button", "aria-label": t("pagination.next"), disabled: pagination.page >= totalPages, onClick: () => onPageChange?.(pagination.page + 1), className: "grid size-8 appearance-none place-items-center rounded-md border-0 bg-transparent text-[var(--color-text-muted)] outline-none hover:bg-[var(--color-surface-muted)] focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25 disabled:opacity-40", children: /* @__PURE__ */ jsx32(ChevronRightIcon, { size: 16 }) })
|
|
3550
|
+
] })
|
|
3551
|
+
] }) : null
|
|
3552
|
+
] });
|
|
3553
|
+
}
|
|
3554
|
+
|
|
3555
|
+
// src/textarea/textarea.tsx
|
|
3556
|
+
import {
|
|
3557
|
+
forwardRef as forwardRef5,
|
|
3558
|
+
useId as useId8
|
|
3559
|
+
} from "react";
|
|
3560
|
+
import { jsx as jsx33, jsxs as jsxs29 } from "react/jsx-runtime";
|
|
3561
|
+
function ClearIcon9() {
|
|
3562
|
+
return /* @__PURE__ */ jsx33("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx33("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
3563
|
+
}
|
|
3564
|
+
function eventWithValue2(value) {
|
|
3565
|
+
return { target: { value }, currentTarget: { value } };
|
|
3566
|
+
}
|
|
3567
|
+
var DTextarea = forwardRef5(function DTextarea2({
|
|
3568
|
+
label,
|
|
3569
|
+
error,
|
|
3570
|
+
hint,
|
|
3571
|
+
clearable = true,
|
|
3572
|
+
onClear,
|
|
3573
|
+
onChange,
|
|
3574
|
+
onNativeChange,
|
|
3575
|
+
containerClassName,
|
|
3576
|
+
className,
|
|
3577
|
+
value,
|
|
3578
|
+
disabled,
|
|
3579
|
+
readOnly,
|
|
3580
|
+
id: externalId,
|
|
3581
|
+
...props
|
|
3582
|
+
}, ref) {
|
|
3583
|
+
const { t } = useDLocalization();
|
|
3584
|
+
const autoId = useId8();
|
|
3585
|
+
const id = externalId ?? autoId;
|
|
3586
|
+
const hasValue = value !== void 0 && value !== null && value !== "";
|
|
3587
|
+
const clear = () => {
|
|
3588
|
+
const event = eventWithValue2("");
|
|
3589
|
+
onClear?.();
|
|
3590
|
+
onChange?.("", event);
|
|
3591
|
+
onNativeChange?.(event);
|
|
3592
|
+
};
|
|
3593
|
+
return /* @__PURE__ */ jsxs29("div", { "data-ds-component": "textarea", className: cn("flex min-w-0 flex-col gap-1.5", containerClassName), children: [
|
|
3594
|
+
label ? /* @__PURE__ */ jsx33("label", { htmlFor: id, className: "inline-block w-fit text-sm font-medium text-[var(--color-text)]", children: label }) : null,
|
|
3595
|
+
/* @__PURE__ */ jsxs29("div", { className: "relative", children: [
|
|
3596
|
+
/* @__PURE__ */ jsx33(
|
|
3597
|
+
"textarea",
|
|
3598
|
+
{
|
|
3599
|
+
...props,
|
|
3600
|
+
ref,
|
|
3601
|
+
id,
|
|
3602
|
+
value,
|
|
3603
|
+
disabled,
|
|
3604
|
+
readOnly,
|
|
3605
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
3606
|
+
onChange: (event) => {
|
|
3607
|
+
onChange?.(event.target.value, event);
|
|
3608
|
+
onNativeChange?.(event);
|
|
3609
|
+
},
|
|
3610
|
+
className: cn(
|
|
3611
|
+
"min-h-[80px] w-full resize-y rounded-[var(--radius-control)] border bg-[var(--color-surface)] px-3 py-2 text-sm text-[var(--color-text)] transition-colors duration-150 placeholder:text-[var(--color-text-muted)]/60 focus:border-[var(--color-brand)] focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20 disabled:cursor-not-allowed disabled:bg-[var(--color-surface-muted)] disabled:opacity-50 read-only:bg-[var(--color-surface-muted)]",
|
|
3612
|
+
error ? "border-[var(--color-danger)] focus:ring-[var(--color-danger)]/20" : "border-[var(--color-border)]",
|
|
3613
|
+
clearable && hasValue && !disabled && !readOnly && "pr-10",
|
|
3614
|
+
className
|
|
3615
|
+
)
|
|
3616
|
+
}
|
|
3617
|
+
),
|
|
3618
|
+
clearable && hasValue && !disabled && !readOnly ? /* @__PURE__ */ jsx33("button", { type: "button", tabIndex: -1, "aria-label": t("textarea.clear"), onMouseDown: (event) => event.preventDefault(), onClick: clear, className: "absolute right-2 top-2 rounded-md p-1 text-[var(--color-text-muted)] transition-colors hover:bg-[var(--color-surface-muted)] hover:text-[var(--color-text)]", children: /* @__PURE__ */ jsx33(ClearIcon9, {}) }) : null
|
|
3619
|
+
] }),
|
|
3620
|
+
error ? /* @__PURE__ */ jsx33("p", { className: "text-xs text-[var(--color-danger)]", children: error }) : null,
|
|
3621
|
+
!error && hint ? /* @__PURE__ */ jsx33("p", { className: "text-xs text-[var(--color-text-muted)]", children: hint }) : null
|
|
3622
|
+
] });
|
|
3623
|
+
});
|
|
3624
|
+
|
|
3625
|
+
// src/toast/toast.tsx
|
|
3626
|
+
import {
|
|
3627
|
+
createContext as createContext4,
|
|
3628
|
+
useCallback as useCallback4,
|
|
3629
|
+
useContext as useContext4,
|
|
3630
|
+
useEffect as useEffect14,
|
|
3631
|
+
useMemo as useMemo9,
|
|
3632
|
+
useRef as useRef12,
|
|
3633
|
+
useState as useState16
|
|
3634
|
+
} from "react";
|
|
3635
|
+
import { jsx as jsx34, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
3636
|
+
var ToastContext = createContext4(null);
|
|
3637
|
+
var toastSequence = 0;
|
|
3638
|
+
function createToastId() {
|
|
3639
|
+
toastSequence += 1;
|
|
3640
|
+
return `toast-${toastSequence}`;
|
|
3641
|
+
}
|
|
3642
|
+
function DToastProvider({
|
|
3643
|
+
children,
|
|
3644
|
+
limit = 3,
|
|
3645
|
+
defaultDuration = 4e3
|
|
3646
|
+
}) {
|
|
3647
|
+
const [toasts, setToasts] = useState16([]);
|
|
3648
|
+
const timers = useRef12(/* @__PURE__ */ new Map());
|
|
3649
|
+
const dismissToast = useCallback4((id) => {
|
|
3650
|
+
const timer = timers.current.get(id);
|
|
3651
|
+
if (timer) clearTimeout(timer);
|
|
3652
|
+
timers.current.delete(id);
|
|
3653
|
+
setToasts((current) => current.filter((toast) => toast.id !== id));
|
|
3654
|
+
}, []);
|
|
3655
|
+
const showToast = useCallback4(
|
|
3656
|
+
(input) => {
|
|
3657
|
+
const id = createToastId();
|
|
3658
|
+
const toast = { ...input, id };
|
|
3659
|
+
setToasts((current) => [...current, toast].slice(-Math.max(1, limit)));
|
|
3660
|
+
const duration = input.duration ?? defaultDuration;
|
|
3661
|
+
if (duration > 0) {
|
|
3662
|
+
timers.current.set(
|
|
3663
|
+
id,
|
|
3664
|
+
setTimeout(() => dismissToast(id), duration)
|
|
3665
|
+
);
|
|
3666
|
+
}
|
|
3667
|
+
return id;
|
|
3668
|
+
},
|
|
3669
|
+
[defaultDuration, dismissToast, limit]
|
|
3670
|
+
);
|
|
3671
|
+
useEffect14(
|
|
3672
|
+
() => () => {
|
|
3673
|
+
timers.current.forEach((timer) => clearTimeout(timer));
|
|
3674
|
+
timers.current.clear();
|
|
3675
|
+
},
|
|
3676
|
+
[]
|
|
3677
|
+
);
|
|
3678
|
+
const value = useMemo9(
|
|
3679
|
+
() => ({ toasts, showToast, dismissToast }),
|
|
3680
|
+
[dismissToast, showToast, toasts]
|
|
3681
|
+
);
|
|
3682
|
+
return /* @__PURE__ */ jsxs30(ToastContext.Provider, { value, children: [
|
|
3683
|
+
children,
|
|
3684
|
+
/* @__PURE__ */ jsx34(DToastContainer, { toasts, onDismiss: dismissToast })
|
|
3685
|
+
] });
|
|
3686
|
+
}
|
|
3687
|
+
function useToast() {
|
|
3688
|
+
const context = useContext4(ToastContext);
|
|
3689
|
+
if (!context) throw new Error("useToast must be used within a DToastProvider.");
|
|
3690
|
+
return context;
|
|
3691
|
+
}
|
|
3692
|
+
var toastStyle = {
|
|
3693
|
+
info: { wrap: "border-[var(--color-brand)]/30 bg-[var(--color-brand)]/10", icon: "text-[var(--color-brand)]" },
|
|
3694
|
+
success: { wrap: "border-[var(--color-success)]/30 bg-[var(--color-success)]/10", icon: "text-[var(--color-success)]" },
|
|
3695
|
+
warning: { wrap: "border-[var(--color-warning)]/30 bg-[var(--color-warning)]/10", icon: "text-[var(--color-warning)]" },
|
|
3696
|
+
danger: { wrap: "border-[var(--color-danger)]/30 bg-[var(--color-danger)]/10", icon: "text-[var(--color-danger)]" },
|
|
3697
|
+
error: { wrap: "border-[var(--color-danger)]/30 bg-[var(--color-danger)]/10", icon: "text-[var(--color-danger)]" }
|
|
3698
|
+
};
|
|
3699
|
+
function ToastIcon({ variant }) {
|
|
3700
|
+
if (variant === "success") return /* @__PURE__ */ jsxs30("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-[18px]", children: [
|
|
3701
|
+
/* @__PURE__ */ jsx34("circle", { cx: "12", cy: "12", r: "9" }),
|
|
3702
|
+
/* @__PURE__ */ jsx34("path", { d: "m8 12 3 3 5-6" })
|
|
3703
|
+
] });
|
|
3704
|
+
if (variant === "warning") return /* @__PURE__ */ jsxs30("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-[18px]", children: [
|
|
3705
|
+
/* @__PURE__ */ jsx34("path", { d: "M12 3 2 21h20L12 3Z" }),
|
|
3706
|
+
/* @__PURE__ */ jsx34("path", { d: "M12 9v4M12 17h.01" })
|
|
3707
|
+
] });
|
|
3708
|
+
if (variant === "danger" || variant === "error") return /* @__PURE__ */ jsxs30("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-[18px]", children: [
|
|
3709
|
+
/* @__PURE__ */ jsx34("circle", { cx: "12", cy: "12", r: "9" }),
|
|
3710
|
+
/* @__PURE__ */ jsx34("path", { d: "M12 8v5M12 16h.01" })
|
|
3711
|
+
] });
|
|
3712
|
+
return /* @__PURE__ */ jsxs30("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-[18px]", children: [
|
|
3713
|
+
/* @__PURE__ */ jsx34("circle", { cx: "12", cy: "12", r: "9" }),
|
|
3714
|
+
/* @__PURE__ */ jsx34("path", { d: "M12 10v6M12 7h.01" })
|
|
3715
|
+
] });
|
|
3716
|
+
}
|
|
3717
|
+
function ToastCloseIcon() {
|
|
3718
|
+
return /* @__PURE__ */ jsx34("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", className: "size-3.5", children: /* @__PURE__ */ jsx34("path", { d: "m18 6-12 12M6 6l12 12" }) });
|
|
3719
|
+
}
|
|
3720
|
+
function DToastContainer({ toasts, onDismiss, className }) {
|
|
3721
|
+
if (!toasts.length) return null;
|
|
3722
|
+
return /* @__PURE__ */ jsx34("div", { "aria-live": "polite", "aria-relevant": "additions", className: cn("pointer-events-none fixed right-4 top-4 z-[9998] flex w-full max-w-sm flex-col gap-2", className), children: toasts.map((toast) => {
|
|
3723
|
+
const variant = toast.variant ?? "info";
|
|
3724
|
+
const style = toastStyle[variant];
|
|
3725
|
+
return /* @__PURE__ */ jsxs30("section", { role: "status", className: cn("pointer-events-auto flex items-start gap-3 rounded-lg border px-4 py-3 shadow-lg backdrop-blur-sm animate-[toast-in_180ms_ease-out]", style.wrap), children: [
|
|
3726
|
+
/* @__PURE__ */ jsx34("span", { className: cn("shrink-0", style.icon), children: /* @__PURE__ */ jsx34(ToastIcon, { variant }) }),
|
|
3727
|
+
/* @__PURE__ */ jsxs30("div", { className: "min-w-0 flex-1", children: [
|
|
3728
|
+
/* @__PURE__ */ jsx34("p", { className: "text-sm font-medium text-[var(--color-text)]", children: toast.title }),
|
|
3729
|
+
toast.description ? /* @__PURE__ */ jsx34("div", { className: "mt-0.5 text-xs text-[var(--color-text-muted)]", children: toast.description }) : null
|
|
3730
|
+
] }),
|
|
3731
|
+
/* @__PURE__ */ jsx34("button", { type: "button", "aria-label": "Dismiss notification", onClick: () => onDismiss(toast.id), className: "shrink-0 rounded p-0.5 text-[var(--color-text-muted)] transition-colors hover:text-[var(--color-text)]", children: /* @__PURE__ */ jsx34(ToastCloseIcon, {}) })
|
|
3732
|
+
] }, toast.id);
|
|
3733
|
+
}) });
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3736
|
+
// src/radio/radio.tsx
|
|
3737
|
+
import { forwardRef as forwardRef6 } from "react";
|
|
3738
|
+
import { jsx as jsx35 } from "react/jsx-runtime";
|
|
3739
|
+
var DRadio = forwardRef6(function DRadio2({ className, ...props }, ref) {
|
|
3740
|
+
return /* @__PURE__ */ jsx35("input", { "data-ds-component": "radio", ref, type: "radio", className: cn("size-4 accent-[var(--color-brand)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/20", className), ...props });
|
|
3741
|
+
});
|
|
3742
|
+
|
|
3743
|
+
// src/toggle/toggle.tsx
|
|
3744
|
+
import { Fragment as Fragment4, jsx as jsx36, jsxs as jsxs31 } from "react/jsx-runtime";
|
|
3745
|
+
function DToggle({
|
|
3746
|
+
label,
|
|
3747
|
+
checked = false,
|
|
3748
|
+
onChange,
|
|
3749
|
+
disabled = false,
|
|
3750
|
+
fullWidth = false,
|
|
3751
|
+
size = "md",
|
|
3752
|
+
labelPosition = "left",
|
|
3753
|
+
gap = "gap-2.5",
|
|
3754
|
+
className,
|
|
3755
|
+
ariaLabel
|
|
3756
|
+
}) {
|
|
3757
|
+
const trackSize = size === "sm" ? "h-4 w-8" : "h-5 w-10";
|
|
3758
|
+
const thumbSize = size === "sm" ? "h-3 w-3" : "h-4 w-4";
|
|
3759
|
+
const translate = size === "sm" ? "translate-x-4" : "translate-x-5";
|
|
3760
|
+
const isVertical = labelPosition === "top" || labelPosition === "bottom";
|
|
3761
|
+
const labelEl = label ? /* @__PURE__ */ jsx36("span", { className: "text-sm text-[var(--color-text)]", children: label }) : null;
|
|
3762
|
+
const toggleEl = /* @__PURE__ */ jsx36(
|
|
3763
|
+
"button",
|
|
3764
|
+
{
|
|
3765
|
+
type: "button",
|
|
3766
|
+
role: "switch",
|
|
3767
|
+
"aria-label": ariaLabel,
|
|
3768
|
+
"aria-checked": checked,
|
|
3769
|
+
disabled,
|
|
3770
|
+
onClick: () => !disabled && onChange?.(!checked),
|
|
3771
|
+
className: cn(
|
|
3772
|
+
"relative inline-flex items-center rounded-full transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-[var(--color-brand)]/20",
|
|
3773
|
+
trackSize,
|
|
3774
|
+
checked ? "bg-[var(--color-brand)]" : "bg-[var(--color-border)]",
|
|
3775
|
+
disabled ? "cursor-not-allowed" : "cursor-pointer"
|
|
3776
|
+
),
|
|
3777
|
+
children: /* @__PURE__ */ jsx36("span", { className: cn("inline-block rounded-full bg-[var(--color-surface)] shadow-sm transition-transform duration-200", thumbSize, checked ? translate : "translate-x-0.5") })
|
|
3778
|
+
}
|
|
3779
|
+
);
|
|
3780
|
+
const content = labelPosition === "right" ? /* @__PURE__ */ jsxs31(Fragment4, { children: [
|
|
3781
|
+
toggleEl,
|
|
3782
|
+
labelEl
|
|
3783
|
+
] }) : labelPosition === "top" ? /* @__PURE__ */ jsxs31(Fragment4, { children: [
|
|
3784
|
+
labelEl,
|
|
3785
|
+
toggleEl
|
|
3786
|
+
] }) : labelPosition === "bottom" ? /* @__PURE__ */ jsxs31(Fragment4, { children: [
|
|
3787
|
+
toggleEl,
|
|
3788
|
+
labelEl
|
|
3789
|
+
] }) : /* @__PURE__ */ jsxs31(Fragment4, { children: [
|
|
3790
|
+
labelEl,
|
|
3791
|
+
toggleEl
|
|
3792
|
+
] });
|
|
3793
|
+
return /* @__PURE__ */ jsx36("div", { "data-ds-component": "toggle", className: cn(fullWidth ? "flex w-full items-center justify-between" : "inline-flex items-center", isVertical && "flex-col items-start", gap, disabled && "opacity-50", className), children: content });
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
// src/theme/theme.tsx
|
|
3797
|
+
import { useEffect as useEffect15 } from "react";
|
|
3798
|
+
import { Fragment as Fragment5, jsx as jsx37 } from "react/jsx-runtime";
|
|
3799
|
+
var variableMap = {
|
|
3800
|
+
background: "--color-background",
|
|
3801
|
+
surface: "--color-surface",
|
|
3802
|
+
surfaceMuted: "--color-surface-muted",
|
|
3803
|
+
text: "--color-text",
|
|
3804
|
+
textMuted: "--color-text-muted",
|
|
3805
|
+
border: "--color-border",
|
|
3806
|
+
brand: "--color-brand",
|
|
3807
|
+
brandHover: "--color-brand-hover",
|
|
3808
|
+
brandActive: "--color-brand-active",
|
|
3809
|
+
brandForeground: "--color-brand-foreground",
|
|
3810
|
+
secondary: "--color-secondary",
|
|
3811
|
+
secondaryHover: "--color-secondary-hover",
|
|
3812
|
+
secondaryActive: "--color-secondary-active",
|
|
3813
|
+
secondaryForeground: "--color-secondary-foreground",
|
|
3814
|
+
focus: "--color-focus",
|
|
3815
|
+
info: "--color-info",
|
|
3816
|
+
success: "--color-success",
|
|
3817
|
+
warning: "--color-warning",
|
|
3818
|
+
danger: "--color-danger",
|
|
3819
|
+
tooltip: "--color-tooltip",
|
|
3820
|
+
accentYellow: "--color-accent-yellow",
|
|
3821
|
+
accentMint: "--color-accent-mint",
|
|
3822
|
+
accentSky: "--color-accent-sky",
|
|
3823
|
+
accentLavender: "--color-accent-lavender",
|
|
3824
|
+
accentCoral: "--color-accent-coral",
|
|
3825
|
+
radiusControl: "--radius-control",
|
|
3826
|
+
radiusCard: "--radius-card",
|
|
3827
|
+
radiusPanel: "--radius-panel",
|
|
3828
|
+
shadowSm: "--shadow-sm",
|
|
3829
|
+
shadowMd: "--shadow-md",
|
|
3830
|
+
shadowLg: "--shadow-lg",
|
|
3831
|
+
shadowPanel: "--shadow-panel",
|
|
3832
|
+
fontSans: "--font-sans"
|
|
3833
|
+
};
|
|
3834
|
+
var defaultThemeTokens = {
|
|
3835
|
+
background: "hsl(220 25% 98%)",
|
|
3836
|
+
surface: "#ffffff",
|
|
3837
|
+
surfaceMuted: "hsl(220 15% 95%)",
|
|
3838
|
+
text: "hsl(220 20% 12%)",
|
|
3839
|
+
textMuted: "hsl(220 10% 50%)",
|
|
3840
|
+
border: "hsl(220 18% 90%)",
|
|
3841
|
+
brand: "hsl(217 91% 53%)",
|
|
3842
|
+
brandHover: "hsl(217 91% 47%)",
|
|
3843
|
+
brandActive: "hsl(217 91% 41%)",
|
|
3844
|
+
brandForeground: "#ffffff",
|
|
3845
|
+
secondary: "hsl(220 15% 95%)",
|
|
3846
|
+
secondaryHover: "hsl(220 15% 92%)",
|
|
3847
|
+
secondaryActive: "hsl(220 15% 88%)",
|
|
3848
|
+
secondaryForeground: "hsl(220 20% 12%)",
|
|
3849
|
+
focus: "hsl(217 91% 53%)",
|
|
3850
|
+
info: "hsl(200 90% 45%)",
|
|
3851
|
+
success: "hsl(145 65% 38%)",
|
|
3852
|
+
warning: "hsl(38 92% 50%)",
|
|
3853
|
+
danger: "hsl(0 72% 51%)",
|
|
3854
|
+
tooltip: "#1f2a44",
|
|
3855
|
+
accentYellow: "#f8e85d",
|
|
3856
|
+
accentMint: "#bfe4d2",
|
|
3857
|
+
accentSky: "#b9d8ef",
|
|
3858
|
+
accentLavender: "#cec4f5",
|
|
3859
|
+
accentCoral: "#f3a08b",
|
|
3860
|
+
radiusControl: "8px",
|
|
3861
|
+
radiusCard: "16px",
|
|
3862
|
+
radiusPanel: "16px",
|
|
3863
|
+
shadowSm: "0 1px 2px rgb(15 23 42 / 0.06)",
|
|
3864
|
+
shadowMd: "0 8px 24px rgb(15 23 42 / 0.10)",
|
|
3865
|
+
shadowLg: "0 18px 50px rgb(15 23 42 / 0.16)",
|
|
3866
|
+
shadowPanel: "0 8px 24px rgb(15 23 42 / 0.10)",
|
|
3867
|
+
fontSans: "'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
3868
|
+
};
|
|
3869
|
+
function themeTokensToCss(tokens) {
|
|
3870
|
+
return Object.entries(tokens).filter(([, value]) => value != null && value !== "").map(([key, value]) => `${variableMap[key]}: ${value};`).join("\n");
|
|
3871
|
+
}
|
|
3872
|
+
function createProjectThemeTokens(project) {
|
|
3873
|
+
return {
|
|
3874
|
+
background: project.background,
|
|
3875
|
+
surface: project.surface,
|
|
3876
|
+
surfaceMuted: project.surfaceMuted,
|
|
3877
|
+
text: project.text,
|
|
3878
|
+
textMuted: project.textMuted,
|
|
3879
|
+
border: project.border,
|
|
3880
|
+
brand: project.primary,
|
|
3881
|
+
brandHover: project.primaryHover ?? project.primary,
|
|
3882
|
+
brandActive: project.primaryActive ?? project.primaryHover ?? project.primary,
|
|
3883
|
+
brandForeground: project.onPrimary,
|
|
3884
|
+
secondary: project.secondary,
|
|
3885
|
+
secondaryHover: project.secondaryHover ?? project.secondary,
|
|
3886
|
+
secondaryActive: project.secondaryActive ?? project.secondaryHover ?? project.secondary,
|
|
3887
|
+
secondaryForeground: project.onSecondary,
|
|
3888
|
+
focus: project.focus ?? project.primary,
|
|
3889
|
+
info: project.info,
|
|
3890
|
+
success: project.success,
|
|
3891
|
+
warning: project.warning,
|
|
3892
|
+
danger: project.danger,
|
|
3893
|
+
tooltip: project.tooltip,
|
|
3894
|
+
radiusControl: project.radiusControl,
|
|
3895
|
+
radiusCard: project.radiusCard,
|
|
3896
|
+
radiusPanel: project.radiusPanel,
|
|
3897
|
+
shadowSm: project.shadowSm,
|
|
3898
|
+
shadowMd: project.shadowMd,
|
|
3899
|
+
shadowLg: project.shadowLg,
|
|
3900
|
+
shadowPanel: project.shadowMd,
|
|
3901
|
+
fontSans: project.fontSans
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
function asCssVariable(variableName) {
|
|
3905
|
+
const normalized = variableName.startsWith("--") ? variableName : `--${variableName}`;
|
|
3906
|
+
return `var(${normalized})`;
|
|
3907
|
+
}
|
|
3908
|
+
function createCssVariableTheme(map) {
|
|
3909
|
+
const project = Object.fromEntries(
|
|
3910
|
+
Object.entries(map).map(([key, variableName]) => [key, variableName ? asCssVariable(variableName) : void 0])
|
|
3911
|
+
);
|
|
3912
|
+
return createProjectThemeTokens(project);
|
|
3913
|
+
}
|
|
3914
|
+
function DThemeProvider({ children, tokens = {}, radius = "inherit", mode = "inherit" }) {
|
|
3915
|
+
useEffect15(() => {
|
|
3916
|
+
if (typeof document === "undefined") return;
|
|
3917
|
+
const root = document.documentElement;
|
|
3918
|
+
const previousMode = root.getAttribute("data-ds-mode");
|
|
3919
|
+
const previousRadius = root.getAttribute("data-theme-radius");
|
|
3920
|
+
const previous = /* @__PURE__ */ new Map();
|
|
3921
|
+
Object.entries(tokens).forEach(([key, value]) => {
|
|
3922
|
+
if (value == null || value === "") return;
|
|
3923
|
+
const variable = variableMap[key];
|
|
3924
|
+
previous.set(variable, root.style.getPropertyValue(variable));
|
|
3925
|
+
root.style.setProperty(variable, value);
|
|
3926
|
+
});
|
|
3927
|
+
if (mode !== "inherit") root.setAttribute("data-ds-mode", mode);
|
|
3928
|
+
if (radius !== "inherit") root.setAttribute("data-theme-radius", radius.toUpperCase());
|
|
3929
|
+
return () => {
|
|
3930
|
+
previous.forEach((value, variable) => {
|
|
3931
|
+
if (value) root.style.setProperty(variable, value);
|
|
3932
|
+
else root.style.removeProperty(variable);
|
|
3933
|
+
});
|
|
3934
|
+
if (mode !== "inherit") {
|
|
3935
|
+
if (previousMode == null) root.removeAttribute("data-ds-mode");
|
|
3936
|
+
else root.setAttribute("data-ds-mode", previousMode);
|
|
3937
|
+
}
|
|
3938
|
+
if (radius !== "inherit") {
|
|
3939
|
+
if (previousRadius == null) root.removeAttribute("data-theme-radius");
|
|
3940
|
+
else root.setAttribute("data-theme-radius", previousRadius);
|
|
3941
|
+
}
|
|
3942
|
+
};
|
|
3943
|
+
}, [mode, radius, tokens]);
|
|
3944
|
+
return /* @__PURE__ */ jsx37(Fragment5, { children });
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
// src/avatar/avatar.tsx
|
|
3948
|
+
import { jsx as jsx38, jsxs as jsxs32 } from "react/jsx-runtime";
|
|
3949
|
+
var sizeClass = { xs: "size-6 text-[9px]", sm: "size-8 text-xs", md: "size-10 text-sm", lg: "size-12 text-base", xl: "size-16 text-lg" };
|
|
3950
|
+
var dotSize = { xs: "size-1.5", sm: "size-2", md: "size-2.5", lg: "size-3", xl: "size-3.5" };
|
|
3951
|
+
var statusClass = { online: "bg-[var(--color-success)]", offline: "bg-[var(--color-text-muted)]", busy: "bg-[var(--color-danger)]", away: "bg-[var(--color-warning)]" };
|
|
3952
|
+
function initials(name) {
|
|
3953
|
+
return name?.trim().split(/\s+/).slice(0, 2).map((part) => part[0]?.toUpperCase()).join("") || "?";
|
|
3954
|
+
}
|
|
3955
|
+
function DAvatar({ src, alt, name, fallback, size = "md", status, className, ...props }) {
|
|
3956
|
+
return /* @__PURE__ */ jsxs32("div", { className: cn("relative inline-flex shrink-0", className), ...props, children: [
|
|
3957
|
+
/* @__PURE__ */ jsx38("div", { className: cn("grid place-items-center overflow-hidden rounded-full border border-[var(--color-border)] bg-[var(--color-surface-muted)] font-semibold text-[var(--color-text-muted)]", sizeClass[size]), children: src ? /* @__PURE__ */ jsx38("img", { src, alt: alt ?? name ?? "", className: "size-full object-cover" }) : fallback ?? initials(name) }),
|
|
3958
|
+
status ? /* @__PURE__ */ jsx38("span", { "aria-label": status, className: cn("absolute bottom-0 right-0 rounded-full ring-2 ring-[var(--color-surface)]", dotSize[size], statusClass[status]) }) : null
|
|
3959
|
+
] });
|
|
3960
|
+
}
|
|
3961
|
+
|
|
3962
|
+
// src/tooltip/tooltip.tsx
|
|
3963
|
+
import { cloneElement, useEffect as useEffect16, useId as useId9, useRef as useRef13, useState as useState17 } from "react";
|
|
3964
|
+
import { jsx as jsx39, jsxs as jsxs33 } from "react/jsx-runtime";
|
|
3965
|
+
var placementClass = {
|
|
3966
|
+
top: "bottom-full left-1/2 mb-2 -translate-x-1/2",
|
|
3967
|
+
bottom: "left-1/2 top-full mt-2 -translate-x-1/2",
|
|
3968
|
+
left: "right-full top-1/2 mr-2 -translate-y-1/2",
|
|
3969
|
+
right: "left-full top-1/2 ml-2 -translate-y-1/2"
|
|
3970
|
+
};
|
|
3971
|
+
function DTooltip({ content, children, placement = "top", className, delayMs = 120 }) {
|
|
3972
|
+
const id = useId9();
|
|
3973
|
+
const [open, setOpen] = useState17(false);
|
|
3974
|
+
const timerRef = useRef13(null);
|
|
3975
|
+
const child = children;
|
|
3976
|
+
const clearTimer = () => {
|
|
3977
|
+
if (timerRef.current !== null) {
|
|
3978
|
+
clearTimeout(timerRef.current);
|
|
3979
|
+
timerRef.current = null;
|
|
3980
|
+
}
|
|
3981
|
+
};
|
|
3982
|
+
const show = () => {
|
|
3983
|
+
clearTimer();
|
|
3984
|
+
timerRef.current = setTimeout(() => {
|
|
3985
|
+
timerRef.current = null;
|
|
3986
|
+
setOpen(true);
|
|
3987
|
+
}, delayMs);
|
|
3988
|
+
};
|
|
3989
|
+
const hide = () => {
|
|
3990
|
+
clearTimer();
|
|
3991
|
+
setOpen(false);
|
|
3992
|
+
};
|
|
3993
|
+
useEffect16(() => clearTimer, []);
|
|
3994
|
+
const trigger = cloneElement(child, {
|
|
3995
|
+
"aria-describedby": open ? id : child.props["aria-describedby"]
|
|
3996
|
+
});
|
|
3997
|
+
return /* @__PURE__ */ jsxs33(
|
|
3998
|
+
"span",
|
|
3999
|
+
{
|
|
4000
|
+
className: "relative inline-flex",
|
|
4001
|
+
onMouseEnter: show,
|
|
4002
|
+
onMouseLeave: hide,
|
|
4003
|
+
onFocus: () => {
|
|
4004
|
+
clearTimer();
|
|
4005
|
+
setOpen(true);
|
|
4006
|
+
},
|
|
4007
|
+
onBlur: hide,
|
|
4008
|
+
children: [
|
|
4009
|
+
trigger,
|
|
4010
|
+
/* @__PURE__ */ jsx39(
|
|
4011
|
+
"span",
|
|
4012
|
+
{
|
|
4013
|
+
id,
|
|
4014
|
+
role: "tooltip",
|
|
4015
|
+
className: cn(
|
|
4016
|
+
"pointer-events-none absolute z-[100] w-max max-w-64 rounded-lg bg-[var(--color-tooltip)] px-2.5 py-1.5 text-xs leading-relaxed text-white shadow-lg transition-all duration-150",
|
|
4017
|
+
placementClass[placement],
|
|
4018
|
+
open ? "visible opacity-100" : "invisible opacity-0",
|
|
4019
|
+
className
|
|
4020
|
+
),
|
|
4021
|
+
children: content
|
|
4022
|
+
}
|
|
4023
|
+
)
|
|
4024
|
+
]
|
|
4025
|
+
}
|
|
4026
|
+
);
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
// src/separator/separator.tsx
|
|
4030
|
+
import { jsx as jsx40 } from "react/jsx-runtime";
|
|
4031
|
+
function DSeparator({ orientation = "horizontal", decorative = true, className, ...props }) {
|
|
4032
|
+
return /* @__PURE__ */ jsx40("div", { role: decorative ? "none" : "separator", "aria-orientation": decorative ? void 0 : orientation, className: cn("shrink-0 bg-[var(--color-border)]", orientation === "horizontal" ? "h-px w-full" : "h-full min-h-4 w-px", className), ...props });
|
|
4033
|
+
}
|
|
4034
|
+
|
|
4035
|
+
// src/spinner/spinner.tsx
|
|
4036
|
+
import { jsx as jsx41 } from "react/jsx-runtime";
|
|
4037
|
+
var sizes = { sm: "size-3.5 border-2", md: "size-5 border-2", lg: "size-8 border-[3px]" };
|
|
4038
|
+
function DSpinner({ size = "md", label = "Loading", className, ...props }) {
|
|
4039
|
+
return /* @__PURE__ */ jsx41("span", { role: "status", "aria-label": label, className: cn("inline-block animate-spin rounded-full border-current border-t-transparent text-[var(--color-brand)]", sizes[size], className), ...props });
|
|
4040
|
+
}
|
|
4041
|
+
|
|
4042
|
+
// src/pagination/pagination.tsx
|
|
4043
|
+
import { jsx as jsx42, jsxs as jsxs34 } from "react/jsx-runtime";
|
|
4044
|
+
function getPaginationItems(page, total, sibling = 1) {
|
|
4045
|
+
if (total <= 7) return Array.from({ length: Math.max(total, 0) }, (_, i) => i + 1);
|
|
4046
|
+
const start = Math.max(2, page - sibling);
|
|
4047
|
+
const end = Math.min(total - 1, page + sibling);
|
|
4048
|
+
const items = [1];
|
|
4049
|
+
if (start > 2) items.push("ellipsis");
|
|
4050
|
+
for (let i = start; i <= end; i += 1) items.push(i);
|
|
4051
|
+
if (end < total - 1) items.push("ellipsis");
|
|
4052
|
+
items.push(total);
|
|
4053
|
+
return items;
|
|
4054
|
+
}
|
|
4055
|
+
var pageButtonBase = "grid size-9 appearance-none place-items-center rounded-lg text-sm font-medium outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25 disabled:cursor-not-allowed disabled:opacity-40";
|
|
4056
|
+
function DPagination({
|
|
4057
|
+
page,
|
|
4058
|
+
totalPages,
|
|
4059
|
+
onChange,
|
|
4060
|
+
siblingCount = 1,
|
|
4061
|
+
disabled = false,
|
|
4062
|
+
className
|
|
4063
|
+
}) {
|
|
4064
|
+
const { t } = useDLocalization();
|
|
4065
|
+
const go = (next) => {
|
|
4066
|
+
if (!disabled && next >= 1 && next <= totalPages && next !== page) onChange(next);
|
|
4067
|
+
};
|
|
4068
|
+
return /* @__PURE__ */ jsxs34("nav", { "data-ds-component": "pagination", "aria-label": t("pagination.label"), className: cn("flex items-center gap-1", className), children: [
|
|
4069
|
+
/* @__PURE__ */ jsx42(
|
|
4070
|
+
"button",
|
|
4071
|
+
{
|
|
4072
|
+
type: "button",
|
|
4073
|
+
"aria-label": t("pagination.previous"),
|
|
4074
|
+
disabled: disabled || page <= 1,
|
|
4075
|
+
onClick: () => go(page - 1),
|
|
4076
|
+
className: cn(pageButtonBase, "border border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]"),
|
|
4077
|
+
children: /* @__PURE__ */ jsx42(ChevronLeftIcon, { size: 16 })
|
|
4078
|
+
}
|
|
4079
|
+
),
|
|
4080
|
+
getPaginationItems(page, totalPages, siblingCount).map((item, index) => item === "ellipsis" ? /* @__PURE__ */ jsx42("span", { "aria-hidden": "true", className: "grid size-9 place-items-center text-[var(--color-text-muted)]", children: /* @__PURE__ */ jsx42(MoreHorizontalIcon, { size: 16 }) }, `e-${index}`) : /* @__PURE__ */ jsx42(
|
|
4081
|
+
"button",
|
|
4082
|
+
{
|
|
4083
|
+
type: "button",
|
|
4084
|
+
"aria-current": item === page ? "page" : void 0,
|
|
4085
|
+
onClick: () => go(item),
|
|
4086
|
+
className: cn(
|
|
4087
|
+
pageButtonBase,
|
|
4088
|
+
item === page ? "border border-[var(--color-brand)] bg-[var(--color-brand)] text-[var(--color-brand-foreground)]" : "border border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-text)] hover:bg-[var(--color-surface-muted)]"
|
|
4089
|
+
),
|
|
4090
|
+
children: item
|
|
4091
|
+
},
|
|
4092
|
+
item
|
|
4093
|
+
)),
|
|
4094
|
+
/* @__PURE__ */ jsx42(
|
|
4095
|
+
"button",
|
|
4096
|
+
{
|
|
4097
|
+
type: "button",
|
|
4098
|
+
"aria-label": t("pagination.next"),
|
|
4099
|
+
disabled: disabled || page >= totalPages,
|
|
4100
|
+
onClick: () => go(page + 1),
|
|
4101
|
+
className: cn(pageButtonBase, "border border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-text-muted)] hover:bg-[var(--color-surface-muted)]"),
|
|
4102
|
+
children: /* @__PURE__ */ jsx42(ChevronRightIcon, { size: 16 })
|
|
4103
|
+
}
|
|
4104
|
+
)
|
|
4105
|
+
] });
|
|
4106
|
+
}
|
|
4107
|
+
|
|
4108
|
+
// src/tabs/tabs.tsx
|
|
4109
|
+
import { createContext as createContext5, useContext as useContext5, useId as useId10, useState as useState18 } from "react";
|
|
4110
|
+
import { jsx as jsx43 } from "react/jsx-runtime";
|
|
4111
|
+
var TabsContext = createContext5(null);
|
|
4112
|
+
function useTabs() {
|
|
4113
|
+
const ctx = useContext5(TabsContext);
|
|
4114
|
+
if (!ctx) throw new Error("DTabs components must be inside <DTabs>.");
|
|
4115
|
+
return ctx;
|
|
4116
|
+
}
|
|
4117
|
+
function DTabs({ value, defaultValue, onValueChange, children, className, ...props }) {
|
|
4118
|
+
const [internal, setInternal] = useState18(defaultValue);
|
|
4119
|
+
const current = value ?? internal;
|
|
4120
|
+
const baseId = useId10();
|
|
4121
|
+
const setValue = (next) => {
|
|
4122
|
+
if (value === void 0) setInternal(next);
|
|
4123
|
+
onValueChange?.(next);
|
|
4124
|
+
};
|
|
4125
|
+
return /* @__PURE__ */ jsx43(TabsContext.Provider, { value: { value: current, setValue, baseId }, children: /* @__PURE__ */ jsx43("div", { "data-ds-component": "tabs", className, ...props, children }) });
|
|
4126
|
+
}
|
|
4127
|
+
function DTabsList({ className, onKeyDown, ...props }) {
|
|
4128
|
+
return /* @__PURE__ */ jsx43(
|
|
4129
|
+
"div",
|
|
4130
|
+
{
|
|
4131
|
+
role: "tablist",
|
|
4132
|
+
className: cn("inline-flex items-center rounded-xl bg-[var(--color-surface-muted)] p-1", className),
|
|
4133
|
+
onKeyDown: (event) => {
|
|
4134
|
+
onKeyDown?.(event);
|
|
4135
|
+
if (event.defaultPrevented || !["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
4136
|
+
const tabs = Array.from(event.currentTarget.querySelectorAll("[role=tab]:not(:disabled)"));
|
|
4137
|
+
if (!tabs.length) return;
|
|
4138
|
+
const index = tabs.indexOf(document.activeElement);
|
|
4139
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : event.key === "ArrowRight" ? (index + 1 + tabs.length) % tabs.length : (index - 1 + tabs.length) % tabs.length;
|
|
4140
|
+
event.preventDefault();
|
|
4141
|
+
tabs[next]?.focus();
|
|
4142
|
+
tabs[next]?.click();
|
|
4143
|
+
},
|
|
4144
|
+
...props
|
|
4145
|
+
}
|
|
4146
|
+
);
|
|
4147
|
+
}
|
|
4148
|
+
function DTabsTrigger({ value, disabled, className, children, ...props }) {
|
|
4149
|
+
const ctx = useTabs();
|
|
4150
|
+
const active = ctx.value === value;
|
|
4151
|
+
return /* @__PURE__ */ jsx43(
|
|
4152
|
+
"button",
|
|
4153
|
+
{
|
|
4154
|
+
type: "button",
|
|
4155
|
+
role: "tab",
|
|
4156
|
+
id: `${ctx.baseId}-tab-${value}`,
|
|
4157
|
+
"aria-selected": active,
|
|
4158
|
+
"aria-controls": `${ctx.baseId}-panel-${value}`,
|
|
4159
|
+
disabled,
|
|
4160
|
+
onClick: () => ctx.setValue(value),
|
|
4161
|
+
className: cn(
|
|
4162
|
+
"appearance-none rounded-lg border-0 bg-transparent px-3 py-1.5 text-sm font-medium outline-none transition-all duration-150 focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25",
|
|
4163
|
+
active ? "bg-[var(--color-surface)] text-[var(--color-text)] shadow-sm" : "text-[var(--color-text-muted)] hover:text-[var(--color-text)]",
|
|
4164
|
+
disabled && "cursor-not-allowed opacity-40",
|
|
4165
|
+
className
|
|
4166
|
+
),
|
|
4167
|
+
...props,
|
|
4168
|
+
children
|
|
4169
|
+
}
|
|
4170
|
+
);
|
|
4171
|
+
}
|
|
4172
|
+
function DTabsContent({ value, className, ...props }) {
|
|
4173
|
+
const ctx = useTabs();
|
|
4174
|
+
if (ctx.value !== value) return null;
|
|
4175
|
+
return /* @__PURE__ */ jsx43("div", { role: "tabpanel", id: `${ctx.baseId}-panel-${value}`, "aria-labelledby": `${ctx.baseId}-tab-${value}`, className, ...props });
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
// src/accordion/accordion.tsx
|
|
4179
|
+
import { createContext as createContext6, useContext as useContext6, useId as useId11, useState as useState19 } from "react";
|
|
4180
|
+
import { jsx as jsx44, jsxs as jsxs35 } from "react/jsx-runtime";
|
|
4181
|
+
var AccordionContext = createContext6(null);
|
|
4182
|
+
function useAccordion() {
|
|
4183
|
+
const context = useContext6(AccordionContext);
|
|
4184
|
+
if (!context) throw new Error("DAccordionItem must be inside <DAccordion>.");
|
|
4185
|
+
return context;
|
|
4186
|
+
}
|
|
4187
|
+
function DAccordion({
|
|
4188
|
+
type = "single",
|
|
4189
|
+
value,
|
|
4190
|
+
defaultValue = [],
|
|
4191
|
+
onValueChange,
|
|
4192
|
+
variant = "default",
|
|
4193
|
+
className,
|
|
4194
|
+
...props
|
|
4195
|
+
}) {
|
|
4196
|
+
const [internal, setInternal] = useState19(defaultValue);
|
|
4197
|
+
const current = value ?? internal;
|
|
4198
|
+
const baseId = useId11();
|
|
4199
|
+
const toggle = (itemValue) => {
|
|
4200
|
+
const next = current.includes(itemValue) ? current.filter((item) => item !== itemValue) : type === "multiple" ? [...current, itemValue] : [itemValue];
|
|
4201
|
+
if (value === void 0) setInternal(next);
|
|
4202
|
+
onValueChange?.(next);
|
|
4203
|
+
};
|
|
4204
|
+
return /* @__PURE__ */ jsx44(AccordionContext.Provider, { value: { open: current, toggle, baseId, variant }, children: /* @__PURE__ */ jsx44(
|
|
4205
|
+
"div",
|
|
4206
|
+
{
|
|
4207
|
+
"data-ds-component": "accordion",
|
|
4208
|
+
"data-accordion-variant": variant,
|
|
4209
|
+
className: cn(
|
|
4210
|
+
variant === "card" && "overflow-hidden rounded-[var(--radius-card)] border border-[var(--color-border)] bg-[var(--color-surface)]",
|
|
4211
|
+
variant === "separated" && "space-y-2",
|
|
4212
|
+
className
|
|
4213
|
+
),
|
|
4214
|
+
...props
|
|
4215
|
+
}
|
|
4216
|
+
) });
|
|
4217
|
+
}
|
|
4218
|
+
function DAccordionItem({ value, title, disabled, className, children, ...props }) {
|
|
4219
|
+
const context = useAccordion();
|
|
4220
|
+
const open = context.open.includes(value);
|
|
4221
|
+
const id = `${context.baseId}-${value.replace(/[^a-zA-Z0-9_-]/g, "-")}`;
|
|
4222
|
+
const triggerId = `${id}-trigger`;
|
|
4223
|
+
const contentId = `${id}-content`;
|
|
4224
|
+
return /* @__PURE__ */ jsxs35(
|
|
4225
|
+
"div",
|
|
4226
|
+
{
|
|
4227
|
+
className: cn(
|
|
4228
|
+
context.variant === "separator" && "border-b border-[var(--color-border)] last:border-b-0",
|
|
4229
|
+
context.variant === "card" && "border-b border-[var(--color-border)] px-4 last:border-b-0",
|
|
4230
|
+
context.variant === "separated" && "overflow-hidden rounded-[var(--radius-control)] border border-[var(--color-border)] bg-[var(--color-surface)] px-4",
|
|
4231
|
+
(context.variant === "default" || context.variant === "separator") && "px-0",
|
|
4232
|
+
className
|
|
4233
|
+
),
|
|
4234
|
+
...props,
|
|
4235
|
+
children: [
|
|
4236
|
+
/* @__PURE__ */ jsxs35(
|
|
4237
|
+
"button",
|
|
4238
|
+
{
|
|
4239
|
+
id: triggerId,
|
|
4240
|
+
type: "button",
|
|
4241
|
+
disabled,
|
|
4242
|
+
"aria-expanded": open,
|
|
4243
|
+
"aria-controls": contentId,
|
|
4244
|
+
onClick: () => context.toggle(value),
|
|
4245
|
+
className: "group flex w-full appearance-none items-center justify-between gap-4 border-0 bg-transparent py-3 text-left text-sm font-medium text-[var(--color-text)] outline-none transition-colors duration-150 hover:text-[var(--color-brand)] focus-visible:ring-2 focus-visible:ring-[var(--color-focus)]/25 disabled:cursor-not-allowed disabled:opacity-40",
|
|
4246
|
+
children: [
|
|
4247
|
+
/* @__PURE__ */ jsx44("span", { children: title }),
|
|
4248
|
+
/* @__PURE__ */ jsx44(
|
|
4249
|
+
ChevronDownIcon,
|
|
4250
|
+
{
|
|
4251
|
+
size: 17,
|
|
4252
|
+
className: cn("shrink-0 text-[var(--color-text-muted)] transition-transform duration-200 ease-out group-hover:text-current", open && "rotate-180")
|
|
4253
|
+
}
|
|
4254
|
+
)
|
|
4255
|
+
]
|
|
4256
|
+
}
|
|
4257
|
+
),
|
|
4258
|
+
/* @__PURE__ */ jsx44(
|
|
4259
|
+
"div",
|
|
4260
|
+
{
|
|
4261
|
+
id: contentId,
|
|
4262
|
+
role: "region",
|
|
4263
|
+
"aria-labelledby": triggerId,
|
|
4264
|
+
"aria-hidden": !open,
|
|
4265
|
+
className: cn(
|
|
4266
|
+
"grid transition-[grid-template-rows,opacity] duration-200 ease-out motion-reduce:transition-none",
|
|
4267
|
+
open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"
|
|
4268
|
+
),
|
|
4269
|
+
children: /* @__PURE__ */ jsx44("div", { className: "min-h-0 overflow-hidden", children: /* @__PURE__ */ jsx44("div", { className: "pb-4 text-sm leading-relaxed text-[var(--color-text-muted)]", children }) })
|
|
4270
|
+
}
|
|
4271
|
+
)
|
|
4272
|
+
]
|
|
4273
|
+
}
|
|
4274
|
+
);
|
|
4275
|
+
}
|
|
4276
|
+
|
|
4277
|
+
// src/breadcrumb/breadcrumb.tsx
|
|
4278
|
+
import { jsx as jsx45 } from "react/jsx-runtime";
|
|
4279
|
+
function DBreadcrumb({ className, ...props }) {
|
|
4280
|
+
return /* @__PURE__ */ jsx45("nav", { "aria-label": "DBreadcrumb", className, ...props });
|
|
4281
|
+
}
|
|
4282
|
+
function DBreadcrumbList({ className, ...props }) {
|
|
4283
|
+
return /* @__PURE__ */ jsx45("ol", { className: cn("flex flex-wrap items-center gap-2 text-sm text-[var(--color-text-muted)]", className), ...props });
|
|
4284
|
+
}
|
|
4285
|
+
function DBreadcrumbItem({ className, ...props }) {
|
|
4286
|
+
return /* @__PURE__ */ jsx45("li", { className: cn("inline-flex items-center gap-2", className), ...props });
|
|
4287
|
+
}
|
|
4288
|
+
function DBreadcrumbLink({ active = false, className, ...props }) {
|
|
4289
|
+
return /* @__PURE__ */ jsx45("a", { "aria-current": active ? "page" : void 0, className: cn(active ? "font-medium text-[var(--color-text)]" : "transition-colors hover:text-[var(--color-text)]", className), ...props });
|
|
4290
|
+
}
|
|
4291
|
+
function DBreadcrumbSeparator({ children = "/", className, ...props }) {
|
|
4292
|
+
return /* @__PURE__ */ jsx45("span", { "aria-hidden": "true", className: cn("text-[var(--color-border)]", className), ...props, children });
|
|
4293
|
+
}
|
|
4294
|
+
export {
|
|
4295
|
+
DAccordion,
|
|
4296
|
+
DAccordionItem,
|
|
4297
|
+
DAlert,
|
|
4298
|
+
DAvatar,
|
|
4299
|
+
DBadge,
|
|
4300
|
+
DBreadcrumb,
|
|
4301
|
+
DBreadcrumbItem,
|
|
4302
|
+
DBreadcrumbLink,
|
|
4303
|
+
DBreadcrumbList,
|
|
4304
|
+
DBreadcrumbSeparator,
|
|
4305
|
+
DButton,
|
|
4306
|
+
DCard,
|
|
4307
|
+
DCardContent,
|
|
4308
|
+
DCardFooter,
|
|
4309
|
+
DCardHeader,
|
|
4310
|
+
DCardSkeleton,
|
|
4311
|
+
DCheckbox,
|
|
4312
|
+
DCombobox,
|
|
4313
|
+
DConfirmDialog,
|
|
4314
|
+
DConnectionError,
|
|
4315
|
+
DCurrencyInput,
|
|
4316
|
+
DDataTable,
|
|
4317
|
+
DDatePicker,
|
|
4318
|
+
DDateRangeFilter,
|
|
4319
|
+
DDecimalInput,
|
|
4320
|
+
DDialog,
|
|
4321
|
+
DDropdown,
|
|
4322
|
+
DEmptyState,
|
|
4323
|
+
DExportButton,
|
|
4324
|
+
DForm,
|
|
4325
|
+
DFormField,
|
|
4326
|
+
DFormSkeleton,
|
|
4327
|
+
DInfoNote,
|
|
4328
|
+
DInput,
|
|
4329
|
+
DLoadingIndicator,
|
|
4330
|
+
DLoadingOverlay,
|
|
4331
|
+
DLocalizationProvider,
|
|
4332
|
+
DNotificationPanel,
|
|
4333
|
+
DPagination,
|
|
4334
|
+
DProgress,
|
|
4335
|
+
DRadio,
|
|
4336
|
+
DRangeDatePicker,
|
|
4337
|
+
DSearchInput,
|
|
4338
|
+
DSelect,
|
|
4339
|
+
DSelectFilter,
|
|
4340
|
+
DSeparator,
|
|
4341
|
+
DSkeleton,
|
|
4342
|
+
DSpinner,
|
|
4343
|
+
DSplashScreen,
|
|
4344
|
+
DStatusFilter,
|
|
4345
|
+
DTableSkeleton,
|
|
4346
|
+
DTabs,
|
|
4347
|
+
DTabsContent,
|
|
4348
|
+
DTabsList,
|
|
4349
|
+
DTabsTrigger,
|
|
4350
|
+
DTextarea,
|
|
4351
|
+
DThemeProvider,
|
|
4352
|
+
DTimePicker,
|
|
4353
|
+
DToastContainer,
|
|
4354
|
+
DToastProvider,
|
|
4355
|
+
DToggle,
|
|
4356
|
+
DTooltip,
|
|
4357
|
+
DValidationMessage,
|
|
4358
|
+
DropdownContext,
|
|
4359
|
+
accepted,
|
|
4360
|
+
cn,
|
|
4361
|
+
createCssVariableTheme,
|
|
4362
|
+
createDTranslator,
|
|
4363
|
+
createProjectThemeTokens,
|
|
4364
|
+
customValidation,
|
|
4365
|
+
date,
|
|
4366
|
+
defaultThemeTokens,
|
|
4367
|
+
email,
|
|
4368
|
+
enMessages,
|
|
4369
|
+
formatCurrencyInputValue,
|
|
4370
|
+
getLocalizedMonthNames,
|
|
4371
|
+
getLocalizedWeekdayNames,
|
|
4372
|
+
getPaginationItems,
|
|
4373
|
+
getPaginationPages,
|
|
4374
|
+
idMessages,
|
|
4375
|
+
integer,
|
|
4376
|
+
maxLength,
|
|
4377
|
+
maxValue,
|
|
4378
|
+
minLength,
|
|
4379
|
+
minValue,
|
|
4380
|
+
normalizeDecimalInput,
|
|
4381
|
+
oneOf,
|
|
4382
|
+
parseCurrencyInputValue,
|
|
4383
|
+
pattern,
|
|
4384
|
+
required,
|
|
4385
|
+
sameAs,
|
|
4386
|
+
selectOptionsFromChildren,
|
|
4387
|
+
themeTokensToCss,
|
|
4388
|
+
time,
|
|
4389
|
+
url,
|
|
4390
|
+
useDFormField,
|
|
4391
|
+
useDLocalization,
|
|
4392
|
+
useDropdown,
|
|
4393
|
+
useDropdownClose,
|
|
4394
|
+
useToast,
|
|
4395
|
+
validateValue
|
|
4396
|
+
};
|
|
4397
|
+
//# sourceMappingURL=index.js.map
|