1
1
import * as React from 'react' ;
2
2
import { useRef } from 'react' ;
3
3
import classNames from 'classnames' ;
4
- import CSSMotion from 'rc-motion' ;
4
+ import CSSMotion from '@ rc-component/ motion' ;
5
5
import { offset } from '../../util' ;
6
- import type { PanelProps , ContentRef } from './Panel' ;
6
+ import type { PanelProps , PanelRef } from './Panel' ;
7
7
import Panel from './Panel' ;
8
+ import type { CSSMotionRef } from '@rc-component/motion/es/CSSMotion' ;
9
+
10
+ export type CSSMotionStateRef = Pick < CSSMotionRef , 'inMotion' | 'enableMotion' > ;
11
+
12
+ export type ContentRef = PanelRef & CSSMotionStateRef ;
8
13
9
14
export type ContentProps = {
10
15
motionName : string ;
@@ -27,7 +32,20 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
27
32
mousePosition,
28
33
} = props ;
29
34
30
- const dialogRef = useRef < HTMLDivElement > ( ) ;
35
+ const dialogRef = useRef <
36
+ {
37
+ nativeElement : HTMLElement ;
38
+ } & CSSMotionStateRef
39
+ > ( ) ;
40
+
41
+ const panelRef = useRef < PanelRef > ( ) ;
42
+
43
+ // ============================== Refs ==============================
44
+ React . useImperativeHandle ( ref , ( ) => ( {
45
+ ...panelRef . current ,
46
+ inMotion : dialogRef . current . inMotion ,
47
+ enableMotion : dialogRef . current . enableMotion ,
48
+ } ) ) ;
31
49
32
50
// ============================= Style ==============================
33
51
const [ transformOrigin , setTransformOrigin ] = React . useState < string > ( ) ;
@@ -38,7 +56,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
38
56
}
39
57
40
58
function onPrepare ( ) {
41
- const elementOffset = offset ( dialogRef . current ) ;
59
+ const elementOffset = offset ( dialogRef . current . nativeElement ) ;
42
60
43
61
setTransformOrigin (
44
62
mousePosition && ( mousePosition . x || mousePosition . y )
@@ -62,7 +80,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
62
80
{ ( { className : motionClassName , style : motionStyle } , motionRef ) => (
63
81
< Panel
64
82
{ ...props }
65
- ref = { ref }
83
+ ref = { panelRef }
66
84
title = { title }
67
85
ariaId = { ariaId }
68
86
prefixCls = { prefixCls }
0 commit comments