@@ -2,80 +2,37 @@ import * as React from 'react';
22import { useRef } from 'react' ;
33import classNames from 'classnames' ;
44import CSSMotion from 'rc-motion' ;
5- import type { IDialogChildProps } from '..' ;
65import { offset } from '../../util' ;
7- import MemoChildren from './MemoChildren' ;
8-
9- const sentinelStyle = { width : 0 , height : 0 , overflow : 'hidden' , outline : 'none' } ;
6+ import type { PanelProps , ContentRef } from './Panel' ;
7+ import Panel from './Panel' ;
108
119export type ContentProps = {
1210 motionName : string ;
1311 ariaId : string ;
1412 onVisibleChanged : ( visible : boolean ) => void ;
15- onMouseDown : React . MouseEventHandler ;
16- onMouseUp : React . MouseEventHandler ;
17- } & IDialogChildProps ;
18-
19- export type ContentRef = {
20- focus : ( ) => void ;
21- changeActive : ( next : boolean ) => void ;
22- } ;
13+ } & PanelProps ;
2314
2415const Content = React . forwardRef < ContentRef , ContentProps > ( ( props , ref ) => {
2516 const {
26- closable,
2717 prefixCls,
28- width,
29- height,
30- footer,
3118 title,
32- closeIcon,
3319 style,
3420 className,
3521 visible,
3622 forceRender,
37- bodyStyle,
38- bodyProps,
39- children,
4023 destroyOnClose,
41- modalRender,
4224 motionName,
4325 ariaId,
44- onClose,
4526 onVisibleChanged,
46- onMouseDown,
47- onMouseUp,
4827 mousePosition,
4928 } = props ;
5029
51- const sentinelStartRef = useRef < HTMLDivElement > ( ) ;
52- const sentinelEndRef = useRef < HTMLDivElement > ( ) ;
5330 const dialogRef = useRef < HTMLDivElement > ( ) ;
5431
55- // ============================== Ref ===============================
56- React . useImperativeHandle ( ref , ( ) => ( {
57- focus : ( ) => {
58- sentinelStartRef . current ?. focus ( ) ;
59- } ,
60- changeActive : ( next ) => {
61- const { activeElement } = document ;
62- if ( next && activeElement === sentinelEndRef . current ) {
63- sentinelStartRef . current . focus ( ) ;
64- } else if ( ! next && activeElement === sentinelStartRef . current ) {
65- sentinelEndRef . current . focus ( ) ;
66- }
67- } ,
68- } ) ) ;
69-
7032 // ============================= Style ==============================
7133 const [ transformOrigin , setTransformOrigin ] = React . useState < string > ( ) ;
7234 const contentStyle : React . CSSProperties = { } ;
73- if ( width !== undefined ) {
74- contentStyle . width = width ;
75- }
76- if ( height !== undefined ) {
77- contentStyle . height = height ;
78- }
35+
7936 if ( transformOrigin ) {
8037 contentStyle . transformOrigin = transformOrigin ;
8138 }
@@ -91,42 +48,6 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
9148 }
9249
9350 // ============================= Render =============================
94- let footerNode : React . ReactNode ;
95- if ( footer ) {
96- footerNode = < div className = { `${ prefixCls } -footer` } > { footer } </ div > ;
97- }
98-
99- let headerNode : React . ReactNode ;
100- if ( title ) {
101- headerNode = (
102- < div className = { `${ prefixCls } -header` } >
103- < div className = { `${ prefixCls } -title` } id = { ariaId } >
104- { title }
105- </ div >
106- </ div >
107- ) ;
108- }
109-
110- let closer : React . ReactNode ;
111- if ( closable ) {
112- closer = (
113- < button type = "button" onClick = { onClose } aria-label = "Close" className = { `${ prefixCls } -close` } >
114- { closeIcon || < span className = { `${ prefixCls } -close-x` } /> }
115- </ button >
116- ) ;
117- }
118-
119- const content = (
120- < div className = { `${ prefixCls } -content` } >
121- { closer }
122- { headerNode }
123- < div className = { `${ prefixCls } -body` } style = { bodyStyle } { ...bodyProps } >
124- { children }
125- </ div >
126- { footerNode }
127- </ div >
128- ) ;
129-
13051 return (
13152 < CSSMotion
13253 visible = { visible }
@@ -139,23 +60,16 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
13960 ref = { dialogRef }
14061 >
14162 { ( { className : motionClassName , style : motionStyle } , motionRef ) => (
142- < div
143- key = "dialog-element"
144- role = "dialog"
145- aria-labelledby = { title ? ariaId : null }
146- aria-modal = "true"
147- ref = { motionRef }
63+ < Panel
64+ { ...props }
65+ ref = { ref }
66+ title = { title }
67+ ariaId = { ariaId }
68+ prefixCls = { prefixCls }
69+ holderRef = { motionRef }
14870 style = { { ...motionStyle , ...style , ...contentStyle } }
149- className = { classNames ( prefixCls , className , motionClassName ) }
150- onMouseDown = { onMouseDown }
151- onMouseUp = { onMouseUp }
152- >
153- < div tabIndex = { 0 } ref = { sentinelStartRef } style = { sentinelStyle } aria-hidden = "true" />
154- < MemoChildren shouldUpdate = { visible || forceRender } >
155- { modalRender ? modalRender ( content ) : content }
156- </ MemoChildren >
157- < div tabIndex = { 0 } ref = { sentinelEndRef } style = { sentinelStyle } aria-hidden = "true" />
158- </ div >
71+ className = { classNames ( className , motionClassName ) }
72+ />
15973 ) }
16074 </ CSSMotion >
16175 ) ;
0 commit comments