@momo-kits/calendar 0.0.74-beta → 0.72.1

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.
@@ -1,158 +1,167 @@
1
1
  /* eslint-disable no-param-reassign */
2
- import React, { Component, } from 'react';
3
- import {
4
- Text, TouchableOpacity, View
5
- } from 'react-native';
2
+ import React, {Component} from 'react';
3
+ import {Text, TouchableOpacity, View} from 'react-native';
6
4
  import PropTypes from 'prop-types';
7
- import { IconSource, Image } from '@momo-kits/core';
8
- import { DatePicker } from '@momo-kits/date-picker';
5
+ import {IconSource, Image} from '@momo-kits/core';
6
+ import {DatePicker} from '@momo-kits/date-picker';
9
7
  import styles from './styles';
10
- import { MONTHS } from './util';
8
+ import {MONTHS} from './util';
11
9
 
12
- const padding = (input) => `${input > 9 ? input : `0${input}`}`;
10
+ const padding = input => `${input > 9 ? input : `0${input}`}`;
13
11
 
14
- const formatDate = (date) => {
15
- if (date && typeof date.getDate === 'function') {
16
- return `${padding(date.getMonth() + 1)}/${(date.getFullYear()).toString()}`;
17
- }
18
- return null;
12
+ const formatDate = date => {
13
+ if (date && typeof date.getDate === 'function') {
14
+ return `${padding(date.getMonth() + 1)}/${date.getFullYear().toString()}`;
15
+ }
16
+ return null;
19
17
  };
20
18
 
21
19
  const makeRange = (min = 0, max = 9999, step = 1) => {
22
- const range = [];
23
- let entry = `${0}`;
20
+ const range = [];
21
+ let entry = `${0}`;
24
22
 
25
- for (min; min <= max; min += step) {
26
- entry = `${min}`;
27
- range.push(entry);
28
- }
23
+ for (min; min <= max; min += step) {
24
+ entry = `${min}`;
25
+ range.push(entry);
26
+ }
29
27
 
30
- return range;
28
+ return range;
31
29
  };
32
30
  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
- });
31
+ constructor(props) {
32
+ super(props);
33
+ const {month} = this.props;
34
+ this.state = {
35
+ selectedMonth: month,
102
36
  };
103
37
 
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
- }
38
+ const minYear = 1900 + new Date().getYear();
39
+ const maxYear = minYear + 5;
40
+ this.months = makeRange(1, 12);
41
+ this.years = makeRange(minYear, maxYear);
42
+ this.momoDatePicker = React.createRef();
43
+ }
44
+
45
+ setMonth = month => {
46
+ this.setState({
47
+ selectedMonth: month,
48
+ });
49
+ };
50
+
51
+ getNext = () => {
52
+ const {selectedMonth} = this.state;
53
+ const {getNextYear, onMonthChange} = this.props;
54
+ let next = selectedMonth + 1;
55
+ if (next > 11) {
56
+ next = 0;
57
+ this.setState({selectedMonth: next});
58
+ getNextYear();
59
+ } else {
60
+ this.setState({selectedMonth: next});
115
61
  }
116
62
 
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
- );
63
+ onMonthChange(next);
64
+ };
65
+
66
+ getPrevious = () => {
67
+ const {selectedMonth} = this.state;
68
+ const {onMonthChange, year, minDate, getPrevYear} = this.props;
69
+
70
+ let prev = selectedMonth - 1;
71
+ if (prev < 0) {
72
+ prev = 11;
73
+ this.setState({selectedMonth: prev});
74
+ getPrevYear();
75
+ onMonthChange(prev);
76
+ } else if (year <= minDate.getFullYear() && prev < minDate.getMonth()) {
77
+ return null;
78
+ } else {
79
+ this.setState({selectedMonth: prev});
80
+ onMonthChange(prev);
144
81
  }
82
+ };
83
+
84
+ pickMonthYear = () => {
85
+ const {navigator, minDate, maxDate} = this.props;
86
+ navigator.showBottom({
87
+ screen: DatePicker,
88
+ params: {
89
+ dragDisabled: true,
90
+ onSelected: this.onMonthYearChange,
91
+ onClose: () => {},
92
+ selectedDate: formatDate(minDate),
93
+ minDate: formatDate(minDate),
94
+ maxDate: formatDate(maxDate),
95
+ format: 'MM/YYYY',
96
+ },
97
+ });
98
+ };
99
+
100
+ onMonthYearChange = date => {
101
+ const {onMonthYearChange} = this.props;
102
+ const splitDate = date.split('/');
103
+ const idM = +splitDate[0];
104
+ const idY = +splitDate[1];
105
+ this.setState({
106
+ selectedMonth: idM - 1,
107
+ });
108
+ if (onMonthYearChange) {
109
+ onMonthYearChange(idM - 1, idY);
110
+ }
111
+ };
112
+
113
+ render() {
114
+ const {selectedMonth} = this.state;
115
+ const {year, minDate} = this.props;
116
+ const previous = selectedMonth - 1 < 0 ? 11 : selectedMonth - 1;
117
+ const opacity =
118
+ previous < minDate.getMonth() && minDate.getFullYear() === year ? 0.2 : 1;
119
+ // const monthNow = (new Date()).getMonth() + 1;
120
+ // const yearNow = (new Date()).getYear() + 1900;
121
+ return (
122
+ <View style={styles.headerWrapper}>
123
+ <TouchableOpacity
124
+ onPress={() => this.getPrevious()}
125
+ style={{paddingHorizontal: 20}}>
126
+ <Image
127
+ style={{
128
+ width: 20,
129
+ height: 20,
130
+ opacity,
131
+ }}
132
+ source={IconSource.ic_back_arrow}
133
+ />
134
+ </TouchableOpacity>
135
+
136
+ <TouchableOpacity onPress={this.pickMonthYear}>
137
+ <Text style={styles.monthLabel}>
138
+ {MONTHS[selectedMonth]}/{year}
139
+ </Text>
140
+ </TouchableOpacity>
141
+
142
+ <TouchableOpacity
143
+ onPress={() => this.getNext()}
144
+ style={{paddingHorizontal: 20}}>
145
+ <Image
146
+ style={{
147
+ width: 20,
148
+ height: 20,
149
+ }}
150
+ source={IconSource.ic_arrow_next}
151
+ />
152
+ </TouchableOpacity>
153
+ </View>
154
+ );
155
+ }
145
156
  }
146
157
 
147
158
  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,
159
+ getNextYear: PropTypes.func,
160
+ onMonthChange: PropTypes.func,
161
+ onMonthYearChange: PropTypes.func,
162
+ getPrevYear: PropTypes.func,
163
+ year: PropTypes.number,
164
+ minDate: PropTypes.any,
154
165
  };
155
166
 
156
- HeaderControls.defaultProps = {
157
-
158
- };
167
+ HeaderControls.defaultProps = {};
@@ -1,22 +1,27 @@
1
1
  import React from 'react';
2
- import { View } from 'react-native';
2
+ import {View} from 'react-native';
3
3
 
4
- import { Text } from '@momo-kits/core';
4
+ import {Text} from '@momo-kits/core';
5
5
  import styles from './styles';
6
- import { WEEKDAYS, } from './util';
6
+ import {WEEKDAYS} from './util';
7
7
 
8
8
  const colorDay = '#9199a2';
9
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>
10
+ <View style={styles.dayLabelsWrapper}>
11
+ {WEEKDAYS.map((day, key) => (
12
+ <Text.Title1
13
+ key={key.toString()}
14
+ style={[
15
+ styles.dayLabels,
16
+ {
17
+ color: colorDay,
18
+ fontSize: 16,
19
+ },
20
+ ]}>
21
+ {day}
22
+ </Text.Title1>
23
+ ))}
24
+ </View>
20
25
  );
21
26
 
22
27
  export default WeekDaysLabels;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable react/no-typos */
2
- import React, { Component, } from 'react';
3
- import { View, } from 'react-native';
2
+ import React, {Component} from 'react';
3
+ import {View} from 'react-native';
4
4
  import PropTypes from 'prop-types';
5
5
  import styles from './styles';
6
6
  import HeaderControls from './HeaderControls';
@@ -8,118 +8,118 @@ import Days from './Days';
8
8
  import WeekDaysLabels from './WeekDaysLabels';
9
9
 
10
10
  class CalendarPicker extends Component {
11
- constructor(props) {
12
- super(props);
11
+ constructor(props) {
12
+ super(props);
13
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
- };
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();
33
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
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
- });
35
+ onDayChange = (day, month, year) => {
36
+ const {onDateChange} = this.props;
37
+ const date = new Date(year, month, day);
38
+ if (onDateChange) {
39
+ onDateChange(date);
45
40
  }
46
-
47
- onMonthYearChange = (month, year) => {
48
- this.setState({
49
- month,
50
- year
51
- });
41
+ if (this.refs.header) {
42
+ this.refs.header.setMonth(month);
52
43
  }
44
+ this.setState({
45
+ year,
46
+ month,
47
+ day,
48
+ });
49
+ };
53
50
 
54
- onMonthChange = (month) => {
55
- this.setState({ month, });
56
- }
51
+ onMonthYearChange = (month, year) => {
52
+ this.setState({
53
+ month,
54
+ year,
55
+ });
56
+ };
57
57
 
58
+ onMonthChange = month => {
59
+ this.setState({month});
60
+ };
58
61
 
59
- getNextYear = () => {
60
- const { year } = this.state;
61
- this.setState({ year: parseInt(year) + 1, });
62
- }
62
+ getNextYear = () => {
63
+ const {year} = this.state;
64
+ this.setState({year: parseInt(year) + 1});
65
+ };
63
66
 
64
- getPrevYear =() => {
65
- const { year } = this.state;
66
- this.setState({ year: parseInt(year) - 1, });
67
- }
67
+ getPrevYear = () => {
68
+ const {year} = this.state;
69
+ this.setState({year: parseInt(year) - 1});
70
+ };
68
71
 
69
- setDoubleDateAndTabIndex = (first, second, tabSelected) => {
70
- this.setState({
71
- firstDate: first,
72
- secondDate: second,
73
- tabSelected
74
- });
75
- }
72
+ setDoubleDateAndTabIndex = (first, second, tabSelected) => {
73
+ this.setState({
74
+ firstDate: first,
75
+ secondDate: second,
76
+ tabSelected,
77
+ });
78
+ };
76
79
 
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 />
80
+ render() {
81
+ const {day, year, month, firstDate, secondDate, tabSelected} = this.state;
82
+ const {minDate, maxDate, mode, navigator} = this.props;
83
+ return (
84
+ <View style={styles.calendar}>
85
+ <HeaderControls
86
+ ref="header"
87
+ year={year}
88
+ month={month}
89
+ navigator={navigator}
90
+ onMonthYearChange={this.onMonthYearChange}
91
+ onMonthChange={this.onMonthChange}
92
+ getNextYear={this.getNextYear}
93
+ getPrevYear={this.getPrevYear}
94
+ minDate={minDate || null}
95
+ />
96
+ <WeekDaysLabels />
98
97
 
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
- }
98
+ <Days
99
+ mode={mode}
100
+ firstDate={firstDate}
101
+ secondDate={secondDate}
102
+ tabSelected={tabSelected}
103
+ month={month}
104
+ year={year}
105
+ day={day}
106
+ minDate={minDate || new Date()}
107
+ maxDate={maxDate}
108
+ selectedDate={this.selectedDate}
109
+ onDayChange={this.onDayChange}
110
+ />
111
+ </View>
112
+ );
113
+ }
115
114
  }
115
+
116
116
  export default CalendarPicker;
117
117
 
118
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,
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
125
  };