-
Notifications
You must be signed in to change notification settings - Fork 7
/
Month.js
120 lines (108 loc) · 2.27 KB
/
Month.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
import React from 'react';
import {
View,
StyleSheet,
Text
} from 'react-native';
import Day from './Day'
export default class Month extends React.Component {
constructor(props) {
super(props);
this.weekDaysLocale = props.weekDaysLocale.slice();
if (props.startFromMonday) {
this.weekDaysLocale.push(this.weekDaysLocale.shift());
}
}
renderWeekDays(){
let {
width, bodyTextColor
} = this.props;
return(
<View style={styles.weekDaysContainer}>
{
this.weekDaysLocale.map((dayName, i) => {
return(
<View key={i} style={[styles.weekDay, {width: Math.floor(width/7)}]}>
<Text style={[styles.weekDayText, {color: bodyTextColor }]}>
{dayName}
</Text>
</View>
)
})
}
</View>
)
}
renderDays(){
let {
days, changeSelection
} = this.props;
return(
<View style={styles.daysContainer}>
{days.map((day, i) => {
return (
<Day
key={i}
{...this.props}
disabled={day.disabled}
status={day.status}
date={day.date}
onDayPress={changeSelection}
/>
);
})}
</View>
)
}
render() {
let {
days, changeSelection, style, monthsLocale,
bodyBackColor, bodyTextColor, headerSepColor, width, monthTextColor
} = this.props;
var monthHeader = monthsLocale[days[15].date.getMonth()] + ' ' + days[15].date.getFullYear();
return (
<View style={[style, {flex: 1, backgroundColor: bodyBackColor}]}>
<Text style={[styles.monthHeader, {color: monthTextColor || bodyTextColor}]}>
{monthHeader}
</Text>
{this.renderWeekDays()}
{this.renderDays()}
<View style={styles.divider} />
</View>
);
}
}
const styles = StyleSheet.create({
monthHeader: {
fontWeight: '600',
color: '#363636',
fontSize: 16,
marginLeft: 15,
marginVertical: 10
},
weekDayText: {
fontSize: 15,
fontWeight: '500',
marginVertical: 10
},
weekDay: {
justifyContent: 'center',
alignItems: 'center'
},
weekDaysContainer: {
flexDirection: 'row',
justifyContent: 'space-between'
},
daysContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center'
},
divider: {
height: 1,
backgroundColor: '#979797',
alignSelf: 'stretch',
opacity: 0.11
}
});