forked from Yadro/time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectDate.tsx
More file actions
41 lines (38 loc) · 1 KB
/
SelectDate.tsx
File metadata and controls
41 lines (38 loc) · 1 KB
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
import React from 'react';
import { Button, DatePicker, Space } from 'antd';
import { LeftOutlined, RightOutlined } from '@ant-design/icons';
import moment from 'moment';
import addDays from 'date-fns/addDays';
import { observer } from 'mobx-react';
interface SelectDateProps {
date: Date;
onChange: (date: Date) => void;
}
function changeDate(date: Date, offsetDay: number) {
return addDays(date, offsetDay);
}
export default observer(function SelectDate({
date,
onChange,
}: SelectDateProps) {
return (
<Space direction="horizontal">
<Button
icon={<LeftOutlined />}
onClick={() => onChange(changeDate(date, -1))}
/>
<DatePicker
value={moment(date)}
onChange={(date) => onChange(date?.toDate() || new Date())}
allowClear={false}
placeholder="Date"
inputReadOnly
format={'ddd DD MMM'}
/>
<Button
icon={<RightOutlined />}
onClick={() => onChange(changeDate(date, 1))}
/>
</Space>
);
});