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-03-18 10:31:25 +08:00
|
|
|
/* Exported as Timeline.Item */
|
|
|
|
class TimelineItem extends React.Component {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
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({
|
2016-02-17 18:04:42 +08:00
|
|
|
[`${prefixCls}-item`]: true,
|
|
|
|
[`${prefixCls}-item-last`]: last,
|
|
|
|
[`${prefixCls}-item-pending`]: pending,
|
2016-01-14 16:43:48 +08:00
|
|
|
});
|
2015-09-01 11:47:12 +08:00
|
|
|
return (
|
2016-01-14 16:43:48 +08:00
|
|
|
<li className={itemClassName}>
|
2016-02-17 18:04:42 +08:00
|
|
|
<div className={`${prefixCls}-item-tail`} />
|
|
|
|
<div className={`${prefixCls}-item-head ${prefixCls}-item-head-${color}`} />
|
|
|
|
<div className={`${prefixCls}-item-content`}>{children}</div>
|
2016-01-14 16:43:48 +08:00
|
|
|
</li>
|
2015-09-01 11:47:12 +08:00
|
|
|
);
|
|
|
|
}
|
2016-03-18 10:31:25 +08:00
|
|
|
}
|
2015-09-01 11:47:12 +08:00
|
|
|
|
2016-03-18 10:31:25 +08:00
|
|
|
export default class Timeline extends React.Component {
|
2016-03-29 14:01:10 +08:00
|
|
|
static Item = TimelineItem;
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-timeline',
|
|
|
|
}
|
|
|
|
|
2015-09-01 11:47:12 +08:00
|
|
|
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,
|
2016-02-17 18:04:42 +08:00
|
|
|
[`${prefixCls}-pending`]: !!pending,
|
2016-01-14 16:43:48 +08:00
|
|
|
});
|
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-03-18 10:31:25 +08:00
|
|
|
}
|