2016-06-03 23:29:21 +03:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2016-08-07 14:43:07 +03:00
exports . DatePicker = exports . datePickerFactory = exports . DatePickerDialog = undefined ;
2016-06-03 23:29:21 +03:00
2016-06-21 01:25:04 +03:00
var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
2016-06-03 23:29:21 +03:00
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 _classnames2 = require ( 'classnames' ) ;
var _classnames3 = _interopRequireDefault ( _classnames2 ) ;
var _reactCssThemr = require ( 'react-css-themr' ) ;
var _identifiers = require ( '../identifiers.js' ) ;
var _events = require ( '../utils/events.js' ) ;
var _events2 = _interopRequireDefault ( _events ) ;
var _time = require ( '../utils/time.js' ) ;
var _time2 = _interopRequireDefault ( _time ) ;
var _IconButton = require ( '../button/IconButton.js' ) ;
var _IconButton2 = _interopRequireDefault ( _IconButton ) ;
var _Input = require ( '../input/Input.js' ) ;
var _Input2 = _interopRequireDefault ( _Input ) ;
var _Dialog = require ( '../dialog/Dialog.js' ) ;
var _Dialog2 = _interopRequireDefault ( _Dialog ) ;
var _Calendar = require ( './Calendar.js' ) ;
var _Calendar2 = _interopRequireDefault ( _Calendar ) ;
var _DatePickerDialog = require ( './DatePickerDialog.js' ) ;
var _DatePickerDialog2 = _interopRequireDefault ( _DatePickerDialog ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
2016-06-21 01:25:04 +03:00
function _objectWithoutProperties ( obj , keys ) { var target = { } ; for ( var i in obj ) { if ( keys . indexOf ( i ) >= 0 ) continue ; if ( ! Object . prototype . hasOwnProperty . call ( obj , i ) ) continue ; target [ i ] = obj [ i ] ; } return target ; }
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 factory = function factory ( Input , DatePickerDialog ) {
var DatePicker = function ( _Component ) {
_inherits ( DatePicker , _Component ) ;
function DatePicker ( ) {
2016-10-08 13:51:21 +03:00
var _ref ;
2016-06-03 23:29:21 +03:00
var _temp , _this , _ret ;
_classCallCheck ( this , DatePicker ) ;
for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
args [ _key ] = arguments [ _key ] ;
}
2016-10-08 13:51:21 +03:00
return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _ref = DatePicker . _ _proto _ _ || Object . getPrototypeOf ( DatePicker ) ) . call . apply ( _ref , [ this ] . concat ( args ) ) ) , _this ) , _this . state = {
2016-08-07 20:01:45 +03:00
active : _this . props . active
2016-06-03 23:29:21 +03:00
} , _this . handleDismiss = function ( ) {
_this . setState ( { active : false } ) ;
2016-10-22 18:35:55 +03:00
if ( _this . props . onDismiss ) {
_this . props . onDismiss ( ) ;
}
2016-08-06 15:35:41 +03:00
} , _this . handleInputFocus = function ( event ) {
_events2 . default . pauseEvent ( event ) ;
_this . setState ( { active : true } ) ;
} , _this . handleInputBlur = function ( event ) {
_events2 . default . pauseEvent ( event ) ;
_this . setState ( { active : false } ) ;
2016-09-27 01:19:14 +03:00
} , _this . handleInputClick = function ( event ) {
2016-06-03 23:29:21 +03:00
_events2 . default . pauseEvent ( event ) ;
_this . setState ( { active : true } ) ;
2016-09-27 01:19:14 +03:00
if ( _this . props . onClick ) _this . props . onClick ( event ) ;
2016-06-21 01:25:04 +03:00
} , _this . handleInputKeyPress = function ( event ) {
if ( event . charCode === 13 ) {
_events2 . default . pauseEvent ( event ) ;
_this . setState ( { active : true } ) ;
}
if ( _this . props . onKeyPress ) _this . props . onKeyPress ( event ) ;
2016-06-03 23:29:21 +03:00
} , _this . handleSelect = function ( value , event ) {
if ( _this . props . onChange ) _this . props . onChange ( value , event ) ;
_this . setState ( { active : false } ) ;
} , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
}
_createClass ( DatePicker , [ {
2016-08-07 20:01:45 +03:00
key : 'componentWillReceiveProps' ,
value : function componentWillReceiveProps ( nextProps ) {
if ( this . state . active !== nextProps . active ) {
this . setState ( { active : nextProps . active } ) ;
}
}
} , {
2016-06-03 23:29:21 +03:00
key : 'render' ,
value : function render ( ) {
2016-11-01 16:26:45 +03:00
var _props = this . props ,
active = _props . active ,
onDismiss = _props . onDismiss ,
autoOk = _props . autoOk ,
cancelLabel = _props . cancelLabel ,
inputClassName = _props . inputClassName ,
inputFormat = _props . inputFormat ,
locale = _props . locale ,
maxDate = _props . maxDate ,
minDate = _props . minDate ,
okLabel = _props . okLabel ,
onEscKeyDown = _props . onEscKeyDown ,
onOverlayClick = _props . onOverlayClick ,
readonly = _props . readonly ,
sundayFirstDayOfWeek = _props . sundayFirstDayOfWeek ,
value = _props . value ,
others = _objectWithoutProperties ( _props , [ 'active' , 'onDismiss' , 'autoOk' , 'cancelLabel' , 'inputClassName' , 'inputFormat' , 'locale' , 'maxDate' , 'minDate' , 'okLabel' , 'onEscKeyDown' , 'onOverlayClick' , 'readonly' , 'sundayFirstDayOfWeek' , 'value' ] ) ;
2016-06-21 01:25:04 +03:00
2016-07-10 17:57:03 +03:00
var finalInputFormat = inputFormat || _time2 . default . formatDate ;
2016-06-03 23:29:21 +03:00
var date = Object . prototype . toString . call ( value ) === '[object Date]' ? value : undefined ;
2016-08-01 14:21:32 +03:00
var formattedDate = date === undefined ? '' : finalInputFormat ( value , locale ) ;
2016-06-03 23:29:21 +03:00
return _react2 . default . createElement (
'div' ,
{ 'data-react-toolbox' : 'date-picker' } ,
2016-06-21 01:25:04 +03:00
_react2 . default . createElement ( Input , _extends ( { } , others , {
2016-06-03 23:29:21 +03:00
className : ( 0 , _classnames3 . default ) ( this . props . theme . input , _defineProperty ( { } , inputClassName , inputClassName ) ) ,
2016-08-06 15:35:41 +03:00
disabled : readonly ,
2016-06-03 23:29:21 +03:00
error : this . props . error ,
2016-08-06 15:35:41 +03:00
icon : this . props . icon ,
2016-06-03 23:29:21 +03:00
label : this . props . label ,
2016-08-06 15:35:41 +03:00
name : this . props . name ,
onFocus : this . handleInputFocus ,
onKeyPress : this . handleInputKeyPress ,
2016-09-27 01:19:14 +03:00
onClick : this . handleInputClick ,
2016-06-03 23:29:21 +03:00
readOnly : true ,
type : 'text' ,
value : formattedDate
2016-06-21 01:25:04 +03:00
} ) ) ,
2016-06-03 23:29:21 +03:00
_react2 . default . createElement ( DatePickerDialog , {
active : this . state . active ,
2016-07-10 17:57:03 +03:00
autoOk : autoOk ,
2016-10-12 18:09:19 +03:00
cancelLabel : cancelLabel ,
2016-06-03 23:29:21 +03:00
className : this . props . className ,
2016-08-07 14:43:07 +03:00
locale : locale ,
2016-07-10 17:57:03 +03:00
maxDate : maxDate ,
minDate : minDate ,
2016-06-08 01:08:37 +03:00
name : this . props . name ,
2016-06-03 23:29:21 +03:00
onDismiss : this . handleDismiss ,
2016-10-22 18:35:55 +03:00
okLabel : okLabel ,
2016-08-11 03:05:06 +03:00
onEscKeyDown : onEscKeyDown || this . handleDismiss ,
onOverlayClick : onOverlayClick || this . handleDismiss ,
2016-06-03 23:29:21 +03:00
onSelect : this . handleSelect ,
2016-08-07 14:43:07 +03:00
sundayFirstDayOfWeek : sundayFirstDayOfWeek ,
2016-06-03 23:29:21 +03:00
theme : this . props . theme ,
value : date
} )
) ;
}
} ] ) ;
return DatePicker ;
} ( _react . Component ) ;
DatePicker . propTypes = {
2016-08-07 20:01:45 +03:00
active : _react . PropTypes . bool ,
2016-06-03 23:29:21 +03:00
autoOk : _react . PropTypes . bool ,
2016-10-12 18:09:19 +03:00
cancelLabel : _react . PropTypes . string ,
2016-06-03 23:29:21 +03:00
className : _react . PropTypes . string ,
error : _react . PropTypes . string ,
icon : _react . PropTypes . oneOfType ( [ _react . PropTypes . string , _react . PropTypes . element ] ) ,
inputClassName : _react . PropTypes . string ,
inputFormat : _react . PropTypes . func ,
label : _react . PropTypes . string ,
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 ,
2016-06-19 22:39:29 +03:00
name : _react . PropTypes . string ,
2016-10-12 18:09:19 +03:00
okLabel : _react . PropTypes . string ,
2016-06-03 23:29:21 +03:00
onChange : _react . PropTypes . func ,
2016-10-06 21:29:58 +03:00
onClick : _react . PropTypes . func ,
2016-10-22 18:35:55 +03:00
onDismiss : _react . PropTypes . func ,
2016-07-10 17:57:03 +03:00
onEscKeyDown : _react . PropTypes . func ,
2016-06-21 01:25:04 +03:00
onKeyPress : _react . PropTypes . func ,
2016-07-10 17:57:03 +03:00
onOverlayClick : _react . PropTypes . func ,
2016-08-06 15:35:41 +03:00
readonly : _react . PropTypes . bool ,
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
input : _react . PropTypes . string
2016-06-03 23:29:21 +03:00
} ) ,
value : _react . PropTypes . oneOfType ( [ _react . PropTypes . instanceOf ( Date ) , _react . PropTypes . string ] )
} ;
2016-08-01 14:21:32 +03:00
DatePicker . defaultProps = {
2016-08-07 20:01:45 +03:00
active : false ,
2016-08-01 14:21:32 +03:00
locale : 'en' ,
sundayFirstDayOfWeek : false
2016-06-03 23:29:21 +03:00
} ;
return DatePicker ;
} ;
var Calendar = ( 0 , _Calendar2 . default ) ( _IconButton2 . default ) ;
var DatePickerDialog = ( 0 , _DatePickerDialog2 . default ) ( _Dialog2 . default , Calendar ) ;
var DatePicker = factory ( _Input2 . default , DatePickerDialog ) ;
exports . default = ( 0 , _reactCssThemr . themr ) ( _identifiers . DATE _PICKER ) ( DatePicker ) ;
2016-08-07 14:43:07 +03:00
exports . DatePickerDialog = DatePickerDialog ;
2016-06-03 23:29:21 +03:00
exports . datePickerFactory = factory ;
exports . DatePicker = DatePicker ;