npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-simple-tooltip

v2.0.0

Published

This package provides an Angular attribute directive and a service for showing tooltips declaratively or programmatically

Downloads

181

Readme

Angular compatibility

|This library |Angular | |-------------------|-------------| |1.0.0 |^12 | |2.0.0 |<=13.2.0 |

Installation

npm i -S angular-simple-tooltip

Setting up

import { TooltipModule } from 'angular-simple-tooltip';

@Module({
    imports: [
        TooltipModule // Make `TooltipDirective` available in your module
    ]
})
export class YourModule {

}

Accessibility

The tooltip component that gets created handles wiring up aria-describedby attribute for accessability between the tooltip trigger and the tooltip content, so it's completely transparent to you as the API user.

Using TooltipDirective

TooltipModule exports an attribute directive called TooltipDirective that you can apply to any elements in your templates to trigger a tooltip on hover/keyboard navigation (when users focus on the tooltip trigger by pressing the tab key)/long presses on mobile devices. The followings are the @Input properties that TooltipDirective accepts

  • kunTooltip Configures the tooltip's content
  • kunTooltipPlacement Configures tooltip's placement, valid values are top, right, bottom, and left.

Available APIs

class TooltipDirective {

    @Input('kunTooltip')
    content: string;

    @Input('kunTooltipPlacement')
    placement: 'top' | 'right' | 'bottom' | 'left' = 'bottom';

}

Code example

import { Component } from '@angular/core';

@Component({
    selector: 'your-component',
    template: `
        <button
            kunTooltip='Hello World'
            <!-- if "kunTooltipPlacement" is not specified, "bottom" is assumed -->
            kunTooltipPlacement='bottom'>
            Hover over me!!!
        </button>
    `
})
export class YourComponent {

}

Result

Example 1

The tooltip also repositions itself to the top if it overflows the bottom edge of the viewport in case kunTooltipPlacement is bottom, similar behavior also applies for the other placement values Example 2

The tooltip is also displayed when the trigger element receives keyboard focus when the user presses the tab key Example 3

On mobile devices, the user can activate the tooltip by long-pressing the trigger element Example 4

Using TooltipService

This package also exports a service called TooltipService that allows you to show tooltips programmatically.

Available APIs

class TooltipService {

    /**
     * Programmatically show tooltip anchored at the element specified by `target`
     *
     * @param target The element at which to place the tooltip.
     * @param content Tooltip's body's content, it can contain HTML
     * @param placement Where the tooltip should be anchored at, `bottom` is the default
     */
    show(target: HTMLElement | SVGElement, content: string, placement?: 'top' | 'right' | 'bottom' | 'left'): void;

    /**
     * Show tooltip at a specific x/y location
     *
     * @param x The x location
     * @param y The y location
     * @param content Tooltip's body's content, it can contain HTML
     * @param placement Where the tooltip should be anchored at, `bottom` is the default
     */
    showAt(x: number, y: number, content: string, placement?: 'top' | 'right' | 'bottom' | 'left'): void;

    /**
     * Hide the currently active tooltip
     */
    hide(): void;

}

Code example

import { TooltipService } from 'angular-simple-tooltip';

@Component({
    selector: 'your-component',
    template: `
        <button
            type='button'
            (mouseover)='onShowTooltip($event.target)'
            (mouseout)='onHideTooltip()'>
            Hover over me!!!
        </button>
    `
})
export class YourComponent {

    constructor(private readonly _tooltipService: TooltipService) {

    }

    onShowTooltip(target: HTMLButtonElement) {
        this._tooltipService.show(target, 'Hello World');
    }

    onHideTooltip() {
        this._tooltipService.hide();
    }

}

The above example is very contrived, a better use case would be for when you need to manually create many <circle> and <path> SVG elements to render a network of some sort, and you need to display details about each node or edge when you hover over them, in this case, you can use TooltipService APIs to programmatically show/hide tooltips on mouseover/mouseout.