UNPKG

choerodon-ui

Version:

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

182 lines (152 loc) 5.14 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 _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } 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 { getPrefixCls as _getPrefixCls } from '../configure'; import { isValidElement, cloneElement } from '../_util/reactNode'; 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 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 React.createElement("span", { className: "".concat(prefixCls, "-switcher-leaf-line") }); } return 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 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; 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({}, props, { showLine: Boolean(showLine) }); return React.createElement(RcTree, _extends({ itemHeight: 20, ref: this.setTreeRef }, newProps, { className: classNames(!showIcon && "".concat(prefixCls, "-icon-hide"), className), checkable: checkable ? React.createElement("span", { className: "".concat(prefixCls, "-checkbox-inner") }) : 0, switcherIcon: this.renderSwitcherIcon, prefixCls: prefixCls }), children); } }]); 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