3.0.1 • Published 23 days ago

@svelte-plugins/tooltips v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
23 days ago

@svelte-plugins/tooltips

A simple tooltip action and component designed for Svelte.

Try it in the Svelte REPL.

Install

yarn add @svelte-plugins/tooltips

# or with NPM

npm i @svelte-plugins/tooltips

# or with PNPM

pnpm i @svelte-plugins/tooltips

Using the Tooltip component

<script>
  import { Tooltip } from "@svelte-plugins/tooltips";
</script>

<Tooltip content="Hello world!">
 Check out my tooltip
</Tooltip>

Using the Tooltip action

<script>
  import { tooltip } from "@svelte-plugins/tooltips";
</script>

Checkout out my <u title="Hello World!" use:tooltip>tooltip</u>

Checkout out my <u use:tooltip={{ content: 'Hello World!' }}>tooltip</u>

API

Props

PropDescriptionValue
actionThe action that triggers the tooltip (hoverclickprop)string (default: hover)
animationThe animation to apply to the tooltipstring (default: )
arrowIf false, the tooltip arrow will not be shown.boolean (default: true)
autoPositionAdjust tooltip position if viewport clipping occursboolean (default: false)
contentThe string or object containing componentref and propsstringobject component (default: )
delayThe animation delay in milliseconds to apply to the tooltipnumber (default: 200)
hideOnClickOutsideHides a tooltip when an outside click occursboolean (default: false)
maxWidthThe max allowable width of the tooltip contentnumber (default: 200)
positionThe position where the tooltip should appear relative to its parentstring (default: top)
showAllows you to manually control the tooltip visibilityboolean (default: false)
styleThe object containing theme variable overridesobject (default: null)
themeThe CSS theme class namestring (default: )

Using components as content

PropDescriptionValue
content.componentSvelte componentcomponent (default: null)
content.propsAny component propetiesobject (default: null)
<script>
  import ComponentAsTooltip from './ComponentAsTooltip';
</script>

Checkout out my <span use:tooltip={{ content: { component: ComponentAsTooltip, props: { title: 'Hello World!' } } }}>tooltip</span>

Theming

You can customize tooltips theme using several methods:

  • Assign a theme class name via the theme property that includes all of your CSS variables overrides
  • Define the overrides directly using the style property
  • Override the CSS variables globally

Tooltip CSS variables:

--tooltip-arrow-size: 10px;
--tooltip-background-color: rgba(0, 0, 0, 0.9);
--tooltip-border-radius: 4px;
--tooltip-box-shadow: 0 1px 20px rgba(0, 0, 0, 0.25);
--tooltip-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell,
  'Helvetica Neue', sans-serif;
--tooltip-font-size: 14px;
--tooltip-font-weight: 500;
--tooltip-line-height: 1.25rem;
--tooltip-color: #fff;
--tooltip-offset-x: 12px;
--tooltip-offset-y: 12px;
--tooltip-padding: 12px;
--tooltip-white-space-hidden: nowrap;
--tooltip-white-space-shown: normal;
--tooltip-z-index: 100;

Using the theme property

// action
<span title="hello world!" use:tooltip={{ theme: 'custom-tooltip' }}>Hover over me</span>

// component
<Tooltip content="hello world!" theme="custom-tooltip">Hover over me</Tooltip>

<style>
  :global(.tooltip.custom-tooltip) {
    --tooltip-background-color: hotpink;
    --tooltip-box-shadow: 0 1px 8px pink;
  }
</style>

Using the style property

// action
<span title="hello world!" use:tooltip={{ style: { backgroundColor: 'blue', borderRadius: '10px' } }}>Hover over me</span>

// component
<Tooltip content="hello world!" style={{ style: { backgroundColor: 'blue' } }}>Hover over me</Tooltip>

Changelog

Changelog

License

MIT

3.0.1

23 days ago

3.0.0

5 months ago

2.2.0

5 months ago

2.1.1

5 months ago

2.1.0

5 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.9

6 months ago

0.1.6

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.5

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago