Skip to content

An angular wrapper for popper.js, great for tooltips and positioning popping elements

License

Notifications You must be signed in to change notification settings

alexandremoore/ngx-popper

 
 

Repository files navigation

ngx-popper

npm npm MIT licensed Stable Release Size Stable Release Size

ngx-popper is an angular wrapper for the Popper.js library.

Installation

node and npm are required to run this package.

  1. Use npm/yarn to install the package:
$ npm install ngx-popper --save 

Or

 $ yarn add ngx-popper --save 
  1. You simply add into your module NgxPopperModule:
import {NgxPopperModule} from 'ngx-popper';

@NgModule({
 // ...
 imports: [
   // ...
   NgxPopperModule
 ]
})

SystemJS

    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'libs/'
        },
        // map tells the System loader where to look for things
        map: {
            ... ,
            'ngx-popper': 'npm:ngx-popper',
            'popper-directive.js': 'npm:ngx-popper',
            'popper.module': 'npm:ngx-popper',
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            ... ,
            'ngx-popper': {
                main: 'index.js',
                defaultExtension: 'js'
            },
            'popper.js': {
                main: 'popper-directive.js',
                defaultExtension: 'js'
            },
            'popper.module': {
                main: './popper.module.js',
                defaultExtension: 'js'
            }
        }
    });

  1. Add to view:
 <div     [popper]="popper1Content"
          [popperShowOnStart]="true"
          [popperTrigger]="'click'"
          [popperPlacement]="'bottom'">
       <p class="bold">Hey!</p>
       <p class="thin">Choose where to put your popper!</p>         
     </div>
     <popper-content #popper1Content>
       <p class="bold">Popper on bottom</p>
     </popper-content>
  1. As text:
     <div [popper]="'As text'"
          [popperTrigger]="'hover'"
          [popperPlacement]="'bottom'"
          (popperOnShown)="onShown($event)">
       <p class="bold">Pop</p>
       <p class="thin">on the bottom</p>
     </div>
     <div popper="{{someTextProperty}}"
          [popperTrigger]="'hover'"
          [popperPlacement]="'bottom'"
          (popperOnShown)="onShown($event)">
       <p class="bold">Pop</p>
       <p class="thin">on the bottom</p>
     </div>
  1. Position fixed, breaking overflow:
     <div [popper]="'As text'"
          [popperTrigger]="'hover'"
          [popperPlacement]="'bottom'"
          [popperPositionFixed]="true"
          (popperOnShown)="onShown($event)">
     </div>
  1. Specific target:
<div class="example">
     <div #popperTargetElement></div>
     <div [popper]="'As text'"
          [popperTrigger]="'hover'"
          [popperPlacement]="'bottom'"
          [popperTarget]="popperTargetElement"
          (popperOnShown)="onShown($event)">
     </div>
  1. hide/show programmatically:
 <div [popper]="tooltipcontent"
         [popperTrigger]="'hover'"
         [popperPlacement]="'bottom'">
         [popperApplyClass]="'popperSpecialStyle'"
      <p class="bold">Pop</p>
      <p class="thin">on the bottom</p>
    </div>
    <popper-content #tooltipcontent>
      <div>
        <p>This is a tooltip with text</p>
        <span (click)="tooltipcontent.hide()">Close</div>
      </div>
    </popper-content>
  1. Attributes map:

    Option Type Default Description
    popperDisableAnimation boolean false Disable the default animation on show/hide
    popperDisableStyle boolean false Disable the default styling
    popperDisabled boolean false Disable the popper, ignore all events
    popperDelay number 0 Delay time until popper it shown
    popperTimeout number 0 Set delay before the popper is hidden
    popperTimeoutAfterShow number 0 Set a time on which the popper will be hidden after it is shown
    popperPlacement Placement(string) auto The placement to show the popper relative to the reference element
    popperTarget HtmlElement auto Specify a different reference element other the the one hosting the directive
    popperBoundaries string(selector) undefined Specify a selector to serve as the boundaries of the element
    popperShowOnStart boolean false Popper default to show
    popperTrigger Trigger(string) hover Trigger/Event on which to show/hide the popper
    popperPositionFixed boolean false Set the popper element to use position: fixed
    popperHideOnClickOutside boolean true Popper will hide on a click outside
    popperHideOnScroll boolean false Popper will hide on scroll
    popperHideOnMouseLeave boolean false Popper will hide on mouse leave
    popperForceDetection boolean false Force the popper to trigger detection event, in case the parent component use onPush strategy
    popperModifiers popperModifier undefined popper.js custom modifiers hock
    popperApplyClass string undefined list of comma separated class to apply on ngpx__container
    popperApplyArrowClass string undefined list of comma separated class to apply on ngpx__arrow
    popperOnShown EventEmitter $event Event handler when popper is shown
    popperOnHidden EventEmitter $event Event handler when popper is hidden
    popperAriaDescribeBy string undefined Define value for aria-describeby attribute
    popperAriaRole string popper Define value for aria-role attribute
  2. Override defaults:

    Ngx-popper comes with a few default properties you can override in default to effect all instances These are overridden by any child attributes.

NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    NgxPopperModule.forRoot({placement: 'bottom'})],
  declarations: [AppComponent],
  providers: [],
  bootstrap: [AppComponent]

})
Options Type Default
showDelay               number           0      
disableAnimation boolean false
disableDefaultStyling boolean false
placement Placement(string) auto
boundariesElement string(selector) undefined
trigger Trigger(string) hover
popperModifiers popperModifier undefined
positionFixed boolean false
hideOnClickOutside boolean true
hideOnMouseLeave boolean false
hideOnScroll boolean false
applyClass string undefined
applyArrowClass string undefined
ariaDescribeBy string undefined
ariaRole string undefined
  1. 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

  1. popperTrigger:

| 'click' | 'mousedown' | 'hover' | 'none'

Demo

Demo

Contribute

Hell ya!!!

  $ yarn install
  $ yarn run build
  $ yarn run dev  

About

An angular wrapper for popper.js, great for tooltips and positioning popping elements

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.1%
  • Other 0.9%