Calendar.js
2.37 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
/* eslint-disable */
import $ from 'jquery';
import 'imports-loader?jQuery=jquery,this=>window!bootstrap';
import 'imports-loader?jQuery=jquery,this=>window!bootstrap_calendar/bootstrap_calendar/js/bootstrap_calendar';
/* eslint-enable */
import './Calendar.scss';
const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
const dayNames = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
class Calendar extends React.Component {
static propTypes = {
white: PropTypes.bool,
}
static defaultProps = {
white: false,
}
componentDidMount() {
const $calendar = $(this.element);
const now = new Date();
const month = now.getMonth() + 1;
const year = now.getFullYear();
const events = [
[
`2/${month}/${year}`,
'The flower bed',
'#',
'#547fff',
'Contents here',
],
[
`5/${month}/${year}`,
'Stop world water pollution',
'#',
'#ffc247',
'Have a kick off meeting with .inc company',
],
[
`18/${month}/${year}`,
'Light Blue 2.2 release',
'#',
'#3abf94',
'Some contents here',
],
[
`29/${month}/${year}`,
'A link',
'http://www.flatlogic.com',
'#f55d5d',
],
];
$calendar.calendar({
months: monthNames,
days: dayNames,
events,
popover_options: {
placement: 'top',
html: true,
},
});
$calendar.find('.icon-arrow-left').addClass('la la-arrow-left');
$calendar.find('.icon-arrow-right').addClass('la la-arrow-right');
const restyleCalendar = () => {
$calendar.find('.event').each((index, el) => {
const $eventIndicator = $('<span></span>');
$eventIndicator
.css('background-color', $(el).css('background-color'))
.appendTo($(el).find('a'));
$(el).css('background-color', '');
});
};
$calendar.find('.icon-arrow-left, .icon-arrow-right').parent().on('click', restyleCalendar);
restyleCalendar();
}
render() {
return (<div ref={(el) => this.element = el} className={cx('calendar', { 'calendar-white': this.props.white })} />);
}
}
export default Calendar;