Skip to content

Commit

Permalink
feat: 馃幐 add allow close input
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Aug 30, 2020
1 parent f8259c0 commit 236a9dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion projects/ngneat/helipopper/src/lib/helipopper-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const initialHelipopperOptions: Partial<HelipopperOptions> = {
appendTo: document.body,
placement: 'top',
variation: 'tooltip',
disabled: false
disabled: false,
allowClose: true
};

export interface HelipopperOptions {
Expand All @@ -25,4 +26,5 @@ export interface HelipopperOptions {
variation: Variation;
disabled: boolean;
sticky: boolean;
allowClose: boolean;
}
12 changes: 10 additions & 2 deletions projects/ngneat/helipopper/src/lib/helipopper.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class HelipopperDirective implements OnDestroy {
@Input()
helipopperTrigger: string | undefined;

@Input()
helipopperAllowClose: boolean = initialOptions.allowClose;

@Input()
helipopperClass: string | Array<string> | undefined;

Expand Down Expand Up @@ -173,6 +176,10 @@ export class HelipopperDirective implements OnDestroy {
this._destroy.next();
}

destroy() {
this.ngOnDestroy();
}

private destroyView() {
this.tplPortal && this.destroyTemplate();
this.innerComponentRef && this.destroyComponent();
Expand Down Expand Up @@ -202,16 +209,17 @@ export class HelipopperDirective implements OnDestroy {
trigger: this.helipopperTrigger,
placement: this._placement,
triggerTarget: this._tooltipTarget,
hideOnClick: this.helipopperAllowClose,
// TODO: Merge the following methods with the passed config
onCreate: instance => {
this.helipopperClass && addClass(instance.popper, this.helipopperClass);
},
onShow: instance => {
this.zone.run(() => this.instance.setContent(this.resolveContent()));
this.isPopper && this.addCloseButton(instance as InstanceWithClose);
this.helipopperAllowClose && this.isPopper && this.addCloseButton(instance as InstanceWithClose);
},
onHidden: instance => {
this.isPopper && this.removeCloseButton(instance as InstanceWithClose);
this.helipopperAllowClose && this.isPopper && this.removeCloseButton(instance as InstanceWithClose);
this.destroyView();
this.helipopperClose.next();
},
Expand Down
1 change: 1 addition & 0 deletions projects/ngneat/helipopper/src/lib/helipopper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class HelipopperService {
directive.variation = options?.variation || initialOptions.variation;
directive.disabled = options?.disabled || initialOptions.disabled;
directive.sticky = options?.sticky;
directive.helipopperAllowClose = options?.allowClose || initialOptions.allowClose;

directive.whenStable.subscribe(() => directive.show());

Expand Down

0 comments on commit 236a9dc

Please sign in to comment.