@duyvu-fsdev/ng-tooltip-directive
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

Getting started with ng-tooltip-directive

Overview

ng-tooltip-directive is a versatile and customizable tooltip library designed for Angular and Ionic/Angular applications

Features

  • Dynamic positioning: Automatically adjusts when overflowing screen boundaries.
  • Customizable styles: Modify tooltip styles using CSS variables or custom classes.
  • Seamless integration: Easily integrates with Angular and Ionic frameworks (angular).

Installation

To install the library, run the following command:

npm install @duyvu-fsdev/ng-tooltip-directive

If you encounter a dependency conflict with the required version, you can resolve it by:

using the --legacy-peer-deps flag:

npm install @duyvu-fsdev/ng-tooltip-directive --legacy-peer-deps

Usage

1. Import the module

Add TooltipModule to your module:
/* *.module.ts */

import { TooltipModule } from '@duyvu-fsdev/ng-tooltip-directive';

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

export class YourModule {}

2. Add the tooltip to your template

Template Example:
/* *.html */

<host-element tooltip [tooltipOption]="tooltipOption">
  <!-- content -->
</host-element>
TypeScript Example:
// *.ts

import { Option } from '@duyvu-fsdev/ng-tooltip-directive';
...

export class YourComponent {
 ...
 tooltipOption: Option = {
  position: 'bottom',
  text: 'Hello, this is a tooltip!',
  class: 'custom-tooltip'
 };
}
Option Interface
Property Type Default Description Example
position 'top' | 'bottom' | 'left' | 'right'| undefined 'bottom' Position of the tooltip relative to the host 'bottom'
text string '' Tooltip text content 'Tooltip text content'
class string '' CSS class for custom styling 'custom-tooltip'

CSS Configuration

1. Customize the variables to apply to all tooltips in the application

/* global.scss */

.app-tooltip {
  --tooltip-background: #fff;
  --tooltip-color: #000;
  --tooltip-border-radius: 4px;
  --tooltip-padding: 8px;
  --tooltip-max-width: 200px;
  --tooltip-height: auto;
}

2. Customize for an individual tooltip using a custom class - e.g., "custom-tooltip"

tooltipOption: Option = {
 ...
 class: 'custom-tooltip' /* Custom class for styling */
};
/* global.scss */

.app-tooltip.custom-tooltip {
  --tooltip-background: #fff;
  --tooltip-color: #000;
  --tooltip-border-radius: 4px;
  --tooltip-padding: 8px;
  --tooltip-max-width: 200px;
  --tooltip-height: auto;
}
You can also apply other custom styles using a custom class
/* global.scss */

.custom-tooltip {
  background: #f00 !important;
  color: #fff !important;
  padding: 10px !important;
  border-radius: 8px !important;
}
Additionally, to avoid cases where the tooltip may not display correctly for elements like span, h1, etc., you should set box-sizing for the host-element.
.host-element-css {
  box-sizing: border-box;
}

Or set box-sizing for all elements in your project (recommended):

/* global.scss */

* {
  box-sizing: border-box;
}

Demo

Demo on stackblitz

Demo

Version

1.0.1 - Update Usage

1.1.0 - Fix styles, Update Usage

1.1.1 - Update demo 1.1.1 - Update demo

License

MIT

Author

Developed and maintained by duyvu-fsdev

Package Sidebar

Install

npm i @duyvu-fsdev/ng-tooltip-directive

Weekly Downloads

113

Version

1.1.2

License

MIT

Unpacked Size

115 kB

Total Files

16

Last publish

Collaborators

  • duyvu.fsdev