2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2016-03-31 17:46:35 +08:00
|
|
|
import classNames from 'classnames';
|
2019-08-05 18:38:10 +08:00
|
|
|
import omit from 'omit.js';
|
2020-05-02 18:55:56 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2016-07-09 10:53:40 +08:00
|
|
|
|
|
|
|
export interface TimeLineItemProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
2016-07-13 11:14:24 +08:00
|
|
|
color?: string;
|
|
|
|
dot?: React.ReactNode;
|
2016-08-22 17:26:14 +08:00
|
|
|
pending?: boolean;
|
2019-04-27 18:18:49 +08:00
|
|
|
position?: string;
|
2016-07-13 11:14:24 +08:00
|
|
|
style?: React.CSSProperties;
|
2020-02-26 17:21:44 +08:00
|
|
|
label?: React.ReactNode;
|
2016-07-09 10:53:40 +08:00
|
|
|
}
|
2016-07-13 11:14:24 +08:00
|
|
|
|
2020-05-02 18:55:56 +08:00
|
|
|
const TimelineItem: React.FC<TimeLineItemProps> = props => {
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
className,
|
|
|
|
color,
|
|
|
|
children,
|
|
|
|
pending,
|
|
|
|
dot,
|
|
|
|
label,
|
|
|
|
...restProps
|
|
|
|
} = props;
|
2016-03-31 17:46:35 +08:00
|
|
|
|
2020-05-02 18:55:56 +08:00
|
|
|
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
|
|
|
|
const itemClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-item`]: true,
|
|
|
|
[`${prefixCls}-item-pending`]: pending,
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
2016-05-07 02:13:08 +08:00
|
|
|
|
2020-05-02 18:55:56 +08:00
|
|
|
const dotClassName = classNames({
|
|
|
|
[`${prefixCls}-item-head`]: true,
|
|
|
|
[`${prefixCls}-item-head-custom`]: dot,
|
|
|
|
[`${prefixCls}-item-head-${color}`]: true,
|
|
|
|
});
|
2016-05-07 02:13:08 +08:00
|
|
|
|
2020-05-02 18:55:56 +08:00
|
|
|
return (
|
|
|
|
<li {...omit(restProps, ['position'])} className={itemClassName}>
|
|
|
|
{label && <div className={`${prefixCls}-item-label`}>{label}</div>}
|
|
|
|
<div className={`${prefixCls}-item-tail`} />
|
|
|
|
<div
|
|
|
|
className={dotClassName}
|
|
|
|
style={{ borderColor: /blue|red|green|gray/.test(color || '') ? undefined : color }}
|
|
|
|
>
|
|
|
|
{dot}
|
|
|
|
</div>
|
|
|
|
<div className={`${prefixCls}-item-content`}>{children}</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
};
|
2016-05-07 02:13:08 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
TimelineItem.defaultProps = {
|
|
|
|
color: 'blue',
|
|
|
|
pending: false,
|
2019-04-27 18:18:49 +08:00
|
|
|
position: '',
|
2018-12-05 19:12:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default TimelineItem;
|