1.0.8 • Published 6 months ago

zero-tooltip v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

zero-tooltip   npm

zero-tooltip is a Vue 3 simple tooltip component for displaying information text when hovering over element.

About

The component is designed to enhance user interactions by providing informative tooltips when hovering over specific element by rendering overlay with given text next to it. Components settings are fully customizable.

Install

# npm
npm install zero-tooltip
# yarn
yarn add zero-tooltip

Add globally in main.ts:

import ZeroTooltip from 'zero-tooltip'
// import default styles
import '../node_modules/zero-tooltip/dist/styles.css'
// register directive
const app = createApp(App)
app.directive('tooltip', ZeroTooltip())

Usage

Use it just like any other Vue.js directive on elements. The given value is displayed as tooltip's text:

<button v-tooltip="'Submits this form'">Submit</button>

Zero dependencies

This component does not depend on any other package, except Vue 3

Customization

Default position for tooltip is above/on top of the element that is being hovered. You can change position by passing argument to directive:

<button v-tooltip:right="'Submits this form'">Submit</button>

Acceptable arguments are: left | top | right | bottom. Passing this argument locally, it overrides default tooltip position given as defaultPosition when registering directive at the app level.

You can also define default position globally when registering directive at the app level:

app.directive('tooltip', ZeroTooltip({
    defaultPosition: 'right'
}))

Tooltip component is fully customizable by giving config object when declaring global tooltip directive:

import ZeroTooltipConfig from 'zero-tooltip'

const tooltipConfig: ZeroTooltipConfig = {
    defaultPosition: ... ,
    positions: ... ,
    offsetFromSource: ... ,
    offsetFromViewport: ... ,
    minWidth: ... ,
    maxWidth: ... ,
    tooltipBorderWidth: ... ,
    tooltipClasses: ... ,
    textClasses: ... ,
    arrowSize: ... ,
    arrowClasses: ... ,
    arrowMinOffsetFromTooltipCorner: ... ,
    zIndex: ...
}

app.directive('tooltip', ZeroTooltip(tooltipConfig))

All above settings are optional.

Tooltip can be customizable also for each usage (locally) using same config as follows:

<template>
    <button v-tooltip:right="tooltipConfig">Submit</button>
</template>

<script setup lang="ts">
import ZeroTooltipLocalConfig from 'zero-tooltip'

const tooltipConfig: ZeroTooltipLocalConfig = reactive({
    content: 'This is tooltip'
    defaultPosition: ... ,
    positions: ... ,
    offsetFromSource: ... ,
    offsetFromViewport: ... ,
    minWidth: ... ,
    maxWidth: ... ,
    tooltipBorderWidth: ... ,
    tooltipClasses: ... ,
    textClasses: ... ,
    arrowSize: ... ,
    arrowClasses: ... ,
    arrowMinOffsetFromTooltipCorner: ... ,
    zIndex: ... ,
    show: ...
})
</script>

ZeroTooltipConfig

PropertyDefault valueTypeDetails
defaultPositiontopTooltipPositionPosition of tooltip component relative to element that is being hovered
positions{ left: 'left', 'right', 'top', 'bottom', top: 'top', 'bottom', 'right', 'left', right: 'right', 'left', 'top', 'bottom', bottom: 'bottom', 'top', 'right', 'left', }TooltipPositionsOrdered list of fallback positions in case tooltip does not have enough space in default position. If none of given positions will have enough space for tooltip, then it will not be rendered.
offsetFromSource10numberTooltip offset in px from element that's being hovered (arrow size is not added to this value)
offsetFromViewport20numberMinimal allowed tooltip offset in px from viewport sides
minWidth100numberMinimal tooltip width in px that will be allowed to render
maxWidth250numberMaximal tooltip width in px that will be allowed to render
tooltipBorderWidth0numberTooltip container border width in px
tooltipClassesundefinedstringList of classes that will be added to tooltip element
textClassesundefinedstringList of classes that will be added to text element
arrowSize5numberLength of arrow hypotenuse in px (arrow is generated using border width property, creating square which gets divided in four triangles, thus arrowSize is length of square side)
arrowClassesundefinedstringList of classes that will be added to arrow element
arrowMinOffsetFromTooltipCorner6numberMinimal allowed arrow offset in px from tooltip corner. Used in situations when tooltip does not have enough space to be centered relative to element that is being hover, thus arrow is rendered closer to one of the tooltip corners
zIndex1numberz-index css property value of tooltip

ZeroTooltipLocalConfig

Same as ZeroTooltipConfig with following additions: | Property | Default value | Type | Details | |---|---|---|---| | content | undefined | string | REQUIRED. Tooltip text. Text is rendered as HTML, thus it's possible to give simple HTML structure, e.g., <h1>Tooltip text</h1> | | show | true | boolean | Define whether to show or not to show tooltip |

License

The license is MIT, so any extension, forking is welcome. zero-tooltip is designed as fully customizable, zero dependency, simple tooltip for Vue.js.

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago