ant-design/components/tabs/hooks/useAnimateConfig.ts
二货爱吃白萝卜 304b36a5bf
refactor: Replace Tabs motion (#36943)
* chore: bump rc-tabs

* refactor: use internal motion

* test: Update snapshot

* chore: clean up

* test: Update snapshot

* test: coverage

* test: resolve conflict
2022-08-08 17:01:25 +08:00

47 lines
1022 B
TypeScript

import type { CSSMotionProps } from 'rc-motion';
import type { AnimatedConfig } from 'rc-tabs/lib/interface';
import type { TabsProps } from '..';
import { getTransitionName } from '../../_util/motion';
const motion: CSSMotionProps = {
motionAppear: false,
motionEnter: true,
motionLeave: true,
};
export default function useAnimateConfig(
prefixCls: string,
animated: TabsProps['animated'] = {
inkBar: true,
tabPane: false,
},
): AnimatedConfig {
let mergedAnimated: AnimatedConfig;
if (animated === false) {
mergedAnimated = {
inkBar: false,
tabPane: false,
};
} else if (animated === true) {
mergedAnimated = {
inkBar: true,
tabPane: false,
};
} else {
mergedAnimated = {
inkBar: true,
...(typeof animated === 'object' ? animated : {}),
};
}
if (mergedAnimated.tabPane) {
mergedAnimated.tabPaneMotion = {
...motion,
motionName: getTransitionName(prefixCls, 'switch'),
};
}
return mergedAnimated;
}