ant-design/components/timeline/TimelineItem.tsx

69 lines
1.9 KiB
TypeScript
Raw Normal View History

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