Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Angular 8+ wrapper for Tippy.js

License

NotificationsYou must be signed in to change notification settings

xidedix/ngx-tippy-wrapper

 
 

Repository files navigation

Logo

Angular wrapper for Tippy.js

Angular 8+ wrapper forTippy.js

Demo

Example applicationhere

Code playgroundcodesandbox/ngx-tippy-wrapper

Installation

Install from npm:

npmingx-tippy-wrapper--save

Importing

ImportNgxTippyModule:

import{NgxTippyModule}from'ngx-tippy-wrapper';

Then in your base module:

@NgModule({imports:[        ...,NgxTippyModule],    ...})

Import base style file to your main style file:

@import'tippy.js/dist/tippy.css';

or angular.json:

"architect":{"build":{  ...,"options":{    ...,"styles":[...,"./node_modules/tippy.js/dist/tippy.css"]}

Using

Basic usage

ApplyngxTippy directive for element and pass content throughdata-tippy-content attribute:

<buttonngxTippydata-tippy-content="Tooltip content">  Element with tooltip</button>

Applying props

You can apply props withtippyProps binding

In template:

<buttonngxTippydata-tippy-content="Tooltip content"class="t-demo__btn"[tippyProps]="{    arrow: false,    placement: 'bottom'  }">  Element with tooltip</button>

Or passprops from component:

<spanngxTippydata-tippy-content="Tooltip content"[tippyProps]="tippyProps">  Element with tooltip</span>

...import{NgxTippyProps}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit{tippyProps:NgxTippyProps={trigger:'click',allowHTML:true,};  ...}

Implemented props

Prop nameTypeExample
tippyPropsNgxTippyProps[tippyProps]="{ arrow: false, placement: 'bottom' }"
tippyNamestringtippyName="awesomeName"
tippyClassNamestringtippyClassName="new-class"
or
tippyClassName="new-class another-class"

tippyProps -list of all props

tippyName - name for tippy instance, required for accessing and control specific instance

tippyClassName - add custom class to thetippy-box element, support multiple classes passed as words separated by space

Applying content

You can pass content for tooltip through:

  1. data attribute:
<buttonngxTippydata-tippy-content="Tooltip content">  Element with tooltip</button>

...import{NgxTippyProps}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit{bindedContent:string='Binded tooltip content';  ...}

Content binding works during componentinitialization, if new content should be set dynamic or reset again - usesetContent() method

  1. content prop :
<buttonngxTippy[tippyProps]="{    allowHTML: true,    content: '<p>Tooltip <strong>HTML</strong> content</p>'  }">  Element with tooltip</button>
  1. setContent() method :

For this methodtippyName prop should be setted

<buttonngxTippytippyName="content">  Element with tooltip</button>

...import{NgxTippyService}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit,AfterViewInit{bindedContent:string='Binded tooltip content';constructor(privatetippyService:NgxTippyService){}  ...ngAfterViewInit(){this.setContentForTooltip();}setContentForTooltip(){this.tippyService.setContent('content',this.bindedContent);}}
  1. tippyProps:
<buttonngxTippy[tippyProps]="tippyProps">  Element with tooltip</button>

...@Component({ ...})exportclassDemoComponentimplementsOnInit{tippyProps:NgxTippyProps={ ...}  ...ngOnInit(){this.setContentForTooltip();}setContentForTooltip(){this.tippyProps.content='Initial tooltip content'}}
  1. template:
  • Pass template reference directly
<button[ngxTippy]="tippyTemplate"tippyName="content"[tippyProps]="tippyContent">  Element with tooltip</button><div#tippyTemplate><h4>Caption</h4><p>Some content</p><button(click)="...">Action</button>  ...</div>
  • Passelement orelement.innerHTML
<div><buttonngxTippytippyName="content"[tippyProps]="tippyProps">    Element with tooltip</button><!-- If passing element itself --><div#tippyTemplate><h4>Caption</h4><p>Some content</p><button(click)="...">Action</button>    ...</div><!-- If passing element innerHTML --><div#tippyTemplatestyle="display: none;"><h4>Caption</h4><p>Some content</p>    ...</div></div>

...import{NgxTippyProps}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsAfterViewInit{  @ViewChild('tippyTemplate',{read:ElementRef,static:false})tippyTemplate:ElementRef;tippyContent:NgxTippyProps={ ...};constructor(privatengxTippyService:NgxTippyService){}ngAfterViewInit(){this.setContentForTooltip();}setContentForTooltip(){consttemplate=this.tippyTemplate.nativeElement;// Pass element itselfthis.ngxTippyService.setContent('content',template);// or// Pass element innerHTMLthis.ngxTippyService.setContent('content',template.innerHTML);}  ...}

Methods

For accessing and control specific tippy instance you need passtippyName prop

Import and provideNgxTippyService:

...import{NgxTippyService}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit{constructor(privatetippyService:NgxTippyService){}  ...}

Through service you can use all methods describedhere and some additional

Implemented methods

Get instance(s)

Method nameMethod parameter/parametersMethod short description
getInstance()name: stringGet specific instance
getInstances()-Get all tippy instances

Instance methods

Method nameMethod parameter/parametersMethod short description
show()name: stringProgrammatically show the tippy
hide()name: stringProgrammatically hide the tippy
hideWithInteractivity()name: string,mouseEvent: MouseEventWill hide the tippy only if the cursor is outside of the tippy's interactive region
disable()name: stringTemporarily prevent a tippy from showing or hiding
enable()name: stringRe-enable a tippy
setProps()name: string,tippyProps: NgxTippyPropsSet/update any tippy props
setContent()name: string,tippyContent: NgxTippyContentSet/update the content
setTriggerTarget()name: string,triggerTarget: Element | Element[]Set/update the trigger source
unmount()name: stringUnmount the tippy from the DOM
clearDelayTimeouts()name: stringClears the instances delay timeouts
destroy()name: stringPermanently destroy and clean up the tippy instance

Static methods

Method nameMethod parameter/parametersMethod short description
setDefaultProps()tippyProps: NgxTippyPropsSet the default props for each new tippy instance
showAll()-Show all tippies
hideAll()options?: NgxHideAllOptionsHide all tippies or hide all except a particular one, additional hide them with duration

Available subscription to changes of tippy instances

It provides information in format:

{  name:string;  reason:InstanceChangeReason;  instance:NgxTippyInstance;}typeInstanceChangeReason=|'setInstance'|'show'|'hide'|'hideWithInteractivity'|'disable'|'enable'|'setProps'|'setContent'|'setTriggerTarget'|'unmount'|'clearDelayTimeouts'|'destroy';
...import{Subscription}from'rxjs';import{NgxTippyService}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit,OnDestroy{privateinstancesChanges$:Subscription;constructor(privatetippyService:NgxTippyService){}ngOnInit(){this.subToInstancesChanges();}ngOnDestroy(){this.instancesChanges$&&this.instancesChanges$.unsubscribe();}subToInstancesChanges(){this.instancesChanges$=this.ngxTippyService.instancesChanges.subscribe((changes:InstancesChanges)=>{ ...});}  ...}

Grouped tooltips

If you want to give different tooltip content to many different elements, while only needing to initialize once with shared props usengx-tippy-group component:

<ngx-tippy-group[tippyProps]="tippyProps"><buttondata-groupeddata-tippy-content="Tooltip content">Element with tooltip</button><buttondata-groupeddata-tippy-content="Tooltip content">Element with tooltip</button></ngx-tippy-group>

For each grouped tooltip you should passdata-grouped attribute

Also content can be binded and shared props overridden (seecustomization):

<ngx-tippy-group[tippyProps]="tippyProps"><buttondata-grouped[attr.data-tippy-content]="bindedContent">    Element with tooltip</button><buttondata-grouped[attr.data-tippy-content]="bindedHTMLContent"data-tippy-allowHTML="true">    Element with tooltip</button><buttondata-groupeddata-tippy-content="Tooltip content"data-tippy-arrow="false">    Element with tooltip</button></ngx-tippy-group>

...import{NgxTippyProps}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit{bindedContent:string='Binded tooltip content';bindedHTMLContent:string='<p>Binded <strong>HTML</strong> content</p>';tippyProps:NgxTippyProps={ ...};  ...}

Multiple tooltips on a single element

For using multiple tooltips on a single element - nest elements with appliedngxTippy directive:

<divngxTippydata-tippy-content="First tooltip content"[tippyProps]="{ ... }"><divngxTippydata-tippy-content="Second tooltip content"[tippyProps]="{ ... }"><buttonclass="t-demo__btn"ngxTippydata-tippy-content="Third tooltip content"[tippyProps]="{ ... }">      Element with tooltips</button></div></div>

Singleton

Forsingleton using - put in tooltips insidengx-tippy-singleton component:

<ngx-tippy-singleton[tippyProps]="{ ... }"><buttondata-singletondata-tippy-content="First tooltip content">    Element with tooltip</button><buttondata-singletondata-tippy-content="First tooltip content">    Element with tooltip</button></ngx-tippy-singleton>

To overrides generaltippyProps by the individual tippyprops:

<ngx-tippy-singleton[tippyProps]="{ ... }"><buttondata-singletondata-tippy-content="First tooltip content"data-tippy-placement="bottom">    Element with tooltip</button><buttondata-singletondata-tippy-content="First tooltip content"data-tippy-arrow="false">    Element with tooltip</button></ngx-tippy-singleton>

...import{NgxSingletonProps}from'ngx-tippy-wrapper';@Component({ ...})exportclassDemoComponentimplementsOnInit{tippyProps:NgxSingletonProps={    ...,overrides:['arrow','placement'],};  ...}

Documentation for v1.0.1

About

Angular 8+ wrapper for Tippy.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript64.4%
  • HTML19.6%
  • JavaScript11.6%
  • CSS4.4%

[8]ページ先頭

©2009-2025 Movatter.jp