// @ts-ignore Currently there is no types definition for semi-animation-react; import { Transition } from '@douyinfe/semi-animation-react'; import React, { CSSProperties } from 'react'; import { Motion } from '../_base/base'; export interface SideSheetTransitionProps{ children?: React.ReactChildren | React.JSXElementConstructor; motion?: Motion; controlled?: boolean; visible?: boolean; placement?: 'left' | 'top' | 'right' | 'bottom'; } // eslint-disable-next-line max-len const formatStyles = function formatStyles(styles: CSSProperties = {}, props: SideSheetTransitionProps = {}): CSSProperties { const { placement } = props; const { translate } = styles; const { opacity } = styles; let transform = ''; switch (placement) { case 'left': transform = `translateX(-${translate}%)`; break; case 'top': transform = `translateY(-${translate}%)`; break; case 'right': transform = `translateX(${translate}%)`; break; case 'bottom': transform = `translateY(${translate}%)`; break; default: break; } return { transform, opacity, }; }; export default class SideSheetTransition extends React.PureComponent { render() { let { motion = {} } = this.props; const { children, controlled = false, visible, } = this.props; if (typeof motion === 'function') { motion = motion(this.props); } else if (!motion || typeof motion !== 'object') { motion = {}; } let extra = {}; if (controlled) { extra = { state: visible ? 'enter' : 'leave', }; } return ( {/* eslint-disable-next-line max-len */} {typeof children === 'function' ? (styles: CSSProperties) => (children as (styles: CSSProperties) => any)(formatStyles(styles, this.props)) : children} ); } }