2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2016-02-19 19:35:49 +08:00
|
|
|
import classNames from 'classnames';
|
2017-07-07 13:36:54 +08:00
|
|
|
import Grid from './Grid';
|
2016-07-14 13:29:50 +08:00
|
|
|
|
2016-09-13 15:31:29 +08:00
|
|
|
export interface CardProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls?: string;
|
2016-07-14 13:29:50 +08:00
|
|
|
title?: React.ReactNode;
|
|
|
|
extra?: React.ReactNode;
|
|
|
|
bordered?: boolean;
|
|
|
|
bodyStyle?: React.CSSProperties;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
loading?: boolean;
|
2017-07-07 13:36:54 +08:00
|
|
|
noHovering?: boolean;
|
2016-07-14 13:29:50 +08:00
|
|
|
children?: any;
|
2016-09-21 09:27:58 +08:00
|
|
|
id?: string;
|
2016-10-21 16:27:26 +08:00
|
|
|
className?: string;
|
2016-07-14 13:29:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 13:36:54 +08:00
|
|
|
const Card = (props: CardProps) => {
|
2016-12-19 15:19:15 +08:00
|
|
|
const {
|
2017-07-07 13:36:54 +08:00
|
|
|
prefixCls = 'ant-card', className, extra, bodyStyle, noHovering,
|
2016-12-19 15:19:15 +08:00
|
|
|
title, loading, bordered = true, ...others,
|
|
|
|
} = props;
|
2016-06-22 13:18:43 +08:00
|
|
|
let children = props.children;
|
2016-11-30 10:20:23 +08:00
|
|
|
const classString = classNames(prefixCls, className, {
|
2016-02-22 16:25:13 +08:00
|
|
|
[`${prefixCls}-loading`]: loading,
|
2016-04-10 15:38:52 +08:00
|
|
|
[`${prefixCls}-bordered`]: bordered,
|
2017-07-07 13:36:54 +08:00
|
|
|
[`${prefixCls}-no-hovering`]: noHovering,
|
2016-02-19 19:35:49 +08:00
|
|
|
});
|
2016-02-22 16:25:13 +08:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
children = (
|
|
|
|
<div>
|
2016-12-20 12:21:08 +08:00
|
|
|
<p className={`${prefixCls}-loading-block`} style={{ width: '94%' }} />
|
|
|
|
<p>
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '28%' }} />
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '62%' }} />
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '22%' }} />
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '66%' }} />
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '56%' }} />
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '39%' }} />
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '21%' }} />
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '15%' }} />
|
|
|
|
<span className={`${prefixCls}-loading-block`} style={{ width: '40%' }} />
|
|
|
|
</p>
|
2016-02-22 16:25:13 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-14 14:41:21 +08:00
|
|
|
let head;
|
|
|
|
if (!title) {
|
|
|
|
head = null;
|
|
|
|
} else {
|
|
|
|
head = typeof title === 'string' ? (
|
|
|
|
<div className={`${prefixCls}-head`}>
|
|
|
|
<h3 className={`${prefixCls}-head-title`}>{title}</h3>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={`${prefixCls}-head`}>
|
|
|
|
<div className={`${prefixCls}-head-title`}>{title}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-02-22 16:25:13 +08:00
|
|
|
|
2016-02-19 19:35:49 +08:00
|
|
|
return (
|
2016-06-22 13:18:43 +08:00
|
|
|
<div {...others} className={classString}>
|
2016-02-20 16:40:18 +08:00
|
|
|
{head}
|
|
|
|
{extra ? <div className={`${prefixCls}-extra`}>{extra}</div> : null}
|
|
|
|
<div className={`${prefixCls}-body`} style={bodyStyle}>{children}</div>
|
2016-02-19 19:35:49 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2017-07-07 13:36:54 +08:00
|
|
|
|
|
|
|
(Card as any).Grid = Grid;
|
|
|
|
|
|
|
|
export default Card;
|