Add loading card

This commit is contained in:
afc163 2016-02-22 16:25:13 +08:00
parent 845e28d32e
commit cacb5725a2
3 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,38 @@
# 预加载的卡片
- order: 4
数据读入前会有文本块样式。
---
````jsx
import { Card } from 'antd';
const App = React.createClass({
getInitialState() {
return {
loading: true,
content: '',
};
},
componentDidMount() {
// mock loading
setTimeout(() => {
this.setState({
loading: false,
content: '卡片的内容',
});
}, 2000);
},
render() {
return (
<Card loading={this.state.loading} title="卡片标题" style={{ width: 300 }}>
{this.state.content}
</Card>
);
},
});
ReactDOM.render(<App />, mountNode);
````

View File

@ -2,16 +2,30 @@ import React from 'react';
import classNames from 'classnames';
export default props => {
const { prefixCls = 'ant-card', className, children, extra, bodyStyle, title, ...other } = props;
let { prefixCls = 'ant-card', className, children, extra, bodyStyle, title, loading, ...other } = props;
const classString = classNames({
[prefixCls]: true,
[className]: !!className,
[`${prefixCls}-loading`]: loading,
});
if (loading) {
children = (
<div>
<p></p>
<p> </p>
<p> </p>
<p>  </p>
</div>
);
}
const head = title ? (
<div className={`${prefixCls}-head`}>
<h3 className={`${prefixCls}-head-title`}>{title}</h3>
</div>
) : null;
return (
<div {...other} className={classString}>
{head}

View File

@ -34,4 +34,15 @@
&-body {
padding: 24px;
}
&-loading &-body {
letter-spacing: -2px;
color: #eee;
font-size: 0.75rem;
}
&-loading &-body p {
word-break: break-all;
line-height: 2;
}
}