You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
7 years ago
|
import * as React from 'react';
|
||
|
import BigCalendar from 'react-big-calendar';
|
||
|
import 'react-big-calendar/lib/css/react-big-calendar.css';
|
||
|
import * as moment from 'moment';
|
||
7 years ago
|
import 'moment/locale/en-gb';
|
||
7 years ago
|
|
||
7 years ago
|
import { EventType } from '../pim-types';
|
||
7 years ago
|
|
||
7 years ago
|
moment.locale('en-gb');
|
||
7 years ago
|
BigCalendar.momentLocalizer(moment);
|
||
|
|
||
7 years ago
|
class Calendar extends React.PureComponent {
|
||
7 years ago
|
state: {
|
||
|
currentDate?: Date;
|
||
|
};
|
||
|
|
||
|
props: {
|
||
7 years ago
|
entries: Array<EventType>,
|
||
|
onItemClick: (contact: EventType) => void,
|
||
7 years ago
|
};
|
||
|
|
||
|
constructor(props: any) {
|
||
|
super(props);
|
||
|
this.state = {};
|
||
|
}
|
||
|
|
||
|
render() {
|
||
7 years ago
|
let entries = this.props.entries.sort((a, b) => {
|
||
7 years ago
|
if (a.summary < b.summary) {
|
||
|
return -1;
|
||
|
} else if (a.summary > b.summary) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
});
|
||
|
|
||
7 years ago
|
function eventPropGetter(event: EventType) {
|
||
|
return {
|
||
|
style: {
|
||
|
backgroundColor: event.color,
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
7 years ago
|
function agendaHeaderFormat(date: {start: Date, end: Date}, culture: string, localizer: any) {
|
||
|
const format = 'll';
|
||
|
return localizer.format(date.start, format) + ' - ' + localizer.format(date.end, format);
|
||
|
}
|
||
|
|
||
7 years ago
|
return (
|
||
7 years ago
|
<div style={{width: '100%', height: 500, padding: 10}}>
|
||
7 years ago
|
<BigCalendar
|
||
|
events={entries}
|
||
7 years ago
|
onSelectEvent={(event: any) => {
|
||
|
this.props.onItemClick(event);
|
||
|
}}
|
||
7 years ago
|
formats={{agendaHeaderFormat: agendaHeaderFormat}}
|
||
7 years ago
|
eventPropGetter={eventPropGetter}
|
||
7 years ago
|
date={this.state.currentDate}
|
||
|
onNavigate={(currentDate: Date) => { this.setState({currentDate}); }}
|
||
|
/>
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Calendar;
|