Browse Source

refactor(theme-shared): improve modal ux performance

pull/1574/head
mehmet-erim 7 years ago
parent
commit
19e671eac1
  1. 2
      npm/ng-packs/packages/theme-shared/src/lib/components/modal/README.md
  2. 25
      npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts
  3. 4
      npm/ng-packs/packages/theme-shared/src/lib/contants/styles.ts

2
npm/ng-packs/packages/theme-shared/src/lib/components/modal/README.md

@ -3,7 +3,7 @@
Example Usage: Example Usage:
```html ```html
<abp-modal size="lg" [(visible)]="isModalShow" [centered]="true"> <abp-modal size="md" [(visible)]="isModalShow" [centered]="false">
<ng-template #abpHeader> <ng-template #abpHeader>
<h3>Modal Title</h3> <h3>Modal Title</h3>
</ng-template> </ng-template>

25
npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts

@ -17,6 +17,8 @@ import { Toaster } from '../../models/toaster';
export type ModalSize = 'sm' | 'md' | 'lg' | 'xl'; export type ModalSize = 'sm' | 'md' | 'lg' | 'xl';
const ANIMATION_TIMEOUT = 200;
@Component({ @Component({
selector: 'abp-modal', selector: 'abp-modal',
templateUrl: './modal.component.html', templateUrl: './modal.component.html',
@ -30,10 +32,12 @@ export class ModalComponent implements OnDestroy {
if (typeof value !== 'boolean') return; if (typeof value !== 'boolean') return;
if (!this.modalContent) { if (!this.modalContent) {
setTimeout(() => { if (value) {
this.showModal = value; setTimeout(() => {
this.visible = value; this.showModal = value;
}, 0); this.visible = value;
}, 0);
}
return; return;
} }
@ -47,7 +51,7 @@ export class ModalComponent implements OnDestroy {
this.setVisible(value); this.setVisible(value);
// this.renderer.removeClass(this.modalContent.nativeElement, 'fade-out-top'); // this.renderer.removeClass(this.modalContent.nativeElement, 'fade-out-top');
this.ngOnDestroy(); this.ngOnDestroy();
}, 350); }, ANIMATION_TIMEOUT - 10);
} }
} }
@ -91,7 +95,7 @@ export class ModalComponent implements OnDestroy {
this.showModal = value; this.showModal = value;
value value
? timer(500) ? timer(ANIMATION_TIMEOUT + 100)
.pipe(take(1)) .pipe(take(1))
.subscribe(_ => (this.closable = true)) .subscribe(_ => (this.closable = true))
: (this.closable = false); : (this.closable = false);
@ -100,7 +104,7 @@ export class ModalComponent implements OnDestroy {
listen() { listen() {
fromEvent(document, 'click') fromEvent(document, 'click')
.pipe( .pipe(
debounceTime(350), debounceTime(100),
takeUntil(this.destroy$), takeUntil(this.destroy$),
filter((event: MouseEvent) => { filter((event: MouseEvent) => {
const isOpenConfirmation = this.isOpenConfirmation || document.querySelector('p-toastitem'); const isOpenConfirmation = this.isOpenConfirmation || document.querySelector('p-toastitem');
@ -120,8 +124,8 @@ export class ModalComponent implements OnDestroy {
fromEvent(document, 'keyup') fromEvent(document, 'keyup')
.pipe( .pipe(
takeUntil(this.destroy$), takeUntil(this.destroy$),
debounceTime(250),
filter((key: KeyboardEvent) => key && key.code === 'Escape' && this.closable), filter((key: KeyboardEvent) => key && key.code === 'Escape' && this.closable),
debounceTime(350),
) )
.subscribe(_ => { .subscribe(_ => {
this.close(); this.close();
@ -133,7 +137,6 @@ export class ModalComponent implements OnDestroy {
.pipe( .pipe(
takeUntil(this.destroy$), takeUntil(this.destroy$),
filter(() => !!(this.closable && this.modalContent)), filter(() => !!(this.closable && this.modalContent)),
debounceTime(350),
) )
.subscribe(() => this.close()); .subscribe(() => this.close());
} }
@ -150,7 +153,7 @@ export class ModalComponent implements OnDestroy {
this.confirmationService this.confirmationService
.warn('AbpAccount::AreYouSureYouWantToCancelEditingWarningMessage', 'AbpAccount::AreYouSure') .warn('AbpAccount::AreYouSureYouWantToCancelEditingWarningMessage', 'AbpAccount::AreYouSure')
.subscribe((status: Toaster.Status) => { .subscribe((status: Toaster.Status) => {
timer(400).subscribe(() => { timer(ANIMATION_TIMEOUT).subscribe(() => {
this.isOpenConfirmation = false; this.isOpenConfirmation = false;
}); });
@ -166,7 +169,7 @@ export class ModalComponent implements OnDestroy {
function getFlatNodes(nodes: NodeList): HTMLElement[] { function getFlatNodes(nodes: NodeList): HTMLElement[] {
return Array.from(nodes).reduce( return Array.from(nodes).reduce(
(acc, val) => [...acc, ...(val.childNodes && val.childNodes.length ? Array.from(val.childNodes) : [val])], (acc, val) => [...acc, ...(val.childNodes && val.childNodes.length ? getFlatNodes(val.childNodes) : [val])],
[], [],
); );
} }

4
npm/ng-packs/packages/theme-shared/src/lib/contants/styles.ts

@ -38,11 +38,11 @@ export default `
/* <animations */ /* <animations */
.fade-in-top { .fade-in-top {
animation: fadeInTop 0.4s ease-in-out; animation: fadeInTop 0.2s ease-in-out;
} }
.fade-out-top { .fade-out-top {
animation: fadeOutTop 0.4s ease-in-out; animation: fadeOutTop 0.2s ease-in-out;
} }

Loading…
Cancel
Save