ant-design/components/timeline/Timeline.tsx
二货爱吃白萝卜 5cc338e177
refactor: All the warning set the warning type for future filter (#44613)
* feat: add warningContext

* refactor: part refactor

* chore: fix compile

* chore: part of it

* chore: part of it

* chore: part of it

* chore: fix lint

* chore: fix test

* chore: clean uo

* chore: hide warning def tmp

* chore: comment test

* chore: fix lint

* chore: refactor select icons

* chore: fix warning message

* test: update test

* chore: rm dead code
2023-09-11 17:28:04 +08:00

73 lines
2.0 KiB
TypeScript

import * as React from 'react';
import classNames from 'classnames';
import { devUseWarning } from '../_util/warning';
import { ConfigContext } from '../config-provider';
// CSSINJS
import useStyle from './style';
import type { TimelineItemProps } from './TimelineItem';
import TimelineItem from './TimelineItem';
import TimelineItemList from './TimelineItemList';
import useItems from './useItems';
export interface TimelineProps {
prefixCls?: string;
className?: string;
rootClassName?: string;
/** 指定最后一个幽灵节点是否存在或内容 */
pending?: React.ReactNode;
pendingDot?: React.ReactNode;
style?: React.CSSProperties;
reverse?: boolean;
mode?: 'left' | 'alternate' | 'right';
items?: TimelineItemProps[];
children?: React.ReactNode;
}
type CompoundedComponent = React.FC<TimelineProps> & {
Item: React.FC<TimelineItemProps>;
};
const Timeline: CompoundedComponent = (props) => {
const { getPrefixCls, direction, timeline } = React.useContext(ConfigContext);
const { prefixCls: customizePrefixCls, children, items, className, style, ...restProps } = props;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
// =================== Warning =====================
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning();
warning(
!children,
'Timeline',
'deprecated',
'`Timeline.Item` is deprecated. Please use `items` instead.',
);
}
// Style
const [wrapSSR, hashId] = useStyle(prefixCls);
const mergedItems: TimelineItemProps[] = useItems(items, children);
return wrapSSR(
<TimelineItemList
{...restProps}
className={classNames(timeline?.className, className)}
style={{ ...timeline?.style, ...style }}
prefixCls={prefixCls}
direction={direction}
items={mergedItems}
hashId={hashId}
/>,
);
};
Timeline.Item = TimelineItem;
if (process.env.NODE_ENV !== 'production') {
Timeline.displayName = 'Timeline';
}
export default Timeline;