ant-design/components/timeline/Timeline.tsx

37 lines
1.0 KiB
TypeScript
Raw Normal View History

2016-03-31 17:46:35 +08:00
import React from 'react';
import classNames from 'classnames';
import TimelineItem from './TimelineItem';
2016-06-22 13:18:43 +08:00
import splitObject from '../_util/splitObject';
2016-03-31 17:46:35 +08:00
export default class Timeline extends React.Component {
static defaultProps = {
prefixCls: 'ant-timeline',
}
render() {
2016-06-22 13:18:43 +08:00
const [{
prefixCls, children, pending, className
},restProps] = splitObject(this.props,
['prefixCls', 'children', 'pending','className']);
2016-03-31 17:46:35 +08:00
const pendingNode = typeof pending === 'boolean' ? null : pending;
2016-04-18 16:17:16 +08:00
const classString = classNames({
2016-03-31 17:46:35 +08:00
[prefixCls]: true,
[`${prefixCls}-pending`]: !!pending,
2016-04-18 16:17:16 +08:00
[className]: className,
2016-03-31 17:46:35 +08:00
});
return (
2016-04-18 16:17:16 +08:00
<ul {...restProps} className={classString}>
2016-03-31 17:46:35 +08:00
{
React.Children.map(children, (ele, idx) =>
React.cloneElement(ele, {
last: idx === children.length - 1,
})
)
}
{(!!pending)
? <TimelineItem pending={!!pending}>{pendingNode}</TimelineItem>
: null}
</ul>
);
}
}