UNPKG

fit-select

Version:

选择框

81 lines (66 loc) 4.34 kB
"use strict"; 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; }; }(); 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) { 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 React = require('react'); var classNames = require('classnames'); var _ = require('lodash'); var _module = require('./module'); require('./index.css'); var reg = function reg(input) { var flags = 'g'; return new RegExp(input, flags); }; var Option = function (_React$Component) { _inherits(Option, _React$Component); function Option() { var _ref; _classCallCheck(this, Option); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, (_ref = Option.__proto__ || Object.getPrototypeOf(Option)).call.apply(_ref, [this].concat(args))); _this.state = new _module.State(); return _this; } _createClass(Option, [{ key: 'componentWillMount', value: function componentWillMount() { // 如果当前value和select的value相同,传递给父级 if (this.props.value === this.props['activeValue']) { this.props['setLabelValue'](this.props.children); } } }, { key: 'handleClick', value: function handleClick() { if (this.props.disabled) return; this.props['onClick'](this.props.value, this.props.children, this.props['optChildren'], this.props.zIndex); } }, { key: 'render', value: function render() { var classes = classNames(_defineProperty({ 'fit-select-option': true, 'active': this.props['active'], 'disabled': this.props.disabled }, this.props['className'], !!this.props['className'])); if (!_.isEmpty(this.props['searchValue'])) { var regex = reg(_.escape(this.props['searchValue'])); if (regex.test(this.props['children'].toString())) { var matchedString = _.escape(this.props['children'].toString()).replace(regex, '<span class="active">' + this.props['searchValue'] + '</span>'); return React.createElement("li", { onClick: this.handleClick.bind(this), className: classes, dangerouslySetInnerHTML: { __html: matchedString } }); } else { return null; } } return React.createElement("li", { onClick: this.handleClick.bind(this), className: classes }, this.props['children']); } }]); return Option; }(React.Component); Option.defaultProps = new _module.Props(); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Option;