all files / src/timePicker/ Pmam.jsx

49.15% Statements 29/59
28.13% Branches 9/32
27.27% Functions 3/11
64.86% Lines 24/37
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108                                                                                                                                                                       
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _react = require('react');
 
var _react2 = _interopRequireDefault(_react);
 
var _propTypes = require('prop-types');
 
var _propTypes2 = _interopRequireDefault(_propTypes);
 
var _classnames2 = require('classnames');
 
var _classnames3 = _interopRequireDefault(_classnames2);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return 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; }
 
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) { Iif (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 } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
 
var Pmam = function (_React$Component) {
  _inherits(Pmam, _React$Component);
 
  function Pmam() {
    _classCallCheck(this, Pmam);
 
    return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  }
 
  Pmam.prototype.handleClick = function handleClick(item) {
    var value = this.props.value;
 
    var newValue = value.clone();
    var hourMap = {
      am: 9,
      pm: 15
    };
    newValue.hour(hourMap[item]);
    this.props.onChange(newValue);
  };
 
  Pmam.prototype.render = function render() {
    var _this2 = this;
 
    var _props = this.props,
        locale = _props.locale,
        value = _props.value,
        prefixCls = _props.prefixCls;
 
    var items = ['am', 'pm'];
    var pmam = value.hour() >= 12 ? 'pm' : 'am';
    return _react2['default'].createElement(
      'div',
      null,
      _react2['default'].createElement(
        'div',
        {
          className: prefixCls + '-panel-selected-value'
        },
        locale[pmam]
      ),
      _react2['default'].createElement(
        'ul',
        { className: prefixCls + '-pmam-panel' },
        items.map(function (item) {
          return _react2['default'].createElement(
            'li',
            {
              key: item,
              className: (0, _classnames3['default'])(prefixCls + '-pmam-item', _defineProperty({}, prefixCls + '-pmam-item-active', item === pmam)),
              onClick: _this2.handleClick.bind(_this2, item)
            },
            locale[item]
          );
        })
      )
    );
  };
 
  return Pmam;
}(_react2['default'].Component);
 
Pmam.propTypes = {
  locale: _propTypes2['default'].object,
  value: _propTypes2['default'].any,
  prefixCls: _propTypes2['default'].string,
  onChange: _propTypes2['default'].func
};
 
Pmam.defaultProps = {
  prefixCls: 'kuma-time-picker'
};
 
Pmam.displayName = 'Pmam';
 
exports['default'] = Pmam;
module.exports = exports['default'];