medos-sdk 1.1.11 → 1.1.12
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/MedosClient.js +1 -1
- package/dist/components/appointment-booking/AppointmentCalender.js +10 -72
- package/dist/components/appointment-booking/appointment-modal-styles.d.ts +272 -0
- package/dist/components/appointment-booking/appointment-modal-styles.js +419 -0
- package/dist/components/appointment-booking/components/AppointmentConfirmationStep.d.ts +28 -0
- package/dist/components/appointment-booking/components/AppointmentConfirmationStep.js +107 -0
- package/dist/components/appointment-booking/components/AppointmentDateTimeModal.d.ts +18 -0
- package/dist/components/appointment-booking/components/AppointmentDateTimeModal.js +306 -0
- package/dist/components/appointment-booking/components/AppointmentSummaryStep.d.ts +12 -0
- package/dist/components/appointment-booking/components/AppointmentSummaryStep.js +194 -0
- package/dist/components/appointment-booking/components/BookingOptionStep.d.ts +14 -0
- package/dist/components/appointment-booking/components/BookingOptionStep.js +350 -0
- package/dist/components/appointment-booking/components/DoctorSelectModal.d.ts +14 -0
- package/dist/components/appointment-booking/components/DoctorSelectModal.js +213 -0
- package/dist/components/appointment-booking/components/PatientDetailsStep.d.ts +3 -0
- package/dist/components/appointment-booking/components/PatientDetailsStep.js +96 -0
- package/dist/components/appointment-booking/components/PatientSelectionStep.d.ts +12 -0
- package/dist/components/appointment-booking/components/PatientSelectionStep.js +254 -0
- package/dist/components/appointment-booking/components/PhoneVerificationStep.d.ts +3 -0
- package/dist/components/appointment-booking/components/PhoneVerificationStep.js +49 -0
- package/dist/components/appointment-booking/components/SuccessStep.d.ts +5 -0
- package/dist/components/appointment-booking/components/SuccessStep.js +9 -0
- package/dist/components/appointment-booking/components/index.d.ts +9 -0
- package/dist/components/appointment-booking/components/index.js +9 -0
- package/dist/components/appointment-booking/hooks/useAppointmentFlow.js +1 -0
- package/dist/components/appointment-booking/index.d.ts +2 -4
- package/dist/components/appointment-booking/index.js +2 -2
- package/dist/components/appointment-booking/types.d.ts +4 -0
- package/dist/components/constants/constant.d.ts +2 -0
- package/dist/components/constants/constant.js +15 -0
- package/dist/components/constants/index.d.ts +3 -0
- package/dist/components/constants/index.js +24 -0
- package/dist/components/constants/options.d.ts +13 -0
- package/dist/components/constants/options.js +35 -0
- package/dist/components/constants/validation.d.ts +6 -0
- package/dist/components/constants/validation.js +16 -0
- package/dist/components/enquiry-form/EnquiryForm.d.ts +7 -0
- package/dist/components/enquiry-form/EnquiryForm.js +238 -0
- package/dist/components/enquiry-form/components/ContactInformationStep.d.ts +13 -0
- package/dist/components/enquiry-form/components/ContactInformationStep.js +21 -0
- package/dist/components/enquiry-form/components/ContactPreferenceStep.d.ts +9 -0
- package/dist/components/enquiry-form/components/ContactPreferenceStep.js +20 -0
- package/dist/components/enquiry-form/components/InquiryDetailsStep.d.ts +10 -0
- package/dist/components/enquiry-form/components/InquiryDetailsStep.js +20 -0
- package/dist/components/enquiry-form/components/index.d.ts +3 -0
- package/dist/components/enquiry-form/components/index.js +3 -0
- package/dist/components/enquiry-form/index.d.ts +2 -0
- package/dist/components/enquiry-form/index.js +2 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +7 -0
- package/dist/components/shared/icons/Check.d.ts +6 -0
- package/dist/components/shared/icons/Check.js +2 -0
- package/dist/components/shared/icons/ChevronDownIcon.d.ts +4 -0
- package/dist/components/shared/icons/ChevronDownIcon.js +2 -0
- package/dist/components/shared/icons/ChevronLeft.d.ts +3 -0
- package/dist/components/shared/icons/ChevronLeft.js +3 -0
- package/dist/components/shared/icons/ChevronRight.d.ts +3 -0
- package/dist/components/shared/icons/ChevronRight.js +3 -0
- package/dist/components/shared/icons/CloseIcon.d.ts +9 -0
- package/dist/components/shared/icons/CloseIcon.js +5 -0
- package/dist/components/shared/icons/ConfirmationCheck.d.ts +1 -0
- package/dist/components/shared/icons/ConfirmationCheck.js +9 -0
- package/dist/components/shared/icons/ConsultationType.d.ts +1 -0
- package/dist/components/shared/icons/ConsultationType.js +2 -0
- package/dist/components/shared/icons/Date&TimeIcon.d.ts +1 -0
- package/dist/components/shared/icons/Date&TimeIcon.js +2 -0
- package/dist/components/shared/icons/MapIcon.d.ts +1 -0
- package/dist/components/shared/icons/MapIcon.js +2 -0
- package/dist/components/shared/icons/MedosLogo.d.ts +3 -0
- package/dist/components/shared/icons/MedosLogo.js +3 -0
- package/dist/components/shared/icons/PaymentMethodIcon.d.ts +1 -0
- package/dist/components/shared/icons/PaymentMethodIcon.js +2 -0
- package/dist/components/shared/icons/SuccessIcon.d.ts +8 -0
- package/dist/components/shared/icons/SuccessIcon.js +14 -0
- package/dist/components/shared/icons/UserIcon.d.ts +1 -0
- package/dist/components/shared/icons/UserIcon.js +2 -0
- package/dist/components/shared/icons/index.d.ts +13 -0
- package/dist/components/shared/icons/index.js +13 -0
- package/dist/components/shared/index.d.ts +2 -0
- package/dist/components/shared/index.js +2 -0
- package/dist/components/shared/ui/Calendar.d.ts +5 -0
- package/dist/components/shared/ui/Calendar.js +167 -0
- package/dist/components/shared/ui/SelectDropdown.d.ts +41 -0
- package/dist/components/shared/ui/SelectDropdown.js +301 -0
- package/dist/components/shared/ui/index.d.ts +2 -0
- package/dist/components/shared/ui/index.js +2 -0
- package/dist/components/styles/appointment.d.ts +4 -0
- package/dist/components/styles/appointment.js +220 -0
- package/dist/components/styles/enquiry.d.ts +2 -0
- package/dist/components/styles/enquiry.js +3 -0
- package/dist/components/styles/index.d.ts +2 -0
- package/dist/components/styles/index.js +2 -0
- package/dist/components/styles/shared.d.ts +3 -0
- package/dist/components/styles/shared.js +78 -0
- package/dist/components/styles.d.ts +1 -6
- package/dist/components/styles.js +1 -298
- package/dist/components/theme-styles.js +18 -0
- package/dist/components/types/appointment.d.ts +42 -0
- package/dist/components/types/appointment.js +1 -0
- package/dist/components/types/common.d.ts +24 -0
- package/dist/components/types/common.js +1 -0
- package/dist/components/types/enquiry.d.ts +59 -0
- package/dist/components/types/enquiry.js +1 -0
- package/dist/components/types/index.d.ts +4 -0
- package/dist/components/types/index.js +4 -0
- package/dist/components/types.d.ts +1 -54
- package/dist/components/types.js +1 -38
- package/dist/components/utils/date.d.ts +4 -0
- package/dist/components/utils/date.js +65 -0
- package/dist/components/utils/formatting.d.ts +4 -0
- package/dist/components/utils/formatting.js +9 -0
- package/dist/components/utils/index.d.ts +3 -0
- package/dist/components/utils/index.js +3 -0
- package/dist/components/utils/validation.d.ts +4 -0
- package/dist/components/utils/validation.js +37 -0
- package/dist/components/utils.d.ts +1 -8
- package/dist/components/utils.js +1 -74
- package/dist/components/validation.d.ts +1 -4
- package/dist/components/validation.js +1 -48
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +1 -1
- package/dist/services/AppointmentService.js +26 -9
- package/dist/services/AuthService.js +1 -1
- package/dist/vanilla/AppointmentCalendarWidget.d.ts +8 -0
- package/dist/vanilla/AppointmentCalendarWidget.js +598 -20
- package/dist/vanilla/components/appointment-booking/appointment-modal-styles.d.ts +272 -0
- package/dist/vanilla/components/appointment-booking/components/AppointmentConfirmationStep.d.ts +28 -0
- package/dist/vanilla/components/appointment-booking/components/AppointmentDateTimeModal.d.ts +18 -0
- package/dist/vanilla/components/appointment-booking/components/AppointmentSummaryStep.d.ts +12 -0
- package/dist/vanilla/components/appointment-booking/components/BookingOptionStep.d.ts +14 -0
- package/dist/vanilla/components/appointment-booking/components/DoctorSelectModal.d.ts +14 -0
- package/dist/vanilla/components/appointment-booking/components/PatientDetailsStep.d.ts +3 -0
- package/dist/vanilla/components/appointment-booking/components/PatientSelectionStep.d.ts +12 -0
- package/dist/vanilla/components/appointment-booking/components/PhoneVerificationStep.d.ts +3 -0
- package/dist/vanilla/components/appointment-booking/components/SuccessStep.d.ts +5 -0
- package/dist/vanilla/components/appointment-booking/components/index.d.ts +9 -0
- package/dist/vanilla/components/appointment-booking/index.d.ts +2 -4
- package/dist/vanilla/components/appointment-booking/types.d.ts +4 -0
- package/dist/vanilla/components/constants/constant.d.ts +2 -0
- package/dist/vanilla/components/constants/index.d.ts +3 -0
- package/dist/vanilla/components/constants/options.d.ts +13 -0
- package/dist/vanilla/components/constants/validation.d.ts +6 -0
- package/dist/vanilla/components/enquiry-form/EnquiryForm.d.ts +7 -0
- package/dist/vanilla/components/enquiry-form/components/ContactInformationStep.d.ts +13 -0
- package/dist/vanilla/components/enquiry-form/components/ContactPreferenceStep.d.ts +9 -0
- package/dist/vanilla/components/enquiry-form/components/InquiryDetailsStep.d.ts +10 -0
- package/dist/vanilla/components/enquiry-form/components/index.d.ts +3 -0
- package/dist/vanilla/components/enquiry-form/index.d.ts +2 -0
- package/dist/vanilla/components/index.d.ts +7 -3
- package/dist/vanilla/components/shared/icons/Check.d.ts +6 -0
- package/dist/vanilla/components/shared/icons/ChevronDownIcon.d.ts +4 -0
- package/dist/vanilla/components/shared/icons/ChevronLeft.d.ts +3 -0
- package/dist/vanilla/components/shared/icons/ChevronRight.d.ts +3 -0
- package/dist/vanilla/components/shared/icons/CloseIcon.d.ts +9 -0
- package/dist/vanilla/components/shared/icons/ConfirmationCheck.d.ts +1 -0
- package/dist/vanilla/components/shared/icons/ConsultationType.d.ts +1 -0
- package/dist/vanilla/components/shared/icons/Date&TimeIcon.d.ts +1 -0
- package/dist/vanilla/components/shared/icons/MapIcon.d.ts +1 -0
- package/dist/vanilla/components/shared/icons/MedosLogo.d.ts +3 -0
- package/dist/vanilla/components/shared/icons/PaymentMethodIcon.d.ts +1 -0
- package/dist/vanilla/components/shared/icons/SuccessIcon.d.ts +8 -0
- package/dist/vanilla/components/shared/icons/UserIcon.d.ts +1 -0
- package/dist/vanilla/components/shared/icons/index.d.ts +13 -0
- package/dist/vanilla/components/shared/index.d.ts +2 -0
- package/dist/vanilla/components/shared/ui/Calendar.d.ts +5 -0
- package/dist/vanilla/components/shared/ui/SelectDropdown.d.ts +41 -0
- package/dist/vanilla/components/shared/ui/index.d.ts +2 -0
- package/dist/vanilla/components/styles/appointment.d.ts +4 -0
- package/dist/vanilla/components/styles/enquiry.d.ts +2 -0
- package/dist/vanilla/components/styles/index.d.ts +2 -0
- package/dist/vanilla/components/styles/shared.d.ts +3 -0
- package/dist/vanilla/components/styles.d.ts +1 -6
- package/dist/vanilla/components/types/appointment.d.ts +42 -0
- package/dist/vanilla/components/types/common.d.ts +24 -0
- package/dist/vanilla/components/types/enquiry.d.ts +59 -0
- package/dist/vanilla/components/types/index.d.ts +4 -0
- package/dist/vanilla/components/types.d.ts +1 -54
- package/dist/vanilla/components/utils/date.d.ts +4 -0
- package/dist/vanilla/components/utils/formatting.d.ts +4 -0
- package/dist/vanilla/components/utils/index.d.ts +3 -0
- package/dist/vanilla/components/utils/validation.d.ts +4 -0
- package/dist/vanilla/components/utils.d.ts +1 -8
- package/dist/vanilla/components/validation.d.ts +1 -4
- package/dist/vanilla/constants/index.d.ts +1 -1
- package/dist/vanilla/enquiry-widget.js +3277 -56
- package/dist/vanilla/index.d.ts +2 -2
- package/dist/vanilla/react/index.d.ts +3 -3
- package/dist/vanilla/vanilla/AppointmentCalendarWidget.d.ts +8 -0
- package/dist/vanilla/widget.css +214 -0
- package/dist/vanilla/widget.js +4047 -187
- package/package.json +2 -2
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { ChevronLeft, ChevronRight } from "../icons";
|
|
4
|
+
import { useTheme } from "../../../react/hooks/useTheme";
|
|
5
|
+
import { useBreakpoint } from "../../../core/theme/responsive";
|
|
6
|
+
import { MONTHS } from "../../constants";
|
|
7
|
+
const getStyle = (theme, isMobile) => `
|
|
8
|
+
.custom-calendar-wrapper {
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
-webkit-overflow-scrolling: touch;
|
|
11
|
+
}
|
|
12
|
+
.custom-calendar {
|
|
13
|
+
width: ${isMobile ? "320px" : "100%"};
|
|
14
|
+
min-width: ${isMobile ? "320px" : "auto"};
|
|
15
|
+
background-color: ${theme.colors?.background || "#ffffff"};
|
|
16
|
+
border-radius: 8px;
|
|
17
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
|
|
18
|
+
padding: ${isMobile ? "12px" : "16px"};
|
|
19
|
+
font-family: ${theme.typography?.fontFamily || "system-ui, -apple-system, sans-serif"};
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
}
|
|
22
|
+
.calendar-header {
|
|
23
|
+
display: flex;
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
align-items: center;
|
|
26
|
+
margin-bottom: 12px;
|
|
27
|
+
}
|
|
28
|
+
.calendar-month {
|
|
29
|
+
font-size: 14px;
|
|
30
|
+
font-weight: 600;
|
|
31
|
+
color: ${theme.colors?.text || "#333333"};
|
|
32
|
+
}
|
|
33
|
+
.calendar-nav {
|
|
34
|
+
width: 20px;
|
|
35
|
+
height: 20px;
|
|
36
|
+
color: ${theme.colors?.secondary || "#007bff"};
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
transition: background-color 0.2s;
|
|
40
|
+
}
|
|
41
|
+
.calendar-nav:hover {
|
|
42
|
+
background-color: ${theme.colors?.backgroundSecondary || "#f8f9fa"};
|
|
43
|
+
}
|
|
44
|
+
.calendar-days-header {
|
|
45
|
+
display: grid;
|
|
46
|
+
grid-template-columns: repeat(7, 1fr);
|
|
47
|
+
text-align: center;
|
|
48
|
+
margin-bottom: 6px;
|
|
49
|
+
font-size: 13px;
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
color: ${theme.colors?.text || "#333333"};
|
|
52
|
+
}
|
|
53
|
+
.calendar-grid {
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-columns: repeat(7, 1fr);
|
|
56
|
+
gap: 6px;
|
|
57
|
+
text-align: center;
|
|
58
|
+
}
|
|
59
|
+
.calendar-day {
|
|
60
|
+
width: 38px;
|
|
61
|
+
height: 38px;
|
|
62
|
+
border: 1px solid transparent;
|
|
63
|
+
border-radius: 8px;
|
|
64
|
+
color: ${theme.colors?.secondary || "#007bff"};
|
|
65
|
+
background-color: transparent;
|
|
66
|
+
font-size: 14px;
|
|
67
|
+
transition: all 0.2s;
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
}
|
|
73
|
+
.calendar-day span {
|
|
74
|
+
line-height: 1;
|
|
75
|
+
}
|
|
76
|
+
.calendar-day:hover:not(.disabled):not(.selected) {
|
|
77
|
+
background-color: ${theme.colors?.secondary || "#007bff"};
|
|
78
|
+
color: ${theme.colors?.textOnSecondary || "#ffffff"};
|
|
79
|
+
}
|
|
80
|
+
.calendar-day.selected {
|
|
81
|
+
border: 1px solid ${theme.colors?.secondary || "#007bff"};
|
|
82
|
+
color: ${theme.colors?.secondary || "#007bff"};
|
|
83
|
+
background-color: transparent;
|
|
84
|
+
font-weight: 600;
|
|
85
|
+
}
|
|
86
|
+
.calendar-day.disabled {
|
|
87
|
+
color: ${theme.colors?.textSecondary || "#6c757d"};
|
|
88
|
+
opacity: 0.4;
|
|
89
|
+
cursor: not-allowed;
|
|
90
|
+
}
|
|
91
|
+
.calendar-dot {
|
|
92
|
+
font-size: 10px;
|
|
93
|
+
margin-top: -2px;
|
|
94
|
+
line-height: 1;
|
|
95
|
+
}
|
|
96
|
+
.calendar-empty {
|
|
97
|
+
visibility: hidden;
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
export const CustomCalendarWithDateSelector = ({ selectedDate, onSelect, pastDisabled = false, }) => {
|
|
101
|
+
const theme = useTheme();
|
|
102
|
+
const breakpoint = useBreakpoint(theme);
|
|
103
|
+
const isMobile = breakpoint === "mobile";
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const styleId = "custom-calendar-style";
|
|
106
|
+
const existingStyle = document.getElementById(styleId);
|
|
107
|
+
const themeStyle = getStyle(theme, isMobile);
|
|
108
|
+
if (existingStyle) {
|
|
109
|
+
existingStyle.innerHTML = themeStyle;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const s = document.createElement("style");
|
|
113
|
+
s.id = styleId;
|
|
114
|
+
s.innerHTML = themeStyle;
|
|
115
|
+
document.head.appendChild(s);
|
|
116
|
+
}
|
|
117
|
+
}, [theme, isMobile]);
|
|
118
|
+
const today = new Date();
|
|
119
|
+
today.setHours(0, 0, 0, 0);
|
|
120
|
+
const [currentMonth, setCurrentMonth] = useState(today.getMonth());
|
|
121
|
+
const [currentYear, setCurrentYear] = useState(today.getFullYear());
|
|
122
|
+
const daysOfWeek = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
|
123
|
+
const months = MONTHS;
|
|
124
|
+
const getDaysInMonth = (year, month) => {
|
|
125
|
+
return new Date(year, month + 1, 0).getDate();
|
|
126
|
+
};
|
|
127
|
+
const getFirstDayOfMonth = (year, month) => {
|
|
128
|
+
return new Date(year, month, 1).getDay();
|
|
129
|
+
};
|
|
130
|
+
const daysInMonth = getDaysInMonth(currentYear, currentMonth);
|
|
131
|
+
const firstDayOfMonth = getFirstDayOfMonth(currentYear, currentMonth);
|
|
132
|
+
const startOffset = (firstDayOfMonth + 6) % 7;
|
|
133
|
+
const prevMonth = () => {
|
|
134
|
+
if (currentMonth === 0) {
|
|
135
|
+
setCurrentMonth(11);
|
|
136
|
+
setCurrentYear(currentYear - 1);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
setCurrentMonth(currentMonth - 1);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const nextMonth = () => {
|
|
143
|
+
if (currentMonth === 11) {
|
|
144
|
+
setCurrentMonth(0);
|
|
145
|
+
setCurrentYear(currentYear + 1);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
setCurrentMonth(currentMonth + 1);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const isSameDate = (d1, d2) => {
|
|
152
|
+
return (d1.getFullYear() === d2.getFullYear() &&
|
|
153
|
+
d1.getMonth() === d2.getMonth() &&
|
|
154
|
+
d1.getDate() === d2.getDate());
|
|
155
|
+
};
|
|
156
|
+
const isBeforeToday = (date) => {
|
|
157
|
+
const todayStart = new Date(today);
|
|
158
|
+
todayStart.setHours(0, 0, 0, 0);
|
|
159
|
+
return date < todayStart;
|
|
160
|
+
};
|
|
161
|
+
return (_jsx("div", { className: "custom-calendar-wrapper", children: _jsxs("div", { className: "custom-calendar", children: [_jsxs("div", { className: "calendar-header", children: [_jsx(ChevronLeft, { onClick: prevMonth, className: "calendar-nav" }), _jsxs("p", { className: "calendar-month", children: [months[currentMonth], " ", currentYear] }), _jsx(ChevronRight, { onClick: nextMonth, className: "calendar-nav" })] }), _jsx("div", { className: "calendar-days-header", children: daysOfWeek.map((d) => (_jsx("div", { className: "calendar-day-name", children: d }, d))) }), _jsxs("div", { className: "calendar-grid", children: [Array.from({ length: startOffset }).map((_, idx) => (_jsx("div", { className: "calendar-empty" }, `empty-start-${currentMonth}-${idx}`))), Array.from({ length: daysInMonth }).map((_, i) => {
|
|
162
|
+
const date = new Date(currentYear, currentMonth, i + 1);
|
|
163
|
+
const disabled = pastDisabled && isBeforeToday(date);
|
|
164
|
+
const isSelected = selectedDate && isSameDate(selectedDate, date);
|
|
165
|
+
return (_jsxs("button", { disabled: disabled, onClick: () => onSelect(date), className: `calendar-day ${isSelected ? "selected" : ""} ${disabled ? "disabled" : ""}`, children: [_jsx("span", { children: i + 1 }), isSelected && _jsx("span", { className: "calendar-dot", children: "\u2022" })] }, i + 1));
|
|
166
|
+
})] })] }) }));
|
|
167
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
interface SelectProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
value?: string;
|
|
5
|
+
onValueChange?: (value: string) => void;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface SelectTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface SelectValueProps {
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
}
|
|
17
|
+
interface SelectContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
interface SelectItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
value: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface BaseComponentProps {
|
|
28
|
+
children: React.ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
declare const Select: React.FC<SelectProps>;
|
|
32
|
+
declare const SelectTrigger: React.ForwardRefExoticComponent<SelectTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
33
|
+
declare const SelectValue: React.FC<SelectValueProps>;
|
|
34
|
+
declare const SelectContent: React.ForwardRefExoticComponent<SelectContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
35
|
+
declare const SelectItem: React.ForwardRefExoticComponent<SelectItemProps & React.RefAttributes<HTMLDivElement>>;
|
|
36
|
+
declare const SelectGroup: React.FC<BaseComponentProps>;
|
|
37
|
+
declare const SelectLabel: React.FC<BaseComponentProps>;
|
|
38
|
+
declare const SelectSeparator: React.FC<{
|
|
39
|
+
className?: string;
|
|
40
|
+
}>;
|
|
41
|
+
export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, };
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { ChevronDownIcon, Check } from "../icons";
|
|
4
|
+
const cn = (...classes) => {
|
|
5
|
+
return classes.filter(Boolean).join(" ");
|
|
6
|
+
};
|
|
7
|
+
if (typeof document !== "undefined") {
|
|
8
|
+
const styleId = "custom-select-styles";
|
|
9
|
+
if (!document.getElementById(styleId)) {
|
|
10
|
+
const styleElement = document.createElement("style");
|
|
11
|
+
styleElement.id = styleId;
|
|
12
|
+
styleElement.innerHTML = `
|
|
13
|
+
/* Container */
|
|
14
|
+
.select-container {
|
|
15
|
+
position: relative;
|
|
16
|
+
display: inline-block;
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Trigger Button */
|
|
21
|
+
.select-trigger {
|
|
22
|
+
display: flex;
|
|
23
|
+
height: 40px;
|
|
24
|
+
width: 100%;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: space-between;
|
|
27
|
+
white-space: nowrap;
|
|
28
|
+
border-radius: 6px;
|
|
29
|
+
border: 1px solid #e2e8f0;
|
|
30
|
+
background-color: #fff;
|
|
31
|
+
padding: 8px 12px;
|
|
32
|
+
font-size: 14px;
|
|
33
|
+
line-height: 1.5;
|
|
34
|
+
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
35
|
+
transition: all 0.15s ease-in-out;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
outline: none;
|
|
38
|
+
font-family: inherit;
|
|
39
|
+
text-align: left;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.select-trigger:hover:not(:disabled) {
|
|
43
|
+
background-color: #f8fafc;
|
|
44
|
+
border-color: #cbd5e1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.select-trigger:focus:not(:disabled) {
|
|
48
|
+
border-color: #94a3b8;
|
|
49
|
+
box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.2);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.select-trigger:disabled {
|
|
53
|
+
cursor: not-allowed;
|
|
54
|
+
opacity: 0.5;
|
|
55
|
+
background-color: #f9fafb;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.select-trigger-error {
|
|
59
|
+
border-color: #ef4444;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.select-trigger-error:focus {
|
|
63
|
+
border-color: #ef4444;
|
|
64
|
+
box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Select Value */
|
|
68
|
+
.select-value {
|
|
69
|
+
flex: 1;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
text-overflow: ellipsis;
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
color: #1e293b;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.select-placeholder {
|
|
77
|
+
color: #94a3b8;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Select Icon */
|
|
81
|
+
.select-icon {
|
|
82
|
+
height: 16px;
|
|
83
|
+
width: 16px;
|
|
84
|
+
opacity: 0.5;
|
|
85
|
+
flex-shrink: 0;
|
|
86
|
+
margin-left: 8px;
|
|
87
|
+
transition: transform 0.2s;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.select-trigger[aria-expanded="true"] .select-icon {
|
|
91
|
+
transform: rotate(180deg);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.select-icon-error {
|
|
95
|
+
color: #ef4444;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Content Dropdown */
|
|
99
|
+
.select-content {
|
|
100
|
+
position: absolute;
|
|
101
|
+
top: 100%;
|
|
102
|
+
left: 0;
|
|
103
|
+
right: 0;
|
|
104
|
+
z-index: 1050;
|
|
105
|
+
margin-top: 4px;
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
border-radius: 6px;
|
|
108
|
+
border: 1px solid #e2e8f0;
|
|
109
|
+
background-color: #ffffff;
|
|
110
|
+
color: #1e293b;
|
|
111
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
112
|
+
animation: select-show 0.15s ease-out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@keyframes select-show {
|
|
116
|
+
from {
|
|
117
|
+
opacity: 0;
|
|
118
|
+
transform: translateY(-4px);
|
|
119
|
+
}
|
|
120
|
+
to {
|
|
121
|
+
opacity: 1;
|
|
122
|
+
transform: translateY(0);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Viewport */
|
|
127
|
+
.select-viewport {
|
|
128
|
+
padding: 4px;
|
|
129
|
+
max-height: 256px;
|
|
130
|
+
overflow-y: auto;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* Select Item */
|
|
134
|
+
.select-item {
|
|
135
|
+
position: relative;
|
|
136
|
+
display: flex;
|
|
137
|
+
width: 100%;
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
user-select: none;
|
|
140
|
+
align-items: center;
|
|
141
|
+
border-radius: 4px;
|
|
142
|
+
padding: 8px 8px 8px 32px;
|
|
143
|
+
font-size: 14px;
|
|
144
|
+
outline: none;
|
|
145
|
+
transition: background-color 0.1s ease;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.select-item:hover:not(.select-item-disabled) {
|
|
149
|
+
background-color: #f1f5f9;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.select-item:focus {
|
|
153
|
+
background-color: #f1f5f9;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.select-item-selected {
|
|
157
|
+
background-color: #f3f4f6;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.select-item-disabled {
|
|
161
|
+
pointer-events: none;
|
|
162
|
+
opacity: 0.5;
|
|
163
|
+
cursor: not-allowed;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* Item Indicator */
|
|
167
|
+
.select-item-indicator {
|
|
168
|
+
position: absolute;
|
|
169
|
+
left: 8px;
|
|
170
|
+
display: flex;
|
|
171
|
+
height: 14px;
|
|
172
|
+
width: 14px;
|
|
173
|
+
align-items: center;
|
|
174
|
+
justify-content: center;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Item Text */
|
|
178
|
+
.select-item-text {
|
|
179
|
+
flex: 1;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Select Group */
|
|
183
|
+
.select-group {
|
|
184
|
+
padding: 2px 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Select Label */
|
|
188
|
+
.select-label {
|
|
189
|
+
padding: 8px 8px 6px;
|
|
190
|
+
font-size: 12px;
|
|
191
|
+
font-weight: 600;
|
|
192
|
+
color: #64748b;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* Select Separator */
|
|
196
|
+
.select-separator {
|
|
197
|
+
margin: 4px 0;
|
|
198
|
+
height: 1px;
|
|
199
|
+
background-color: #e2e8f0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* Scrollbar styling */
|
|
203
|
+
.select-viewport::-webkit-scrollbar {
|
|
204
|
+
width: 8px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.select-viewport::-webkit-scrollbar-track {
|
|
208
|
+
background: #f1f5f9;
|
|
209
|
+
border-radius: 4px;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.select-viewport::-webkit-scrollbar-thumb {
|
|
213
|
+
background: #cbd5e1;
|
|
214
|
+
border-radius: 4px;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.select-viewport::-webkit-scrollbar-thumb:hover {
|
|
218
|
+
background: #94a3b8;
|
|
219
|
+
}
|
|
220
|
+
`;
|
|
221
|
+
document.head.appendChild(styleElement);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const SelectContext = React.createContext(undefined);
|
|
225
|
+
const useSelectContext = () => {
|
|
226
|
+
const context = React.useContext(SelectContext);
|
|
227
|
+
if (!context) {
|
|
228
|
+
throw new Error("Select components must be used within a Select");
|
|
229
|
+
}
|
|
230
|
+
return context;
|
|
231
|
+
};
|
|
232
|
+
const Select = ({ children, value, onValueChange, defaultValue, disabled = false, }) => {
|
|
233
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
234
|
+
const [selectedValue, setSelectedValue] = React.useState(value || defaultValue || "");
|
|
235
|
+
const [selectedLabel, setSelectedLabel] = React.useState("");
|
|
236
|
+
const triggerRef = React.useRef(null);
|
|
237
|
+
const contentRef = React.useRef(null);
|
|
238
|
+
React.useEffect(() => {
|
|
239
|
+
if (value !== undefined) {
|
|
240
|
+
setSelectedValue(value);
|
|
241
|
+
}
|
|
242
|
+
}, [value]);
|
|
243
|
+
React.useEffect(() => {
|
|
244
|
+
const handleClickOutside = (event) => {
|
|
245
|
+
if (triggerRef.current &&
|
|
246
|
+
contentRef.current &&
|
|
247
|
+
!triggerRef.current.contains(event.target) &&
|
|
248
|
+
!contentRef.current.contains(event.target)) {
|
|
249
|
+
setIsOpen(false);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
if (isOpen) {
|
|
253
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
254
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
255
|
+
}
|
|
256
|
+
}, [isOpen]);
|
|
257
|
+
const handleSelect = (value, label) => {
|
|
258
|
+
setSelectedValue(value);
|
|
259
|
+
setSelectedLabel(label);
|
|
260
|
+
if (onValueChange) {
|
|
261
|
+
onValueChange(value);
|
|
262
|
+
}
|
|
263
|
+
setIsOpen(false);
|
|
264
|
+
};
|
|
265
|
+
return (_jsx(SelectContext.Provider, { value: {
|
|
266
|
+
isOpen,
|
|
267
|
+
setIsOpen,
|
|
268
|
+
selectedValue,
|
|
269
|
+
selectedLabel,
|
|
270
|
+
handleSelect,
|
|
271
|
+
triggerRef,
|
|
272
|
+
contentRef,
|
|
273
|
+
disabled,
|
|
274
|
+
}, children: _jsx("div", { className: "select-container", children: children }) }));
|
|
275
|
+
};
|
|
276
|
+
const SelectTrigger = React.forwardRef(({ children, className, error = false, ...props }, ref) => {
|
|
277
|
+
const { isOpen, setIsOpen, triggerRef, disabled } = useSelectContext();
|
|
278
|
+
return (_jsxs("button", { ref: triggerRef, type: "button", className: cn("select-trigger", error && "select-trigger-error", className), onClick: () => !disabled && setIsOpen(!isOpen), disabled: disabled, "aria-expanded": isOpen, "aria-haspopup": "listbox", ...props, children: [children, _jsx(ChevronDownIcon, { className: cn("select-icon", error && "select-icon-error") })] }));
|
|
279
|
+
});
|
|
280
|
+
SelectTrigger.displayName = "SelectTrigger";
|
|
281
|
+
const SelectValue = ({ placeholder = "Select...", }) => {
|
|
282
|
+
const { selectedLabel, selectedValue } = useSelectContext();
|
|
283
|
+
return (_jsx("span", { className: cn("select-value", !selectedValue && "select-placeholder"), children: selectedLabel || placeholder }));
|
|
284
|
+
};
|
|
285
|
+
const SelectContent = React.forwardRef(({ children, className, ...props }, ref) => {
|
|
286
|
+
const { isOpen, contentRef } = useSelectContext();
|
|
287
|
+
if (!isOpen)
|
|
288
|
+
return null;
|
|
289
|
+
return (_jsx("div", { ref: contentRef, className: cn("select-content", className), role: "listbox", ...props, children: _jsx("div", { className: "select-viewport", children: children }) }));
|
|
290
|
+
});
|
|
291
|
+
SelectContent.displayName = "SelectContent";
|
|
292
|
+
const SelectItem = React.forwardRef(({ children, value, className, disabled = false, ...props }, ref) => {
|
|
293
|
+
const { selectedValue, handleSelect } = useSelectContext();
|
|
294
|
+
const isSelected = selectedValue === value;
|
|
295
|
+
return (_jsxs("div", { ref: ref, className: cn("select-item", isSelected && "select-item-selected", disabled && "select-item-disabled", className), onClick: () => !disabled && handleSelect(value, children), role: "option", "aria-selected": isSelected, "data-disabled": disabled, ...props, children: [isSelected && (_jsx("span", { className: "select-item-indicator", children: _jsx(Check, {}) })), _jsx("span", { className: "select-item-text", children: children })] }));
|
|
296
|
+
});
|
|
297
|
+
SelectItem.displayName = "SelectItem";
|
|
298
|
+
const SelectGroup = ({ children, className }) => (_jsx("div", { className: cn("select-group", className), children: children }));
|
|
299
|
+
const SelectLabel = ({ children, className }) => (_jsx("div", { className: cn("select-label", className), children: children }));
|
|
300
|
+
const SelectSeparator = ({ className }) => (_jsx("div", { className: cn("select-separator", className) }));
|
|
301
|
+
export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, };
|