index.js
7.25 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
179
180
181
182
183
184
185
186
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _extends from "@babel/runtime/helpers/extends";
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import Grid from './Grid';
import Meta from './Meta';
import Tabs from '../tabs';
import Row from '../row';
import Col from '../col';
import { ConfigContext } from '../config-provider';
import SizeContext from '../config-provider/SizeContext';
function getAction(actions) {
var actionList = actions.map(function (action, index) {
return (
/*#__PURE__*/
// eslint-disable-next-line react/no-array-index-key
React.createElement("li", {
style: {
width: "".concat(100 / actions.length, "%")
},
key: "action-".concat(index)
}, /*#__PURE__*/React.createElement("span", null, action))
);
});
return actionList;
}
var Card = function Card(props) {
var _extends2, _classNames;
var _React$useContext = React.useContext(ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls,
direction = _React$useContext.direction;
var size = React.useContext(SizeContext);
var onTabChange = function onTabChange(key) {
if (props.onTabChange) {
props.onTabChange(key);
}
};
var isContainGrid = function isContainGrid() {
var containGrid;
React.Children.forEach(props.children, function (element) {
if (element && element.type && element.type === Grid) {
containGrid = true;
}
});
return containGrid;
};
var customizePrefixCls = props.prefixCls,
className = props.className,
extra = props.extra,
_props$headStyle = props.headStyle,
headStyle = _props$headStyle === void 0 ? {} : _props$headStyle,
_props$bodyStyle = props.bodyStyle,
bodyStyle = _props$bodyStyle === void 0 ? {} : _props$bodyStyle,
title = props.title,
loading = props.loading,
_props$bordered = props.bordered,
bordered = _props$bordered === void 0 ? true : _props$bordered,
customizeSize = props.size,
type = props.type,
cover = props.cover,
actions = props.actions,
tabList = props.tabList,
children = props.children,
activeTabKey = props.activeTabKey,
defaultActiveTabKey = props.defaultActiveTabKey,
tabBarExtraContent = props.tabBarExtraContent,
hoverable = props.hoverable,
_props$tabProps = props.tabProps,
tabProps = _props$tabProps === void 0 ? {} : _props$tabProps,
others = __rest(props, ["prefixCls", "className", "extra", "headStyle", "bodyStyle", "title", "loading", "bordered", "size", "type", "cover", "actions", "tabList", "children", "activeTabKey", "defaultActiveTabKey", "tabBarExtraContent", "hoverable", "tabProps"]);
var prefixCls = getPrefixCls('card', customizePrefixCls);
var loadingBlockStyle = bodyStyle.padding === 0 || bodyStyle.padding === '0px' ? {
padding: 24
} : undefined;
var block = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-loading-block")
});
var loadingBlock = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-loading-content"),
style: loadingBlockStyle
}, /*#__PURE__*/React.createElement(Row, {
gutter: 8
}, /*#__PURE__*/React.createElement(Col, {
span: 22
}, block)), /*#__PURE__*/React.createElement(Row, {
gutter: 8
}, /*#__PURE__*/React.createElement(Col, {
span: 8
}, block), /*#__PURE__*/React.createElement(Col, {
span: 15
}, block)), /*#__PURE__*/React.createElement(Row, {
gutter: 8
}, /*#__PURE__*/React.createElement(Col, {
span: 6
}, block), /*#__PURE__*/React.createElement(Col, {
span: 18
}, block)), /*#__PURE__*/React.createElement(Row, {
gutter: 8
}, /*#__PURE__*/React.createElement(Col, {
span: 13
}, block), /*#__PURE__*/React.createElement(Col, {
span: 9
}, block)), /*#__PURE__*/React.createElement(Row, {
gutter: 8
}, /*#__PURE__*/React.createElement(Col, {
span: 4
}, block), /*#__PURE__*/React.createElement(Col, {
span: 3
}, block), /*#__PURE__*/React.createElement(Col, {
span: 16
}, block)));
var hasActiveTabKey = activeTabKey !== undefined;
var extraProps = _extends(_extends({}, tabProps), (_extends2 = {}, _defineProperty(_extends2, hasActiveTabKey ? 'activeKey' : 'defaultActiveKey', hasActiveTabKey ? activeTabKey : defaultActiveTabKey), _defineProperty(_extends2, "tabBarExtraContent", tabBarExtraContent), _extends2));
var head;
var tabs = tabList && tabList.length ? /*#__PURE__*/React.createElement(Tabs, _extends({
size: "large"
}, extraProps, {
className: "".concat(prefixCls, "-head-tabs"),
onChange: onTabChange
}), tabList.map(function (item) {
return /*#__PURE__*/React.createElement(Tabs.TabPane, {
tab: item.tab,
disabled: item.disabled,
key: item.key
});
})) : null;
if (title || extra || tabs) {
head = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-head"),
style: headStyle
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-head-wrapper")
}, title && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-head-title")
}, title), extra && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-extra")
}, extra)), tabs);
}
var coverDom = cover ? /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-cover")
}, cover) : null;
var body = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-body"),
style: bodyStyle
}, loading ? loadingBlock : children);
var actionDom = actions && actions.length ? /*#__PURE__*/React.createElement("ul", {
className: "".concat(prefixCls, "-actions")
}, getAction(actions)) : null;
var divProps = omit(others, ['onTabChange']);
var mergedSize = customizeSize || size;
var classString = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-loading"), loading), _defineProperty(_classNames, "".concat(prefixCls, "-bordered"), bordered), _defineProperty(_classNames, "".concat(prefixCls, "-hoverable"), hoverable), _defineProperty(_classNames, "".concat(prefixCls, "-contain-grid"), isContainGrid()), _defineProperty(_classNames, "".concat(prefixCls, "-contain-tabs"), tabList && tabList.length), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(mergedSize), mergedSize), _defineProperty(_classNames, "".concat(prefixCls, "-type-").concat(type), !!type), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _classNames), className);
return /*#__PURE__*/React.createElement("div", _extends({}, divProps, {
className: classString
}), head, coverDom, body, actionDom);
};
Card.Grid = Grid;
Card.Meta = Meta;
export default Card;