@deepnoid/ui 0.1.202 → 0.1.204
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/.turbo/turbo-build.log +166 -166
- package/dist/{chunk-2EUKWA4W.mjs → chunk-AUGYJPCS.mjs} +89 -47
- package/dist/{chunk-KYWCJIXI.mjs → chunk-W3V4SZV5.mjs} +24 -68
- package/dist/components/list/index.mjs +3 -3
- package/dist/components/picker/datePicker.d.mts +2 -0
- package/dist/components/picker/datePicker.d.ts +2 -0
- package/dist/components/picker/datePicker.js +90 -48
- package/dist/components/picker/datePicker.mjs +1 -1
- package/dist/components/picker/index.js +90 -48
- package/dist/components/picker/index.mjs +6 -6
- package/dist/components/table/index.js +19 -63
- package/dist/components/table/index.mjs +4 -4
- package/dist/components/table/table-body.js +19 -63
- package/dist/components/table/table-body.mjs +2 -2
- package/dist/components/table/table-head.d.mts +1 -1
- package/dist/components/table/table-head.d.ts +1 -1
- package/dist/components/table/table-head.js +19 -63
- package/dist/components/table/table-head.mjs +2 -2
- package/dist/components/table/table.js +19 -63
- package/dist/components/table/table.mjs +2 -2
- package/dist/components/toast/index.mjs +2 -2
- package/dist/components/toast/use-toast.mjs +2 -2
- package/dist/index.js +110 -112
- package/dist/index.mjs +44 -44
- package/package.json +1 -1
- package/dist/{chunk-SSGCTWWW.mjs → chunk-L3A3IEKZ.mjs} +3 -3
|
@@ -66,6 +66,8 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
66
66
|
confirmTitle,
|
|
67
67
|
range = false,
|
|
68
68
|
dualCalendar = false,
|
|
69
|
+
disabledDates,
|
|
70
|
+
enabledDates,
|
|
69
71
|
...inputProps
|
|
70
72
|
} = { ...props, ...variantProps };
|
|
71
73
|
const [selectedDate, setSelectedDate] = useState(range ? "" : typeof value === "string" ? value || "" : "");
|
|
@@ -187,29 +189,18 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
187
189
|
for (let i = 0; i < dates.length; i += 7) weeks.push(dates.slice(i, i + 7));
|
|
188
190
|
return weeks;
|
|
189
191
|
}, []);
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const newLeftDate = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() + 1);
|
|
199
|
-
setLeftCurrentDate(newLeftDate);
|
|
200
|
-
if (dualCalendar) {
|
|
201
|
-
setRightCurrentDate(new Date(newLeftDate.getFullYear(), newLeftDate.getMonth() + 1));
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
const handleRightNextMonth = () => {
|
|
205
|
-
if (!dualCalendar) return;
|
|
206
|
-
const newRightDate = new Date(rightCurrentDate.getFullYear(), rightCurrentDate.getMonth() + 1);
|
|
207
|
-
setRightCurrentDate(newRightDate);
|
|
208
|
-
setLeftCurrentDate(new Date(newRightDate.getFullYear(), newRightDate.getMonth() - 1));
|
|
209
|
-
};
|
|
192
|
+
const isDateDisabled = useCallback(
|
|
193
|
+
(date) => {
|
|
194
|
+
if (enabledDates) return !enabledDates(date);
|
|
195
|
+
if (disabledDates) return disabledDates(date);
|
|
196
|
+
return false;
|
|
197
|
+
},
|
|
198
|
+
[disabledDates, enabledDates]
|
|
199
|
+
);
|
|
210
200
|
const handleDateSelect = (date, isCurrentMonth, currentDate) => {
|
|
211
201
|
if (!isCurrentMonth) return;
|
|
212
202
|
const selected = new Date(currentDate.getFullYear(), currentDate.getMonth(), date);
|
|
203
|
+
if (isDateDisabled(selected)) return;
|
|
213
204
|
const formatted = formatDateToString(selected);
|
|
214
205
|
if (range) {
|
|
215
206
|
if (rangeSelection === "start") {
|
|
@@ -220,7 +211,10 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
220
211
|
if (selected >= startDate) {
|
|
221
212
|
setTempSelectedRange({ ...tempSelectedRange, endDate: formatted });
|
|
222
213
|
} else {
|
|
223
|
-
setTempSelectedRange({
|
|
214
|
+
setTempSelectedRange({
|
|
215
|
+
startDate: formatted,
|
|
216
|
+
endDate: tempSelectedRange.startDate
|
|
217
|
+
});
|
|
224
218
|
}
|
|
225
219
|
}
|
|
226
220
|
} else {
|
|
@@ -229,6 +223,7 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
229
223
|
};
|
|
230
224
|
const handleSetToday = () => {
|
|
231
225
|
const today = /* @__PURE__ */ new Date();
|
|
226
|
+
if (isDateDisabled(today)) return;
|
|
232
227
|
const formatted = formatDateToString(today);
|
|
233
228
|
if (range) {
|
|
234
229
|
if (rangeSelection === "start") {
|
|
@@ -239,7 +234,10 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
239
234
|
if (today >= startDate) {
|
|
240
235
|
setTempSelectedRange({ ...tempSelectedRange, endDate: formatted });
|
|
241
236
|
} else {
|
|
242
|
-
setTempSelectedRange({
|
|
237
|
+
setTempSelectedRange({
|
|
238
|
+
startDate: formatted,
|
|
239
|
+
endDate: tempSelectedRange.startDate
|
|
240
|
+
});
|
|
243
241
|
}
|
|
244
242
|
}
|
|
245
243
|
} else {
|
|
@@ -251,11 +249,11 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
251
249
|
const handleConfirmDate = () => {
|
|
252
250
|
if (isConfirmDisabled) return;
|
|
253
251
|
if (range) {
|
|
254
|
-
setSelectedRange(tempSelectedRange);
|
|
255
252
|
onChange == null ? void 0 : onChange(tempSelectedRange);
|
|
253
|
+
setSelectedRange(tempSelectedRange);
|
|
256
254
|
} else {
|
|
257
|
-
setSelectedDate(tempSelectedDate);
|
|
258
255
|
onChange == null ? void 0 : onChange(tempSelectedDate);
|
|
256
|
+
setSelectedDate(tempSelectedDate);
|
|
259
257
|
}
|
|
260
258
|
setIsPanelOpen(false);
|
|
261
259
|
};
|
|
@@ -270,31 +268,29 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
270
268
|
};
|
|
271
269
|
const getDayProps = useCallback(
|
|
272
270
|
(dateObj, currentDate) => {
|
|
271
|
+
const date = new Date(currentDate.getFullYear(), currentDate.getMonth(), dateObj.date);
|
|
272
|
+
if (isDateDisabled(date)) return "disabled";
|
|
273
273
|
const today = /* @__PURE__ */ new Date();
|
|
274
274
|
const isToday = today.getDate() === dateObj.date && today.getMonth() === currentDate.getMonth() && today.getFullYear() === currentDate.getFullYear();
|
|
275
275
|
if (range) {
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
const
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
const isInRange =
|
|
282
|
-
if (
|
|
283
|
-
if (
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
return "default";
|
|
287
|
-
} else {
|
|
288
|
-
const formatted = tempSelectedDate ? formatStringToDate(tempSelectedDate) : null;
|
|
289
|
-
const isSelected = (formatted == null ? void 0 : formatted.getDate()) === dateObj.date && formatted.getMonth() === currentDate.getMonth() && formatted.getFullYear() === currentDate.getFullYear();
|
|
290
|
-
return dateObj.currentMonth && isSelected ? "selected" : dateObj.currentMonth && isToday ? "today" : !dateObj.currentMonth ? "disabled" : "default";
|
|
276
|
+
const start = tempSelectedRange.startDate ? formatStringToDate(tempSelectedRange.startDate) : null;
|
|
277
|
+
const end = tempSelectedRange.endDate ? formatStringToDate(tempSelectedRange.endDate) : null;
|
|
278
|
+
const current = date;
|
|
279
|
+
const isStart = start && start.getFullYear() === current.getFullYear() && start.getMonth() === current.getMonth() && start.getDate() === current.getDate();
|
|
280
|
+
const isEnd = end && end.getFullYear() === current.getFullYear() && end.getMonth() === current.getMonth() && end.getDate() === current.getDate();
|
|
281
|
+
const isInRange = start && end && current > start && current < end;
|
|
282
|
+
if (isStart || isEnd) return "selected";
|
|
283
|
+
if (isInRange) return "period";
|
|
284
|
+
if (isToday) return "today";
|
|
285
|
+
return dateObj.currentMonth ? "default" : "disabled";
|
|
291
286
|
}
|
|
287
|
+
const selected = tempSelectedDate ? formatStringToDate(tempSelectedDate) : null;
|
|
288
|
+
const isSelected = selected && selected.getFullYear() === date.getFullYear() && selected.getMonth() === date.getMonth() && selected.getDate() === date.getDate();
|
|
289
|
+
return isSelected ? "selected" : isToday ? "today" : dateObj.currentMonth ? "default" : "disabled";
|
|
292
290
|
},
|
|
293
|
-
[tempSelectedDate, tempSelectedRange, range]
|
|
291
|
+
[tempSelectedDate, tempSelectedRange, range, isDateDisabled]
|
|
294
292
|
);
|
|
295
|
-
const getPlaceholderText = () =>
|
|
296
|
-
return placeholder;
|
|
297
|
-
};
|
|
293
|
+
const getPlaceholderText = () => placeholder;
|
|
298
294
|
useEffect(() => {
|
|
299
295
|
if (range && typeof value === "object") {
|
|
300
296
|
setSelectedRange(value || { startDate: "", endDate: "" });
|
|
@@ -315,17 +311,63 @@ var DatePicker = forwardRef((originalProps, ref) => {
|
|
|
315
311
|
const endContent = /* @__PURE__ */ jsx(Icon_default, { name: "calendar", size, className: "cursor-pointer", fill: true, onClick: handleCalendarIconClick });
|
|
316
312
|
const renderCalendar = (currentDate, isLeft) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-[5px]", children: [
|
|
317
313
|
/* @__PURE__ */ jsx("div", { className: slots.calendarHead({ class: classNames == null ? void 0 : classNames.calendarHead }), children: dualCalendar ? isLeft ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
318
|
-
/* @__PURE__ */ jsx(
|
|
314
|
+
/* @__PURE__ */ jsx(
|
|
315
|
+
icon_button_default,
|
|
316
|
+
{
|
|
317
|
+
name: "left",
|
|
318
|
+
variant: "soft",
|
|
319
|
+
color: "neutral",
|
|
320
|
+
onClick: () => {
|
|
321
|
+
const newLeft = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() - 1);
|
|
322
|
+
setLeftCurrentDate(newLeft);
|
|
323
|
+
setRightCurrentDate(new Date(newLeft.getFullYear(), newLeft.getMonth() + 1));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
),
|
|
319
327
|
/* @__PURE__ */ jsx("span", { className: "text-xl font-extrabold", children: monthYearFormat(currentDate.getFullYear(), currentDate.getMonth()) }),
|
|
320
328
|
/* @__PURE__ */ jsx("div", { className: "w-8" })
|
|
321
329
|
] }) : /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
322
330
|
/* @__PURE__ */ jsx("div", { className: "w-8" }),
|
|
323
331
|
/* @__PURE__ */ jsx("span", { className: "text-xl font-extrabold", children: monthYearFormat(currentDate.getFullYear(), currentDate.getMonth()) }),
|
|
324
|
-
/* @__PURE__ */ jsx(
|
|
332
|
+
/* @__PURE__ */ jsx(
|
|
333
|
+
icon_button_default,
|
|
334
|
+
{
|
|
335
|
+
name: "right",
|
|
336
|
+
variant: "soft",
|
|
337
|
+
color: "neutral",
|
|
338
|
+
onClick: () => {
|
|
339
|
+
const newRight = new Date(rightCurrentDate.getFullYear(), rightCurrentDate.getMonth() + 1);
|
|
340
|
+
setRightCurrentDate(newRight);
|
|
341
|
+
setLeftCurrentDate(new Date(newRight.getFullYear(), newRight.getMonth() - 1));
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
)
|
|
325
345
|
] }) : /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
326
|
-
/* @__PURE__ */ jsx(
|
|
346
|
+
/* @__PURE__ */ jsx(
|
|
347
|
+
icon_button_default,
|
|
348
|
+
{
|
|
349
|
+
name: "left",
|
|
350
|
+
variant: "soft",
|
|
351
|
+
color: "neutral",
|
|
352
|
+
onClick: () => {
|
|
353
|
+
const newLeft = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() - 1);
|
|
354
|
+
setLeftCurrentDate(newLeft);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
),
|
|
327
358
|
/* @__PURE__ */ jsx("span", { className: "text-xl font-extrabold", children: monthYearFormat(currentDate.getFullYear(), currentDate.getMonth()) }),
|
|
328
|
-
/* @__PURE__ */ jsx(
|
|
359
|
+
/* @__PURE__ */ jsx(
|
|
360
|
+
icon_button_default,
|
|
361
|
+
{
|
|
362
|
+
name: "right",
|
|
363
|
+
variant: "soft",
|
|
364
|
+
color: "neutral",
|
|
365
|
+
onClick: () => {
|
|
366
|
+
const newLeft = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() + 1);
|
|
367
|
+
setLeftCurrentDate(newLeft);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
)
|
|
329
371
|
] }) }),
|
|
330
372
|
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-7", children: daysOfWeek.map((day, index) => /* @__PURE__ */ jsx(day_default, { variant: "text", children: day }, `${day}-${index}`)) }),
|
|
331
373
|
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-7 gap-y-[5px] text-center", children: getCalendarDates(currentDate).map((week, weekIndex) => /* @__PURE__ */ jsx(Fragment, { children: week.map((dateObj, index) => {
|
|
@@ -16,12 +16,12 @@ import {
|
|
|
16
16
|
} from "./chunk-27Y6K5NK.mjs";
|
|
17
17
|
|
|
18
18
|
// src/components/table/table-head.tsx
|
|
19
|
-
import {
|
|
19
|
+
import { useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState3 } from "react";
|
|
20
20
|
|
|
21
21
|
// src/components/table/table.tsx
|
|
22
22
|
import {
|
|
23
23
|
forwardRef,
|
|
24
|
-
useEffect
|
|
24
|
+
useEffect,
|
|
25
25
|
useImperativeHandle,
|
|
26
26
|
useMemo,
|
|
27
27
|
useState as useState2
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
import { tv } from "tailwind-variants";
|
|
30
30
|
|
|
31
31
|
// src/components/table/table-body.tsx
|
|
32
|
-
import {
|
|
32
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
33
33
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
34
34
|
function TableCell({
|
|
35
35
|
row,
|
|
@@ -41,53 +41,31 @@ function TableCell({
|
|
|
41
41
|
}) {
|
|
42
42
|
var _a, _b;
|
|
43
43
|
const value = row[column.field];
|
|
44
|
-
const formattedValue = ((_a = column.valueFormatter) == null ? void 0 : _a.call(column, { value, field: column.field }))
|
|
44
|
+
const formattedValue = (_b = (_a = column.valueFormatter) == null ? void 0 : _a.call(column, { value, field: column.field })) != null ? _b : value;
|
|
45
45
|
const content = column.renderCell ? column.renderCell({ id: row.id, field: column.field, value, formattedValue, row }) : formattedValue;
|
|
46
|
+
const isTextContent = ["string", "number"].includes(typeof content) || content === null || content === void 0;
|
|
46
47
|
const tdRef = useRef(null);
|
|
47
48
|
const [showTitle, setShowTitle] = useState(false);
|
|
48
|
-
|
|
49
|
-
const checkOverflow = (el) => {
|
|
50
|
-
if (el.scrollWidth > el.clientWidth) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
const children = Array.from(el.children);
|
|
54
|
-
for (const child of children) {
|
|
55
|
-
if (child.scrollWidth > child.clientWidth) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
};
|
|
61
|
-
useEffect(() => {
|
|
49
|
+
useLayoutEffect(() => {
|
|
62
50
|
if (tdRef.current && isTextContent) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
setShowTitle(checkOverflow(tdRef.current));
|
|
66
|
-
}
|
|
67
|
-
}, 0);
|
|
51
|
+
const el = tdRef.current;
|
|
52
|
+
setShowTitle(el.scrollWidth > el.clientWidth);
|
|
68
53
|
}
|
|
69
54
|
}, [content, isTextContent]);
|
|
70
55
|
return /* @__PURE__ */ jsx(
|
|
71
56
|
"td",
|
|
72
57
|
{
|
|
73
58
|
ref: tdRef,
|
|
74
|
-
className: clsx(
|
|
75
|
-
slots.td(),
|
|
76
|
-
classNames == null ? void 0 : classNames.td,
|
|
77
|
-
column.className,
|
|
78
|
-
isTextContent && "truncate",
|
|
79
|
-
isTextContent && "[&>*]:inline-block [&>*]:max-w-full [&>*]:truncate [&>*]:align-middle"
|
|
80
|
-
),
|
|
59
|
+
className: clsx(slots.td(), classNames == null ? void 0 : classNames.td, column.className, isTextContent && "truncate"),
|
|
81
60
|
style: {
|
|
82
61
|
...getCellStyle(column),
|
|
83
62
|
maxWidth: column.width || "150px",
|
|
84
63
|
textAlign: column.align || "center",
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
64
|
+
whiteSpace: isTextContent ? "nowrap" : "normal",
|
|
65
|
+
overflow: isTextContent ? "hidden" : "visible",
|
|
66
|
+
textOverflow: isTextContent ? "ellipsis" : void 0
|
|
89
67
|
},
|
|
90
|
-
title: showTitle ? String(
|
|
68
|
+
title: showTitle && isTextContent ? String(content != null ? content : "") : void 0,
|
|
91
69
|
children: content
|
|
92
70
|
},
|
|
93
71
|
`${row.id}-${column.field}-${colIdx}-${rowIndex}`
|
|
@@ -194,10 +172,10 @@ var Table = forwardRef((originalProps, ref) => {
|
|
|
194
172
|
const checkboxWidth = rowCheckbox ? 40 : 0;
|
|
195
173
|
return columnsWidth + checkboxWidth;
|
|
196
174
|
}, [columns, rowCheckbox]);
|
|
197
|
-
|
|
175
|
+
useEffect(() => {
|
|
198
176
|
onCheckedRowsChange == null ? void 0 : onCheckedRowsChange(getCheckedRowData(checkedRowIds));
|
|
199
177
|
}, [checkedRowIds]);
|
|
200
|
-
|
|
178
|
+
useEffect(() => {
|
|
201
179
|
const currentRowIds = new Set(rows.map((row) => row.id));
|
|
202
180
|
const ids = Array.from(checkedRowIds);
|
|
203
181
|
const hasValidCheckedRows = ids.every((id) => currentRowIds.has(id));
|
|
@@ -561,37 +539,13 @@ function TableHeaderCell({
|
|
|
561
539
|
}) {
|
|
562
540
|
const thRef = useRef2(null);
|
|
563
541
|
const [showTitle, setShowTitle] = useState3(false);
|
|
564
|
-
|
|
565
|
-
if (
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const children = Array.from(el.children);
|
|
569
|
-
for (const child of children) {
|
|
570
|
-
if (child.scrollWidth > child.clientWidth) {
|
|
571
|
-
return true;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
return false;
|
|
575
|
-
};
|
|
576
|
-
const extractTextFromContent = (node) => {
|
|
577
|
-
if (typeof node === "string" || typeof node === "number") {
|
|
578
|
-
return String(node);
|
|
579
|
-
}
|
|
580
|
-
if (isValidElement(node)) {
|
|
581
|
-
return String(node.props.children || "");
|
|
582
|
-
}
|
|
583
|
-
return "";
|
|
584
|
-
};
|
|
585
|
-
useEffect3(() => {
|
|
586
|
-
if (thRef.current && !isCheckbox) {
|
|
587
|
-
setTimeout(() => {
|
|
588
|
-
if (thRef.current) {
|
|
589
|
-
setShowTitle(checkOverflow(thRef.current));
|
|
590
|
-
}
|
|
591
|
-
}, 0);
|
|
542
|
+
useLayoutEffect2(() => {
|
|
543
|
+
if (!isCheckbox && thRef.current) {
|
|
544
|
+
const el = thRef.current;
|
|
545
|
+
setShowTitle(el.scrollWidth > el.clientWidth);
|
|
592
546
|
}
|
|
593
547
|
}, [content, isCheckbox]);
|
|
594
|
-
const titleText = !isCheckbox && showTitle ?
|
|
548
|
+
const titleText = !isCheckbox && showTitle ? typeof content === "string" || typeof content === "number" ? String(content) : "" : void 0;
|
|
595
549
|
return /* @__PURE__ */ jsx3(
|
|
596
550
|
"th",
|
|
597
551
|
{
|
|
@@ -604,7 +558,10 @@ function TableHeaderCell({
|
|
|
604
558
|
flexShrink: 0,
|
|
605
559
|
flexGrow: 0,
|
|
606
560
|
boxSizing: "border-box"
|
|
607
|
-
} : column ? {
|
|
561
|
+
} : column ? {
|
|
562
|
+
...getCellStyle(column),
|
|
563
|
+
textAlign: "center"
|
|
564
|
+
} : void 0,
|
|
608
565
|
title: titleText,
|
|
609
566
|
children: content
|
|
610
567
|
}
|
|
@@ -613,7 +570,6 @@ function TableHeaderCell({
|
|
|
613
570
|
var TableHead = ({
|
|
614
571
|
slots,
|
|
615
572
|
columns,
|
|
616
|
-
color,
|
|
617
573
|
size,
|
|
618
574
|
rowCheckbox = false,
|
|
619
575
|
hasCheckedRows,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../../chunk-7MVEAQ7Z.mjs";
|
|
3
|
-
import {
|
|
4
|
-
listItem_default
|
|
5
|
-
} from "../../chunk-K3M3QEEV.mjs";
|
|
6
3
|
import {
|
|
7
4
|
list_default
|
|
8
5
|
} from "../../chunk-NGRGAY42.mjs";
|
|
6
|
+
import {
|
|
7
|
+
listItem_default
|
|
8
|
+
} from "../../chunk-K3M3QEEV.mjs";
|
|
9
9
|
import "../../chunk-ZYIIXWVY.mjs";
|
|
10
10
|
import "../../chunk-YEYUS6DW.mjs";
|
|
11
11
|
import "../../chunk-E3G5QXSH.mjs";
|
|
@@ -31,6 +31,8 @@ interface DatePickerProps extends Omit<ComponentProps<"input">, "size" | "color"
|
|
|
31
31
|
confirmTitle: string;
|
|
32
32
|
range?: boolean;
|
|
33
33
|
dualCalendar?: boolean;
|
|
34
|
+
disabledDates?: (date: Date) => boolean;
|
|
35
|
+
enabledDates?: (date: Date) => boolean;
|
|
34
36
|
}
|
|
35
37
|
declare const DatePicker: react.ForwardRefExoticComponent<Omit<DatePickerProps, "ref"> & react.RefAttributes<HTMLInputElement>>;
|
|
36
38
|
|
|
@@ -31,6 +31,8 @@ interface DatePickerProps extends Omit<ComponentProps<"input">, "size" | "color"
|
|
|
31
31
|
confirmTitle: string;
|
|
32
32
|
range?: boolean;
|
|
33
33
|
dualCalendar?: boolean;
|
|
34
|
+
disabledDates?: (date: Date) => boolean;
|
|
35
|
+
enabledDates?: (date: Date) => boolean;
|
|
34
36
|
}
|
|
35
37
|
declare const DatePicker: react.ForwardRefExoticComponent<Omit<DatePickerProps, "ref"> & react.RefAttributes<HTMLInputElement>>;
|
|
36
38
|
|
|
@@ -6711,6 +6711,8 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6711
6711
|
confirmTitle,
|
|
6712
6712
|
range = false,
|
|
6713
6713
|
dualCalendar = false,
|
|
6714
|
+
disabledDates,
|
|
6715
|
+
enabledDates,
|
|
6714
6716
|
...inputProps
|
|
6715
6717
|
} = { ...props, ...variantProps };
|
|
6716
6718
|
const [selectedDate, setSelectedDate] = (0, import_react7.useState)(range ? "" : typeof value === "string" ? value || "" : "");
|
|
@@ -6832,29 +6834,18 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6832
6834
|
for (let i = 0; i < dates.length; i += 7) weeks.push(dates.slice(i, i + 7));
|
|
6833
6835
|
return weeks;
|
|
6834
6836
|
}, []);
|
|
6835
|
-
const
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
}
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
const newLeftDate = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() + 1);
|
|
6844
|
-
setLeftCurrentDate(newLeftDate);
|
|
6845
|
-
if (dualCalendar) {
|
|
6846
|
-
setRightCurrentDate(new Date(newLeftDate.getFullYear(), newLeftDate.getMonth() + 1));
|
|
6847
|
-
}
|
|
6848
|
-
};
|
|
6849
|
-
const handleRightNextMonth = () => {
|
|
6850
|
-
if (!dualCalendar) return;
|
|
6851
|
-
const newRightDate = new Date(rightCurrentDate.getFullYear(), rightCurrentDate.getMonth() + 1);
|
|
6852
|
-
setRightCurrentDate(newRightDate);
|
|
6853
|
-
setLeftCurrentDate(new Date(newRightDate.getFullYear(), newRightDate.getMonth() - 1));
|
|
6854
|
-
};
|
|
6837
|
+
const isDateDisabled = (0, import_react7.useCallback)(
|
|
6838
|
+
(date) => {
|
|
6839
|
+
if (enabledDates) return !enabledDates(date);
|
|
6840
|
+
if (disabledDates) return disabledDates(date);
|
|
6841
|
+
return false;
|
|
6842
|
+
},
|
|
6843
|
+
[disabledDates, enabledDates]
|
|
6844
|
+
);
|
|
6855
6845
|
const handleDateSelect = (date, isCurrentMonth, currentDate) => {
|
|
6856
6846
|
if (!isCurrentMonth) return;
|
|
6857
6847
|
const selected = new Date(currentDate.getFullYear(), currentDate.getMonth(), date);
|
|
6848
|
+
if (isDateDisabled(selected)) return;
|
|
6858
6849
|
const formatted = formatDateToString(selected);
|
|
6859
6850
|
if (range) {
|
|
6860
6851
|
if (rangeSelection === "start") {
|
|
@@ -6865,7 +6856,10 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6865
6856
|
if (selected >= startDate) {
|
|
6866
6857
|
setTempSelectedRange({ ...tempSelectedRange, endDate: formatted });
|
|
6867
6858
|
} else {
|
|
6868
|
-
setTempSelectedRange({
|
|
6859
|
+
setTempSelectedRange({
|
|
6860
|
+
startDate: formatted,
|
|
6861
|
+
endDate: tempSelectedRange.startDate
|
|
6862
|
+
});
|
|
6869
6863
|
}
|
|
6870
6864
|
}
|
|
6871
6865
|
} else {
|
|
@@ -6874,6 +6868,7 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6874
6868
|
};
|
|
6875
6869
|
const handleSetToday = () => {
|
|
6876
6870
|
const today = /* @__PURE__ */ new Date();
|
|
6871
|
+
if (isDateDisabled(today)) return;
|
|
6877
6872
|
const formatted = formatDateToString(today);
|
|
6878
6873
|
if (range) {
|
|
6879
6874
|
if (rangeSelection === "start") {
|
|
@@ -6884,7 +6879,10 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6884
6879
|
if (today >= startDate) {
|
|
6885
6880
|
setTempSelectedRange({ ...tempSelectedRange, endDate: formatted });
|
|
6886
6881
|
} else {
|
|
6887
|
-
setTempSelectedRange({
|
|
6882
|
+
setTempSelectedRange({
|
|
6883
|
+
startDate: formatted,
|
|
6884
|
+
endDate: tempSelectedRange.startDate
|
|
6885
|
+
});
|
|
6888
6886
|
}
|
|
6889
6887
|
}
|
|
6890
6888
|
} else {
|
|
@@ -6896,11 +6894,11 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6896
6894
|
const handleConfirmDate = () => {
|
|
6897
6895
|
if (isConfirmDisabled) return;
|
|
6898
6896
|
if (range) {
|
|
6899
|
-
setSelectedRange(tempSelectedRange);
|
|
6900
6897
|
onChange == null ? void 0 : onChange(tempSelectedRange);
|
|
6898
|
+
setSelectedRange(tempSelectedRange);
|
|
6901
6899
|
} else {
|
|
6902
|
-
setSelectedDate(tempSelectedDate);
|
|
6903
6900
|
onChange == null ? void 0 : onChange(tempSelectedDate);
|
|
6901
|
+
setSelectedDate(tempSelectedDate);
|
|
6904
6902
|
}
|
|
6905
6903
|
setIsPanelOpen(false);
|
|
6906
6904
|
};
|
|
@@ -6915,31 +6913,29 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6915
6913
|
};
|
|
6916
6914
|
const getDayProps = (0, import_react7.useCallback)(
|
|
6917
6915
|
(dateObj, currentDate) => {
|
|
6916
|
+
const date = new Date(currentDate.getFullYear(), currentDate.getMonth(), dateObj.date);
|
|
6917
|
+
if (isDateDisabled(date)) return "disabled";
|
|
6918
6918
|
const today = /* @__PURE__ */ new Date();
|
|
6919
6919
|
const isToday = today.getDate() === dateObj.date && today.getMonth() === currentDate.getMonth() && today.getFullYear() === currentDate.getFullYear();
|
|
6920
6920
|
if (range) {
|
|
6921
|
-
const
|
|
6922
|
-
const
|
|
6923
|
-
const
|
|
6924
|
-
const
|
|
6925
|
-
const
|
|
6926
|
-
const isInRange =
|
|
6927
|
-
if (
|
|
6928
|
-
if (
|
|
6929
|
-
if (
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
return dateObj.currentMonth && isSelected ? "selected" : dateObj.currentMonth && isToday ? "today" : !dateObj.currentMonth ? "disabled" : "default";
|
|
6936
|
-
}
|
|
6921
|
+
const start = tempSelectedRange.startDate ? formatStringToDate(tempSelectedRange.startDate) : null;
|
|
6922
|
+
const end = tempSelectedRange.endDate ? formatStringToDate(tempSelectedRange.endDate) : null;
|
|
6923
|
+
const current = date;
|
|
6924
|
+
const isStart = start && start.getFullYear() === current.getFullYear() && start.getMonth() === current.getMonth() && start.getDate() === current.getDate();
|
|
6925
|
+
const isEnd = end && end.getFullYear() === current.getFullYear() && end.getMonth() === current.getMonth() && end.getDate() === current.getDate();
|
|
6926
|
+
const isInRange = start && end && current > start && current < end;
|
|
6927
|
+
if (isStart || isEnd) return "selected";
|
|
6928
|
+
if (isInRange) return "period";
|
|
6929
|
+
if (isToday) return "today";
|
|
6930
|
+
return dateObj.currentMonth ? "default" : "disabled";
|
|
6931
|
+
}
|
|
6932
|
+
const selected = tempSelectedDate ? formatStringToDate(tempSelectedDate) : null;
|
|
6933
|
+
const isSelected = selected && selected.getFullYear() === date.getFullYear() && selected.getMonth() === date.getMonth() && selected.getDate() === date.getDate();
|
|
6934
|
+
return isSelected ? "selected" : isToday ? "today" : dateObj.currentMonth ? "default" : "disabled";
|
|
6937
6935
|
},
|
|
6938
|
-
[tempSelectedDate, tempSelectedRange, range]
|
|
6936
|
+
[tempSelectedDate, tempSelectedRange, range, isDateDisabled]
|
|
6939
6937
|
);
|
|
6940
|
-
const getPlaceholderText = () =>
|
|
6941
|
-
return placeholder;
|
|
6942
|
-
};
|
|
6938
|
+
const getPlaceholderText = () => placeholder;
|
|
6943
6939
|
(0, import_react7.useEffect)(() => {
|
|
6944
6940
|
if (range && typeof value === "object") {
|
|
6945
6941
|
setSelectedRange(value || { startDate: "", endDate: "" });
|
|
@@ -6960,17 +6956,63 @@ var DatePicker = (0, import_react7.forwardRef)((originalProps, ref) => {
|
|
|
6960
6956
|
const endContent = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon_default, { name: "calendar", size, className: "cursor-pointer", fill: true, onClick: handleCalendarIconClick });
|
|
6961
6957
|
const renderCalendar = (currentDate, isLeft) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex flex-col gap-[5px]", children: [
|
|
6962
6958
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: slots.calendarHead({ class: classNames == null ? void 0 : classNames.calendarHead }), children: dualCalendar ? isLeft ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
6963
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
6959
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
6960
|
+
icon_button_default,
|
|
6961
|
+
{
|
|
6962
|
+
name: "left",
|
|
6963
|
+
variant: "soft",
|
|
6964
|
+
color: "neutral",
|
|
6965
|
+
onClick: () => {
|
|
6966
|
+
const newLeft = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() - 1);
|
|
6967
|
+
setLeftCurrentDate(newLeft);
|
|
6968
|
+
setRightCurrentDate(new Date(newLeft.getFullYear(), newLeft.getMonth() + 1));
|
|
6969
|
+
}
|
|
6970
|
+
}
|
|
6971
|
+
),
|
|
6964
6972
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-xl font-extrabold", children: monthYearFormat(currentDate.getFullYear(), currentDate.getMonth()) }),
|
|
6965
6973
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "w-8" })
|
|
6966
6974
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
6967
6975
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "w-8" }),
|
|
6968
6976
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-xl font-extrabold", children: monthYearFormat(currentDate.getFullYear(), currentDate.getMonth()) }),
|
|
6969
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
6977
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
6978
|
+
icon_button_default,
|
|
6979
|
+
{
|
|
6980
|
+
name: "right",
|
|
6981
|
+
variant: "soft",
|
|
6982
|
+
color: "neutral",
|
|
6983
|
+
onClick: () => {
|
|
6984
|
+
const newRight = new Date(rightCurrentDate.getFullYear(), rightCurrentDate.getMonth() + 1);
|
|
6985
|
+
setRightCurrentDate(newRight);
|
|
6986
|
+
setLeftCurrentDate(new Date(newRight.getFullYear(), newRight.getMonth() - 1));
|
|
6987
|
+
}
|
|
6988
|
+
}
|
|
6989
|
+
)
|
|
6970
6990
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
6971
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
6991
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
6992
|
+
icon_button_default,
|
|
6993
|
+
{
|
|
6994
|
+
name: "left",
|
|
6995
|
+
variant: "soft",
|
|
6996
|
+
color: "neutral",
|
|
6997
|
+
onClick: () => {
|
|
6998
|
+
const newLeft = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() - 1);
|
|
6999
|
+
setLeftCurrentDate(newLeft);
|
|
7000
|
+
}
|
|
7001
|
+
}
|
|
7002
|
+
),
|
|
6972
7003
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-xl font-extrabold", children: monthYearFormat(currentDate.getFullYear(), currentDate.getMonth()) }),
|
|
6973
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
7004
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
7005
|
+
icon_button_default,
|
|
7006
|
+
{
|
|
7007
|
+
name: "right",
|
|
7008
|
+
variant: "soft",
|
|
7009
|
+
color: "neutral",
|
|
7010
|
+
onClick: () => {
|
|
7011
|
+
const newLeft = new Date(leftCurrentDate.getFullYear(), leftCurrentDate.getMonth() + 1);
|
|
7012
|
+
setLeftCurrentDate(newLeft);
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
7015
|
+
)
|
|
6974
7016
|
] }) }),
|
|
6975
7017
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "grid grid-cols-7", children: daysOfWeek.map((day, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(day_default, { variant: "text", children: day }, `${day}-${index}`)) }),
|
|
6976
7018
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "grid grid-cols-7 gap-y-[5px] text-center", children: getCalendarDates(currentDate).map((week, weekIndex) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react7.Fragment, { children: week.map((dateObj, index) => {
|