1
|
|
|
import React from 'react'; |
2
|
|
|
import moment from 'moment'; |
3
|
|
|
import { DateRangePicker } from 'rsuite'; |
4
|
|
|
import PropTypes from 'prop-types'; |
5
|
|
|
|
6
|
|
|
const DateRangePickerWrapper = ({id, disabled, format, value, onChange, size, style, onClean, locale, placeholder}) => { |
7
|
|
|
|
8
|
|
|
let flag = true; |
9
|
|
|
const Ref = React.useRef(); |
10
|
|
|
|
11
|
|
|
const onSelected = (date) => { |
12
|
|
|
let time = moment(date).format('YYYY-MM-DD'); |
13
|
|
|
let calendarObj = Ref.current.overlay.children[0].children[0].children[0].children[0].children[1]; |
14
|
|
|
if(flag) { |
15
|
|
|
calendarObj.children[0].children[0].children[0].children[1].innerText = time; |
16
|
|
|
}else{ |
17
|
|
|
if (moment(calendarObj.children[0].children[0].children[0].children[1].innerText).isBefore(time)){ |
18
|
|
|
calendarObj.children[1].children[0].children[0].children[1].innerText = time; |
19
|
|
|
} else { |
20
|
|
|
calendarObj.children[1].children[0].children[0].children[1].innerText = |
21
|
|
|
calendarObj.children[0].children[0].children[0].children[1].innerText; |
22
|
|
|
calendarObj.children[0].children[0].children[0].children[1].innerText = time |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
flag = !flag; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
const onOpen = () => { |
29
|
|
|
flag = true; |
30
|
|
|
let calendarTitleObj = Ref.current.overlay.children[0].children[0].children[0].children[0].children[0]; |
31
|
|
|
let calendarObj = Ref.current.overlay.children[0].children[0].children[0].children[0].children[1]; |
32
|
|
|
calendarObj.children[0].children[0].children[0].children[1].innerText = calendarTitleObj.firstChild.data.split(' ')[0]; |
33
|
|
|
calendarObj.children[1].children[0].children[0].children[1].innerText = calendarTitleObj.lastChild.data.split(' ')[0]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return ( |
37
|
|
|
<DateRangePicker |
38
|
|
|
id={id} |
39
|
|
|
disabled={disabled} |
40
|
|
|
format={format} |
41
|
|
|
value={value} |
42
|
|
|
onChange={onChange} |
43
|
|
|
size={size} |
44
|
|
|
style={style} |
45
|
|
|
onClean={onClean} |
46
|
|
|
locale={locale} |
47
|
|
|
placeholder={placeholder} |
48
|
|
|
onSelect={onSelected} |
49
|
|
|
onOpen={onOpen} |
50
|
|
|
ref={Ref} |
51
|
|
|
/> |
52
|
|
|
) |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
DateRangePickerWrapper.propTypes = { |
56
|
|
|
ranges: PropTypes.array, |
57
|
|
|
value: PropTypes.arrayOf(PropTypes.instanceOf(Date)), |
58
|
|
|
defaultValue: PropTypes.arrayOf(PropTypes.instanceOf(Date)), |
59
|
|
|
defaultCalendarValue: PropTypes.arrayOf(PropTypes.instanceOf(Date)), |
60
|
|
|
hoverRange: PropTypes.oneOfType([PropTypes.oneOf(['week', 'month']), PropTypes.func]), |
61
|
|
|
format: PropTypes.string, |
62
|
|
|
isoWeek: PropTypes.bool, |
63
|
|
|
oneTap: PropTypes.bool, |
64
|
|
|
limitEndYear: PropTypes.number, |
65
|
|
|
onChange: PropTypes.func, |
66
|
|
|
onOk: PropTypes.func, |
67
|
|
|
disabledDate: PropTypes.func, |
68
|
|
|
onSelect: PropTypes.func, |
69
|
|
|
showWeekNumbers: PropTypes.bool, |
70
|
|
|
showMeridian: PropTypes.bool, |
71
|
|
|
showOneCalendar: PropTypes.bool |
72
|
|
|
}; |
73
|
|
|
export default DateRangePickerWrapper; |