-
Notifications
You must be signed in to change notification settings - Fork 8
/
Day.js
111 lines (100 loc) · 3.34 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
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
/**
* Persian Calendar Picker Component
*
* Copyright 2016 Reza (github.com/rghorbani)
* Licensed under the terms of the MIT license. See LICENSE file in the project root for terms.
*/
'use strict';
const React = require('react');
const PropTypes = require('prop-types');
const {
Text,
TouchableOpacity,
View,
} = require('react-native');
const styles = require('./style');
class Day extends React.Component {
static propTypes = {
date: PropTypes.object,
onDayChange: PropTypes.func,
maxDate: PropTypes.instanceOf(Date),
minDate: PropTypes.instanceOf(Date),
selected: PropTypes.bool,
day: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
]).isRequired,
screenWidth: PropTypes.number,
startFromMonday: PropTypes.bool,
selectedDayColor: PropTypes.string,
selectedDayTextColor: PropTypes.string,
textStyle: Text.propTypes.style,
prevDays: PropTypes.string,
};
constructor(props) {
super(props);
this.DAY_WIDTH = (this.props.screenWidth - 16) / 7;
this.SELECTED_DAY_WIDTH = (this.props.screenWidth - 16) / 7 - 10;
this.BORDER_RADIUS = this.SELECTED_DAY_WIDTH / 2;
this.onDayChange = this.onDayChange.bind(this);
}
render() {
let textStyle = this.props.textStyle;
if (this.props.selected) {
const now = this.props.date._i.replace(/-/g, '').replace('//', '');
if (Number(now) > Number(this.props.prevDays)) {
let selectedDayColorStyle = this.props.selectedDayColor ? {backgroundColor: this.props.selectedDayColor} : {};
let selectedDayTextColorStyle = this.props.selectedDayTextColor ? {color: this.props.selectedDayTextColor} : {};
return (
<View style={styles.dayWrapper}>
<View style={[styles.dayButtonSelected, selectedDayColorStyle]}>
<TouchableOpacity
style={styles.dayButton}
onPress={() => this.onDayChange() }
>
<Text style={[styles.dayLabel, textStyle, selectedDayTextColorStyle, { color: '#fff' }]}>
{this.props.day.toString().PersianNumber()}
</Text>
</TouchableOpacity>
</View>
</View>
);
}else {
return (
<View style={styles.dayWrapper}>
<Text style={[styles.dayLabel, textStyle, styles.disabledTextColor]}>
{this.props.day.toString().PersianNumber()}
</Text>
</View>
);
}
} else {
if (this.props.date < this.props.minDate || this.props.date > this.props.maxDate) {
return (
<View style={styles.dayWrapper}>
<Text style={[styles.dayLabel, textStyle, styles.disabledTextColor]}>
{this.props.day.toString().PersianNumber()}
</Text>
</View>
);
} else {
return (
<View style={styles.dayWrapper}>
<TouchableOpacity
style={styles.dayButton}
onPress={() => this.onDayChange()}
>
<Text style={[styles.dayLabel, textStyle]}>
{this.props.day.toString().PersianNumber()}
</Text>
</TouchableOpacity>
</View>
);
}
}
}
onDayChange() {
this.props.onDayChange && this.props.onDayChange(this.props.day);
}
}
module.exports = Day;