ant-design/components/timeline/Timeline.tsx

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-09-21 11:54:53 +08:00
import React from 'react';
2016-03-31 17:46:35 +08:00
import classNames from 'classnames';
import TimelineItem from './TimelineItem';
2016-06-22 13:18:43 +08:00
import splitObject from '../_util/splitObject';
2016-07-09 10:53:40 +08:00
export interface TimelineProps {
2016-07-13 11:14:24 +08:00
/** 指定最后一个幽灵节点是否存在或内容 */
pending?: boolean | React.ReactNode;
style?: React.CSSProperties;
2016-07-09 10:53:40 +08:00
}
2016-07-13 17:22:23 +08:00
2016-07-09 10:53:40 +08:00
export default class Timeline extends React.Component<TimelineProps, any> {
2016-08-24 16:09:55 +08:00
static Item: React.ReactNode;
2016-03-31 17:46:35 +08:00
static defaultProps = {
prefixCls: 'ant-timeline',
2016-07-13 11:14:24 +08:00
};
2016-03-31 17:46:35 +08:00
render() {
2016-06-22 13:18:43 +08:00
const [{
2016-07-13 17:22:23 +08:00
prefixCls, children, pending, className,
2016-07-09 10:53:40 +08:00
}, 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
});
const items = React.Children.map(children, (ele: React.ReactElement<any>, idx) =>
React.cloneElement(ele, {
last: idx === children.length - 1,
})
);
const pendingItem = (!!pending) ? (
<TimelineItem pending={!!pending}>{pendingNode}</TimelineItem>
) : null;
2016-03-31 17:46:35 +08:00
return (
2016-04-18 16:17:16 +08:00
<ul {...restProps} className={classString}>
{items}
{pendingItem}
2016-03-31 17:46:35 +08:00
</ul>
);
}
}