0.3.15 • Published 4 years ago

@teamhive/ngx-tooltip v0.3.15

Weekly downloads
295
License
MIT
Repository
-
Last release
4 years ago

NgxTooltip

Built on top of Tippy.js

Install

npm i @teamhive/ngx-tooltip

Getting Started

example.module.ts

⋮
import { NgModule } from '@angular/core';
import { TooltipModule, TooltipOptions } from '@teamhive/ngx-tooltip';

@NgModule({
    ⋮
    imports: [
        TooltipModule.forRoot({
            // custom defaults go here e.g.
            placement: 'top',
            arrow: 'true',
            arrowType: 'sharp',
            allowHTML: true,
            maxWidth: 200
        } as TooltipOptions)
    ]
    ⋮
})
export class ExampleModule { }

Usage

Basic

example.component.html

<div ngxTooltip tooltipContent="Lorem ipsum dolor…"> … </div>

HTML Content

⚠️   you should almost certainly santitize any html you didn't make yourself!

example.component.ts

import { TooltipContent } from '@teamhive/ngx-tooltip';
⋮
tooltipElement: TooltipContent;
⋮
ngOnInit() {
    this.tooltipElement = document.getElementById('tooltip-template');
    ⋮
}
⋮

example.component.html

<div ngxTooltip [tooltipAllowHtml]="true" tooltipContent="<span> … </span>"> … </div>

<!-- or -->

<span id="tooltip-template"> … </span>
<div ngxTooltip [tooltipAllowHtml]="true" [tooltipContent]="templateElement"> … </div>

<!-- or, best yet (Yay for template reference variables!!!!) -->

<span #tooltipTemplate> … </span>
<div ngxTooltip [tooltipAllowHtml]="true" [tooltipContent]="tooltipTemplate"> … </div>

Specify Options

example.component.ts

import { TooltipOptions } from '@teamhive/ngx-tooltip';
⋮
tooltipOptions: TooltipOptions = {
    placement: 'top',
    arrow: 'true',
    arrowType: 'sharp',
    allowHTML: true,
    content: '<span …> … </span>'
};
⋮

example.component.html

<div [ngxTooltip]="{content: 'Lorem ipsum dolor…', maxWidth: 200 …}"> … </div>

<!-- or -->

<div [ngxTooltip]="tooltipOptions"> … </div>

TooltipService

example.component.ts

import { TooltipService } from '@teamhive/ngx-tooltip';
⋮
constructor(tooltipService: TooltipService) {}
⋮
forceCloseAll() {
    tooltipService.hideAll();
}
⋮
methoddescriptionreturn type
hideAll()Hides each TooltipInstancevoid
showAll()Shows each TooltipInstancevoid
enableAll()Enables each TooltipInstance except those without content to prevent empty tooltips from being displayed.void
disableAll()Disables each TooltipInstancevoid
destroyAll()Destroys each TooltipInstancevoid
getGroup()Returns group TooltipInstance collectionMap<string | number, TooltipInstance>

Properties

Some commonly used options are made available through element properties. see full list of options.

propertydescriptiontype
ngxTooltipall options can be passed via the directive itselfTooltipOptions
tooltipGroupspecifies a group collection the tooltip should belong to. Actions can be applied to an entire group via the TooltipService. This property is custom to NgxTooltip and does not have a tippy.js equivalent.string | number
tooltipContentThe content of the tooltip. Along with a string or element, you can use a function that takes the reference element as an argument and returns content.TooltipContent string | Element | ((ref: Element) => Element | string)
tooltipPlacementPositions the tippy relative to its reference element. Use the suffix '-start' or '-end' to shift the tippy to the start or end of the reference element, instead of centering it. For example, top-start or left-end.TooltipPlacement 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end'
tooltipAnimationThe type of transition animation.TooltipAnimation'shift-away' | 'shift-toward' | 'fade' | 'scale' | 'perspective'
tooltipTriggerThe events (each separated by a space) which cause a tippy to show. Possible values: "mouseenter", "focus", "click", "manual". Use "manual" to only trigger the tippy programmatically.string
tooltipTouchDetermines if tooltip works on touch devicesboolean
tooltipTouchHoldDetermines trigger behavior on touch devices. Instead of a tap on the reference to show and a tap elsewhere to hide the tippy, the reference must be pressed and held for the tippy to show. Letting go from the screen will hide it.boolean
tooltipArrowTypeDetermines the arrow type. Using this property automatically enables the arrow optionTooltipArrowType'sharp' | 'round'
tooltipMaxWidthDetermines the maximum width of the tippy - use a number for pixels, or a string to add units such as rem. In CSS, it's defined as 350px by default. This option applies the width to the style attribute of the tippy element.number | string
tooltipThemeThemes added as classes (each separated by a space) to the ngx-tooltip element's.string
tooltipAllowHtmlDetermines if the tooltip can have HTML content rendered inside of it.boolean

Additional properties

cannot be set via Element properties

propertydescriptiontype
idtooltip instance unique numeric id.number
stateobject defining the sate of tooltip instanceTooltipState
groupoptional tooltip instance group idstring | number

Methods

Some commonly used options are made available through element properties.

methoddescriptionreturn type
hide()Force hides tooltip.void
show()Force shows tooltip even if disabled.void
enable()Force enables tooltip, unless it is without content, to prevent empty tooltips from being displayed.void
disable()Force disables tooltip.void
destroy()Force destroys tooltip.void

Theming

@teamhive/ngx-tooltip makes use of css variables for theming.

When you pass a theme name via TooltipModule.forRoot{}, ngxTooltip, or tooltipTheme - a css class is attached to the tooltip elements so they can be targeted for styling.

CSS Variables

VariableDescription
--tooltip-colorFull CSS color property.
--tooltip-arrow-colorColor of arrow. Used for various properties necessary to properly & uniformly color arrow. It is highly recommended to keep same as background color.
--tooltip-background-colorFull CSS background-color property.
--tooltip-font-sizeFull CSS font-size property.
--tooltip-font-weightFull CSS font-weight property.
--tooltip-font-styleFulll CSS font-style property.
--tooltip-font-familyFull CSS font-famliy property.
--tooltip-box-shadowFull CSS box-shadow property.
--tooltip-border-radiusFull CSS border-radius property.
--tooltip-text-alignFull CSS text-align property.
--tooltip-paddingFull CSS padding property.

example.scss

// the package styles.css file must be imported to use css variables
@import "@teamhive/ngx-tooltip/assets/styles/styles.css";

// custom styling should be placed in class selector of `${customThemeName}-theme`
.currant-theme {
    --tooltip-color: #9df2a4;               // seafoam
    --tooltip-arrow-color: #463E53;         // blackcurrant
    --tooltip-background-color: #463E53;    // blackcurrant
    --tooltip-font-size: 16px;
    --tooltip-font-weight: 500;
    --tooltip-font-style: normal;
    --tooltip-font-family: "Helvetica Neue", Helvetica, sans-serif;
    --tooltip-box-shadow: 2px 2px 5px grey;
    --tooltip-border-radius: 5px;
    --tooltip-text-align: center;
    --tooltip-padding: 5px;
}

example.component.html

<div ngxTooltip tooltipTheme="currant" tooltipContent="blackcurrant & seafoam"…>
    custom theme
</div>

for advanced theming, see the Tippy.js theming docs.

All Options

options taken from tippy.js docs

Contributors

| :---: |Michael Riess|

0.3.15

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago