@momo-kits/calendar 0.0.32-beta → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import React, { Component, } from 'react';
3
+ import {
4
+ Text, TouchableOpacity, View
5
+ } from 'react-native';
6
+ import PropTypes from 'prop-types';
7
+ import { IconSource, Image } from '@momo-kits/core';
8
+ import { DatePicker } from '@momo-kits/date-picker';
9
+ import styles from './styles';
10
+ import { MONTHS } from './util';
11
+
12
+ const padding = (input) => `${input > 9 ? input : `0${input}`}`;
13
+
14
+ const formatDate = (date) => {
15
+ if (date && typeof date.getDate === 'function') {
16
+ return `${padding(date.getMonth() + 1)}/${(date.getFullYear()).toString()}`;
17
+ }
18
+ return null;
19
+ };
20
+
21
+ const makeRange = (min = 0, max = 9999, step = 1) => {
22
+ const range = [];
23
+ let entry = `${0}`;
24
+
25
+ for (min; min <= max; min += step) {
26
+ entry = `${min}`;
27
+ range.push(entry);
28
+ }
29
+
30
+ return range;
31
+ };
32
+ export default class HeaderControls extends Component {
33
+ constructor(props) {
34
+ super(props);
35
+ const { month } = this.props;
36
+ this.state = {
37
+ selectedMonth: month
38
+ };
39
+
40
+ const minYear = 1900 + (new Date()).getYear();
41
+ const maxYear = minYear + 5;
42
+ this.months = makeRange(1, 12);
43
+ this.years = makeRange(minYear, maxYear);
44
+ this.momoDatePicker = React.createRef();
45
+ }
46
+
47
+ setMonth = (month) => {
48
+ this.setState({
49
+ selectedMonth: month,
50
+ });
51
+ }
52
+
53
+ getNext = () => {
54
+ const { selectedMonth } = this.state;
55
+ const { getNextYear, onMonthChange } = this.props;
56
+ let next = selectedMonth + 1;
57
+ if (next > 11) {
58
+ next = 0;
59
+ this.setState({ selectedMonth: next });
60
+ getNextYear();
61
+ } else {
62
+ this.setState({ selectedMonth: next });
63
+ }
64
+
65
+ onMonthChange(next);
66
+ }
67
+
68
+ getPrevious = () => {
69
+ const { selectedMonth } = this.state;
70
+ const {
71
+ onMonthChange, year, minDate, getPrevYear
72
+ } = this.props;
73
+
74
+ let prev = selectedMonth - 1;
75
+ if (prev < 0) {
76
+ prev = 11;
77
+ this.setState({ selectedMonth: prev });
78
+ getPrevYear();
79
+ onMonthChange(prev);
80
+ } else if (year <= minDate.getFullYear() && prev < minDate.getMonth()) {
81
+ return null;
82
+ } else {
83
+ this.setState({ selectedMonth: prev });
84
+ onMonthChange(prev);
85
+ }
86
+ }
87
+
88
+ pickMonthYear = () => {
89
+ const { navigator, minDate, maxDate } = this.props;
90
+ navigator.showBottom({
91
+ screen: DatePicker,
92
+ params: {
93
+ dragDisabled: true,
94
+ onSelected: this.onMonthYearChange,
95
+ onClose: () => { },
96
+ selectedDate: formatDate(minDate),
97
+ minDate: formatDate(minDate),
98
+ maxDate: formatDate(maxDate),
99
+ format: 'MM/YYYY',
100
+ }
101
+ });
102
+ };
103
+
104
+ onMonthYearChange = (date) => {
105
+ const { onMonthYearChange } = this.props;
106
+ const splitDate = date.split('/');
107
+ const idM = +splitDate[0];
108
+ const idY = +splitDate[1];
109
+ this.setState({
110
+ selectedMonth: idM - 1
111
+ });
112
+ if (onMonthYearChange) {
113
+ onMonthYearChange(idM - 1, idY);
114
+ }
115
+ }
116
+
117
+ render() {
118
+ const { selectedMonth } = this.state;
119
+ const { year, minDate } = this.props;
120
+ const previous = selectedMonth - 1 < 0 ? 11 : selectedMonth - 1;
121
+ const opacity = (previous < minDate.getMonth() && minDate.getFullYear() === year) ? 0.2 : 1;
122
+ // const monthNow = (new Date()).getMonth() + 1;
123
+ // const yearNow = (new Date()).getYear() + 1900;
124
+ return (
125
+ <View style={styles.headerWrapper}>
126
+
127
+ <TouchableOpacity onPress={() => this.getPrevious()} style={{ paddingHorizontal: 20, }}>
128
+ <Image style={{ width: 20, height: 20, opacity }} source={IconSource.ic_back_arrow} />
129
+ </TouchableOpacity>
130
+
131
+ <TouchableOpacity onPress={this.pickMonthYear}>
132
+ <Text style={styles.monthLabel}>
133
+ { MONTHS[selectedMonth] }
134
+ /
135
+ { year }
136
+ </Text>
137
+ </TouchableOpacity>
138
+
139
+ <TouchableOpacity onPress={() => this.getNext()} style={{ paddingHorizontal: 20, }}>
140
+ <Image style={{ width: 20, height: 20, }} source={IconSource.ic_arrow_next} />
141
+ </TouchableOpacity>
142
+ </View>
143
+ );
144
+ }
145
+ }
146
+
147
+ HeaderControls.propTypes = {
148
+ getNextYear: PropTypes.func,
149
+ onMonthChange: PropTypes.func,
150
+ onMonthYearChange: PropTypes.func,
151
+ getPrevYear: PropTypes.func,
152
+ year: PropTypes.number,
153
+ minDate: PropTypes.any,
154
+ };
155
+
156
+ HeaderControls.defaultProps = {
157
+
158
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ import { Text } from '@momo-kits/core';
5
+ import styles from './styles';
6
+ import { WEEKDAYS, } from './util';
7
+
8
+ const colorDay = '#9199a2';
9
+ const WeekDaysLabels = () => (
10
+ <View style={styles.dayLabelsWrapper}>
11
+ { WEEKDAYS.map((day, key) => (
12
+ <Text.Title
13
+ key={key.toString()}
14
+ style={[styles.dayLabels, { color: colorDay, fontSize: 16 }]}
15
+ >
16
+ {day}
17
+ </Text.Title>
18
+ )) }
19
+ </View>
20
+ );
21
+
22
+ export default WeekDaysLabels;
@@ -0,0 +1,125 @@
1
+ /* eslint-disable react/no-typos */
2
+ import React, { Component, } from 'react';
3
+ import { View, } from 'react-native';
4
+ import PropTypes from 'prop-types';
5
+ import styles from './styles';
6
+ import HeaderControls from './HeaderControls';
7
+ import Days from './Days';
8
+ import WeekDaysLabels from './WeekDaysLabels';
9
+
10
+ class CalendarPicker extends Component {
11
+ constructor(props) {
12
+ super(props);
13
+
14
+ this.selectedDate = null;
15
+ const temp = props.selectedDate;
16
+ try {
17
+ if (typeof temp.getDate === 'function') {
18
+ this.selectedDate = temp;
19
+ } else {
20
+ this.selectedDate = new Date(temp);
21
+ }
22
+ } catch (e) {
23
+ this.selectedDate = new Date();
24
+ }
25
+ this.state = {
26
+ // date: this.selectedDate,
27
+ month: this.selectedDate.getMonth(),
28
+ day: this.selectedDate.getDate(),
29
+ year: this.selectedDate.getFullYear(),
30
+ // selectedDay: [],
31
+ tabSelected: 0,
32
+ };
33
+ }
34
+
35
+ onDayChange = (day, month, year) => {
36
+ const { onDateChange } = this.props;
37
+ const date = new Date(year, month, day);
38
+ if (onDateChange) { onDateChange(date); }
39
+ if (this.refs.header) { this.refs.header.setMonth(month); }
40
+ this.setState({
41
+ year,
42
+ month,
43
+ day,
44
+ });
45
+ }
46
+
47
+ onMonthYearChange = (month, year) => {
48
+ this.setState({
49
+ month,
50
+ year
51
+ });
52
+ }
53
+
54
+ onMonthChange = (month) => {
55
+ this.setState({ month, });
56
+ }
57
+
58
+
59
+ getNextYear = () => {
60
+ const { year } = this.state;
61
+ this.setState({ year: parseInt(year) + 1, });
62
+ }
63
+
64
+ getPrevYear =() => {
65
+ const { year } = this.state;
66
+ this.setState({ year: parseInt(year) - 1, });
67
+ }
68
+
69
+ setDoubleDateAndTabIndex = (first, second, tabSelected) => {
70
+ this.setState({
71
+ firstDate: first,
72
+ secondDate: second,
73
+ tabSelected
74
+ });
75
+ }
76
+
77
+ render() {
78
+ const {
79
+ day, year, month, firstDate, secondDate, tabSelected
80
+ } = this.state;
81
+ const {
82
+ minDate, maxDate, mode, navigator
83
+ } = this.props;
84
+ return (
85
+ <View style={styles.calendar}>
86
+ <HeaderControls
87
+ ref="header"
88
+ year={year}
89
+ month={month}
90
+ navigator={navigator}
91
+ onMonthYearChange={this.onMonthYearChange}
92
+ onMonthChange={this.onMonthChange}
93
+ getNextYear={this.getNextYear}
94
+ getPrevYear={this.getPrevYear}
95
+ minDate={minDate || null}
96
+ />
97
+ <WeekDaysLabels />
98
+
99
+ <Days
100
+ mode={mode}
101
+ firstDate={firstDate}
102
+ secondDate={secondDate}
103
+ tabSelected={tabSelected}
104
+ month={month}
105
+ year={year}
106
+ day={day}
107
+ minDate={minDate || new Date()}
108
+ maxDate={maxDate}
109
+ selectedDate={this.selectedDate}
110
+ onDayChange={this.onDayChange}
111
+ />
112
+ </View>
113
+ );
114
+ }
115
+ }
116
+ export default CalendarPicker;
117
+
118
+ CalendarPicker.propTypes = {
119
+ navigator: PropTypes.object.isRequired,
120
+ minDate: PropTypes.any,
121
+ maxDate: PropTypes.any,
122
+ mode: PropTypes.oneOf(['doubleDate', 'signleDate']),
123
+ selectedDate: PropTypes.any,
124
+ onDateChange: PropTypes.func,
125
+ };
@@ -0,0 +1,184 @@
1
+ import { Dimensions, StyleSheet } from 'react-native';
2
+
3
+ const widthScreen = Dimensions.get('window').width;
4
+
5
+ const styles = StyleSheet.create({
6
+ calendar: {
7
+ // height:widthScreen - 20,
8
+ backgroundColor: 'white',
9
+ borderColor: '#DADADA',
10
+ borderBottomWidth: 1,
11
+ borderTopWidth: 1,
12
+ },
13
+ dayWrapper: {
14
+ width: widthScreen / 7,
15
+ height: 40,
16
+ backgroundColor: 'rgba(0,0,0,0.0)'
17
+
18
+ },
19
+
20
+ dayButton: {
21
+ width: 50,
22
+ height: 50,
23
+ alignSelf: 'center'
24
+ },
25
+
26
+ styleFirstDate: {
27
+ position: 'absolute',
28
+ // width:45,
29
+ height: 40,
30
+ top: 0,
31
+ left: widthScreen / 14,
32
+ right: -1,
33
+ backgroundColor: '#90d6f3',
34
+ borderRadius: 0
35
+ },
36
+ styleSecondDate: {
37
+ position: 'absolute',
38
+ // width:45,
39
+ height: 40,
40
+ top: 0,
41
+ right: widthScreen / 14,
42
+ left: 0,
43
+ backgroundColor: '#90d6f3',
44
+ borderRadius: 0
45
+ },
46
+ styleBetween: {
47
+ height: 40,
48
+ // width:60,
49
+ top: 0,
50
+ left: 0,
51
+ right: -1,
52
+ position: 'absolute',
53
+ backgroundColor: '#90d6f3',
54
+ borderRadius: 0
55
+ },
56
+ dayButtonSelected: {
57
+ width: 40,
58
+ height: 40,
59
+ borderRadius: 20,
60
+ backgroundColor: '#2eb3e8',
61
+ alignSelf: 'center'
62
+ },
63
+
64
+ dayButtonNow: {
65
+ width: 40,
66
+ height: 40,
67
+ borderRadius: 20,
68
+ backgroundColor: '#8F8E94',
69
+ alignSelf: 'center'
70
+ },
71
+
72
+ dayLabel: {
73
+ fontSize: 16,
74
+ color: '#393939',
75
+ marginTop: 10,
76
+ alignSelf: 'center'
77
+ },
78
+
79
+ dayLabelsWrapper: {
80
+ width: widthScreen,
81
+ flexDirection: 'row',
82
+ marginBottom: 10,
83
+ paddingTop: 5,
84
+ paddingBottom: 5,
85
+ borderColor: '#DADADA',
86
+ borderBottomWidth: 1,
87
+ borderTopWidth: 1,
88
+ },
89
+
90
+ daysWrapper: {
91
+ alignSelf: 'center',
92
+ },
93
+
94
+ dayLabels: {
95
+ width: widthScreen / 7,
96
+ fontSize: 12,
97
+ color: '#000',
98
+ textAlign: 'center',
99
+ },
100
+
101
+ selectedDay: {
102
+ width: 60,
103
+ height: 60,
104
+ backgroundColor: '#5ce600',
105
+ borderRadius: 30,
106
+ alignSelf: 'center'
107
+ },
108
+
109
+ monthLabel: {
110
+ fontSize: widthScreen > 320 ? 20 : 17,
111
+ fontWeight: '300',
112
+ color: '#000',
113
+ width: 180,
114
+ textAlign: 'center'
115
+ },
116
+
117
+ headerWrapper: {
118
+ width: widthScreen,
119
+ alignItems: 'center',
120
+ justifyContent: 'space-between',
121
+ flexDirection: 'row',
122
+ marginVertical: 10,
123
+ backgroundColor: 'rgba(0,0,0,0.0)'
124
+ },
125
+
126
+ monthSelector: {
127
+ width: 80,
128
+ },
129
+
130
+ prev: {
131
+ textAlign: 'left',
132
+ fontSize: 16,
133
+ color: '#dadada',
134
+ },
135
+
136
+ next: {
137
+ textAlign: 'right',
138
+ fontSize: 16,
139
+ color: '#dadada',
140
+ },
141
+
142
+ yearLabel: {
143
+ fontSize: 14,
144
+ fontWeight: 'bold',
145
+ color: '#000',
146
+ textAlign: 'center'
147
+ },
148
+
149
+ weeks: {
150
+ flexDirection: 'column'
151
+ },
152
+
153
+ weekRow: {
154
+ flexDirection: 'row'
155
+ },
156
+ btnCellHeader: {
157
+ flex: 1,
158
+ justifyContent: 'center',
159
+ alignItems: 'center',
160
+ borderWidth: 1,
161
+ borderColor: '#DADADA',
162
+ backgroundColor: 'white'
163
+ },
164
+ center: {
165
+ justifyContent: 'center',
166
+ alignItems: 'center'
167
+ },
168
+ txtDate: {
169
+ color: '#4D4D4D',
170
+ fontSize: 18,
171
+ fontWeight: 'bold',
172
+ paddingVertical: 10
173
+ },
174
+ lineActiveTab: {
175
+ height: 3,
176
+ width: '100%',
177
+ position: 'absolute',
178
+ bottom: 0,
179
+ left: 0,
180
+ backgroundColor: '#49A3BC'
181
+ }
182
+ });
183
+
184
+ export default styles;
@@ -0,0 +1,50 @@
1
+ import { SwitchLanguage } from '@momo-kits/core';
2
+
3
+ module.exports = {
4
+ WEEKDAYS: SwitchLanguage.getLocalize({
5
+ vi: [
6
+ 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN',
7
+ ],
8
+ en: ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
9
+ }),
10
+
11
+ WEEKDAYSNAME: [
12
+ 'Thứ 2', 'Thứ 3', 'Thứ 4', 'Thứ 5', 'Thứ 6', 'Thứ 7', 'Chủ nhật',
13
+ ],
14
+
15
+ MONTHS: SwitchLanguage.getLocalize({
16
+ vi: [
17
+ 'Tháng 1', 'Tháng 2', 'Tháng 3', 'Tháng 4', 'Tháng 5', 'Tháng 6', 'Tháng 7',
18
+ 'Tháng 8', 'Tháng 9', 'Tháng 10', 'Tháng 11', 'Tháng 12'
19
+ ],
20
+ en: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
21
+ }),
22
+
23
+ MAX_ROWS: 7,
24
+
25
+ MAX_COLUMNS: 7,
26
+
27
+ getDaysInMonth(month, year) {
28
+ const lastDayOfMonth = new Date(year, month + 1, 0);
29
+ return lastDayOfMonth.getDate();
30
+ },
31
+
32
+ getDayofDate(date) {
33
+ const WEEKDAYSNAME = ['Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm', 'Thứ sáu', 'Thứ bảy', 'Chủ nhật'];
34
+ let day = date.getDay();
35
+ if (date.getDay() === 0) {
36
+ day = 7;
37
+ }
38
+ return WEEKDAYSNAME[day - 1];
39
+ },
40
+ formatDate(date) {
41
+ const padding = (input) => `${input > 9 ? input : `0${input}`}`;
42
+ if (date && typeof date.getDate === 'function') {
43
+ return `${padding(date.getDate())}/${
44
+ padding(date.getMonth() + 1)}/${
45
+ (date.getFullYear()).toString()}`;
46
+ }
47
+ return null;
48
+ },
49
+
50
+ };
@@ -1 +1,127 @@
1
- var _core=require("@momo-kits/core");module.exports={solar:{1:[{day:1,month:1,label:_core.SwitchLanguage.newYear}],2:[{day:14,month:2,label:_core.SwitchLanguage.valentine}],3:[{day:8,month:3,label:_core.SwitchLanguage.womenDay}],4:[{day:30,month:4,label:_core.SwitchLanguage.liberationDay}],5:[{day:1,month:5,label:_core.SwitchLanguage.laborDay}],6:[{day:1,month:6,label:_core.SwitchLanguage.childrenDay}],9:[{day:2,month:9,label:_core.SwitchLanguage.nationalDay}],10:[{day:20,month:10,label:_core.SwitchLanguage.womenDayVN}],11:[{day:20,month:11,label:_core.SwitchLanguage.teacherDay}],12:[{day:24,month:12,label:_core.SwitchLanguage.christmasEve},{day:25,month:12,label:_core.SwitchLanguage.christmas}]},lunar:[{lunarDay:30,lunarMonth:12,lunar:true,label:_core.SwitchLanguage.lunarNewYear,highlight:'(30/12)'},{lunarDay:1,lunarMonth:1,lunar:true,label:_core.SwitchLanguage.lunarNewYear,highlight:'(1/1)'},{lunarDay:2,lunarMonth:1,lunar:true,label:_core.SwitchLanguage.lunarNewYear,highlight:'(2/1)'},{lunarDay:3,lunarMonth:1,lunar:true,label:_core.SwitchLanguage.lunarNewYear,highlight:'(3/1)'},{lunarDay:4,lunarMonth:1,lunar:true,label:_core.SwitchLanguage.lunarNewYear,highlight:'(4/1)'},{lunarDay:10,lunarMonth:3,lunar:true,label:_core.SwitchLanguage.hungKingDay,highlight:'(10/3)'}]};
1
+ import {
2
+ SwitchLanguage
3
+ } from '@momo-kits/core';
4
+
5
+ module.exports = {
6
+ solar: {
7
+ 1: [
8
+ {
9
+ day: 1,
10
+ month: 1,
11
+ label: SwitchLanguage.newYear
12
+ }
13
+ ],
14
+ 2: [
15
+ {
16
+ day: 14,
17
+ month: 2,
18
+ label: SwitchLanguage.valentine
19
+ }
20
+ ],
21
+ 3: [
22
+ {
23
+ day: 8,
24
+ month: 3,
25
+ label: SwitchLanguage.womenDay
26
+ }
27
+ ],
28
+ 4: [
29
+ {
30
+ day: 30,
31
+ month: 4,
32
+ label: SwitchLanguage.liberationDay
33
+ }
34
+ ],
35
+ 5: [
36
+ {
37
+ day: 1,
38
+ month: 5,
39
+ label: SwitchLanguage.laborDay
40
+ }
41
+ ],
42
+ 6: [
43
+ {
44
+ day: 1,
45
+ month: 6,
46
+ label: SwitchLanguage.childrenDay
47
+ }
48
+ ],
49
+ 9: [
50
+ {
51
+ day: 2,
52
+ month: 9,
53
+ label: SwitchLanguage.nationalDay
54
+ }
55
+ ],
56
+ 10: [
57
+ {
58
+ day: 20,
59
+ month: 10,
60
+ label: SwitchLanguage.womenDayVN
61
+ }
62
+ ],
63
+ 11: [
64
+ {
65
+ day: 20,
66
+ month: 11,
67
+ label: SwitchLanguage.teacherDay
68
+ }
69
+ ],
70
+ 12: [
71
+ {
72
+ day: 24,
73
+ month: 12,
74
+ label: SwitchLanguage.christmasEve
75
+ },
76
+ {
77
+ day: 25,
78
+ month: 12,
79
+ label: SwitchLanguage.christmas
80
+ }
81
+ ]
82
+ },
83
+ lunar: [
84
+ {
85
+ lunarDay: 30,
86
+ lunarMonth: 12,
87
+ lunar: true,
88
+ label: SwitchLanguage.lunarNewYear,
89
+ highlight: '(30/12)'
90
+ },
91
+ {
92
+ lunarDay: 1,
93
+ lunarMonth: 1,
94
+ lunar: true,
95
+ label: SwitchLanguage.lunarNewYear,
96
+ highlight: '(1/1)'
97
+ },
98
+ {
99
+ lunarDay: 2,
100
+ lunarMonth: 1,
101
+ lunar: true,
102
+ label: SwitchLanguage.lunarNewYear,
103
+ highlight: '(2/1)'
104
+ },
105
+ {
106
+ lunarDay: 3,
107
+ lunarMonth: 1,
108
+ lunar: true,
109
+ label: SwitchLanguage.lunarNewYear,
110
+ highlight: '(3/1)'
111
+ },
112
+ {
113
+ lunarDay: 4,
114
+ lunarMonth: 1,
115
+ lunar: true,
116
+ label: SwitchLanguage.lunarNewYear,
117
+ highlight: '(4/1)'
118
+ },
119
+ {
120
+ lunarDay: 10,
121
+ lunarMonth: 3,
122
+ lunar: true,
123
+ label: SwitchLanguage.hungKingDay,
124
+ highlight: '(10/3)'
125
+ }
126
+ ]
127
+ };
package/babel.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports={presets:['module:metro-react-native-babel-preset']};