UNPKG

xtendui

Version:

Xtend UI is a powerful frontend library of Tailwind CSS components enhanced by vanilla js. It helps you build interfaces with advanced interactions and animations.

132 lines (118 loc) 2.52 kB
/*! * Xtend UI (https://xtendui.github.io/xtendui/) * @copyright (c) 2017-2026 Riccardo Caroli * @license MIT (https://github.com/xtendui/xtendui/blob/master/LICENSE.txt) */ import { Xt } from './xt.mjs' import './toggle.mjs' import RJSON from 'relaxed-json' Xt.JSON = RJSON /** * Tooltip */ class Tooltip extends Xt.Toggle { /** * constructor * @param {Node|HTMLElement|EventTarget|Window} object Base node * @param {Object} optionsCustom User options * @constructor */ constructor(object, optionsCustom = {}) { super(object, optionsCustom) } } // // options // Tooltip.constructorName = 'Tooltip' Tooltip.componentName = 'xt-tooltip' Tooltip.optionsDefault = { // element elements: '[data-xt-tooltip-element]', targets: '[data-xt-tooltip-target]', // class classSkip: { elements: true, elementsInner: true, }, // quantity min: 0, max: 1, // event on: 'mouseenter focus', off: 'mouseleave', mouseParent: false, eventLimit: '.xt-event-limit, .xt-tooltip', closeauto: true, openauto: false, closeDeep: '.xt-dismiss', closeInside: '.xt-tooltip, .xt-backdrop', closeOutside: 'body', preventEvent: true, // timing queue: { elements: false, targets: true, elementsInner: false, targetsInner: true, }, // other disableDeactivate: true, position: 'top', positionInner: false, strategy: 'absolute', spaceOverflow: 15, spaceFlip: 15, spaceArrow: false, popperjs: true, zIndex: { targets: { start: 700, // same as options.zIndex.targets.start factor: -1, }, }, a11y: { role: 'tooltip', labelElements: true, labelTargets: false, hiddenTargets: true, controls: false, selected: false, expanded: false, hidden: false, live: false, disabled: true, keyboard: true, vertical: false, items: false, }, } // // export // Xt.Tooltip = Tooltip // // observe // if (typeof window !== 'undefined') { Xt.mount({ matches: `[data-${Xt.Tooltip.componentName}]`, mount: ({ ref }) => { // vars const optionsMarkup = ref.getAttribute(`data-${Xt.Tooltip.componentName}`) const options = optionsMarkup ? RJSON.parse(optionsMarkup) : {} // init let selfDestroy = () => {} new Xt.Tooltip(ref, options).then(self => { selfDestroy = () => { self.destroy() self = null } }) // unmount return () => { selfDestroy() } }, }) }