ant-design/components/timeline/TimelineItem.tsx

64 lines
1.6 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2016-03-31 17:46:35 +08:00
import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } 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;
2016-07-13 11:14:24 +08:00
style?: React.CSSProperties;
2016-07-09 10:53:40 +08:00
}
2016-07-13 11:14:24 +08:00
2018-12-07 20:02:01 +08:00
const TimelineItem: React.SFC<TimeLineItemProps> = props => (
<ConfigConsumer>
{({ getPrefixCls }: ConfigConsumerProps) => {
const {
prefixCls: customizePrefixCls,
2018-12-07 20:02:01 +08:00
className,
color = '',
children,
pending,
dot,
...restProps
} = props;
2016-03-31 17:46:35 +08:00
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
2018-12-07 20:02:01 +08:00
const itemClassName = classNames(
{
[`${prefixCls}-item`]: true,
[`${prefixCls}-item-pending`]: pending,
},
className,
);
const dotClassName = classNames({
[`${prefixCls}-item-head`]: true,
[`${prefixCls}-item-head-custom`]: dot,
[`${prefixCls}-item-head-${color}`]: true,
});
return (
<li {...restProps} className={itemClassName}>
<div className={`${prefixCls}-item-tail`} />
<div
className={dotClassName}
style={{ borderColor: /blue|red|green/.test(color) ? undefined : color }}
>
{dot}
</div>
2018-12-07 20:02:01 +08:00
<div className={`${prefixCls}-item-content`}>{children}</div>
</li>
);
}}
</ConfigConsumer>
);
TimelineItem.defaultProps = {
color: 'blue',
pending: false,
};
export default TimelineItem;