logo dile-components dile-components

dile-tooltip

Here’s an improved version of your explanation:

dile-tooltip is a web component that provides a customizable tooltip interface.

It displays a message in an overlay when the user hovers over an element. You can control the position of the tooltip using the component's properties. Additionally, the dile-tooltip apareance can be fully customized using CSS custom properties.

Installation

npm install @dile/ui

In dile-components you'll also find the dile-chip-tooltip component, which provides a configurable chip interface with an icon that includes a tooltip. It's a quick and convenient way to implement both the tooltip and trigger in a single component.

Usage

Import the component.

import '@dile/ui/components/tooltip/tooltip';

Use the component.

<dile-tooltip tooltip="tooltip text" position="top" arrow fadeIn > Text </dile-tooltip>

Properties

The dile-tooltip component has the properties bellow:

Keyboard Support

Accessibility

The dile-tooltip component is built with accessibility in mind and meets WCAG 2.2 AA standards:

Styling

You can customize the component using CSS Custom Properties. The component accepts both specific tooltip custom properties and generic fallback variables for a consistent design system.

Custom property Description Default
--dile-tooltip-background-color Tooltip background color --dile-primary-color or #e74c3c
--dile-tooltip-color Tooltip text color --dile-on-primary-color or #fff
--dile-tooltip-width The width of the tooltip 120px
--dile-tooltip-border-radius The border radius of the tooltip 6px
--dile-tooltip-padding The padding of the tooltip text 5px
--dile-tooltip-time-transition The time of transition of the animation if fadeIn is true 0.5s
--dile-tooltip-font-size The font size of the tooltip 16px
--dile-tooltip-font-weight The font weight of the tooltip normal
--dile-tooltip-text-align Text align for the tooltip center
--dile-tooltip-focus-outline-width Focus indicator outline width 2px
--dile-tooltip-focus-outline-color Focus indicator outline color #12c9e9
--dile-tooltip-focus-outline-offset Focus indicator outline offset 2px

dile-tooltip demos

Default tooltips

I have a top tooltip | I have a right tooltip | I have a left tooltip | I have a bottom tooltip
<style>
  dile-tooltip {
    color: #777;
  }
</style>
<dile-tooltip tooltip="tooltip text" position="top" fadeIn>I have a top tooltip</dile-tooltip> | 
<dile-tooltip tooltip="tooltip text" position="right" fadeIn>I have a right tooltip</dile-tooltip> | 
<dile-tooltip tooltip="tooltip text" position="left" fadeIn>I have a left tooltip</dile-tooltip> | 
<dile-tooltip tooltip="tooltip text" position="bottom" fadeIn>I have a bottom tooltip</dile-tooltip> 

Arrow tooltips

I have a top tooltip | I have a right tooltip | I have a left tooltip | I have a bottom tooltip
<dile-tooltip tooltip="tooltip text" position="top" fadeIn arrow>I have a top tooltip</dile-tooltip> | 
<dile-tooltip tooltip="tooltip text" position="right" fadeIn arrow>I have a right tooltip</dile-tooltip> | 
<dile-tooltip tooltip="tooltip text" position="left" fadeIn arrow>I have a left tooltip</dile-tooltip> | 
<dile-tooltip tooltip="tooltip text" position="bottom" fadeIn arrow>I have a bottom tooltip</dile-tooltip> 

Styled tooltips

I have a top tooltip | I have a right tooltip | I have a left tooltip | I have a bottom tooltip
<style>
.styled {
  --dile-tooltip-background-color: #cef;
  --dile-tooltip-color: #303030;
  --dile-tooltip-padding: 8px;
  --dile-tooltip-font-size: 1.1rem;
}
</style>
<dile-tooltip class="styled" tooltip="tooltip text" position="top" fadeIn arrow>I have a top tooltip</dile-tooltip> | 
<dile-tooltip class="styled" tooltip="tooltip text" position="right" fadeIn arrow>I have a right tooltip</dile-tooltip> | 
<dile-tooltip class="styled" tooltip="tooltip text" position="left" fadeIn arrow>I have a left tooltip</dile-tooltip> | 
<dile-tooltip class="styled" tooltip="tooltip text" position="bottom" fadeIn arrow>I have a bottom tooltip</dile-tooltip>