-
Notifications
You must be signed in to change notification settings - Fork 375
/
custom-formatting.jsx
61 lines (55 loc) · 1.55 KB
/
custom-formatting.jsx
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
import * as React from 'react';
import Paper from '@material-ui/core/Paper';
import moment from 'moment';
import { ViewState } from '@devexpress/dx-react-scheduler';
import {
Scheduler,
WeekView,
Toolbar,
Appointments,
} from '@devexpress/dx-react-scheduler-material-ui';
import { appointments } from '../../../demo-data/appointments';
const formatDayScaleDate = (date, options) => {
const momentDate = moment(date);
const { weekday } = options;
return momentDate.format(weekday ? 'dddd' : 'D');
};
const formatTimeScaleDate = date => moment(date).format('hh:mm:ss');
const DayScaleCell = (
{ formatDate, ...restProps },
) => <WeekView.DayScaleCell {...restProps} formatDate={formatDayScaleDate} />;
const TimeScaleCell = (
{ formatDate, ...restProps },
) => <WeekView.TimeScaleCell {...restProps} formatDate={formatTimeScaleDate} />;
export default class Demo extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
data: appointments,
currentDate: '2018-06-27',
};
}
render() {
const { data, currentDate, locale } = this.state;
return (
<Paper>
<Scheduler
data={data}
locale={locale}
>
<ViewState
defaultCurrentDate={currentDate}
/>
<WeekView
startDayHour={9}
endDayHour={19}
dayScaleCellComponent={DayScaleCell}
timeScaleCellComponent={TimeScaleCell}
/>
<Toolbar />
<Appointments />
</Scheduler>
</Paper>
);
}
}