11import React from 'react' ;
2- import PropTypes from 'prop-types' ;
32import Portal from '../portal/Portal' ;
43import { classnames } from '../../helpers/component' ;
54
65const CLASSES = {
76 MODAL : 'pm-modal' ,
87 MODAL_OUT : 'pm-modalOut' ,
9- MODAL_SMALL : 'pm-modal--smaller'
8+ MODAL_SMALL : 'pm-modal--smaller' ,
9+ MODAL_WIDE : 'pm-modal--wider' ,
10+ MODAL_FULL : 'pm-modal--full' ,
11+ MODAL_AUTO : 'pm-modal--auto'
1012} ;
1113
12- /** @type any */
14+ export interface Props {
15+ onExit : ( ) => void ;
16+ onClose : ( ) => void ;
17+ children : React . ReactNode ;
18+ modalTitleID : string ;
19+ className ?: string ;
20+ size ?: 'small' | 'wide' | 'full' | 'auto' ;
21+ isBehind ?: boolean ;
22+ isClosing ?: boolean ;
23+ }
24+
1325const Dialog = ( {
1426 onExit,
15- small : isSmall = false ,
27+ size ,
1628 isClosing = false ,
17- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
18- isFirst = false ,
19- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
20- isLast = false ,
2129 isBehind = false ,
2230 modalTitleID,
2331 children,
2432 className : extraClassNames = '' ,
2533 ...rest
26- } ) => {
27- const handleAnimationEnd = ( { animationName } ) => {
28- if ( animationName === CLASSES . MODAL_OUT && isClosing ) {
29- onExit && onExit ( ) ;
34+ } : Props ) => {
35+ const handleAnimationEnd = ( { animationName } : React . AnimationEvent < HTMLDialogElement > ) => {
36+ if ( animationName !== CLASSES . MODAL_OUT ) {
37+ return ;
38+ }
39+ if ( ! isClosing ) {
40+ return ;
41+ }
42+ if ( onExit ) {
43+ onExit ( ) ;
3044 }
3145 } ;
3246
@@ -40,8 +54,14 @@ const Dialog = ({
4054 open
4155 className = { classnames ( [
4256 CLASSES . MODAL ,
43- isSmall && CLASSES . MODAL_SMALL ,
44- isSmall && 'pm-modal--shorterLabels' ,
57+ size &&
58+ {
59+ small : CLASSES . MODAL_SMALL ,
60+ wide : CLASSES . MODAL_WIDE ,
61+ full : CLASSES . MODAL_FULL ,
62+ auto : CLASSES . MODAL_AUTO
63+ } [ size ] ,
64+ size === 'small' && 'pm-modal--shorterLabels' ,
4565 isClosing && CLASSES . MODAL_OUT ,
4666 extraClassNames
4767 ] ) }
@@ -55,17 +75,4 @@ const Dialog = ({
5575 ) ;
5676} ;
5777
58- Dialog . propTypes = {
59- onExit : PropTypes . func . isRequired ,
60- onClose : PropTypes . func . isRequired ,
61- children : PropTypes . node . isRequired ,
62- modalTitleID : PropTypes . string . isRequired ,
63- className : PropTypes . string ,
64- small : PropTypes . bool ,
65- isBehind : PropTypes . bool ,
66- isFirst : PropTypes . bool ,
67- isLast : PropTypes . bool ,
68- isClosing : PropTypes . bool
69- } ;
70-
7178export default Dialog ;
0 commit comments