Svelte library for tooltips
Go to file
2022-05-06 19:26:50 +02:00
.github readme and rearrange directions 2022-01-13 15:00:46 +01:00
src make inline block 2022-05-06 19:20:17 +02:00
static initial commit 2022-01-13 13:35:07 +01:00
.gitignore initial commit 2022-01-13 13:35:07 +01:00
.npmrc initial commit 2022-01-13 13:35:07 +01:00
package.json first actual version 2022-05-06 19:26:50 +02:00
pnpm-lock.yaml updates 2022-05-06 19:05:54 +02:00
README.md links 2022-05-06 19:15:10 +02:00
SETUP.md readme 2022-05-06 19:13:47 +02:00
svelte.config.js updates 2022-05-06 19:05:54 +02:00
tsconfig.json initial commit 2022-01-13 13:35:07 +01:00

svelte-hint

⚠️ This is beta software and still not ready to use

Svelte library for tooltips internally powered by the awesome Fluent UI with sensible default values.

Check out the demo to see it in action.

Screenshot

🌈 Features

  • Automatic positioning & overflow handling on screen edges.
  • Fully typed.
  • Sensible default values.
  • Use text or custom html/components as tooltips.

📀 Installation

npm install svelte-hint

⌨️ Usage

With text

<script lang="ts">
  import { Hint } from 'svelte-hint'
</script>

<Hint text="A tooltip!">
  <button class="btn btn-success drag">Hover me!</button>
</Hint>

With custom html / components

<script lang="ts">
  import { Hint } from 'svelte-hint'
</script>

<Hint>
  <button class="btn btn-success drag">Hover me!</button>
  <i slot="hint">Some custom html</i>
</Hint>

🏗 Setup

Floating UI needs some additional setup. Below are a few examples (which are shamefully copied from the carbon team).

🗂 Docs

Props

Prop Type Default Description
text string '' Text to be used as the tooltip. If empty the slot will be used.
placement Placement auto See the Fluent UI docs.
boundary HTMLElement | string 'clippingAncestors' See the Fluent UI docs.
offset Options 4 See the Fluent UI docs.
auto boolean | 'start' | 'end' false Use the autoPlacement middleware. If set placement will be ignored.

Slots

hint

Only works if the text props is empty. Otherwise the slot is ignored.

If you don't want to use the pre-styled tooltip you are free to use whatever html / svelte code you'd like as the tooltip.

<Hint>
  <div>Hover me</div>
  <div slot="hint">Some custom html</div>
</Hint>