UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

154 lines (131 loc) 4.51 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _typeof from "@babel/runtime/helpers/typeof"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import React, { Component } from 'react'; import classNames from 'classnames'; import DirectoryTree from './DirectoryTree'; import animation from '../_util/openAnimation'; import RcTree, { TreeNode } from '../rc-components/tree'; import Icon from '../icon'; import Progress from '../progress'; import { ProgressType } from '../progress/enum'; import { Size } from '../_util/enum'; import { isValidElement, cloneElement } from '../_util/reactNode'; import ConfigContext from '../config-provider/ConfigContext'; export { TreeNode }; var Tree = /*#__PURE__*/function (_Component) { _inherits(Tree, _Component); var _super = _createSuper(Tree); function Tree() { var _this; _classCallCheck(this, Tree); _this = _super.apply(this, arguments); _this.renderSwitcherIcon = function (_ref) { var isLeaf = _ref.isLeaf, loading = _ref.loading; var _this$props = _this.props, showLine = _this$props.showLine, switcherIcon = _this$props.switcherIcon; var prefixCls = _this.getPrefixCls(); if (loading) { return /*#__PURE__*/React.createElement(Progress, { type: ProgressType.loading, className: "".concat(prefixCls, "-switcher-loading-icon"), size: Size.small }); } var switcherCls = "".concat(prefixCls, "-switcher-icon"); var showLeafIcon; if (showLine && _typeof(showLine) === 'object') { showLeafIcon = showLine.showLeafIcon; } if (isLeaf) { if (showLine) { if (_typeof(showLine) === 'object' && !showLeafIcon) { return /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-switcher-leaf-line") }); } return /*#__PURE__*/React.createElement(Icon, { type: "note", className: "".concat(prefixCls, "-switcher-line-icon") }); } return null; } if (isValidElement(switcherIcon)) { var switcherOriginCls = switcherIcon.props.className || ''; return cloneElement(switcherIcon, { className: [switcherOriginCls, switcherCls] }); } return /*#__PURE__*/React.createElement(Icon, { type: "arrow_drop_down", className: switcherCls }); }; _this.setTreeRef = function (node) { _this.tree = node; }; return _this; } _createClass(Tree, [{ key: "getPrefixCls", value: function getPrefixCls() { var prefixCls = this.props.prefixCls; var getPrefixCls = this.context.getPrefixCls; return getPrefixCls('tree', prefixCls); } }, { key: "onKeyDown", value: function onKeyDown(e) { this.tree.onKeyDown(e); return e.isDefaultPrevented(); } }, { key: "render", value: function render() { var props = this.props; var className = props.className, showIcon = props.showIcon, showLine = props.showLine, children = props.children, checkable = props.checkable; var prefixCls = this.getPrefixCls(); var newProps = _objectSpread(_objectSpread({}, props), {}, { showLine: Boolean(showLine) }); return /*#__PURE__*/React.createElement(RcTree, _extends({ itemHeight: 20, ref: this.setTreeRef }, newProps, { className: classNames(!showIcon && "".concat(prefixCls, "-icon-hide"), className), checkable: checkable ? /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-checkbox-inner") }) : 0, switcherIcon: this.renderSwitcherIcon, prefixCls: prefixCls }), children); } }], [{ key: "contextType", get: function get() { return ConfigContext; } }]); return Tree; }(Component); export { Tree as default }; Tree.displayName = 'Tree'; Tree.TreeNode = TreeNode; Tree.DirectoryTree = DirectoryTree; Tree.defaultProps = { checkable: false, showIcon: false, openAnimation: animation }; //# sourceMappingURL=index.js.map