1
0

ModalTransition.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // @ts-ignore Temporarily do not proceed the action package ts
  2. import { Transition } from '@douyinfe/semi-animation-react';
  3. import React, { JSXElementConstructor, ReactChildren } from 'react';
  4. import { Motion } from '../_base/base';
  5. interface ContentTransitionProps {
  6. // eslint-disable-next-line max-len
  7. motion?: Motion<ContentTransitionProps>;
  8. children?: ReactChildren | JSXElementConstructor<any>;
  9. controlled?: boolean;
  10. visible?: boolean;
  11. }
  12. export default function ContentTransition(props: ContentTransitionProps = {}) {
  13. const { motion: motionFromProps, children, controlled, visible } = props;
  14. let motion = motionFromProps;
  15. let extra = {};
  16. if (typeof motion === 'function') {
  17. motion = motion(props);
  18. } else if (!motion || typeof motion !== 'object') {
  19. motion = {};
  20. }
  21. if (controlled) {
  22. extra = {
  23. // immediate: true,
  24. state: visible ? 'enter' : 'leave',
  25. };
  26. }
  27. return (
  28. <Transition
  29. config={{ tension: 600, friction: 30 } as any}
  30. from={{ scale: 0.7, opacity: { val: 0, duration: 180 } }}
  31. enter={{ scale: { val: 1 }, opacity: { val: 1, duration: 90 } } as any}
  32. leave={{ scale: { val: 0.7 }, opacity: { val: 0, duration: 75 } } as any}
  33. {...extra}
  34. {...motion}
  35. >
  36. {children}
  37. </Transition>
  38. );
  39. }