type: fix Modal styles typing (#49055)

This commit is contained in:
afc163 2024-05-24 13:49:45 +08:00 committed by GitHub
parent 86abdb9918
commit 9db0fc7440
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 20 deletions

View File

@ -4,8 +4,28 @@ import Modal from '..';
describe('Modal.typescript', () => {
it('Modal.okType', () => {
const form = <Modal okType="danger" />;
const modal = <Modal okType="danger" />;
expect(form).toBeTruthy();
expect(modal).toBeTruthy();
});
it('Modal.styles', () => {
const style: React.CSSProperties = {
position: 'absolute',
};
const modal = (
<Modal
styles={{
header: style,
body: style,
footer: style,
mask: style,
wrapper: style,
content: style,
}}
/>
);
expect(modal).toBeTruthy();
});
});

View File

@ -32,16 +32,14 @@ const BlockModal = (props: ModalProps) => {
<Modal
getContainer={() => divRef.current!}
{...props}
styles={
{
styles={{
mask: {
position: 'absolute',
},
wrapper: {
position: 'absolute',
},
} as any
}
}}
style={{
top: '50%',
transform: 'translateY(-50%)',

View File

@ -5,13 +5,12 @@ import type { ClosableType } from '../_util/hooks/useClosable';
import type { ButtonProps, LegacyButtonType } from '../button/button';
import type { DirectionType } from '../config-provider';
export type ModalFooterRender = (
originNode: React.ReactNode,
extra: { OkBtn: FC; CancelBtn: FC },
) => React.ReactNode;
interface ModalCommonProps {
styles?: Omit<NonNullable<DialogProps['styles']>, 'wrapper'>;
interface ModalCommonProps extends Omit<DialogProps, 'footer'> {
footer?:
| React.ReactNode
| ((originNode: React.ReactNode, extra: { OkBtn: FC; CancelBtn: FC }) => React.ReactNode);
}
export interface ModalProps extends ModalCommonProps {
/** Whether the modal dialog is visible or not */
open?: boolean;
@ -32,8 +31,6 @@ export interface ModalProps extends ModalCommonProps {
centered?: boolean;
/** Width of the modal dialog */
width?: string | number;
/** Footer content */
footer?: ModalFooterRender | React.ReactNode;
/** Text of the OK button */
okText?: React.ReactNode;
/** Button `type` of the OK button */