@itilite/lumina-ui 1.0.4-alpha → 1.0.5-alpha
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/dist/atom/AdvancedDateRangePicker/AdvancedDateRangePicker.js +5 -4
- package/dist/atom/AdvancedDateRangePicker/AdvancedDateRangePicker.mjs +2 -2
- package/dist/atom/AdvancedDateRangePicker/InternalCalendar.js +1 -1
- package/dist/atom/AdvancedDateRangePicker/InternalCalendar.mjs +1 -1
- package/dist/chunk-5JXIJTAS.mjs +448 -0
- package/dist/chunk-FPH63V2R.mjs +269 -0
- package/dist/chunk-SRKN7WS7.mjs +448 -0
- package/dist/chunk-UC4NTBDH.mjs +439 -0
- package/dist/chunk-XIVTXS3Y.mjs +439 -0
- package/dist/index.js +5 -4
- package/dist/index.mjs +10 -10
- package/dist/styles.css +857 -807
- package/package.json +1 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Chevron
|
|
3
|
+
} from "./chunk-ZTRM4HZJ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/atom/AdvancedDateRangePicker/InternalCalendar.tsx
|
|
6
|
+
import { memo, useEffect, useRef, useState } from "react";
|
|
7
|
+
import dayjs from "dayjs";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var InternalCalendar = ({
|
|
10
|
+
id = "",
|
|
11
|
+
onChange = () => {
|
|
12
|
+
},
|
|
13
|
+
dateRange = ["", ""],
|
|
14
|
+
showSingleCalendar: showSingleCalendarProp = false,
|
|
15
|
+
disablePastDates = false,
|
|
16
|
+
minDate = null,
|
|
17
|
+
maxDate = null,
|
|
18
|
+
minYear = 1900,
|
|
19
|
+
maxYear = (/* @__PURE__ */ new Date()).getFullYear() + 10,
|
|
20
|
+
allowSameDates = false
|
|
21
|
+
}) => {
|
|
22
|
+
const onChangeRef = useRef(onChange);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
onChangeRef.current = onChange;
|
|
25
|
+
}, [onChange]);
|
|
26
|
+
const getInitialDate = () => {
|
|
27
|
+
const today2 = /* @__PURE__ */ new Date();
|
|
28
|
+
today2.setHours(0, 0, 0, 0);
|
|
29
|
+
if (dateRange[0]) return new Date(dateRange[0]);
|
|
30
|
+
if (today2.getFullYear() >= minYear && today2.getFullYear() <= maxYear) {
|
|
31
|
+
return today2;
|
|
32
|
+
}
|
|
33
|
+
if (minDate) {
|
|
34
|
+
const minDateTime = new Date(minDate);
|
|
35
|
+
minDateTime.setHours(0, 0, 0, 0);
|
|
36
|
+
return minDateTime;
|
|
37
|
+
}
|
|
38
|
+
return today2;
|
|
39
|
+
};
|
|
40
|
+
const [currentDate, setCurrentDate] = useState(() => getInitialDate());
|
|
41
|
+
const [startDate, setStartDate] = useState(
|
|
42
|
+
dateRange[0] ? new Date(dateRange[0]) : null
|
|
43
|
+
);
|
|
44
|
+
const [endDate, setEndDate] = useState(
|
|
45
|
+
dateRange[0] && dateRange[1] ? new Date(dateRange[1]) : null
|
|
46
|
+
);
|
|
47
|
+
const [hoverDate, setHoverDate] = useState(null);
|
|
48
|
+
const [isSelectingEnd, setIsSelectingEnd] = useState(
|
|
49
|
+
dateRange[0] && !dateRange[1] ? true : false
|
|
50
|
+
);
|
|
51
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const checkMobile = () => {
|
|
54
|
+
setIsMobile(window.innerWidth <= 768);
|
|
55
|
+
};
|
|
56
|
+
checkMobile();
|
|
57
|
+
window.addEventListener("resize", checkMobile);
|
|
58
|
+
return () => window.removeEventListener("resize", checkMobile);
|
|
59
|
+
}, []);
|
|
60
|
+
const showSingle = showSingleCalendarProp || isMobile;
|
|
61
|
+
const prevRangeRef = useRef(dateRange);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const isSameRange = dateRange[0] === prevRangeRef.current[0] && dateRange[1] === prevRangeRef.current[1];
|
|
64
|
+
if (isSameRange) return;
|
|
65
|
+
prevRangeRef.current = dateRange;
|
|
66
|
+
const nextStart = dateRange[0] ? new Date(dateRange[0]) : null;
|
|
67
|
+
const nextEnd = dateRange[1] ? new Date(dateRange[1]) : null;
|
|
68
|
+
setStartDate(nextStart);
|
|
69
|
+
setEndDate(nextEnd);
|
|
70
|
+
if (nextStart) {
|
|
71
|
+
const startMonth = nextStart.getFullYear() * 12 + nextStart.getMonth();
|
|
72
|
+
const currentMonthVal = currentDate.getFullYear() * 12 + currentDate.getMonth();
|
|
73
|
+
const isVisibleInFirst = startMonth === currentMonthVal;
|
|
74
|
+
const isVisibleInSecond = !showSingle && startMonth === currentMonthVal + 1;
|
|
75
|
+
if (!isVisibleInFirst && !isVisibleInSecond) {
|
|
76
|
+
setCurrentDate(new Date(nextStart.getFullYear(), nextStart.getMonth(), 1));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, [dateRange, showSingle]);
|
|
80
|
+
const today = /* @__PURE__ */ new Date();
|
|
81
|
+
today.setHours(0, 0, 0, 0);
|
|
82
|
+
const firstMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
|
|
83
|
+
const secondMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1);
|
|
84
|
+
const monthNames = [
|
|
85
|
+
"January",
|
|
86
|
+
"February",
|
|
87
|
+
"March",
|
|
88
|
+
"April",
|
|
89
|
+
"May",
|
|
90
|
+
"June",
|
|
91
|
+
"July",
|
|
92
|
+
"August",
|
|
93
|
+
"September",
|
|
94
|
+
"October",
|
|
95
|
+
"November",
|
|
96
|
+
"December"
|
|
97
|
+
];
|
|
98
|
+
const dayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
99
|
+
const generateCalendarDays = (monthDate) => {
|
|
100
|
+
const year = monthDate.getFullYear();
|
|
101
|
+
const month = monthDate.getMonth();
|
|
102
|
+
const firstDay = new Date(year, month, 1);
|
|
103
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
104
|
+
const daysInMonth = lastDay.getDate();
|
|
105
|
+
const startingDayOfWeek = firstDay.getDay();
|
|
106
|
+
const days = [];
|
|
107
|
+
for (let i = 0; i < startingDayOfWeek; i++) days.push(null);
|
|
108
|
+
for (let day = 1; day <= daysInMonth; day++) days.push(new Date(year, month, day));
|
|
109
|
+
return days;
|
|
110
|
+
};
|
|
111
|
+
const isSameDate = (d1, d2) => {
|
|
112
|
+
if (!d1 || !d2) return false;
|
|
113
|
+
return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
114
|
+
};
|
|
115
|
+
const isDateDisabled = (date) => {
|
|
116
|
+
if (!date) return false;
|
|
117
|
+
const checkDate = new Date(date);
|
|
118
|
+
checkDate.setHours(0, 0, 0, 0);
|
|
119
|
+
if (disablePastDates && checkDate < today) return true;
|
|
120
|
+
if (minDate) {
|
|
121
|
+
const m = new Date(minDate);
|
|
122
|
+
m.setHours(0, 0, 0, 0);
|
|
123
|
+
if (checkDate < m) return true;
|
|
124
|
+
}
|
|
125
|
+
if (maxDate) {
|
|
126
|
+
const m = new Date(maxDate);
|
|
127
|
+
m.setHours(0, 0, 0, 0);
|
|
128
|
+
if (checkDate > m) return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
};
|
|
132
|
+
const isDateBetweenRange = (date) => {
|
|
133
|
+
if (!startDate || !date) return false;
|
|
134
|
+
const comp = endDate || hoverDate;
|
|
135
|
+
if (!comp) return false;
|
|
136
|
+
const s = startDate < comp ? startDate : comp;
|
|
137
|
+
const e = startDate < comp ? comp : startDate;
|
|
138
|
+
return date > s && date < e;
|
|
139
|
+
};
|
|
140
|
+
const isDateInRange = (date) => {
|
|
141
|
+
if (!startDate || !date) return false;
|
|
142
|
+
const comp = endDate || hoverDate;
|
|
143
|
+
if (!comp) return false;
|
|
144
|
+
const s = startDate < comp ? startDate : comp;
|
|
145
|
+
const e = startDate < comp ? comp : startDate;
|
|
146
|
+
return date >= s && date <= e;
|
|
147
|
+
};
|
|
148
|
+
const handleDateClick = (date) => {
|
|
149
|
+
if (isDateDisabled(date)) return;
|
|
150
|
+
let nextStart = startDate;
|
|
151
|
+
let nextEnd = endDate;
|
|
152
|
+
const isSame = startDate && dayjs(date).isSame(startDate, "day");
|
|
153
|
+
if (!allowSameDates && isSame) {
|
|
154
|
+
setStartDate(null);
|
|
155
|
+
setEndDate(null);
|
|
156
|
+
setIsSelectingEnd(false);
|
|
157
|
+
onChangeRef.current(["", ""]);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!startDate || startDate && endDate) {
|
|
161
|
+
nextStart = date;
|
|
162
|
+
nextEnd = null;
|
|
163
|
+
setStartDate(nextStart);
|
|
164
|
+
setEndDate(nextEnd);
|
|
165
|
+
setIsSelectingEnd(true);
|
|
166
|
+
} else {
|
|
167
|
+
if (date < startDate) {
|
|
168
|
+
nextEnd = startDate;
|
|
169
|
+
nextStart = date;
|
|
170
|
+
} else {
|
|
171
|
+
nextEnd = date;
|
|
172
|
+
}
|
|
173
|
+
setStartDate(nextStart);
|
|
174
|
+
setEndDate(nextEnd);
|
|
175
|
+
setIsSelectingEnd(false);
|
|
176
|
+
}
|
|
177
|
+
onChangeRef.current([
|
|
178
|
+
nextStart ? dayjs(nextStart).format("D MMM, YYYY") : "",
|
|
179
|
+
nextEnd ? dayjs(nextEnd).format("D MMM, YYYY") : ""
|
|
180
|
+
]);
|
|
181
|
+
};
|
|
182
|
+
const handleDateHover = (date) => {
|
|
183
|
+
if (isDateDisabled(date)) return;
|
|
184
|
+
if (isSelectingEnd && startDate && !endDate) setHoverDate(date);
|
|
185
|
+
};
|
|
186
|
+
const navigateMonth = (direction) => {
|
|
187
|
+
const newDate = new Date(currentDate);
|
|
188
|
+
newDate.setMonth(currentDate.getMonth() + direction);
|
|
189
|
+
setCurrentDate(newDate);
|
|
190
|
+
};
|
|
191
|
+
const renderCalendar = (monthDate) => {
|
|
192
|
+
const days = generateCalendarDays(monthDate);
|
|
193
|
+
const monthName = monthNames[monthDate.getMonth()];
|
|
194
|
+
const year = monthDate.getFullYear();
|
|
195
|
+
return /* @__PURE__ */ jsxs("div", { className: "tw-flex-1 tw-mb-2", children: [
|
|
196
|
+
/* @__PURE__ */ jsx("div", { className: "tw-text-center tw-mb-4", children: /* @__PURE__ */ jsxs("h3", { className: "tw-typography-footNoteBold tw-text-gray-900 tw-m-0", children: [
|
|
197
|
+
monthName,
|
|
198
|
+
" ",
|
|
199
|
+
year
|
|
200
|
+
] }) }),
|
|
201
|
+
/* @__PURE__ */ jsx("div", { className: "tw-grid tw-grid-cols-7 tw-mb-2", children: dayNames.map((day) => /* @__PURE__ */ jsx("div", { className: "tw-py-2 tw-text-center tw-typography-caption2 tw-text-gray-500", children: day }, day)) }),
|
|
202
|
+
/* @__PURE__ */ jsx("div", { className: "tw-grid tw-grid-cols-7", children: days.map((date, index) => {
|
|
203
|
+
if (!date) return /* @__PURE__ */ jsx("div", { className: "tw-h-7" }, index);
|
|
204
|
+
const isStart = isSameDate(date, startDate);
|
|
205
|
+
const isEnd = isSameDate(date, endDate);
|
|
206
|
+
const isInRange = isDateBetweenRange(date);
|
|
207
|
+
const isSelected = isDateInRange(date);
|
|
208
|
+
const isDisabled = isDateDisabled(date);
|
|
209
|
+
const isHovering = isSelectingEnd && hoverDate && isSameDate(date, hoverDate);
|
|
210
|
+
let cellClasses = "tw-relative tw-z-20 tw-h-7 tw-w-7 tw-flex tw-items-center tw-justify-center tw-typography-caption1Bold tw-cursor-pointer tw-transition-all ";
|
|
211
|
+
if (isDisabled) {
|
|
212
|
+
cellClasses += "tw-text-gray-300 tw-cursor-not-allowed ";
|
|
213
|
+
} else if (isStart || isEnd) {
|
|
214
|
+
cellClasses += "tw-bg-black tw-text-white tw-rounded-full ";
|
|
215
|
+
} else if (isInRange) {
|
|
216
|
+
cellClasses += "tw-text-gray-900 ";
|
|
217
|
+
} else {
|
|
218
|
+
cellClasses += "tw-text-gray-700 hover:tw-bg-gray-100 tw-rounded-full ";
|
|
219
|
+
}
|
|
220
|
+
if (isHovering && !isEnd) {
|
|
221
|
+
cellClasses += "tw-border-2 tw-border-gray-400 tw-border-dashed ";
|
|
222
|
+
}
|
|
223
|
+
return /* @__PURE__ */ jsxs("div", { className: "tw-relative tw-flex tw-justify-center", children: [
|
|
224
|
+
isInRange && /* @__PURE__ */ jsx("div", { className: "tw-absolute tw-inset-y-1 tw-inset-x-0 tw-bg-[#E5E9ED] tw-z-10" }),
|
|
225
|
+
isStart && endDate && !isSameDate(startDate, endDate) && /* @__PURE__ */ jsx("div", { className: "tw-absolute tw-inset-y-1 tw-right-0 tw-left-1/2 tw-bg-[#E5E9ED] tw-z-10" }),
|
|
226
|
+
isEnd && startDate && !isSameDate(startDate, endDate) && /* @__PURE__ */ jsx("div", { className: "tw-absolute tw-inset-y-1 tw-left-0 tw-right-1/2 tw-bg-[#E5E9ED] tw-z-10" }),
|
|
227
|
+
/* @__PURE__ */ jsx(
|
|
228
|
+
"div",
|
|
229
|
+
{
|
|
230
|
+
className: cellClasses,
|
|
231
|
+
onClick: () => handleDateClick(date),
|
|
232
|
+
onMouseEnter: () => handleDateHover(date),
|
|
233
|
+
children: date.getDate()
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
] }, date.toISOString());
|
|
237
|
+
}) })
|
|
238
|
+
] });
|
|
239
|
+
};
|
|
240
|
+
return /* @__PURE__ */ jsxs("div", { className: "tw-relative tw-bg-white tw-w-full", children: [
|
|
241
|
+
/* @__PURE__ */ jsxs("div", { className: "tw-flex tw-items-center tw-justify-between tw-absolute tw-inset-x-0 tw-top-0 tw-z-30 tw-px-4", children: [
|
|
242
|
+
/* @__PURE__ */ jsx(
|
|
243
|
+
"div",
|
|
244
|
+
{
|
|
245
|
+
className: "tw-cursor-pointer tw-p-2 tw-rounded-full hover:tw-bg-gray-100",
|
|
246
|
+
onClick: () => navigateMonth(-1),
|
|
247
|
+
children: /* @__PURE__ */ jsx(Chevron, { size: "medium" })
|
|
248
|
+
}
|
|
249
|
+
),
|
|
250
|
+
/* @__PURE__ */ jsx(
|
|
251
|
+
"div",
|
|
252
|
+
{
|
|
253
|
+
className: "tw-cursor-pointer tw-p-2 tw-rounded-full hover:tw-bg-gray-100",
|
|
254
|
+
onClick: () => navigateMonth(1),
|
|
255
|
+
children: /* @__PURE__ */ jsx(Chevron, { size: "medium", className: "tw-rotate-180" })
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
] }),
|
|
259
|
+
/* @__PURE__ */ jsxs("div", { className: "tw-flex tw-gap-8 tw-pt-2", children: [
|
|
260
|
+
renderCalendar(firstMonth),
|
|
261
|
+
!showSingle && renderCalendar(secondMonth)
|
|
262
|
+
] })
|
|
263
|
+
] });
|
|
264
|
+
};
|
|
265
|
+
var InternalCalendar_default = memo(InternalCalendar);
|
|
266
|
+
|
|
267
|
+
export {
|
|
268
|
+
InternalCalendar_default
|
|
269
|
+
};
|