@zestia/ember-async-tooltips
Installation
ember install @zestia/ember-async-tooltips
Demo
https://zestia.github.io/ember-async-tooltips/
Features
- Manual positioning โ๏ธ
- Automatic positioning โ๏ธ
- Customisable show/hide delays โ๏ธ
- Customisable reference element โ๏ธ
- Pre-loads any required data โ๏ธ
Notes
- This addon intentionally does not come with any styles.
Example
When the tooltipper is hovered over, and any loading that needs to take place has finished, then the tooltip will be rendered inside. (Or, you can use the {{in-element}}
helper to render the tooltip elsewhere).
You can replace the @Tooltip
argument with any custom component of your choosing.
Positioning
Please see the positioning library for more information on the possible positions.
Manual positioning
Setting the @position
argument will compute top
and left
CSS properties to position the tooltip around the outside edge of the tooltipper that caused it to display.
Automatic positioning
By omitting the @position
argument, the tooltip will be positioned automatically around the outside edge of the tooltipper. For example: If the tooltipper is at the very bottom of the viewport, then the tooltip will be displayed above it - so as to remain visible.
You can control what position the reference element is considered to be in by changing how the viewport is split into a grid.
Custom positioning
You can set @position
to be a function. Your function will receive the reference element's position in the viewport. You are then free to return an appropriate counter-position for your tooltip. e.g:
position() {
switch(referencePosition) {
case 'top right':
return 'left top';
// ...
}
}
Showing/hiding
By default, tooltips will display when hovering over a tooltipper. But tooltippers also yield the ability to show or hide its tooltip manually, on focusin for example. Additionally, you can customise the show/hide delays.
You can also use the actions @onShowTooltip
and @onHideTooltip
. These hooks include load time, render time, and animation time.
Sticky tooltips
You can group tooltips together, so that once one from a group is showing, then others in that group will show instantly - ignoring their show delay.
The normal showing/hiding behaviour will resume after a period of time. This can be optionally be customised with @stickyTimeout
.
API
The tooltipper yields an API to control the tooltip.
Similarly, the tooltip receives an API as an argument:
Custom reference element
By default the tooltipper is the reference element that the causes the tooltip to show or hide, and is also the element that the tooltip will be positioned next to. But, you can specify any element to be the reference element.
Preloading data
When a tooltipper is hovered over, @onLoad
will be fired. You can respond to this action by returning a promise. The result of that promise will be available in the tooltip's template as @tooltip.data
. This is a good way preload any data required for the tooltip to display.
The following example waits for 300ms before showing a tooltip, during this time it is loading some data. The show delay will only be extended if the data wasn't retreived in time.
Animating
If your tooltips need to animate in and out, you can utilise these class names:
.tooltip--showing {
animation: your-show-animation;
}
.tooltip--hiding {
animation: your-hide-animation;
}
You may want to alter animations for sticky tooltips:
.tooltip--sticky {
animation-name: none
}