-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCalendarPicker.tsx
88 lines (80 loc) · 2.21 KB
/
CalendarPicker.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import { ChevronLeft, ChevronRight } from '@osrd-project/ui-icons';
import cx from 'classnames';
import Calendar from './Calendar';
import { type CalendarSlot } from './type';
import useCalendarPicker from './useCalendarPicker';
export type CalendarPickerPrivateProps = {
selectedSlot?: CalendarSlot;
onDayClick: (day: Date) => void;
modalPosition: {
top: number;
left: number;
};
calendarPickerRef: React.RefObject<HTMLDivElement>;
selectableSlot?: CalendarSlot;
};
export type CalendarPickerPublicProps = {
initialDate?: Date;
numberOfMonths?: 1 | 2 | 3;
};
export type CalendarPickerProps = CalendarPickerPrivateProps & CalendarPickerPublicProps;
const CalendarPicker = ({
initialDate,
selectedSlot,
selectableSlot,
numberOfMonths = 1,
onDayClick,
modalPosition,
calendarPickerRef,
}: CalendarPickerProps) => {
const {
displayedMonthsStartDates,
showNavigationBtn,
canGoToNextMonth,
canGoToPreviousMonth,
handleGoToNextMonth,
handleGoToPreviousMonth,
} = useCalendarPicker({
initialDate,
selectedSlot,
selectableSlot,
numberOfMonths,
});
return (
<div ref={calendarPickerRef} className="calendar-picker" style={modalPosition}>
{showNavigationBtn && (
<span
className={cx('calendar-navigation-btn', 'previous', {
disabled: !canGoToPreviousMonth,
})}
onClick={handleGoToPreviousMonth}
>
<ChevronLeft size="lg" />
</span>
)}
<div className={cx('calendar-list', { 'navigation-btn-hidden': !showNavigationBtn })}>
{displayedMonthsStartDates.map((date) => (
<Calendar
key={date.getTime()}
displayedMonthStartDate={date}
selectableSlot={selectableSlot}
selectedSlot={selectedSlot}
onDayClick={onDayClick}
/>
))}
</div>
{showNavigationBtn && (
<span
className={cx('calendar-navigation-btn', 'next', {
disabled: !canGoToNextMonth,
})}
onClick={handleGoToNextMonth}
>
<ChevronRight size="lg" />
</span>
)}
</div>
);
};
export default CalendarPicker;