11import * as React from 'react' ;
22import { useRef } from 'react' ;
33import classNames from 'classnames' ;
4- import CSSMotion from 'rc-motion' ;
4+ import CSSMotion from '@ rc-component/ motion' ;
55import { offset } from '../../util' ;
6- import type { PanelProps , ContentRef } from './Panel' ;
6+ import type { PanelProps , PanelRef } from './Panel' ;
77import 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 ;
813
914export type ContentProps = {
1015 motionName : string ;
@@ -27,7 +32,20 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
2732 mousePosition,
2833 } = props ;
2934
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+ } ) ) ;
3149
3250 // ============================= Style ==============================
3351 const [ transformOrigin , setTransformOrigin ] = React . useState < string > ( ) ;
@@ -38,7 +56,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
3856 }
3957
4058 function onPrepare ( ) {
41- const elementOffset = offset ( dialogRef . current ) ;
59+ const elementOffset = offset ( dialogRef . current . nativeElement ) ;
4260
4361 setTransformOrigin (
4462 mousePosition && ( mousePosition . x || mousePosition . y )
@@ -62,7 +80,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
6280 { ( { className : motionClassName , style : motionStyle } , motionRef ) => (
6381 < Panel
6482 { ...props }
65- ref = { ref }
83+ ref = { panelRef }
6684 title = { title }
6785 ariaId = { ariaId }
6886 prefixCls = { prefixCls }
0 commit comments