17.0.0 • Published 1 month ago

ngx-popperjs v17.0.0

Weekly downloads
859
License
MIT
Repository
github
Last release
1 month ago

ngx-popperjs

npm npm MIT licensed Build Status Size

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

Note that I also updated everything to use Popper 2 (v 2.4.4 at this time)

The goal of this library is to take Mr Frankel's ngx-popper and update the compatibility up to Angular 10 (in first instance Angular 8). Since his library is compatible with Angular 7 and downwards, this will start with Angular 8. If you need to work with an older version of Angular (5 to 7), please refer to Mr Frankel's ngx-popper.

Installation

node and npm are required to run this package.

  1. Use npm/yarn to install the package:

    $ npm install @popperjs/core ngx-popperjs --save

    Or

     $ yarn add @popperjs/core --save
     $ yarn add ngx-popperjs --save 
  2. You simply add into your module NgxPopperjsModule:

    import {NgxPopperModule} from 'ngx-popperjs';
    
    @NgModule({
     // ...
     imports: [
       // ...
       NgxPopperjsModule
     ]
    })

SystemJS

    System.config({
        paths: {
           'npm:': 'https://unpkg.com/' // or your local folder
         }
        // map tells the System loader where to look for things
        map: {
            ... ,
            "@popperjs/core": "npm:@popperjs/core@2.4.4/dist/umd/popper.js",
            "ngx-popperjs": "npm:ngx-popperjs@8.0.0/bundles/ngx-popperjs.umd.js
        }
    });

Optionally you can include in your styles.css / styles.css one of the prebuilt themes:

  • @import ~ngx-popperjs/css/theme-dark.css
  • @import ~ngx-popperjs/css/theme-white.css
  • @import ~ngx-popperjs/scss/theme-dark
  • @import ~ngx-popperjs/scss/theme-white

or easily create your own theme using the @mixin

@import ~ngx-popperjs/scss/theme

body {
    @include ngx-popperjs-theme($background-color, $text-color, $max-width, $z-index) 
}
  1. Add to view:

     <popper-content #popper1Content>
         <p class="bold">Popper on bottom</p>
     </popper-content>
     <div [popper]="popper1Content"
          [popperShowOnStart]="true"
          [popperTrigger]="'click'"
          [popperHideOnClickOutside]="true"
          [popperHideOnScroll]="true"
          [popperPlacement]="'bottom'">
         <p class="bold">Hey!</p>
         <p class="thin">Choose where to put your popper!</p>         
     </div>
  2. 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'"
              [popperStyles]="{'background-color: 'blue''}",
              (popperOnShown)="onShown($event)">
           <p class="bold">Pop</p>
           <p class="thin">on the bottom</p>
         </div>
  3. Position fixed, breaking overflow:

         <div popper="As text"
              [popperTrigger]="'hover'"
              [popperPlacement]="'bottom'"
              [popperPositionFixed]="true"
              (popperOnShown)="onShown($event)">
         </div>
  4. Specific target:

    <div class="example">
         <div #popperTargetElement></div>
         <div popper="As text"
              popperTrigger="hover"
              popperPlacement="bottom"
              [popperTarget]="popperTargetElement.nativeElement"
              (popperOnShown)="onShown($event)">
         </div>
  5. 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</span>
          </div>
        </popper-content>
  6. Attributes map:

    OptionTypeDefaultDescription
    popperDisableAnimationbooleanfalseDisable the default animation on show/hide
    popperDisableStylebooleanfalseDisable the default styling
    popperDisabledbooleanfalseDisable the popper, ignore all events
    popperDelaynumber0Delay time until popper it shown
    popperTimeoutnumber0Set delay before the popper is hidden
    popperTimeoutAfterShownumber0Set a time on which the popper will be hidden after it is shown
    popperPlacementPlacement(string)autoThe placement to show the popper relative to the reference element
    popperTargetHtmlElementautoSpecify a different reference element other the the one hosting the directive
    popperBoundariesstring(selector)undefinedSpecify a selector to serve as the boundaries of the element
    popperShowOnStartbooleanfalsePopper default to show
    popperTriggerTrigger(string)hoverTrigger/Event on which to show/hide the popper
    popperPositionFixedbooleanfalseSet the popper element to use position: fixed
    popperAppendTostringundefinedappend The popper-content element to a given selector, if multiple will apply to first
    popperPreventOverflowbooleanundefinedPrevent the popper from being positioned outside the boundary
    popperHideOnClickOutsidebooleantruePopper will hide on a click outside
    popperHideOnScrollbooleanfalsePopper will hide on scroll
    popperHideOnMouseLeavebooleanfalsePopper will hide on mouse leave
    popperModifierspopperModifierundefinedpopper.js custom modifiers hock
    popperApplyClassstringundefinedlist of comma separated class to apply on ngpx__container
    popperStylesObjectundefinedApply the styles object, aligned with ngStyles
    popperApplyArrowClassstringundefinedlist of comma separated class to apply on ngpx__arrow
    popperOnShownEventEmitter<>$eventEvent handler when popper is shown
    popperOnHiddenEventEmitter<>$eventEvent handler when popper is hidden
    popperOnUpdateEventEmitter<>$eventEvent handler when popper is updated
    popperAriaDescribeBystringundefinedDefine value for aria-describeby attribute
    popperAriaRolestringpopperDefine value for aria-role attribute
  1. Override defaults:

    ngx-popperjs 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,
    NgxPopperjsModule.forRoot({placement: 'bottom'})],
  declarations: [AppComponent],
  providers: [],
  bootstrap: [AppComponent]

});
OptionsTypeDefault
showDelay              number          0      
disableAnimationbooleanfalse
disableDefaultStylingbooleanfalse
placementPlacement(string)auto
boundariesElementstring(selector)undefined
triggerTrigger(string)hover
popperModifierspopperModifierundefined
positionFixedbooleanfalse
hideOnClickOutsidebooleantrue
hideOnMouseLeavebooleanfalse
hideOnScrollbooleanfalse
applyClassstringundefined
stylesObjectundefined
applyArrowClassstringundefined
ariaDescribeBystringundefined
ariaRolestringundefined
appendTostringundefined
preventOverflowbooleanundefined
  1. popperPlacement:

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

  2. popperTrigger:

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

Demo

Demo

Contribute

Hell ya!!!

  $ npm install
  $ npm run start  //run example

Thanks to

MrFrankel for setting up ngx-popper and maintaining till v 7.0.0.

16.0.9

1 month ago

16.0.8

1 month ago

17.0.0-rc.1

6 months ago

17.0.0-rc.3

6 months ago

17.0.0-rc.2

6 months ago

12.2.3

7 months ago

12.2.4

7 months ago

16.1.0-beta.0

7 months ago

17.0.0-beta.1

7 months ago

17.0.0-beta.0

7 months ago

16.0.7

7 months ago

17.0.0

6 months ago

14.1.8

9 months ago

13.3.1

9 months ago

13.3.2

9 months ago

14.1.7

9 months ago

12.2.2

9 months ago

15.2.0

12 months ago

15.2.1

11 months ago

15.2.4

9 months ago

15.2.2

9 months ago

16.0.2

9 months ago

16.0.1

11 months ago

16.0.0

11 months ago

16.0.6

9 months ago

16.0.5

9 months ago

16.0.4

9 months ago

16.0.3

9 months ago

15.1.0

1 year ago

14.1.2

2 years ago

14.1.3

1 year ago

14.1.4

1 year ago

14.1.5

1 year ago

14.1.6

1 year ago

15.0.2

1 year ago

15.0.3

1 year ago

15.0.0

1 year ago

15.0.1

1 year ago

15.0.4

1 year ago

14.1.1

2 years ago

13.2.2

2 years ago

13.2.0

2 years ago

13.3.0

2 years ago

14.0.0

2 years ago

13.2.1

2 years ago

14.1.0

2 years ago

14.0.1

2 years ago

14.0.2

2 years ago

13.1.0

2 years ago

13.0.0

2 years ago

13.0.1

2 years ago

12.2.1

2 years ago

12.2.0

2 years ago

12.1.2

3 years ago

12.1.1

3 years ago

12.1.0

3 years ago

12.0.0

3 years ago

11.0.0

3 years ago

9.0.7

3 years ago

9.0.6

3 years ago

10.0.4

3 years ago

9.0.5

3 years ago

10.0.3

3 years ago

9.0.4

3 years ago

9.0.3

3 years ago

10.0.2

3 years ago

9.0.2

3 years ago

10.0.1

3 years ago

8.0.10

3 years ago

8.0.9

3 years ago

8.0.7

3 years ago

10.0.0

3 years ago

9.0.0

4 years ago

8.0.6

4 years ago

8.0.5

4 years ago

8.0.4

4 years ago

8.0.3

4 years ago

8.0.2

4 years ago

8.0.1

4 years ago

8.0.0

4 years ago