ant-design/components/timeline/TimelineItem.tsx
骗你是小猫咪 3269d8c387
feat: Timeline.Item support label (#21560)
* feat: Timeline add label

* improve label style with mode

* update snapshot

* use optional chaining

* add doc

* Update label.md

Co-authored-by: 偏右 <afc163@gmail.com>
2020-02-26 17:21:44 +08:00

70 lines
1.8 KiB
TypeScript

import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
export interface TimeLineItemProps {
prefixCls?: string;
className?: string;
color?: string;
dot?: React.ReactNode;
pending?: boolean;
position?: string;
style?: React.CSSProperties;
label?: React.ReactNode;
}
const TimelineItem: React.SFC<TimeLineItemProps> = props => (
<ConfigConsumer>
{({ getPrefixCls }: ConfigConsumerProps) => {
const {
prefixCls: customizePrefixCls,
className,
color = '',
children,
pending,
dot,
label,
...restProps
} = props;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
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 {...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>
);
}}
</ConfigConsumer>
);
TimelineItem.defaultProps = {
color: 'blue',
pending: false,
position: '',
};
export default TimelineItem;