Example
Wrap both the tooltip's trigger element (such as an <i-button>
) and the <template slot="body">
inside a <i-tooltip>
component.
<i-tooltip>
<i-button>Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
Placement
Trigger tooltips at the top
, bottom
, left
or right
of elements by adding the placement
property to the <i-tooltip>
element.
Each of the positions also has a -start
or -end
variant (top-start
, top-end
, bottom-start
, bottom-end
, etc.) that sets the tooltip to the start or end of the placement instead of centering it.
<i-tooltip placement="top">
<i-button>Top Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip placement="bottom">
<i-button>Bottom Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip placement="left">
<i-button>Left Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip placement="right">
<i-button>Right Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
Tooltips can contain text of virtually any size. You can control the wrapping and the maximum width of the tooltip by setting white-space: normal
and a fixed width
property on the tooltip content.
<i-tooltip>
<i-button>Normal Tooltip</i-button>
<template slot="body">
This is a <strong>freeform tooltip</strong> with a <u>long text</u>. Its width is not controlled.
</template>
</i-tooltip>
<i-tooltip>
<i-button>Fixed Width Tooltip</i-button>
<div style="white-space: normal; width: 240px" slot="body">
This is a <strong>freeform tooltip</strong> with a <u>long text</u>. Its width is controlled.
</div>
</i-tooltip>
Trigger Type
You can use the trigger
property to trigger the tooltip on hover
or click
. By default, tooltips are triggered on hover
, a design decision made to improve user experience.
<i-tooltip trigger="click">
<i-button>Click Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip trigger="hover">
<i-button>Hover Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip trigger="focus">
<i-button>Focus Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip :trigger="['focus', 'hover']">
<i-button>Multiple Events Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>&nbsp;
<i-tooltip trigger="manual" v-model="visible">
<i-button @click="visible = !visible">Manual Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
Sizes
You're able to use the size
modifier to control the size of your tooltips, using one of the available sizes: sm
, md
, and lg
.
The default size is set to md
.
<i-tooltip size="sm">
<i-button>Small Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip size="md">
<i-button>Medium Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip size="lg">
<i-button>Large Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
Variants
Inkline includes two predefined tooltip styles, each serving its own semantic purpose. You can set the style of a <i-tooltip>
using the variant
property, which can have a value of light
or dark
. By default, tooltips use the dark
variant.
<i-tooltip variant="light">
<i-button variant="light">Light Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
<i-tooltip variant="dark">
<i-button variant="dark">Dark Tooltip</i-button>
<template slot="body">Tooltip</template>
</i-tooltip>
Component API
Here you can find a list of the various customization options you can use for the tooltip components as props, as well as available slots and events.
Property arrow
Type Boolean
Accepted true
, false
Default true
Description Sets whether to attach an arrow to the tooltip.
Property disabled
Type Boolean
Accepted true
, false
Default false
Description Sets the tooltip state as disabled.
Property id
Type String
Default tooltip-<uid>
Description Sets the identifier of the tooltip.
Property placement
Type String
Accepted top
,
top-start
,
top-end
,
bottom
,
bottom-start
,
bottom-end
,
left
,
left-start
,
left-end
,
right
,
right-start
,
right-end
Default top
Description Sets the placement of the tooltip.
Property popperOptions
Type Object
Description Sets custom options for the Popper.js plugin.
Property trigger
Type String
Accepted click
, hover
Default hover
Description Sets the trigger event of the tooltip.
Property transformOrigin
Type Boolean
,
String
Default true
Description Sets the transform origin of the tooltip.
Property variant
Type String
Accepted light
, dark
Default light
Description Sets the color variant of the popover.
Description Slot for tooltip component trigger.
Description Slot for tooltip component body.
Event change
Type (visible: Boolean) => {}
Description Emitted when visibility changes.
Sass Variables
Here you can find a list of the Sass variables you can use for the tooltip components. If you're looking to find common variables that these rely on, you should take a look at the Sass Variables page.
Property $tooltip-font-size
Default $font-size
Property $tooltip-font-weight
Default $font-weight-normal
Property $tooltip-line-height
Default $line-height
Property $tooltip-margin
Default spacers('1/2')
Property $tooltip-border-width
Default $border-width
Property $tooltip-border-radius
Default $border-radius
Property $tooltip-padding-base
Default spacers('1/4') spacers('1/2')
Property $tooltip-padding
Default size-map($tooltip-padding-base, $sizes, $size-multipliers)
Property $tooltip-color-for-light-variant
Default $color-for-light-variant
Property $tooltip-color-for-dark-variant
Default $color-for-dark-variant
Property $tooltip-variant-{variant}
Default tooltip-variant($color-{variant})
Property $tooltip-variants
Default (
light: $tooltip-variant-light,
dark: $tooltip-variant-dark
)
Default @function tooltip-variant($variant) {
$tooltip-variant-color: variant-color-by-luminance($variant, $tooltip-color-for-light-variant, $tooltip-color-for-dark-variant);
$tooltip-variant-background: $variant;
$tooltip-variant-border-color: variant-color-by-luminance($variant, $border-color-dark, $border-color-light);
$variant-map: (
color: $tooltip-variant-color,
background: $tooltip-variant-background,
border-color: $tooltip-variant-border-color,
);
@return $variant-map;
}