-
Notifications
You must be signed in to change notification settings - Fork 1
/
Day.js
61 lines (54 loc) · 1.82 KB
/
Day.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
import React, {Component, View, TouchableOpacity, Text, PropTypes, StyleSheet} from 'react-native';
import moment from 'moment';
export default class Day extends Component {
static propTypes = {
filler: PropTypes.bool,
isSelected: PropTypes.bool,
currentDay: PropTypes.instanceOf(moment),
events: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.string,
PropTypes.instanceOf(moment)
])
),
onPress: PropTypes.func,
dayStyle: React.PropTypes.object,
};
static defaultProps = {
dayStyle: {}
};
render() {
if(this.props.filler)
return <View style={[styles.day, this.props.dayStyle.day, this.props.dayStyle.filler]}><Text>{' '}</Text></View>;
const isToday = this.props.currentDay.isSame(moment(), 'd');
const hasEvents = this.props.events.length > 0;
let style = [];
style.push(styles.day);
style.push(this.props.dayStyle.day);
isToday && style.push(styles.today);
isToday && style.push(this.props.dayStyle.today);
hasEvents && style.push(styles.dayWithEvents);
hasEvents && style.push(this.props.dayStyle.dayWithEvents);
this.props.isSelected && style.push(styles.daySelected);
this.props.isSelected && style.push(this.props.dayStyle.daySelected);
return (
<View style={style}>
<TouchableOpacity onPress={this.props.onPress}>
<Text style={this.props.dayStyle.text}>{this.props.currentDay.format('D')}</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
day: {
flex: 1,
alignItems: 'center'
},
today: {
},
dayWithEvents: {
},
daySelected: {
}
});