@momo-kits/calendar 0.0.34-beta → 0.0.34
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.
- package/index.js +4 -1
- package/package.json +7 -12
- package/publish.sh +2 -2
- package/src/Calendar.js +394 -1
- package/src/CalendarPro.js +363 -1
- package/src/Day/index.js +210 -1
- package/src/Day/style.js +129 -1
- package/src/HeaderControl.js +79 -1
- package/src/LunarDateConverter.js +191 -1
- package/src/LunarService.js +185 -1
- package/src/Month/index.js +80 -1
- package/src/MonthList.js +253 -1
- package/src/TabHeader.js +79 -1
- package/src/Util.js +225 -1
- package/src/calendarPicker/Day.js +154 -0
- package/src/calendarPicker/Days.js +203 -0
- package/src/calendarPicker/HeaderControls.js +158 -0
- package/src/calendarPicker/WeekDaysLabels.js +22 -0
- package/src/calendarPicker/index.js +125 -0
- package/src/calendarPicker/styles.js +184 -0
- package/src/calendarPicker/util.js +50 -0
- package/src/holidayData.js +127 -1
- package/babel.config.js +0 -1
package/src/CalendarPro.js
CHANGED
|
@@ -1 +1,363 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _react=_interopRequireWildcard(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));var _reactNative=require("react-native");var _moment=_interopRequireDefault(require("moment"));var _core=require("@momo-kits/core");var _MonthList=_interopRequireDefault(require("./MonthList"));var _HeaderControl=_interopRequireDefault(require("./HeaderControl"));var _LunarDateConverter=_interopRequireDefault(require("./LunarDateConverter"));var _Util=_interopRequireDefault(require("./Util"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/calendar/dist/src/CalendarPro.js";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});}keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=(0,_getPrototypeOf2.default)(Derived),result;if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2.default)(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return(0,_possibleConstructorReturn2.default)(this,result);};}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}var widthScreen=_reactNative.Dimensions.get('window').width;var CalendarPro=function(_Component){(0,_inherits2.default)(CalendarPro,_Component);var _super=_createSuper(CalendarPro);function CalendarPro(props){var _this;(0,_classCallCheck2.default)(this,CalendarPro);_this=_super.call(this,props);_this.setDateRange=function(dateRange,isScrollToStartDate){if(dateRange&&dateRange.startDate&&dateRange.endDate){_this.setState({startDate:dateRange.startDate,endDate:dateRange.endDate},function(){var dateScroll=isScrollToStartDate?dateRange.startDate:dateRange.endDate;_this.refs.MonthList.scrollToMonth(dateScroll);});}};_this.loadLabel=function(data,type){var _this$props=_this.props,i18n=_this$props.i18n,customI18n=_this$props.customI18n;if(~['w','weekday','text'].indexOf(type)){return(customI18n[type]||{})[data]||_Util.default.I18N_MAP[i18n][type][data];}if(type==='date'){return data.format(customI18n[type]||_Util.default.I18N_MAP[i18n][type]);}};_this.getDateRange=function(){var _this$props2=_this.props,maxDate=_this$props2.maxDate,minDate=_this$props2.minDate,format=_this$props2.format;var max=(0,_moment.default)(maxDate,format);var min=(0,_moment.default)(minDate,format);var maxValid=max.isValid();var minValid=min.isValid();if(!maxValid&&!minValid){max=(0,_moment.default)().add(12,'months');min=(0,_moment.default)();}if(!maxValid&&minValid){max=min.add(12,'months');}if(maxValid&&!minValid){min=max.subtract(12,'months');}if(min.isSameOrAfter(max))return{};_this.minDate=min;_this.maxDate=max;};_this.onChoose=function(day){var _this$state=_this.state,startDate=_this$state.startDate,tabSelected=_this$state.tabSelected;var _this$props3=_this.props,isDoubleDateMode=_this$props3.isDoubleDateMode,onDateChange=_this$props3.onDateChange;if(isDoubleDateMode){if(tabSelected===1){if(startDate&&day>=startDate){_this.ownSetState({endDate:day});}else if(startDate&&day<startDate){_this.ownSetState({startDate:day,endDate:null});}}else{_this.ownSetState({startDate:day});}}else{_this.ownSetState({startDate:day,endDate:null});}if(onDateChange){onDateChange(day);}};_this.executeProcessAfterScrollCalendar=function(date,key){var holidays=Object.values(_Util.default.getHolidaysInMonth((0,_moment.default)(date)));var showLunar=_this.state.showLunar;if(_this.refs&&_this.refs.HeaderControl){_this.refs.HeaderControl.onUpdateInfo({date:date});_this.header=date.clone().startOf('month');}var data=[];if(!showLunar){data=holidays.filter(function(item){return!item.lunar||item.mixedLabel;});}else{data=holidays;}_this.ownSetState({holidays:holidays,temp:data,headerKey:key});};_this.onScrollCalendar=function(data){var headerKey=_this.state.headerKey;if(data){if(data.key!==headerKey){_this.executeProcessAfterScrollCalendar(data.date,data.key);}}};_this.setDoubleDateAndTabIndex=function(firstDate,secondDate,tabSelected){_this.ownSetState({startDate:firstDate?(0,_moment.default)(firstDate):null,endDate:secondDate?(0,_moment.default)(secondDate):null,tabSelected:tabSelected});};_this.toggleLunarDate=function(){var _this$state2=_this.state,showLunar=_this$state2.showLunar,holidays=_this$state2.holidays;var onCallbackCalendar=_this.props.onCallbackCalendar;var data=[];var nextStateShowLunar=!showLunar;if(!nextStateShowLunar){data=holidays.filter(function(item){return!item.lunar||item.mixedLabel;});}else{data=holidays;}if(onCallbackCalendar){onCallbackCalendar('lunar',nextStateShowLunar);}_this.ownSetState({showLunar:!showLunar,temp:data,ownUpdate:true});};_this.onPressBackArrow=function(){var previousDate=(0,_moment.default)(_this.header).startOf('month').subtract(1,'months');if(_this.refs&&_this.refs.HeaderControl&&previousDate.isSameOrAfter(_this.minDate,'month')){_this.header=previousDate;_this.refs.HeaderControl.onUpdateInfo({date:previousDate});_this.refs.MonthList.scrollToMonth(previousDate);}};_this.onPressNextArrow=function(){var nextDate=(0,_moment.default)(_this.header).startOf('month').add(1,'months');if(_this.refs&&_this.refs.HeaderControl&&nextDate.isSameOrBefore(_this.maxDate,'month')){_this.header=nextDate;_this.refs.HeaderControl.onUpdateInfo({date:nextDate});_this.refs.MonthList.scrollToMonth(nextDate);}};_this.today=(0,_moment.default)();_this.year=_this.today.year();_this.getDateRange();_this.header=_this.today.clone();_this.selectedDate=props.selectedDate;_this.state={startDate:props.startDate,endDate:props.endDate,showLunar:props.isShowLunar,tabSelected:0,holidays:[],ownUpdate:false};_this.converter=new _LunarDateConverter.default();return _this;}(0,_createClass2.default)(CalendarPro,[{key:"ownSetState",value:function ownSetState(state){this.setState(_objectSpread(_objectSpread({},state),{},{ownUpdate:true}));}},{key:"render",value:function render(){var _this$state3=this.state,startDate=_this$state3.startDate,endDate=_this$state3.endDate,showLunar=_this$state3.showLunar,tabSelected=_this$state3.tabSelected,holidays=_this$state3.holidays,temp=_this$state3.temp;var _this$props4=this.props,i18n=_this$props4.i18n,isDoubleDateMode=_this$props4.isDoubleDateMode,priceList=_this$props4.priceList,labelFrom=_this$props4.labelFrom,labelTo=_this$props4.labelTo,isHideLabel=_this$props4.isHideLabel,isHideHoliday=_this$props4.isHideHoliday,isOffLunar=_this$props4.isOffLunar;var priceListFormat=priceList==null?void 0:priceList.outbound;if(isDoubleDateMode){priceListFormat=tabSelected===0?priceList==null?void 0:priceList.outbound:priceList==null?void 0:priceList.inbound;}return _react.default.createElement(_reactNative.View,{style:styles.container,__source:{fileName:_jsxFileName,lineNumber:219,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:styles.viewDate,__source:{fileName:_jsxFileName,lineNumber:220,columnNumber:17}},_react.default.createElement(_HeaderControl.default,{ref:"HeaderControl",onPressBackArrow:this.onPressBackArrow,onPressNextArrow:this.onPressNextArrow,__source:{fileName:_jsxFileName,lineNumber:221,columnNumber:21}}),_react.default.createElement(_reactNative.View,{style:styles.viewDay,__source:{fileName:_jsxFileName,lineNumber:227,columnNumber:21}},[1,2,3,4,5,6,7].map(function(item){return _react.default.createElement(_core.Text,{style:[styles.textDay,{color:item===6||item===7?_core.Colors.red_05:_core.Colors.black_12}],key:item,__source:{fileName:_jsxFileName,lineNumber:229,columnNumber:29}},_Util.default.mapWeeKDate(item));})),_react.default.createElement(_MonthList.default,{ref:"MonthList",today:this.today,minDate:this.minDate,maxDate:this.maxDate,startDate:startDate,endDate:endDate,onChoose:this.onChoose,i18n:i18n,onScrollCalendar:this.onScrollCalendar,isShowLunar:!isOffLunar&&showLunar,isDoubleDateMode:isDoubleDateMode,tabSelected:tabSelected,lunarConverter:this.converter,holidays:holidays,selectedDate:this.selectedDate,priceList:priceListFormat,labelFrom:labelFrom,labelTo:labelTo,isHideLabel:isHideLabel,__source:{fileName:_jsxFileName,lineNumber:238,columnNumber:21}})),!isOffLunar&&_react.default.createElement(_reactNative.View,{style:styles.viewLunar,__source:{fileName:_jsxFileName,lineNumber:262,columnNumber:25}},_react.default.createElement(_reactNative.TouchableWithoutFeedback,{onPress:this.toggleLunarDate,__source:{fileName:_jsxFileName,lineNumber:263,columnNumber:29}},_react.default.createElement(_core.Image,{source:showLunar?_core.IconSource.ic_checkbox_checked_24:_core.IconSource.ic_checkbox_unchecked_24,style:styles.iconSelected,__source:{fileName:_jsxFileName,lineNumber:264,columnNumber:33}})),_react.default.createElement(_core.Text.SubTitle,{style:styles.txtLunar,onPress:this.toggleLunarDate,__source:{fileName:_jsxFileName,lineNumber:266,columnNumber:29}},_core.SwitchLanguage.showLunar)),!isHideHoliday&&_react.default.createElement(_reactNative.ScrollView,{contentContainerStyle:styles.contentScroll,showsVerticalScrollIndicator:false,enabledNestedScroll:true,__source:{fileName:_jsxFileName,lineNumber:278,columnNumber:25}},temp&&temp.length>0&&temp.map(function(item,idx){var labelHoliday=showLunar?item.mixedLabel||item.label||'':item.label||'';var labelHighlight=showLunar?item.highlight||'':'';var labelDate=_core.Language.defaultLanguage==='en'?_Util.default.mapMonthShorten(item.month)+" "+item.day:item.day+" th\xE1ng "+item.month;return _react.default.createElement(_reactNative.View,{style:styles.row,key:idx.toString(),__source:{fileName:_jsxFileName,lineNumber:288,columnNumber:37}},_react.default.createElement(_core.Text.SubTitle,{style:styles.txtMonthLunar,__source:{fileName:_jsxFileName,lineNumber:289,columnNumber:41}},labelDate),_react.default.createElement(_core.Text.SubTitle,{style:styles.subTextLunar,__source:{fileName:_jsxFileName,lineNumber:292,columnNumber:41}},labelHoliday+" ",labelHighlight?_react.default.createElement(_core.Text,{style:{color:_core.Colors.red_05},__source:{fileName:_jsxFileName,lineNumber:295,columnNumber:66}},labelHighlight):''));})));}}],[{key:"getDerivedStateFromProps",value:function getDerivedStateFromProps(nextProps,prevState){if(prevState.ownUpdate){return{ownUpdate:false};}if(nextProps.isShowLunar!==prevState.showLunar){return{showLunar:nextProps.isShowLunar};}return null;}}]);return CalendarPro;}(_react.Component);exports.default=CalendarPro;CalendarPro.propTypes={i18n:_propTypes.default.string,format:_propTypes.default.string,customI18n:_propTypes.default.object,isShowLunar:_propTypes.default.bool,onCallbackCalendar:_propTypes.default.func,minDate:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.instanceOf(Date)]),maxDate:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.instanceOf(Date)])};CalendarPro.defaultProps={format:'YYYY-MM-DD',i18n:'vi',customI18n:{},isShowLunar:true};var styles=_reactNative.StyleSheet.create({row:{flexDirection:'row'},txtMonthLunar:{color:_core.Colors.red_05,width:80},subTextLunar:{color:'#222222',paddingLeft:6,flexShrink:1},contentScroll:{paddingHorizontal:12,paddingVertical:10},iconSelected:{width:24,height:24,resizeMode:'cover'},txtLunar:{paddingLeft:6,color:'#222222',lineHeight:14},viewLunar:{flexDirection:'row',alignItems:'center',marginHorizontal:12,paddingVertical:12,borderBottomWidth:1,borderStyle:'solid',borderColor:'#c7c7cd'},viewDate:{paddingHorizontal:12},textDay:{lineHeight:16,width:(widthScreen-38)/7,textAlign:'center',fontWeight:'bold'},viewDay:{flexDirection:'row',justifyContent:'space-between',paddingHorizontal:7,paddingTop:15,paddingBottom:10},container:{flex:1,backgroundColor:'white',marginTop:20}});
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
View,
|
|
7
|
+
Dimensions,
|
|
8
|
+
ScrollView,
|
|
9
|
+
TouchableWithoutFeedback,
|
|
10
|
+
StyleSheet
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import Moment from 'moment';
|
|
13
|
+
import {
|
|
14
|
+
Text, SwitchLanguage, LocalizedStrings, Colors, Image, IconSource
|
|
15
|
+
} from '@momo-kits/core';
|
|
16
|
+
import MonthList from './MonthList';
|
|
17
|
+
import HeaderControl from './HeaderControl';
|
|
18
|
+
import LunarDateConverter from './LunarDateConverter';
|
|
19
|
+
import Util from './Util';
|
|
20
|
+
|
|
21
|
+
const widthScreen = Dimensions.get('window').width;
|
|
22
|
+
|
|
23
|
+
export default class CalendarPro extends Component {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
26
|
+
this.today = Moment();
|
|
27
|
+
this.year = this.today.year();
|
|
28
|
+
this.getDateRange();
|
|
29
|
+
this.header = this.today.clone();
|
|
30
|
+
this.selectedDate = props.selectedDate;
|
|
31
|
+
this.state = {
|
|
32
|
+
startDate: props.startDate,
|
|
33
|
+
endDate: props.endDate,
|
|
34
|
+
showLunar: props.isShowLunar,
|
|
35
|
+
tabSelected: 0,
|
|
36
|
+
holidays: [],
|
|
37
|
+
ownUpdate: false,
|
|
38
|
+
};
|
|
39
|
+
this.converter = new LunarDateConverter();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static getDerivedStateFromProps(nextProps, prevState) {
|
|
43
|
+
if (prevState.ownUpdate) {
|
|
44
|
+
return {
|
|
45
|
+
ownUpdate: false,
|
|
46
|
+
};
|
|
47
|
+
} if (nextProps.isShowLunar !== prevState.showLunar) {
|
|
48
|
+
return { showLunar: nextProps.isShowLunar };
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setDateRange = (dateRange, isScrollToStartDate) => {
|
|
54
|
+
if (dateRange && dateRange.startDate && dateRange.endDate) {
|
|
55
|
+
this.setState({ startDate: dateRange.startDate, endDate: dateRange.endDate }, () => {
|
|
56
|
+
const dateScroll = isScrollToStartDate ? dateRange.startDate : dateRange.endDate;
|
|
57
|
+
this.refs.MonthList.scrollToMonth(dateScroll);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ownSetState(state) {
|
|
63
|
+
this.setState({ ...state, ownUpdate: true });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
loadLabel = (data, type) => {
|
|
67
|
+
const {
|
|
68
|
+
i18n,
|
|
69
|
+
customI18n
|
|
70
|
+
} = this.props;
|
|
71
|
+
if (~['w', 'weekday', 'text'].indexOf(type)) {
|
|
72
|
+
return (customI18n[type] || {})[data] || Util.I18N_MAP[i18n][type][data];
|
|
73
|
+
}
|
|
74
|
+
if (type === 'date') {
|
|
75
|
+
return data.format(customI18n[type] || Util.I18N_MAP[i18n][type]);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
getDateRange = () => {
|
|
80
|
+
const {
|
|
81
|
+
maxDate,
|
|
82
|
+
minDate,
|
|
83
|
+
format
|
|
84
|
+
} = this.props;
|
|
85
|
+
let max = Moment(maxDate, format);
|
|
86
|
+
let min = Moment(minDate, format);
|
|
87
|
+
const maxValid = max.isValid();
|
|
88
|
+
const minValid = min.isValid();
|
|
89
|
+
if (!maxValid && !minValid) {
|
|
90
|
+
max = Moment().add(12, 'months');
|
|
91
|
+
min = Moment();
|
|
92
|
+
}
|
|
93
|
+
if (!maxValid && minValid) {
|
|
94
|
+
max = min.add(12, 'months');
|
|
95
|
+
}
|
|
96
|
+
if (maxValid && !minValid) {
|
|
97
|
+
min = max.subtract(12, 'months');
|
|
98
|
+
}
|
|
99
|
+
if (min.isSameOrAfter(max)) return {};
|
|
100
|
+
this.minDate = min;
|
|
101
|
+
this.maxDate = max;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
onChoose = (day) => {
|
|
105
|
+
const {
|
|
106
|
+
startDate, tabSelected
|
|
107
|
+
} = this.state;
|
|
108
|
+
const { isDoubleDateMode, onDateChange } = this.props;
|
|
109
|
+
if (isDoubleDateMode) {
|
|
110
|
+
if (tabSelected === 1) {
|
|
111
|
+
if (startDate && day >= startDate) {
|
|
112
|
+
this.ownSetState({
|
|
113
|
+
endDate: day
|
|
114
|
+
});
|
|
115
|
+
} else if (startDate && day < startDate) {
|
|
116
|
+
this.ownSetState({
|
|
117
|
+
startDate: day,
|
|
118
|
+
endDate: null
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
this.ownSetState({
|
|
123
|
+
startDate: day
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
this.ownSetState({
|
|
128
|
+
startDate: day,
|
|
129
|
+
endDate: null,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (onDateChange) {
|
|
133
|
+
onDateChange(day);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
executeProcessAfterScrollCalendar = (date, key) => {
|
|
138
|
+
const holidays = Object.values(Util.getHolidaysInMonth(Moment(date)));
|
|
139
|
+
const {
|
|
140
|
+
showLunar
|
|
141
|
+
} = this.state;
|
|
142
|
+
if (this.refs && this.refs.HeaderControl) {
|
|
143
|
+
this.refs.HeaderControl.onUpdateInfo({ date });
|
|
144
|
+
this.header = date.clone().startOf('month');
|
|
145
|
+
}
|
|
146
|
+
let data = [];
|
|
147
|
+
if (!showLunar) {
|
|
148
|
+
data = holidays.filter((item) => !item.lunar || item.mixedLabel);
|
|
149
|
+
} else {
|
|
150
|
+
data = holidays;
|
|
151
|
+
}
|
|
152
|
+
this.ownSetState({ holidays, temp: data, headerKey: key });
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
onScrollCalendar = (data) => {
|
|
156
|
+
const { headerKey } = this.state;
|
|
157
|
+
if (data) {
|
|
158
|
+
if (data.key !== headerKey) {
|
|
159
|
+
this.executeProcessAfterScrollCalendar(data.date, data.key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
setDoubleDateAndTabIndex = (firstDate, secondDate, tabSelected) => {
|
|
165
|
+
this.ownSetState({
|
|
166
|
+
startDate: firstDate ? Moment(firstDate) : null,
|
|
167
|
+
endDate: secondDate ? Moment(secondDate) : null,
|
|
168
|
+
tabSelected
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
toggleLunarDate = () => {
|
|
173
|
+
const { showLunar, holidays } = this.state;
|
|
174
|
+
const { onCallbackCalendar } = this.props;
|
|
175
|
+
let data = [];
|
|
176
|
+
const nextStateShowLunar = !showLunar;
|
|
177
|
+
if (!nextStateShowLunar) {
|
|
178
|
+
data = holidays.filter((item) => !item.lunar || item.mixedLabel);
|
|
179
|
+
} else {
|
|
180
|
+
data = holidays;
|
|
181
|
+
}
|
|
182
|
+
if (onCallbackCalendar) {
|
|
183
|
+
onCallbackCalendar('lunar', nextStateShowLunar);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.ownSetState({ showLunar: !showLunar, temp: data, ownUpdate: true });
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
onPressBackArrow = () => {
|
|
190
|
+
const previousDate = Moment(this.header).startOf('month').subtract(1, 'months');
|
|
191
|
+
if (this.refs && this.refs.HeaderControl && previousDate.isSameOrAfter(this.minDate, 'month')) {
|
|
192
|
+
this.header = previousDate;
|
|
193
|
+
this.refs.HeaderControl.onUpdateInfo({ date: previousDate });
|
|
194
|
+
this.refs.MonthList.scrollToMonth(previousDate);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
onPressNextArrow = () => {
|
|
199
|
+
const nextDate = Moment(this.header).startOf('month').add(1, 'months');
|
|
200
|
+
if (this.refs && this.refs.HeaderControl && nextDate.isSameOrBefore(this.maxDate, 'month')) {
|
|
201
|
+
this.header = nextDate;
|
|
202
|
+
this.refs.HeaderControl.onUpdateInfo({ date: nextDate });
|
|
203
|
+
this.refs.MonthList.scrollToMonth(nextDate);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
render() {
|
|
208
|
+
const {
|
|
209
|
+
startDate, endDate, showLunar, tabSelected, holidays, temp
|
|
210
|
+
} = this.state;
|
|
211
|
+
const {
|
|
212
|
+
i18n, isDoubleDateMode, priceList, labelFrom, labelTo, isHideLabel, isHideHoliday, isOffLunar
|
|
213
|
+
} = this.props;
|
|
214
|
+
let priceListFormat = priceList?.outbound;
|
|
215
|
+
if (isDoubleDateMode) {
|
|
216
|
+
priceListFormat = tabSelected === 0 ? priceList?.outbound : priceList?.inbound;
|
|
217
|
+
}
|
|
218
|
+
return (
|
|
219
|
+
<View style={styles.container}>
|
|
220
|
+
<View style={styles.viewDate}>
|
|
221
|
+
<HeaderControl
|
|
222
|
+
ref="HeaderControl"
|
|
223
|
+
// selectedDate={this.selectedDate}
|
|
224
|
+
onPressBackArrow={this.onPressBackArrow}
|
|
225
|
+
onPressNextArrow={this.onPressNextArrow}
|
|
226
|
+
/>
|
|
227
|
+
<View style={styles.viewDay}>
|
|
228
|
+
{[1, 2, 3, 4, 5, 6, 7].map((item) => (
|
|
229
|
+
<Text
|
|
230
|
+
style={[styles.textDay, { color: item === 6 || item === 7 ? Colors.red_05 : Colors.black_12 }]}
|
|
231
|
+
key={item}
|
|
232
|
+
>
|
|
233
|
+
{Util.mapWeeKDate(item)}
|
|
234
|
+
</Text>
|
|
235
|
+
)
|
|
236
|
+
)}
|
|
237
|
+
</View>
|
|
238
|
+
<MonthList
|
|
239
|
+
ref="MonthList"
|
|
240
|
+
today={this.today}
|
|
241
|
+
minDate={this.minDate}
|
|
242
|
+
maxDate={this.maxDate}
|
|
243
|
+
startDate={startDate}
|
|
244
|
+
endDate={endDate}
|
|
245
|
+
onChoose={this.onChoose}
|
|
246
|
+
i18n={i18n}
|
|
247
|
+
onScrollCalendar={this.onScrollCalendar}
|
|
248
|
+
isShowLunar={!isOffLunar && showLunar}
|
|
249
|
+
isDoubleDateMode={isDoubleDateMode}
|
|
250
|
+
tabSelected={tabSelected}
|
|
251
|
+
lunarConverter={this.converter}
|
|
252
|
+
holidays={holidays}
|
|
253
|
+
selectedDate={this.selectedDate}
|
|
254
|
+
priceList={priceListFormat}
|
|
255
|
+
labelFrom={labelFrom}
|
|
256
|
+
labelTo={labelTo}
|
|
257
|
+
isHideLabel={isHideLabel}
|
|
258
|
+
/>
|
|
259
|
+
</View>
|
|
260
|
+
{
|
|
261
|
+
!isOffLunar && (
|
|
262
|
+
<View style={styles.viewLunar}>
|
|
263
|
+
<TouchableWithoutFeedback onPress={this.toggleLunarDate}>
|
|
264
|
+
<Image source={showLunar ? IconSource.ic_checkbox_checked_24 : IconSource.ic_checkbox_unchecked_24} style={styles.iconSelected} />
|
|
265
|
+
</TouchableWithoutFeedback>
|
|
266
|
+
<Text.SubTitle
|
|
267
|
+
style={styles.txtLunar}
|
|
268
|
+
onPress={this.toggleLunarDate}
|
|
269
|
+
>
|
|
270
|
+
{SwitchLanguage.showLunar}
|
|
271
|
+
</Text.SubTitle>
|
|
272
|
+
</View>
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
{
|
|
277
|
+
!isHideHoliday && (
|
|
278
|
+
<ScrollView
|
|
279
|
+
contentContainerStyle={styles.contentScroll}
|
|
280
|
+
showsVerticalScrollIndicator={false}
|
|
281
|
+
enabledNestedScroll
|
|
282
|
+
>
|
|
283
|
+
{temp && temp.length > 0 && temp.map((item, idx) => {
|
|
284
|
+
const labelHoliday = showLunar ? (item.mixedLabel || item.label || '') : (item.label || '');
|
|
285
|
+
const labelHighlight = showLunar ? (item.highlight || '') : '';
|
|
286
|
+
const labelDate = LocalizedStrings.defaultLanguage === 'en' ? `${Util.mapMonthShorten(item.month)} ${item.day}` : `${item.day} tháng ${item.month}`;
|
|
287
|
+
return (
|
|
288
|
+
<View style={styles.row} key={idx.toString()}>
|
|
289
|
+
<Text.SubTitle style={styles.txtMonthLunar}>
|
|
290
|
+
{labelDate}
|
|
291
|
+
</Text.SubTitle>
|
|
292
|
+
<Text.SubTitle style={styles.subTextLunar}>
|
|
293
|
+
{`${labelHoliday} `}
|
|
294
|
+
{
|
|
295
|
+
labelHighlight ? <Text style={{ color: Colors.red_05 }}>{labelHighlight}</Text> : ''
|
|
296
|
+
}
|
|
297
|
+
</Text.SubTitle>
|
|
298
|
+
</View>
|
|
299
|
+
);
|
|
300
|
+
})}
|
|
301
|
+
</ScrollView>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
</View>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
CalendarPro.propTypes = {
|
|
311
|
+
i18n: PropTypes.string,
|
|
312
|
+
format: PropTypes.string,
|
|
313
|
+
customI18n: PropTypes.object,
|
|
314
|
+
isShowLunar: PropTypes.bool,
|
|
315
|
+
onCallbackCalendar: PropTypes.func,
|
|
316
|
+
minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
317
|
+
maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)])
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
CalendarPro.defaultProps = {
|
|
321
|
+
format: 'YYYY-MM-DD',
|
|
322
|
+
i18n: 'vi',
|
|
323
|
+
customI18n: {},
|
|
324
|
+
isShowLunar: true
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const styles = StyleSheet.create({
|
|
328
|
+
row: { flexDirection: 'row' },
|
|
329
|
+
txtMonthLunar: { color: Colors.red_05, width: 80 },
|
|
330
|
+
subTextLunar: {
|
|
331
|
+
// fontSize: 12,
|
|
332
|
+
color: '#222222',
|
|
333
|
+
paddingLeft: 6,
|
|
334
|
+
flexShrink: 1
|
|
335
|
+
},
|
|
336
|
+
contentScroll: { paddingHorizontal: 12, paddingVertical: 10 },
|
|
337
|
+
iconSelected: { width: 24, height: 24, resizeMode: 'cover' },
|
|
338
|
+
txtLunar: {
|
|
339
|
+
paddingLeft: 6,
|
|
340
|
+
color: '#222222',
|
|
341
|
+
// fontSize: 12,
|
|
342
|
+
lineHeight: 14
|
|
343
|
+
},
|
|
344
|
+
viewLunar: {
|
|
345
|
+
flexDirection: 'row', alignItems: 'center', marginHorizontal: 12, paddingVertical: 12, borderBottomWidth: 1, borderStyle: 'solid', borderColor: '#c7c7cd'
|
|
346
|
+
},
|
|
347
|
+
viewDate: { paddingHorizontal: 12 },
|
|
348
|
+
textDay: {
|
|
349
|
+
// fontSize: 14,
|
|
350
|
+
lineHeight: 16,
|
|
351
|
+
width: (widthScreen - 38) / 7,
|
|
352
|
+
textAlign: 'center',
|
|
353
|
+
fontWeight: 'bold',
|
|
354
|
+
},
|
|
355
|
+
viewDay: {
|
|
356
|
+
flexDirection: 'row',
|
|
357
|
+
justifyContent: 'space-between',
|
|
358
|
+
paddingHorizontal: 7,
|
|
359
|
+
paddingTop: 15,
|
|
360
|
+
paddingBottom: 10,
|
|
361
|
+
},
|
|
362
|
+
container: { flex: 1, backgroundColor: 'white', marginTop: 20, },
|
|
363
|
+
});
|
package/src/Day/index.js
CHANGED
|
@@ -1 +1,210 @@
|
|
|
1
|
-
|
|
1
|
+
import React, {Component} from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import {View, TouchableHighlight, Text} from 'react-native';
|
|
5
|
+
import {Colors, SwitchLanguage} from '@momo-kits/core';
|
|
6
|
+
import style from './style';
|
|
7
|
+
|
|
8
|
+
class Day extends Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.statusCheck();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
chooseDay = () => {
|
|
15
|
+
const {onChoose, date} = this.props;
|
|
16
|
+
onChoose && onChoose(date);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
findHoliday = (date, holidays) => {
|
|
20
|
+
if (date && holidays && holidays.length > 0) {
|
|
21
|
+
const day = date.date();
|
|
22
|
+
const month = date.month() + 1;
|
|
23
|
+
return holidays.find(item => item.day === day && item.month === month);
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
checkHoliday = (date, holidays) => {
|
|
29
|
+
const holiday = this.findHoliday(date, holidays);
|
|
30
|
+
return {
|
|
31
|
+
solarHoliday: !!(holiday && !holiday.lunar),
|
|
32
|
+
lunarHoliday: !!(holiday && holiday.lunar),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
statusCheck = props => {
|
|
37
|
+
const {
|
|
38
|
+
startDate,
|
|
39
|
+
endDate,
|
|
40
|
+
date = null,
|
|
41
|
+
minDate,
|
|
42
|
+
maxDate,
|
|
43
|
+
empty,
|
|
44
|
+
index,
|
|
45
|
+
isShowLunar,
|
|
46
|
+
tabSelected,
|
|
47
|
+
isDoubleDateMode,
|
|
48
|
+
lunarDate,
|
|
49
|
+
isSolarHoliday,
|
|
50
|
+
isLunarHoliday,
|
|
51
|
+
price,
|
|
52
|
+
} = props || this.props;
|
|
53
|
+
this.isValid =
|
|
54
|
+
date &&
|
|
55
|
+
(date >= minDate || date.isSame(minDate, 'day')) &&
|
|
56
|
+
(date <= maxDate || date.isSame(maxDate, 'day'));
|
|
57
|
+
this.isMid =
|
|
58
|
+
(isDoubleDateMode && date > startDate && date < endDate) ||
|
|
59
|
+
(!date && empty >= startDate && empty <= endDate);
|
|
60
|
+
this.isStart = date && date.isSame(startDate, 'd');
|
|
61
|
+
this.isStartPart = this.isStart && endDate;
|
|
62
|
+
this.isEnd = isDoubleDateMode && date && date.isSame(endDate, 'day');
|
|
63
|
+
this.isFocus = this.isMid || this.isStart || this.isEnd;
|
|
64
|
+
this.isWeekEnd = index === 6 || index === 5;
|
|
65
|
+
this.showLunar = isShowLunar;
|
|
66
|
+
this.lunarDate = lunarDate;
|
|
67
|
+
this.isDoubleDateMode = isDoubleDateMode;
|
|
68
|
+
this.isLunarHoliday = isLunarHoliday;
|
|
69
|
+
this.isLunarDayStart = this.lunarDate && this.lunarDate.lunarDay === 1;
|
|
70
|
+
this.isSolarHoliday = isSolarHoliday;
|
|
71
|
+
this.isInScope = isDoubleDateMode
|
|
72
|
+
? tabSelected === 0 ||
|
|
73
|
+
(tabSelected === 1 &&
|
|
74
|
+
startDate &&
|
|
75
|
+
date &&
|
|
76
|
+
date.isSameOrAfter(startDate, 'day'))
|
|
77
|
+
: true;
|
|
78
|
+
return this.isFocus || this.diffPrice;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
shouldComponentUpdate(nextProps) {
|
|
82
|
+
const {
|
|
83
|
+
isDoubleDateMode,
|
|
84
|
+
isShowLunar,
|
|
85
|
+
tabSelected,
|
|
86
|
+
isSolarHoliday,
|
|
87
|
+
isLunarHoliday,
|
|
88
|
+
price,
|
|
89
|
+
isBestPrice,
|
|
90
|
+
startDate,
|
|
91
|
+
endDate,
|
|
92
|
+
} = this.props;
|
|
93
|
+
const prevStatus = this.isFocus;
|
|
94
|
+
const selectionModeChange = isDoubleDateMode !== nextProps.isDoubleDateMode;
|
|
95
|
+
const lunarChange = isShowLunar !== nextProps.isShowLunar;
|
|
96
|
+
const nextStatus = this.statusCheck(nextProps);
|
|
97
|
+
const tabChange = tabSelected !== nextProps.tabSelected;
|
|
98
|
+
const solarHoliday = isSolarHoliday !== nextProps.isSolarHoliday;
|
|
99
|
+
const lunarHoliday = isLunarHoliday !== nextProps.isLunarHoliday;
|
|
100
|
+
const diffPrice =
|
|
101
|
+
price !== nextProps.price && isBestPrice !== nextProps.isBestPrice;
|
|
102
|
+
const startDateChange =
|
|
103
|
+
startDate && !startDate?.isSame?.(nextProps.startDate, 'day');
|
|
104
|
+
const endDateChange =
|
|
105
|
+
endDate && !endDate?.isSame?.(nextProps.endDate, 'day');
|
|
106
|
+
return !!(
|
|
107
|
+
prevStatus !== nextStatus ||
|
|
108
|
+
selectionModeChange ||
|
|
109
|
+
lunarChange ||
|
|
110
|
+
tabChange ||
|
|
111
|
+
solarHoliday ||
|
|
112
|
+
lunarHoliday ||
|
|
113
|
+
diffPrice ||
|
|
114
|
+
startDateChange ||
|
|
115
|
+
endDateChange
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
render() {
|
|
120
|
+
const {
|
|
121
|
+
date,
|
|
122
|
+
empty,
|
|
123
|
+
isDoubleDateMode,
|
|
124
|
+
price,
|
|
125
|
+
isBestPrice,
|
|
126
|
+
isShowPrice,
|
|
127
|
+
labelFrom,
|
|
128
|
+
labelTo,
|
|
129
|
+
isHideLabel,
|
|
130
|
+
} = this.props;
|
|
131
|
+
const text = date ? date.date() : '';
|
|
132
|
+
return (
|
|
133
|
+
<View style={style.dayContainer}>
|
|
134
|
+
<View
|
|
135
|
+
style={[
|
|
136
|
+
this.isMid && !empty && style.mid,
|
|
137
|
+
this.isStartPart && style.dayStartContainer,
|
|
138
|
+
this.isEnd && style.dayEndContainer,
|
|
139
|
+
]}>
|
|
140
|
+
{this.isValid && this.isInScope ? (
|
|
141
|
+
<TouchableHighlight
|
|
142
|
+
style={[style.day, (this.isStart || this.isEnd) && style.focused]}
|
|
143
|
+
underlayColor="rgba(255, 255, 255, 0.35)"
|
|
144
|
+
onPress={this.chooseDay}>
|
|
145
|
+
<>
|
|
146
|
+
<Text
|
|
147
|
+
style={[
|
|
148
|
+
style.dayText,
|
|
149
|
+
this.isWeekEnd && style.weekendDay,
|
|
150
|
+
this.isSolarHoliday && style.weekendDay,
|
|
151
|
+
(this.isStart || this.isEnd) && style.focusedText,
|
|
152
|
+
]}>
|
|
153
|
+
{text}
|
|
154
|
+
</Text>
|
|
155
|
+
{this.lunarDate && this.showLunar && (
|
|
156
|
+
<Text
|
|
157
|
+
style={[
|
|
158
|
+
style.lunarDayText,
|
|
159
|
+
(this.isLunarHoliday || this.isLunarDayStart) &&
|
|
160
|
+
style.weekendDay,
|
|
161
|
+
(this.isStart || this.isEnd) && style.focusedText,
|
|
162
|
+
]}>
|
|
163
|
+
{this.lunarDate.lunarDay === 1
|
|
164
|
+
? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
|
|
165
|
+
: this.lunarDate.lunarDay}
|
|
166
|
+
</Text>
|
|
167
|
+
)}
|
|
168
|
+
</>
|
|
169
|
+
</TouchableHighlight>
|
|
170
|
+
) : (
|
|
171
|
+
<View style={[style.day]}>
|
|
172
|
+
<Text style={[style.dayText, style.dayTextDisabled]}>{text}</Text>
|
|
173
|
+
{this.lunarDate && this.showLunar && text ? (
|
|
174
|
+
<Text style={[style.lunarDayText, style.dayTextDisabled]}>
|
|
175
|
+
{this.lunarDate.lunarDay === 1
|
|
176
|
+
? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
|
|
177
|
+
: this.lunarDate.lunarDay}
|
|
178
|
+
</Text>
|
|
179
|
+
) : (
|
|
180
|
+
<View />
|
|
181
|
+
)}
|
|
182
|
+
</View>
|
|
183
|
+
)}
|
|
184
|
+
</View>
|
|
185
|
+
|
|
186
|
+
{isDoubleDateMode && this.isStart && !isHideLabel && (
|
|
187
|
+
<View style={style.txtGo}>
|
|
188
|
+
<Text style={{fontSize: 8, color: 'white'}}>
|
|
189
|
+
{labelFrom || SwitchLanguage.departing}
|
|
190
|
+
</Text>
|
|
191
|
+
</View>
|
|
192
|
+
)}
|
|
193
|
+
{isDoubleDateMode && this.isEnd && !isHideLabel && (
|
|
194
|
+
<View style={style.txtBack}>
|
|
195
|
+
<Text style={{fontSize: 8, color: 'white'}}>
|
|
196
|
+
{labelTo || SwitchLanguage.returning}
|
|
197
|
+
</Text>
|
|
198
|
+
</View>
|
|
199
|
+
)}
|
|
200
|
+
{this.isValid && this.isInScope && !!price && (
|
|
201
|
+
<Text style={[style.price, isBestPrice && {color: Colors.pink_05_b}]}>
|
|
202
|
+
{price}
|
|
203
|
+
</Text>
|
|
204
|
+
)}
|
|
205
|
+
</View>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default Day;
|