2015-09-01 11:47:12 +08:00
|
|
|
import React from 'react';
|
2016-01-14 16:43:48 +08:00
|
|
|
import classNames from 'classnames';
|
2015-09-01 11:47:12 +08:00
|
|
|
|
2016-01-14 16:43:48 +08:00
|
|
|
const TimelineItem = React.createClass({
|
2015-09-01 11:47:12 +08:00
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
2016-01-14 16:43:48 +08:00
|
|
|
prefixCls: 'ant-timeline',
|
|
|
|
color: 'blue',
|
|
|
|
last: false,
|
|
|
|
pending: false,
|
2015-09-01 11:47:12 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
render() {
|
2016-01-14 16:43:48 +08:00
|
|
|
const { prefixCls, color, last, children, pending } = this.props;
|
|
|
|
const itemClassName = classNames({
|
|
|
|
[prefixCls + '-item']: true,
|
|
|
|
[prefixCls + '-item-last']: last,
|
|
|
|
[prefixCls + '-item-pending']: pending,
|
|
|
|
});
|
2015-09-01 11:47:12 +08:00
|
|
|
return (
|
2016-01-14 16:43:48 +08:00
|
|
|
<li className={itemClassName}>
|
|
|
|
<div className={prefixCls + '-item-tail'} />
|
|
|
|
<div className={prefixCls + '-item-head ' + prefixCls + '-item-head-' + color} />
|
|
|
|
<div className={prefixCls + '-item-content'}>{children}</div>
|
|
|
|
</li>
|
2015-09-01 11:47:12 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-14 16:43:48 +08:00
|
|
|
const Timeline = React.createClass({
|
2015-09-01 11:47:12 +08:00
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
prefixCls: 'ant-timeline',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render() {
|
2016-01-14 16:43:48 +08:00
|
|
|
const { prefixCls, children, pending } = this.props;
|
|
|
|
const pendingNode = typeof pending === 'boolean' ? null : pending;
|
|
|
|
const className = classNames({
|
|
|
|
[prefixCls]: true,
|
|
|
|
[prefixCls + '-pending']: !!pending,
|
|
|
|
});
|
2015-09-01 11:47:12 +08:00
|
|
|
return (
|
2016-01-14 16:43:48 +08:00
|
|
|
<ul className={className}>
|
|
|
|
{
|
|
|
|
React.Children.map(children, (ele, idx) =>
|
|
|
|
React.cloneElement(ele, {
|
|
|
|
last: idx === children.length - 1,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
{(!!pending)
|
|
|
|
? <TimelineItem pending={!!pending}>{pendingNode}</TimelineItem>
|
|
|
|
: null}
|
|
|
|
</ul>
|
2015-09-01 11:47:12 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-14 16:43:48 +08:00
|
|
|
Timeline.Item = TimelineItem;
|
|
|
|
|
2015-09-01 21:15:31 +08:00
|
|
|
export default Timeline;
|