Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add modalRender #195

Merged
merged 4 commits into from Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/Dialog.tsx
Expand Up @@ -233,6 +233,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
bodyProps,
children,
destroyOnClose,
modalRender = modalNode => modalNode,
jhoneybee marked this conversation as resolved.
Show resolved Hide resolved
} = this.props;
const dest: any = {};
if (width !== undefined) {
Expand Down Expand Up @@ -276,6 +277,22 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
);
}

const content = (
<div className={`${prefixCls}-content`}>
{closer}
{headerNode}
<div
className={`${prefixCls}-body`}
style={bodyStyle}
ref={this.saveRef('body')}
{...bodyProps}
>
{children}
</div>
{footerNode}
</div>
)

const styleBox = { ...style, ...dest };
const sentinelStyle = { width: 0, height: 0, overflow: 'hidden', outline: 'none' };
const transitionName = this.getTransitionName();
Expand All @@ -296,19 +313,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
style={sentinelStyle}
aria-hidden="true"
/>
<div className={`${prefixCls}-content`}>
{closer}
{headerNode}
<div
className={`${prefixCls}-body`}
style={bodyStyle}
ref={this.saveRef('body')}
{...bodyProps}
>
{children}
</div>
{footerNode}
</div>
{modalRender(content)}
<div
tabIndex={0}
ref={this.saveRef('sentinelEnd')}
Expand Down
1 change: 1 addition & 0 deletions src/IDialogPropTypes.tsx
Expand Up @@ -37,6 +37,7 @@ export interface IDialogPropTypes {
wrapProps?: any;
getContainer?: IStringOrHtmlElement | (() => IStringOrHtmlElement) | false;
closeIcon?: ReactNode;
modalRender?: (node: ReactNode) => ReactNode;
forceRender?: boolean;
// https://github.com/ant-design/ant-design/issues/19771
// https://github.com/react-component/dialog/issues/95
Expand Down
16 changes: 14 additions & 2 deletions tests/index.spec.js
@@ -1,6 +1,6 @@
/* eslint-disable react/no-render-return-value */
/* eslint-disable func-names */
import React from 'react';
import React, { cloneElement } from 'react';
import { mount } from 'enzyme';

import KeyCode from 'rc-util/lib/KeyCode';
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('dialog', () => {
dialog.unmount();
jest.useRealTimers();
});

jhoneybee marked this conversation as resolved.
Show resolved Hide resolved
it('show', () => {
dialog.setState({ visible: true });
jest.runAllTimers();
Expand Down Expand Up @@ -425,4 +425,16 @@ describe('dialog', () => {
d.update();
expect(d.find('.rc-dialog-wrap').props().style.display).toEqual(null);
});

it('modalRender', () => {
const modalRender = mount(
<DialogWrap modalRender={node => cloneElement(node, { ...node.props, style: { background: '#1890ff' }})}>
</DialogWrap>
);
modalRender.setState({ visible: true });
jest.runAllTimers();
modalRender.update();
expect(modalRender.find('.rc-dialog-content').props().style.background).toEqual('#1890ff');
modalRender.unmount();
});
});