@woobee/ui 0.2.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 +194 -0
- package/SKIPPED.md +58 -0
- package/dist/index.d.mts +578 -0
- package/dist/index.d.ts +578 -0
- package/dist/index.js +3653 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3594 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3594 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import React15, { forwardRef, useRef, useEffect, createContext, useState, useImperativeHandle, useContext, useReducer, useCallback } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { CSSTransition } from 'react-transition-group';
|
|
5
|
+
|
|
6
|
+
// src/utils/classNames.ts
|
|
7
|
+
function classNames(classNameHash) {
|
|
8
|
+
return Object.entries(classNameHash).filter(([, value]) => !!value).map(([key]) => key).join(" ");
|
|
9
|
+
}
|
|
10
|
+
function classNameObject(classNameString) {
|
|
11
|
+
if (!classNameString) return {};
|
|
12
|
+
return classNameString.split(" ").reduce((prev, className) => {
|
|
13
|
+
if (className) {
|
|
14
|
+
prev[className] = true;
|
|
15
|
+
}
|
|
16
|
+
return prev;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
function Button({
|
|
20
|
+
children,
|
|
21
|
+
onClick,
|
|
22
|
+
placeholder = null,
|
|
23
|
+
variant = "primary",
|
|
24
|
+
size = "medium",
|
|
25
|
+
className = "",
|
|
26
|
+
type = "button",
|
|
27
|
+
loading = false,
|
|
28
|
+
disabled = false,
|
|
29
|
+
leftIcon = null,
|
|
30
|
+
rightIcon = null,
|
|
31
|
+
compact = false,
|
|
32
|
+
...props
|
|
33
|
+
}) {
|
|
34
|
+
return /* @__PURE__ */ jsxs(
|
|
35
|
+
"button",
|
|
36
|
+
{
|
|
37
|
+
type,
|
|
38
|
+
onClick,
|
|
39
|
+
disabled: disabled || loading,
|
|
40
|
+
className: classNames({
|
|
41
|
+
"items-center justify-center rounded-lg focus:outline-none focus:ring-0 disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed shadow-sm": true,
|
|
42
|
+
"relative": !!leftIcon || !!rightIcon,
|
|
43
|
+
"px-2.5 py-1.5 text-xs": size === "small",
|
|
44
|
+
"px-4 py-2 text-sm": size === "medium",
|
|
45
|
+
"px-5 py-3 text-base": size === "big",
|
|
46
|
+
"px-5 py-3 text-lg font-medium": size === "huge",
|
|
47
|
+
"!px-1 !py-0.5": compact,
|
|
48
|
+
"border bg-brown-500 dark:bg-primary-500 dark:hover:bg-primary-600 border-transparent text-white dark:text-black": variant === "primary",
|
|
49
|
+
"text-gray-700 bg-white dark:bg-charcoal-800 dark:hover:bg-charcoal-700 dark:text-charcoal-100 border border-gray-300 dark:border-charcoal-700 hover:text-gray-500": variant === "secondary",
|
|
50
|
+
"!rounded-md text-left w-full text-gray-700 bg-white dark:bg-charcoal-800 dark:hover:bg-charcoal-700 dark:text-charcoal-100 border border-gray-200 dark:border-charcoal-700 hover:bg-gray-50 hover:text-gray-500": variant === "form-input",
|
|
51
|
+
"hover:text-brown-500 dark:text-charcoal-100 dark:hover:text-primary-500 !shadow-none": variant === "flat",
|
|
52
|
+
"!text-gray-300 hover:!text-gray-400 dark:!text-charcoal-400": !children,
|
|
53
|
+
...classNameObject(className)
|
|
54
|
+
}),
|
|
55
|
+
...props,
|
|
56
|
+
children: [
|
|
57
|
+
loading && /* @__PURE__ */ jsx("div", { className: "absolute inset-y-0 left-0 flex items-center pl-3", children: /* @__PURE__ */ jsxs("svg", { className: "w-4 h-4 animate-spin", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
58
|
+
/* @__PURE__ */ jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
59
|
+
/* @__PURE__ */ jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })
|
|
60
|
+
] }) }),
|
|
61
|
+
!loading && leftIcon && /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 left-0 flex items-center pl-3", children: leftIcon }),
|
|
62
|
+
/* @__PURE__ */ jsx("span", { children: children || placeholder }),
|
|
63
|
+
!loading && rightIcon && /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 right-0 flex items-center pr-3", children: rightIcon })
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function Tag({
|
|
69
|
+
children,
|
|
70
|
+
className = "",
|
|
71
|
+
onRemove,
|
|
72
|
+
color,
|
|
73
|
+
style,
|
|
74
|
+
size = "medium"
|
|
75
|
+
}) {
|
|
76
|
+
const customStyle = color ? { backgroundColor: color, ...style } : style;
|
|
77
|
+
return /* @__PURE__ */ jsxs(
|
|
78
|
+
"span",
|
|
79
|
+
{
|
|
80
|
+
className: classNames({
|
|
81
|
+
"inline-flex items-center rounded font-medium whitespace-nowrap": true,
|
|
82
|
+
"bg-cream-200 dark:bg-charcoal-700 text-gray-800 dark:text-gray-200": !color,
|
|
83
|
+
"text-white": !!color,
|
|
84
|
+
// medium size
|
|
85
|
+
"text-sm": size === "medium",
|
|
86
|
+
"pl-2.5 pr-1 py-0.5 space-x-1": size === "medium" && !!onRemove,
|
|
87
|
+
"px-2 py-0.5": size === "medium" && !onRemove,
|
|
88
|
+
// small size
|
|
89
|
+
"text-xs": size === "small",
|
|
90
|
+
"pl-2 pr-0.5 py-0.5 space-x-0.5": size === "small" && !!onRemove,
|
|
91
|
+
"px-1.5 py-0.5": size === "small" && !onRemove,
|
|
92
|
+
...classNameObject(className)
|
|
93
|
+
}),
|
|
94
|
+
style: customStyle,
|
|
95
|
+
children: [
|
|
96
|
+
/* @__PURE__ */ jsx("span", { children }),
|
|
97
|
+
onRemove && /* @__PURE__ */ jsx(
|
|
98
|
+
Button,
|
|
99
|
+
{
|
|
100
|
+
variant: "flat",
|
|
101
|
+
compact: true,
|
|
102
|
+
size: size === "small" ? "small" : "medium",
|
|
103
|
+
className: "!text-red-500 hover:text-red-700 !px-0.5",
|
|
104
|
+
onClick: onRemove,
|
|
105
|
+
children: /* @__PURE__ */ jsx("span", { children: "\xD7" })
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
function TagGroup({
|
|
113
|
+
tags = [],
|
|
114
|
+
onRemove,
|
|
115
|
+
placeholder = "No tags selected",
|
|
116
|
+
className = ""
|
|
117
|
+
}) {
|
|
118
|
+
return /* @__PURE__ */ jsx(
|
|
119
|
+
"div",
|
|
120
|
+
{
|
|
121
|
+
className: classNames({
|
|
122
|
+
"flex flex-wrap h-11 gap-1.5 items-center": true,
|
|
123
|
+
...classNameObject(className)
|
|
124
|
+
}),
|
|
125
|
+
children: tags.length > 0 ? tags.map((tag) => /* @__PURE__ */ jsx(
|
|
126
|
+
Tag,
|
|
127
|
+
{
|
|
128
|
+
color: tag.color,
|
|
129
|
+
onRemove: onRemove ? () => onRemove(tag) : void 0,
|
|
130
|
+
children: tag.name
|
|
131
|
+
},
|
|
132
|
+
tag.id || tag.name
|
|
133
|
+
)) : placeholder && /* @__PURE__ */ jsx("span", { className: "text-gray-300 dark:text-charcoal-400 text-sm flex items-center", children: placeholder })
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function Tabs({
|
|
138
|
+
value,
|
|
139
|
+
onChange,
|
|
140
|
+
options = [
|
|
141
|
+
{ id: "point", label: "Point" },
|
|
142
|
+
{ id: "percentage", label: "Percentage" }
|
|
143
|
+
],
|
|
144
|
+
className = ""
|
|
145
|
+
}) {
|
|
146
|
+
return /* @__PURE__ */ jsx(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
className: classNames({
|
|
150
|
+
"inline-flex rounded-lg bg-cream-50 dark:bg-charcoal-800/90 dark:backdrop-filter dark:backdrop-blur-sm overflow-hidden text-xs p-1 space-x-0.5 rounded-xl": true,
|
|
151
|
+
...classNameObject(className)
|
|
152
|
+
}),
|
|
153
|
+
children: options.map((option) => /* @__PURE__ */ jsx(
|
|
154
|
+
"button",
|
|
155
|
+
{
|
|
156
|
+
className: classNames({
|
|
157
|
+
"px-3 py-2 transition-colors rounded-lg": true,
|
|
158
|
+
"bg-white text-brown-500 dark:text-primary-500 dark:bg-charcoal-600": value === option.id,
|
|
159
|
+
"hover:text-brown-500 dark:text-charcoal-300 dark:hover:text-primary-500": value !== option.id
|
|
160
|
+
}),
|
|
161
|
+
onClick: () => onChange(option.id),
|
|
162
|
+
children: option.label
|
|
163
|
+
},
|
|
164
|
+
option.id
|
|
165
|
+
))
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
var Toggle = forwardRef(
|
|
170
|
+
({ listening, size, name, value, onChange, className }, ref) => {
|
|
171
|
+
const internalRef = useRef(null);
|
|
172
|
+
const spanRef = ref || internalRef;
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (listening && spanRef && "current" in spanRef && spanRef.current && value !== null) {
|
|
175
|
+
spanRef.current.value = value;
|
|
176
|
+
}
|
|
177
|
+
}, [value, listening, spanRef]);
|
|
178
|
+
return /* @__PURE__ */ jsx(
|
|
179
|
+
"span",
|
|
180
|
+
{
|
|
181
|
+
ref: spanRef,
|
|
182
|
+
role: "checkbox",
|
|
183
|
+
"aria-checked": value,
|
|
184
|
+
tabIndex: 0,
|
|
185
|
+
onClick: () => onChange(!value),
|
|
186
|
+
className: classNames({
|
|
187
|
+
"relative inline-block flex-shrink-0 border-2 border-transparent rounded-full transition-colors ease-in-out duration-200 focus:outline-none focus:shadow-outline": true,
|
|
188
|
+
"h-6 w-11": !size || size === "medium",
|
|
189
|
+
"h-4 w-7": size === "small",
|
|
190
|
+
"bg-brown-500 dark:bg-primary-500": value,
|
|
191
|
+
"bg-gray-200 dark:bg-charcoal-300": !value,
|
|
192
|
+
"cursor-pointer": !(className || "").includes("cursor-"),
|
|
193
|
+
...classNameObject(className)
|
|
194
|
+
}),
|
|
195
|
+
children: /* @__PURE__ */ jsx(
|
|
196
|
+
"span",
|
|
197
|
+
{
|
|
198
|
+
"aria-hidden": "true",
|
|
199
|
+
className: classNames({
|
|
200
|
+
"rounded-full bg-white shadow transform transition ease-in-out duration-200": true,
|
|
201
|
+
"inline-block h-5 w-5": !size || size === "medium",
|
|
202
|
+
"block h-3 w-3": size === "small",
|
|
203
|
+
"translate-x-5": value && (!size || size === "medium"),
|
|
204
|
+
"translate-x-0": !value,
|
|
205
|
+
"translate-x-3": value && size === "small"
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
Toggle.displayName = "Toggle";
|
|
214
|
+
var Toggle_default = Toggle;
|
|
215
|
+
function Loading({
|
|
216
|
+
title,
|
|
217
|
+
layout,
|
|
218
|
+
className = "",
|
|
219
|
+
spinClassName = "",
|
|
220
|
+
spinSizeClassName = "w-24 h-24"
|
|
221
|
+
}) {
|
|
222
|
+
return /* @__PURE__ */ jsxs(
|
|
223
|
+
"div",
|
|
224
|
+
{
|
|
225
|
+
className: classNames({
|
|
226
|
+
"space-y-3": true,
|
|
227
|
+
"flex flex-col items-center justify-center fixed inset-0": layout === "fixed",
|
|
228
|
+
"w-full": layout === "fill",
|
|
229
|
+
[className]: true
|
|
230
|
+
}),
|
|
231
|
+
children: [
|
|
232
|
+
/* @__PURE__ */ jsx(
|
|
233
|
+
"div",
|
|
234
|
+
{
|
|
235
|
+
className: classNames({
|
|
236
|
+
[spinClassName]: true,
|
|
237
|
+
[spinSizeClassName]: true,
|
|
238
|
+
"relative border-8 border-gray-500 rounded-full animate-spin": true
|
|
239
|
+
}),
|
|
240
|
+
children: /* @__PURE__ */ jsx("div", { className: "absolute -left-4 -top-4 right-2/4 bottom-2/4 bg-white/50 bg-opacity-75 rounded-full rounded-b-none rounded-r-none" })
|
|
241
|
+
}
|
|
242
|
+
),
|
|
243
|
+
!!title && title.length > 0 && /* @__PURE__ */ jsx("div", { children: title })
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
function CheckboxList({
|
|
249
|
+
items = [],
|
|
250
|
+
selected = [],
|
|
251
|
+
onToggle,
|
|
252
|
+
itemKey = "id",
|
|
253
|
+
itemLabel = (item) => item.name || item.label || item.fullName,
|
|
254
|
+
isChecked,
|
|
255
|
+
loading = false,
|
|
256
|
+
placeholder = "No items found."
|
|
257
|
+
}) {
|
|
258
|
+
const getFinalKey = (item, index) => {
|
|
259
|
+
const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
|
|
260
|
+
return key !== void 0 && key !== null ? key : index;
|
|
261
|
+
};
|
|
262
|
+
const renderPlaceholder = () => {
|
|
263
|
+
if (typeof placeholder === "string") {
|
|
264
|
+
return /* @__PURE__ */ jsx("div", { className: "p-4 text-center text-sm text-gray-500 dark:text-charcoal-400", children: placeholder });
|
|
265
|
+
}
|
|
266
|
+
return placeholder;
|
|
267
|
+
};
|
|
268
|
+
return /* @__PURE__ */ jsx("div", { className: "w-full border border-gray-300 dark:border-charcoal-700 rounded-lg shadow-sm bg-white dark:bg-charcoal-800 overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "max-h-60 overflow-y-auto divide-y divide-gray-100 dark:divide-charcoal-700", children: loading && items.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-4 flex items-center justify-center min-h-36", children: /* @__PURE__ */ jsx(Loading, { spinSizeClassName: "w-6 h-6", className: "inline-block" }) }) : /* @__PURE__ */ jsx(Fragment, { children: items.length > 0 ? items.map((item, index) => {
|
|
269
|
+
const finalKey = getFinalKey(item, index);
|
|
270
|
+
const label = typeof itemLabel === "function" ? itemLabel(item) : item[itemLabel];
|
|
271
|
+
const checked = typeof isChecked === "function" ? isChecked(item, selected) : selected.some(
|
|
272
|
+
(s) => (s && typeof s === "object" ? s.id : s) === finalKey
|
|
273
|
+
);
|
|
274
|
+
return /* @__PURE__ */ jsx(
|
|
275
|
+
"div",
|
|
276
|
+
{
|
|
277
|
+
className: classNames({
|
|
278
|
+
"px-2 py-2 cursor-pointer flex items-center justify-between transition-colors": true,
|
|
279
|
+
"hover:bg-gray-50 dark:hover:bg-charcoal-700": !checked,
|
|
280
|
+
"bg-gray-50 dark:bg-primary-900/20": checked
|
|
281
|
+
}),
|
|
282
|
+
onClick: () => onToggle && onToggle(item),
|
|
283
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-3", children: [
|
|
284
|
+
/* @__PURE__ */ jsx(
|
|
285
|
+
"div",
|
|
286
|
+
{
|
|
287
|
+
className: classNames({
|
|
288
|
+
"w-5 h-5 rounded border flex items-center justify-center transition-colors cursor-pointer": true,
|
|
289
|
+
"border-gray-300 bg-white dark:border-charcoal-700 dark:bg-charcoal-700": !checked,
|
|
290
|
+
"border-brown-500 bg-brown-500 dark:bg-primary-500 dark:border-primary-500 dark:text-black text-white": checked
|
|
291
|
+
}),
|
|
292
|
+
children: checked && /* @__PURE__ */ jsx("svg", { className: "w-4 h-4", viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z" }) })
|
|
293
|
+
}
|
|
294
|
+
),
|
|
295
|
+
/* @__PURE__ */ jsx(
|
|
296
|
+
"span",
|
|
297
|
+
{
|
|
298
|
+
className: classNames({
|
|
299
|
+
"text-sm": true,
|
|
300
|
+
"text-gray-900 dark:text-gray-100": !checked,
|
|
301
|
+
"dark:text-primary-400": checked
|
|
302
|
+
}),
|
|
303
|
+
children: label
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
] })
|
|
307
|
+
},
|
|
308
|
+
finalKey
|
|
309
|
+
);
|
|
310
|
+
}) : renderPlaceholder() }) }) });
|
|
311
|
+
}
|
|
312
|
+
var ModalContext = createContext({
|
|
313
|
+
modalShowing: false,
|
|
314
|
+
drawerShowing: false,
|
|
315
|
+
setModalShowing: () => {
|
|
316
|
+
},
|
|
317
|
+
setDrawerShowing: () => {
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
function useModalContext() {
|
|
321
|
+
return useContext(ModalContext);
|
|
322
|
+
}
|
|
323
|
+
function ModalProvider({ children }) {
|
|
324
|
+
const [currentState, setCurrentState] = useState(0);
|
|
325
|
+
function reducer(state, action) {
|
|
326
|
+
const updatedValues = { ...state };
|
|
327
|
+
if ("modalShowing" in action) {
|
|
328
|
+
updatedValues.modalShowing = action.modalShowing;
|
|
329
|
+
}
|
|
330
|
+
if ("drawerShowing" in action) {
|
|
331
|
+
updatedValues.drawerShowing = action.drawerShowing;
|
|
332
|
+
}
|
|
333
|
+
if ("render" in action && !!action.render) {
|
|
334
|
+
setCurrentState(1 - currentState);
|
|
335
|
+
}
|
|
336
|
+
return updatedValues;
|
|
337
|
+
}
|
|
338
|
+
const [values, dispatch] = useReducer(reducer, {
|
|
339
|
+
modalShowing: false,
|
|
340
|
+
drawerShowing: false
|
|
341
|
+
});
|
|
342
|
+
const { modalShowing, drawerShowing } = values;
|
|
343
|
+
useEffect(() => {
|
|
344
|
+
if (typeof document === "undefined") return;
|
|
345
|
+
const bodyEl = document.getElementsByTagName("BODY")[0];
|
|
346
|
+
if (!bodyEl) return;
|
|
347
|
+
if (modalShowing) {
|
|
348
|
+
bodyEl.classList.add("overflow-hidden");
|
|
349
|
+
} else {
|
|
350
|
+
bodyEl.classList.remove("overflow-hidden");
|
|
351
|
+
}
|
|
352
|
+
}, [modalShowing]);
|
|
353
|
+
return /* @__PURE__ */ jsx(
|
|
354
|
+
ModalContext.Provider,
|
|
355
|
+
{
|
|
356
|
+
value: {
|
|
357
|
+
modalShowing,
|
|
358
|
+
drawerShowing,
|
|
359
|
+
setModalShowing: (value) => dispatch({ modalShowing: value, render: modalShowing !== value }),
|
|
360
|
+
setDrawerShowing: (value) => dispatch({ drawerShowing: value, render: drawerShowing !== value })
|
|
361
|
+
},
|
|
362
|
+
children
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
var TransitionContext = createContext({
|
|
367
|
+
parent: {}
|
|
368
|
+
});
|
|
369
|
+
function useIsInitialRender() {
|
|
370
|
+
const isInitialRender = useRef(true);
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
isInitialRender.current = false;
|
|
373
|
+
}, []);
|
|
374
|
+
return isInitialRender.current;
|
|
375
|
+
}
|
|
376
|
+
function CSSTransitionComponent({
|
|
377
|
+
show,
|
|
378
|
+
enter = "",
|
|
379
|
+
enterFrom = "",
|
|
380
|
+
enterTo = "",
|
|
381
|
+
leave = "",
|
|
382
|
+
leaveFrom = "",
|
|
383
|
+
leaveTo = "",
|
|
384
|
+
appear,
|
|
385
|
+
children,
|
|
386
|
+
onEnter = () => {
|
|
387
|
+
},
|
|
388
|
+
onEntering = () => {
|
|
389
|
+
},
|
|
390
|
+
onEntered = () => {
|
|
391
|
+
},
|
|
392
|
+
onExit = () => {
|
|
393
|
+
},
|
|
394
|
+
onExiting = () => {
|
|
395
|
+
},
|
|
396
|
+
onExited = () => {
|
|
397
|
+
}
|
|
398
|
+
}) {
|
|
399
|
+
const enterClasses = enter.split(" ").filter((s) => s.length);
|
|
400
|
+
const enterFromClasses = enterFrom.split(" ").filter((s) => s.length);
|
|
401
|
+
const enterToClasses = enterTo.split(" ").filter((s) => s.length);
|
|
402
|
+
const leaveClasses = leave.split(" ").filter((s) => s.length);
|
|
403
|
+
const leaveFromClasses = leaveFrom.split(" ").filter((s) => s.length);
|
|
404
|
+
const leaveToClasses = leaveTo.split(" ").filter((s) => s.length);
|
|
405
|
+
const nodeRef = useRef(null);
|
|
406
|
+
function addClasses(node, classes) {
|
|
407
|
+
classes.length && node.classList.add(...classes);
|
|
408
|
+
}
|
|
409
|
+
function removeClasses(node, classes) {
|
|
410
|
+
classes.length && node.classList.remove(...classes);
|
|
411
|
+
}
|
|
412
|
+
return /* @__PURE__ */ jsx(
|
|
413
|
+
CSSTransition,
|
|
414
|
+
{
|
|
415
|
+
nodeRef,
|
|
416
|
+
appear,
|
|
417
|
+
unmountOnExit: true,
|
|
418
|
+
in: show,
|
|
419
|
+
addEndListener: (done) => {
|
|
420
|
+
if (!nodeRef.current) return done();
|
|
421
|
+
nodeRef.current.addEventListener("transitionend", done, false);
|
|
422
|
+
},
|
|
423
|
+
onEnter: () => {
|
|
424
|
+
if (!nodeRef.current) return;
|
|
425
|
+
addClasses(nodeRef.current, [...enterClasses, ...enterFromClasses]);
|
|
426
|
+
onEnter(nodeRef.current);
|
|
427
|
+
},
|
|
428
|
+
onEntering: () => {
|
|
429
|
+
if (!nodeRef.current) return;
|
|
430
|
+
removeClasses(nodeRef.current, enterFromClasses);
|
|
431
|
+
addClasses(nodeRef.current, enterToClasses);
|
|
432
|
+
onEntering(nodeRef.current);
|
|
433
|
+
},
|
|
434
|
+
onEntered: () => {
|
|
435
|
+
if (!nodeRef.current) return;
|
|
436
|
+
removeClasses(nodeRef.current, [...enterToClasses, ...enterClasses]);
|
|
437
|
+
onEntered(nodeRef.current);
|
|
438
|
+
},
|
|
439
|
+
onExit: () => {
|
|
440
|
+
if (!nodeRef.current) return;
|
|
441
|
+
addClasses(nodeRef.current, [...leaveClasses, ...leaveFromClasses]);
|
|
442
|
+
onExit(nodeRef.current);
|
|
443
|
+
},
|
|
444
|
+
onExiting: () => {
|
|
445
|
+
if (!nodeRef.current) return;
|
|
446
|
+
removeClasses(nodeRef.current, leaveFromClasses);
|
|
447
|
+
addClasses(nodeRef.current, leaveToClasses);
|
|
448
|
+
onExiting(nodeRef.current);
|
|
449
|
+
},
|
|
450
|
+
onExited: () => {
|
|
451
|
+
if (!nodeRef.current) return;
|
|
452
|
+
removeClasses(nodeRef.current, [...leaveToClasses, ...leaveClasses]);
|
|
453
|
+
onExited(nodeRef.current);
|
|
454
|
+
},
|
|
455
|
+
children: React15.cloneElement(children, {
|
|
456
|
+
ref: (node) => {
|
|
457
|
+
nodeRef.current = node;
|
|
458
|
+
const childRef = children.ref;
|
|
459
|
+
if (typeof childRef === "function") {
|
|
460
|
+
childRef(node);
|
|
461
|
+
} else if (childRef && typeof childRef === "object") {
|
|
462
|
+
childRef.current = node;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
}
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
function Transition({ show, appear, ...rest }) {
|
|
470
|
+
const { parent } = useContext(TransitionContext);
|
|
471
|
+
const isInitialRender = useIsInitialRender();
|
|
472
|
+
const isChild = show === void 0;
|
|
473
|
+
if (isChild) {
|
|
474
|
+
return /* @__PURE__ */ jsx(
|
|
475
|
+
CSSTransitionComponent,
|
|
476
|
+
{
|
|
477
|
+
appear: parent.appear || !parent.isInitialRender,
|
|
478
|
+
show: parent.show,
|
|
479
|
+
...rest
|
|
480
|
+
}
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
return /* @__PURE__ */ jsx(
|
|
484
|
+
TransitionContext.Provider,
|
|
485
|
+
{
|
|
486
|
+
value: {
|
|
487
|
+
parent: {
|
|
488
|
+
show,
|
|
489
|
+
isInitialRender,
|
|
490
|
+
appear
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
children: /* @__PURE__ */ jsx(CSSTransitionComponent, { appear, show, ...rest })
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
function ModalFooter({
|
|
498
|
+
footer,
|
|
499
|
+
disabled,
|
|
500
|
+
onCancel,
|
|
501
|
+
onSubmit,
|
|
502
|
+
onChange,
|
|
503
|
+
closeText,
|
|
504
|
+
submitText,
|
|
505
|
+
submitColor,
|
|
506
|
+
changeText,
|
|
507
|
+
darkMode
|
|
508
|
+
}) {
|
|
509
|
+
if (footer) {
|
|
510
|
+
return /* @__PURE__ */ jsx(
|
|
511
|
+
"div",
|
|
512
|
+
{
|
|
513
|
+
className: classNames({
|
|
514
|
+
"px-3 pt-5 pb-4 bg-gray-100 border-t border-gray-300 dark:border-charcoal-700 sm:px-6 sm:pt-3 sm:pb-3 dark:bg-black/40": true,
|
|
515
|
+
"!bg-charcoal-700 !border-t-charcoal-600": !!darkMode
|
|
516
|
+
}),
|
|
517
|
+
children: footer
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
const hasSubmit = typeof onSubmit === "function";
|
|
522
|
+
const hasCancel = typeof onCancel === "function";
|
|
523
|
+
const hasChange = typeof onChange === "function";
|
|
524
|
+
function handleSubmit(e) {
|
|
525
|
+
if (typeof onSubmit === "function" && !disabled) {
|
|
526
|
+
onSubmit(e);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
let submitVariant = "primary";
|
|
530
|
+
let submitBtnClassName = "w-full";
|
|
531
|
+
if (submitColor) {
|
|
532
|
+
if (submitColor === "red") {
|
|
533
|
+
submitVariant = void 0;
|
|
534
|
+
submitBtnClassName = "w-full bg-red-600 hover:bg-red-700 dark:bg-red-500 dark:hover:bg-red-600 border-transparent text-white";
|
|
535
|
+
} else if (submitColor === "primary") {
|
|
536
|
+
submitVariant = "primary";
|
|
537
|
+
} else {
|
|
538
|
+
submitVariant = void 0;
|
|
539
|
+
submitBtnClassName = classNames({ "w-full": true, [submitColor]: true });
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return hasSubmit || hasCancel || hasChange ? /* @__PURE__ */ jsxs("div", { className: "flex justify-between px-3 py-3 space-x-2 bg-transparent sm:px-6 sm:pt-3 sm:pb-3", children: [
|
|
543
|
+
hasChange && /* @__PURE__ */ jsx("div", { className: "flex space-x-2", children: /* @__PURE__ */ jsx("span", { className: "rounded-2xl", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: onChange, children: changeText || "Change" }) }) }),
|
|
544
|
+
(hasSubmit || hasCancel) && /* @__PURE__ */ jsxs("div", { className: "flex justify-end flex-grow space-x-2", children: [
|
|
545
|
+
hasCancel && /* @__PURE__ */ jsx("span", { className: "flex shadow-sm rounded-2xl", children: /* @__PURE__ */ jsx(Button, { className: "w-full", variant: "secondary", onClick: onCancel, children: closeText || "Cancel" }) }),
|
|
546
|
+
hasSubmit && /* @__PURE__ */ jsx("span", { className: "flex w-full shadow-sm rounded-2xl sm:w-auto", children: /* @__PURE__ */ jsx(
|
|
547
|
+
Button,
|
|
548
|
+
{
|
|
549
|
+
className: submitBtnClassName,
|
|
550
|
+
variant: submitVariant,
|
|
551
|
+
disabled,
|
|
552
|
+
onClick: () => handleSubmit({}),
|
|
553
|
+
children: submitText || "Submit"
|
|
554
|
+
}
|
|
555
|
+
) })
|
|
556
|
+
] })
|
|
557
|
+
] }) : null;
|
|
558
|
+
}
|
|
559
|
+
var MODAL_OPEN_COUNT = 0;
|
|
560
|
+
function Modal({
|
|
561
|
+
wrapperClassName,
|
|
562
|
+
open,
|
|
563
|
+
size,
|
|
564
|
+
title,
|
|
565
|
+
description,
|
|
566
|
+
transparent,
|
|
567
|
+
header,
|
|
568
|
+
sidebar,
|
|
569
|
+
footer,
|
|
570
|
+
children,
|
|
571
|
+
disabled,
|
|
572
|
+
onClose,
|
|
573
|
+
onExited = () => {
|
|
574
|
+
},
|
|
575
|
+
onCancel,
|
|
576
|
+
onSubmit,
|
|
577
|
+
onChange,
|
|
578
|
+
closeText,
|
|
579
|
+
submitText,
|
|
580
|
+
submitColor,
|
|
581
|
+
changeText,
|
|
582
|
+
fullscreen,
|
|
583
|
+
opts
|
|
584
|
+
}) {
|
|
585
|
+
const { setModalShowing } = useContext(ModalContext);
|
|
586
|
+
const { darkMode, sidebarPosition = "right", mobileSidebarPosition = "bottom" } = opts || {};
|
|
587
|
+
const isMobileSidebarTop = mobileSidebarPosition === "top" || mobileSidebarPosition === "above";
|
|
588
|
+
const [mounted, setMounted] = useState(false);
|
|
589
|
+
useEffect(() => {
|
|
590
|
+
setMounted(true);
|
|
591
|
+
return () => setMounted(false);
|
|
592
|
+
}, []);
|
|
593
|
+
useEffect(() => {
|
|
594
|
+
if (typeof document === "undefined") return;
|
|
595
|
+
const bodyEl = document.getElementsByTagName("BODY")[0];
|
|
596
|
+
if (open) {
|
|
597
|
+
setModalShowing(true);
|
|
598
|
+
if (MODAL_OPEN_COUNT === 0) {
|
|
599
|
+
bodyEl?.classList?.add("overflow-hidden");
|
|
600
|
+
}
|
|
601
|
+
MODAL_OPEN_COUNT++;
|
|
602
|
+
} else {
|
|
603
|
+
setModalShowing(false);
|
|
604
|
+
}
|
|
605
|
+
return () => {
|
|
606
|
+
if (open) {
|
|
607
|
+
MODAL_OPEN_COUNT--;
|
|
608
|
+
if (MODAL_OPEN_COUNT === 0) {
|
|
609
|
+
bodyEl?.classList?.remove("overflow-hidden");
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}, [open]);
|
|
614
|
+
function handleClose() {
|
|
615
|
+
if (typeof onClose === "function") {
|
|
616
|
+
onClose();
|
|
617
|
+
}
|
|
618
|
+
setModalShowing(false);
|
|
619
|
+
}
|
|
620
|
+
if (!mounted) return null;
|
|
621
|
+
return createPortal(
|
|
622
|
+
/* @__PURE__ */ jsx(Transition, { show: open, onExited, children: /* @__PURE__ */ jsx("div", { className: "fixed inset-x-0 text-sm bottom-0 z-[1300] px-0 bg-opacity-30 lg:px-6 lg:inset-0 lg:flex lg:items-center lg:justify-center", children: /* @__PURE__ */ jsxs(
|
|
623
|
+
"div",
|
|
624
|
+
{
|
|
625
|
+
className: classNames({
|
|
626
|
+
"max-h-[100dvh] overflow-y-auto sm:w-full": true,
|
|
627
|
+
"lg:max-w-2xl": !size,
|
|
628
|
+
"lg:max-w-md": size === "small",
|
|
629
|
+
"lg:max-w-3xl": size === "medium",
|
|
630
|
+
"lg:max-w-6xl": size === "large",
|
|
631
|
+
"h-[100dvh] lg:h-auto lg:max-w-3xl": size === "full"
|
|
632
|
+
}),
|
|
633
|
+
children: [
|
|
634
|
+
/* @__PURE__ */ jsx(
|
|
635
|
+
Transition,
|
|
636
|
+
{
|
|
637
|
+
enter: "ease-out duration-300",
|
|
638
|
+
enterFrom: "opacity-0",
|
|
639
|
+
enterTo: "opacity-100",
|
|
640
|
+
leave: "ease-in duration-200",
|
|
641
|
+
leaveFrom: "opacity-100",
|
|
642
|
+
leaveTo: "opacity-0",
|
|
643
|
+
children: /* @__PURE__ */ jsx("div", { className: "fixed inset-0 transition-opacity", children: /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-gray-500 dark:bg-charcoal-800 opacity-75" }) })
|
|
644
|
+
}
|
|
645
|
+
),
|
|
646
|
+
/* @__PURE__ */ jsx(
|
|
647
|
+
Transition,
|
|
648
|
+
{
|
|
649
|
+
enter: "ease-out duration-300",
|
|
650
|
+
enterFrom: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
|
|
651
|
+
enterTo: "opacity-100 translate-y-0 sm:scale-100",
|
|
652
|
+
leave: "ease-in duration-200",
|
|
653
|
+
leaveFrom: "opacity-100 translate-y-0 sm:scale-100",
|
|
654
|
+
leaveTo: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
|
|
655
|
+
children: /* @__PURE__ */ jsxs(
|
|
656
|
+
"div",
|
|
657
|
+
{
|
|
658
|
+
className: classNames({
|
|
659
|
+
"relative flex flex-col z-40 max-h-[100dvh] sm:max-h-9/10 sm:rounded-xl overflow-hidden transform transition-all sm:w-full": true,
|
|
660
|
+
"sm:max-w-2xl": !size,
|
|
661
|
+
"sm:max-w-md": size === "small",
|
|
662
|
+
"sm:max-w-4xl": size === "medium",
|
|
663
|
+
"sm:max-w-6xl": size === "large",
|
|
664
|
+
"sm:max-w-full sm:!max-h-full": size === "full",
|
|
665
|
+
"shadow-xl": !transparent,
|
|
666
|
+
"bg-white dark:bg-black": !transparent && !wrapperClassName,
|
|
667
|
+
"bg-transparent ": !!transparent && !wrapperClassName,
|
|
668
|
+
...classNameObject(wrapperClassName)
|
|
669
|
+
}),
|
|
670
|
+
role: "dialog",
|
|
671
|
+
"aria-modal": "true",
|
|
672
|
+
"aria-labelledby": "modal-headline",
|
|
673
|
+
children: [
|
|
674
|
+
!header && /* @__PURE__ */ jsxs(
|
|
675
|
+
"div",
|
|
676
|
+
{
|
|
677
|
+
className: classNames({
|
|
678
|
+
"flex items-center justify-between px-3 pt-3 pb-2 space-x-2 sm:px-6 sm:pt-6 sm:pb-3": true,
|
|
679
|
+
"sm:border-b sm:border-gray-200 dark:sm:border-charcoal-700 sm:shadow-sm": !!sidebar
|
|
680
|
+
}),
|
|
681
|
+
children: [
|
|
682
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
|
|
683
|
+
/* @__PURE__ */ jsx("h3", { className: "my-0 text-base font-semibold leading-tight text-gray-900 dark:text-white", children: title }),
|
|
684
|
+
!!description && description.length > 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-primary-700", children: description })
|
|
685
|
+
] }),
|
|
686
|
+
/* @__PURE__ */ jsx(Button, { variant: "flat", compact: true, onClick: handleClose, children: /* @__PURE__ */ jsx("svg", { className: "w-6 h-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M6 18L18 6M6 6l12 12" }) }) })
|
|
687
|
+
]
|
|
688
|
+
}
|
|
689
|
+
),
|
|
690
|
+
!!header && /* @__PURE__ */ jsx(Fragment, { children: header }),
|
|
691
|
+
/* @__PURE__ */ jsx(
|
|
692
|
+
"div",
|
|
693
|
+
{
|
|
694
|
+
className: classNames({
|
|
695
|
+
"pb-3 max-h-full overflow-y-auto": true,
|
|
696
|
+
"h-[100dvh] lg:h-auto": fullscreen || size === "full",
|
|
697
|
+
"sm:pt-4 sm:relative border-b border-gray-200 dark:border-charcoal-700": !!sidebar,
|
|
698
|
+
"sm:pr-80": !!sidebar && sidebarPosition === "right",
|
|
699
|
+
"sm:pl-80": !!sidebar && sidebarPosition === "left"
|
|
700
|
+
}),
|
|
701
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex-grow px-3 sm:px-6", children: [
|
|
702
|
+
!!sidebar && isMobileSidebarTop && /* @__PURE__ */ jsx(
|
|
703
|
+
"div",
|
|
704
|
+
{
|
|
705
|
+
className: classNames({
|
|
706
|
+
"sm:absolute sm:top-0 sm:bottom-0 sm:w-80 sm:max-h-full sm:overflow-y-scroll sm:px-5 sm:py-4": true,
|
|
707
|
+
"sm:right-0 sm:border-l sm:border-gray-200 dark:sm:border-charcoal-700": sidebarPosition === "right",
|
|
708
|
+
"sm:left-0 sm:border-r sm:border-gray-200 dark:sm:border-charcoal-700": sidebarPosition === "left",
|
|
709
|
+
"pb-6 mb-6 border-b border-gray-200 dark:border-charcoal-700 sm:border-b-0 sm:pb-0 sm:mb-0": true
|
|
710
|
+
}),
|
|
711
|
+
children: sidebar
|
|
712
|
+
}
|
|
713
|
+
),
|
|
714
|
+
children,
|
|
715
|
+
!!sidebar && !isMobileSidebarTop && /* @__PURE__ */ jsx(
|
|
716
|
+
"div",
|
|
717
|
+
{
|
|
718
|
+
className: classNames({
|
|
719
|
+
"sm:absolute sm:top-0 sm:bottom-0 sm:w-80 sm:max-h-full sm:overflow-y-scroll sm:px-5 sm:py-4": true,
|
|
720
|
+
"sm:right-0 sm:border-l sm:border-gray-200 dark:sm:border-charcoal-700": sidebarPosition === "right",
|
|
721
|
+
"sm:left-0 sm:border-r sm:border-gray-200 dark:sm:border-charcoal-700": sidebarPosition === "left",
|
|
722
|
+
"pt-6 mt-6 border-t border-gray-200 dark:border-charcoal-700 sm:border-t-0 sm:mt-0": true
|
|
723
|
+
}),
|
|
724
|
+
children: sidebar
|
|
725
|
+
}
|
|
726
|
+
)
|
|
727
|
+
] })
|
|
728
|
+
}
|
|
729
|
+
),
|
|
730
|
+
/* @__PURE__ */ jsx(
|
|
731
|
+
ModalFooter,
|
|
732
|
+
{
|
|
733
|
+
footer,
|
|
734
|
+
disabled,
|
|
735
|
+
onCancel,
|
|
736
|
+
onSubmit,
|
|
737
|
+
onChange,
|
|
738
|
+
closeText,
|
|
739
|
+
submitText,
|
|
740
|
+
submitColor,
|
|
741
|
+
changeText,
|
|
742
|
+
darkMode
|
|
743
|
+
}
|
|
744
|
+
)
|
|
745
|
+
]
|
|
746
|
+
}
|
|
747
|
+
)
|
|
748
|
+
}
|
|
749
|
+
)
|
|
750
|
+
]
|
|
751
|
+
}
|
|
752
|
+
) }) }),
|
|
753
|
+
document.body
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
function ConfirmationBox({
|
|
757
|
+
open,
|
|
758
|
+
title = "Confirm Action",
|
|
759
|
+
description = "Are you sure you want to perform this action?",
|
|
760
|
+
cancelText = "Cancel",
|
|
761
|
+
confirmText = "Confirm",
|
|
762
|
+
confirmColor,
|
|
763
|
+
type = "danger",
|
|
764
|
+
disabled = false,
|
|
765
|
+
onClose,
|
|
766
|
+
onConfirm
|
|
767
|
+
}) {
|
|
768
|
+
let iconContainerClass = "";
|
|
769
|
+
let iconSvg = null;
|
|
770
|
+
let defaultConfirmColor = "primary";
|
|
771
|
+
if (type === "danger") {
|
|
772
|
+
iconContainerClass = "bg-red-50 dark:bg-red-950/30 text-red-600 dark:text-red-400";
|
|
773
|
+
defaultConfirmColor = "red";
|
|
774
|
+
iconSvg = /* @__PURE__ */ jsx("svg", { className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) });
|
|
775
|
+
} else if (type === "warning") {
|
|
776
|
+
iconContainerClass = "bg-yellow-50 dark:bg-yellow-950/30 text-yellow-600 dark:text-yellow-400";
|
|
777
|
+
defaultConfirmColor = "primary";
|
|
778
|
+
iconSvg = /* @__PURE__ */ jsx("svg", { className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) });
|
|
779
|
+
} else {
|
|
780
|
+
iconContainerClass = "bg-blue-50 dark:bg-blue-950/30 text-blue-600 dark:text-blue-400";
|
|
781
|
+
defaultConfirmColor = "primary";
|
|
782
|
+
iconSvg = /* @__PURE__ */ jsx("svg", { className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) });
|
|
783
|
+
}
|
|
784
|
+
const resolvedConfirmColor = confirmColor || defaultConfirmColor;
|
|
785
|
+
return /* @__PURE__ */ jsx(
|
|
786
|
+
Modal,
|
|
787
|
+
{
|
|
788
|
+
open,
|
|
789
|
+
size: "small",
|
|
790
|
+
title,
|
|
791
|
+
onClose,
|
|
792
|
+
onCancel: onClose,
|
|
793
|
+
onSubmit: onConfirm,
|
|
794
|
+
closeText: cancelText,
|
|
795
|
+
submitText: confirmText,
|
|
796
|
+
submitColor: resolvedConfirmColor,
|
|
797
|
+
disabled,
|
|
798
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-start space-x-4", children: [
|
|
799
|
+
iconSvg && /* @__PURE__ */ jsx("div", { className: `flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full ${iconContainerClass}`, children: iconSvg }),
|
|
800
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 pt-1.5", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 font-medium", children: description }) })
|
|
801
|
+
] })
|
|
802
|
+
}
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
function Drawer({
|
|
806
|
+
theme,
|
|
807
|
+
open,
|
|
808
|
+
onClose,
|
|
809
|
+
title,
|
|
810
|
+
level,
|
|
811
|
+
description,
|
|
812
|
+
children,
|
|
813
|
+
footer,
|
|
814
|
+
animation = {},
|
|
815
|
+
wrapperClassName,
|
|
816
|
+
sectionClassName = ""
|
|
817
|
+
}) {
|
|
818
|
+
const { setDrawerShowing } = useContext(ModalContext);
|
|
819
|
+
useEffect(() => {
|
|
820
|
+
setDrawerShowing(open);
|
|
821
|
+
}, [open]);
|
|
822
|
+
function handleClose() {
|
|
823
|
+
if (typeof onClose === "function") {
|
|
824
|
+
onClose();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return /* @__PURE__ */ jsx(
|
|
828
|
+
Transition,
|
|
829
|
+
{
|
|
830
|
+
show: open,
|
|
831
|
+
enter: "transform transition ease-in-out duration-500 sm:duration-700",
|
|
832
|
+
enterFrom: "translate-x-full",
|
|
833
|
+
enterTo: "translate-x-0",
|
|
834
|
+
leave: "transform transition ease-in-out duration-500 sm:duration-700",
|
|
835
|
+
leaveFrom: "translate-x-0",
|
|
836
|
+
leaveTo: "translate-x-full",
|
|
837
|
+
...animation,
|
|
838
|
+
children: /* @__PURE__ */ jsx(
|
|
839
|
+
"section",
|
|
840
|
+
{
|
|
841
|
+
className: classNames({
|
|
842
|
+
"fixed inset-y-0 max-w-full right-0 flex": true,
|
|
843
|
+
"z-20": !level || level === "base" || level === "extra-wide" || level === "full",
|
|
844
|
+
"z-30": level === "middle",
|
|
845
|
+
"z-40": level === "top",
|
|
846
|
+
"z-50": level === "ceil",
|
|
847
|
+
[sectionClassName]: true
|
|
848
|
+
}),
|
|
849
|
+
children: /* @__PURE__ */ jsx(
|
|
850
|
+
"div",
|
|
851
|
+
{
|
|
852
|
+
className: classNames({
|
|
853
|
+
"w-screen": true,
|
|
854
|
+
"sm:max-w-7xl": level === "extra-wide",
|
|
855
|
+
"sm:max-w-full": level === "full",
|
|
856
|
+
"sm:max-w-4xl": !level || level === "base",
|
|
857
|
+
"sm:max-w-2xl": level === "middle",
|
|
858
|
+
"sm:max-w-md": level === "top",
|
|
859
|
+
"sm:max-w-sm": level === "ceil"
|
|
860
|
+
}),
|
|
861
|
+
children: /* @__PURE__ */ jsx(
|
|
862
|
+
"div",
|
|
863
|
+
{
|
|
864
|
+
className: classNames({
|
|
865
|
+
"h-full flex flex-col shadow-xl": true,
|
|
866
|
+
"bg-white dark:bg-primary-800": !wrapperClassName,
|
|
867
|
+
...classNameObject(wrapperClassName)
|
|
868
|
+
}),
|
|
869
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col h-full", children: [
|
|
870
|
+
/* @__PURE__ */ jsxs(
|
|
871
|
+
"header",
|
|
872
|
+
{
|
|
873
|
+
className: classNames({
|
|
874
|
+
"h-auto py-2.5 sm:py-3 px-4 sm:px-6": true,
|
|
875
|
+
"bg-primary-100 dark:bg-primary-900": !theme && (!level || level === "base" || level === "extra-wide" || level === "full"),
|
|
876
|
+
"bg-primary-200 dark:bg-primary-900": !theme && level === "middle",
|
|
877
|
+
"bg-primary-300 dark:bg-primary-900": !theme && level === "top",
|
|
878
|
+
"bg-primary-50 dark:bg-primary-900 border-b border-primary-100": !theme && level === "ceil",
|
|
879
|
+
"bg-white": theme === "WHITE",
|
|
880
|
+
"bg-black": theme === "BLACK",
|
|
881
|
+
"bg-red-500": theme === "RED",
|
|
882
|
+
"bg-orange-500": theme === "ORANGE",
|
|
883
|
+
"bg-yellow-500": theme === "YELLOW",
|
|
884
|
+
"bg-lime-500": theme === "LIME",
|
|
885
|
+
"bg-green-500": theme === "GREEN",
|
|
886
|
+
"bg-brown-500": theme === "BROWN",
|
|
887
|
+
"bg-blue-500": theme === "BLUE",
|
|
888
|
+
"bg-dark-blue-500": theme === "DARK_BLUE",
|
|
889
|
+
"bg-purple-500": theme === "PURPLE",
|
|
890
|
+
"bg-flamingo-500": theme === "FLAMINGO",
|
|
891
|
+
"bg-pink-500": theme === "PINK"
|
|
892
|
+
}),
|
|
893
|
+
children: [
|
|
894
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between space-x-3", children: [
|
|
895
|
+
/* @__PURE__ */ jsx("h2", { className: "text-base sm:text-lg leading-7 font-medium", children: title }),
|
|
896
|
+
/* @__PURE__ */ jsx("div", { className: "h-7 flex items-center", children: /* @__PURE__ */ jsx(
|
|
897
|
+
"div",
|
|
898
|
+
{
|
|
899
|
+
"aria-label": "Close",
|
|
900
|
+
className: "-mr-3 text-primary-700 dark:text-white hover:text-primary-500 p-1.5 rounded-lg hover:bg-primary-100 transition ease-in-out duration-150",
|
|
901
|
+
onClick: handleClose,
|
|
902
|
+
children: /* @__PURE__ */ jsx("svg", { className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M6 18L18 6M6 6l12 12" }) })
|
|
903
|
+
}
|
|
904
|
+
) })
|
|
905
|
+
] }),
|
|
906
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("p", { className: "text-sm leading-5 text-primary-300", children: description }) })
|
|
907
|
+
]
|
|
908
|
+
}
|
|
909
|
+
),
|
|
910
|
+
/* @__PURE__ */ jsx("div", { className: "py-3 flex-1 flex flex-col justify-between overflow-y-auto", children: /* @__PURE__ */ jsx("div", { className: "px-4 sm:px-6", children }) }),
|
|
911
|
+
!!footer && /* @__PURE__ */ jsx("div", { className: "sm:border-t sm:border-cool-gray-200 sm:dark:border-gray-700 py-2.5 sm:py-4 px-4 sm:px-6", children: footer })
|
|
912
|
+
] })
|
|
913
|
+
}
|
|
914
|
+
)
|
|
915
|
+
}
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
)
|
|
919
|
+
}
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
function SortIcon({ direction }) {
|
|
923
|
+
if (direction === "DESC") {
|
|
924
|
+
return /* @__PURE__ */ jsx("span", { className: "ml-2 text-sm", children: /* @__PURE__ */ jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M3 4h13M3 8h9m-9 4h9m5-4v12m0 0l-4-4m4 4l4-4" }) }) });
|
|
925
|
+
}
|
|
926
|
+
if (direction === "ASC") {
|
|
927
|
+
return /* @__PURE__ */ jsx("span", { className: "ml-2 text-sm", children: /* @__PURE__ */ jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M3 4h13M3 8h9m-9 4h6m4 0l4-4m0 0l4 4m-4-4v12" }) }) });
|
|
928
|
+
}
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
function InlinePrompt({
|
|
932
|
+
title,
|
|
933
|
+
onConfirm,
|
|
934
|
+
className = "",
|
|
935
|
+
withText,
|
|
936
|
+
confirmText,
|
|
937
|
+
cancelText,
|
|
938
|
+
opts
|
|
939
|
+
}) {
|
|
940
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
941
|
+
const nodeTarget = useRef(null);
|
|
942
|
+
const nodeWindow = useRef(null);
|
|
943
|
+
const { condensed, blocked } = opts || {};
|
|
944
|
+
function handleClickOutside(e) {
|
|
945
|
+
if (nodeTarget.current?.contains(e.target) || nodeWindow.current?.contains(e.target)) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
setIsOpen(false);
|
|
949
|
+
}
|
|
950
|
+
function handleOpenConfirmation() {
|
|
951
|
+
if (!blocked) {
|
|
952
|
+
setIsOpen(true);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
function handleCloseConfirmation() {
|
|
956
|
+
setIsOpen(false);
|
|
957
|
+
}
|
|
958
|
+
function handleConfirm() {
|
|
959
|
+
onConfirm();
|
|
960
|
+
setIsOpen(false);
|
|
961
|
+
}
|
|
962
|
+
useEffect(() => {
|
|
963
|
+
if (isOpen) {
|
|
964
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
965
|
+
} else {
|
|
966
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
967
|
+
}
|
|
968
|
+
return () => {
|
|
969
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
970
|
+
};
|
|
971
|
+
}, [isOpen]);
|
|
972
|
+
return /* @__PURE__ */ jsx("div", { className: "inline-block text-left", children: /* @__PURE__ */ jsxs("div", { className: "rounded-md w-full relative", children: [
|
|
973
|
+
/* @__PURE__ */ jsx(
|
|
974
|
+
"a",
|
|
975
|
+
{
|
|
976
|
+
ref: nodeTarget,
|
|
977
|
+
onClick: handleOpenConfirmation,
|
|
978
|
+
className: classNames({
|
|
979
|
+
"inline-flex justify-center w-full rounded-md bg-transparent font-medium focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:bg-gray-50 transition ease-in-out duration-150 cursor-pointer": true,
|
|
980
|
+
"leading-5 px-4 py-2": !condensed,
|
|
981
|
+
"text-gray-700 hover:text-gray-500 active:text-gray-800 text-md": !className.includes("text-"),
|
|
982
|
+
...classNameObject(className)
|
|
983
|
+
}),
|
|
984
|
+
"aria-haspopup": "true",
|
|
985
|
+
"aria-expanded": "true",
|
|
986
|
+
children: title
|
|
987
|
+
}
|
|
988
|
+
),
|
|
989
|
+
/* @__PURE__ */ jsx(
|
|
990
|
+
Transition,
|
|
991
|
+
{
|
|
992
|
+
show: isOpen,
|
|
993
|
+
enter: "transition ease-out duration-100",
|
|
994
|
+
enterFrom: "opacity-0 scale-95",
|
|
995
|
+
enterTo: "opacity-100 scale-100",
|
|
996
|
+
leave: "transition ease-in duration-75",
|
|
997
|
+
leaveFrom: "opacity-100 scale-100",
|
|
998
|
+
leaveTo: "opacity-0 scale-95",
|
|
999
|
+
children: /* @__PURE__ */ jsxs(
|
|
1000
|
+
"div",
|
|
1001
|
+
{
|
|
1002
|
+
ref: nodeWindow,
|
|
1003
|
+
className: "absolute top-0 left-0 min-w-full border border-gray-200 rounded-md bg-gray-50 flex justify-center z-20",
|
|
1004
|
+
children: [
|
|
1005
|
+
/* @__PURE__ */ jsxs("a", { onClick: handleConfirm, className: "inline-flex items-center cursor-pointer m-1 text-sm text-green-500", children: [
|
|
1006
|
+
/* @__PURE__ */ jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", className: "text-green-500 w-6 h-6", children: /* @__PURE__ */ jsx(
|
|
1007
|
+
"path",
|
|
1008
|
+
{
|
|
1009
|
+
fillRule: "evenodd",
|
|
1010
|
+
d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",
|
|
1011
|
+
clipRule: "evenodd"
|
|
1012
|
+
}
|
|
1013
|
+
) }),
|
|
1014
|
+
withText && confirmText
|
|
1015
|
+
] }),
|
|
1016
|
+
/* @__PURE__ */ jsxs(
|
|
1017
|
+
"a",
|
|
1018
|
+
{
|
|
1019
|
+
className: "inline-flex items-center cursor-pointer m-1 text-sm text-red-500",
|
|
1020
|
+
onClick: handleCloseConfirmation,
|
|
1021
|
+
children: [
|
|
1022
|
+
/* @__PURE__ */ jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", className: "text-red-500 w-6 h-6", children: /* @__PURE__ */ jsx(
|
|
1023
|
+
"path",
|
|
1024
|
+
{
|
|
1025
|
+
fillRule: "evenodd",
|
|
1026
|
+
d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
|
|
1027
|
+
clipRule: "evenodd"
|
|
1028
|
+
}
|
|
1029
|
+
) }),
|
|
1030
|
+
withText && cancelText
|
|
1031
|
+
]
|
|
1032
|
+
}
|
|
1033
|
+
)
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
)
|
|
1037
|
+
}
|
|
1038
|
+
)
|
|
1039
|
+
] }) });
|
|
1040
|
+
}
|
|
1041
|
+
function H1({ className, children }) {
|
|
1042
|
+
return /* @__PURE__ */ jsx(
|
|
1043
|
+
"h1",
|
|
1044
|
+
{
|
|
1045
|
+
className: classNames({
|
|
1046
|
+
"text-lg sm:text-xl font-title text-primary-500 font-semibold": true,
|
|
1047
|
+
...classNameObject(className)
|
|
1048
|
+
}),
|
|
1049
|
+
children
|
|
1050
|
+
}
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
function H2({ className, children }) {
|
|
1054
|
+
return /* @__PURE__ */ jsx(
|
|
1055
|
+
"h2",
|
|
1056
|
+
{
|
|
1057
|
+
className: classNames({
|
|
1058
|
+
"text-2xl font-semibold": true,
|
|
1059
|
+
...classNameObject(className)
|
|
1060
|
+
}),
|
|
1061
|
+
children
|
|
1062
|
+
}
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
function H3({ id, className, children }) {
|
|
1066
|
+
if (id) {
|
|
1067
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1068
|
+
/* @__PURE__ */ jsx("div", { id, className: "-mt-24" }),
|
|
1069
|
+
/* @__PURE__ */ jsx(
|
|
1070
|
+
"h3",
|
|
1071
|
+
{
|
|
1072
|
+
className: classNames({
|
|
1073
|
+
"pt-20 mb-0 text-lg font-semibold": true,
|
|
1074
|
+
...classNameObject(className)
|
|
1075
|
+
}),
|
|
1076
|
+
children
|
|
1077
|
+
}
|
|
1078
|
+
)
|
|
1079
|
+
] });
|
|
1080
|
+
}
|
|
1081
|
+
return /* @__PURE__ */ jsx(
|
|
1082
|
+
"h3",
|
|
1083
|
+
{
|
|
1084
|
+
className: classNames({
|
|
1085
|
+
"text-lg mb-0 font-semibold": true,
|
|
1086
|
+
...classNameObject(className)
|
|
1087
|
+
}),
|
|
1088
|
+
children
|
|
1089
|
+
}
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
function H4({ id, className, children }) {
|
|
1093
|
+
if (id) {
|
|
1094
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1095
|
+
/* @__PURE__ */ jsx("div", { id, className: "-mt-24" }),
|
|
1096
|
+
/* @__PURE__ */ jsx(
|
|
1097
|
+
"h4",
|
|
1098
|
+
{
|
|
1099
|
+
className: classNames({
|
|
1100
|
+
"pt-20 mb-0 text-base font-semibold": true,
|
|
1101
|
+
...classNameObject(className)
|
|
1102
|
+
}),
|
|
1103
|
+
children
|
|
1104
|
+
}
|
|
1105
|
+
)
|
|
1106
|
+
] });
|
|
1107
|
+
}
|
|
1108
|
+
return /* @__PURE__ */ jsx(
|
|
1109
|
+
"h4",
|
|
1110
|
+
{
|
|
1111
|
+
className: classNames({
|
|
1112
|
+
"text-base mb-0 font-semibold": true,
|
|
1113
|
+
...classNameObject(className)
|
|
1114
|
+
}),
|
|
1115
|
+
children
|
|
1116
|
+
}
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
function B({ children }) {
|
|
1120
|
+
return /* @__PURE__ */ jsx("b", { className: "font-semibold", children });
|
|
1121
|
+
}
|
|
1122
|
+
function Table({ children, className }) {
|
|
1123
|
+
return /* @__PURE__ */ jsx(
|
|
1124
|
+
"div",
|
|
1125
|
+
{
|
|
1126
|
+
className: classNames({
|
|
1127
|
+
...classNameObject(className),
|
|
1128
|
+
"flex flex-col relative": true,
|
|
1129
|
+
"sm:px-0 lg:px-8": !className || !className.includes("px-")
|
|
1130
|
+
}),
|
|
1131
|
+
children: /* @__PURE__ */ jsx("div", { className: "-my-2 py-2 px-0.5 sm:px-0 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8", children: /* @__PURE__ */ jsx("div", { className: "align-middle inline-block min-w-full shadow overflow-hidden rounded-lg border-b border-t border-gray-200", children: /* @__PURE__ */ jsx("table", { className: "min-w-full", children }) }) })
|
|
1132
|
+
}
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
function Thead({ children }) {
|
|
1136
|
+
return /* @__PURE__ */ jsx("thead", { children });
|
|
1137
|
+
}
|
|
1138
|
+
function Tr({ children }) {
|
|
1139
|
+
return /* @__PURE__ */ jsx("tr", { children });
|
|
1140
|
+
}
|
|
1141
|
+
function Th({ condensed, className, children, sticky, ...opts }) {
|
|
1142
|
+
return /* @__PURE__ */ jsx(
|
|
1143
|
+
"th",
|
|
1144
|
+
{
|
|
1145
|
+
className: classNames({
|
|
1146
|
+
...classNameObject(className),
|
|
1147
|
+
"sticky z-10 top-0": !!sticky,
|
|
1148
|
+
"border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider": true,
|
|
1149
|
+
"px-6": !condensed,
|
|
1150
|
+
"py-4": !condensed && (!className || !className.includes("py-")),
|
|
1151
|
+
"px-2.5": !!condensed,
|
|
1152
|
+
"py-2": !!condensed && (!className || !className.includes("py-"))
|
|
1153
|
+
}),
|
|
1154
|
+
...opts,
|
|
1155
|
+
children
|
|
1156
|
+
}
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
function Tbody({ children }) {
|
|
1160
|
+
return /* @__PURE__ */ jsx("tbody", { className: "bg-white", children });
|
|
1161
|
+
}
|
|
1162
|
+
function Td({ className, align, colSpan, condensed, narrow, children }) {
|
|
1163
|
+
return /* @__PURE__ */ jsx(
|
|
1164
|
+
"td",
|
|
1165
|
+
{
|
|
1166
|
+
align,
|
|
1167
|
+
colSpan,
|
|
1168
|
+
className: classNames({
|
|
1169
|
+
...classNameObject(className),
|
|
1170
|
+
"whitespace-no-wrap border-b border-gray-200": true,
|
|
1171
|
+
"px-6": !condensed && !narrow,
|
|
1172
|
+
"py-4": !condensed && !narrow && (!className || !className.includes("py-")),
|
|
1173
|
+
"px-2": !!condensed,
|
|
1174
|
+
"py-2": !!condensed && (!className || !className.includes("py-")),
|
|
1175
|
+
"px-0": !!narrow,
|
|
1176
|
+
"py-0": !!narrow && (!className || !className.includes("py-"))
|
|
1177
|
+
}),
|
|
1178
|
+
children
|
|
1179
|
+
}
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
var Input = forwardRef((props, ref) => {
|
|
1183
|
+
const {
|
|
1184
|
+
id,
|
|
1185
|
+
theme,
|
|
1186
|
+
className,
|
|
1187
|
+
label,
|
|
1188
|
+
placeholder,
|
|
1189
|
+
active,
|
|
1190
|
+
pattern,
|
|
1191
|
+
maxLength,
|
|
1192
|
+
inputMode,
|
|
1193
|
+
prefix,
|
|
1194
|
+
type = "text",
|
|
1195
|
+
info,
|
|
1196
|
+
defaultValue,
|
|
1197
|
+
checked,
|
|
1198
|
+
min,
|
|
1199
|
+
max,
|
|
1200
|
+
error = false,
|
|
1201
|
+
errorMessage,
|
|
1202
|
+
readOnly = false,
|
|
1203
|
+
name,
|
|
1204
|
+
autoComplete = "off",
|
|
1205
|
+
autoFocus,
|
|
1206
|
+
spellCheck,
|
|
1207
|
+
noBorder,
|
|
1208
|
+
listening,
|
|
1209
|
+
onChange,
|
|
1210
|
+
onFocus,
|
|
1211
|
+
onBlur,
|
|
1212
|
+
onClick,
|
|
1213
|
+
onKeyUp,
|
|
1214
|
+
onKeyDown,
|
|
1215
|
+
hideIndicator,
|
|
1216
|
+
darkMode
|
|
1217
|
+
} = props;
|
|
1218
|
+
const [focused, setFocused] = useState(false);
|
|
1219
|
+
const inputRef = useRef(null);
|
|
1220
|
+
const hasPrefix = !!prefix && prefix.length > 0;
|
|
1221
|
+
useImperativeHandle(ref, () => inputRef.current);
|
|
1222
|
+
useEffect(() => {
|
|
1223
|
+
if (listening && inputRef.current && defaultValue !== null && defaultValue !== void 0) {
|
|
1224
|
+
if (hasPrefix) {
|
|
1225
|
+
inputRef.current.value = prefix + String(defaultValue);
|
|
1226
|
+
} else {
|
|
1227
|
+
inputRef.current.value = String(defaultValue);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}, [defaultValue]);
|
|
1231
|
+
function handleChange(e) {
|
|
1232
|
+
const value = e.target.value;
|
|
1233
|
+
if (hasPrefix && inputRef.current) {
|
|
1234
|
+
const plainValue = hasPrefix ? value.length < prefix.length ? value.length === 1 ? value : "" : value.replace(prefix, "") : value;
|
|
1235
|
+
inputRef.current.value = prefix + plainValue;
|
|
1236
|
+
if (typeof onChange === "function") {
|
|
1237
|
+
if (type === "checkbox") {
|
|
1238
|
+
onChange(e.target.checked);
|
|
1239
|
+
} else {
|
|
1240
|
+
onChange(plainValue);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
} else {
|
|
1244
|
+
if (typeof onChange === "function") {
|
|
1245
|
+
if (type === "checkbox") {
|
|
1246
|
+
onChange(e.target.checked);
|
|
1247
|
+
} else {
|
|
1248
|
+
onChange(value);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
function handleFocus(e) {
|
|
1254
|
+
if (type === "search") {
|
|
1255
|
+
setFocused(true);
|
|
1256
|
+
}
|
|
1257
|
+
if (typeof onFocus === "function") {
|
|
1258
|
+
onFocus(e);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
function handleBlur(e) {
|
|
1262
|
+
if (type === "search") {
|
|
1263
|
+
setFocused(false);
|
|
1264
|
+
}
|
|
1265
|
+
if (typeof onBlur === "function") {
|
|
1266
|
+
onBlur(e);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1270
|
+
/* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
|
|
1271
|
+
/* @__PURE__ */ jsx(
|
|
1272
|
+
"input",
|
|
1273
|
+
{
|
|
1274
|
+
id,
|
|
1275
|
+
className: classNames({
|
|
1276
|
+
...classNameObject(className),
|
|
1277
|
+
"px-3 group form-input placeholder-gray-300 dark:placeholder-charcoal-400 focus:outline-none block transition ease-in-out duration-150 text-black dark:text-charcoal-100 dark:bg-charcoal-800 shadow-sm focus:dark:text-primary-500 focus:dark:border-primary-500 focus:dark:ring-primary-500": true,
|
|
1278
|
+
"!text-white !border-charcoal-400 !placeholder-charcoal-400 focus:!text-primary-500 focus:!border-primary-500 focus:!ring-primary-500": !!darkMode,
|
|
1279
|
+
"h-11": !className || !className.includes("h-"),
|
|
1280
|
+
"text-sm": type !== "tel",
|
|
1281
|
+
"text-lg": type === "tel",
|
|
1282
|
+
"rounded-lg": type !== "radio",
|
|
1283
|
+
"rounded-full": type === "radio",
|
|
1284
|
+
"border border-gray-200 dark:border-charcoal-700 shadow-sm text-black": !noBorder && !readOnly && type !== "radio",
|
|
1285
|
+
"border border-opacity-20 bg-gray-100 cursor-not-allowed": readOnly,
|
|
1286
|
+
"border-transparent": !!noBorder,
|
|
1287
|
+
"border-red-300 text-red-900 placeholder-red-100 focus:placeholder-red-100 focus:border-red-500 focus:ring-red-300": error,
|
|
1288
|
+
"focus:ring-primary-500": !error && type !== "radio",
|
|
1289
|
+
"focus:ring-transparent": type === "radio",
|
|
1290
|
+
"w-full": type !== "radio" && (!className || className.includes("w-full") || !className.includes("w-")),
|
|
1291
|
+
"sm:leading-normal": !className || !className.includes("leading-"),
|
|
1292
|
+
"cursor-pointer": type === "checkbox" || type === "button",
|
|
1293
|
+
"text-black h-4 w-4": type === "radio",
|
|
1294
|
+
"pr-10": type === "search"
|
|
1295
|
+
}),
|
|
1296
|
+
...type === "button" ? { value: label } : {},
|
|
1297
|
+
inputMode,
|
|
1298
|
+
pattern,
|
|
1299
|
+
name,
|
|
1300
|
+
min,
|
|
1301
|
+
max,
|
|
1302
|
+
ref: inputRef,
|
|
1303
|
+
type,
|
|
1304
|
+
maxLength,
|
|
1305
|
+
defaultValue,
|
|
1306
|
+
placeholder,
|
|
1307
|
+
readOnly,
|
|
1308
|
+
autoComplete,
|
|
1309
|
+
autoFocus,
|
|
1310
|
+
spellCheck,
|
|
1311
|
+
onClick,
|
|
1312
|
+
onChange: handleChange,
|
|
1313
|
+
onFocus: handleFocus,
|
|
1314
|
+
onBlur: handleBlur,
|
|
1315
|
+
onKeyUp,
|
|
1316
|
+
onKeyDown
|
|
1317
|
+
}
|
|
1318
|
+
),
|
|
1319
|
+
error && !hideIndicator && /* @__PURE__ */ jsx(
|
|
1320
|
+
"div",
|
|
1321
|
+
{
|
|
1322
|
+
className: classNames({
|
|
1323
|
+
"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none": true,
|
|
1324
|
+
"!text-white focus:!text-primary-500": !!darkMode
|
|
1325
|
+
}),
|
|
1326
|
+
children: /* @__PURE__ */ jsx("svg", { className: "w-5 h-5 text-red-500", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ jsx(
|
|
1327
|
+
"path",
|
|
1328
|
+
{
|
|
1329
|
+
fillRule: "evenodd",
|
|
1330
|
+
d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",
|
|
1331
|
+
clipRule: "evenodd"
|
|
1332
|
+
}
|
|
1333
|
+
) })
|
|
1334
|
+
}
|
|
1335
|
+
),
|
|
1336
|
+
type === "search" && /* @__PURE__ */ jsx(
|
|
1337
|
+
"div",
|
|
1338
|
+
{
|
|
1339
|
+
className: classNames({
|
|
1340
|
+
"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none focus:outline-none active:outline-none": true,
|
|
1341
|
+
"!text-white": !!darkMode,
|
|
1342
|
+
"text-gray-600": !focused,
|
|
1343
|
+
"!text-primary-500": focused
|
|
1344
|
+
}),
|
|
1345
|
+
children: /* @__PURE__ */ jsx("svg", { className: "w-5 h-5", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ jsx(
|
|
1346
|
+
"path",
|
|
1347
|
+
{
|
|
1348
|
+
fillRule: "evenodd",
|
|
1349
|
+
d: "M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z",
|
|
1350
|
+
clipRule: "evenodd"
|
|
1351
|
+
}
|
|
1352
|
+
) })
|
|
1353
|
+
}
|
|
1354
|
+
)
|
|
1355
|
+
] }),
|
|
1356
|
+
error && errorMessage && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-red-600", children: errorMessage }),
|
|
1357
|
+
info != null && !error && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-gray-500", children: info })
|
|
1358
|
+
] });
|
|
1359
|
+
});
|
|
1360
|
+
Input.displayName = "Input";
|
|
1361
|
+
var Input_default = Input;
|
|
1362
|
+
function Label({
|
|
1363
|
+
className,
|
|
1364
|
+
error = false,
|
|
1365
|
+
htmlFor,
|
|
1366
|
+
info,
|
|
1367
|
+
mandatory,
|
|
1368
|
+
opts,
|
|
1369
|
+
children
|
|
1370
|
+
}) {
|
|
1371
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1372
|
+
/* @__PURE__ */ jsxs(
|
|
1373
|
+
"label",
|
|
1374
|
+
{
|
|
1375
|
+
htmlFor,
|
|
1376
|
+
className: classNames({
|
|
1377
|
+
"block text-sm font-medium mb-1.5 text-black dark:text-white": true,
|
|
1378
|
+
"text-black dark:text-white/80": !error,
|
|
1379
|
+
"text-red-600": error,
|
|
1380
|
+
...classNameObject(className)
|
|
1381
|
+
}),
|
|
1382
|
+
children: [
|
|
1383
|
+
children,
|
|
1384
|
+
mandatory && /* @__PURE__ */ jsx("span", { className: "text-red-500 ml-1", children: "*" })
|
|
1385
|
+
]
|
|
1386
|
+
}
|
|
1387
|
+
),
|
|
1388
|
+
info && /* @__PURE__ */ jsx(
|
|
1389
|
+
"span",
|
|
1390
|
+
{
|
|
1391
|
+
className: classNames({
|
|
1392
|
+
"text-sm leading-5 text-black mb-1.5": true,
|
|
1393
|
+
"text-red-600": error
|
|
1394
|
+
}),
|
|
1395
|
+
children: info
|
|
1396
|
+
}
|
|
1397
|
+
)
|
|
1398
|
+
] });
|
|
1399
|
+
}
|
|
1400
|
+
var Select = forwardRef((props, ref) => {
|
|
1401
|
+
const {
|
|
1402
|
+
id,
|
|
1403
|
+
loading = false,
|
|
1404
|
+
className,
|
|
1405
|
+
onChange,
|
|
1406
|
+
error = false,
|
|
1407
|
+
errorMessage,
|
|
1408
|
+
info,
|
|
1409
|
+
readOnly = false,
|
|
1410
|
+
name,
|
|
1411
|
+
children,
|
|
1412
|
+
value
|
|
1413
|
+
} = props;
|
|
1414
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1415
|
+
!loading && /* @__PURE__ */ jsx("div", { className: "rounded-md shadow-sm border border-gray-200", children: /* @__PURE__ */ jsx(
|
|
1416
|
+
"select",
|
|
1417
|
+
{
|
|
1418
|
+
id,
|
|
1419
|
+
value,
|
|
1420
|
+
className: classNames({
|
|
1421
|
+
...classNameObject(className),
|
|
1422
|
+
...classNameObject(
|
|
1423
|
+
`form-select block w-full transition duration-150 ease-in-out ${error ? "border-red-300 text-red-900 placeholder-red-300 focus:border-red-300 focus:shadow-outline-red" : ""}`
|
|
1424
|
+
)
|
|
1425
|
+
}),
|
|
1426
|
+
ref,
|
|
1427
|
+
name,
|
|
1428
|
+
disabled: readOnly,
|
|
1429
|
+
onChange,
|
|
1430
|
+
children
|
|
1431
|
+
}
|
|
1432
|
+
) }),
|
|
1433
|
+
loading && /* @__PURE__ */ jsx("span", { className: "inline-flex relative w-6 loading" }),
|
|
1434
|
+
error && errorMessage && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-red-600", children: errorMessage }),
|
|
1435
|
+
info != null && !error && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-gray-500", children: info })
|
|
1436
|
+
] });
|
|
1437
|
+
});
|
|
1438
|
+
Select.displayName = "Select";
|
|
1439
|
+
var Select_default = Select;
|
|
1440
|
+
var SelectInput = forwardRef((props, ref) => {
|
|
1441
|
+
const {
|
|
1442
|
+
className,
|
|
1443
|
+
placeholder = "Select an option",
|
|
1444
|
+
items = [],
|
|
1445
|
+
selectedValue = "",
|
|
1446
|
+
readOnly = false,
|
|
1447
|
+
error = false,
|
|
1448
|
+
onChange = () => {
|
|
1449
|
+
}
|
|
1450
|
+
} = props;
|
|
1451
|
+
function handleOnChange(event) {
|
|
1452
|
+
const value = event.target.value;
|
|
1453
|
+
if (typeof onChange === "function") {
|
|
1454
|
+
onChange(value);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
return /* @__PURE__ */ jsxs(
|
|
1458
|
+
"select",
|
|
1459
|
+
{
|
|
1460
|
+
onChange: handleOnChange,
|
|
1461
|
+
value: selectedValue || "",
|
|
1462
|
+
disabled: readOnly,
|
|
1463
|
+
className: classNames({
|
|
1464
|
+
"form-select block w-full transition duration-150 ease-in-out border border-gray-200 rounded-md shadow-sm text-sm px-3 h-11 text-black": true,
|
|
1465
|
+
"cursor-not-allowed border bg-gray-100": readOnly,
|
|
1466
|
+
"border-red-300 text-red-900 placeholder-red-100 focus:placeholder-red-100 focus:border-red-500 focus:ring-red-300": error
|
|
1467
|
+
}),
|
|
1468
|
+
children: [
|
|
1469
|
+
/* @__PURE__ */ jsx("option", { value: "", children: placeholder }, ""),
|
|
1470
|
+
items.map((item, index) => /* @__PURE__ */ jsx("option", { value: item.id, children: item.name }, index))
|
|
1471
|
+
]
|
|
1472
|
+
}
|
|
1473
|
+
);
|
|
1474
|
+
});
|
|
1475
|
+
SelectInput.displayName = "SelectInput";
|
|
1476
|
+
var SelectInput_default = SelectInput;
|
|
1477
|
+
var Textarea = forwardRef((props, ref) => {
|
|
1478
|
+
const {
|
|
1479
|
+
id,
|
|
1480
|
+
className,
|
|
1481
|
+
onChange,
|
|
1482
|
+
onFocus,
|
|
1483
|
+
onMouseDown,
|
|
1484
|
+
placeholder,
|
|
1485
|
+
error = false,
|
|
1486
|
+
errorMessage,
|
|
1487
|
+
info,
|
|
1488
|
+
readOnly = false,
|
|
1489
|
+
name,
|
|
1490
|
+
defaultValue,
|
|
1491
|
+
rows,
|
|
1492
|
+
opts,
|
|
1493
|
+
autoFocus
|
|
1494
|
+
} = props;
|
|
1495
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1496
|
+
/* @__PURE__ */ jsxs("div", { className: "relative rounded-xl shadow-sm", "data-plate-focus": opts?.plateFocus, children: [
|
|
1497
|
+
/* @__PURE__ */ jsx(
|
|
1498
|
+
"textarea",
|
|
1499
|
+
{
|
|
1500
|
+
"data-plate-focus": opts?.plateFocus,
|
|
1501
|
+
autoFocus,
|
|
1502
|
+
id,
|
|
1503
|
+
rows,
|
|
1504
|
+
placeholder,
|
|
1505
|
+
className: classNames({
|
|
1506
|
+
...classNameObject(className),
|
|
1507
|
+
"form-input border block w-full placeholder-gray-300 dark:placeholder-white/50 dark:focus:placeholder-charcoal-400 text-sm transition ease-in-out duration-150 px-3 py-2 border-gray-200 dark:border-charcoal-700 text-black dark:text-charcoal-100 dark:bg-charcoal-800 rounded-lg": true,
|
|
1508
|
+
"focus:ring-white dark:focus:ring-1 dark:focus:border-primary-600 dark:focus:ring-primary-500": !error,
|
|
1509
|
+
"focus:outline-none focus:ring-0 focus:ring-offset-0 dark:focus:border-primary-500": true,
|
|
1510
|
+
"border-red-300 text-red-900 placeholder-red-300 dark:placeholder-red-600 focus:border-red-300 focus:shadow-outline-red": error
|
|
1511
|
+
}),
|
|
1512
|
+
name,
|
|
1513
|
+
ref,
|
|
1514
|
+
defaultValue,
|
|
1515
|
+
onFocus,
|
|
1516
|
+
onMouseDown,
|
|
1517
|
+
onChange,
|
|
1518
|
+
readOnly
|
|
1519
|
+
}
|
|
1520
|
+
),
|
|
1521
|
+
error && /* @__PURE__ */ jsx("div", { className: "absolute top-2 right-0 pr-3 flex pointer-events-none", children: /* @__PURE__ */ jsx("svg", { className: "h-5 w-5 text-red-500", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ jsx(
|
|
1522
|
+
"path",
|
|
1523
|
+
{
|
|
1524
|
+
fillRule: "evenodd",
|
|
1525
|
+
d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",
|
|
1526
|
+
clipRule: "evenodd"
|
|
1527
|
+
}
|
|
1528
|
+
) }) })
|
|
1529
|
+
] }),
|
|
1530
|
+
error && errorMessage && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-red-600", children: errorMessage }),
|
|
1531
|
+
info != null && !error && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-gray-500", children: info })
|
|
1532
|
+
] });
|
|
1533
|
+
});
|
|
1534
|
+
Textarea.displayName = "Textarea";
|
|
1535
|
+
var Textarea_default = Textarea;
|
|
1536
|
+
function TagInput({
|
|
1537
|
+
name,
|
|
1538
|
+
defaultValue,
|
|
1539
|
+
onChange,
|
|
1540
|
+
placeholder
|
|
1541
|
+
}) {
|
|
1542
|
+
const [currentState, setCurrentState] = useState(0);
|
|
1543
|
+
const tagInputRef = useRef(null);
|
|
1544
|
+
function reducer(state, action) {
|
|
1545
|
+
const updatedValues = { ...state };
|
|
1546
|
+
if ("tags" in action) {
|
|
1547
|
+
updatedValues.tags = Array.from(new Set(action.tags));
|
|
1548
|
+
}
|
|
1549
|
+
if ("reset" in action && action.reset) {
|
|
1550
|
+
updatedValues.tags = [];
|
|
1551
|
+
}
|
|
1552
|
+
if ("render" in action && action.render) {
|
|
1553
|
+
setCurrentState(1 - currentState);
|
|
1554
|
+
}
|
|
1555
|
+
return updatedValues;
|
|
1556
|
+
}
|
|
1557
|
+
const [values, dispatch] = useReducer(reducer, {
|
|
1558
|
+
tags: []
|
|
1559
|
+
});
|
|
1560
|
+
const { tags } = values;
|
|
1561
|
+
useEffect(() => {
|
|
1562
|
+
if (defaultValue) {
|
|
1563
|
+
dispatch({ tags: defaultValue, render: true });
|
|
1564
|
+
} else {
|
|
1565
|
+
dispatch({ reset: true, render: true });
|
|
1566
|
+
}
|
|
1567
|
+
}, [defaultValue]);
|
|
1568
|
+
function handleAddTag(event) {
|
|
1569
|
+
if (event.key === "Enter") {
|
|
1570
|
+
const value = event.target.value;
|
|
1571
|
+
if (!value) return false;
|
|
1572
|
+
const newTags = Array.from(/* @__PURE__ */ new Set([...tags, value]));
|
|
1573
|
+
dispatch({ tags: newTags, render: true });
|
|
1574
|
+
if (typeof onChange === "function") {
|
|
1575
|
+
onChange(newTags);
|
|
1576
|
+
}
|
|
1577
|
+
if (tagInputRef.current) {
|
|
1578
|
+
tagInputRef.current.value = "";
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
function handleRemoveTag(tag) {
|
|
1583
|
+
if (!tag) return false;
|
|
1584
|
+
const newTags = tags.filter((i) => i !== tag);
|
|
1585
|
+
dispatch({ tags: newTags, render: true });
|
|
1586
|
+
if (typeof onChange === "function") {
|
|
1587
|
+
onChange(newTags);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center w-full flex-wrap px-2 pt-2 pb-1 border border-gray-300 rounded-md", children: [
|
|
1591
|
+
tags.map((tag, index) => /* @__PURE__ */ jsxs(
|
|
1592
|
+
"span",
|
|
1593
|
+
{
|
|
1594
|
+
className: "inline-flex bg-primary-200 text-primary-800 text-sm rounded-full h-6 px-3 justify-center items-center mr-1 mb-1",
|
|
1595
|
+
children: [
|
|
1596
|
+
tag,
|
|
1597
|
+
/* @__PURE__ */ jsx(
|
|
1598
|
+
"svg",
|
|
1599
|
+
{
|
|
1600
|
+
className: "w-4 h-4 ml-1 cursor-pointer",
|
|
1601
|
+
fill: "currentColor",
|
|
1602
|
+
viewBox: "0 0 20 20",
|
|
1603
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1604
|
+
onClick: () => handleRemoveTag(tag),
|
|
1605
|
+
children: /* @__PURE__ */ jsx(
|
|
1606
|
+
"path",
|
|
1607
|
+
{
|
|
1608
|
+
fillRule: "evenodd",
|
|
1609
|
+
d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
|
|
1610
|
+
clipRule: "evenodd"
|
|
1611
|
+
}
|
|
1612
|
+
)
|
|
1613
|
+
}
|
|
1614
|
+
)
|
|
1615
|
+
]
|
|
1616
|
+
},
|
|
1617
|
+
index
|
|
1618
|
+
)),
|
|
1619
|
+
/* @__PURE__ */ jsx(
|
|
1620
|
+
"input",
|
|
1621
|
+
{
|
|
1622
|
+
ref: tagInputRef,
|
|
1623
|
+
className: "ml-2 text-sm focus:border-transparent focus:outline-none mb-1",
|
|
1624
|
+
placeholder: tags && tags.length > 0 ? "" : placeholder,
|
|
1625
|
+
onKeyDown: handleAddTag
|
|
1626
|
+
}
|
|
1627
|
+
)
|
|
1628
|
+
] });
|
|
1629
|
+
}
|
|
1630
|
+
function NoData({ className }) {
|
|
1631
|
+
return /* @__PURE__ */ jsxs("div", { className: `flex flex-col items-center text-center my-8 ${className || ""}`, children: [
|
|
1632
|
+
/* @__PURE__ */ jsx(
|
|
1633
|
+
"img",
|
|
1634
|
+
{
|
|
1635
|
+
src: "/img/no-data.png",
|
|
1636
|
+
width: 420,
|
|
1637
|
+
height: 307,
|
|
1638
|
+
className: "max-w-[90%]",
|
|
1639
|
+
alt: "no data found"
|
|
1640
|
+
}
|
|
1641
|
+
),
|
|
1642
|
+
/* @__PURE__ */ jsxs("div", { className: "max-w-[90%] flex flex-col text-center", children: [
|
|
1643
|
+
/* @__PURE__ */ jsx("h4", { className: "text-6 font-medium text-gray-900 mt-3 dark:text-white/50", children: "It's empty." }),
|
|
1644
|
+
/* @__PURE__ */ jsx("p", { className: "text-4 text-gray-700 dark:text-white/60", children: "Nothing to do for now." })
|
|
1645
|
+
] })
|
|
1646
|
+
] });
|
|
1647
|
+
}
|
|
1648
|
+
var ThemeContext = createContext(void 0);
|
|
1649
|
+
function ThemeProvider({ children, defaultTheme = "system" }) {
|
|
1650
|
+
const [mode, setMode] = useState(defaultTheme);
|
|
1651
|
+
const [isDark, setIsDark] = useState(false);
|
|
1652
|
+
const stateRef = useRef(mode);
|
|
1653
|
+
useEffect(() => {
|
|
1654
|
+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1655
|
+
const isDark2 = mode === "dark" || mode === "system" && prefersDark;
|
|
1656
|
+
document.documentElement.classList.toggle("dark", isDark2);
|
|
1657
|
+
stateRef.current = mode;
|
|
1658
|
+
setIsDark(isDark2);
|
|
1659
|
+
}, [mode]);
|
|
1660
|
+
useEffect(() => {
|
|
1661
|
+
const saved = localStorage.getItem("theme") || defaultTheme;
|
|
1662
|
+
setMode(saved);
|
|
1663
|
+
}, [defaultTheme]);
|
|
1664
|
+
useEffect(() => {
|
|
1665
|
+
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1666
|
+
const listener = () => {
|
|
1667
|
+
const prevMode = stateRef.current;
|
|
1668
|
+
if (prevMode !== "system") {
|
|
1669
|
+
setTimeout(() => {
|
|
1670
|
+
document.documentElement.classList.toggle("dark", prevMode === "dark");
|
|
1671
|
+
}, 100);
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
media.addEventListener("change", listener);
|
|
1675
|
+
return () => media.removeEventListener("change", listener);
|
|
1676
|
+
}, []);
|
|
1677
|
+
function handleToggleTheme(triggerMode) {
|
|
1678
|
+
const triggeredMode = triggerMode === mode ? "system" : triggerMode;
|
|
1679
|
+
setMode(triggeredMode);
|
|
1680
|
+
if (!triggeredMode || triggeredMode === "system") {
|
|
1681
|
+
localStorage.removeItem("theme");
|
|
1682
|
+
} else {
|
|
1683
|
+
localStorage.setItem("theme", triggeredMode);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
return /* @__PURE__ */ jsx(
|
|
1687
|
+
ThemeContext.Provider,
|
|
1688
|
+
{
|
|
1689
|
+
value: {
|
|
1690
|
+
theme: mode,
|
|
1691
|
+
darkMode: isDark,
|
|
1692
|
+
handleToggleTheme
|
|
1693
|
+
},
|
|
1694
|
+
children
|
|
1695
|
+
}
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
function useThemeContext() {
|
|
1699
|
+
const context = useContext(ThemeContext);
|
|
1700
|
+
if (!context) {
|
|
1701
|
+
throw new Error("useThemeContext must be used within a ThemeProvider");
|
|
1702
|
+
}
|
|
1703
|
+
return context;
|
|
1704
|
+
}
|
|
1705
|
+
function ThemeToggle() {
|
|
1706
|
+
const { theme, handleToggleTheme } = useThemeContext();
|
|
1707
|
+
return /* @__PURE__ */ jsxs("div", { className: "text-charcoal-700 dark:text-white z-30 flex space-x-1.5 items-center", children: [
|
|
1708
|
+
/* @__PURE__ */ jsx(
|
|
1709
|
+
"div",
|
|
1710
|
+
{
|
|
1711
|
+
className: classNames({
|
|
1712
|
+
"opacity-20 cursor-pointer": true,
|
|
1713
|
+
"!opacity-100": theme === "light"
|
|
1714
|
+
}),
|
|
1715
|
+
onClick: () => handleToggleTheme("light"),
|
|
1716
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "w-6 h-6", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" }) })
|
|
1717
|
+
}
|
|
1718
|
+
),
|
|
1719
|
+
/* @__PURE__ */ jsx(
|
|
1720
|
+
"div",
|
|
1721
|
+
{
|
|
1722
|
+
className: classNames({
|
|
1723
|
+
"opacity-20 cursor-pointer": true,
|
|
1724
|
+
"!opacity-100": theme === "dark"
|
|
1725
|
+
}),
|
|
1726
|
+
onClick: () => handleToggleTheme("dark"),
|
|
1727
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "w-5 h-5", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z" }) })
|
|
1728
|
+
}
|
|
1729
|
+
)
|
|
1730
|
+
] });
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// src/utils/debounce.ts
|
|
1734
|
+
function debounce(fn, delay) {
|
|
1735
|
+
let timeoutId;
|
|
1736
|
+
return function(...args) {
|
|
1737
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1738
|
+
timeoutId = setTimeout(() => {
|
|
1739
|
+
fn.apply(this, args);
|
|
1740
|
+
}, delay);
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
// src/hooks/useDebounce.ts
|
|
1745
|
+
function useDebounce(callback, delay, deps = []) {
|
|
1746
|
+
const callbackFn = useCallback(debounce(callback, delay), deps);
|
|
1747
|
+
return [callbackFn];
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// src/hooks/useResizeListener.ts
|
|
1751
|
+
function useResizeListener(props = {}) {
|
|
1752
|
+
const [values, setValues] = useState(
|
|
1753
|
+
[
|
|
1754
|
+
typeof window === "undefined" ? props.mobileAgent ? 375 : 1080 : window.innerWidth,
|
|
1755
|
+
typeof window === "undefined" ? props.mobileAgent ? 812 : 750 : window.innerHeight,
|
|
1756
|
+
typeof window === "undefined" ? null : window.innerWidth < 576 ? "mobile" : "desktop",
|
|
1757
|
+
typeof window === "undefined" ? null : window.innerWidth < 576 ? "portrait-view" : "landscape-view",
|
|
1758
|
+
typeof window === "undefined" ? props.mobileAgent || null : window.innerWidth < 576 ? true : false,
|
|
1759
|
+
typeof window === "undefined" ? props.mobileAgent || null : window.innerWidth >= 576 && window.innerWidth < 992 ? true : false
|
|
1760
|
+
]
|
|
1761
|
+
);
|
|
1762
|
+
const [screenWidth, screenHeight, viewport, viewMode, mobileView, tabletView] = values || [];
|
|
1763
|
+
function handleChangeViewport() {
|
|
1764
|
+
setValues([
|
|
1765
|
+
window.innerWidth,
|
|
1766
|
+
window.innerHeight,
|
|
1767
|
+
window.innerWidth < 576 ? "mobile" : "desktop",
|
|
1768
|
+
window.innerWidth < 576 ? "portrait-view" : "landscape-view",
|
|
1769
|
+
window.innerWidth < 576 ? true : false,
|
|
1770
|
+
window.innerWidth >= 576 && window.innerWidth < 992 ? true : false
|
|
1771
|
+
]);
|
|
1772
|
+
}
|
|
1773
|
+
const [debouncedSetValue] = useDebounce(handleChangeViewport, 300);
|
|
1774
|
+
useEffect(() => {
|
|
1775
|
+
window.addEventListener("resize", debouncedSetValue);
|
|
1776
|
+
return () => {
|
|
1777
|
+
window.removeEventListener("resize", debouncedSetValue);
|
|
1778
|
+
};
|
|
1779
|
+
}, [debouncedSetValue]);
|
|
1780
|
+
return { screenWidth, screenHeight, viewport, viewMode, mobileView, tabletView };
|
|
1781
|
+
}
|
|
1782
|
+
var PopoverContext = createContext(void 0);
|
|
1783
|
+
function PopoverCard({
|
|
1784
|
+
show,
|
|
1785
|
+
style,
|
|
1786
|
+
tooltipStyle,
|
|
1787
|
+
position,
|
|
1788
|
+
description,
|
|
1789
|
+
actions,
|
|
1790
|
+
onClose
|
|
1791
|
+
}) {
|
|
1792
|
+
function handleMenuClick(action) {
|
|
1793
|
+
if (typeof action === "function") {
|
|
1794
|
+
action();
|
|
1795
|
+
}
|
|
1796
|
+
if (typeof onClose === "function") {
|
|
1797
|
+
onClose();
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
function handleCloseMenu() {
|
|
1801
|
+
if (typeof onClose === "function") {
|
|
1802
|
+
onClose();
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const stickyTop = position === "top";
|
|
1806
|
+
if (typeof document === "undefined") return null;
|
|
1807
|
+
return createPortal(
|
|
1808
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1809
|
+
/* @__PURE__ */ jsxs(
|
|
1810
|
+
"div",
|
|
1811
|
+
{
|
|
1812
|
+
className: classNames({
|
|
1813
|
+
"hidden sm:block fixed text-sm z-[9999] w-52 max-h-64 overflow-y-auto border border-gray-100 bg-white dark:bg-charcoal-800 dark:border-charcoal-700 shadow-md rounded-md pt-3 pb-2": true,
|
|
1814
|
+
"pointer-events-none opacity-0": !show,
|
|
1815
|
+
"opacity-100": show
|
|
1816
|
+
}),
|
|
1817
|
+
style: style || void 0,
|
|
1818
|
+
children: [
|
|
1819
|
+
!!description && /* @__PURE__ */ jsx("p", { className: "px-3 pb-1 opacity-70", children: description }),
|
|
1820
|
+
actions && actions.length > 0 && /* @__PURE__ */ jsx("div", { className: "space-y-1.5 w-full", children: actions.filter((action) => (action.items || []).length > 0).map((action, actionIndex) => /* @__PURE__ */ jsxs("div", { children: [
|
|
1821
|
+
actionIndex > 0 && /* @__PURE__ */ jsx("div", { className: "w-full h-px bg-gray-100 dark:bg-charcoal-800 mb-3" }),
|
|
1822
|
+
action.section && /* @__PURE__ */ jsx("p", { className: "px-3 text-xxs sm:text-xs uppercase text-gray-500 dark:text-white dark:hover", children: action.section }),
|
|
1823
|
+
/* @__PURE__ */ jsx(
|
|
1824
|
+
"div",
|
|
1825
|
+
{
|
|
1826
|
+
className: classNames({
|
|
1827
|
+
"mt-1": !!action.section
|
|
1828
|
+
}),
|
|
1829
|
+
children: (action.items || []).map((item) => /* @__PURE__ */ jsx(
|
|
1830
|
+
"div",
|
|
1831
|
+
{
|
|
1832
|
+
className: "text-sm sm:text-base px-3 py-1.5 text-charcoal-700 dark:text-charcoal-300 hover:text-gray-900 hover:bg-gray-200 hover:dark:text-charcoal-200 hover:dark:bg-charcoal-700 cursor-pointer whitespace-normal",
|
|
1833
|
+
onClick: () => handleMenuClick(item.action || item.onClick),
|
|
1834
|
+
children: item.label
|
|
1835
|
+
},
|
|
1836
|
+
item.id
|
|
1837
|
+
))
|
|
1838
|
+
}
|
|
1839
|
+
)
|
|
1840
|
+
] }, action.id)) })
|
|
1841
|
+
]
|
|
1842
|
+
}
|
|
1843
|
+
),
|
|
1844
|
+
/* @__PURE__ */ jsx(
|
|
1845
|
+
"div",
|
|
1846
|
+
{
|
|
1847
|
+
className: classNames({
|
|
1848
|
+
"hidden sm:block fixed z-[9999] rotate-45 w-4 h-4 overflow-y-auto border-gray-100 bg-white dark:bg-charcoal-700 dark:border-charcoal-800": true,
|
|
1849
|
+
"border-t border-l": !stickyTop,
|
|
1850
|
+
"border-b border-r": stickyTop,
|
|
1851
|
+
"pointer-events-none opacity-0": !show,
|
|
1852
|
+
"opacity-100": show
|
|
1853
|
+
}),
|
|
1854
|
+
style: tooltipStyle || void 0
|
|
1855
|
+
}
|
|
1856
|
+
),
|
|
1857
|
+
/* @__PURE__ */ jsxs("div", { className: classNames({
|
|
1858
|
+
"block sm:hidden fixed inset-0 z-[9999] pointer-events-none": true
|
|
1859
|
+
}), children: [
|
|
1860
|
+
/* @__PURE__ */ jsx(
|
|
1861
|
+
"div",
|
|
1862
|
+
{
|
|
1863
|
+
className: classNames({
|
|
1864
|
+
"absolute inset-0 bg-black/50 transition-opacity duration-300": true,
|
|
1865
|
+
"opacity-0": !show,
|
|
1866
|
+
"opacity-100 pointer-events-auto": show
|
|
1867
|
+
}),
|
|
1868
|
+
onClick: handleCloseMenu
|
|
1869
|
+
}
|
|
1870
|
+
),
|
|
1871
|
+
/* @__PURE__ */ jsxs(
|
|
1872
|
+
"div",
|
|
1873
|
+
{
|
|
1874
|
+
className: classNames({
|
|
1875
|
+
"absolute bottom-0 left-0 right-0 bg-white dark:bg-charcoal-800 overflow-hidden transition-transform duration-300 transform": true,
|
|
1876
|
+
"translate-y-full": !show,
|
|
1877
|
+
"translate-y-0 pointer-events-auto": show
|
|
1878
|
+
}),
|
|
1879
|
+
children: [
|
|
1880
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3", children: [
|
|
1881
|
+
/* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-900 dark:text-white", children: "Menu" }),
|
|
1882
|
+
/* @__PURE__ */ jsx(
|
|
1883
|
+
"div",
|
|
1884
|
+
{
|
|
1885
|
+
onClick: handleCloseMenu,
|
|
1886
|
+
className: "p-1 -mr-1 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-charcoal-700 rounded-full",
|
|
1887
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
1888
|
+
}
|
|
1889
|
+
)
|
|
1890
|
+
] }),
|
|
1891
|
+
/* @__PURE__ */ jsxs("div", { className: "px-4 pb-6 max-h-[70vh] overflow-y-auto", children: [
|
|
1892
|
+
!!description && /* @__PURE__ */ jsx("p", { className: "mb-4 text-sm text-gray-500 dark:text-gray-400", children: description }),
|
|
1893
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-4", children: actions && actions.filter((action) => (action.items || []).length > 0).map((action, actionIndex) => /* @__PURE__ */ jsxs("div", { children: [
|
|
1894
|
+
action.section && /* @__PURE__ */ jsx("p", { className: "text-xs font-medium uppercase text-gray-500 dark:text-gray-400 mb-2", children: action.section }),
|
|
1895
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-1", children: (action.items || []).map((item) => /* @__PURE__ */ jsx(
|
|
1896
|
+
"div",
|
|
1897
|
+
{
|
|
1898
|
+
className: "py-1.5 px-2 -mx-2 flex items-center text-base text-gray-900 dark:text-gray-200 active:bg-gray-50 dark:active:bg-charcoal-700 rounded-lg cursor-pointer",
|
|
1899
|
+
onClick: () => handleMenuClick(item.action || item.onClick),
|
|
1900
|
+
children: item.label
|
|
1901
|
+
},
|
|
1902
|
+
item.id
|
|
1903
|
+
)) }),
|
|
1904
|
+
actionIndex < actions.length - 1 && /* @__PURE__ */ jsx("hr", { className: "mt-2 border-transparent" })
|
|
1905
|
+
] }, action.id)) })
|
|
1906
|
+
] })
|
|
1907
|
+
]
|
|
1908
|
+
}
|
|
1909
|
+
)
|
|
1910
|
+
] }),
|
|
1911
|
+
show && /* @__PURE__ */ jsx(
|
|
1912
|
+
"div",
|
|
1913
|
+
{
|
|
1914
|
+
className: "hidden sm:block fixed inset-0",
|
|
1915
|
+
onClick: handleCloseMenu
|
|
1916
|
+
}
|
|
1917
|
+
)
|
|
1918
|
+
] }),
|
|
1919
|
+
document.body
|
|
1920
|
+
);
|
|
1921
|
+
}
|
|
1922
|
+
var resetValues = {
|
|
1923
|
+
show: false,
|
|
1924
|
+
style: null,
|
|
1925
|
+
tooltipStyle: null,
|
|
1926
|
+
position: null,
|
|
1927
|
+
description: null,
|
|
1928
|
+
actions: null
|
|
1929
|
+
};
|
|
1930
|
+
function PopoverProvider({ children }) {
|
|
1931
|
+
const [currentState, setCurrentState] = useState(0);
|
|
1932
|
+
const [values, dispatch] = useReducer(reducer, resetValues);
|
|
1933
|
+
const { show, style, tooltipStyle, position, description, actions } = values;
|
|
1934
|
+
function reducer(state, action) {
|
|
1935
|
+
const updatedValues = { ...state };
|
|
1936
|
+
if ("show" in action) {
|
|
1937
|
+
updatedValues.show = action.show;
|
|
1938
|
+
}
|
|
1939
|
+
if ("style" in action) {
|
|
1940
|
+
updatedValues.style = action.style;
|
|
1941
|
+
}
|
|
1942
|
+
if ("tooltipStyle" in action) {
|
|
1943
|
+
updatedValues.tooltipStyle = action.tooltipStyle;
|
|
1944
|
+
}
|
|
1945
|
+
if ("position" in action) {
|
|
1946
|
+
updatedValues.position = action.position;
|
|
1947
|
+
}
|
|
1948
|
+
if ("description" in action) {
|
|
1949
|
+
updatedValues.description = action.description;
|
|
1950
|
+
}
|
|
1951
|
+
if ("actions" in action) {
|
|
1952
|
+
updatedValues.actions = action.actions;
|
|
1953
|
+
}
|
|
1954
|
+
if ("render" in action && !!action.render) {
|
|
1955
|
+
setCurrentState((prev) => 1 - prev);
|
|
1956
|
+
}
|
|
1957
|
+
return updatedValues;
|
|
1958
|
+
}
|
|
1959
|
+
function handleShowPopover(params) {
|
|
1960
|
+
dispatch({
|
|
1961
|
+
...params,
|
|
1962
|
+
render: true
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
function handleClosePopover() {
|
|
1966
|
+
dispatch({
|
|
1967
|
+
...resetValues,
|
|
1968
|
+
render: true
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
return /* @__PURE__ */ jsxs(
|
|
1972
|
+
PopoverContext.Provider,
|
|
1973
|
+
{
|
|
1974
|
+
value: {
|
|
1975
|
+
showPopover: show,
|
|
1976
|
+
setPopover: handleShowPopover
|
|
1977
|
+
},
|
|
1978
|
+
children: [
|
|
1979
|
+
children,
|
|
1980
|
+
!!show && /* @__PURE__ */ jsx(
|
|
1981
|
+
PopoverCard,
|
|
1982
|
+
{
|
|
1983
|
+
show,
|
|
1984
|
+
style,
|
|
1985
|
+
tooltipStyle,
|
|
1986
|
+
position,
|
|
1987
|
+
description,
|
|
1988
|
+
actions,
|
|
1989
|
+
onClose: handleClosePopover
|
|
1990
|
+
}
|
|
1991
|
+
)
|
|
1992
|
+
]
|
|
1993
|
+
}
|
|
1994
|
+
);
|
|
1995
|
+
}
|
|
1996
|
+
function usePopoverContext() {
|
|
1997
|
+
const context = useContext(PopoverContext);
|
|
1998
|
+
if (!context) {
|
|
1999
|
+
throw new Error("usePopoverContext must be used within a PopoverProvider");
|
|
2000
|
+
}
|
|
2001
|
+
return context;
|
|
2002
|
+
}
|
|
2003
|
+
function Popover({ className, description, actions, children, opts }) {
|
|
2004
|
+
const { activated } = opts || {};
|
|
2005
|
+
const { showPopover, setPopover } = usePopoverContext();
|
|
2006
|
+
const { screenWidth, screenHeight } = useResizeListener();
|
|
2007
|
+
const [menuData, setMenuData] = useState({ showMenu: false, x: 0, y: 0, left: 0, right: 0, top: 0, bottom: 0 });
|
|
2008
|
+
const parentRef = useRef(null);
|
|
2009
|
+
(actions || []).some((action) => (action.items || []).length > 0);
|
|
2010
|
+
useEffect(() => {
|
|
2011
|
+
const stickyTop = menuData.showMenu && screenHeight - (menuData.y + 14) < 300;
|
|
2012
|
+
setPopover({
|
|
2013
|
+
show: menuData.showMenu,
|
|
2014
|
+
style: !stickyTop ? {
|
|
2015
|
+
top: menuData.bottom + 14,
|
|
2016
|
+
right: screenWidth - menuData.right - 6
|
|
2017
|
+
} : {
|
|
2018
|
+
bottom: screenHeight - menuData.top + 12,
|
|
2019
|
+
right: screenWidth - menuData.right - 6
|
|
2020
|
+
},
|
|
2021
|
+
tooltipStyle: !stickyTop ? {
|
|
2022
|
+
top: menuData.bottom + 6,
|
|
2023
|
+
right: screenWidth - menuData.right + 6
|
|
2024
|
+
} : {
|
|
2025
|
+
bottom: screenHeight - menuData.top + 4,
|
|
2026
|
+
right: screenWidth - menuData.right + 6
|
|
2027
|
+
},
|
|
2028
|
+
position: stickyTop ? "top" : "bottom",
|
|
2029
|
+
description,
|
|
2030
|
+
actions
|
|
2031
|
+
});
|
|
2032
|
+
}, [menuData, screenWidth, screenHeight, description, actions, setPopover]);
|
|
2033
|
+
useEffect(() => {
|
|
2034
|
+
if (!showPopover && !!menuData.showMenu) {
|
|
2035
|
+
setMenuData((prev) => ({
|
|
2036
|
+
...prev,
|
|
2037
|
+
showMenu: false
|
|
2038
|
+
}));
|
|
2039
|
+
}
|
|
2040
|
+
}, [showPopover, menuData.showMenu]);
|
|
2041
|
+
function handleToggleMenu(e) {
|
|
2042
|
+
e.stopPropagation();
|
|
2043
|
+
if (menuData.showMenu) {
|
|
2044
|
+
handleCloseMenu();
|
|
2045
|
+
} else {
|
|
2046
|
+
handleOpenMenu();
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function handleOpenMenu() {
|
|
2050
|
+
if (parentRef && parentRef.current) {
|
|
2051
|
+
const coords = parentRef.current.getBoundingClientRect();
|
|
2052
|
+
setMenuData({
|
|
2053
|
+
showMenu: true,
|
|
2054
|
+
left: coords.left,
|
|
2055
|
+
right: coords.right,
|
|
2056
|
+
top: coords.top,
|
|
2057
|
+
bottom: coords.bottom,
|
|
2058
|
+
x: screenWidth - coords.right,
|
|
2059
|
+
y: coords.bottom
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
function handleCloseMenu() {
|
|
2064
|
+
setMenuData({
|
|
2065
|
+
showMenu: false,
|
|
2066
|
+
x: 0,
|
|
2067
|
+
y: 0,
|
|
2068
|
+
left: 0,
|
|
2069
|
+
right: 0,
|
|
2070
|
+
top: 0,
|
|
2071
|
+
bottom: 0
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
return /* @__PURE__ */ jsx("div", { className: "block h-full", children: /* @__PURE__ */ jsx(
|
|
2075
|
+
"div",
|
|
2076
|
+
{
|
|
2077
|
+
ref: parentRef,
|
|
2078
|
+
className: classNames({
|
|
2079
|
+
"cursor-pointer py-0.5 px-2 h-full flex items-center justify-center hover:bg-gray-300/50 hover:dark:bg-charcoal-700 rounded-xl": true,
|
|
2080
|
+
"bg-gray-300/50 dark:bg-charcoal-700": menuData.showMenu && !activated,
|
|
2081
|
+
...classNameObject(className)
|
|
2082
|
+
}),
|
|
2083
|
+
onClick: handleToggleMenu,
|
|
2084
|
+
children
|
|
2085
|
+
}
|
|
2086
|
+
) });
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
// src/utils/format.ts
|
|
2090
|
+
var srgbToLinear = (c) => {
|
|
2091
|
+
c /= 255;
|
|
2092
|
+
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
2093
|
+
};
|
|
2094
|
+
var luminance = (r, g, b) => {
|
|
2095
|
+
const R = srgbToLinear(r);
|
|
2096
|
+
const G = srgbToLinear(g);
|
|
2097
|
+
const B2 = srgbToLinear(b);
|
|
2098
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B2;
|
|
2099
|
+
};
|
|
2100
|
+
var contrastRatio = (L1, L2) => {
|
|
2101
|
+
const [light, dark] = L1 > L2 ? [L1, L2] : [L2, L1];
|
|
2102
|
+
return (light + 0.05) / (dark + 0.05);
|
|
2103
|
+
};
|
|
2104
|
+
var hexToRgb = (hex) => {
|
|
2105
|
+
hex = hex.replace(/^#/, "");
|
|
2106
|
+
if (hex.length === 3) {
|
|
2107
|
+
hex = hex.split("").map((x) => x + x).join("");
|
|
2108
|
+
}
|
|
2109
|
+
const num = parseInt(hex, 16);
|
|
2110
|
+
return {
|
|
2111
|
+
r: num >> 16 & 255,
|
|
2112
|
+
g: num >> 8 & 255,
|
|
2113
|
+
b: num & 255
|
|
2114
|
+
};
|
|
2115
|
+
};
|
|
2116
|
+
function bestTextColorForBg(hex) {
|
|
2117
|
+
const { r, g, b } = hexToRgb(hex || "#FFFFFF");
|
|
2118
|
+
const Lbg = luminance(r, g, b);
|
|
2119
|
+
const contrastWithWhite = contrastRatio(Lbg, 1);
|
|
2120
|
+
const contrastWithBlack = contrastRatio(Lbg, 0);
|
|
2121
|
+
return contrastWithWhite >= contrastWithBlack ? "white" : "black";
|
|
2122
|
+
}
|
|
2123
|
+
var numberFormatter = (x, decimal, opts) => {
|
|
2124
|
+
const { decimalSign, thousandSign } = opts || {};
|
|
2125
|
+
if (x === null || x === void 0 || x === "") return "";
|
|
2126
|
+
const parsedX = typeof x === "string" ? parseFloat(x) : x;
|
|
2127
|
+
if (isNaN(parsedX)) return "";
|
|
2128
|
+
const value = Math.round(parsedX * 100) / 100;
|
|
2129
|
+
if (typeof decimal == "number") {
|
|
2130
|
+
if (Math.floor(value) == value) {
|
|
2131
|
+
return value.toFixed(decimal || 0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, thousandSign || ",");
|
|
2132
|
+
}
|
|
2133
|
+
return value.toFixed(decimal).toString().replace(".", decimalSign || ".").replace(/\B(?=(\d{3})+(?!\d))/g, thousandSign || ",");
|
|
2134
|
+
}
|
|
2135
|
+
return parsedX.toString().replace(/\B(?=(\d{3})+(?!\d))/g, thousandSign || ",");
|
|
2136
|
+
};
|
|
2137
|
+
function moveItem(items, movedItem, fromIndex, toIndex) {
|
|
2138
|
+
return items.reduce((prev, item, itemIndex) => {
|
|
2139
|
+
if (itemIndex === fromIndex) {
|
|
2140
|
+
return prev;
|
|
2141
|
+
}
|
|
2142
|
+
if (itemIndex === toIndex) {
|
|
2143
|
+
if (fromIndex < toIndex) {
|
|
2144
|
+
return [...prev, item, movedItem];
|
|
2145
|
+
} else {
|
|
2146
|
+
return [...prev, movedItem, item];
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
return [...prev, item];
|
|
2150
|
+
}, []);
|
|
2151
|
+
}
|
|
2152
|
+
function Dragger({
|
|
2153
|
+
type,
|
|
2154
|
+
parentClassName,
|
|
2155
|
+
header,
|
|
2156
|
+
records,
|
|
2157
|
+
timestamp,
|
|
2158
|
+
disabled,
|
|
2159
|
+
children,
|
|
2160
|
+
onChange
|
|
2161
|
+
}) {
|
|
2162
|
+
const [, setCurrentState] = useState(0);
|
|
2163
|
+
const [values, dispatch] = useReducer(reducer, {
|
|
2164
|
+
items: null,
|
|
2165
|
+
displayItems: null,
|
|
2166
|
+
dragging: false,
|
|
2167
|
+
dragItem: null,
|
|
2168
|
+
dragFrom: null,
|
|
2169
|
+
dragTo: null,
|
|
2170
|
+
updated: false,
|
|
2171
|
+
timer: null
|
|
2172
|
+
});
|
|
2173
|
+
const { items, displayItems, dragging, dragItem, dragFrom, dragTo, updated } = values || {};
|
|
2174
|
+
const grandChildren = children && children.props.children;
|
|
2175
|
+
const isValid = !disabled && !!records && !!children && !!grandChildren && grandChildren.length > 0;
|
|
2176
|
+
useEffect(() => {
|
|
2177
|
+
dispatch({
|
|
2178
|
+
items: grandChildren,
|
|
2179
|
+
updated: false,
|
|
2180
|
+
render: true
|
|
2181
|
+
});
|
|
2182
|
+
}, [timestamp, grandChildren]);
|
|
2183
|
+
useEffect(() => {
|
|
2184
|
+
if (!updated) {
|
|
2185
|
+
if (grandChildren && grandChildren.length > 0) {
|
|
2186
|
+
dispatch({
|
|
2187
|
+
items: grandChildren,
|
|
2188
|
+
displayItems: grandChildren,
|
|
2189
|
+
updated: false,
|
|
2190
|
+
render: true
|
|
2191
|
+
});
|
|
2192
|
+
} else {
|
|
2193
|
+
dispatch({
|
|
2194
|
+
items: [],
|
|
2195
|
+
displayItems: [],
|
|
2196
|
+
updated: false,
|
|
2197
|
+
render: true
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
}, [grandChildren, updated]);
|
|
2202
|
+
function reducer(state, action) {
|
|
2203
|
+
const updatedValues = { ...state };
|
|
2204
|
+
if ("items" in action) {
|
|
2205
|
+
updatedValues.items = action.items;
|
|
2206
|
+
}
|
|
2207
|
+
if ("displayItems" in action) {
|
|
2208
|
+
updatedValues.displayItems = action.displayItems;
|
|
2209
|
+
}
|
|
2210
|
+
if ("dragging" in action) {
|
|
2211
|
+
updatedValues.dragging = action.dragging;
|
|
2212
|
+
}
|
|
2213
|
+
if ("dragItem" in action) {
|
|
2214
|
+
updatedValues.dragItem = action.dragItem;
|
|
2215
|
+
}
|
|
2216
|
+
if ("dragFrom" in action) {
|
|
2217
|
+
updatedValues.dragFrom = action.dragFrom;
|
|
2218
|
+
}
|
|
2219
|
+
if ("dragTo" in action) {
|
|
2220
|
+
updatedValues.dragTo = action.dragTo;
|
|
2221
|
+
}
|
|
2222
|
+
if ("updated" in action) {
|
|
2223
|
+
updatedValues.updated = action.updated;
|
|
2224
|
+
}
|
|
2225
|
+
if ("timer" in action) {
|
|
2226
|
+
updatedValues.timer = action.timer;
|
|
2227
|
+
}
|
|
2228
|
+
if ("cursorX" in action) {
|
|
2229
|
+
updatedValues.cursorX = action.cursorX;
|
|
2230
|
+
}
|
|
2231
|
+
if ("cursorY" in action) {
|
|
2232
|
+
updatedValues.cursorY = action.cursorY;
|
|
2233
|
+
}
|
|
2234
|
+
if (action.render) {
|
|
2235
|
+
setCurrentState((prev) => 1 - prev);
|
|
2236
|
+
}
|
|
2237
|
+
return updatedValues;
|
|
2238
|
+
}
|
|
2239
|
+
if (!isValid) {
|
|
2240
|
+
if (type === "table") {
|
|
2241
|
+
return /* @__PURE__ */ jsxs("table", { className: parentClassName, children: [
|
|
2242
|
+
header,
|
|
2243
|
+
children
|
|
2244
|
+
] });
|
|
2245
|
+
}
|
|
2246
|
+
return children;
|
|
2247
|
+
}
|
|
2248
|
+
function handleDragStart(e, item, index) {
|
|
2249
|
+
e.stopPropagation();
|
|
2250
|
+
dispatch({
|
|
2251
|
+
dragging: true,
|
|
2252
|
+
dragItem: item,
|
|
2253
|
+
dragFrom: index,
|
|
2254
|
+
render: true
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
function handleDragEnd() {
|
|
2258
|
+
if (dragFrom !== dragTo) {
|
|
2259
|
+
const updatedItems = moveItem(items || [], dragItem, dragFrom, dragTo);
|
|
2260
|
+
dispatch({
|
|
2261
|
+
items: updatedItems,
|
|
2262
|
+
displayItems: updatedItems,
|
|
2263
|
+
dragging: false,
|
|
2264
|
+
dragItem: null,
|
|
2265
|
+
dragFrom: null,
|
|
2266
|
+
dragTo: null,
|
|
2267
|
+
updated: true,
|
|
2268
|
+
render: true
|
|
2269
|
+
});
|
|
2270
|
+
if (typeof onChange === "function") {
|
|
2271
|
+
const updated2 = !!updatedItems && updatedItems.map((updatedItem) => records.find((record) => record.id === updatedItem.key));
|
|
2272
|
+
onChange(updated2);
|
|
2273
|
+
}
|
|
2274
|
+
} else {
|
|
2275
|
+
dispatch({
|
|
2276
|
+
items,
|
|
2277
|
+
displayItems,
|
|
2278
|
+
dragging: false,
|
|
2279
|
+
dragItem: null,
|
|
2280
|
+
dragFrom: null,
|
|
2281
|
+
dragTo: null,
|
|
2282
|
+
render: true
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
function handleDragOver(ev, index) {
|
|
2287
|
+
ev.preventDefault();
|
|
2288
|
+
if (dragging && dragTo !== index) {
|
|
2289
|
+
if (dragFrom !== index) {
|
|
2290
|
+
const updatedItems = moveItem(items || [], dragItem, dragFrom, index);
|
|
2291
|
+
dispatch({
|
|
2292
|
+
displayItems: updatedItems,
|
|
2293
|
+
dragTo: index,
|
|
2294
|
+
render: dragTo !== index
|
|
2295
|
+
});
|
|
2296
|
+
} else {
|
|
2297
|
+
dispatch({
|
|
2298
|
+
displayItems: items,
|
|
2299
|
+
dragTo: index,
|
|
2300
|
+
render: dragTo !== index
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
function handleContextMenu(e) {
|
|
2306
|
+
e.preventDefault();
|
|
2307
|
+
}
|
|
2308
|
+
function handleTouchStart(e) {
|
|
2309
|
+
const touch = e.touches[0] || e.changedTouches[0];
|
|
2310
|
+
const { clientX, clientY } = touch;
|
|
2311
|
+
const timer = setTimeout(() => handleLongTouchStart({ clientX, clientY }), 500);
|
|
2312
|
+
dispatch({
|
|
2313
|
+
timer,
|
|
2314
|
+
cursorX: clientX,
|
|
2315
|
+
cursorY: clientY,
|
|
2316
|
+
dragging: false
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
function handleLongTouchStart({ clientX, clientY }) {
|
|
2320
|
+
const difference = Math.abs(clientY - (values.cursorY || 0));
|
|
2321
|
+
if (difference > 40) {
|
|
2322
|
+
return false;
|
|
2323
|
+
}
|
|
2324
|
+
dispatch({ dragging: true });
|
|
2325
|
+
const cards = records;
|
|
2326
|
+
let elementInBoundary = null;
|
|
2327
|
+
let elementIndex = null;
|
|
2328
|
+
for (let i = 0; i < cards.length; i++) {
|
|
2329
|
+
const cardItem = cards[i];
|
|
2330
|
+
if (!!cardItem) {
|
|
2331
|
+
const element = document.getElementById(cardItem.id);
|
|
2332
|
+
if (element) {
|
|
2333
|
+
const { top, right, bottom, left } = element.getBoundingClientRect();
|
|
2334
|
+
if (left <= clientX && clientX <= right && top <= clientY && clientY <= bottom) {
|
|
2335
|
+
elementInBoundary = element;
|
|
2336
|
+
elementIndex = i;
|
|
2337
|
+
break;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
if (elementInBoundary && elementIndex !== null && items) {
|
|
2343
|
+
dispatch({
|
|
2344
|
+
dragging: true,
|
|
2345
|
+
dragItem: items[elementIndex],
|
|
2346
|
+
dragFrom: elementIndex,
|
|
2347
|
+
render: true
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
function handleTouchMove(e) {
|
|
2352
|
+
const touch = e.touches[0] || e.changedTouches[0];
|
|
2353
|
+
const { clientX, clientY } = touch;
|
|
2354
|
+
dispatch({
|
|
2355
|
+
cursorX: clientX,
|
|
2356
|
+
cursorY: clientY
|
|
2357
|
+
});
|
|
2358
|
+
if (values.dragging && items) {
|
|
2359
|
+
const cards = records;
|
|
2360
|
+
let targetIndex = null;
|
|
2361
|
+
for (let i = 0; i < cards.length; i++) {
|
|
2362
|
+
const cardItem = cards[i];
|
|
2363
|
+
if (!!cardItem) {
|
|
2364
|
+
const element = document.getElementById(cardItem.id);
|
|
2365
|
+
if (element) {
|
|
2366
|
+
const { top, right, bottom, left } = element.getBoundingClientRect();
|
|
2367
|
+
if (left <= clientX && clientX <= right && top <= clientY && clientY <= bottom) {
|
|
2368
|
+
targetIndex = i;
|
|
2369
|
+
break;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
if (targetIndex !== null && values.dragFrom !== targetIndex) {
|
|
2375
|
+
const updatedItems = moveItem(items, values.dragItem, values.dragFrom, targetIndex);
|
|
2376
|
+
dispatch({
|
|
2377
|
+
displayItems: updatedItems,
|
|
2378
|
+
dragTo: targetIndex,
|
|
2379
|
+
render: dragTo !== targetIndex
|
|
2380
|
+
});
|
|
2381
|
+
} else {
|
|
2382
|
+
dispatch({
|
|
2383
|
+
displayItems: items,
|
|
2384
|
+
dragTo: values.dragFrom,
|
|
2385
|
+
render: dragTo !== values.dragFrom
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
function handleTouchEnd() {
|
|
2391
|
+
if (dragFrom !== dragTo) {
|
|
2392
|
+
const updatedItems = moveItem(values.items || [], values.dragItem, values.dragFrom, values.dragTo);
|
|
2393
|
+
dispatch({
|
|
2394
|
+
items: updatedItems,
|
|
2395
|
+
displayItems: updatedItems,
|
|
2396
|
+
dragging: false,
|
|
2397
|
+
dragItem: null,
|
|
2398
|
+
dragFrom: null,
|
|
2399
|
+
dragTo: null,
|
|
2400
|
+
updated: true,
|
|
2401
|
+
render: true
|
|
2402
|
+
});
|
|
2403
|
+
if (typeof onChange === "function") {
|
|
2404
|
+
const updated2 = !!updatedItems && updatedItems.map((updatedItem) => records.find((record) => record.id === updatedItem.key));
|
|
2405
|
+
onChange(updated2);
|
|
2406
|
+
}
|
|
2407
|
+
} else {
|
|
2408
|
+
dispatch({
|
|
2409
|
+
items,
|
|
2410
|
+
displayItems,
|
|
2411
|
+
dragging: false,
|
|
2412
|
+
dragItem: null,
|
|
2413
|
+
dragFrom: null,
|
|
2414
|
+
dragTo: null,
|
|
2415
|
+
render: true
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
if (values.timer) {
|
|
2419
|
+
clearTimeout(values.timer);
|
|
2420
|
+
}
|
|
2421
|
+
dispatch({ dragging: false });
|
|
2422
|
+
}
|
|
2423
|
+
const derivedItems = !!items && React15.cloneElement(children, {
|
|
2424
|
+
children: items.map((grandChild, index) => {
|
|
2425
|
+
return React15.cloneElement(grandChild, {
|
|
2426
|
+
id: (records[index] || {}).id,
|
|
2427
|
+
draggable: true,
|
|
2428
|
+
className: classNames({
|
|
2429
|
+
...classNameObject(grandChild.props.className),
|
|
2430
|
+
"opacity-0": !!dragging && dragTo === index
|
|
2431
|
+
}),
|
|
2432
|
+
onDragStart: (e) => handleDragStart(e, grandChild, index),
|
|
2433
|
+
onDragEnd: () => handleDragEnd(),
|
|
2434
|
+
onDragOver: (ev) => handleDragOver(ev, index),
|
|
2435
|
+
onTouchStart: (e) => handleTouchStart(e),
|
|
2436
|
+
onTouchMove: (e) => handleTouchMove(e),
|
|
2437
|
+
onTouchEnd: () => handleTouchEnd(),
|
|
2438
|
+
onContextMenu: (e) => handleContextMenu(e)
|
|
2439
|
+
});
|
|
2440
|
+
})
|
|
2441
|
+
});
|
|
2442
|
+
const derivedDisplayItems = !!displayItems && React15.cloneElement(children, {
|
|
2443
|
+
children: displayItems.map((grandChild, index) => {
|
|
2444
|
+
return React15.cloneElement(grandChild, {
|
|
2445
|
+
draggable: true,
|
|
2446
|
+
className: classNames({
|
|
2447
|
+
...classNameObject(grandChild.props.className),
|
|
2448
|
+
"opacity-25 sm:opacity-0": !!dragging && dragTo === index
|
|
2449
|
+
})
|
|
2450
|
+
});
|
|
2451
|
+
})
|
|
2452
|
+
});
|
|
2453
|
+
if (type === "table") {
|
|
2454
|
+
return /* @__PURE__ */ jsxs(
|
|
2455
|
+
"table",
|
|
2456
|
+
{
|
|
2457
|
+
className: classNames({
|
|
2458
|
+
"relative": true,
|
|
2459
|
+
...classNameObject(parentClassName)
|
|
2460
|
+
}),
|
|
2461
|
+
children: [
|
|
2462
|
+
header,
|
|
2463
|
+
derivedItems,
|
|
2464
|
+
/* @__PURE__ */ jsx(
|
|
2465
|
+
"tbody",
|
|
2466
|
+
{
|
|
2467
|
+
className: classNames({
|
|
2468
|
+
"absolute top-10 left-0 right-0 z-20 pointer-events-none": true,
|
|
2469
|
+
"hidden": !dragging
|
|
2470
|
+
}),
|
|
2471
|
+
children: derivedDisplayItems
|
|
2472
|
+
}
|
|
2473
|
+
)
|
|
2474
|
+
]
|
|
2475
|
+
}
|
|
2476
|
+
);
|
|
2477
|
+
}
|
|
2478
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
2479
|
+
derivedItems,
|
|
2480
|
+
/* @__PURE__ */ jsx(
|
|
2481
|
+
"div",
|
|
2482
|
+
{
|
|
2483
|
+
className: classNames({
|
|
2484
|
+
"absolute top-0 left-0 right-0 z-20 pointer-events-none bg-white dark:bg-gray-900": true,
|
|
2485
|
+
"hidden": !dragging
|
|
2486
|
+
}),
|
|
2487
|
+
children: derivedDisplayItems
|
|
2488
|
+
}
|
|
2489
|
+
)
|
|
2490
|
+
] });
|
|
2491
|
+
}
|
|
2492
|
+
function ExcelTable({
|
|
2493
|
+
columns = [],
|
|
2494
|
+
data = [],
|
|
2495
|
+
onChange,
|
|
2496
|
+
onRowAdd,
|
|
2497
|
+
onRowDelete,
|
|
2498
|
+
placeholder,
|
|
2499
|
+
isAddRowVisible = true,
|
|
2500
|
+
addRowLabel = "+ Add Option"
|
|
2501
|
+
}) {
|
|
2502
|
+
const [editingCell, setEditingCell] = useState(null);
|
|
2503
|
+
useEffect(() => {
|
|
2504
|
+
setTimeout(() => {
|
|
2505
|
+
const textareas = document.querySelectorAll(".excel-table-textarea");
|
|
2506
|
+
textareas.forEach((ta) => {
|
|
2507
|
+
ta.style.height = "auto";
|
|
2508
|
+
ta.style.height = ta.scrollHeight + "px";
|
|
2509
|
+
});
|
|
2510
|
+
}, 0);
|
|
2511
|
+
}, [data]);
|
|
2512
|
+
const handleCellNavigation = (e, currentRow, currentCol) => {
|
|
2513
|
+
const isEditing = editingCell?.row === currentRow && editingCell?.col === currentCol;
|
|
2514
|
+
const totalRows = data.length;
|
|
2515
|
+
const totalCols = columns.length + 1;
|
|
2516
|
+
const addRowIndex = totalRows;
|
|
2517
|
+
let nextRow = currentRow;
|
|
2518
|
+
let nextCol = currentCol;
|
|
2519
|
+
const isAddRow = currentRow === addRowIndex;
|
|
2520
|
+
if (isEditing) {
|
|
2521
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
2522
|
+
setEditingCell(null);
|
|
2523
|
+
if (currentRow < totalRows - 1) nextRow = currentRow + 1;
|
|
2524
|
+
else if (currentRow === totalRows - 1) nextRow = addRowIndex;
|
|
2525
|
+
} else {
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
} else {
|
|
2529
|
+
if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key)) {
|
|
2530
|
+
e.preventDefault();
|
|
2531
|
+
if (e.key === "ArrowUp") {
|
|
2532
|
+
if (isAddRow) nextRow = totalRows - 1;
|
|
2533
|
+
else nextRow = Math.max(0, currentRow - 1);
|
|
2534
|
+
}
|
|
2535
|
+
if (e.key === "ArrowDown") {
|
|
2536
|
+
if (currentRow < totalRows - 1) nextRow = currentRow + 1;
|
|
2537
|
+
else if (currentRow === totalRows - 1) nextRow = addRowIndex;
|
|
2538
|
+
}
|
|
2539
|
+
if (e.key === "ArrowLeft") nextCol = Math.max(0, currentCol - 1);
|
|
2540
|
+
if (e.key === "ArrowRight") nextCol = Math.min(totalCols - 1, currentCol + 1);
|
|
2541
|
+
} else if (e.key === "Enter") {
|
|
2542
|
+
e.preventDefault();
|
|
2543
|
+
if (isAddRow) {
|
|
2544
|
+
onRowAdd && onRowAdd();
|
|
2545
|
+
setTimeout(() => {
|
|
2546
|
+
const target = document.querySelector(`[data-row="${totalRows}"][data-col="0"]`);
|
|
2547
|
+
if (target) {
|
|
2548
|
+
target.focus();
|
|
2549
|
+
target.click();
|
|
2550
|
+
}
|
|
2551
|
+
}, 0);
|
|
2552
|
+
return;
|
|
2553
|
+
} else if (currentCol < columns.length) {
|
|
2554
|
+
setEditingCell({ row: currentRow, col: currentCol });
|
|
2555
|
+
} else {
|
|
2556
|
+
onRowDelete && onRowDelete(currentRow);
|
|
2557
|
+
setTimeout(() => {
|
|
2558
|
+
const targetRow = currentRow < data.length - 1 ? currentRow : Math.max(0, currentRow - 1);
|
|
2559
|
+
const target = document.querySelector(`[data-row="${targetRow}"][data-col="${columns.length}"]`);
|
|
2560
|
+
if (target) target.focus();
|
|
2561
|
+
else {
|
|
2562
|
+
const addBtn = document.getElementById("add-option-btn");
|
|
2563
|
+
if (addBtn) addBtn.focus();
|
|
2564
|
+
}
|
|
2565
|
+
}, 0);
|
|
2566
|
+
return;
|
|
2567
|
+
}
|
|
2568
|
+
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && !isAddRow && currentCol < columns.length) {
|
|
2569
|
+
setEditingCell({ row: currentRow, col: currentCol });
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
if (nextRow !== currentRow || nextCol !== currentCol) {
|
|
2574
|
+
if (nextRow === addRowIndex) {
|
|
2575
|
+
const target = document.getElementById("add-option-btn");
|
|
2576
|
+
if (target) target.focus();
|
|
2577
|
+
} else {
|
|
2578
|
+
const target = document.querySelector(`[data-row="${nextRow}"][data-col="${nextCol}"]`);
|
|
2579
|
+
if (target) {
|
|
2580
|
+
target.focus();
|
|
2581
|
+
if (target.tagName === "INPUT" && target.type !== "checkbox" || target.tagName === "TEXTAREA") {
|
|
2582
|
+
target.select();
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
};
|
|
2588
|
+
const handleFocus = (e, row, col) => {
|
|
2589
|
+
if (editingCell?.row !== row || editingCell?.col !== col) {
|
|
2590
|
+
setEditingCell(null);
|
|
2591
|
+
e.target.select();
|
|
2592
|
+
}
|
|
2593
|
+
};
|
|
2594
|
+
const handleChange = (rowIdx, colId, val) => {
|
|
2595
|
+
const newData = [...data];
|
|
2596
|
+
newData[rowIdx] = { ...newData[rowIdx], [colId]: val };
|
|
2597
|
+
onChange && onChange(newData);
|
|
2598
|
+
};
|
|
2599
|
+
const handlePaste = (e, startRow, startCol) => {
|
|
2600
|
+
e.preventDefault();
|
|
2601
|
+
const clipboardData = e.clipboardData.getData("text/plain");
|
|
2602
|
+
const rows = clipboardData.split(/\r\n|\n|\r/).filter((row) => row.trim() !== "");
|
|
2603
|
+
let newData = [...data];
|
|
2604
|
+
rows.forEach((row, rIdx) => {
|
|
2605
|
+
const targetRowIdx = startRow + rIdx;
|
|
2606
|
+
const cells = row.split(" ");
|
|
2607
|
+
if (!newData[targetRowIdx]) {
|
|
2608
|
+
newData[targetRowIdx] = {};
|
|
2609
|
+
}
|
|
2610
|
+
columns.forEach((col, cIdx) => {
|
|
2611
|
+
const colIndexInPaste = cIdx - startCol;
|
|
2612
|
+
if (colIndexInPaste >= 0 && cells[colIndexInPaste] !== void 0) {
|
|
2613
|
+
const val = cells[colIndexInPaste];
|
|
2614
|
+
newData[targetRowIdx] = { ...newData[targetRowIdx], [col.id]: val };
|
|
2615
|
+
}
|
|
2616
|
+
});
|
|
2617
|
+
});
|
|
2618
|
+
onChange && onChange(newData);
|
|
2619
|
+
};
|
|
2620
|
+
return /* @__PURE__ */ jsx("div", { className: "border border-gray-200 dark:border-charcoal-600 rounded-sm overflow-hidden", children: /* @__PURE__ */ jsxs("table", { className: "w-full border-collapse bg-white dark:bg-charcoal-900", children: [
|
|
2621
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
2622
|
+
columns.map((col, idx) => /* @__PURE__ */ jsx(
|
|
2623
|
+
"th",
|
|
2624
|
+
{
|
|
2625
|
+
className: classNames({
|
|
2626
|
+
"border-b border-r border-gray-200 dark:border-charcoal-600 bg-gray-50 dark:bg-charcoal-800 px-3 py-2 text-xs font-semibold text-gray-500": true,
|
|
2627
|
+
"w-auto": !col.width,
|
|
2628
|
+
[col.width || ""]: !!col.width,
|
|
2629
|
+
"text-left": !col.align,
|
|
2630
|
+
"text-center": col.align === "center",
|
|
2631
|
+
"text-right": col.align === "right"
|
|
2632
|
+
}),
|
|
2633
|
+
children: col.label
|
|
2634
|
+
},
|
|
2635
|
+
col.id || idx
|
|
2636
|
+
)),
|
|
2637
|
+
/* @__PURE__ */ jsx("th", { className: "border-b border-gray-200 dark:border-charcoal-600 bg-gray-50 dark:bg-charcoal-800 w-8" })
|
|
2638
|
+
] }) }),
|
|
2639
|
+
/* @__PURE__ */ jsxs("tbody", { children: [
|
|
2640
|
+
data.map((row, rowIdx) => /* @__PURE__ */ jsxs("tr", { className: "group", children: [
|
|
2641
|
+
columns.map((col, colIdx) => /* @__PURE__ */ jsx(
|
|
2642
|
+
"td",
|
|
2643
|
+
{
|
|
2644
|
+
className: "border-b border-r border-gray-200 dark:border-charcoal-600 p-0 relative align-top h-auto",
|
|
2645
|
+
children: col.type === "textarea" ? /* @__PURE__ */ jsx(
|
|
2646
|
+
"textarea",
|
|
2647
|
+
{
|
|
2648
|
+
rows: 1,
|
|
2649
|
+
value: row[col.id] || "",
|
|
2650
|
+
onChange: (e) => {
|
|
2651
|
+
handleChange(rowIdx, col.id, e.target.value);
|
|
2652
|
+
e.target.style.height = "auto";
|
|
2653
|
+
e.target.style.height = e.target.scrollHeight + "px";
|
|
2654
|
+
},
|
|
2655
|
+
onFocus: (e) => handleFocus(e, rowIdx, colIdx),
|
|
2656
|
+
onKeyDown: (e) => handleCellNavigation(e, rowIdx, colIdx),
|
|
2657
|
+
onPaste: (e) => handlePaste(e, rowIdx, colIdx),
|
|
2658
|
+
"data-row": rowIdx,
|
|
2659
|
+
"data-col": colIdx,
|
|
2660
|
+
placeholder: typeof placeholder === "function" ? placeholder(rowIdx) : placeholder,
|
|
2661
|
+
className: "excel-table-textarea w-full min-h-[38px] px-3 py-2 border-none focus:ring-2 focus:ring-primary-500 focus:ring-inset bg-transparent outline-none text-sm text-gray-900 dark:text-white placeholder-gray-400 resize-none overflow-hidden leading-normal block",
|
|
2662
|
+
style: { height: "auto" }
|
|
2663
|
+
}
|
|
2664
|
+
) : col.type === "checkbox" ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-[38px]", children: /* @__PURE__ */ jsx(
|
|
2665
|
+
"input",
|
|
2666
|
+
{
|
|
2667
|
+
type: "checkbox",
|
|
2668
|
+
checked: !!row[col.id],
|
|
2669
|
+
onChange: (e) => handleChange(rowIdx, col.id, e.target.checked),
|
|
2670
|
+
onKeyDown: (e) => handleCellNavigation(e, rowIdx, colIdx),
|
|
2671
|
+
"data-row": rowIdx,
|
|
2672
|
+
"data-col": colIdx,
|
|
2673
|
+
className: "w-5 h-5 cursor-pointer accent-primary-500"
|
|
2674
|
+
}
|
|
2675
|
+
) }) : /* @__PURE__ */ jsx(
|
|
2676
|
+
"input",
|
|
2677
|
+
{
|
|
2678
|
+
type: col.type === "number" ? "number" : "text",
|
|
2679
|
+
value: row[col.id] || "",
|
|
2680
|
+
onChange: (e) => handleChange(rowIdx, col.id, e.target.value),
|
|
2681
|
+
onFocus: (e) => handleFocus(e, rowIdx, colIdx),
|
|
2682
|
+
onKeyDown: (e) => handleCellNavigation(e, rowIdx, colIdx),
|
|
2683
|
+
onPaste: (e) => handlePaste(e, rowIdx, colIdx),
|
|
2684
|
+
"data-row": rowIdx,
|
|
2685
|
+
"data-col": colIdx,
|
|
2686
|
+
className: classNames({
|
|
2687
|
+
"w-full h-full min-h-[38px] px-3 py-1 border-none focus:ring-2 focus:ring-primary-500 focus:ring-inset bg-transparent outline-none text-sm text-gray-900 dark:text-white": true,
|
|
2688
|
+
"text-left": col.align !== "center" && col.align !== "right",
|
|
2689
|
+
"text-center": col.align === "center",
|
|
2690
|
+
"text-right": col.align === "right"
|
|
2691
|
+
}),
|
|
2692
|
+
placeholder: col.type === "number" ? "0" : ""
|
|
2693
|
+
}
|
|
2694
|
+
)
|
|
2695
|
+
},
|
|
2696
|
+
col.id || colIdx
|
|
2697
|
+
)),
|
|
2698
|
+
/* @__PURE__ */ jsx("td", { className: "border-b border-gray-200 dark:border-charcoal-600 p-0 text-center align-top h-auto", children: /* @__PURE__ */ jsx(
|
|
2699
|
+
"div",
|
|
2700
|
+
{
|
|
2701
|
+
onClick: () => onRowDelete && onRowDelete(rowIdx),
|
|
2702
|
+
onFocus: () => setEditingCell(null),
|
|
2703
|
+
onKeyDown: (e) => handleCellNavigation(e, rowIdx, columns.length),
|
|
2704
|
+
"data-row": rowIdx,
|
|
2705
|
+
"data-col": columns.length,
|
|
2706
|
+
tabIndex: 0,
|
|
2707
|
+
className: "cursor-pointer text-gray-300 hover:text-red-500 w-full h-[38px] flex items-center justify-center transition-colors focus:ring-2 focus:ring-inset focus:ring-primary-500 outline-none",
|
|
2708
|
+
children: "\xD7"
|
|
2709
|
+
}
|
|
2710
|
+
) })
|
|
2711
|
+
] }, rowIdx)),
|
|
2712
|
+
isAddRowVisible && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columns.length + 1, className: "p-0", children: /* @__PURE__ */ jsx(
|
|
2713
|
+
"div",
|
|
2714
|
+
{
|
|
2715
|
+
id: "add-option-btn",
|
|
2716
|
+
onClick: onRowAdd,
|
|
2717
|
+
onKeyDown: (e) => handleCellNavigation(e, data.length, 0),
|
|
2718
|
+
tabIndex: 0,
|
|
2719
|
+
className: "w-full cursor-pointer text-left px-3 py-2 text-gray-400 text-xs font-medium hover:text-primary-500 hover:bg-gray-50 dark:hover:bg-charcoal-800 transition-colors focus:ring-2 focus:ring-inset focus:ring-primary-500 outline-none",
|
|
2720
|
+
children: addRowLabel
|
|
2721
|
+
}
|
|
2722
|
+
) }) })
|
|
2723
|
+
] })
|
|
2724
|
+
] }) });
|
|
2725
|
+
}
|
|
2726
|
+
function Coverflow({ images = [], onClose }) {
|
|
2727
|
+
const scrollContainerRef = useRef(null);
|
|
2728
|
+
const thumbnailContainerRef = useRef(null);
|
|
2729
|
+
const [visualIndex, setVisualIndex] = useState(0);
|
|
2730
|
+
const isJumpingRef = useRef(false);
|
|
2731
|
+
const wheelLockRef = useRef(false);
|
|
2732
|
+
const wheelTimeoutRef = useRef(null);
|
|
2733
|
+
const [isReady, setIsReady] = useState(false);
|
|
2734
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
2735
|
+
useEffect(() => {
|
|
2736
|
+
setIsMounted(true);
|
|
2737
|
+
}, []);
|
|
2738
|
+
const count = images.length;
|
|
2739
|
+
const hasMultiple = count > 1;
|
|
2740
|
+
const extendedImages = hasMultiple ? [images[count - 1], ...images, images[0]] : images;
|
|
2741
|
+
useEffect(() => {
|
|
2742
|
+
if (hasMultiple && scrollContainerRef.current) {
|
|
2743
|
+
const container = scrollContainerRef.current;
|
|
2744
|
+
const width = container.offsetWidth;
|
|
2745
|
+
container.scrollLeft = width;
|
|
2746
|
+
setVisualIndex(1);
|
|
2747
|
+
requestAnimationFrame(() => setIsReady(true));
|
|
2748
|
+
} else {
|
|
2749
|
+
setIsReady(true);
|
|
2750
|
+
}
|
|
2751
|
+
}, [hasMultiple]);
|
|
2752
|
+
useEffect(() => {
|
|
2753
|
+
if (hasMultiple && thumbnailContainerRef.current) {
|
|
2754
|
+
const thumbContainer = thumbnailContainerRef.current;
|
|
2755
|
+
const thumbNode = thumbContainer.children[visualIndex];
|
|
2756
|
+
if (thumbNode) {
|
|
2757
|
+
thumbNode.scrollIntoView({
|
|
2758
|
+
behavior: isJumpingRef.current ? "auto" : "smooth",
|
|
2759
|
+
block: "nearest",
|
|
2760
|
+
inline: "center"
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
}, [visualIndex, hasMultiple]);
|
|
2765
|
+
useEffect(() => {
|
|
2766
|
+
const container = scrollContainerRef.current;
|
|
2767
|
+
if (!container || !hasMultiple) return;
|
|
2768
|
+
const handleWheel = (e) => {
|
|
2769
|
+
if (e.ctrlKey) return;
|
|
2770
|
+
e.preventDefault();
|
|
2771
|
+
if (!wheelLockRef.current) {
|
|
2772
|
+
const threshold = 10;
|
|
2773
|
+
if (Math.abs(e.deltaX) > threshold || Math.abs(e.deltaY) > threshold) {
|
|
2774
|
+
const width = container.offsetWidth;
|
|
2775
|
+
const currentIndex = Math.round(container.scrollLeft / width);
|
|
2776
|
+
let targetIndex = currentIndex;
|
|
2777
|
+
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
|
|
2778
|
+
targetIndex = e.deltaX > 0 ? currentIndex + 1 : currentIndex - 1;
|
|
2779
|
+
} else {
|
|
2780
|
+
targetIndex = e.deltaY > 0 ? currentIndex + 1 : currentIndex - 1;
|
|
2781
|
+
}
|
|
2782
|
+
container.scrollTo({
|
|
2783
|
+
left: targetIndex * width,
|
|
2784
|
+
behavior: "smooth"
|
|
2785
|
+
});
|
|
2786
|
+
wheelLockRef.current = true;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
if (wheelTimeoutRef.current) clearTimeout(wheelTimeoutRef.current);
|
|
2790
|
+
wheelTimeoutRef.current = setTimeout(() => {
|
|
2791
|
+
wheelLockRef.current = false;
|
|
2792
|
+
}, 200);
|
|
2793
|
+
};
|
|
2794
|
+
container.addEventListener("wheel", handleWheel, { passive: false });
|
|
2795
|
+
return () => {
|
|
2796
|
+
container.removeEventListener("wheel", handleWheel);
|
|
2797
|
+
if (wheelTimeoutRef.current) clearTimeout(wheelTimeoutRef.current);
|
|
2798
|
+
};
|
|
2799
|
+
}, [hasMultiple]);
|
|
2800
|
+
const handleScroll = () => {
|
|
2801
|
+
if (!scrollContainerRef.current) return;
|
|
2802
|
+
const container = scrollContainerRef.current;
|
|
2803
|
+
const { scrollLeft, offsetWidth } = container;
|
|
2804
|
+
const scrollIndex = scrollLeft / offsetWidth;
|
|
2805
|
+
const roundedIndex = Math.round(scrollIndex);
|
|
2806
|
+
if (roundedIndex !== visualIndex) {
|
|
2807
|
+
setVisualIndex(roundedIndex);
|
|
2808
|
+
}
|
|
2809
|
+
if (isJumpingRef.current) return;
|
|
2810
|
+
if (scrollLeft <= 0) {
|
|
2811
|
+
performJump(count * offsetWidth);
|
|
2812
|
+
} else if (Math.abs(scrollLeft - (count + 1) * offsetWidth) < 2) {
|
|
2813
|
+
performJump(offsetWidth);
|
|
2814
|
+
}
|
|
2815
|
+
};
|
|
2816
|
+
const performJump = (targetLeft) => {
|
|
2817
|
+
if (!scrollContainerRef.current) return;
|
|
2818
|
+
isJumpingRef.current = true;
|
|
2819
|
+
const container = scrollContainerRef.current;
|
|
2820
|
+
container.style.scrollBehavior = "auto";
|
|
2821
|
+
container.scrollLeft = targetLeft;
|
|
2822
|
+
container.style.scrollBehavior = "";
|
|
2823
|
+
const newIndex = Math.round(targetLeft / container.offsetWidth);
|
|
2824
|
+
setVisualIndex(newIndex);
|
|
2825
|
+
if (thumbnailContainerRef.current) {
|
|
2826
|
+
const thumbContainer = thumbnailContainerRef.current;
|
|
2827
|
+
const thumbNode = thumbContainer.children[newIndex];
|
|
2828
|
+
if (thumbNode) {
|
|
2829
|
+
thumbNode.scrollIntoView({
|
|
2830
|
+
behavior: "auto",
|
|
2831
|
+
block: "nearest",
|
|
2832
|
+
inline: "center"
|
|
2833
|
+
});
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
setTimeout(() => {
|
|
2837
|
+
isJumpingRef.current = false;
|
|
2838
|
+
}, 50);
|
|
2839
|
+
};
|
|
2840
|
+
const scrollToIndex = (targetVisualIndex) => {
|
|
2841
|
+
if (!scrollContainerRef.current) return;
|
|
2842
|
+
const container = scrollContainerRef.current;
|
|
2843
|
+
const width = container.offsetWidth;
|
|
2844
|
+
container.scrollTo({
|
|
2845
|
+
left: width * targetVisualIndex,
|
|
2846
|
+
behavior: "smooth"
|
|
2847
|
+
});
|
|
2848
|
+
};
|
|
2849
|
+
const nextSlide = (e) => {
|
|
2850
|
+
if (!scrollContainerRef.current) return;
|
|
2851
|
+
const container = scrollContainerRef.current;
|
|
2852
|
+
const width = container.offsetWidth;
|
|
2853
|
+
const nextIndex = Math.round(container.scrollLeft / width) + 1;
|
|
2854
|
+
container.scrollTo({
|
|
2855
|
+
left: nextIndex * width,
|
|
2856
|
+
behavior: "smooth"
|
|
2857
|
+
});
|
|
2858
|
+
};
|
|
2859
|
+
const prevSlide = (e) => {
|
|
2860
|
+
if (!scrollContainerRef.current) return;
|
|
2861
|
+
const container = scrollContainerRef.current;
|
|
2862
|
+
const width = container.offsetWidth;
|
|
2863
|
+
const prevIndex = Math.round(container.scrollLeft / width) - 1;
|
|
2864
|
+
container.scrollTo({
|
|
2865
|
+
left: prevIndex * width,
|
|
2866
|
+
behavior: "smooth"
|
|
2867
|
+
});
|
|
2868
|
+
};
|
|
2869
|
+
useEffect(() => {
|
|
2870
|
+
const handleKeyDown = (e) => {
|
|
2871
|
+
if (e.key === "Escape") onClose && onClose();
|
|
2872
|
+
if (e.key === "ArrowLeft") prevSlide();
|
|
2873
|
+
if (e.key === "ArrowRight") nextSlide();
|
|
2874
|
+
};
|
|
2875
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
2876
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2877
|
+
}, [onClose]);
|
|
2878
|
+
if (!isMounted || !images || images.length === 0) return null;
|
|
2879
|
+
return createPortal(
|
|
2880
|
+
/* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-[1400] bg-black/95 flex flex-col justify-between animate-fadeIn transition-opacity duration-300", children: [
|
|
2881
|
+
/* @__PURE__ */ jsx(
|
|
2882
|
+
"div",
|
|
2883
|
+
{
|
|
2884
|
+
onClick: onClose,
|
|
2885
|
+
className: "absolute top-4 right-4 z-[110] p-2 bg-black/20 hover:bg-white/20 rounded-full text-white transition-colors cursor-pointer",
|
|
2886
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 2, stroke: "currentColor", className: "w-6 h-6", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) })
|
|
2887
|
+
}
|
|
2888
|
+
),
|
|
2889
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 relative flex items-center justify-center overflow-hidden w-full h-full", children: /* @__PURE__ */ jsx(
|
|
2890
|
+
"div",
|
|
2891
|
+
{
|
|
2892
|
+
ref: scrollContainerRef,
|
|
2893
|
+
onScroll: handleScroll,
|
|
2894
|
+
className: classNames({
|
|
2895
|
+
"w-full h-full flex overflow-x-auto snap-x snap-mandatory scrollbar-none": true,
|
|
2896
|
+
"opacity-0": hasMultiple && !isReady,
|
|
2897
|
+
"opacity-100": !hasMultiple || isReady
|
|
2898
|
+
}),
|
|
2899
|
+
children: extendedImages.map((img, index) => {
|
|
2900
|
+
const key = `${img.id || index}-${index}`;
|
|
2901
|
+
return /* @__PURE__ */ jsx(
|
|
2902
|
+
"div",
|
|
2903
|
+
{
|
|
2904
|
+
className: "w-full h-full flex-shrink-0 flex items-center justify-center snap-center relative p-4",
|
|
2905
|
+
children: /* @__PURE__ */ jsxs("div", { className: "relative w-full h-full max-w-4xl max-h-[75vh] flex items-center justify-center", children: [
|
|
2906
|
+
/* @__PURE__ */ jsx(
|
|
2907
|
+
"img",
|
|
2908
|
+
{
|
|
2909
|
+
src: img.imageUrl,
|
|
2910
|
+
alt: img.imageTitle || "Gallery Image",
|
|
2911
|
+
className: "max-w-full max-h-full object-contain drop-shadow-2xl"
|
|
2912
|
+
}
|
|
2913
|
+
),
|
|
2914
|
+
(img.imageTitle || img.imageDescription) && /* @__PURE__ */ jsxs("div", { className: "absolute bottom-0 left-0 right-0 p-3 bg-gradient-to-t from-black/90 via-black/50 to-transparent text-white text-center pointer-events-none", children: [
|
|
2915
|
+
img.imageTitle && /* @__PURE__ */ jsx(H3, { className: "!text-base mb-1", children: img.imageTitle }),
|
|
2916
|
+
img.imageDescription && /* @__PURE__ */ jsx("p", { className: "text-xs text-charcoal-200 max-w-2xl mx-auto", children: img.imageDescription })
|
|
2917
|
+
] })
|
|
2918
|
+
] })
|
|
2919
|
+
},
|
|
2920
|
+
key
|
|
2921
|
+
);
|
|
2922
|
+
})
|
|
2923
|
+
}
|
|
2924
|
+
) }),
|
|
2925
|
+
hasMultiple && /* @__PURE__ */ jsxs("div", { className: "w-full p-4 pb-8 bg-gradient-to-t from-black to-transparent flex items-center justify-center gap-4 z-50", children: [
|
|
2926
|
+
/* @__PURE__ */ jsx(
|
|
2927
|
+
"div",
|
|
2928
|
+
{
|
|
2929
|
+
onClick: () => prevSlide(),
|
|
2930
|
+
className: "p-2 rounded-full hover:bg-white/10 text-white transition-colors flex-shrink-0 cursor-pointer",
|
|
2931
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 2, stroke: "currentColor", className: "w-8 h-8", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15.75 19.5L8.25 12l7.5-7.5" }) })
|
|
2932
|
+
}
|
|
2933
|
+
),
|
|
2934
|
+
/* @__PURE__ */ jsx(
|
|
2935
|
+
"div",
|
|
2936
|
+
{
|
|
2937
|
+
ref: thumbnailContainerRef,
|
|
2938
|
+
className: "flex gap-2 overflow-x-auto no-scrollbar max-w-xl px-2 snap-x",
|
|
2939
|
+
children: extendedImages.map((img, idx) => /* @__PURE__ */ jsx(
|
|
2940
|
+
"div",
|
|
2941
|
+
{
|
|
2942
|
+
onClick: () => scrollToIndex(idx),
|
|
2943
|
+
className: classNames({
|
|
2944
|
+
"relative w-14 h-14 flex-shrink-0 rounded-md overflow-hidden border transition-all duration-300 snap-center cursor-pointer": true,
|
|
2945
|
+
"border-primary-500 opacity-100": visualIndex === idx,
|
|
2946
|
+
"border-transparent opacity-40 hover:opacity-80": visualIndex !== idx
|
|
2947
|
+
}),
|
|
2948
|
+
children: /* @__PURE__ */ jsx(
|
|
2949
|
+
"img",
|
|
2950
|
+
{
|
|
2951
|
+
src: img.imageUrl,
|
|
2952
|
+
alt: "Thumbnail",
|
|
2953
|
+
className: "w-full h-full object-cover transition-transform duration-300"
|
|
2954
|
+
}
|
|
2955
|
+
)
|
|
2956
|
+
},
|
|
2957
|
+
`${img.id || idx}-${idx}`
|
|
2958
|
+
))
|
|
2959
|
+
}
|
|
2960
|
+
),
|
|
2961
|
+
/* @__PURE__ */ jsx(
|
|
2962
|
+
"div",
|
|
2963
|
+
{
|
|
2964
|
+
onClick: () => nextSlide(),
|
|
2965
|
+
className: "p-2 rounded-full hover:bg-white/10 text-white transition-colors flex-shrink-0 cursor-pointer",
|
|
2966
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 2, stroke: "currentColor", className: "w-8 h-8", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M8.25 4.5l7.5 7.5-7.5 7.5" }) })
|
|
2967
|
+
}
|
|
2968
|
+
)
|
|
2969
|
+
] })
|
|
2970
|
+
] }),
|
|
2971
|
+
document.body
|
|
2972
|
+
);
|
|
2973
|
+
}
|
|
2974
|
+
function CurrencyDisplay({ loading, error, currency, amount, decimal = 2, opts }) {
|
|
2975
|
+
const { contentFull } = opts || {};
|
|
2976
|
+
return /* @__PURE__ */ jsxs(
|
|
2977
|
+
"div",
|
|
2978
|
+
{
|
|
2979
|
+
className: classNames({
|
|
2980
|
+
"flex space-x-2 justify-between items-center group": true,
|
|
2981
|
+
"w-full": !!contentFull,
|
|
2982
|
+
"-ml-1.5 text-red-500": amount < 0,
|
|
2983
|
+
"text-red-500": !!error,
|
|
2984
|
+
"animate-pulse bg-gray-100 text-transparent rounded-md": !!loading
|
|
2985
|
+
}),
|
|
2986
|
+
children: [
|
|
2987
|
+
/* @__PURE__ */ jsxs(
|
|
2988
|
+
"span",
|
|
2989
|
+
{
|
|
2990
|
+
className: classNames({
|
|
2991
|
+
"group-hover:text-inherit": true,
|
|
2992
|
+
"!text-transparent": !!loading,
|
|
2993
|
+
"text-red-200": amount < 0 || !!error,
|
|
2994
|
+
"text-gray-200": (!amount || amount >= 0) && !error
|
|
2995
|
+
}),
|
|
2996
|
+
children: [
|
|
2997
|
+
amount < 0 && "-",
|
|
2998
|
+
currency || "$"
|
|
2999
|
+
]
|
|
3000
|
+
}
|
|
3001
|
+
),
|
|
3002
|
+
/* @__PURE__ */ jsx("span", { children: amount ? numberFormatter(Math.abs(amount), decimal) : "-" })
|
|
3003
|
+
]
|
|
3004
|
+
}
|
|
3005
|
+
);
|
|
3006
|
+
}
|
|
3007
|
+
function DataTableRow({ index, selected, label, description, additionalDescription, data, opts }) {
|
|
3008
|
+
const { labelCenter, vertical, darkMode } = opts || {};
|
|
3009
|
+
return /* @__PURE__ */ jsxs(
|
|
3010
|
+
"tr",
|
|
3011
|
+
{
|
|
3012
|
+
className: classNames({
|
|
3013
|
+
"align-top group dark:even:bg-charcoal-800 dark:odd:bg-charcoal-700": true,
|
|
3014
|
+
"!bg-primary-500/30 dark:!bg-primary-500/10 !text-black dark:!text-primary-400": selected,
|
|
3015
|
+
"even:bg-cream-50 odd:bg-white": !darkMode,
|
|
3016
|
+
"even:bg-charcoal-800 odd:bg-charcoal-700": !!darkMode
|
|
3017
|
+
}),
|
|
3018
|
+
children: [
|
|
3019
|
+
/* @__PURE__ */ jsx(
|
|
3020
|
+
"td",
|
|
3021
|
+
{
|
|
3022
|
+
className: classNames({
|
|
3023
|
+
"py-1.5 px-2 sm:px-3 cursor-default whitespace-nowrap first:rounded-l-lg last:rounded-r-lg cursor-pointer": true,
|
|
3024
|
+
"text-center": !!labelCenter,
|
|
3025
|
+
"align-middle": vertical === "middle"
|
|
3026
|
+
}),
|
|
3027
|
+
children: label
|
|
3028
|
+
}
|
|
3029
|
+
),
|
|
3030
|
+
description && /* @__PURE__ */ jsxs("td", { className: "px-2 py-1.5 sm:px-3 min-w-64 cursor-default first:rounded-l-lg last:rounded-r-lg cursor-pointer", children: [
|
|
3031
|
+
description,
|
|
3032
|
+
additionalDescription && /* @__PURE__ */ jsx("p", { className: "uppercase opacity-50", children: additionalDescription })
|
|
3033
|
+
] }),
|
|
3034
|
+
data.map((dataItem, dataIndex) => /* @__PURE__ */ jsx(
|
|
3035
|
+
"td",
|
|
3036
|
+
{
|
|
3037
|
+
className: classNames({
|
|
3038
|
+
"text-center py-1.5 px-2 sm:px-3 cursor-default first:rounded-l-lg last:rounded-r-lg cursor-pointer": true,
|
|
3039
|
+
"!bg-primary-100 !text-primary-500 font-semibold": !!dataItem.threshold && dataItem.data[index] > dataItem.threshold,
|
|
3040
|
+
"!text-left": dataItem.align === "left",
|
|
3041
|
+
"align-middle": vertical === "middle"
|
|
3042
|
+
}),
|
|
3043
|
+
children: typeof dataItem.data[index] === "string" || React15.isValidElement(dataItem.data[index]) ? dataItem.data[index] : numberFormatter(dataItem.data[index], dataItem.decimal != null ? dataItem.decimal : 1)
|
|
3044
|
+
},
|
|
3045
|
+
`${dataIndex}-${index}`
|
|
3046
|
+
))
|
|
3047
|
+
]
|
|
3048
|
+
}
|
|
3049
|
+
);
|
|
3050
|
+
}
|
|
3051
|
+
function DataTable({
|
|
3052
|
+
headers,
|
|
3053
|
+
labels,
|
|
3054
|
+
selectedId,
|
|
3055
|
+
descriptions,
|
|
3056
|
+
additionalDescriptions,
|
|
3057
|
+
colors,
|
|
3058
|
+
data,
|
|
3059
|
+
total,
|
|
3060
|
+
opts
|
|
3061
|
+
}) {
|
|
3062
|
+
const { mobileView } = useResizeListener();
|
|
3063
|
+
const { ignoreTotal, showCurrency, labelTitle, labelCentered, vertical, darkMode } = opts || {};
|
|
3064
|
+
const [displayHeaders, setDisplayHeaders] = useState([]);
|
|
3065
|
+
useEffect(() => {
|
|
3066
|
+
setDisplayHeaders(headers);
|
|
3067
|
+
}, [headers]);
|
|
3068
|
+
return /* @__PURE__ */ jsxs(
|
|
3069
|
+
"table",
|
|
3070
|
+
{
|
|
3071
|
+
className: classNames({
|
|
3072
|
+
"w-full text-sm dark:text-charcoal-100 rounded-xl border-separate border-spacing-0": true,
|
|
3073
|
+
"text-charcoal-100": !!darkMode,
|
|
3074
|
+
"text-charcoal-500": !darkMode
|
|
3075
|
+
}),
|
|
3076
|
+
children: [
|
|
3077
|
+
/* @__PURE__ */ jsxs("thead", { children: [
|
|
3078
|
+
!displayHeaders && /* @__PURE__ */ jsxs("tr", { className: "font-semibold uppercase", children: [
|
|
3079
|
+
/* @__PURE__ */ jsx(
|
|
3080
|
+
"td",
|
|
3081
|
+
{
|
|
3082
|
+
className: classNames({
|
|
3083
|
+
"px-2 py-2.5 px-2 sm:px-3 whitespace-nowrap w-4": true,
|
|
3084
|
+
"text-center": !!labelCentered
|
|
3085
|
+
}),
|
|
3086
|
+
children: mobileView ? "#" : labelTitle || "Code"
|
|
3087
|
+
}
|
|
3088
|
+
),
|
|
3089
|
+
(descriptions || []).length > 0 && /* @__PURE__ */ jsx("td", { className: "py-2.5 px-2 sm:px-3 bg-gray-50", children: "Description" }),
|
|
3090
|
+
data.map((dataItem, dataIndex) => /* @__PURE__ */ jsx(
|
|
3091
|
+
"td",
|
|
3092
|
+
{
|
|
3093
|
+
className: classNames({
|
|
3094
|
+
"w-4 py-2.5 px-2 sm:px-3 whitespace-nowrap text-center": true,
|
|
3095
|
+
"bg-gray-50": !colors,
|
|
3096
|
+
"!text-left": dataItem.align === "left"
|
|
3097
|
+
}),
|
|
3098
|
+
style: colors && colors[dataIndex] ? {
|
|
3099
|
+
backgroundColor: `${colors[dataIndex]}`,
|
|
3100
|
+
color: bestTextColorForBg(colors[dataIndex])
|
|
3101
|
+
} : void 0,
|
|
3102
|
+
children: dataItem.label
|
|
3103
|
+
},
|
|
3104
|
+
dataItem.key || dataItem.label
|
|
3105
|
+
))
|
|
3106
|
+
] }),
|
|
3107
|
+
displayHeaders && /* @__PURE__ */ jsx("tr", { className: "text-xs font-semibold uppercase", children: displayHeaders })
|
|
3108
|
+
] }),
|
|
3109
|
+
/* @__PURE__ */ jsx("tbody", { children: (labels || []).map((label, index) => {
|
|
3110
|
+
const keyData = data[0]?.data || [];
|
|
3111
|
+
return /* @__PURE__ */ jsx(
|
|
3112
|
+
DataTableRow,
|
|
3113
|
+
{
|
|
3114
|
+
index,
|
|
3115
|
+
label,
|
|
3116
|
+
selected: selectedId === keyData[index]?.props?.recordId,
|
|
3117
|
+
description: descriptions && descriptions[index],
|
|
3118
|
+
additionalDescription: additionalDescriptions && additionalDescriptions[index],
|
|
3119
|
+
data,
|
|
3120
|
+
opts: {
|
|
3121
|
+
labelCenter: labelCentered,
|
|
3122
|
+
vertical,
|
|
3123
|
+
darkMode
|
|
3124
|
+
}
|
|
3125
|
+
},
|
|
3126
|
+
(keyData[index] || {}).key || index
|
|
3127
|
+
);
|
|
3128
|
+
}) }),
|
|
3129
|
+
!ignoreTotal && /* @__PURE__ */ jsx("tfoot", { children: /* @__PURE__ */ jsxs("tr", { className: "group", children: [
|
|
3130
|
+
/* @__PURE__ */ jsx(
|
|
3131
|
+
"td",
|
|
3132
|
+
{
|
|
3133
|
+
colSpan: (descriptions || []).length === 0 ? 1 : 2,
|
|
3134
|
+
className: classNames({
|
|
3135
|
+
"border-t dark:border-charcoal-500 py-2.5 px-2 sm:px-3 font-semibold uppercase": true,
|
|
3136
|
+
"border-charcoal-500": !!darkMode,
|
|
3137
|
+
"border-gray-100 bg-gray-50": !darkMode
|
|
3138
|
+
}),
|
|
3139
|
+
children: "Total"
|
|
3140
|
+
}
|
|
3141
|
+
),
|
|
3142
|
+
!total && data.map((dataItem, dataIndex) => {
|
|
3143
|
+
const sumVal = dataItem.data ? dataItem.data.reduce((a, b) => a + (Number(b) || 0), 0) : 0;
|
|
3144
|
+
return /* @__PURE__ */ jsx(
|
|
3145
|
+
"td",
|
|
3146
|
+
{
|
|
3147
|
+
className: classNames({
|
|
3148
|
+
"border-t dark:border-charcoal-500 py-2.5 px-2 sm:px-3 text-center font-semibold": true,
|
|
3149
|
+
"bg-gray-50": !colors && !darkMode,
|
|
3150
|
+
"border-gray-100": !darkMode,
|
|
3151
|
+
"border-charcoal-500": !!darkMode
|
|
3152
|
+
}),
|
|
3153
|
+
style: colors && colors[dataIndex] ? {
|
|
3154
|
+
backgroundColor: `${colors[dataIndex]}`,
|
|
3155
|
+
color: bestTextColorForBg(colors[dataIndex])
|
|
3156
|
+
} : void 0,
|
|
3157
|
+
children: typeof dataItem.total === "string" ? dataItem.total != null ? dataItem.total : sumVal : showCurrency ? /* @__PURE__ */ jsx(
|
|
3158
|
+
CurrencyDisplay,
|
|
3159
|
+
{
|
|
3160
|
+
amount: dataItem.total
|
|
3161
|
+
}
|
|
3162
|
+
) : numberFormatter(dataItem.total != null ? dataItem.total : sumVal, 1)
|
|
3163
|
+
},
|
|
3164
|
+
`${dataIndex}-total`
|
|
3165
|
+
);
|
|
3166
|
+
}),
|
|
3167
|
+
!!total && total.map((dataItem, dataIndex) => /* @__PURE__ */ jsx(
|
|
3168
|
+
"td",
|
|
3169
|
+
{
|
|
3170
|
+
className: classNames({
|
|
3171
|
+
"border-t dark:border-charcoal-500 py-2.5 px-2 sm:px-3 text-center font-semibold": true,
|
|
3172
|
+
"bg-gray-50": !colors && !darkMode,
|
|
3173
|
+
"border-gray-100": !darkMode,
|
|
3174
|
+
"border-charcoal-500": !!darkMode
|
|
3175
|
+
}),
|
|
3176
|
+
style: colors && colors[dataIndex] ? {
|
|
3177
|
+
backgroundColor: `${colors[dataIndex]}`,
|
|
3178
|
+
color: bestTextColorForBg(colors[dataIndex])
|
|
3179
|
+
} : void 0,
|
|
3180
|
+
children: typeof total[dataIndex] === "string" || React15.isValidElement(total[dataIndex]) ? total[dataIndex] : showCurrency ? /* @__PURE__ */ jsx(CurrencyDisplay, { amount: total[dataIndex] }) : numberFormatter(total[dataIndex], 1)
|
|
3181
|
+
},
|
|
3182
|
+
`${dataIndex}-total`
|
|
3183
|
+
))
|
|
3184
|
+
] }) })
|
|
3185
|
+
]
|
|
3186
|
+
}
|
|
3187
|
+
);
|
|
3188
|
+
}
|
|
3189
|
+
function NumberDisplay({ loading, amount, error, decimal = 0 }) {
|
|
3190
|
+
return /* @__PURE__ */ jsxs(
|
|
3191
|
+
"div",
|
|
3192
|
+
{
|
|
3193
|
+
className: classNames({
|
|
3194
|
+
"flex space-x-2 items-center justify-between group w-full": true,
|
|
3195
|
+
"text-red-500": amount < 0 || !!error,
|
|
3196
|
+
"animate-pulse bg-gray-100 text-transparent rounded-md": !!loading
|
|
3197
|
+
}),
|
|
3198
|
+
children: [
|
|
3199
|
+
/* @__PURE__ */ jsx(
|
|
3200
|
+
"span",
|
|
3201
|
+
{
|
|
3202
|
+
className: classNames({
|
|
3203
|
+
"group-hover:text-inherit": true,
|
|
3204
|
+
"!text-transparent": !!loading,
|
|
3205
|
+
"text-red-200": amount < 0 || !!error,
|
|
3206
|
+
"text-gray-200": amount >= 0 && !error
|
|
3207
|
+
}),
|
|
3208
|
+
children: amount < 0 && "-"
|
|
3209
|
+
}
|
|
3210
|
+
),
|
|
3211
|
+
/* @__PURE__ */ jsx("span", { className: "text-right", children: amount ? numberFormatter(Math.abs(amount), decimal) : "" })
|
|
3212
|
+
]
|
|
3213
|
+
}
|
|
3214
|
+
);
|
|
3215
|
+
}
|
|
3216
|
+
function ChangeDisplay({ postfix = "%", data = [], decimal = 0 }) {
|
|
3217
|
+
const [current, prev] = data;
|
|
3218
|
+
function calculateGrowthPercentage(curr, previous) {
|
|
3219
|
+
if (!previous && !curr) {
|
|
3220
|
+
return 0;
|
|
3221
|
+
}
|
|
3222
|
+
if (!previous) {
|
|
3223
|
+
return Infinity;
|
|
3224
|
+
}
|
|
3225
|
+
return (curr - previous) * 100 / previous;
|
|
3226
|
+
}
|
|
3227
|
+
const CAPPED = 1e4;
|
|
3228
|
+
const growth = calculateGrowthPercentage(current, prev);
|
|
3229
|
+
const displayGrowth = Math.max(Math.min(growth, CAPPED), -CAPPED);
|
|
3230
|
+
if (prev > 0 && current === 0) {
|
|
3231
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center space-x-2 text-red-600 w-full", children: [
|
|
3232
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 text-right", children: "Lost" }),
|
|
3233
|
+
/* @__PURE__ */ jsx("div", { className: "opacity-30 group-hover:opacity-100", children: "\u25BC" })
|
|
3234
|
+
] });
|
|
3235
|
+
}
|
|
3236
|
+
if (growth === Infinity) {
|
|
3237
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center space-x-2 text-green-600 w-full", children: [
|
|
3238
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 text-right", children: "New" }),
|
|
3239
|
+
/* @__PURE__ */ jsx("div", { className: "opacity-30 group-hover:opacity-100", children: "\u25B2" })
|
|
3240
|
+
] });
|
|
3241
|
+
}
|
|
3242
|
+
if (growth === 0) {
|
|
3243
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center space-x-2 w-full", children: [
|
|
3244
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 text-right", children: "-" }),
|
|
3245
|
+
/* @__PURE__ */ jsx("div", { children: "\xA0" })
|
|
3246
|
+
] });
|
|
3247
|
+
}
|
|
3248
|
+
return /* @__PURE__ */ jsxs(
|
|
3249
|
+
"div",
|
|
3250
|
+
{
|
|
3251
|
+
className: classNames({
|
|
3252
|
+
"flex justify-between items-center space-x-2 whitespace-nowrap w-full": true,
|
|
3253
|
+
"text-red-600": growth < 0,
|
|
3254
|
+
"text-green-600": growth > 0
|
|
3255
|
+
}),
|
|
3256
|
+
children: [
|
|
3257
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 text-right", children: [
|
|
3258
|
+
Math.abs(growth) <= CAPPED && (growth >= 0 ? "+" : "-"),
|
|
3259
|
+
growth > CAPPED && " >",
|
|
3260
|
+
growth < -CAPPED && " <",
|
|
3261
|
+
numberFormatter(Math.abs(displayGrowth), decimal),
|
|
3262
|
+
postfix
|
|
3263
|
+
] }),
|
|
3264
|
+
/* @__PURE__ */ jsx("div", { className: "opacity-30 group-hover:opacity-100", children: growth > 0 ? /* @__PURE__ */ jsx(Fragment, { children: "\u25B2" }) : /* @__PURE__ */ jsx(Fragment, { children: "\u25BC" }) })
|
|
3265
|
+
]
|
|
3266
|
+
}
|
|
3267
|
+
);
|
|
3268
|
+
}
|
|
3269
|
+
function DateTimeDisplay({ loading, value }) {
|
|
3270
|
+
let formatted = "-";
|
|
3271
|
+
try {
|
|
3272
|
+
if (value) {
|
|
3273
|
+
formatted = new Intl.DateTimeFormat("en-GB", {
|
|
3274
|
+
weekday: "short",
|
|
3275
|
+
day: "numeric",
|
|
3276
|
+
month: "short",
|
|
3277
|
+
year: "numeric"
|
|
3278
|
+
}).format(new Date(value));
|
|
3279
|
+
}
|
|
3280
|
+
} catch (e) {
|
|
3281
|
+
formatted = String(value);
|
|
3282
|
+
}
|
|
3283
|
+
return /* @__PURE__ */ jsx(
|
|
3284
|
+
"div",
|
|
3285
|
+
{
|
|
3286
|
+
className: classNames({
|
|
3287
|
+
"w-full whitespace-nowrap": true,
|
|
3288
|
+
"animate-pulse bg-gray-100 text-transparent rounded-md": !!loading
|
|
3289
|
+
}),
|
|
3290
|
+
children: formatted
|
|
3291
|
+
}
|
|
3292
|
+
);
|
|
3293
|
+
}
|
|
3294
|
+
function ThumbnailDisplay({ loading, value }) {
|
|
3295
|
+
const image = Array.isArray(value) ? value.length > 0 ? value[0] : null : value;
|
|
3296
|
+
const { imageUrl, imageDescription } = image || {};
|
|
3297
|
+
return /* @__PURE__ */ jsxs(
|
|
3298
|
+
"div",
|
|
3299
|
+
{
|
|
3300
|
+
className: classNames({
|
|
3301
|
+
"w-full whitespace-nowrap": true,
|
|
3302
|
+
"animate-pulse bg-gray-100 text-transparent rounded-md": !!loading
|
|
3303
|
+
}),
|
|
3304
|
+
children: [
|
|
3305
|
+
image && imageUrl && /* @__PURE__ */ jsx(
|
|
3306
|
+
"img",
|
|
3307
|
+
{
|
|
3308
|
+
src: imageUrl,
|
|
3309
|
+
alt: imageDescription || "",
|
|
3310
|
+
className: "w-8 min-w-8 h-8 object-cover rounded-md"
|
|
3311
|
+
}
|
|
3312
|
+
),
|
|
3313
|
+
!image && /* @__PURE__ */ jsx("div", { className: "w-8 min-w-8 h-8 bg-gray-100 dark:bg-charcoal-800 rounded-md" })
|
|
3314
|
+
]
|
|
3315
|
+
}
|
|
3316
|
+
);
|
|
3317
|
+
}
|
|
3318
|
+
function DataGridHeader({ sort, onClick, opts, children }) {
|
|
3319
|
+
const { align, grow, noWrap, isSorted, stickyHeader, darkMode } = opts || {};
|
|
3320
|
+
if (sort) {
|
|
3321
|
+
return /* @__PURE__ */ jsx(
|
|
3322
|
+
"th",
|
|
3323
|
+
{
|
|
3324
|
+
className: classNames({
|
|
3325
|
+
"py-2.5 px-2 sm:px-3 whitespace-nowrap text-center cursor-pointer font-semibold": true,
|
|
3326
|
+
"w-4": !grow,
|
|
3327
|
+
"!text-left": align === "left",
|
|
3328
|
+
"!text-right": align === "right",
|
|
3329
|
+
"whitespace-nowrap": !!noWrap,
|
|
3330
|
+
"sticky top-0 z-10 dark:bg-charcoal-800": !!stickyHeader,
|
|
3331
|
+
"bg-cream-50": !darkMode,
|
|
3332
|
+
"bg-charcoal-800": !!darkMode
|
|
3333
|
+
}),
|
|
3334
|
+
onClick,
|
|
3335
|
+
children: /* @__PURE__ */ jsxs("span", { className: "relative", children: [
|
|
3336
|
+
children,
|
|
3337
|
+
isSorted && /* @__PURE__ */ jsxs("div", { className: "absolute top-0 bottom-0 -right-3.5 flex items-center", children: [
|
|
3338
|
+
isSorted === "asc" && /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "w-3 h-3", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M8.25 6.75 12 3m0 0 3.75 3.75M12 3v18" }) }),
|
|
3339
|
+
isSorted === "desc" && /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "w-3 h-3", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15.75 17.25 12 21m0 0-3.75-3.75M12 21V3" }) })
|
|
3340
|
+
] })
|
|
3341
|
+
] })
|
|
3342
|
+
}
|
|
3343
|
+
);
|
|
3344
|
+
}
|
|
3345
|
+
return /* @__PURE__ */ jsx(
|
|
3346
|
+
"th",
|
|
3347
|
+
{
|
|
3348
|
+
className: classNames({
|
|
3349
|
+
"py-2.5 px-2 sm:px-3 text-center font-semibold": true,
|
|
3350
|
+
"w-4": !grow,
|
|
3351
|
+
"!text-left": align === "left",
|
|
3352
|
+
"whitespace-nowrap": !!noWrap,
|
|
3353
|
+
"sticky top-0 z-10 dark:bg-charcoal-800": !!stickyHeader,
|
|
3354
|
+
"bg-cream-50": !darkMode,
|
|
3355
|
+
"bg-charcoal-800": !!darkMode
|
|
3356
|
+
}),
|
|
3357
|
+
children
|
|
3358
|
+
}
|
|
3359
|
+
);
|
|
3360
|
+
}
|
|
3361
|
+
function DataGridElement({ processing: defaultProcessing, type, value, error, menu, params, opts, onSelect }) {
|
|
3362
|
+
const [processing, setProcessing] = useState(defaultProcessing);
|
|
3363
|
+
useEffect(() => {
|
|
3364
|
+
setProcessing(defaultProcessing);
|
|
3365
|
+
}, [defaultProcessing]);
|
|
3366
|
+
const { align } = opts || {};
|
|
3367
|
+
if (!processing && menu) {
|
|
3368
|
+
return /* @__PURE__ */ jsx(
|
|
3369
|
+
Popover,
|
|
3370
|
+
{
|
|
3371
|
+
actions: [
|
|
3372
|
+
{
|
|
3373
|
+
id: "edit-section",
|
|
3374
|
+
section: "Action",
|
|
3375
|
+
items: menu.map((menuItem) => {
|
|
3376
|
+
return {
|
|
3377
|
+
id: menuItem.id,
|
|
3378
|
+
label: menuItem.label,
|
|
3379
|
+
action: async () => {
|
|
3380
|
+
setProcessing(true);
|
|
3381
|
+
await menuItem.onClick(params);
|
|
3382
|
+
setProcessing(false);
|
|
3383
|
+
}
|
|
3384
|
+
};
|
|
3385
|
+
})
|
|
3386
|
+
}
|
|
3387
|
+
],
|
|
3388
|
+
opts: { compact: true, asBlock: true, align },
|
|
3389
|
+
children: /* @__PURE__ */ jsx(
|
|
3390
|
+
DataGridContent,
|
|
3391
|
+
{
|
|
3392
|
+
loading: processing,
|
|
3393
|
+
error,
|
|
3394
|
+
type,
|
|
3395
|
+
value,
|
|
3396
|
+
opts: {
|
|
3397
|
+
...opts,
|
|
3398
|
+
contentFull: true
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
)
|
|
3402
|
+
}
|
|
3403
|
+
);
|
|
3404
|
+
}
|
|
3405
|
+
return /* @__PURE__ */ jsx(
|
|
3406
|
+
DataGridContent,
|
|
3407
|
+
{
|
|
3408
|
+
loading: processing,
|
|
3409
|
+
error,
|
|
3410
|
+
type,
|
|
3411
|
+
value,
|
|
3412
|
+
opts,
|
|
3413
|
+
onClick: () => {
|
|
3414
|
+
if (typeof onSelect === "function") {
|
|
3415
|
+
onSelect(params?.row);
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
);
|
|
3420
|
+
}
|
|
3421
|
+
function DataGridContent({ loading, error, type, value, opts, onClick }) {
|
|
3422
|
+
if (type === "currency") {
|
|
3423
|
+
return /* @__PURE__ */ jsx(CurrencyDisplay, { loading, error, amount: value, opts });
|
|
3424
|
+
}
|
|
3425
|
+
if (type === "number") {
|
|
3426
|
+
return /* @__PURE__ */ jsx(NumberDisplay, { loading, error, amount: value });
|
|
3427
|
+
}
|
|
3428
|
+
if (type === "change") {
|
|
3429
|
+
const [current, previous] = value || [];
|
|
3430
|
+
return /* @__PURE__ */ jsx(ChangeDisplay, { data: [current, previous], decimal: 0 });
|
|
3431
|
+
}
|
|
3432
|
+
if (type === "datetime") {
|
|
3433
|
+
return /* @__PURE__ */ jsx(DateTimeDisplay, { value });
|
|
3434
|
+
}
|
|
3435
|
+
if (type === "thumbnail") {
|
|
3436
|
+
return /* @__PURE__ */ jsx(ThumbnailDisplay, { value });
|
|
3437
|
+
}
|
|
3438
|
+
const { noWrap, lineClamp } = opts || {};
|
|
3439
|
+
return /* @__PURE__ */ jsx(
|
|
3440
|
+
"div",
|
|
3441
|
+
{
|
|
3442
|
+
className: classNames({
|
|
3443
|
+
"whitespace-nowrap": !!noWrap,
|
|
3444
|
+
"line-clamp-1": lineClamp === 1,
|
|
3445
|
+
"line-clamp-2": lineClamp === 2,
|
|
3446
|
+
"line-clamp-3": lineClamp === 3,
|
|
3447
|
+
"animate-pulse bg-gray-100 text-transparent pointer-events-none": !!loading
|
|
3448
|
+
}),
|
|
3449
|
+
onClick,
|
|
3450
|
+
children: value
|
|
3451
|
+
}
|
|
3452
|
+
);
|
|
3453
|
+
}
|
|
3454
|
+
function DataGrid({ headers, data, selectedId, footers, opts, onSelect }) {
|
|
3455
|
+
const [displayedData, setDisplayedData] = useState([]);
|
|
3456
|
+
const [orderByState, setOrderByState] = useState({
|
|
3457
|
+
category: headers[0]?.id || "",
|
|
3458
|
+
direction: "asc"
|
|
3459
|
+
});
|
|
3460
|
+
const displayedHeaders = (headers || []).filter((header) => !header.hidden);
|
|
3461
|
+
function handleSort(category) {
|
|
3462
|
+
if (orderByState.category !== category) {
|
|
3463
|
+
setOrderByState({ category, direction: "asc" });
|
|
3464
|
+
} else {
|
|
3465
|
+
setOrderByState({ category, direction: orderByState.direction === "asc" ? "desc" : "asc" });
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
useEffect(() => {
|
|
3469
|
+
if ((data || []).length > 0) {
|
|
3470
|
+
const availableKeys = (headers || []).map((header) => header.id);
|
|
3471
|
+
const { category, direction } = orderByState;
|
|
3472
|
+
const sortCategory = availableKeys.includes(category) ? category : headers[0]?.id;
|
|
3473
|
+
const sortDirection = ["asc", "desc"].includes(direction) ? direction : "asc";
|
|
3474
|
+
const targetHeader = headers.find((header) => header.id === sortCategory);
|
|
3475
|
+
const headerType = targetHeader?.type;
|
|
3476
|
+
let sortedData = [...data];
|
|
3477
|
+
if (headerType === "change") {
|
|
3478
|
+
sortedData = sortedData.sort((a, b) => {
|
|
3479
|
+
const x = a[sortCategory] || [0, 0];
|
|
3480
|
+
const y = b[sortCategory] || [0, 0];
|
|
3481
|
+
const left = x[1] ? (x[0] - x[1]) / x[1] : Infinity;
|
|
3482
|
+
const right = y[1] ? (y[0] - y[1]) / y[1] : Infinity;
|
|
3483
|
+
const multiplier = sortDirection === "asc" ? 1 : -1;
|
|
3484
|
+
if (left < right) {
|
|
3485
|
+
return multiplier * -1;
|
|
3486
|
+
}
|
|
3487
|
+
if (left > right) {
|
|
3488
|
+
return multiplier * 1;
|
|
3489
|
+
}
|
|
3490
|
+
if (x[0] - x[1] < y[0] - y[1]) {
|
|
3491
|
+
return multiplier * -1;
|
|
3492
|
+
}
|
|
3493
|
+
if (x[0] - x[1] > y[0] - y[1]) {
|
|
3494
|
+
return multiplier * 1;
|
|
3495
|
+
}
|
|
3496
|
+
return 0;
|
|
3497
|
+
});
|
|
3498
|
+
} else {
|
|
3499
|
+
sortedData.sort((a, b) => {
|
|
3500
|
+
let aVal = a[sortCategory];
|
|
3501
|
+
let bVal = b[sortCategory];
|
|
3502
|
+
if (aVal === bVal) return 0;
|
|
3503
|
+
if (aVal === null || aVal === void 0) return 1;
|
|
3504
|
+
if (bVal === null || bVal === void 0) return -1;
|
|
3505
|
+
if (typeof aVal === "string") {
|
|
3506
|
+
aVal = aVal.toLowerCase();
|
|
3507
|
+
}
|
|
3508
|
+
if (typeof bVal === "string") {
|
|
3509
|
+
bVal = bVal.toLowerCase();
|
|
3510
|
+
}
|
|
3511
|
+
const comparison = aVal < bVal ? -1 : 1;
|
|
3512
|
+
return sortDirection === "asc" ? comparison : -comparison;
|
|
3513
|
+
});
|
|
3514
|
+
}
|
|
3515
|
+
const updatedData = (displayedHeaders || []).map((header) => {
|
|
3516
|
+
return {
|
|
3517
|
+
key: header.id,
|
|
3518
|
+
label: header.label,
|
|
3519
|
+
align: header.align,
|
|
3520
|
+
data: (sortedData || []).map((row, rowIndex) => {
|
|
3521
|
+
const isError = header.error && Function("value", `return ${header.error}`)(row[header.id]);
|
|
3522
|
+
const [timestamp] = (header.id || "").split(" - ");
|
|
3523
|
+
const isProcessing = row[`${timestamp} - processing`];
|
|
3524
|
+
return /* @__PURE__ */ jsx(
|
|
3525
|
+
DataGridElement,
|
|
3526
|
+
{
|
|
3527
|
+
processing: isProcessing,
|
|
3528
|
+
type: header.type,
|
|
3529
|
+
value: row[header.id],
|
|
3530
|
+
menu: header.menu,
|
|
3531
|
+
opts: {
|
|
3532
|
+
align: header.align,
|
|
3533
|
+
noWrap: header.noWrap,
|
|
3534
|
+
vAlign: header.vertical,
|
|
3535
|
+
lineClamp: header.lineClamp
|
|
3536
|
+
},
|
|
3537
|
+
params: {
|
|
3538
|
+
id: row.id,
|
|
3539
|
+
data: sortedData,
|
|
3540
|
+
row,
|
|
3541
|
+
headerId: header.id,
|
|
3542
|
+
params: header.params
|
|
3543
|
+
},
|
|
3544
|
+
error: isError,
|
|
3545
|
+
onSelect
|
|
3546
|
+
},
|
|
3547
|
+
`${header.id}-${row.id}`
|
|
3548
|
+
);
|
|
3549
|
+
})
|
|
3550
|
+
};
|
|
3551
|
+
});
|
|
3552
|
+
setDisplayedData(updatedData);
|
|
3553
|
+
} else {
|
|
3554
|
+
setDisplayedData([]);
|
|
3555
|
+
}
|
|
3556
|
+
}, [data, orderByState, headers]);
|
|
3557
|
+
const displayedLabels = (displayedData || [])[0]?.data;
|
|
3558
|
+
const renderedData = (displayedData || []).filter((_, index) => index > 0);
|
|
3559
|
+
const renderedHeaders = (displayedHeaders || []).map((header) => /* @__PURE__ */ jsx(
|
|
3560
|
+
DataGridHeader,
|
|
3561
|
+
{
|
|
3562
|
+
sort: header.sort,
|
|
3563
|
+
opts: {
|
|
3564
|
+
align: header.align,
|
|
3565
|
+
noWrap: header.noWrap,
|
|
3566
|
+
grow: header.grow,
|
|
3567
|
+
isSorted: header.id === orderByState.category ? orderByState.direction : null,
|
|
3568
|
+
stickyHeader: opts?.stickyHeader,
|
|
3569
|
+
darkMode: opts?.darkMode
|
|
3570
|
+
},
|
|
3571
|
+
onClick: () => handleSort(header.id),
|
|
3572
|
+
children: header.label
|
|
3573
|
+
},
|
|
3574
|
+
header.id
|
|
3575
|
+
));
|
|
3576
|
+
return /* @__PURE__ */ jsx(
|
|
3577
|
+
DataTable,
|
|
3578
|
+
{
|
|
3579
|
+
headers: renderedHeaders,
|
|
3580
|
+
labels: displayedLabels,
|
|
3581
|
+
data: renderedData,
|
|
3582
|
+
selectedId,
|
|
3583
|
+
total: footers,
|
|
3584
|
+
opts: {
|
|
3585
|
+
...opts,
|
|
3586
|
+
ignoreTotal: !footers
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
);
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
export { B, Button, CheckboxList, ConfirmationBox, Coverflow, DataGrid, Dragger, Drawer, ExcelTable, H1, H2, H3, H4, InlinePrompt, Input_default as Input, Label, Loading, Modal, ModalContext, ModalProvider, NoData, Popover, PopoverContext, PopoverProvider, Select_default as Select, SelectInput_default as SelectInput, SortIcon, Table, Tabs, Tag, TagGroup, TagInput, Tbody, Td, Textarea_default as Textarea, Th, Thead, ThemeContext, ThemeProvider, ThemeToggle, Toggle_default as Toggle, Tr, Transition, bestTextColorForBg, classNameObject, classNames, debounce, moveItem, numberFormatter, useDebounce, useModalContext, usePopoverContext, useResizeListener, useThemeContext };
|
|
3593
|
+
//# sourceMappingURL=index.mjs.map
|
|
3594
|
+
//# sourceMappingURL=index.mjs.map
|