2016-03-31 17:46:35 +08:00
|
|
|
import classNames from 'classnames';
|
2023-05-05 20:52:44 +08:00
|
|
|
import React from 'react';
|
2020-05-02 18:55:56 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-01-10 22:57:09 +08:00
|
|
|
import type { LiteralUnion } from '../_util/type';
|
|
|
|
|
|
|
|
type Color = 'blue' | 'red' | 'green' | 'gray';
|
2016-07-09 10:53:40 +08:00
|
|
|
|
2020-10-03 22:03:09 +08:00
|
|
|
export interface TimelineItemProps {
|
2023-02-07 16:16:48 +08:00
|
|
|
key?: React.Key;
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
2023-01-10 22:57:09 +08:00
|
|
|
color?: LiteralUnion<Color>;
|
2016-07-13 11:14:24 +08:00
|
|
|
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;
|
2022-04-08 22:55:42 +08:00
|
|
|
children?: React.ReactNode;
|
2016-07-09 10:53:40 +08:00
|
|
|
}
|
2016-07-13 11:14:24 +08:00
|
|
|
|
2022-04-08 22:55:42 +08:00
|
|
|
// for compatibility
|
2020-10-03 22:03:09 +08:00
|
|
|
// https://github.com/ant-design/ant-design/pull/26832
|
|
|
|
export interface TimeLineItemProps extends TimelineItemProps {
|
|
|
|
__deprecated_do_not_use_it__?: any; // eslint-disable-line camelcase
|
|
|
|
}
|
|
|
|
|
2020-11-24 20:19:35 +08:00
|
|
|
const TimelineItem: React.FC<TimelineItemProps> = ({
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
className,
|
|
|
|
color = 'blue',
|
|
|
|
dot,
|
|
|
|
pending = false,
|
2020-12-28 15:30:18 +08:00
|
|
|
position /** Dead, but do not pass in <li {...omit()} */,
|
2020-11-24 20:19:35 +08:00
|
|
|
label,
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
}) => {
|
2020-05-02 18:55:56 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
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
|
|
|
|
2023-01-10 22:57:09 +08:00
|
|
|
const customColor = /blue|red|green|gray/.test(color || '') ? undefined : color;
|
|
|
|
|
2020-05-02 18:55:56 +08:00
|
|
|
const dotClassName = classNames({
|
|
|
|
[`${prefixCls}-item-head`]: true,
|
2021-04-02 22:37:36 +08:00
|
|
|
[`${prefixCls}-item-head-custom`]: !!dot,
|
2023-01-10 22:57:09 +08:00
|
|
|
[`${prefixCls}-item-head-${color}`]: !customColor,
|
2020-05-02 18:55:56 +08:00
|
|
|
});
|
2016-05-07 02:13:08 +08:00
|
|
|
|
2020-05-02 18:55:56 +08:00
|
|
|
return (
|
2020-11-24 20:19:35 +08:00
|
|
|
<li {...restProps} className={itemClassName}>
|
2020-05-02 18:55:56 +08:00
|
|
|
{label && <div className={`${prefixCls}-item-label`}>{label}</div>}
|
|
|
|
<div className={`${prefixCls}-item-tail`} />
|
2022-02-08 09:52:00 +08:00
|
|
|
<div className={dotClassName} style={{ borderColor: customColor, color: customColor }}>
|
2020-05-02 18:55:56 +08:00
|
|
|
{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
|
|
|
export default TimelineItem;
|