1 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 |
|
4 | var __rest = this && this.__rest || function (s, e) {
|
5 | var t = {};
|
6 |
|
7 | for (var p in s) {
|
8 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
9 | }
|
10 |
|
11 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
12 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
13 | }
|
14 | return t;
|
15 | };
|
16 |
|
17 | import classNames from 'classnames';
|
18 | import React, { Children, forwardRef, useContext } from 'react';
|
19 | import { ConfigContext } from '../config-provider';
|
20 | import { Col } from '../grid';
|
21 | import { cloneElement } from '../_util/reactNode';
|
22 | import { ListContext } from './index';
|
23 | export var Meta = function Meta(_a) {
|
24 | var customizePrefixCls = _a.prefixCls,
|
25 | className = _a.className,
|
26 | avatar = _a.avatar,
|
27 | title = _a.title,
|
28 | description = _a.description,
|
29 | others = __rest(_a, ["prefixCls", "className", "avatar", "title", "description"]);
|
30 |
|
31 | var _useContext = useContext(ConfigContext),
|
32 | getPrefixCls = _useContext.getPrefixCls;
|
33 |
|
34 | var prefixCls = getPrefixCls('list', customizePrefixCls);
|
35 | var classString = classNames("".concat(prefixCls, "-item-meta"), className);
|
36 | var content = React.createElement("div", {
|
37 | className: "".concat(prefixCls, "-item-meta-content")
|
38 | }, title && React.createElement("h4", {
|
39 | className: "".concat(prefixCls, "-item-meta-title")
|
40 | }, title), description && React.createElement("div", {
|
41 | className: "".concat(prefixCls, "-item-meta-description")
|
42 | }, description));
|
43 | return React.createElement("div", _extends({}, others, {
|
44 | className: classString
|
45 | }), avatar && React.createElement("div", {
|
46 | className: "".concat(prefixCls, "-item-meta-avatar")
|
47 | }, avatar), (title || description) && content);
|
48 | };
|
49 |
|
50 | var InternalItem = function InternalItem(_a, ref) {
|
51 | var customizePrefixCls = _a.prefixCls,
|
52 | children = _a.children,
|
53 | actions = _a.actions,
|
54 | extra = _a.extra,
|
55 | className = _a.className,
|
56 | colStyle = _a.colStyle,
|
57 | others = __rest(_a, ["prefixCls", "children", "actions", "extra", "className", "colStyle"]);
|
58 |
|
59 | var _useContext2 = useContext(ListContext),
|
60 | grid = _useContext2.grid,
|
61 | itemLayout = _useContext2.itemLayout;
|
62 |
|
63 | var _useContext3 = useContext(ConfigContext),
|
64 | getPrefixCls = _useContext3.getPrefixCls;
|
65 |
|
66 | var isItemContainsTextNodeAndNotSingular = function isItemContainsTextNodeAndNotSingular() {
|
67 | var result;
|
68 | Children.forEach(children, function (element) {
|
69 | if (typeof element === 'string') {
|
70 | result = true;
|
71 | }
|
72 | });
|
73 | return result && Children.count(children) > 1;
|
74 | };
|
75 |
|
76 | var isFlexMode = function isFlexMode() {
|
77 | if (itemLayout === 'vertical') {
|
78 | return !!extra;
|
79 | }
|
80 |
|
81 | return !isItemContainsTextNodeAndNotSingular();
|
82 | };
|
83 |
|
84 | var prefixCls = getPrefixCls('list', customizePrefixCls);
|
85 | var actionsContent = actions && actions.length > 0 && React.createElement("ul", {
|
86 | className: "".concat(prefixCls, "-item-action"),
|
87 | key: "actions"
|
88 | }, actions.map(function (action, i) {
|
89 | return (
|
90 |
|
91 |
|
92 | React.createElement("li", {
|
93 | key: "".concat(prefixCls, "-item-action-").concat(i)
|
94 | }, action, i !== actions.length - 1 && React.createElement("em", {
|
95 | className: "".concat(prefixCls, "-item-action-split")
|
96 | }))
|
97 | );
|
98 | }));
|
99 | var Element = grid ? 'div' : 'li';
|
100 | var itemChildren = React.createElement(Element, _extends({}, others, !grid ? {
|
101 | ref: ref
|
102 | } : {}, {
|
103 | className: classNames("".concat(prefixCls, "-item"), _defineProperty({}, "".concat(prefixCls, "-item-no-flex"), !isFlexMode()), className)
|
104 | }), itemLayout === 'vertical' && extra ? [React.createElement("div", {
|
105 | className: "".concat(prefixCls, "-item-main"),
|
106 | key: "content"
|
107 | }, children, actionsContent), React.createElement("div", {
|
108 | className: "".concat(prefixCls, "-item-extra"),
|
109 | key: "extra"
|
110 | }, extra)] : [children, actionsContent, cloneElement(extra, {
|
111 | key: 'extra'
|
112 | })]);
|
113 | return grid ? React.createElement(Col, {
|
114 | ref: ref,
|
115 | flex: 1,
|
116 | style: colStyle
|
117 | }, itemChildren) : itemChildren;
|
118 | };
|
119 |
|
120 | var Item = forwardRef(InternalItem);
|
121 | Item.Meta = Meta;
|
122 | export default Item; |
\ | No newline at end of file |