UNPKG

5.42 kBJavaScriptView Raw
1import { createVNode as _createVNode } from "vue";
2
3function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
5function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
6
7function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
8
9import { defineComponent, inject } from 'vue';
10import classNames from '../_util/classNames';
11import PropTypes, { withUndefined } from '../_util/vue-types';
12import { initDefaultProps, hasProp } from '../_util/props-util';
13import { defaultConfigProvider } from '../config-provider';
14import Avatar, { SkeletonAvatarProps } from './Avatar';
15import Title, { SkeletonTitleProps } from './Title';
16import Paragraph, { SkeletonParagraphProps } from './Paragraph';
17import { withInstall } from '../_util/type';
18export var SkeletonProps = {
19 active: PropTypes.looseBool,
20 loading: PropTypes.looseBool,
21 prefixCls: PropTypes.string,
22 children: PropTypes.any,
23 avatar: withUndefined(PropTypes.oneOfType([PropTypes.string, SkeletonAvatarProps, PropTypes.looseBool])),
24 title: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.string, SkeletonTitleProps])),
25 paragraph: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.string, SkeletonParagraphProps]))
26};
27
28function getComponentProps(prop) {
29 if (prop && _typeof(prop) === 'object') {
30 return prop;
31 }
32
33 return {};
34}
35
36function getAvatarBasicProps(hasTitle, hasParagraph) {
37 if (hasTitle && !hasParagraph) {
38 return {
39 shape: 'square'
40 };
41 }
42
43 return {
44 shape: 'circle'
45 };
46}
47
48function getTitleBasicProps(hasAvatar, hasParagraph) {
49 if (!hasAvatar && hasParagraph) {
50 return {
51 width: '38%'
52 };
53 }
54
55 if (hasAvatar && hasParagraph) {
56 return {
57 width: '50%'
58 };
59 }
60
61 return {};
62}
63
64function getParagraphBasicProps(hasAvatar, hasTitle) {
65 var basicProps = {}; // Width
66
67 if (!hasAvatar || !hasTitle) {
68 basicProps.width = '61%';
69 } // Rows
70
71
72 if (!hasAvatar && hasTitle) {
73 basicProps.rows = 3;
74 } else {
75 basicProps.rows = 2;
76 }
77
78 return basicProps;
79}
80
81var Skeleton = defineComponent({
82 name: 'ASkeleton',
83 props: initDefaultProps(SkeletonProps, {
84 avatar: false,
85 title: true,
86 paragraph: true
87 }),
88 setup: function setup() {
89 return {
90 configProvider: inject('configProvider', defaultConfigProvider)
91 };
92 },
93 render: function render() {
94 var _a, _b;
95
96 var _this$$props = this.$props,
97 customizePrefixCls = _this$$props.prefixCls,
98 loading = _this$$props.loading,
99 avatar = _this$$props.avatar,
100 title = _this$$props.title,
101 paragraph = _this$$props.paragraph,
102 active = _this$$props.active;
103 var getPrefixCls = this.configProvider.getPrefixCls;
104 var prefixCls = getPrefixCls('skeleton', customizePrefixCls);
105
106 if (loading || !hasProp(this, 'loading')) {
107 var _classNames;
108
109 var hasAvatar = !!avatar || avatar === '';
110 var hasTitle = !!title;
111 var hasParagraph = !!paragraph; // Avatar
112
113 var avatarNode;
114
115 if (hasAvatar) {
116 var avatarProps = _extends(_extends({
117 prefixCls: "".concat(prefixCls, "-avatar")
118 }, getAvatarBasicProps(hasTitle, hasParagraph)), getComponentProps(avatar));
119
120 avatarNode = _createVNode("div", {
121 "class": "".concat(prefixCls, "-header")
122 }, [_createVNode(Avatar, avatarProps, null)]);
123 }
124
125 var contentNode;
126
127 if (hasTitle || hasParagraph) {
128 // Title
129 var $title;
130
131 if (hasTitle) {
132 var titleProps = _extends(_extends({
133 prefixCls: "".concat(prefixCls, "-title")
134 }, getTitleBasicProps(hasAvatar, hasParagraph)), getComponentProps(title));
135
136 $title = _createVNode(Title, titleProps, null);
137 } // Paragraph
138
139
140 var paragraphNode;
141
142 if (hasParagraph) {
143 var paragraphProps = _extends(_extends({
144 prefixCls: "".concat(prefixCls, "-paragraph")
145 }, getParagraphBasicProps(hasAvatar, hasTitle)), getComponentProps(paragraph));
146
147 paragraphNode = _createVNode(Paragraph, paragraphProps, null);
148 }
149
150 contentNode = _createVNode("div", {
151 "class": "".concat(prefixCls, "-content")
152 }, [$title, paragraphNode]);
153 }
154
155 var cls = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-with-avatar"), hasAvatar), _defineProperty(_classNames, "".concat(prefixCls, "-active"), active), _classNames));
156 return _createVNode("div", {
157 "class": cls
158 }, [avatarNode, contentNode]);
159 }
160
161 return (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a);
162 }
163});
164export default withInstall(Skeleton);
\No newline at end of file