@momo-kits/calendar 0.0.73-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,203 +1,230 @@
1
- import React, { Component, } from 'react';
2
- import { View, } from 'react-native';
1
+ import React, {Component} from 'react';
2
+ import {View} from 'react-native';
3
3
  import styles from './styles';
4
- import { getDaysInMonth, MAX_COLUMNS, MAX_ROWS, } from './util';
4
+ import {getDaysInMonth, MAX_COLUMNS, MAX_ROWS} from './util';
5
5
  import Day from './Day';
6
6
 
7
7
  export default class Days extends Component {
8
- constructor(props) {
9
- super(props);
10
- this.state = {
11
- selectedDay: 0,
12
- selectedMonth: 0,
13
- selectedYear: 0,
14
- };
15
- this.selectedDate = null;
16
- }
8
+ constructor(props) {
9
+ super(props);
10
+ this.state = {
11
+ selectedDay: 0,
12
+ selectedMonth: 0,
13
+ selectedYear: 0,
14
+ };
15
+ this.selectedDate = null;
16
+ }
17
17
 
18
- componentDidMount() {
19
- const { selectedDate } = this.props;
20
- if (selectedDate) {
21
- const temp = selectedDate;
22
- if (typeof temp.getDate === 'function') {
23
- this.selectedDate = temp;
24
- } else {
25
- this.selectedDate = new Date(temp);
26
- }
27
- this.updateSelectedStates(
28
- this.selectedDate.getDate(),
29
- this.selectedDate.getMonth(),
30
- this.selectedDate.getFullYear(),
31
- );
32
- }
18
+ componentDidMount() {
19
+ const {selectedDate} = this.props;
20
+ if (selectedDate) {
21
+ const temp = selectedDate;
22
+ if (typeof temp.getDate === 'function') {
23
+ this.selectedDate = temp;
24
+ } else {
25
+ this.selectedDate = new Date(temp);
26
+ }
27
+ this.updateSelectedStates(
28
+ this.selectedDate.getDate(),
29
+ this.selectedDate.getMonth(),
30
+ this.selectedDate.getFullYear(),
31
+ );
33
32
  }
33
+ }
34
34
 
35
- updateSelectedStates = (day, month, year) => {
36
- const { onDayChange } = this.props;
37
- // const monthTmp = month + 1;
38
- this.setState({
39
- selectedDay: day,
40
- selectedMonth: month,
41
- selectedYear: year,
42
- });
43
- if (onDayChange) {
44
- onDayChange(day, month, year);
45
- }
35
+ updateSelectedStates = (day, month, year) => {
36
+ const {onDayChange} = this.props;
37
+ // const monthTmp = month + 1;
38
+ this.setState({
39
+ selectedDay: day,
40
+ selectedMonth: month,
41
+ selectedYear: year,
42
+ });
43
+ if (onDayChange) {
44
+ onDayChange(day, month, year);
46
45
  }
46
+ };
47
47
 
48
- onPressDay = (day, month, year) => {
49
- const { minDate, maxDate } = this.props;
50
- const selectDate = new Date(year, month, day);
51
- selectDate.setHours(0, 0, 0, 0);
52
- if (minDate) {
53
- minDate.setHours(0, 0, 0, 0);
54
- if (selectDate < minDate) {
55
- return;
56
- }
57
- }
58
-
59
- if (maxDate) {
60
- maxDate.setHours(0, 0, 0, 0);
61
- if (selectDate > maxDate) {
62
- return;
63
- }
64
- }
65
- this.updateSelectedStates(day, month, year);
48
+ onPressDay = (day, month, year) => {
49
+ const {minDate, maxDate} = this.props;
50
+ const selectDate = new Date(year, month, day);
51
+ selectDate.setHours(0, 0, 0, 0);
52
+ if (minDate) {
53
+ minDate.setHours(0, 0, 0, 0);
54
+ if (selectDate < minDate) {
55
+ return;
56
+ }
66
57
  }
67
58
 
68
- getCalendarDays = () => {
69
- const {
70
- month, year, mode, minDate, maxDate, firstDate, secondDate, tabSelected
71
- } = this.props;
72
- const { selectedMonth, selectedDay, selectedYear } = this.state;
73
- let columns;
74
- const matrix = [];
75
- let i;
76
- let j;
77
- let currentDay = 0;
78
- const thisMonthFirstDay = new Date(year, month, 1);
79
- let slotsAccumulator = 1;
80
-
81
- let goNextMonth = false;
82
- for (i = 0; i < MAX_ROWS; i += 1) { // Week rows
83
- columns = [];
84
- if (goNextMonth) { break; }
85
- for (j = 0; j < MAX_COLUMNS; j += 1) { // Day columns
86
- // HungHC: getDay() Sunday is 0, Monday is 1, and so on.
87
- let tmp = thisMonthFirstDay.getDay();
88
- if (tmp === 0) { tmp = 7; }
89
- if (slotsAccumulator >= tmp) {
90
- if (currentDay < getDaysInMonth(month, year)) {
91
- const day = currentDay + 1;
92
- const selected = (selectedDay === day
93
- && selectedMonth === month
94
- && selectedYear === year);
95
- const date = Date(year, month, day);
59
+ if (maxDate) {
60
+ maxDate.setHours(0, 0, 0, 0);
61
+ if (selectDate > maxDate) {
62
+ return;
63
+ }
64
+ }
65
+ this.updateSelectedStates(day, month, year);
66
+ };
96
67
 
97
- columns.push(<Day
98
- mode={mode}
99
- key={j.toString()}
100
- column={j}
101
- day={day}
102
- month={month}
103
- year={year}
104
- selected={selected}
105
- date={date}
106
- minDate={minDate}
107
- maxDate={maxDate}
108
- firstDate={firstDate}
109
- secondDate={secondDate}
110
- tabSelected={tabSelected}
68
+ getCalendarDays = () => {
69
+ const {
70
+ month,
71
+ year,
72
+ mode,
73
+ minDate,
74
+ maxDate,
75
+ firstDate,
76
+ secondDate,
77
+ tabSelected,
78
+ } = this.props;
79
+ const {selectedMonth, selectedDay, selectedYear} = this.state;
80
+ let columns;
81
+ const matrix = [];
82
+ let i;
83
+ let j;
84
+ let currentDay = 0;
85
+ const thisMonthFirstDay = new Date(year, month, 1);
86
+ let slotsAccumulator = 1;
111
87
 
112
- otherMonth={false}
113
- onDayChange={this.onPressDay}
114
- />);
115
- currentDay += 1;
116
- } else {
117
- // HungHC: show next month
118
- goNextMonth = true;
119
- if (j === 0) {
120
- break;
121
- }
88
+ let goNextMonth = false;
89
+ for (i = 0; i < MAX_ROWS; i += 1) {
90
+ // Week rows
91
+ columns = [];
92
+ if (goNextMonth) {
93
+ break;
94
+ }
95
+ for (j = 0; j < MAX_COLUMNS; j += 1) {
96
+ // Day columns
97
+ // HungHC: getDay() Sunday is 0, Monday is 1, and so on.
98
+ let tmp = thisMonthFirstDay.getDay();
99
+ if (tmp === 0) {
100
+ tmp = 7;
101
+ }
102
+ if (slotsAccumulator >= tmp) {
103
+ if (currentDay < getDaysInMonth(month, year)) {
104
+ const day = currentDay + 1;
105
+ const selected =
106
+ selectedDay === day &&
107
+ selectedMonth === month &&
108
+ selectedYear === year;
109
+ const date = Date(year, month, day);
122
110
 
123
- let nextMonth = month + 1;
124
- const day = currentDay + 1 - getDaysInMonth(month, year);
125
- let yearTmp = year;
126
- if (nextMonth > 11) {
127
- nextMonth = 0;
128
- yearTmp = year + 1;
129
- }
130
- const date = Date(yearTmp, nextMonth, day);
131
- const selected = (selectedDay === day
132
- && selectedMonth === nextMonth
133
- && selectedYear === yearTmp);
134
- columns.push(<Day
135
- mode={mode}
136
- key={j.toString()}
137
- column={j}
138
- day={day}
139
- month={nextMonth}
140
- year={yearTmp}
141
- selected={selected}
142
- date={date}
143
- minDate={minDate}
144
- maxDate={maxDate}
145
- firstDate={firstDate}
146
- secondDate={secondDate}
147
- tabSelected={tabSelected}
148
- otherMonth
149
- onDayChange={this.onPressDay}
150
- />);
151
- currentDay += 1;
152
- }
153
- } else {
154
- // HungHC: show prev month
155
- let prevMonth = month - 1;
156
- let yearTmp = year;
157
- if (prevMonth < 0) {
158
- prevMonth = 11;
159
- yearTmp = year - 1;
160
- }
161
- const daysPrev = getDaysInMonth(prevMonth, yearTmp);
162
- let tmpDay = thisMonthFirstDay.getDay();
163
- if (tmpDay === 0) { tmpDay = 7; }
164
- const delta = (slotsAccumulator - tmpDay + 1);
165
- const day = daysPrev + delta;
111
+ columns.push(
112
+ <Day
113
+ mode={mode}
114
+ key={j.toString()}
115
+ column={j}
116
+ day={day}
117
+ month={month}
118
+ year={year}
119
+ selected={selected}
120
+ date={date}
121
+ minDate={minDate}
122
+ maxDate={maxDate}
123
+ firstDate={firstDate}
124
+ secondDate={secondDate}
125
+ tabSelected={tabSelected}
126
+ otherMonth={false}
127
+ onDayChange={this.onPressDay}
128
+ />,
129
+ );
130
+ currentDay += 1;
131
+ } else {
132
+ // HungHC: show next month
133
+ goNextMonth = true;
134
+ if (j === 0) {
135
+ break;
136
+ }
166
137
 
167
- const selected = (selectedDay === day
168
- && selectedMonth === prevMonth
169
- && selectedYear === yearTmp);
138
+ let nextMonth = month + 1;
139
+ const day = currentDay + 1 - getDaysInMonth(month, year);
140
+ let yearTmp = year;
141
+ if (nextMonth > 11) {
142
+ nextMonth = 0;
143
+ yearTmp = year + 1;
144
+ }
145
+ const date = Date(yearTmp, nextMonth, day);
146
+ const selected =
147
+ selectedDay === day &&
148
+ selectedMonth === nextMonth &&
149
+ selectedYear === yearTmp;
150
+ columns.push(
151
+ <Day
152
+ mode={mode}
153
+ key={j.toString()}
154
+ column={j}
155
+ day={day}
156
+ month={nextMonth}
157
+ year={yearTmp}
158
+ selected={selected}
159
+ date={date}
160
+ minDate={minDate}
161
+ maxDate={maxDate}
162
+ firstDate={firstDate}
163
+ secondDate={secondDate}
164
+ tabSelected={tabSelected}
165
+ otherMonth
166
+ onDayChange={this.onPressDay}
167
+ />,
168
+ );
169
+ currentDay += 1;
170
+ }
171
+ } else {
172
+ // HungHC: show prev month
173
+ let prevMonth = month - 1;
174
+ let yearTmp = year;
175
+ if (prevMonth < 0) {
176
+ prevMonth = 11;
177
+ yearTmp = year - 1;
178
+ }
179
+ const daysPrev = getDaysInMonth(prevMonth, yearTmp);
180
+ let tmpDay = thisMonthFirstDay.getDay();
181
+ if (tmpDay === 0) {
182
+ tmpDay = 7;
183
+ }
184
+ const delta = slotsAccumulator - tmpDay + 1;
185
+ const day = daysPrev + delta;
170
186
 
171
- const date = Date(yearTmp, prevMonth, day);
172
- columns.push(<Day
173
- mode={mode}
174
- key={j.toString()}
175
- column={j}
176
- day={day}
177
- month={prevMonth}
178
- year={yearTmp}
179
- selected={selected}
180
- date={date}
181
- minDate={minDate}
182
- maxDate={maxDate}
183
- firstDate={firstDate}
184
- secondDate={secondDate}
185
- tabSelected={tabSelected}
186
- otherMonth
187
- onDayChange={this.onPressDay}
188
- />);
189
- }
187
+ const selected =
188
+ selectedDay === day &&
189
+ selectedMonth === prevMonth &&
190
+ selectedYear === yearTmp;
190
191
 
191
- slotsAccumulator += 1;
192
- }
193
- matrix[i] = [];
194
- matrix[i].push(<View key={i.toString()} style={styles.weekRow}>{columns}</View>);
192
+ const date = Date(yearTmp, prevMonth, day);
193
+ columns.push(
194
+ <Day
195
+ mode={mode}
196
+ key={j.toString()}
197
+ column={j}
198
+ day={day}
199
+ month={prevMonth}
200
+ year={yearTmp}
201
+ selected={selected}
202
+ date={date}
203
+ minDate={minDate}
204
+ maxDate={maxDate}
205
+ firstDate={firstDate}
206
+ secondDate={secondDate}
207
+ tabSelected={tabSelected}
208
+ otherMonth
209
+ onDayChange={this.onPressDay}
210
+ />,
211
+ );
195
212
  }
196
213
 
197
- return matrix;
214
+ slotsAccumulator += 1;
215
+ }
216
+ matrix[i] = [];
217
+ matrix[i].push(
218
+ <View key={i.toString()} style={styles.weekRow}>
219
+ {columns}
220
+ </View>,
221
+ );
198
222
  }
199
223
 
200
- render() {
201
- return <View style={styles.daysWrapper}>{ this.getCalendarDays()}</View>;
202
- }
224
+ return matrix;
225
+ };
226
+
227
+ render() {
228
+ return <View style={styles.daysWrapper}>{this.getCalendarDays()}</View>;
229
+ }
203
230
  }