antd
Version:
An enterprise-class UI design language and React-based implementation
170 lines (162 loc) • 6.64 kB
JavaScript
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
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) t[p[i]] = s[p[i]];
}return t;
};
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
import { Col } from '../grid';
export var Meta = function Meta(props) {
var _props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === undefined ? 'ant-list' : _props$prefixCls,
className = props.className,
avatar = props.avatar,
title = props.title,
description = props.description,
others = __rest(props, ["prefixCls", "className", "avatar", "title", "description"]);
var classString = classNames(prefixCls + '-item-meta', className);
var content = React.createElement(
'div',
{ className: prefixCls + '-item-meta-content' },
title && React.createElement(
'h4',
{ className: prefixCls + '-item-meta-title' },
title
),
description && React.createElement(
'div',
{ className: prefixCls + '-item-meta-description' },
description
)
);
return React.createElement(
'div',
_extends({}, others, { className: classString }),
avatar && React.createElement(
'div',
{ className: prefixCls + '-item-meta-avatar' },
avatar
),
(title || description) && content
);
};
function getGrid(grid, t) {
return grid[t] && Math.floor(24 / grid[t]);
}
var GridColumns = ['', 1, 2, 3, 4, 6, 8, 12, 24];
var Item = function (_React$Component) {
_inherits(Item, _React$Component);
function Item() {
_classCallCheck(this, Item);
return _possibleConstructorReturn(this, (Item.__proto__ || Object.getPrototypeOf(Item)).apply(this, arguments));
}
_createClass(Item, [{
key: 'render',
value: function render() {
var grid = this.context.grid;
var _a = this.props,
_a$prefixCls = _a.prefixCls,
prefixCls = _a$prefixCls === undefined ? 'ant-list' : _a$prefixCls,
children = _a.children,
actions = _a.actions,
extra = _a.extra,
className = _a.className,
others = __rest(_a, ["prefixCls", "children", "actions", "extra", "className"]);
var classString = classNames(prefixCls + '-item', className);
var metaContent = [];
var otherContent = [];
React.Children.forEach(children, function (element) {
if (element && element.type && element.type === Meta) {
metaContent.push(element);
} else {
otherContent.push(element);
}
});
var contentClassString = classNames(prefixCls + '-item-content', _defineProperty({}, prefixCls + '-item-content-single', metaContent.length < 1));
var content = otherContent.length > 0 ? React.createElement(
'div',
{ className: contentClassString },
otherContent
) : null;
var actionsContent = void 0;
if (actions && actions.length > 0) {
var actionsContentItem = function actionsContentItem(action, i) {
return React.createElement(
'li',
{ key: prefixCls + '-item-action-' + i },
action,
i !== actions.length - 1 && React.createElement('em', { className: prefixCls + '-item-action-split' })
);
};
actionsContent = React.createElement(
'ul',
{ className: prefixCls + '-item-action' },
actions.map(function (action, i) {
return actionsContentItem(action, i);
})
);
}
var extraContent = React.createElement(
'div',
{ className: prefixCls + '-item-extra-wrap' },
React.createElement(
'div',
{ className: prefixCls + '-item-main' },
metaContent,
content,
actionsContent
),
React.createElement(
'div',
{ className: prefixCls + '-item-extra' },
extra
)
);
var mainContent = grid ? React.createElement(
Col,
{ span: getGrid(grid, 'column'), xs: getGrid(grid, 'xs'), sm: getGrid(grid, 'sm'), md: getGrid(grid, 'md'), lg: getGrid(grid, 'lg'), xl: getGrid(grid, 'xl'), xxl: getGrid(grid, 'xxl') },
React.createElement(
'div',
_extends({}, others, { className: classString }),
extra && extraContent,
!extra && metaContent,
!extra && content,
!extra && actionsContent
)
) : React.createElement(
'div',
_extends({}, others, { className: classString }),
extra && extraContent,
!extra && metaContent,
!extra && content,
!extra && actionsContent
);
return mainContent;
}
}]);
return Item;
}(React.Component);
export default Item;
Item.Meta = Meta;
Item.propTypes = {
column: PropTypes.oneOf(GridColumns),
xs: PropTypes.oneOf(GridColumns),
sm: PropTypes.oneOf(GridColumns),
md: PropTypes.oneOf(GridColumns),
lg: PropTypes.oneOf(GridColumns),
xl: PropTypes.oneOf(GridColumns),
xxl: PropTypes.oneOf(GridColumns)
};
Item.contextTypes = {
grid: PropTypes.any
};