UNPKG

fit-select

Version:

选择框

49 lines (48 loc) 1.73 kB
"use strict"; const React = require('react'); const classNames = require('classnames'); const module = require('./module'); require('./index.scss'); class OptGroup extends React.Component { constructor(...args) { super(...args); this.state = new module.State(); } handleOptionClick(value, label) { this.props['onClick'](value, label); } setLabelValue(labelValue) { this.props['setLabelValue'](labelValue); } render() { const classes = classNames({ '_namespace': true, [this.props['className']]: !!this.props['className'] }); // 循环子元素 let Children = this.props.children; if (!this.props.ignoreChildren) { Children = React.Children.map(this.props['children'], (item, index) => { let active = false; if (item.props.value === this.props['activeValue']) { active = true; } return React.cloneElement(item, Object.assign({}, item.props, { onClick: this.handleOptionClick.bind(this), key: index, active: active, setLabelValue: this.setLabelValue.bind(this), activeValue: this.props['activeValue'], searchValue: this.props['searchValue'] })); }); } return (<div className={classes}> <li className="group-result">{this.props.label}</li> {Children} </div>); } } OptGroup.defaultProps = new module.Props(); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = OptGroup;