-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathDatePickerCalendar.js
60 lines (56 loc) · 1.76 KB
/
DatePickerCalendar.js
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
import React from 'react'
import { bool, instanceOf, func, object, objectOf, string } from 'prop-types'
import { isSameDay, startOfMonth } from 'date-fns'
import { isSelectable, mergeModifiers, setTime } from './utils'
import useControllableState from './useControllableState'
import Calendar from './Calendar'
export default function DatePickerCalendar({
locale,
date: selectedDate,
month: receivedMonth,
onDateChange,
onMonthChange,
minimumDate,
maximumDate,
modifiers: receivedModifiers,
modifiersClassNames,
monthFormat,
weekdayFormat,
touchDragEnabled
}) {
const isSelected = date => isSameDay(date, selectedDate) && isSelectable(date, { minimumDate, maximumDate })
const modifiers = mergeModifiers({ selected: isSelected, disabled: isSelected }, receivedModifiers)
const [month, setMonth] = useControllableState(receivedMonth, onMonthChange, startOfMonth(selectedDate || new Date()))
const handleDateChange = date => {
onDateChange(selectedDate ? setTime(date, selectedDate) : date)
}
return (
<Calendar
locale={locale}
month={month}
onMonthChange={setMonth}
onDayClick={handleDateChange}
minimumDate={minimumDate}
maximumDate={maximumDate}
modifiers={modifiers}
modifiersClassNames={modifiersClassNames}
monthFormat={monthFormat}
weekdayFormat={weekdayFormat}
touchDragEnabled={touchDragEnabled}
/>
)
}
DatePickerCalendar.propTypes = {
locale: object.isRequired,
date: instanceOf(Date),
month: instanceOf(Date),
onDateChange: func,
onMonthChange: func,
minimumDate: instanceOf(Date),
maximumDate: instanceOf(Date),
modifiers: objectOf(func),
modifiersClassNames: objectOf(string),
monthFormat: string,
weekdayFormat: string,
touchDragEnabled: bool
}