Skip to content

Commit 5a53dd6

Browse files
committed
chore: motion of bg
1 parent 2579ec5 commit 5a53dd6

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

assets/index.less

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@
8181
box-sizing: border-box;
8282
border: 1px solid red;
8383
background: green;
84-
transition: all 0.3s;
84+
85+
&-hidden {
86+
display: none;
87+
}
88+
89+
&-visible {
90+
transition: all 0.3s;
91+
}
8592
}
8693

8794
// Debug

src/UniqueProvider/FloatBg.tsx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
22
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';
36

47
export 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

1822
const 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

60105
export default FloatBg;

src/UniqueProvider/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
182182
offsetX={offsetX}
183183
offsetY={offsetY}
184184
popupSize={popupSize}
185+
motion={options.popupMotion}
185186
/>
186187
</Popup>
187188
</TriggerContext.Provider>

0 commit comments

Comments
 (0)