ToastTransition.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // @ts-ignore Currently there is no types for semi-animation-react
  2. import { Transition } from '@douyinfe/semi-animation-react';
  3. import { Motion } from '../_base/base';
  4. import React, { CSSProperties } from 'react';
  5. export interface ToastTransitionProps{
  6. motion?: Motion<ToastTransitionProps>;
  7. children?: React.ReactNode | ((TransitionProps: any) => any)
  8. }
  9. export default function ToastTransition(props: ToastTransitionProps = {}) {
  10. let { motion = {} } = props;
  11. if (typeof motion === 'function') {
  12. motion = motion(props);
  13. } else if (!motion || typeof motion !== 'object') {
  14. motion = {};
  15. }
  16. return (
  17. <Transition
  18. // onFrame={style => console.log(style)}
  19. from={{ translateY: -100, opacity: 0 }}
  20. enter={{ translateY: { val: 0, tension: 560, friction: 32 }, opacity: { val: 1, duration: 300 } } as any}
  21. leave={{
  22. translateY: { val: -100, easing: 'easeOutCubic', duration: 300 },
  23. opacity: { val: 0, duration: 200 },
  24. } as any}
  25. {...motion}
  26. >
  27. {typeof props.children === 'function' ?
  28. ({ translateY, opacity }: { translateY: string | number; opacity: string | number }) =>
  29. (props.children as
  30. (styles: { transform: CSSProperties['transform']; opacity: string | number }) => any)({
  31. transform: `translateY(${translateY}%)`,
  32. opacity,
  33. }) :
  34. props.children}
  35. </Transition>
  36. );
  37. }