all files / src/ Item.jsx

45.31% Statements 29/64
25% Branches 10/40
30% Functions 3/10
75% Lines 24/32
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                                                                                                                                             
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
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; };
 
var _react = require('react');
 
var _react2 = _interopRequireDefault(_react);
 
var _propTypes = require('prop-types');
 
var _propTypes2 = _interopRequireDefault(_propTypes);
 
var _rcMenu = require('rc-menu');
 
var _utils = require('./utils');
 
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 _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; }
 
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 Item = function (_React$Component) {
  _inherits(Item, _React$Component);
 
  function Item() {
    _classCallCheck(this, Item);
 
    return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  }
 
  Item.prototype.render = function render() {
    var _context = this.context,
        mode = _context.mode,
        level = _context.level,
        prefixCls = _context.prefixCls,
        lineClamp = _context.lineClamp;
 
    var _props = this.props,
        children = _props.children,
        otherProps = _objectWithoutProperties(_props, ['children']);
 
    var _getClampProps = (0, _utils.getClampProps)({
      mode: mode,
      level: level,
      className: prefixCls + '-clamp-text',
      lineClamp: lineClamp
    }),
        spanProps = _getClampProps.props,
        clamp = _getClampProps.clamp;
 
    if (typeof children === 'string') {
      spanProps.title = children;
    }
 
    return _react2['default'].createElement(
      _rcMenu.MenuItem,
      _extends({
        className: clamp ? prefixCls + '-item-clamp' : ''
      }, otherProps),
      _react2['default'].createElement(
        'span',
        spanProps,
        children
      )
    );
  };
 
  return Item;
}(_react2['default'].Component);
 
Item.propTypes = _extends({}, _rcMenu.MenuItem.propTypes);
 
Item.defaultProps = _extends({}, _rcMenu.MenuItem.defaultProps);
 
Item.contextTypes = {
  mode: _propTypes2['default'].string,
  level: _propTypes2['default'].number,
  prefixCls: _propTypes2['default'].string,
  lineClamp: _propTypes2['default'].number
};
 
exports['default'] = Item;
module.exports = exports['default'];