Skip to content

Commit 1be7b06

Browse files
authored
Merge pull request #135 from lfester/ImproveCalendar
Fix propTypes, README and crash
2 parents 330cb8f + 582da1d commit 1be7b06

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

src/react-chayns-calendar/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The component got the following properties:
2626
| Property | Description | Type | Default | Required
2727
|------------|-----------------------------------------------------------------------------------------------------|--------|-------|------|
2828
| startDate | The *startDate* defines the first month which can be displayed. | date | | |
29-
| endDate | The *end* defines the last month which can be displayed. | bool | | |
29+
| endDate | The *end* defines the last month which can be displayed. | date | | |
3030
| selected | The current selected date | date | today | |
3131
| activated | If activateAll is false this array defines the activated dates | array of date | |
3232
| highlighted | This is an array of special, highlighted dates | array of object | |

src/react-chayns-calendar/component/Calendar.jsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ function getMonthNames(language = chayns.env.language) {
2222

2323
export default class Calendar extends Component {
2424
static propTypes = {
25-
startDate: PropTypes.instanceOf(Date).isRequired,
26-
endDate: PropTypes.instanceOf(Date).isRequired,
27-
onDateSelect: PropTypes.func.isRequired,
25+
startDate: PropTypes.instanceOf(Date),
26+
endDate: PropTypes.instanceOf(Date),
27+
onDateSelect: PropTypes.func,
2828
selected: PropTypes.instanceOf(Date),
2929
activated: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
3030
highlighted: PropTypes.oneOfType([
@@ -44,6 +44,9 @@ export default class Calendar extends Component {
4444

4545
static defaultProps = {
4646
selected: TODAY,
47+
startDate: null,
48+
endDate: null,
49+
onDateSelect: null,
4750
activateAll: true,
4851
activated: null,
4952
highlighted: null,
@@ -299,7 +302,7 @@ export default class Calendar extends Component {
299302
});
300303
}
301304
}
302-
} else {
305+
} else if (_highlighted) {
303306
tempDates.push({
304307
dates: _highlighted.dates,
305308
style: _highlighted.style,

src/react-chayns-calendar/component/DayItem.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class DayItem extends PureComponent {
99
static propTypes = {
1010
date: PropTypes.instanceOf(Date).isRequired,
1111
inMonth: PropTypes.bool.isRequired,
12-
onDateSelect: PropTypes.func.isRequired,
13-
activateAll: PropTypes.func,
12+
onDateSelect: PropTypes.func,
13+
activateAll: PropTypes.bool,
1414
selected: PropTypes.instanceOf(Date),
1515
activated: PropTypes.bool,
1616
highlighted: PropTypes.bool,
@@ -23,6 +23,7 @@ class DayItem extends PureComponent {
2323
highlighted: false,
2424
activateAll: null,
2525
highlightStyle: null,
26+
onDateSelect: null,
2627
};
2728

2829
constructor(props) {

src/react-chayns-calendar/component/Month.jsx

+26-8
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,40 @@ const Month = ({
3333
Month.propTypes = {
3434
title: PropTypes.string,
3535
className: PropTypes.string,
36-
onDateSelect: PropTypes.func.isRequired,
37-
activateAll: PropTypes.func,
38-
startDate: PropTypes.instanceOf(Date).isRequired,
39-
endDate: PropTypes.instanceOf(Date).isRequired,
36+
onDateSelect: PropTypes.func,
37+
activateAll: PropTypes.bool,
38+
startDate: PropTypes.instanceOf(Date),
39+
endDate: PropTypes.instanceOf(Date),
4040
selected: PropTypes.instanceOf(Date),
41-
activated: PropTypes.bool,
42-
highlighted: PropTypes.bool,
41+
activated: PropTypes.arrayOf(Date),
42+
highlighted: PropTypes.oneOfType([
43+
PropTypes.shape({
44+
dates: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
45+
style: PropTypes.shape({
46+
color: PropTypes.string,
47+
backgroundColor: PropTypes.string,
48+
}),
49+
}),
50+
PropTypes.arrayOf(PropTypes.shape({
51+
dates: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
52+
style: PropTypes.shape({
53+
color: PropTypes.string,
54+
backgroundColor: PropTypes.string,
55+
}),
56+
})),
57+
]),
4358
};
4459

4560
Month.defaultProps = {
4661
title: '',
4762
className: '',
4863
selected: null,
49-
activated: false,
64+
activated: null,
65+
startDate: null,
66+
endDate: null,
5067
highlighted: false,
51-
activateAll: null,
68+
activateAll: true,
69+
onDateSelect: null,
5270
};
5371

5472
export default Month;

src/react-chayns-calendar/component/MonthTable.jsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@ function getDayNames(language = chayns.env.language) {
1616

1717
export default class MonthTable extends PureComponent {
1818
static propTypes = {
19-
onDateSelect: PropTypes.func.isRequired,
20-
activateAll: PropTypes.func,
21-
startDate: PropTypes.instanceOf(Date).isRequired,
19+
onDateSelect: PropTypes.func,
20+
activateAll: PropTypes.bool,
21+
startDate: PropTypes.instanceOf(Date),
2222
selected: PropTypes.instanceOf(Date),
23-
activated: PropTypes.bool,
24-
highlighted: PropTypes.bool,
23+
activated: PropTypes.arrayOf(Date),
24+
highlighted: PropTypes.arrayOf(PropTypes.shape({
25+
dates: PropTypes.arrayOf(Date).isRequired,
26+
style: PropTypes.object,
27+
})),
2528
};
2629

2730
static defaultProps = {
2831
selected: null,
29-
activated: false,
30-
highlighted: false,
31-
activateAll: null,
32+
activated: null,
33+
highlighted: null,
34+
startDate: null,
35+
activateAll: true,
36+
onDateSelect: null,
3237
};
3338

3439
static isActivated(activated, date) {

0 commit comments

Comments
 (0)