Skip to content

Commit

Permalink
add none trigger and improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrankel committed Sep 5, 2017
1 parent 1a2cc44 commit 92964a6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,44 @@ constructor(private elem: ElementRef) {
PopperController.baseOptions.disableAnimation = true;
}
```

| Options | Type | Default |
|:------------------- |:---------------- |:-------- |
| disableAnimation | boolean | false |
| disableDefaultStyling | boolean | false |
| placement | Placement(string) | auto |
| boundariesElement | string(selector) | undefined|
| trigger | Trigger(string) | hover |
| popperModifiers | popperModifier | undefined|


7. popperPlacement:

| 'top'
| 'bottom'
| 'left'
| 'right'
| 'top-start'
| 'bottom-start'
| 'left-start'
| 'right-start'
| 'top-end'
| 'bottom-end'
| 'left-end'
| 'right-end'
| 'auto'
| 'auto-top'
| 'auto-bottom'
| 'auto-left'
| 'auto-right'
| Function

8. popperTrigger:
| 'click'
| 'mousedown'
| 'hover';
| 'none';


### Demo
<a href="https://mrfrankel.github.io/ngx-popper/">Demo</a>
Expand Down
10 changes: 6 additions & 4 deletions src/popper.model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export type Trigger =
| 'click'
| 'mousedown'
| 'hover';
| 'hover'
| 'none' ;

export class Triggers {
static Click: Trigger = 'click';
static Hover: Trigger = 'hover';
static MouseDown: Trigger = 'mousedown';
static CLICK: Trigger = 'click';
static HOVER: Trigger = 'hover';
static MOUSEDOWN: Trigger = 'mousedown';
static NONE: Trigger = 'none';
}

export type Placement =
Expand Down
18 changes: 12 additions & 6 deletions src/popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class PopperController implements OnInit, OnChanges {
private scheduledShowTimeout: any;
private scheduledHideTimeout: any;
private ignoreDocClick: boolean = false;
private subscriptions: any[] = [];

constructor(private viewContainerRef: ViewContainerRef,
private resolver: ComponentFactoryResolver) {
Expand Down Expand Up @@ -72,7 +73,7 @@ export class PopperController implements OnInit, OnChanges {

@HostListener('click', ['$event'])
showOrHideOnClick($event: MouseEvent): void {
if (this.disabled || this.showTrigger !== Triggers.Click) {
if (this.disabled || this.showTrigger !== Triggers.CLICK) {
return;
}
this.ignoreDocClick = true;
Expand All @@ -81,7 +82,7 @@ export class PopperController implements OnInit, OnChanges {

@HostListener('mousedown', ['$event'])
showOrHideOnMouseOver($event: MouseEvent): void {
if (this.disabled || this.showTrigger !== Triggers.MouseDown) {
if (this.disabled || this.showTrigger !== Triggers.MOUSEDOWN) {
return;
}
this.ignoreDocClick = true;
Expand All @@ -90,7 +91,7 @@ export class PopperController implements OnInit, OnChanges {

@HostListener('mouseenter')
showOnHover(): void {
if (this.disabled || this.showTrigger !== Triggers.Hover) {
if (this.disabled || this.showTrigger !== Triggers.HOVER) {
return;
}
this.scheduledShow();
Expand All @@ -102,15 +103,15 @@ export class PopperController implements OnInit, OnChanges {
this.ignoreDocClick = false;
return;
}
if (this.disabled || this.showTrigger !== Triggers.Click) {
if (this.disabled || this.showTrigger !== Triggers.CLICK) {
return;
}
this.scheduledHide($event, 0);
}

@HostListener('mouseleave', ['$event'])
hideOnLeave($event: MouseEvent): void {
if (this.disabled || this.showTrigger !== Triggers.Hover) {
if (this.disabled || this.showTrigger !== Triggers.HOVER) {
return;
}
this.scheduledHide($event, 0);
Expand Down Expand Up @@ -151,6 +152,11 @@ export class PopperController implements OnInit, OnChanges {
}
}

ngOnDestroy(){
this.subscriptions.forEach(sub => sub.unsubscribe && sub.unsubscribe());
this.subscriptions.length = 0;
}

toggle() {
this.shown ? this.hide() : this.scheduledShow();
}
Expand Down Expand Up @@ -235,7 +241,7 @@ export class PopperController implements OnInit, OnChanges {
trigger: this.showTrigger,
popperModifiers: this.popperModifiers,
});
popperRef.onHidden.subscribe(this.hide.bind(this));
this.subscriptions.push(popperRef.onHidden.subscribe(this.hide.bind(this)));
if (this.hideTimeout > 0)
setTimeout(this.hide.bind(this), this.hideTimeout);
}
Expand Down

0 comments on commit 92964a6

Please sign in to comment.