2016-06-03 23:29:21 +03:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
var _react = require ( 'react' ) ;
var _react2 = _interopRequireDefault ( _react ) ;
var _time = require ( '../utils/time.js' ) ;
var _time2 = _interopRequireDefault ( _time ) ;
var _utils = require ( '../utils/utils.js' ) ;
var _utils2 = _interopRequireDefault ( _utils ) ;
var _CalendarDay = require ( './CalendarDay.js' ) ;
var _CalendarDay2 = _interopRequireDefault ( _CalendarDay ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2016-08-01 14:21:32 +03:00
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
2016-06-03 23:29:21 +03:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
var Month = function ( _Component ) {
_inherits ( Month , _Component ) ;
function Month ( ) {
2016-09-03 17:03:04 +03:00
var _Object$getPrototypeO ;
2016-06-03 23:29:21 +03:00
var _temp , _this , _ret ;
_classCallCheck ( this , Month ) ;
for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
args [ _key ] = arguments [ _key ] ;
}
2016-09-03 17:03:04 +03:00
return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _Object$getPrototypeO = Object . getPrototypeOf ( Month ) ) . call . apply ( _Object$getPrototypeO , [ this ] . concat ( args ) ) ) , _this ) , _this . handleDayClick = function ( day ) {
2016-06-03 23:29:21 +03:00
if ( _this . props . onDayClick ) _this . props . onDayClick ( day ) ;
} , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
}
_createClass ( Month , [ {
key : 'renderWeeks' ,
value : function renderWeeks ( ) {
2016-08-01 14:21:32 +03:00
var _this2 = this ;
var days = _utils2 . default . range ( 0 , 7 ) . map ( function ( d ) {
return _time2 . default . getDayOfWeekLetter ( d , _this2 . props . locale ) ;
} ) ;
var source = this . props . sundayFirstDayOfWeek ? days : [ ] . concat ( _toConsumableArray ( days . slice ( 1 ) ) , [ days [ 0 ] ] ) ;
return source . map ( function ( d , i ) {
2016-06-03 23:29:21 +03:00
return _react2 . default . createElement (
'span' ,
{ key : i } ,
2016-08-01 14:21:32 +03:00
d
2016-06-03 23:29:21 +03:00
) ;
} ) ;
}
} , {
key : 'renderDays' ,
value : function renderDays ( ) {
2016-08-01 14:21:32 +03:00
var _this3 = this ;
2016-06-03 23:29:21 +03:00
return _utils2 . default . range ( 1 , _time2 . default . getDaysInMonth ( this . props . viewDate ) + 1 ) . map ( function ( i ) {
2016-08-01 14:21:32 +03:00
var date = new Date ( _this3 . props . viewDate . getFullYear ( ) , _this3 . props . viewDate . getMonth ( ) , i ) ;
var disabled = _time2 . default . dateOutOfRange ( date , _this3 . props . minDate , _this3 . props . maxDate ) ;
2016-06-03 23:29:21 +03:00
return _react2 . default . createElement ( _CalendarDay2 . default , {
key : i ,
day : i ,
disabled : disabled ,
2016-08-07 14:43:07 +03:00
onClick : _this3 . handleDayClick ,
2016-08-01 14:21:32 +03:00
selectedDate : _this3 . props . selectedDate ,
theme : _this3 . props . theme ,
viewDate : _this3 . props . viewDate ,
sundayFirstDayOfWeek : _this3 . props . sundayFirstDayOfWeek
2016-06-03 23:29:21 +03:00
} ) ;
} ) ;
}
} , {
key : 'render' ,
value : function render ( ) {
return _react2 . default . createElement (
'div' ,
{ 'data-react-toolbox' : 'month' , className : this . props . theme . month } ,
_react2 . default . createElement (
'span' ,
{ className : this . props . theme . title } ,
2016-08-01 14:21:32 +03:00
_time2 . default . getFullMonth ( this . props . viewDate , this . props . locale ) ,
2016-06-03 23:29:21 +03:00
' ' ,
this . props . viewDate . getFullYear ( )
) ,
_react2 . default . createElement (
'div' ,
{ className : this . props . theme . week } ,
this . renderWeeks ( )
) ,
_react2 . default . createElement (
'div' ,
{ className : this . props . theme . days } ,
this . renderDays ( )
)
) ;
}
} ] ) ;
return Month ;
} ( _react . Component ) ;
Month . propTypes = {
2016-08-01 14:44:26 +03:00
locale : _react2 . default . PropTypes . oneOfType ( [ _react2 . default . PropTypes . string , _react2 . default . PropTypes . object ] ) ,
2016-06-03 23:29:21 +03:00
maxDate : _react . PropTypes . object ,
minDate : _react . PropTypes . object ,
onDayClick : _react . PropTypes . func ,
selectedDate : _react . PropTypes . object ,
2016-08-01 14:44:26 +03:00
sundayFirstDayOfWeek : _react2 . default . PropTypes . bool ,
2016-06-03 23:29:21 +03:00
theme : _react . PropTypes . shape ( {
2016-06-04 00:45:19 +03:00
days : _react . PropTypes . string ,
month : _react . PropTypes . string ,
title : _react . PropTypes . string ,
week : _react . PropTypes . string
2016-06-03 23:29:21 +03:00
} ) ,
viewDate : _react . PropTypes . object
} ;
exports . default = Month ;