Svelte Tooltip Component for Bootstrap (Bootstrap’s tooltip plugin in svlete applications), can be used with sapper or standalone with svelte.Just like Vainilla bootstrap this plugin too is built on a third party library, Popper.js, which provides dynamic positioning and viewport detection. But Unlike Vainilla bootstrap we are using PopperJs V2 instead of V1
npm install --save-dev sv-bootstrap-tooltip @rollup/plugin-replace
- Add below code in your rollup config
import replace from '@rollup/plugin-replace';
..
..
..
plugins: [
..., // Other Plugins
..., // Other Plugins
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
include: '**/node_modules/**',
})
]
Bootstrap CSS needs to be present globally in project
<script>
import Tooltip from "sv-bootstrap-tooltip";
let referenceEle;
</script>
<button type="button" class="btn btn-secondary" bind:this={referenceEle}>
Tooltip on top
</button>
<Tooltip triggerElement={referenceEle}>Tooltip</Tooltip>
You can pass the any html between opening and closing tag of Tooltip
Element
<script>
import Tooltip from "sv-bootstrap-tooltip";
let referenceEle;
</script>
<button type="button" class="btn btn-secondary" bind:this={referenceEle}>
Tooltip on top
</button>
<Tooltip triggerElement={referenceEle}>
<em>Tooltip</em>
<u>with</u>
<b>HTML</b>
</Tooltip>
This option is used to define the placement of tooltip on an triggerElement
. By default the placement is top
<script>
import Tooltip from "sv-bootstrap-tooltip";
let referenceEle;
</script>
<button type="button" class="btn btn-secondary" bind:this={referenceEle}>
Tooltip on top
</button>
<Tooltip triggerElement={referenceEle} placement="left">Tooltip</Tooltip>
Options are similar to Vanilla Bootstrap
Placement | Description |
---|---|
auto | Placements will choose the side with most space and arrow will be in the center of trigger element |
top | Placements will be on top and arrow will be in the center of trigger element |
bottom | Placements will be bottom and arrow will be in the center of trigger element |
right | Placements will be right and arrow will be in the center of trigger element |
left | Placements will be left and arrow will be in the center of trigger element |
This option should tell the Tooltip
to filp side if there is no space on the prefered side
<script>
import Tooltip from "sv-bootstrap-tooltip";
let referenceEle;
</script>
<button type="button" class="btn btn-secondary" bind:this={referenceEle}>
Tooltip on top
</button>
<Tooltip flip="false" triggerElement={referenceEle}>
</Tooltip>
Name | Type | Default | Description |
---|---|---|---|
open | boolean | false | This option is used to manage the Tooltip manually. |
flip | boolean | true | This option should tell the Tooltip to filp side if there is no space on the prefered side. |
trigger | string | `hover | focus` |
offset | [?number, ?number] or Function(Definition) | [0, 4] | The offset modifier lets you displace tooltip element from triggerElement element. |
placement | string | top | This option is used to define the placement of tooltip on an triggerElement . |
onOpened | function | Empty function(noop) | Can be used for callbacks after the tooltip is opened. |
onClosed | function | Empty function(noop) | Can be used for callbacks after the tooltip is closed. |
NOTE
For only manual triggering just pass empty string
""
to trigger option and use open option to handle the tooltip manually
- Animation
- Adding More Placement options