8000 GitHub - substrate-system/tool-tip: Tooltips as a web component
[go: up one dir, main page]

Skip to content

substrate-system/tool-tip

Repository files navigation

tool-tip

tests types module install size GZip size semantic versioning Common Changelog license

Webcomponent for tooltips — text when you hover.

See a live demo

Contents

Install

npm i -S @substrate-system/tool-tip

Example

<tool-tip content="This is a tooltip">
    <!-- put the target as a child of tool-tip -->
    <button>Hover me</button>
</tool-tip>

API

This exposes ESM and common JS via package.json exports field.

ESM

import { ToolTip } from '@substrate-system/tool-tip'

Common JS

require('@substrate-system/tool-tip')

Attributes

Attribute Type Default Description
content string "" The text content of the tooltip.
placement Placement "top" Where to place the tooltip relative to the target.
trigger string "hover focus" Space-separated list of triggers: hover, focus, click, manual.
disabled boolean false If true, the tooltip will not be shown.
distance number 8 Distance in pixels from the target.
skidding number 0 Lateral offset in pixels.
delay number 0 Delay in milliseconds before showing the tooltip on hover.
hoist boolean false If true, the tooltip will be appended to document.body.

placement

<tool-tip content="example" placement="left"></tool-tip>
export type Placement =
    | 'top'
    | 'top-start'
    | 'top-end'
    | 'right'
    | 'right-start'
    | 'right-end'
    | 'bottom'
    | 'bottom-start'
    | 'bottom-end'
    | 'left'
    | 'left-start'
    | 'left-end'

CSS

Import CSS

import '@substrate-system/tool-tip/css'

Or minified:

import '@substrate-system/tool-tip/min/css'

Use

This calls the global function customElements.define. Just import, then use the tag in your HTML.

The target, or the element with the tooltip, should be the child of a tool-tip element.

JS

import '@substrate-system/tool-tip'

HTML

<tool-tip content="This is a tooltip">
    <!-- put the target as a child of tool-tip -->
    <button>Hover me</button>
</tool-tip>

pre-built

This package exposes minified JS and CSS files too. Copy them to a location that is accessible to your web server, then link to them in HTML.

copy

cp ./node_modules/@substrate-system/tool-tip/dist/index.min.js ./public/tool-tip.min.js
cp ./node_modules/@substrate-system/tool-tip/dist/style.min.css ./public/tool-tip.css

HTML

<head>
    <link rel="stylesheet" href="./tool-tip.css">
</head>
<body>
    <!-- ... -->
    <script type="module" src="./tool-tip.min.js"></script>
</body>
0