Skeleton.js
5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Title = _interopRequireDefault(require("./Title"));
var _Paragraph = _interopRequireDefault(require("./Paragraph"));
var _configProvider = require("../config-provider");
var _Element = _interopRequireDefault(require("./Element"));
var _Avatar = _interopRequireDefault(require("./Avatar"));
var _Button = _interopRequireDefault(require("./Button"));
var _Input = _interopRequireDefault(require("./Input"));
var _Image = _interopRequireDefault(require("./Image"));
function getComponentProps(prop) {
if (prop && (0, _typeof2["default"])(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 = function Skeleton(props) {
var renderSkeleton = function renderSkeleton(_ref) {
var getPrefixCls = _ref.getPrefixCls,
direction = _ref.direction;
var customizePrefixCls = props.prefixCls,
loading = props.loading,
className = props.className,
children = props.children,
avatar = props.avatar,
title = props.title,
paragraph = props.paragraph,
active = props.active,
round = props.round;
var prefixCls = getPrefixCls('skeleton', customizePrefixCls);
if (loading || !('loading' in props)) {
var _classNames;
var hasAvatar = !!avatar;
var hasTitle = !!title;
var hasParagraph = !!paragraph; // Avatar
var avatarNode;
if (hasAvatar) {
var avatarProps = (0, _extends2["default"])((0, _extends2["default"])({
prefixCls: "".concat(prefixCls, "-avatar")
}, getAvatarBasicProps(hasTitle, hasParagraph)), getComponentProps(avatar)); // We direct use SkeletonElement as avatar in skeleton internal.
avatarNode = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-header")
}, /*#__PURE__*/React.createElement(_Element["default"], avatarProps));
}
var contentNode;
if (hasTitle || hasParagraph) {
// Title
var $title;
if (hasTitle) {
var titleProps = (0, _extends2["default"])((0, _extends2["default"])({
prefixCls: "".concat(prefixCls, "-title")
}, getTitleBasicProps(hasAvatar, hasParagraph)), getComponentProps(title));
$title = /*#__PURE__*/React.createElement(_Title["default"], titleProps);
} // Paragraph
var paragraphNode;
if (hasParagraph) {
var paragraphProps = (0, _extends2["default"])((0, _extends2["default"])({
prefixCls: "".concat(prefixCls, "-paragraph")
}, getParagraphBasicProps(hasAvatar, hasTitle)), getComponentProps(paragraph));
paragraphNode = /*#__PURE__*/React.createElement(_Paragraph["default"], paragraphProps);
}
contentNode = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-content")
}, $title, paragraphNode);
}
var cls = (0, _classnames["default"])(prefixCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-with-avatar"), hasAvatar), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-active"), active), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-round"), round), _classNames), className);
return /*#__PURE__*/React.createElement("div", {
className: cls
}, avatarNode, contentNode);
}
return children;
};
return /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, null, renderSkeleton);
};
Skeleton.defaultProps = {
avatar: false,
title: true,
paragraph: true
};
Skeleton.Button = _Button["default"];
Skeleton.Avatar = _Avatar["default"];
Skeleton.Input = _Input["default"];
Skeleton.Image = _Image["default"];
var _default = Skeleton;
exports["default"] = _default;