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(theme:modal): add size support percentage #1626

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 packages/theme/src/services/modal/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Your body content

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| `size` | Specify modal size | `sm,md,lg,xl,number` | `lg` |
| `size` | Specify modal size | `sm,md,lg,xl,number,string` | `lg` |
| `exact` | Exact match return value, default is `true`, If the return value is not null (`null` or `undefined`) is considered successful, otherwise it is considered error. | `boolean` | `true` |
| `includeTabs` | Whether to wrap the tab page | `boolean` | `false` |
| `drag` | Drag | `boolean, ModalHelperDragOptions` | - |
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/services/modal/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Your body content

| 名称 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
| `size` | 指定对话框大小 | `sm,md,lg,xl,number` | `lg` |
| `size` | 指定对话框大小 | `sm,md,lg,xl,number,string` | `lg` |
| `exact` | 是否精准(默认:`true`),若返回值非空值(`null`或`undefined`)视为成功,否则视为错误 | `boolean` | `true` |
| `includeTabs` | 是否包裹标签页 | `boolean` | `false` |
| `drag` | 支持拖动 | `boolean, ModalHelperDragOptions` | - |
Expand Down
16 changes: 9 additions & 7 deletions packages/theme/src/services/modal/modal.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { ModalOptions, NzModalService } from 'ng-zorro-antd/modal';

export interface ModalHelperOptions {
/** 大小;例如:lg、600,默认:`lg` */
size?: 'sm' | 'md' | 'lg' | 'xl' | '' | number;
/** 大小;例如:lg、600、80%,默认:`lg` */
size?: 'sm' | 'md' | 'lg' | 'xl' | '' | number | string;
/** 对话框 [ModalOptions](https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/modal/modal-types.ts) 参数 */
modalOptions?: ModalOptions;
/** 是否精准(默认:`true`),若返回值非空值(`null`或`undefined`)视为成功,否则视为错误 */
Expand Down Expand Up @@ -100,8 +100,10 @@ export class ModalHelper {
if (size) {
if (typeof size === 'number') {
width = `${size}px`;
} else {
} else if (['sm', 'md', 'lg', 'xl'].includes(size)) {
cls = `modal-${size}`;
} else {
width = size;
}
}
if (includeTabs) {
Expand All @@ -121,14 +123,14 @@ export class ModalHelper {
};
cls += ` ${this.dragClsPrefix} ${dragWrapCls}`;
}
const defaultOptions: ModalOptions = {
const subject = this.srv.create({
nzWrapClassName: cls,
nzContent: comp,
nzWidth: width ? width : undefined,
nzFooter: null,
nzData: params
};
const subject = this.srv.create({ ...defaultOptions, ...modalOptions });
nzData: params,
...modalOptions
});
// 保留 nzComponentParams 原有风格,但依然可以通过 @Inject(NZ_MODAL_DATA) 获取
if (useNzData !== true) {
Object.assign(subject.componentInstance, params);
Expand Down
8 changes: 8 additions & 0 deletions packages/theme/src/services/modal/modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ describe('theme: ModalHelper', () => {
tick(1000);
fixture.detectChanges();
}));
it('should be 80% size', fakeAsync(() => {
modal.create(TestModalComponent, { ret: 'true' }, { size: '10%' }).subscribe();
fixture.detectChanges();
tick(1000);
fixture.detectChanges();
const width = document.querySelector<HTMLElement>('.ant-modal')?.style.width;
expect(width).toBe('10%');
}));
});
});

Expand Down