11import React from 'react' ;
22import useOffsetStyle from '../hooks/useOffsetStyle' ;
3+ import classNames from 'classnames' ;
4+ import CSSMotion from '@rc-component/motion' ;
5+ import type { CSSMotionProps } from '@rc-component/motion' ;
36
47export interface FloatBgProps {
58 prefixCls : string ; // ${prefixCls}-float-bg
@@ -13,6 +16,7 @@ export interface FloatBgProps {
1316 offsetX : number ;
1417 offsetY : number ;
1518 popupSize ?: { width : number ; height : number } ;
19+ motion ?: CSSMotionProps ;
1620}
1721
1822const FloatBg = ( props : FloatBgProps ) => {
@@ -28,11 +32,21 @@ const FloatBg = (props: FloatBgProps) => {
2832 offsetX,
2933 offsetY,
3034 popupSize,
35+ motion,
3136 } = props ;
3237
33- // Apply className as requested in TODO
34- const className = `${ prefixCls } -float-bg` ;
38+ const floatBgCls = `${ prefixCls } -float-bg` ;
3539
40+ // ========================= Ready ==========================
41+ // const [delayReady, setDelayReady] = React.useState(false);
42+
43+ // React.useEffect(() => {
44+ // setDelayReady(ready);
45+ // }, [ready]);
46+
47+ const [ motionVisible , setMotionVisible ] = React . useState ( false ) ;
48+
49+ // ========================= Styles =========================
3650 const offsetStyle = useOffsetStyle (
3751 isMobile ,
3852 ready ,
@@ -52,9 +66,40 @@ const FloatBg = (props: FloatBgProps) => {
5266 }
5367
5468 // Remove console.log as it's for debugging only
55- // console.log('>>>', popupEle );
69+ // console.log('>>>', ready, open, offsetStyle );
5670
57- return < div className = { className } style = { { ...offsetStyle , ...sizeStyle } } /> ;
71+ // ========================= Render =========================
72+ return (
73+ < CSSMotion
74+ motionAppear
75+ motionEnter
76+ motionLeave
77+ removeOnLeave = { false }
78+ leavedClassName = { `${ floatBgCls } -hidden` }
79+ { ...motion }
80+ visible = { open }
81+ onVisibleChanged = { ( nextVisible ) => {
82+ setMotionVisible ( nextVisible ) ;
83+ } }
84+ >
85+ { ( { className : motionClassName , style : motionStyle } ) => {
86+ const cls = classNames ( floatBgCls , motionClassName , {
87+ [ `${ floatBgCls } -visible` ] : motionVisible ,
88+ } ) ;
89+
90+ return (
91+ < div
92+ className = { cls }
93+ style = { {
94+ ...offsetStyle ,
95+ ...sizeStyle ,
96+ ...motionStyle ,
97+ } }
98+ />
99+ ) ;
100+ } }
101+ </ CSSMotion >
102+ ) ;
58103} ;
59104
60105export default FloatBg ;
0 commit comments