UNPKG

hy-checkbox

Version:

checkbox & radio ui components for react

97 lines (75 loc) 5.4 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); require('./tree.less'); var _treeNode = require('./treeNode'); var _treeNode2 = _interopRequireDefault(_treeNode); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; } /* * @Author: SiMeiyu * @Date: 2017-07-04 10:08:38 */ var TreeRoot = function (_React$Component) { _inherits(TreeRoot, _React$Component); function TreeRoot() { _classCallCheck(this, TreeRoot); return _possibleConstructorReturn(this, (TreeRoot.__proto__ || Object.getPrototypeOf(TreeRoot)).apply(this, arguments)); } _createClass(TreeRoot, [{ key: 'renderTreeNode', value: function renderTreeNode(child, index) { var cloneProps = { ref: 'tree-node-' + child.key, root: this, eventKey: child.key, prefixCls: this.props.prefixCls, showLine: this.props.showLine, showIcon: this.props.showIcon, multiple: this.props.multiple, selectable: this.props.selectable, switchIcon: this.props.switchIcon, selected: this.props.selectedKey === child.key, checked: this.props.checkedKeys.find(function (k) { return k === child.key; }) }; return _react2.default.cloneElement(child, cloneProps); } }, { key: 'render', value: function render() { var _this2 = this; var _props = this.props, prefixCls = _props.prefixCls, className = _props.className, showLine = _props.showLine, showIcon = _props.showIcon, selectedKey = _props.selectedKey, multiple = _props.multiple, selectable = _props.selectable, switchIcon = _props.switchIcon, children = _props.children; var classes = (0, _classnames2.default)(prefixCls + '-tree', prefixCls + '-tree-root', className); return _react2.default.createElement( 'ul', { className: classes, ref: function ref(tree) { _this2.tree = tree; } }, _react2.default.Children.map(children, this.renderTreeNode, this) ); } }]); return TreeRoot; }(_react2.default.Component); exports.default = TreeRoot;