From 6b13871f7d13d1c18e0adddd458beb13d3bdc3b0 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Tue, 26 May 2020 09:36:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Modal>Header,=20Title,=20B?= =?UTF-8?q?ody,=20Footer=20=E7=9B=B8=E5=85=B3=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Modal.tsx | 109 +++++++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 11 deletions(-) diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx index ecb17aeca..0a173801d 100644 --- a/src/components/Modal.tsx +++ b/src/components/Modal.tsx @@ -11,11 +11,11 @@ import Transition, { EXITING } from 'react-transition-group/Transition'; import {Portal} from 'react-overlays'; -import cx from 'classnames'; import {current, addModal, removeModal} from './ModalManager'; -import {ClassNamesFn, themeable} from '../theme'; +import {ClassNamesFn, themeable, ThemeProps} from '../theme'; +import {Icon} from './icons'; -export interface ModalProps { +export interface ModalProps extends ThemeProps { className?: string; contentClassName?: string; size?: any; @@ -25,8 +25,6 @@ export interface ModalProps { container?: any; show?: boolean; disabled?: boolean; - classPrefix: string; - classnames: ClassNamesFn; onExited?: () => void; onEntered?: () => void; } @@ -45,6 +43,88 @@ export class Modal extends React.Component { overlay: true }; + static Header = themeable( + ({ + classnames: cx, + className, + showCloseButton, + onClose, + children, + classPrefix, + ...rest + }: ThemeProps & { + className?: string; + showCloseButton?: boolean; + onClose?: () => void; + children?: React.ReactNode; + } & React.HTMLAttributes) => ( +
+ {showCloseButton !== false ? ( + + + + ) : null} + {children} +
+ ) + ); + + static Title = themeable( + ({ + classnames: cx, + className, + children, + classPrefix, + ...rest + }: ThemeProps & { + className?: string; + children?: React.ReactNode; + } & React.HTMLAttributes) => ( +
+ {children} +
+ ) + ); + + static Body = themeable( + ({ + classnames: cx, + className, + children, + classPrefix, + ...rest + }: ThemeProps & { + className?: string; + children?: React.ReactNode; + } & React.HTMLAttributes) => ( +
+ {children} +
+ ) + ); + + static Footer = themeable( + ({ + classnames: cx, + className, + children, + classPrefix, + ...rest + }: ThemeProps & { + className?: string; + children?: React.ReactNode; + } & React.HTMLAttributes) => ( +
+ {children} +
+ ) + ); + componentDidMount() { if (this.props.show) { this.handleEntered(); @@ -90,7 +170,7 @@ export class Modal extends React.Component { show, size, overlay, - classPrefix: ns + classnames: cx } = this.props; return ( @@ -109,19 +189,19 @@ export class Modal extends React.Component { ref={this.modalRef} role="dialog" className={cx( - `amis-dialog-widget ${ns}Modal`, + `amis-dialog-widget Modal`, { - [`${ns}Modal--${size}`]: size + [`Modal--${size}`]: size }, className )} > {overlay ? ( -
+
) : null}
{ } } -export default themeable(Modal); +const themedModal = themeable(Modal); + +export default themedModal as typeof themedModal & { + Header: typeof Modal.Header; + Title: typeof Modal.Title; + Body: typeof Modal.Body; + Footer: typeof Modal.Footer; +};