nucleus-core-ts 0.8.7 → 0.8.8
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/client.js +1 -1
- package/dist/fe/components/AbstractAnimatedBackground/index.js +437 -0
- package/dist/fe/components/AuthorizationPage/components/AuthorizationPage.js +841 -0
- package/dist/fe/components/AuthorizationPage/components/ClaimList.js +100 -0
- package/dist/fe/components/AuthorizationPage/components/RoleClaimEditor.js +232 -0
- package/dist/fe/components/AuthorizationPage/components/RoleList.js +115 -0
- package/dist/fe/components/AuthorizationPage/index.js +6 -0
- package/dist/fe/components/AuthorizationPage/store/index.js +117 -0
- package/dist/fe/components/AuthorizationPage/theme/index.js +137 -0
- package/dist/fe/components/AuthorizationPage/types/index.js +1 -0
- package/dist/fe/components/Button/components/Button.js +158 -0
- package/dist/fe/components/Button/components/ButtonSpinner.js +52 -0
- package/dist/fe/components/Button/index.js +3 -0
- package/dist/fe/components/Button/theme/index.js +186 -0
- package/dist/fe/components/Button/types/index.js +1 -0
- package/dist/fe/components/Button/utils/cn.js +5 -0
- package/dist/fe/components/Captcha/components/Captcha.js +311 -0
- package/dist/fe/components/Captcha/index.js +2 -0
- package/dist/fe/components/Captcha/theme.js +52 -0
- package/dist/fe/components/Captcha/types.js +1 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordForm.js +242 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordHeader.js +39 -0
- package/dist/fe/components/ChangePasswordPage/components/ChangePasswordPage.js +60 -0
- package/dist/fe/components/ChangePasswordPage/index.js +5 -0
- package/dist/fe/components/ChangePasswordPage/store/index.js +44 -0
- package/dist/fe/components/ChangePasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ChangePasswordPage/types/index.js +1 -0
- package/dist/fe/components/Checkbox/components/Checkbox.js +115 -0
- package/dist/fe/components/Checkbox/components/CheckboxIcon.js +119 -0
- package/dist/fe/components/Checkbox/components/SwitchTrack.js +178 -0
- package/dist/fe/components/Checkbox/index.js +4 -0
- package/dist/fe/components/Checkbox/theme/index.js +221 -0
- package/dist/fe/components/Checkbox/types/index.js +1 -0
- package/dist/fe/components/Checkbox/utils/cn.js +5 -0
- package/dist/fe/components/DataTable/DataTable.js +225 -0
- package/dist/fe/components/DataTable/components/ActionCell.js +26 -0
- package/dist/fe/components/DataTable/components/DataCell.js +76 -0
- package/dist/fe/components/DataTable/components/EditableCell.js +221 -0
- package/dist/fe/components/DataTable/components/EmptyState.js +29 -0
- package/dist/fe/components/DataTable/components/HeaderCell.js +64 -0
- package/dist/fe/components/DataTable/components/InfiniteScrollTrigger.js +66 -0
- package/dist/fe/components/DataTable/components/LoadingSpinner.js +19 -0
- package/dist/fe/components/DataTable/components/ResizeHandle.js +41 -0
- package/dist/fe/components/DataTable/components/SelectionCell.js +105 -0
- package/dist/fe/components/DataTable/components/SkeletonRow.js +56 -0
- package/dist/fe/components/DataTable/components/SkeletonTable.js +83 -0
- package/dist/fe/components/DataTable/components/SortIcon.js +39 -0
- package/dist/fe/components/DataTable/components/TableHeader.js +49 -0
- package/dist/fe/components/DataTable/components/TableRow.js +118 -0
- package/dist/fe/components/DataTable/components/index.js +14 -0
- package/dist/fe/components/DataTable/hooks/index.js +2 -0
- package/dist/fe/components/DataTable/hooks/useAutoFitColumn.js +23 -0
- package/dist/fe/components/DataTable/hooks/useResizeColumn.js +122 -0
- package/dist/fe/components/DataTable/index.js +3 -0
- package/dist/fe/components/DataTable/store/index.js +97 -0
- package/dist/fe/components/DataTable/theme/index.js +144 -0
- package/dist/fe/components/DataTable/types/index.js +1 -0
- package/dist/fe/components/DataTable/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/components/CalendarGrid.js +95 -0
- package/dist/fe/components/DatePicker/components/CalendarHeader.js +152 -0
- package/dist/fe/components/DatePicker/components/DatePicker.js +381 -0
- package/dist/fe/components/DatePicker/components/MonthYearSelector.js +93 -0
- package/dist/fe/components/DatePicker/index.js +7 -0
- package/dist/fe/components/DatePicker/locales/index.js +1113 -0
- package/dist/fe/components/DatePicker/theme/index.js +315 -0
- package/dist/fe/components/DatePicker/types/index.js +1 -0
- package/dist/fe/components/DatePicker/utils/cn.js +5 -0
- package/dist/fe/components/DatePicker/utils/date.js +132 -0
- package/dist/fe/components/DevicesPage/components/DeviceCard.js +251 -0
- package/dist/fe/components/DevicesPage/components/DevicesHeader.js +42 -0
- package/dist/fe/components/DevicesPage/components/DevicesPage.js +450 -0
- package/dist/fe/components/DevicesPage/index.js +5 -0
- package/dist/fe/components/DevicesPage/store/index.js +55 -0
- package/dist/fe/components/DevicesPage/theme/index.js +131 -0
- package/dist/fe/components/DevicesPage/types/index.js +1 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordForm.js +214 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordHeader.js +42 -0
- package/dist/fe/components/ForgotPasswordPage/components/ForgotPasswordPage.js +59 -0
- package/dist/fe/components/ForgotPasswordPage/index.js +5 -0
- package/dist/fe/components/ForgotPasswordPage/store/index.js +28 -0
- package/dist/fe/components/ForgotPasswordPage/theme/index.js +87 -0
- package/dist/fe/components/ForgotPasswordPage/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/components/FormBuilder.js +156 -0
- package/dist/fe/components/FormBuilder/components/FormField.js +218 -0
- package/dist/fe/components/FormBuilder/hooks/useFormBuilder.js +152 -0
- package/dist/fe/components/FormBuilder/index.js +4 -0
- package/dist/fe/components/FormBuilder/theme/index.js +134 -0
- package/dist/fe/components/FormBuilder/types/index.js +1 -0
- package/dist/fe/components/FormBuilder/utils/cn.js +5 -0
- package/dist/fe/components/FormBuilder/utils/fieldMapping.js +216 -0
- package/dist/fe/components/FormBuilder/utils/validation.js +78 -0
- package/dist/fe/components/LoginPage/components/LoginForm.js +214 -0
- package/dist/fe/components/LoginPage/components/LoginHeader.js +24 -0
- package/dist/fe/components/LoginPage/components/LoginPage.js +138 -0
- package/dist/fe/components/LoginPage/index.js +5 -0
- package/dist/fe/components/LoginPage/store/index.js +59 -0
- package/dist/fe/components/LoginPage/theme/index.js +98 -0
- package/dist/fe/components/LoginPage/types/index.js +1 -0
- package/dist/fe/components/MagicLinkVerifyPage/components/MagicLinkVerifyPage.js +200 -0
- package/dist/fe/components/MagicLinkVerifyPage/index.js +3 -0
- package/dist/fe/components/MagicLinkVerifyPage/store.js +20 -0
- package/dist/fe/components/MagicLinkVerifyPage/theme.js +36 -0
- package/dist/fe/components/MagicLinkVerifyPage/types.js +1 -0
- package/dist/fe/components/NucleusEntityShowcase.js +1409 -0
- package/dist/fe/components/NucleusTextInput/components/FloatingLabel.js +56 -0
- package/dist/fe/components/NucleusTextInput/components/InputIcons.js +258 -0
- package/dist/fe/components/NucleusTextInput/components/NucleusTextInput.js +321 -0
- package/dist/fe/components/NucleusTextInput/components/PasswordStrengthIndicator.js +104 -0
- package/dist/fe/components/NucleusTextInput/components/TypewriterText.js +56 -0
- package/dist/fe/components/NucleusTextInput/index.js +7 -0
- package/dist/fe/components/NucleusTextInput/theme/index.js +121 -0
- package/dist/fe/components/NucleusTextInput/types/index.js +1 -0
- package/dist/fe/components/NucleusTextInput/utils/cn.js +5 -0
- package/dist/fe/components/NucleusTextInput/utils/format.js +62 -0
- package/dist/fe/components/NucleusTextInput/utils/validation.js +191 -0
- package/dist/fe/components/ProfilePage/components/AddressCard.js +196 -0
- package/dist/fe/components/ProfilePage/components/PhoneCard.js +206 -0
- package/dist/fe/components/ProfilePage/components/ProfileHeader.js +150 -0
- package/dist/fe/components/ProfilePage/components/ProfilePage.js +1336 -0
- package/dist/fe/components/ProfilePage/index.js +6 -0
- package/dist/fe/components/ProfilePage/store/index.js +115 -0
- package/dist/fe/components/ProfilePage/theme/index.js +168 -0
- package/dist/fe/components/ProfilePage/types/index.js +1 -0
- package/dist/fe/components/RangePicker/components/RangePicker.js +338 -0
- package/dist/fe/components/RangePicker/components/RangeThumb.js +68 -0
- package/dist/fe/components/RangePicker/components/RangeTooltip.js +45 -0
- package/dist/fe/components/RangePicker/components/RangeTrack.js +32 -0
- package/dist/fe/components/RangePicker/index.js +5 -0
- package/dist/fe/components/RangePicker/theme/index.js +88 -0
- package/dist/fe/components/RangePicker/types/index.js +1 -0
- package/dist/fe/components/RangePicker/utils/cn.js +3 -0
- package/dist/fe/components/RegisterPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/RegisterPage/components/RegisterForm.js +322 -0
- package/dist/fe/components/RegisterPage/components/RegisterHeader.js +23 -0
- package/dist/fe/components/RegisterPage/components/RegisterPage.js +85 -0
- package/dist/fe/components/RegisterPage/index.js +6 -0
- package/dist/fe/components/RegisterPage/store/index.js +106 -0
- package/dist/fe/components/RegisterPage/theme/index.js +128 -0
- package/dist/fe/components/RegisterPage/types/index.js +1 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordForm.js +347 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordHeader.js +42 -0
- package/dist/fe/components/ResetPasswordPage/components/ResetPasswordPage.js +61 -0
- package/dist/fe/components/ResetPasswordPage/index.js +5 -0
- package/dist/fe/components/ResetPasswordPage/store/index.js +36 -0
- package/dist/fe/components/ResetPasswordPage/theme/index.js +99 -0
- package/dist/fe/components/ResetPasswordPage/types/index.js +1 -0
- package/dist/fe/components/SearchBox/components/SearchBox.js +271 -0
- package/dist/fe/components/SearchBox/components/SearchBoxDropdown.js +87 -0
- package/dist/fe/components/SearchBox/index.js +5 -0
- package/dist/fe/components/SearchBox/theme/index.js +184 -0
- package/dist/fe/components/SearchBox/types/index.js +1 -0
- package/dist/fe/components/SearchBox/utils/cn.js +5 -0
- package/dist/fe/components/SearchBox/utils/debounce.js +22 -0
- package/dist/fe/components/SearchBox/utils/sanitize.js +48 -0
- package/dist/fe/components/SelectBox/components/SelectBox.js +364 -0
- package/dist/fe/components/SelectBox/components/SelectDropdown.js +92 -0
- package/dist/fe/components/SelectBox/components/SelectOptionItem.js +43 -0
- package/dist/fe/components/SelectBox/components/SelectTrigger.js +22 -0
- package/dist/fe/components/SelectBox/index.js +5 -0
- package/dist/fe/components/SelectBox/theme/index.js +98 -0
- package/dist/fe/components/SelectBox/types/index.js +1 -0
- package/dist/fe/components/SelectBox/utils/cn.js +3 -0
- package/dist/fe/components/SetPasswordPage/components/PasswordStrengthIndicator.js +107 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordForm.js +142 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordHeader.js +23 -0
- package/dist/fe/components/SetPasswordPage/components/SetPasswordPage.js +263 -0
- package/dist/fe/components/SetPasswordPage/index.js +7 -0
- package/dist/fe/components/SetPasswordPage/store/index.js +79 -0
- package/dist/fe/components/SetPasswordPage/theme/index.js +98 -0
- package/dist/fe/components/SetPasswordPage/types/index.js +12 -0
- package/dist/fe/components/UsersPage/components/InviteUserModal.js +262 -0
- package/dist/fe/components/UsersPage/components/Pagination.js +147 -0
- package/dist/fe/components/UsersPage/components/RoleAssignmentModal.js +186 -0
- package/dist/fe/components/UsersPage/components/StatsCards.js +124 -0
- package/dist/fe/components/UsersPage/components/UserDetailDrawer.js +444 -0
- package/dist/fe/components/UsersPage/components/UserFilters.js +142 -0
- package/dist/fe/components/UsersPage/components/UserListItem.js +125 -0
- package/dist/fe/components/UsersPage/components/UserListSkeleton.js +40 -0
- package/dist/fe/components/UsersPage/components/UsersPage.js +556 -0
- package/dist/fe/components/UsersPage/index.js +10 -0
- package/dist/fe/components/UsersPage/store/index.js +151 -0
- package/dist/fe/components/UsersPage/theme/index.js +231 -0
- package/dist/fe/components/UsersPage/types/index.js +1 -0
- package/dist/fe/components/VerifyEmailPage/components/VerifyEmailPage.js +290 -0
- package/dist/fe/components/VerifyEmailPage/index.js +3 -0
- package/dist/fe/components/VerifyEmailPage/store/index.js +45 -0
- package/dist/fe/components/VerifyEmailPage/theme/index.js +52 -0
- package/dist/fe/components/VerifyEmailPage/types/index.js +1 -0
- package/dist/fe/hooks/useNucleusEntity.js +247 -0
- package/dist/fe/index.js +28 -157
- package/dist/fe/types/index.js +1 -0
- package/dist/fe/utils/cn.js +5 -0
- package/dist/fe/utils/columnUtils.js +189 -0
- package/dist/fe/utils/endpointKeys.js +44 -0
- package/dist/index.js +1 -1
- package/dist/src/Client/Proxy/httpProxy.js +1 -0
- package/dist/src/Client/Proxy/index.js +1 -1
- package/dist/src/Client/Proxy/server.js +1 -0
- package/dist/src/Client/Proxy/types.js +1 -0
- package/dist/src/Client/Proxy/utils.js +1 -0
- package/dist/src/Client/Proxy/wsProxy.js +1 -0
- package/package.json +1 -1
- package/scripts/build.ts +32 -16
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { getLocale } from "../locales";
|
|
7
|
+
import { datePickerTheme } from "../theme";
|
|
8
|
+
import { cn } from "../utils/cn";
|
|
9
|
+
import { addMonths, formatDateRangeWithLocale, formatDateWithLocale, startOfDay } from "../utils/date";
|
|
10
|
+
import { CalendarGrid } from "./CalendarGrid";
|
|
11
|
+
import { CalendarHeader } from "./CalendarHeader";
|
|
12
|
+
import { MonthYearSelector } from "./MonthYearSelector";
|
|
13
|
+
gsap.registerPlugin(useGSAP);
|
|
14
|
+
export function DatePicker({ mode, value, onChange, locale = "en-US", placeholder, label, disabled = false, minDate, maxDate, disabledDates, disabledDaysOfWeek, className, inputClassName, dropdownClassName, showClearButton = true, showTodayButton = true, firstDayOfWeek, leftIcon, rightIcon, errorMessage, helperText, required = false, onOpen, onClose }) {
|
|
15
|
+
const localeConfig = getLocale(locale);
|
|
16
|
+
const effectiveFirstDayOfWeek = firstDayOfWeek ?? localeConfig.firstDayOfWeek;
|
|
17
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
18
|
+
const [dropdownPosition, setDropdownPosition] = useState("bottom");
|
|
19
|
+
const [currentMonth, setCurrentMonth] = useState(()=>{
|
|
20
|
+
if (mode === "single" && value) {
|
|
21
|
+
return startOfDay(value);
|
|
22
|
+
}
|
|
23
|
+
if (mode === "range" && value?.start) {
|
|
24
|
+
const rangeValue = value;
|
|
25
|
+
return rangeValue.start ? startOfDay(rangeValue.start) : startOfDay(new Date());
|
|
26
|
+
}
|
|
27
|
+
return startOfDay(new Date());
|
|
28
|
+
});
|
|
29
|
+
const [calendarView, setCalendarView] = useState("calendar");
|
|
30
|
+
const [hoverDate, setHoverDate] = useState(null);
|
|
31
|
+
const containerRef = useRef(null);
|
|
32
|
+
const dropdownRef = useRef(null);
|
|
33
|
+
const inputId = useId();
|
|
34
|
+
const theme = datePickerTheme;
|
|
35
|
+
const selectedDate = mode === "single" ? value : null;
|
|
36
|
+
const selectedRange = mode === "range" ? value : null;
|
|
37
|
+
const displayValue = mode === "single" ? formatDateWithLocale(selectedDate, locale) : formatDateRangeWithLocale(selectedRange || {
|
|
38
|
+
start: null,
|
|
39
|
+
end: null
|
|
40
|
+
}, locale);
|
|
41
|
+
const placeholderText = placeholder || (mode === "range" ? `${localeConfig.selectStartDate} - ${localeConfig.selectEndDate}` : localeConfig.selectDate);
|
|
42
|
+
const { contextSafe } = useGSAP({
|
|
43
|
+
scope: containerRef
|
|
44
|
+
});
|
|
45
|
+
useEffect(()=>{
|
|
46
|
+
if (!isOpen) return;
|
|
47
|
+
const updatePosition = ()=>{
|
|
48
|
+
if (!containerRef.current) return;
|
|
49
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
50
|
+
const spaceBelow = window.innerHeight - rect.bottom;
|
|
51
|
+
const spaceAbove = rect.top;
|
|
52
|
+
const dropdownHeight = 400;
|
|
53
|
+
if (spaceBelow < dropdownHeight && spaceAbove > spaceBelow) {
|
|
54
|
+
setDropdownPosition("top");
|
|
55
|
+
} else {
|
|
56
|
+
setDropdownPosition("bottom");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
updatePosition();
|
|
60
|
+
window.addEventListener("scroll", updatePosition, true);
|
|
61
|
+
window.addEventListener("resize", updatePosition);
|
|
62
|
+
return ()=>{
|
|
63
|
+
window.removeEventListener("scroll", updatePosition, true);
|
|
64
|
+
window.removeEventListener("resize", updatePosition);
|
|
65
|
+
};
|
|
66
|
+
}, [
|
|
67
|
+
isOpen
|
|
68
|
+
]);
|
|
69
|
+
useEffect(()=>{
|
|
70
|
+
if (!isOpen) return;
|
|
71
|
+
const handleClickOutside = (e)=>{
|
|
72
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
73
|
+
handleClose();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const handleEscape = (e)=>{
|
|
77
|
+
if (e.key === "Escape") {
|
|
78
|
+
handleClose();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
82
|
+
document.addEventListener("keydown", handleEscape);
|
|
83
|
+
return ()=>{
|
|
84
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
85
|
+
document.removeEventListener("keydown", handleEscape);
|
|
86
|
+
};
|
|
87
|
+
}, [
|
|
88
|
+
isOpen
|
|
89
|
+
]);
|
|
90
|
+
const handleOpen = contextSafe(()=>{
|
|
91
|
+
if (disabled) return;
|
|
92
|
+
setIsOpen(true);
|
|
93
|
+
setCalendarView("calendar");
|
|
94
|
+
onOpen?.();
|
|
95
|
+
requestAnimationFrame(()=>{
|
|
96
|
+
if (dropdownRef.current) {
|
|
97
|
+
gsap.fromTo(dropdownRef.current, {
|
|
98
|
+
opacity: 0,
|
|
99
|
+
y: dropdownPosition === "bottom" ? -12 : 12,
|
|
100
|
+
scale: 0.96
|
|
101
|
+
}, {
|
|
102
|
+
opacity: 1,
|
|
103
|
+
y: 0,
|
|
104
|
+
scale: 1,
|
|
105
|
+
duration: 0.25,
|
|
106
|
+
ease: "power3.out"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
const handleClose = contextSafe(()=>{
|
|
112
|
+
if (dropdownRef.current) {
|
|
113
|
+
gsap.to(dropdownRef.current, {
|
|
114
|
+
opacity: 0,
|
|
115
|
+
y: dropdownPosition === "bottom" ? -8 : 8,
|
|
116
|
+
scale: 0.96,
|
|
117
|
+
duration: 0.15,
|
|
118
|
+
ease: "power2.in",
|
|
119
|
+
onComplete: ()=>{
|
|
120
|
+
setIsOpen(false);
|
|
121
|
+
setHoverDate(null);
|
|
122
|
+
onClose?.();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
setIsOpen(false);
|
|
127
|
+
setHoverDate(null);
|
|
128
|
+
onClose?.();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const handleDateSelect = (date)=>{
|
|
132
|
+
if (mode === "single") {
|
|
133
|
+
onChange(date);
|
|
134
|
+
handleClose();
|
|
135
|
+
} else {
|
|
136
|
+
const range = selectedRange || {
|
|
137
|
+
start: null,
|
|
138
|
+
end: null
|
|
139
|
+
};
|
|
140
|
+
if (!range.start || range.start && range.end) {
|
|
141
|
+
onChange({
|
|
142
|
+
start: date,
|
|
143
|
+
end: null
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
if (date < range.start) {
|
|
147
|
+
onChange({
|
|
148
|
+
start: date,
|
|
149
|
+
end: range.start
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
onChange({
|
|
153
|
+
start: range.start,
|
|
154
|
+
end: date
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
handleClose();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const handleClear = contextSafe(()=>{
|
|
162
|
+
if (mode === "single") {
|
|
163
|
+
onChange(null);
|
|
164
|
+
} else {
|
|
165
|
+
onChange({
|
|
166
|
+
start: null,
|
|
167
|
+
end: null
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const handleToday = ()=>{
|
|
172
|
+
const today = startOfDay(new Date());
|
|
173
|
+
setCurrentMonth(today);
|
|
174
|
+
if (mode === "single") {
|
|
175
|
+
onChange(today);
|
|
176
|
+
handleClose();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const handlePrevMonth = ()=>setCurrentMonth(addMonths(currentMonth, -1));
|
|
180
|
+
const handleNextMonth = ()=>setCurrentMonth(addMonths(currentMonth, 1));
|
|
181
|
+
const handlePrevYear = ()=>setCurrentMonth(addMonths(currentMonth, -12));
|
|
182
|
+
const handleNextYear = ()=>setCurrentMonth(addMonths(currentMonth, 12));
|
|
183
|
+
const handleMonthYearClick = ()=>{
|
|
184
|
+
setCalendarView(calendarView === "calendar" ? "month" : "calendar");
|
|
185
|
+
};
|
|
186
|
+
const handleMonthSelect = (month)=>{
|
|
187
|
+
setCurrentMonth(new Date(currentMonth.getFullYear(), month, 1));
|
|
188
|
+
setCalendarView("calendar");
|
|
189
|
+
};
|
|
190
|
+
const handleYearSelect = (year)=>{
|
|
191
|
+
setCurrentMonth(new Date(year, currentMonth.getMonth(), 1));
|
|
192
|
+
};
|
|
193
|
+
const handleInputClick = ()=>{
|
|
194
|
+
if (isOpen) {
|
|
195
|
+
handleClose();
|
|
196
|
+
} else {
|
|
197
|
+
handleOpen();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
201
|
+
ref: containerRef,
|
|
202
|
+
className: cn(theme.container.base, theme.container.spacing, className),
|
|
203
|
+
children: [
|
|
204
|
+
label && /*#__PURE__*/ _jsxs("label", {
|
|
205
|
+
htmlFor: inputId,
|
|
206
|
+
className: cn(theme.label.base, theme.label.text.size, theme.label.text.color.light, theme.label.text.color.dark, theme.label.spacing),
|
|
207
|
+
children: [
|
|
208
|
+
label,
|
|
209
|
+
required && /*#__PURE__*/ _jsx("span", {
|
|
210
|
+
className: "text-red-500 ml-1",
|
|
211
|
+
children: "*"
|
|
212
|
+
})
|
|
213
|
+
]
|
|
214
|
+
}),
|
|
215
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
216
|
+
className: "relative",
|
|
217
|
+
children: [
|
|
218
|
+
/*#__PURE__*/ _jsxs("button", {
|
|
219
|
+
id: inputId,
|
|
220
|
+
type: "button",
|
|
221
|
+
onClick: handleInputClick,
|
|
222
|
+
disabled: disabled,
|
|
223
|
+
className: cn(theme.input.wrapper.base, theme.input.wrapper.border.base, theme.input.wrapper.background.light, theme.input.wrapper.background.dark, theme.input.wrapper.padding, theme.input.wrapper.rounded, theme.input.wrapper.shadow, theme.input.wrapper.transition, isOpen && theme.input.wrapper.border.focused, errorMessage && theme.input.wrapper.border.error, disabled && theme.input.wrapper.border.disabled, inputClassName),
|
|
224
|
+
"aria-expanded": isOpen,
|
|
225
|
+
"aria-haspopup": "dialog",
|
|
226
|
+
children: [
|
|
227
|
+
leftIcon && /*#__PURE__*/ _jsx("span", {
|
|
228
|
+
className: cn(theme.input.icon.base, theme.input.icon.size, theme.input.icon.color.light, theme.input.icon.color.dark, theme.input.icon.spacing.left, isOpen && theme.input.icon.color.focused),
|
|
229
|
+
children: leftIcon
|
|
230
|
+
}),
|
|
231
|
+
!leftIcon && /*#__PURE__*/ _jsx("span", {
|
|
232
|
+
className: cn(theme.input.icon.base, theme.input.icon.size, theme.input.icon.color.light, theme.input.icon.color.dark, theme.input.icon.spacing.left, isOpen && theme.input.icon.color.focused),
|
|
233
|
+
children: /*#__PURE__*/ _jsxs("svg", {
|
|
234
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
235
|
+
viewBox: "0 0 24 24",
|
|
236
|
+
fill: "none",
|
|
237
|
+
stroke: "currentColor",
|
|
238
|
+
strokeWidth: "2",
|
|
239
|
+
strokeLinecap: "round",
|
|
240
|
+
strokeLinejoin: "round",
|
|
241
|
+
className: "w-full h-full",
|
|
242
|
+
"aria-hidden": "true",
|
|
243
|
+
children: [
|
|
244
|
+
/*#__PURE__*/ _jsx("rect", {
|
|
245
|
+
x: "3",
|
|
246
|
+
y: "4",
|
|
247
|
+
width: "18",
|
|
248
|
+
height: "18",
|
|
249
|
+
rx: "2",
|
|
250
|
+
ry: "2"
|
|
251
|
+
}),
|
|
252
|
+
/*#__PURE__*/ _jsx("line", {
|
|
253
|
+
x1: "16",
|
|
254
|
+
y1: "2",
|
|
255
|
+
x2: "16",
|
|
256
|
+
y2: "6"
|
|
257
|
+
}),
|
|
258
|
+
/*#__PURE__*/ _jsx("line", {
|
|
259
|
+
x1: "8",
|
|
260
|
+
y1: "2",
|
|
261
|
+
x2: "8",
|
|
262
|
+
y2: "6"
|
|
263
|
+
}),
|
|
264
|
+
/*#__PURE__*/ _jsx("line", {
|
|
265
|
+
x1: "3",
|
|
266
|
+
y1: "10",
|
|
267
|
+
x2: "21",
|
|
268
|
+
y2: "10"
|
|
269
|
+
})
|
|
270
|
+
]
|
|
271
|
+
})
|
|
272
|
+
}),
|
|
273
|
+
/*#__PURE__*/ _jsx("span", {
|
|
274
|
+
className: cn(theme.input.text.base, theme.input.text.size, displayValue ? cn(theme.input.text.color.light, theme.input.text.color.dark) : cn(theme.input.text.placeholder.light, theme.input.text.placeholder.dark), "text-left"),
|
|
275
|
+
children: displayValue || placeholderText
|
|
276
|
+
}),
|
|
277
|
+
rightIcon && /*#__PURE__*/ _jsx("span", {
|
|
278
|
+
className: cn(theme.input.icon.base, theme.input.icon.size, theme.input.icon.color.light, theme.input.icon.color.dark, theme.input.icon.spacing.right, isOpen && theme.input.icon.color.focused),
|
|
279
|
+
children: rightIcon
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
}),
|
|
283
|
+
isOpen && /*#__PURE__*/ _jsx("div", {
|
|
284
|
+
ref: dropdownRef,
|
|
285
|
+
className: cn(theme.dropdown.base, theme.dropdown.background.light, theme.dropdown.background.dark, theme.dropdown.border.light, theme.dropdown.border.dark, theme.dropdown.rounded, theme.dropdown.shadow, theme.dropdown.padding, dropdownPosition === "top" && theme.dropdown.position.top, dropdownPosition === "top" && theme.dropdown.spacing.top, dropdownPosition === "bottom" && theme.dropdown.position.bottom, dropdownPosition === "bottom" && theme.dropdown.spacing.bottom, dropdownClassName),
|
|
286
|
+
role: "dialog",
|
|
287
|
+
"aria-modal": "true",
|
|
288
|
+
"aria-label": localeConfig.selectDate,
|
|
289
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
290
|
+
className: theme.calendar.base,
|
|
291
|
+
children: [
|
|
292
|
+
mode === "range" && /*#__PURE__*/ _jsxs("div", {
|
|
293
|
+
className: cn(theme.rangeIndicator.base, theme.rangeIndicator.padding, "border-b", theme.footer.border.light, theme.footer.border.dark),
|
|
294
|
+
children: [
|
|
295
|
+
/*#__PURE__*/ _jsx("div", {
|
|
296
|
+
className: cn("flex-1 text-center", theme.rangeIndicator.text.size, selectedRange?.start ? cn(theme.input.text.color.light, theme.input.text.color.dark) : cn(theme.rangeIndicator.text.color.light, theme.rangeIndicator.text.color.dark)),
|
|
297
|
+
children: selectedRange?.start ? formatDateWithLocale(selectedRange.start, locale) : localeConfig.selectStartDate
|
|
298
|
+
}),
|
|
299
|
+
/*#__PURE__*/ _jsx("span", {
|
|
300
|
+
className: cn(theme.rangeIndicator.separator, theme.rangeIndicator.text.color.light),
|
|
301
|
+
children: "→"
|
|
302
|
+
}),
|
|
303
|
+
/*#__PURE__*/ _jsx("div", {
|
|
304
|
+
className: cn("flex-1 text-center", theme.rangeIndicator.text.size, selectedRange?.end ? cn(theme.input.text.color.light, theme.input.text.color.dark) : cn(theme.rangeIndicator.text.color.light, theme.rangeIndicator.text.color.dark)),
|
|
305
|
+
children: selectedRange?.end ? formatDateWithLocale(selectedRange.end, locale) : localeConfig.selectEndDate
|
|
306
|
+
})
|
|
307
|
+
]
|
|
308
|
+
}),
|
|
309
|
+
calendarView === "calendar" ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
310
|
+
children: [
|
|
311
|
+
/*#__PURE__*/ _jsx(CalendarHeader, {
|
|
312
|
+
currentMonth: currentMonth,
|
|
313
|
+
onPrevMonth: handlePrevMonth,
|
|
314
|
+
onNextMonth: handleNextMonth,
|
|
315
|
+
onPrevYear: handlePrevYear,
|
|
316
|
+
onNextYear: handleNextYear,
|
|
317
|
+
onMonthYearClick: handleMonthYearClick,
|
|
318
|
+
locale: locale,
|
|
319
|
+
minDate: minDate,
|
|
320
|
+
maxDate: maxDate
|
|
321
|
+
}),
|
|
322
|
+
/*#__PURE__*/ _jsx(CalendarGrid, {
|
|
323
|
+
currentMonth: currentMonth,
|
|
324
|
+
selectedDate: selectedDate,
|
|
325
|
+
selectedRange: selectedRange,
|
|
326
|
+
mode: mode,
|
|
327
|
+
locale: locale,
|
|
328
|
+
minDate: minDate,
|
|
329
|
+
maxDate: maxDate,
|
|
330
|
+
disabledDates: disabledDates,
|
|
331
|
+
disabledDaysOfWeek: disabledDaysOfWeek,
|
|
332
|
+
firstDayOfWeek: effectiveFirstDayOfWeek,
|
|
333
|
+
onDateSelect: handleDateSelect,
|
|
334
|
+
hoverDate: hoverDate,
|
|
335
|
+
onHoverChange: setHoverDate
|
|
336
|
+
})
|
|
337
|
+
]
|
|
338
|
+
}) : /*#__PURE__*/ _jsx(MonthYearSelector, {
|
|
339
|
+
currentMonth: currentMonth,
|
|
340
|
+
onMonthSelect: handleMonthSelect,
|
|
341
|
+
onYearSelect: handleYearSelect,
|
|
342
|
+
locale: locale,
|
|
343
|
+
minDate: minDate,
|
|
344
|
+
maxDate: maxDate,
|
|
345
|
+
view: calendarView === "month" ? "month" : "year",
|
|
346
|
+
onViewChange: (v)=>setCalendarView(v),
|
|
347
|
+
onClose: ()=>setCalendarView("calendar")
|
|
348
|
+
}),
|
|
349
|
+
(showTodayButton || showClearButton) && /*#__PURE__*/ _jsxs("div", {
|
|
350
|
+
className: cn(theme.footer.base, theme.footer.padding, theme.footer.border.light, theme.footer.border.dark),
|
|
351
|
+
children: [
|
|
352
|
+
showClearButton && /*#__PURE__*/ _jsx("button", {
|
|
353
|
+
type: "button",
|
|
354
|
+
onClick: handleClear,
|
|
355
|
+
className: cn(theme.footer.button.base, theme.footer.button.padding, theme.footer.button.rounded, theme.footer.button.text.size, theme.footer.button.clear.background, theme.footer.button.clear.text.light, theme.footer.button.clear.text.dark, theme.footer.button.clear.hover.light, theme.footer.button.clear.hover.dark, theme.footer.button.transition),
|
|
356
|
+
children: localeConfig.clear
|
|
357
|
+
}),
|
|
358
|
+
showTodayButton && /*#__PURE__*/ _jsx("button", {
|
|
359
|
+
type: "button",
|
|
360
|
+
onClick: handleToday,
|
|
361
|
+
className: cn(theme.footer.button.base, theme.footer.button.padding, theme.footer.button.rounded, theme.footer.button.text.size, theme.footer.button.today.background.light, theme.footer.button.today.background.dark, theme.footer.button.today.text.light, theme.footer.button.today.text.dark, theme.footer.button.today.hover.light, theme.footer.button.today.hover.dark, theme.footer.button.transition),
|
|
362
|
+
children: localeConfig.today
|
|
363
|
+
})
|
|
364
|
+
]
|
|
365
|
+
})
|
|
366
|
+
]
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
]
|
|
370
|
+
}),
|
|
371
|
+
errorMessage && /*#__PURE__*/ _jsx("span", {
|
|
372
|
+
className: cn(theme.errorText.base, theme.errorText.text, theme.errorText.color),
|
|
373
|
+
children: errorMessage
|
|
374
|
+
}),
|
|
375
|
+
helperText && !errorMessage && /*#__PURE__*/ _jsx("span", {
|
|
376
|
+
className: cn(theme.helperText.base, theme.helperText.text, theme.helperText.color.light, theme.helperText.color.dark),
|
|
377
|
+
children: helperText
|
|
378
|
+
})
|
|
379
|
+
]
|
|
380
|
+
});
|
|
381
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useGSAP } from "@gsap/react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { getLocale } from "../locales";
|
|
7
|
+
import { datePickerTheme } from "../theme";
|
|
8
|
+
import { cn } from "../utils/cn";
|
|
9
|
+
import { getYearRange } from "../utils/date";
|
|
10
|
+
gsap.registerPlugin(useGSAP);
|
|
11
|
+
export function MonthYearSelector({ currentMonth, onMonthSelect, onYearSelect, locale, minDate, maxDate, view, onViewChange, onClose }) {
|
|
12
|
+
const containerRef = useRef(null);
|
|
13
|
+
const theme = datePickerTheme;
|
|
14
|
+
const localeConfig = getLocale(locale);
|
|
15
|
+
const currentYear = currentMonth.getFullYear();
|
|
16
|
+
const currentMonthIndex = currentMonth.getMonth();
|
|
17
|
+
const years = getYearRange(currentYear, 16);
|
|
18
|
+
useGSAP(()=>{
|
|
19
|
+
if (!containerRef.current) return;
|
|
20
|
+
const items = containerRef.current.querySelectorAll("[data-item]");
|
|
21
|
+
gsap.fromTo(items, {
|
|
22
|
+
opacity: 0,
|
|
23
|
+
scale: 0.9
|
|
24
|
+
}, {
|
|
25
|
+
opacity: 1,
|
|
26
|
+
scale: 1,
|
|
27
|
+
duration: 0.25,
|
|
28
|
+
stagger: 0.02,
|
|
29
|
+
ease: "power2.out"
|
|
30
|
+
});
|
|
31
|
+
}, [
|
|
32
|
+
view
|
|
33
|
+
]);
|
|
34
|
+
const handleMonthClick = (monthIndex)=>{
|
|
35
|
+
onMonthSelect(monthIndex);
|
|
36
|
+
onClose();
|
|
37
|
+
};
|
|
38
|
+
const handleYearClick = (year)=>{
|
|
39
|
+
onYearSelect(year);
|
|
40
|
+
onViewChange("month");
|
|
41
|
+
};
|
|
42
|
+
if (view === "year") {
|
|
43
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
44
|
+
ref: containerRef,
|
|
45
|
+
className: theme.yearSelector.base,
|
|
46
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
47
|
+
className: theme.yearSelector.grid,
|
|
48
|
+
children: years.map((year)=>{
|
|
49
|
+
const isSelected = year === currentYear;
|
|
50
|
+
const isDisabled = minDate && year < minDate.getFullYear() || maxDate && year > maxDate.getFullYear();
|
|
51
|
+
return /*#__PURE__*/ _jsx("button", {
|
|
52
|
+
type: "button",
|
|
53
|
+
"data-item": true,
|
|
54
|
+
onClick: ()=>handleYearClick(year),
|
|
55
|
+
disabled: isDisabled,
|
|
56
|
+
className: cn(theme.yearSelector.item.base, theme.yearSelector.item.padding, theme.yearSelector.item.rounded, theme.yearSelector.item.text.size, theme.yearSelector.item.transition, isSelected ? cn(theme.yearSelector.item.selected.background, theme.yearSelector.item.selected.text) : cn(theme.yearSelector.item.text.color.light, theme.yearSelector.item.text.color.dark, theme.yearSelector.item.hover.light, theme.yearSelector.item.hover.dark), isDisabled && "opacity-30 cursor-not-allowed"),
|
|
57
|
+
children: year
|
|
58
|
+
}, year);
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
64
|
+
ref: containerRef,
|
|
65
|
+
className: theme.monthSelector.base,
|
|
66
|
+
children: [
|
|
67
|
+
/*#__PURE__*/ _jsx("div", {
|
|
68
|
+
className: "flex justify-center mb-3",
|
|
69
|
+
children: /*#__PURE__*/ _jsx("button", {
|
|
70
|
+
type: "button",
|
|
71
|
+
onClick: ()=>onViewChange("year"),
|
|
72
|
+
className: cn(theme.header.title.base, theme.header.title.text.size, theme.header.title.text.weight, theme.header.title.text.color.light, theme.header.title.text.color.dark, theme.header.title.hover.light, theme.header.title.hover.dark, theme.header.title.rounded, theme.header.title.padding, theme.header.title.transition),
|
|
73
|
+
children: currentYear
|
|
74
|
+
})
|
|
75
|
+
}),
|
|
76
|
+
/*#__PURE__*/ _jsx("div", {
|
|
77
|
+
className: theme.monthSelector.grid,
|
|
78
|
+
children: localeConfig.monthsShort.map((month, index)=>{
|
|
79
|
+
const isSelected = index === currentMonthIndex;
|
|
80
|
+
const isDisabled = minDate && new Date(currentYear, index + 1, 0) < minDate || maxDate && new Date(currentYear, index, 1) > maxDate;
|
|
81
|
+
return /*#__PURE__*/ _jsx("button", {
|
|
82
|
+
type: "button",
|
|
83
|
+
"data-item": true,
|
|
84
|
+
onClick: ()=>handleMonthClick(index),
|
|
85
|
+
disabled: isDisabled,
|
|
86
|
+
className: cn(theme.monthSelector.item.base, theme.monthSelector.item.padding, theme.monthSelector.item.rounded, theme.monthSelector.item.text.size, theme.monthSelector.item.transition, isSelected ? cn(theme.monthSelector.item.selected.background, theme.monthSelector.item.selected.text) : cn(theme.monthSelector.item.text.color.light, theme.monthSelector.item.text.color.dark, theme.monthSelector.item.hover.light, theme.monthSelector.item.hover.dark), isDisabled && "opacity-30 cursor-not-allowed"),
|
|
87
|
+
children: month
|
|
88
|
+
}, month);
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CalendarGrid } from "./components/CalendarGrid";
|
|
2
|
+
export { CalendarHeader } from "./components/CalendarHeader";
|
|
3
|
+
export { DatePicker } from "./components/DatePicker";
|
|
4
|
+
export { MonthYearSelector } from "./components/MonthYearSelector";
|
|
5
|
+
export { getAvailableLocales, getLocale, locales } from "./locales";
|
|
6
|
+
export { datePickerTheme, extendDatePickerTheme } from "./theme";
|
|
7
|
+
export { addMonths, addYears, endOfMonth, formatDate, formatDateRange, formatDateRangeWithLocale, formatDateWithLocale, getCalendarDays, getMonthDays, getWeekdaysForLocale, getYearRange, isDateDisabled, isDateInRange, isSameDay, isSameMonth, isToday, parseDate, startOfDay, startOfMonth } from "./utils/date";
|