UNPKG

choerodon-ui

Version:

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

223 lines (172 loc) 6.08 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; 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"; import _typeof from "@babel/runtime/helpers/typeof"; 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 * as React from 'react'; import classNames from 'classnames'; import Title from './Title'; import Grid from './Grid'; import Paragraph from './Paragraph'; import { getPrefixCls } from '../configure'; import Element from './Element'; function getComponentProps(prop) { if (prop && _typeof(prop) === 'object') { return prop; } return {}; } function getAvatarBasicProps(hasTitle, hasParagraph) { if (hasTitle && !hasParagraph) { // Square avatar return { size: 'large', shape: 'square' }; } return { size: 'large', shape: 'circle' }; } function getTitleBasicProps(hasAvatar, hasParagraph) { if (!hasAvatar && hasParagraph) { return { width: '38%' }; } if (hasAvatar && hasParagraph) { return { width: '50%' }; } return {}; } function getParagraphBasicProps(hasAvatar, hasTitle) { var basicProps = {}; // Width if (!hasAvatar || !hasTitle) { basicProps.width = '61%'; } // Rows if (!hasAvatar && hasTitle) { basicProps.rows = 3; } else { basicProps.rows = 2; } return basicProps; } var Skeleton = /*#__PURE__*/ function (_React$Component) { _inherits(Skeleton, _React$Component); var _super = _createSuper(Skeleton); function Skeleton() { var _this; _classCallCheck(this, Skeleton); _this = _super.apply(this, arguments); _this.renderSkeleton = function () { var _this$props = _this.props, customizePrefixCls = _this$props.prefixCls, loading = _this$props.loading, className = _this$props.className, children = _this$props.children, avatar = _this$props.avatar, title = _this$props.title, paragraph = _this$props.paragraph, active = _this$props.active, grid = _this$props.grid; var prefixCls = getPrefixCls('skeleton', customizePrefixCls); if (loading || !('loading' in _this.props)) { var _classNames; var hasAvatar = !!avatar; var hasTitle = !!title; var hasParagraph = !!paragraph; var hasGrid = !!grid; // Avatar var avatarNode; if (hasAvatar) { var avatarProps = _objectSpread({ prefixCls: "".concat(prefixCls, "-avatar") }, getAvatarBasicProps(hasTitle, hasParagraph), {}, getComponentProps(avatar)); // We direct use SkeletonElement as avatar in skeleton internal. avatarNode = React.createElement("div", { className: "".concat(prefixCls, "-header") }, React.createElement(Element, _extends({}, avatarProps))); } var contentNode; if (hasTitle || hasParagraph || hasGrid) { // Title var $title; if (hasTitle) { var titleProps = _objectSpread({ prefixCls: "".concat(prefixCls, "-title") }, getTitleBasicProps(hasAvatar, hasParagraph || hasGrid), {}, getComponentProps(title)); $title = React.createElement(Title, _extends({}, titleProps)); } // Paragraph var paragraphNode; if (hasParagraph) { var paragraphProps = _objectSpread({ prefixCls: "".concat(prefixCls, "-paragraph") }, getParagraphBasicProps(hasAvatar, hasTitle), {}, getComponentProps(paragraph)); paragraphNode = React.createElement(Paragraph, _extends({}, paragraphProps)); } // Grid var gridNode; if (hasGrid) { var gridProps = _objectSpread({ prefixCls: "".concat(prefixCls, "-grid") }, getComponentProps(grid)); gridNode = React.createElement(Grid, _extends({}, gridProps)); } contentNode = React.createElement("div", { className: "".concat(prefixCls, "-content") }, $title, paragraphNode, gridNode); } var cls = classNames(prefixCls, className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-with-avatar"), hasAvatar), _defineProperty(_classNames, "".concat(prefixCls, "-active"), active), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), false), _classNames)); return React.createElement("div", { className: cls }, avatarNode, contentNode); } return children; }; return _this; } _createClass(Skeleton, [{ key: "render", value: function render() { return React.createElement(React.Fragment, null, this.renderSkeleton()); } }]); return Skeleton; }(React.Component); Skeleton.defaultProps = { avatar: false, title: true, paragraph: true }; export default Skeleton; //# sourceMappingURL=Skeleton.js.map