ant-design/components/card/index.tsx

83 lines
2.4 KiB
TypeScript
Raw Normal View History

2016-09-21 11:54:53 +08:00
import React from 'react';
2016-02-19 19:35:49 +08:00
import classNames from 'classnames';
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;
noHovering?: boolean;
2016-07-14 13:29:50 +08:00
children?: any;
id?: string;
2016-10-21 16:27:26 +08:00
className?: string;
2016-07-14 13:29:50 +08:00
}
const Card = (props: CardProps) => {
2016-12-19 15:19:15 +08:00
const {
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;
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,
[`${prefixCls}-no-hovering`]: noHovering,
2016-02-19 19:35:49 +08:00
});
2016-02-22 16:25:13 +08:00
if (loading) {
children = (
<div>
<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>
);
};
(Card as any).Grid = Grid;
export default Card;