Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@lion/tooltip
Advanced tools
lion-tooltip
is a component used for basic popups on hover.
Its purpose is to show content appearing when the user hovers over an invoker element with the cursor or with the keyboard, or if the invoker element is focused.
import { css, html } from '@lion/core';
import { LionTooltip } from './src/LionTooltip.js';
import './lion-tooltip.js';
export default {
title: 'Overlays/Tooltip',
// parameters: {
// component: 'lion-tooltip',
// options: {
// selectedPanel: 'storybookjs/knobs/panel'
// }
// }
// decorators: [withKnobs]
};
const tooltipDemoStyles = css`
.demo-tooltip-invoker {
margin: 50px;
}
.demo-tooltip-content {
display: block;
font-size: 16px;
color: white;
background-color: black;
border-radius: 4px;
padding: 8px;
}
.demo-box-placements {
display: flex;
flex-direction: column;
margin: 40px 0 0 200px;
}
.demo-box-placements lion-tooltip {
margin: 20px;
}
`;
export const main = () => html`
<style>
${tooltipDemoStyles}
</style>
<lion-tooltip has-arrow .config=${{ popperConfig: { placement: 'right' } }}>
<button slot="invoker" class="demo-tooltip-invoker">Hover me</button>
<div slot="content" class="demo-tooltip-content">This is a tooltip</div>
</lion-tooltip>
`;
.config
to override the overlay configurationpopperConfig
property that has a one to one relation with Popper.js configuration API.npm i --save @lion/tooltip
import { LionTooltip } from '@lion/tooltip';
// or
import '@lion/tooltip/lion-tooltip.js';
There is a difference between tooltips used as a primary label or as a description. In most cases a button will already have its own label, so the tooltip will be used as a description with extra information, which is already set as default. Only in case of icon buttons you want to use the tooltip as the primary label. To do so you need to set the invokerRelation
to label
.
For detailed information please read: inclusive tooltips.
export const invokerRelation = () => html`
<style>
${tooltipDemoStyles}
</style>
<lion-tooltip .config=${{ invokerRelation: 'label' }}>
<button slot="invoker" class="demo-tooltip-invoker">📅</button>
<div slot="content" class="demo-tooltip-content">Agenda<div>
</lion-tooltip>
`;
You can easily change the placement of the content node relative to the invoker.
export const placements = () => html`
<style>
${tooltipDemoStyles}
</style>
<div class="demo-box-placements">
<lion-tooltip has-arrow .config=${{ popperConfig: { placement: 'top' } }}>
<button slot="invoker">Top</button>
<div slot="content" class="demo-tooltip-content">Its top placement</div>
</lion-tooltip>
<lion-tooltip has-arrow .config=${{ popperConfig: { placement: 'right' } }}>
<button slot="invoker">Right</button>
<div slot="content" class="demo-tooltip-content">Its right placement</div>
</lion-tooltip>
<lion-tooltip has-arrow .config=${{ popperConfig: { placement: 'bottom' } }}>
<button slot="invoker">Bottom</button>
<div slot="content" class="demo-tooltip-content">Its bottom placement</div>
</lion-tooltip>
<lion-tooltip has-arrow .config=${{ popperConfig: { placement: 'left' } }}>
<button slot="invoker">Left</button>
<div slot="content" class="demo-tooltip-content">Its left placement</div>
</lion-tooltip>
</div>
`;
You can override the Popper configuration, the API is one to one with Popper's API, and includes modifiers.
export const overridePopperConfig = () => html`
<style>${tooltipDemoStyles}</style>
<lion-tooltip .config=${{
popperConfig: {
placement: 'bottom-start',
strategy: 'fixed',
modifiers: [
{
name: 'keepTogether',
options: {},
enabled: true,
},
{
name: 'preventOverflow',
options: {
boundariesElement: 'viewport',
padding: 16,
},
enabled: false,
},
{
name: 'flip',
options: {
boundariesElement: 'viewport',
padding: 4,
},
enabled: true,
},
{
name: 'offset',
options: {
// Note the different offset notation
offset: [0, 4],
},
enabled: true,
},
],
},
}}>
<button slot="invoker" class="demo-tooltip-invoker">Hover me</button>
<div slot="content" class="demo-tooltip-content">This is a tooltip<div>
</lion-tooltip>
`;
Modifier explanations:
By default, the arrow is disabled for our tooltip. Via the has-arrow
property it can be enabled.
As a Subclasser, you can decide to turn the arrow on by default if this fits your Design System, by setting
this.hasArrow = true;
in the constructor.
export const arrow = () => html`
<style>
${tooltipDemoStyles}
</style>
<lion-tooltip has-arrow>
<button slot="invoker">Hover me</button>
<div slot="content">This is a tooltip</div>
</lion-tooltip>
`;
If you plan on providing a custom arrow, you can extend the lion-tooltip
.
All you need to do is override the _arrowTemplate
method to pass your own SVG, and extend the styles to pass the proper dimensions of your arrow.
The rest of the work is done by Popper.js (for positioning) and the lion-tooltip-arrow
(arrow dimensions, rotation, etc.).
export const customArrow = () => {
if (!customElements.get('custom-tooltip')) {
customElements.define(
'custom-tooltip',
class extends LionTooltip {
static get styles() {
return [
super.styles,
css`
:host {
--tooltip-arrow-width: 20px;
--tooltip-arrow-height: 8px;
}
`,
];
}
constructor() {
super();
this.hasArrow = true;
}
_arrowTemplate() {
return html`
<svg viewBox="0 0 20 8">
<path d="M 0,0 h 20 L 10,8 z"></path>
</svg>
`;
}
},
);
}
return html`
<style>
${tooltipDemoStyles}
</style>
<custom-tooltip>
<button slot="invoker" class="demo-tooltip-invoker">Hover me</button>
<div slot="content" class="demo-tooltip-content">This is a tooltip</div>
</custom-tooltip>
`;
};
FAQs
Show relative overlay content on hover
The npm package @lion/tooltip receives a total of 94 weekly downloads. As such, @lion/tooltip popularity was classified as not popular.
We found that @lion/tooltip demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.