diff --git a/src/Dialog/Content/MemoChildren.tsx b/src/Dialog/Content/MemoChildren.tsx index 815d0cec..345402f3 100644 --- a/src/Dialog/Content/MemoChildren.tsx +++ b/src/Dialog/Content/MemoChildren.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; export type MemoChildrenProps = { shouldUpdate: boolean; children: React.ReactNode; -} +}; export default React.memo( ({ children }: MemoChildrenProps) => children as React.ReactElement, diff --git a/src/Dialog/Content/Panel.tsx b/src/Dialog/Content/Panel.tsx index afea6a4f..cb4d1eab 100644 --- a/src/Dialog/Content/Panel.tsx +++ b/src/Dialog/Content/Panel.tsx @@ -81,23 +81,26 @@ const Panel = React.forwardRef((props, ref) => { contentStyle.height = height; } // ================================ Render ================================ - let footerNode: React.ReactNode; - if (footer) { - footerNode =
{footer}
; - } + const footerNode = footer ? ( +
+ {footer} +
+ ) : null; - let headerNode: React.ReactNode; - if (title) { - headerNode = ( -
-
- {title} -
+ const headerNode = title ? ( +
+
+ {title}
- ); - } +
+ ) : null; - const closableObj = useMemo(() => { if (typeof closable === 'object' && closable !== null) { return closable; @@ -106,24 +109,34 @@ const Panel = React.forwardRef((props, ref) => { return { closeIcon: closeIcon ?? }; } return {}; - }, [closable, closeIcon]); + }, [closable, closeIcon, prefixCls]); const ariaProps = pickAttrs(closableObj, true); - - let closer: React.ReactNode; - if (closable) { - closer = ( - - ); - } + + const closerNode = closable ? ( + + ) : null; const content = ( -
- {closer} +
+ {closerNode} {headerNode} -
+
{children}
{footerNode} @@ -137,10 +150,7 @@ const Panel = React.forwardRef((props, ref) => { aria-labelledby={title ? ariaId : null} aria-modal="true" ref={mergedRef} - style={{ - ...style, - ...contentStyle, - }} + style={{ ...style, ...contentStyle }} className={classNames(prefixCls, className)} onMouseDown={onMouseDown} onMouseUp={onMouseUp} diff --git a/src/Dialog/Mask.tsx b/src/Dialog/Mask.tsx index e7ccb847..99f1440b 100644 --- a/src/Dialog/Mask.tsx +++ b/src/Dialog/Mask.tsx @@ -11,9 +11,8 @@ export type MaskProps = { className?: string; }; -export default function Mask(props: MaskProps) { +const Mask: React.FC = (props) => { const { prefixCls, style, visible, maskProps, motionName, className } = props; - return ( ); -} +}; + +export default Mask; diff --git a/src/Dialog/index.tsx b/src/Dialog/index.tsx index 66305d65..65a6fcf3 100644 --- a/src/Dialog/index.tsx +++ b/src/Dialog/index.tsx @@ -12,7 +12,7 @@ import type { ContentRef } from './Content/Panel'; import Mask from './Mask'; import { warning } from 'rc-util/lib/warning'; -export default function Dialog(props: IDialogPropTypes) { +const Dialog: React.FC = (props) => { const { prefixCls = 'rc-dialog', zIndex, @@ -20,7 +20,6 @@ export default function Dialog(props: IDialogPropTypes) { keyboard = true, focusTriggerAfterClose = true, // scrollLocker, - // Wrapper wrapStyle, wrapClassName, @@ -47,12 +46,12 @@ export default function Dialog(props: IDialogPropTypes) { } = props; if (process.env.NODE_ENV !== 'production') { - ["wrapStyle", "bodyStyle", "maskStyle"].forEach((prop) => { + ['wrapStyle', 'bodyStyle', 'maskStyle'].forEach((prop) => { // (prop in props) && console.error(`Warning: ${prop} is deprecated, please use styles instead.`) - warning(!(prop in props), `${prop} is deprecated, please use styles instead.`) + warning(!(prop in props), `${prop} is deprecated, please use styles instead.`); }); - if ("wrapClassName" in props) { - warning(false, `wrapClassName is deprecated, please use classNames instead.`) + if ('wrapClassName' in props) { + warning(false, `wrapClassName is deprecated, please use classNames instead.`); } } @@ -167,6 +166,13 @@ export default function Dialog(props: IDialogPropTypes) { [], ); + const mergedStyle: React.CSSProperties = { + zIndex, + ...wrapStyle, + ...modalStyles?.wrapper, + display: !animatedVisible ? 'none' : null, + }; + // ========================= Render ========================= return (
@@ -191,7 +193,7 @@ export default function Dialog(props: IDialogPropTypes) { className={classNames(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper)} ref={wrapperRef} onClick={onWrapperClick} - style={{ zIndex, ...wrapStyle, ...modalStyles?.wrapper, display: !animatedVisible ? 'none' : null }} + style={mergedStyle} {...wrapProps} >
); -} +}; + +export default Dialog; diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index 9e5e6bc3..7d84fc4d 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -13,7 +13,7 @@ import type { IDialogPropTypes } from './IDialogPropTypes'; * So here should add a child (div element) to custom container. * */ -const DialogWrap: React.FC = (props: IDialogPropTypes) => { +const DialogWrap: React.FC = (props) => { const { visible, getContainer, diff --git a/src/IDialogPropTypes.tsx b/src/IDialogPropTypes.tsx index 2d9bf12c..61ce71d7 100644 --- a/src/IDialogPropTypes.tsx +++ b/src/IDialogPropTypes.tsx @@ -24,7 +24,7 @@ export type IDialogPropTypes = { keyboard?: boolean; style?: CSSProperties; mask?: boolean; - children?: any; + children?: React.ReactNode; afterClose?: () => any; afterOpenChange?: (open: boolean) => void; onClose?: (e: SyntheticEvent) => any;