UNPKG

@beisen/dropdown-list

Version:

DropDownList

146 lines (116 loc) 6.03 kB
'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 _reactDom = require('react-dom'); var _CheckBoxItem = require('./CheckBoxItem.js'); var _CheckBoxItem2 = _interopRequireDefault(_CheckBoxItem); 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 CheckboxList = function (_Component) { _inherits(CheckboxList, _Component); function CheckboxList(props) { _classCallCheck(this, CheckboxList); var _this = _possibleConstructorReturn(this, _Component.call(this, props)); var defaults = { checkboxItems: [{ bsStyle: true, isChecked: false, listActive: false, top: 55, hightLightColor: '#F5F8FA' }] }; _this.state = _extends({}, defaults, props); // this.state = props; return _this; } CheckboxList.prototype.componentDidMount = function componentDidMount() { this.setState({ listActive: true }); }; CheckboxList.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { if (nextProps.checkboxItems != this.state.checkboxItems) { this.setState({ checkboxItems: nextProps.checkboxItems }); } }; //处理点击事件 改变当前点击checkbox的isChecked值 CheckboxList.prototype.handleClick = function handleClick(event, value, val) { if (this.props.disabled) { return false; } var checkboxItems = this.state.checkboxItems; checkboxItems.forEach(function (elem, index) { if (elem.value == value && elem.bsStyle == true) { elem.isChecked = !elem.isChecked; } }); //this.props.CheckBoxItemClick({"target":event.target,"value":val}); this.setState({ checkboxItems: checkboxItems }); }; CheckboxList.prototype.handleHover = function handleHover(event) { var hoverName = event.target.className; if (hoverName.indexOf('pc-sys-Checkbox-hover-svg') == -1) { event.target.className = hoverName.replace(/nomal/, 'hover'); } }; CheckboxList.prototype.handleMouseOut = function handleMouseOut(event) { var hoverName = event.target.className; if (hoverName.indexOf('pc-sys-Checkbox-hover-svg') !== -1) { event.target.className = hoverName.replace(/hover/, 'nomal'); } }; CheckboxList.prototype.itemHover = function itemHover(id) { this.setState({ top: 55 + id * 38 - this.refs.searchCheckbox.scrollTop, hightLightColor: '#F5F8FA' }); }; CheckboxList.prototype.onMouseOut = function onMouseOut() { this.setState({ top: 55, hightLightColor: '#FFF' }); }; CheckboxList.prototype.render = function render() { var _this2 = this; var checkboxItems = this.props.checkboxItems; var _props = this.props; var name = _props.name; var hidden = _props.hidden; var disabled = _props.disabled; var searchValue = _props.searchValue; var height = checkboxItems.length * 38 > 380 ? 380 : checkboxItems.length * 38; if (hidden) { return _react2.default.createElement('div', null); } else { return _react2.default.createElement( 'div', { ref: 'searchCheckbox', className: "search-checkbox-component" + (this.state.listActive ? " list-real-spread" : ""), style: { 'height': height }, onMouseOut: this.onMouseOut.bind(this) }, checkboxItems.map(function (item, index) { var isItemmChecked = void 0; if (disabled) { isItemmChecked = 'search-checkbox-table-item-check table-item-check-back pc-sys-Checkbox-disabled-svg'; } else { isItemmChecked = item.isChecked ? "search-checkbox-table-item-check search-checkbox-table-item-check-go pc-sys-Checkbox-active-svg" : "search-checkbox-table-item-check search-checkbox-table-item-check-back pc-sys-Checkbox-nomal-svg"; } return _react2.default.createElement(_CheckBoxItem2.default, { searchValue: searchValue, key: index, item: item, isItemmChecked: isItemmChecked, title: item.text, bsStyle: item.bsStyle, id: item.id, index: index, itemHover: _this2.itemHover.bind(_this2), handleClick: _this2.handleClick.bind(_this2), handleHover: _this2.handleHover.bind(_this2), handleMouseOut: _this2.handleMouseOut.bind(_this2) }); }), _react2.default.createElement('div', { className: 'search-checkbox-high-light', style: { "transition": "top 0.2s cubic-bezier(.25,.1,.25,1)", "transitionDelay": "0s!important", 'top': this.state.top, 'backgroundColor': this.state.hightLightColor } }) ); } }; return CheckboxList; }(_react.Component); exports.default = CheckboxList;