Skip to content

fix(modal): improve modal's size #452

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

Merged
merged 4 commits into from
Sep 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modal/__tests__/__snapshots__/modal.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`Test Modal Component Should Match snapshot 1`] = `
aria-modal="true"
class="ant-modal dt-modal"
role="dialog"
style="width: 640px;"
style="width: 520px;"
>
<div
aria-hidden="true"
Expand Down
10 changes: 9 additions & 1 deletion src/modal/__tests__/modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Test Modal Component', () => {
test
</Modal>
);
expect(modal.query(container)?.style.width).toBe('640px');
expect(modal.query(container)?.style.width).toBe('520px');

// small size
rerender(
Expand All @@ -36,6 +36,14 @@ describe('Test Modal Component', () => {
);
expect(modal.query(container)?.style.width).toBe('400px');

// middle size
rerender(
<Modal visible title="title" getContainer={false} size="middle">
test
</Modal>
);
expect(modal.query(container)?.style.width).toBe('640px');

// large size
rerender(
<Modal visible title="title" getContainer={false} size="large">
Expand Down
5 changes: 3 additions & 2 deletions src/modal/components/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { omit } from 'lodash';
import './index.scss';

export interface IModalProps extends ModalProps {
size?: 'small' | 'default' | 'large';
size?: 'small' | 'default' | 'middle' | 'large';
banner?: AlertProps['message'] | Omit<AlertProps, 'banner'>;
}

const getWidthFromSize = (size: IModalProps['size']) => {
if (size === 'small') return 400;
if (size === 'middle') return 640;
if (size === 'large') return 900;
return 640;
return 520;
};

const isValidBanner = (banner: IModalProps['banner']): banner is AlertProps['message'] => {
Expand Down
11 changes: 10 additions & 1 deletion src/modal/demos/basic/size.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ export default function Size() {
setSize('default');
}}
>
正常尺寸
默认尺寸
</Button>
<Button
type="primary"
onClick={() => {
setVisible(true);
setSize('middle');
}}
>
中等尺寸
</Button>
<Button
type="primary"
Expand Down
8 changes: 4 additions & 4 deletions src/modal/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ toc: content

[AlertProps](https://4x-ant-design.antgroup.com/components/alert-cn/#API)

| 参数 | 说明 | 类型 | 默认值 |
| ------ | ---- | --------------------------------- | --------- |
| size | 尺寸 | `'small' \| 'default' \| 'large'` | `default` |
| banner | 提示 | `React.ReactNode \| AlertProps` | |
| 参数 | 说明 | 类型 | 默认值 |
| ------ | ---- | --------------------------------------------- | --------- |
| size | 尺寸 | `'small' \| 'default' \| 'middle' \| 'large'` | `default` |
| banner | 提示 | `React.ReactNode \| AlertProps` | |

:::info
其余参数继承 antd4.x 的 [Modal](https://4x.ant.design/components/modal-cn/#API)
Expand Down