mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-04 00:49:39 +08:00
c4b8c9df93
* refactor: genStyleHooks * chore: update sciprt * refactor: affix * refactor: select * chore: update * refactor: update * refactor: update * refactor: done * chore: code clean * chore: code clean * chore: fix lint * chore: decrease size limit * chore: code clean * chore: code clean * chore: remove export
70 lines
2.0 KiB
TypeScript
70 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 useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
|
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('Timeline');
|
|
|
|
warning.deprecated(!children, 'Timeline.Item', 'items');
|
|
}
|
|
|
|
// Style
|
|
const rootCls = useCSSVarCls(prefixCls);
|
|
const [wrapCSSVar, hashId] = useStyle(prefixCls, rootCls);
|
|
|
|
const mergedItems: TimelineItemProps[] = useItems(items, children);
|
|
|
|
return wrapCSSVar(
|
|
<TimelineItemList
|
|
{...restProps}
|
|
className={classNames(timeline?.className, className, rootCls)}
|
|
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;
|