Skip to content

Commit 0fe2815

Browse files
committed
refactor(Overlay): 替换csstransition
1 parent 8ba6dfb commit 0fe2815

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/packages/overlay/overlay.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, {
55
useRef,
66
useState,
77
} from 'react'
8-
import { CSSTransition } from 'react-transition-group'
8+
import { useSpring, animated } from '@react-spring/web'
99
import classNames from 'classnames'
1010
import { ComponentDefaults } from '@/utils/typings'
1111
import { useLockScroll } from '@/hooks/use-lock-scroll'
@@ -50,7 +50,7 @@ export const Overlay: FunctionComponent<
5050

5151
const shouldLockScroll = !innerVisible ? false : lockScroll
5252
useLockScroll(nodeRef, shouldLockScroll)
53-
const classes = classNames(classPrefix, className)
53+
const classes = classNames(classPrefix, `${classPrefix}-slide`, className)
5454
const styles = {
5555
...style,
5656
zIndex,
@@ -62,26 +62,30 @@ export const Overlay: FunctionComponent<
6262
}
6363
}
6464

65+
const springProps = useSpring({
66+
opacity: innerVisible ? 1 : 0,
67+
config: { duration },
68+
onRest: () => {
69+
if (innerVisible) {
70+
afterShow()
71+
} else {
72+
afterClose()
73+
}
74+
},
75+
})
76+
6577
return (
66-
<CSSTransition
67-
nodeRef={nodeRef}
68-
classNames={`${classPrefix}-slide`}
69-
unmountOnExit
70-
timeout={duration}
71-
in={innerVisible}
72-
onEntered={afterShow}
73-
onExited={afterClose}
74-
>
75-
<div
78+
innerVisible && (
79+
<animated.div
7680
ref={nodeRef}
7781
className={classes}
78-
style={styles}
82+
style={{ ...styles, ...springProps }}
7983
{...rest}
8084
onClick={handleClick}
8185
>
8286
{children}
83-
</div>
84-
</CSSTransition>
87+
</animated.div>
88+
)
8589
)
8690
}
8791

0 commit comments

Comments
 (0)