UNPKG

@beisen/dropdown-list

Version:

DropDownList

96 lines (74 loc) 3.86 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactDom = require('react-dom'); 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 _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) : _defaults(subClass, superClass); } var CheckboxItem = function (_Component) { _inherits(CheckboxItem, _Component); function CheckboxItem() { _classCallCheck(this, CheckboxItem); return _possibleConstructorReturn(this, _Component.apply(this, arguments)); } CheckboxItem.prototype.handleClick = function handleClick(e) { this.props.handleClick(e, this.props.item.value, this.props.item); }; CheckboxItem.prototype.itemHover = function itemHover() { this.props.itemHover(this.props.index); }; CheckboxItem.prototype.render = function render() { var _context; //通过判断bsStyle控制checkbox是否可选 var itemBsStyle = this.props.bsStyle; var _props = this.props; var searchValue = _props.searchValue; var index = _props.index; var item = _props.item; var searchContent = void 0, text = item.text, beforeText = void 0; if (searchValue.length > 0) { //获取搜索字符在字段中的位置,分两种 1.首位(index==0) 2.非首位 var _index = item.text.indexOf(searchValue); var valueLength = searchValue.length; if (_index == 0) { var subValue = item.text.substring(_index, valueLength); searchContent = _react2.default.createElement( 'em', null, subValue ); text = text.substring(valueLength, item.text.length); } else if (_index > 0) { beforeText = item.text.substring(0, _index); var _subValue = item.text.substring(_index, valueLength + _index); searchContent = _react2.default.createElement( 'em', null, _subValue ); text = text.substring(valueLength + _index, item.text.length); } } return _react2.default.createElement( 'div', { className: itemBsStyle ? 'search-checkbox search-checkbox-optional' : 'search-checkbox search-checkbox-notOptional', onMouseOver: this.itemHover.bind(this) }, _react2.default.createElement('label', { className: itemBsStyle ? this.props.isItemmChecked : '', onClick: this.handleClick.bind(this), onMouseOver: (_context = this.props).handleHover.bind(_context), onMouseOut: (_context = this.props).handleMouseOut.bind(_context) }), _react2.default.createElement( 'label', { className: 'search-checkbox-check-title', title: this.props.item.text }, beforeText, searchContent, text ) ); }; return CheckboxItem; }(_react.Component); exports.default = CheckboxItem;