1
1
import React from 'react' ;
2
2
import useOffsetStyle from '../hooks/useOffsetStyle' ;
3
+ import classNames from 'classnames' ;
4
+ import CSSMotion from '@rc-component/motion' ;
5
+ import type { CSSMotionProps } from '@rc-component/motion' ;
3
6
4
7
export interface FloatBgProps {
5
8
prefixCls : string ; // ${prefixCls}-float-bg
@@ -13,6 +16,7 @@ export interface FloatBgProps {
13
16
offsetX : number ;
14
17
offsetY : number ;
15
18
popupSize ?: { width : number ; height : number } ;
19
+ motion ?: CSSMotionProps ;
16
20
}
17
21
18
22
const FloatBg = ( props : FloatBgProps ) => {
@@ -28,11 +32,21 @@ const FloatBg = (props: FloatBgProps) => {
28
32
offsetX,
29
33
offsetY,
30
34
popupSize,
35
+ motion,
31
36
} = props ;
32
37
33
- // Apply className as requested in TODO
34
- const className = `${ prefixCls } -float-bg` ;
38
+ const floatBgCls = `${ prefixCls } -float-bg` ;
35
39
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 =========================
36
50
const offsetStyle = useOffsetStyle (
37
51
isMobile ,
38
52
ready ,
@@ -52,9 +66,40 @@ const FloatBg = (props: FloatBgProps) => {
52
66
}
53
67
54
68
// Remove console.log as it's for debugging only
55
- // console.log('>>>', popupEle );
69
+ // console.log('>>>', ready, open, offsetStyle );
56
70
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
+ ) ;
58
103
} ;
59
104
60
105
export default FloatBg ;
0 commit comments