Skip to content

Commit

Permalink
fix for forRoot in AOT, added default options
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrankel committed Jan 16, 2018
1 parent cd1961c commit 2c93f5c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ example
node_modules
/src
/*.*
dist/dist-tsc
dist/example
./dist/dist-tsc
./dist/example
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ NgModule({
| trigger | Trigger(string) | hover |
| popperModifiers | popperModifier | undefined|
| positionFixed | boolean | false |
| hideOnClickOutside | boolean | true |
| hideOnScroll | boolean | false |

9. popperPlacement:

Expand Down
11 changes: 1 addition & 10 deletions example/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[popper]="popper1Content"
[popperTrigger]="'click'"
[popperTarget]="popper1"
[popperCloseOnClickOutside]="false"
[popperShowOnStart]="true"
[popperPlacement]="example1select" class="rel" id="example10reference1">
<p class="bold">Hey!</p>
Expand Down Expand Up @@ -45,9 +44,7 @@
<div class="rel" id="example2reference1"
#popper2
[popper]="popper2Content"
[popperShowOnStart]="true"
[popperCloseOnClickOutside]="false"
[popperTrigger]="'none'">
[popperShowOnStart]="true">
<p class="bold">Scroll me</p>
<p class="thin">up and down</p>
</div>
Expand Down Expand Up @@ -77,8 +74,6 @@ <h2 id="example2" tabindex="0">Popper on scrolling container</h2>
#popper3
[popper]="popper3Content"
[popperShowOnStart]="true"
[popperCloseOnClickOutside]="false"
[popperTrigger]="'none'"
[popperPlacement]="'right'"
[popperBoundaries]="'#example3Container'"
[popperModifiers]="example3modifiers"
Expand Down Expand Up @@ -108,8 +103,6 @@ <h2 id="example3" tabindex="0">Custom flip behavior</h2>
#popper4
[popper]="popper4Content"
[popperShowOnStart]="true"
[popperTrigger]="'none'"
[popperHideOnClickOutside]="false"
[popperPlacement]="'left-start'">
<p class="bold">Reference</p>
</div>
Expand All @@ -132,9 +125,7 @@ <h2 id="example5" tabindex="0">Shifted poppers</h2>
<div class="rel" id="example5reference1"
#popper5
[popper]="popper5Content"
[popperTrigger]="'none'"
[popperShowOnStart]="true"
[popperHideOnClickOutside]="false"
[popperPlacement]="'bottom'">
<p class="bold">Pop</p>
<p class="thin">on the bottom</p>
Expand Down
11 changes: 6 additions & 5 deletions example/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {AppComponent} from './app.component';
import {NgxPopperModule} from '../../dist/ngx-popper.js';
import {testComponent} from './test/test';
import { Draggable } from 'ng2draggable/draggable.directive';
import {NgxPopperModule, Triggers} from '../../dist/ngx-popper.js';
import {Draggable} from 'ng2draggable/draggable.directive';

@NgModule({
imports: [
BrowserModule,
FormsModule,
NgxPopperModule.forRoot({trigger: 'hover'})],
NgxPopperModule.forRoot({
trigger: Triggers.NONE,
hideOnClickOutside: false
})],
declarations: [
testComponent,
Draggable,
AppComponent],
providers: [],
Expand Down
19 changes: 0 additions & 19 deletions example/app/test/test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "ngx-popper",
"version": "1.9.0",
"version": "1.9.4",
"description": "ngx-popper is an angular wrapper for popper.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "",
"build": "ng-packagr -p ng-package.json",
"deploy": "npm run build && standard-version && npm publish --access=public dist",
"deploy": "npm run build && npm publish --access=public dist",
"dev": "webpack-dev-server"
},
"repository": {
Expand Down
20 changes: 12 additions & 8 deletions src/popper-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
OnChanges,
SimpleChange,
Output,
EventEmitter, OnInit, Renderer2, ChangeDetectorRef
EventEmitter, OnInit, Renderer2, ChangeDetectorRef, Inject
} from '@angular/core';
import {PopperContent} from './popper-content';
import {Placement, Placements, PopperContentOptions, Trigger, Triggers} from './popper.model';
Expand All @@ -30,10 +30,12 @@ export class PopperController implements OnInit, OnChanges {
constructor(private viewContainerRef: ViewContainerRef,
private changeDetectorRef: ChangeDetectorRef,
private resolver: ComponentFactoryResolver,
private renderer: Renderer2) {
private renderer: Renderer2,
@Inject('popperDefaults') private popperDefaults: PopperContentOptions) {
PopperController.baseOptions = {...this.popperDefaults, ...PopperController.baseOptions}
}

static baseOptions: PopperContentOptions = <PopperContentOptions>{};
public static baseOptions: PopperContentOptions = <PopperContentOptions>{};

@Input('popper')
content: string | PopperContent;
Expand All @@ -45,7 +47,7 @@ export class PopperController implements OnInit, OnChanges {
placement: Placement = Placements.Auto;

@Input('popperTrigger')
showTrigger: Trigger;
showTrigger: Trigger | undefined;

@Input('popperTarget')
targetElement: HTMLElement;
Expand All @@ -66,13 +68,13 @@ export class PopperController implements OnInit, OnChanges {
showOnStart: boolean;

@Input('popperCloseOnClickOutside')
closeOnClickOutside: boolean = true;
closeOnClickOutside: boolean;

@Input('popperHideOnClickOutside')
hideOnClickOutside: boolean;
hideOnClickOutside: boolean | undefined;

@Input('popperHideOnScroll')
hideOnScroll: boolean = false;
hideOnScroll: boolean | undefined;

@Input('popperPositionFixed')
positionFixed: boolean;
Expand Down Expand Up @@ -267,7 +269,9 @@ export class PopperController implements OnInit, OnChanges {
}

private setDefaults(){
this.showTrigger = this.showTrigger || PopperController.baseOptions.trigger;
this.showTrigger = typeof this.showTrigger === 'undefined' ? PopperController.baseOptions.trigger : this.showTrigger;
this.hideOnClickOutside = typeof this.hideOnClickOutside === 'undefined' ? PopperController.baseOptions.hideOnClickOutside : this.hideOnClickOutside;
this.hideOnScroll = typeof this.hideOnScroll === 'undefined' ? PopperController.baseOptions.hideOnScroll : this.hideOnScroll;
}

private clearEventListeners() {
Expand Down
2 changes: 2 additions & 0 deletions src/popper.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ export interface PopperContentOptions {
boundariesElement?: string;
trigger?: Trigger;
positionFixed?: boolean;
hideOnClickOutside?: boolean;
hideOnScroll?: boolean;
popperModifiers?: {};
}
5 changes: 2 additions & 3 deletions src/popper.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {PopperContentOptions} from './popper.model';
})
export class NgxPopperModule {
ngDoBootstrap(){}
public static forRoot(popperBaseOptions?: PopperContentOptions): ModuleWithProviders {
PopperController.baseOptions = Object.assign(PopperController.baseOptions, popperBaseOptions || {});
return {ngModule: NgxPopperModule, providers: []};
public static forRoot(popperBaseOptions: PopperContentOptions = {}): ModuleWithProviders {
return {ngModule: NgxPopperModule, providers: [{provide: 'popperDefaults', useValue: popperBaseOptions}]};
}
}

0 comments on commit 2c93f5c

Please sign in to comment.