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

perf(theme:modal): perf code #1671

Merged
merged 1 commit into from
Oct 22, 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
19 changes: 10 additions & 9 deletions packages/theme/src/services/modal/modal.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { deepMerge } from '@delon/util/other';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { ModalOptions, NzModalService } from 'ng-zorro-antd/modal';

const CLS_DRAG = 'MODAL-DRAG';

export interface ModalHelperOptions {
/** 大小;例如:lg、600、80%,默认:`lg` */
size?: 'sm' | 'md' | 'lg' | 'xl' | '' | number | string;
Expand Down Expand Up @@ -39,7 +41,6 @@ export interface ModalHelperDragOptions {
@Injectable({ providedIn: 'root' })
export class ModalHelper {
private document: Document;
private dragClsPrefix = 'MODAL-DRAG';

constructor(
private srv: NzModalService,
Expand All @@ -54,7 +55,7 @@ export class ModalHelper {
const modalEl = wrapEl.firstChild as HTMLDivElement;
const handelEl = options.handleCls ? wrapEl.querySelector<HTMLDivElement>(options.handleCls) : null;
if (handelEl) {
handelEl.classList.add(`${this.dragClsPrefix}-HANDLE`);
handelEl.classList.add(`${CLS_DRAG}-HANDLE`);
}

return this.drag
Expand Down Expand Up @@ -95,36 +96,36 @@ export class ModalHelper {
);
return new Observable((observer: Observer<NzSafeAny>) => {
const { size, includeTabs, modalOptions, drag, useNzData } = options as ModalHelperOptions;
let cls = '';
let cls: string[] = [];
let width = '';
if (size) {
if (typeof size === 'number') {
width = `${size}px`;
} else if (['sm', 'md', 'lg', 'xl'].includes(size)) {
cls = `modal-${size}`;
cls.push(`modal-${size}`);
} else {
width = size;
}
}
if (includeTabs) {
cls += ' modal-include-tabs';
cls.push(`modal-include-tabs`);
}
if (modalOptions && modalOptions.nzWrapClassName) {
cls += ` ${modalOptions.nzWrapClassName}`;
cls.push(modalOptions.nzWrapClassName);
delete modalOptions.nzWrapClassName;
}
let dragOptions: ModalHelperDragOptions | null;
let dragWrapCls = `${this.dragClsPrefix}-${+new Date()}`;
let dragWrapCls = `${CLS_DRAG}-${+new Date()}`;
let dragRef: DragRef | null;
if (drag != null && drag !== false) {
dragOptions = {
handleCls: `.modal-header, .ant-modal-title`,
...(typeof drag === 'object' ? drag : {})
};
cls += ` ${this.dragClsPrefix} ${dragWrapCls}`;
cls.push(CLS_DRAG, dragWrapCls);
}
const subject = this.srv.create({
nzWrapClassName: cls,
nzWrapClassName: cls.join(' '),
nzContent: comp,
nzWidth: width ? width : undefined,
nzFooter: null,
Expand Down
6 changes: 4 additions & 2 deletions packages/theme/system/antd/_modal.less
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
}
}

.MODAL-DRAG-HANDLE {
cursor: move;
.MODAL-DRAG {
&-HANDLE {
cursor: move;
}
}