@vue-interface/tooltip 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Justin Kimbrell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Tooltip
2
+
3
+ The `tooltip` component provides flexible tooltips with customizable placement options.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i @vue-interface/tooltip
9
+ ```
10
+
11
+ ```bash
12
+ yarn add @vue-interface/tooltip
13
+ ```
14
+
15
+ ```bash
16
+ pnpm i @vue-interface/tooltip
17
+ ```
18
+
19
+ ```bash
20
+ bun i @vue-interface/tooltip
21
+ ```
22
+
23
+ ## Basic Usage
24
+
25
+ Tooltips can be positioned at the top, bottom, left, or right of the target element using standard attributes.
26
+
27
+ ```html
28
+ <a href="#" title="Top" data-tooltip-placement="top">Top</a>
29
+ <a href="#" title="Bottom" data-tooltip-placement="bottom">Bottom</a>
30
+ <a href="#" title="Left" data-tooltip-placement="left">Left</a>
31
+ <a href="#" title="Right" data-tooltip-placement="right">Right</a>
32
+ ```
33
+
34
+ ## Via Directive
35
+
36
+ You can also use the `v-tooltip` directive for a more concise syntax.
37
+
38
+ ```html
39
+ <button
40
+ v-tooltip="{
41
+ title: 'Top',
42
+ placement: 'top'
43
+ }">
44
+ Top
45
+ </button>
46
+ ```
47
+
48
+ For more comprehensive documentation and examples, please visit the [online documentation](https://vue-interface.github.io/packages/tooltip/).
@@ -0,0 +1,3 @@
1
+ import { default as Tooltip } from './src/Tooltip.vue';
2
+ import { TooltipDirective, TooltipPlugin } from './src/TooltipPlugin';
3
+ export { Tooltip, TooltipDirective, TooltipPlugin };
@@ -0,0 +1,68 @@
1
+ import { FlipOptions, MaybeElement, OffsetOptions, ReferenceElement, UseFloatingOptions } from '@floating-ui/vue';
2
+ import { Ref, ShallowRef } from 'vue';
3
+ export type TooltipProps = {
4
+ title?: string;
5
+ show?: boolean;
6
+ target?: Ref<MaybeElement<ReferenceElement>> | ReferenceElement;
7
+ placement?: UseFloatingOptions['placement'];
8
+ strategy?: UseFloatingOptions['strategy'];
9
+ middleware?: (arrow: Readonly<ShallowRef<HTMLDivElement | null>>) => UseFloatingOptions['middleware'];
10
+ flip?: FlipOptions;
11
+ offset?: OffsetOptions;
12
+ };
13
+ declare function open(): void;
14
+ declare function close(): void;
15
+ declare function __VLS_template(): {
16
+ attrs: Partial<{}>;
17
+ slots: Readonly<{
18
+ default: () => void;
19
+ }> & {
20
+ default: () => void;
21
+ };
22
+ refs: {
23
+ tooltipEl: HTMLDivElement;
24
+ arrowEl: HTMLDivElement;
25
+ inner: HTMLDivElement;
26
+ };
27
+ rootEl: any;
28
+ };
29
+ type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
30
+ declare const __VLS_component: import('vue').DefineComponent<TooltipProps, {
31
+ open: typeof open;
32
+ close: typeof close;
33
+ tooltipEl: Readonly<ShallowRef<HTMLDivElement | null>>;
34
+ arrowEl: Readonly<ShallowRef<HTMLDivElement | null>>;
35
+ isShowing: Ref<boolean, boolean>;
36
+ hash: string;
37
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<TooltipProps> & Readonly<{}>, {
38
+ placement: import('@floating-ui/vue').Placement | Readonly<Ref<import('@floating-ui/vue').Placement | undefined, import('@floating-ui/vue').Placement | undefined>> | (() => import('@floating-ui/vue').Placement | undefined);
39
+ strategy: import('@floating-ui/vue').Strategy | Readonly<Ref<import('@floating-ui/vue').Strategy | undefined, import('@floating-ui/vue').Strategy | undefined>> | (() => import('@floating-ui/vue').Strategy | undefined);
40
+ middleware: (arrow: Readonly<ShallowRef<HTMLDivElement | null>>) => UseFloatingOptions["middleware"];
41
+ title: string;
42
+ target: Ref<MaybeElement<ReferenceElement>> | ReferenceElement;
43
+ flip: {
44
+ mainAxis?: boolean | undefined;
45
+ crossAxis?: boolean | "alignment" | undefined;
46
+ fallbackPlacements?: Array<import('@floating-ui/vue').Placement> | undefined;
47
+ fallbackStrategy?: "bestFit" | "initialPlacement" | undefined;
48
+ fallbackAxisSideDirection?: "none" | "start" | "end" | undefined;
49
+ flipAlignment?: boolean | undefined;
50
+ rootBoundary?: import('@floating-ui/vue').RootBoundary | undefined;
51
+ elementContext?: import('@floating-ui/vue').ElementContext | undefined;
52
+ altBoundary?: boolean | undefined;
53
+ padding?: import('@floating-ui/vue').Padding | undefined;
54
+ boundary?: import('@floating-ui/vue').Boundary | undefined;
55
+ };
56
+ offset: OffsetOptions;
57
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
58
+ tooltipEl: HTMLDivElement;
59
+ arrowEl: HTMLDivElement;
60
+ inner: HTMLDivElement;
61
+ }, any>;
62
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
63
+ export default _default;
64
+ type __VLS_WithTemplateSlots<T, S> = T & {
65
+ new (): {
66
+ $slots: S;
67
+ };
68
+ };
@@ -0,0 +1,4 @@
1
+ import { App, Directive } from 'vue';
2
+ import { TooltipProps } from './Tooltip.vue';
3
+ export declare const TooltipDirective: Directive<Element, string | TooltipProps>;
4
+ export declare function TooltipPlugin(app: App<Element>): void;
@@ -0,0 +1,178 @@
1
+ import { defineComponent as O, useTemplateRef as b, ref as w, isRef as k, shallowReadonly as M, computed as s, watchEffect as g, onUnmounted as j, createBlock as B, openBlock as D, Teleport as I, createElementVNode as p, normalizeStyle as y, unref as u, normalizeClass as P, renderSlot as U, createTextVNode as W, toDisplayString as z, h as V, render as q } from "vue";
2
+ import { useFloating as H, autoUpdate as J, flip as G, offset as K, arrow as Q } from "@floating-ui/vue";
3
+ const X = ["data-tooltip-id"], Y = {
4
+ ref: "inner",
5
+ class: "tooltip-inner"
6
+ }, Z = /* @__PURE__ */ O({
7
+ __name: "Tooltip",
8
+ props: {
9
+ title: { default: void 0 },
10
+ show: { type: Boolean },
11
+ target: { default: void 0 },
12
+ placement: { default: "top" },
13
+ strategy: { default: void 0 },
14
+ middleware: { type: Function, default: void 0 },
15
+ flip: { default: void 0 },
16
+ offset: { type: [Number, Object, Function], default: void 0 }
17
+ },
18
+ setup(e, { expose: t }) {
19
+ const o = e, l = b("tooltipEl"), r = b("arrowEl"), i = w(!1), f = Math.random().toString(36).slice(2, 12), n = k(o.target) ? o.target : M(w(o.target)), N = s(() => {
20
+ if (n.value instanceof Element)
21
+ return n.value.getAttribute("data-tooltip-id");
22
+ });
23
+ g(() => {
24
+ !n.value || N.value || n.value instanceof Element && (n.value.setAttribute("data-tooltip-id", f), n.value.addEventListener("mouseover", h), n.value.addEventListener("mouseout", E));
25
+ }), g(() => {
26
+ i.value = o.show;
27
+ });
28
+ const _ = s(() => o.offset ? o.offset : () => {
29
+ const { height: d } = r.value ? getComputedStyle(r.value) : { height: "0px" };
30
+ return {
31
+ mainAxis: parseInt(d.replace("px", ""))
32
+ };
33
+ }), { floatingStyles: R, middlewareData: c, placement: S } = H(n, l, {
34
+ placement: o.placement,
35
+ middleware: o.middleware?.(r) ?? [
36
+ G(o.flip),
37
+ K(_.value),
38
+ Q({
39
+ element: r
40
+ })
41
+ ],
42
+ whileElementsMounted: J
43
+ }), C = s(() => ({
44
+ show: i.value
45
+ })), F = s(() => S.value.split("-")[0]), v = s(() => ({
46
+ top: "bottom",
47
+ right: "left",
48
+ bottom: "top",
49
+ left: "right"
50
+ })[F.value]), L = s(() => ({
51
+ top: "rotate(225deg)",
52
+ right: "rotate(-45deg)",
53
+ bottom: "rotate(45deg)",
54
+ left: "rotate(135deg)"
55
+ }));
56
+ function h() {
57
+ i.value = !0;
58
+ }
59
+ function E() {
60
+ i.value = !1;
61
+ }
62
+ return j(() => {
63
+ n.value instanceof Element && n.value.removeAttribute("data-tooltip-id");
64
+ }), t({
65
+ open: h,
66
+ close: E,
67
+ tooltipEl: l,
68
+ arrowEl: r,
69
+ isShowing: i,
70
+ hash: f
71
+ }), (d, oe) => (D(), B(I, { to: "body" }, [
72
+ p("div", {
73
+ ref_key: "tooltipEl",
74
+ ref: l,
75
+ class: P(["tooltip", C.value]),
76
+ role: "tooltip",
77
+ "data-tooltip-id": u(f),
78
+ style: y(u(R))
79
+ }, [
80
+ p("div", {
81
+ ref_key: "arrowEl",
82
+ ref: r,
83
+ class: "tooltip-arrow",
84
+ style: y({
85
+ transform: L.value[v.value],
86
+ ...Object.assign({
87
+ left: u(c).arrow?.x != null ? `${u(c).arrow.x}px` : "",
88
+ top: u(c).arrow?.y != null ? `${u(c).arrow.y}px` : ""
89
+ }, {
90
+ [v.value]: `calc(${-(r.value?.offsetWidth ?? 0) / 2}px)`
91
+ })
92
+ })
93
+ }, null, 4),
94
+ p("div", Y, [
95
+ U(d.$slots, "default", {}, () => [
96
+ W(z(e.title), 1)
97
+ ])
98
+ ], 512)
99
+ ], 14, X)
100
+ ]));
101
+ }
102
+ }), a = "data-tooltip", x = new RegExp(`^${a}-`);
103
+ function T(e) {
104
+ return Array.from(e.attributes).map((t) => [t.name, t.value]).filter(([t]) => t === "title" || t.match(x)).map(([t, o]) => [t.replace(new RegExp(x), ""), o]).reduce((t, o) => Object.assign(t, { [o[0]]: o[1] }), {});
105
+ }
106
+ function m(e, t) {
107
+ const o = document.createElement("template"), l = V(Z, Object.assign({
108
+ target: e
109
+ }, T(e), t));
110
+ q(l, o);
111
+ const r = e.getAttribute("title");
112
+ return r && (e.setAttribute(`${a}-og-title`, r), e.removeAttribute("title")), () => {
113
+ l.component && l.component.exposed?.tooltipEl.value?.remove();
114
+ };
115
+ }
116
+ function $(e) {
117
+ const t = document.querySelectorAll(
118
+ `[${a}-id="${e.getAttribute(`${a}-id`)}"]`
119
+ );
120
+ for (const l of t)
121
+ l.remove();
122
+ e.removeAttribute(`${a}-id`);
123
+ const o = e.getAttribute(`${a}-og-title`);
124
+ o && e.setAttribute("title", o);
125
+ }
126
+ function A(e) {
127
+ if (!(e instanceof Element))
128
+ return !1;
129
+ const t = T(e);
130
+ return !t.id && !!t.title;
131
+ }
132
+ function ee(e) {
133
+ return e instanceof Element ? e.hasAttribute(`${a}-id`) : !1;
134
+ }
135
+ const te = {
136
+ beforeMount(e, t) {
137
+ m(e, typeof t.value == "string" ? {
138
+ title: t.value
139
+ } : t.value);
140
+ },
141
+ beforeUnmount(e) {
142
+ $(e);
143
+ }
144
+ };
145
+ function ie(e) {
146
+ e.mixin({
147
+ beforeMount() {
148
+ new MutationObserver((o) => {
149
+ for (const { addedNodes: l, removedNodes: r } of o)
150
+ l.forEach((i) => {
151
+ A(i) && m(i);
152
+ }), r.forEach((i) => {
153
+ ee(i) && $(i);
154
+ });
155
+ }).observe(document.body, {
156
+ childList: !0,
157
+ subtree: !0
158
+ });
159
+ },
160
+ mounted() {
161
+ let t = this.$el;
162
+ this.$el instanceof Text && (t = this.$el.parentNode);
163
+ const o = document.createTreeWalker(
164
+ t,
165
+ NodeFilter.SHOW_ALL,
166
+ (l) => l instanceof Element ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
167
+ );
168
+ for (; o.nextNode(); )
169
+ A(o.currentNode) && m(o.currentNode);
170
+ }
171
+ }), e.directive("tooltip", te);
172
+ }
173
+ export {
174
+ Z as Tooltip,
175
+ te as TooltipDirective,
176
+ ie as TooltipPlugin
177
+ };
178
+ //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.js","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { arrow, autoUpdate, flip as flipFn, FlipOptions, MaybeElement, offset as offsetFn, OffsetOptions, ReferenceElement, useFloating, UseFloatingOptions } from '@floating-ui/vue';\nimport { computed, isRef, onUnmounted, Ref, ref, shallowReadonly, ShallowRef, useTemplateRef, watchEffect } from 'vue';\n\nexport type TooltipProps = {\n title?: string;\n show?: boolean;\n target?: Ref<MaybeElement<ReferenceElement>> | ReferenceElement;\n placement?: UseFloatingOptions['placement'];\n strategy?: UseFloatingOptions['strategy'];\n middleware?: (arrow: Readonly<ShallowRef<HTMLDivElement | null>>) => UseFloatingOptions['middleware'];\n flip?: FlipOptions;\n offset?: OffsetOptions;\n};\n\nconst props = withDefaults(defineProps<TooltipProps>(), {\n title: undefined,\n target: undefined,\n placement: 'top',\n middleware: undefined,\n strategy: undefined,\n flip: undefined,\n offset: undefined,\n});\n\ndefineSlots<{\n default: () => void\n}>();\n\nconst tooltipEl = useTemplateRef<HTMLDivElement>('tooltipEl');\nconst arrowEl = useTemplateRef<HTMLDivElement>('arrowEl');\nconst isShowing = ref(false);\nconst hash = Math.random().toString(36).slice(2, 12);\n\nconst targetEl = isRef(props.target)\n ? props.target\n : shallowReadonly(ref(props.target));\n\nconst id = computed(() => {\n if(!(targetEl.value instanceof Element)) {\n return;\n }\n\n return targetEl.value.getAttribute('data-tooltip-id');\n});\n\n\nwatchEffect(() => {\n if(!targetEl.value || id.value) {\n return;\n }\n\n if(targetEl.value instanceof Element) {\n targetEl.value.setAttribute('data-tooltip-id', hash);\n targetEl.value.addEventListener('mouseover', open);\n targetEl.value.addEventListener('mouseout', close);\n }\n});\n\nwatchEffect(() => {\n isShowing.value = props.show;\n});\n\nconst dynamicOffset = computed<OffsetOptions>(() => {\n if(props.offset) {\n return props.offset;\n }\n\n return () => {\n const { height } = arrowEl.value ? getComputedStyle(arrowEl.value) : { height: '0px' };\n\n return {\n mainAxis: parseInt(height.replace('px', '')),\n };\n };\n});\n\nconst { floatingStyles, middlewareData, placement } = useFloating(targetEl, tooltipEl, {\n placement: props.placement,\n middleware: props.middleware?.(arrowEl) ?? [\n flipFn(props.flip),\n offsetFn(dynamicOffset.value),\n arrow({\n element: arrowEl\n }),\n ],\n whileElementsMounted: autoUpdate\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: isShowing.value\n };\n});\n\ntype Side = 'bottom' | 'left' | 'top' | 'right';\n\nconst side = computed(() => placement.value.split('-')[0] as Side);\n\nconst arrowPosition = computed(() => {\n return {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right'\n }[side.value] as Side;\n});\n\nconst arrowRotation = computed<Record<Side,string>>(() => ({\n top: 'rotate(225deg)',\n right: 'rotate(-45deg)',\n bottom: 'rotate(45deg)',\n left: 'rotate(135deg)',\n}));\n\nfunction open() {\n isShowing.value = true;\n}\n\nfunction close() {\n isShowing.value = false;\n}\n\nonUnmounted(() => {\n if(targetEl.value instanceof Element) {\n targetEl.value.removeAttribute('data-tooltip-id');\n }\n});\n\ndefineExpose({\n open,\n close,\n tooltipEl,\n arrowEl,\n isShowing,\n hash,\n});\n</script>\n\n<template>\n <Teleport to=\"body\">\n <div\n ref=\"tooltipEl\"\n class=\"tooltip\"\n role=\"tooltip\"\n :data-tooltip-id=\"hash\"\n :class=\"tooltipClasses\"\n :style=\"floatingStyles\">\n <div\n ref=\"arrowEl\"\n class=\"tooltip-arrow\"\n :style=\"{\n transform: arrowRotation[arrowPosition],\n ...Object.assign({\n left:\n middlewareData.arrow?.x != null\n ? `${middlewareData.arrow.x}px`\n : '',\n top:\n middlewareData.arrow?.y != null\n ? `${middlewareData.arrow.y}px`\n : ''\n }, {\n [arrowPosition]: `calc(${-(arrowEl?.offsetWidth ?? 0) / 2}px)`\n })\n }\" />\n <div\n ref=\"inner\"\n class=\"tooltip-inner\">\n <slot>{{ title }}</slot>\n </div>\n </div>\n </Teleport>\n</template>","import { h, render, type App, type Directive } from 'vue';\nimport Tooltip, { type TooltipProps } from './Tooltip.vue';\n\nconst prefix = 'data-tooltip';\nconst prefixRegExp = new RegExp(`^${prefix}\\-`);\n\nfunction getAttributes(el: Element): Record<string,string> {\n return Array.from(el.attributes)\n .map(a => [a.name, a.value])\n .filter(([key]) => key === 'title' || key.match(prefixRegExp))\n .map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])\n .reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});\n}\n\nfunction createTooltip(target: Element, props?: TooltipProps) {\n const container = document.createElement('template');\n \n const vnode = h(Tooltip, Object.assign({\n target\n }, getAttributes(target), props));\n\n render(vnode, container);\n\n const title = target.getAttribute('title');\n\n if(title) {\n target.setAttribute(`${prefix}-og-title`, title);\n target.removeAttribute('title');\n }\n\n return () => {\n if(vnode.component) {\n vnode.component.exposed?.tooltipEl.value?.remove();\n }\n };\n}\n\nfunction destroyTooltip(target: Element) {\n const tooltips = document.querySelectorAll(\n `[${prefix}-id=\"${target.getAttribute(`${prefix}-id`)}\"]`\n );\n\n for(const tooltip of tooltips) {\n tooltip.remove();\n }\n\n target.removeAttribute(`${prefix}-id`);\n\n const title = target.getAttribute(`${prefix}-og-title`);\n\n if(title) {\n target.setAttribute('title', title);\n }\n}\n\nfunction shouldCreateTooltip(target: Node): target is Element {\n if(!(target instanceof Element)) {\n return false;\n }\n\n const attrs = getAttributes(target);\n\n return !attrs.id && !!attrs.title;\n}\n\nfunction shouldRemoveTooltip(target: Node): target is Element {\n if(!(target instanceof Element)) {\n return false;\n }\n\n return target.hasAttribute(`${prefix}-id`);\n}\n\nexport const TooltipDirective: Directive<Element, string|TooltipProps> = {\n beforeMount(target, binding) {\n createTooltip(target, typeof binding.value === 'string' ? {\n title: binding.value\n }: binding.value);\n },\n beforeUnmount(target) {\n destroyTooltip(target);\n }\n};\n\nexport function TooltipPlugin(app: App<Element>) {\n app.mixin({\n beforeMount() {\n const observer = new MutationObserver((mutations) => {\n for(const { addedNodes, removedNodes } of mutations) {\n addedNodes.forEach((node) => {\n if(shouldCreateTooltip(node)) {\n createTooltip(node);\n }\n });\n\n removedNodes.forEach((node) => {\n if(shouldRemoveTooltip(node)) {\n destroyTooltip(node);\n }\n });\n }\n });\n \n observer.observe(document.body, {\n childList: true,\n subtree: true\n });\n },\n mounted() {\n let el = this.$el;\n\n if(this.$el instanceof Text) {\n el = this.$el.parentNode;\n }\n\n const walker = document.createTreeWalker(\n el,\n NodeFilter.SHOW_ALL,\n (node: Node) => {\n if(!(node instanceof Element)) {\n return NodeFilter.FILTER_REJECT;\n }\n \n return NodeFilter.FILTER_ACCEPT;\n }\n );\n\n while(walker.nextNode()) {\n if(shouldCreateTooltip(walker.currentNode)) {\n createTooltip(walker.currentNode);\n }\n }\n }\n });\n\n app.directive<Element, string|TooltipProps>('tooltip', TooltipDirective);\n}"],"names":["props","__props","tooltipEl","useTemplateRef","arrowEl","isShowing","ref","hash","targetEl","isRef","shallowReadonly","id","computed","watchEffect","open","close","dynamicOffset","height","floatingStyles","middlewareData","placement","useFloating","flipFn","offsetFn","arrow","autoUpdate","tooltipClasses","side","arrowPosition","arrowRotation","onUnmounted","__expose","_createBlock","_Teleport","_createElementVNode","_normalizeClass","_unref","_normalizeStyle","_hoisted_2","_renderSlot","_ctx","prefix","prefixRegExp","getAttributes","el","a","key","value","carry","attr","createTooltip","target","container","vnode","h","Tooltip","render","title","destroyTooltip","tooltips","tooltip","shouldCreateTooltip","attrs","shouldRemoveTooltip","TooltipDirective","binding","TooltipPlugin","app","mutations","addedNodes","removedNodes","node","walker"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,UAAMA,IAAQC,GAcRC,IAAYC,EAA+B,WAAW,GACtDC,IAAUD,EAA+B,SAAS,GAClDE,IAAYC,EAAI,EAAK,GACrBC,IAAO,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,GAE7CC,IAAWC,EAAMT,EAAM,MAAM,IAC7BA,EAAM,SACNU,EAAgBJ,EAAIN,EAAM,MAAM,CAAC,GAEjCW,IAAKC,EAAS,MAAM;AACtB,UAAKJ,EAAS,iBAAiB;AAI/B,eAAOA,EAAS,MAAM,aAAa,iBAAiB;AAAA,IACxD,CAAC;AAGD,IAAAK,EAAY,MAAM;AACd,MAAG,CAACL,EAAS,SAASG,EAAG,SAItBH,EAAS,iBAAiB,YACzBA,EAAS,MAAM,aAAa,mBAAmBD,CAAI,GACnDC,EAAS,MAAM,iBAAiB,aAAaM,CAAI,GACjDN,EAAS,MAAM,iBAAiB,YAAYO,CAAK;AAAA,IAEzD,CAAC,GAEDF,EAAY,MAAM;AACd,MAAAR,EAAU,QAAQL,EAAM;AAAA,IAC5B,CAAC;AAED,UAAMgB,IAAgBJ,EAAwB,MACvCZ,EAAM,SACEA,EAAM,SAGV,MAAM;AACT,YAAM,EAAE,QAAAiB,EAAA,IAAWb,EAAQ,QAAQ,iBAAiBA,EAAQ,KAAK,IAAI,EAAE,QAAQ,MAAA;AAE/E,aAAO;AAAA,QACH,UAAU,SAASa,EAAO,QAAQ,MAAM,EAAE,CAAC;AAAA,MAAA;AAAA,IAEnD,CACH,GAEK,EAAE,gBAAAC,GAAgB,gBAAAC,GAAgB,WAAAC,MAAcC,EAAYb,GAAUN,GAAW;AAAA,MACnF,WAAWF,EAAM;AAAA,MACjB,YAAYA,EAAM,aAAaI,CAAO,KAAK;AAAA,QACvCkB,EAAOtB,EAAM,IAAI;AAA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EAAA,KAAkBF;AACtC,UAAAC,EAAW,QAAQ,CAACE,MAAS;AACzB,YAAGV,EAAoBU,CAAI,KACvBrB,EAAcqB,CAAI;AAAA,UAE1B,CAAC,GAEDD,EAAa,QAAQ,CAACC,MAAS;AAC3B,YAAGR,GAAoBQ,CAAI,KACvBb,EAAea,CAAI;AAAA,UAE3B,CAAC;AAAA,MAET,CAAC,EAEQ,QAAQ,SAAS,MAAM;AAAA,QAC5B,WAAW;AAAA,QACX,SAAS;AAAA,MAAA,CACZ;AAAA,IACL;AAAA,IACA,UAAU;AACN,UAAI3B,IAAK,KAAK;AAEd,MAAG,KAAK,eAAe,SACnBA,IAAK,KAAK,IAAI;AAGlB,YAAM4B,IAAS,SAAS;AAAA,QACpB5B;AAAA,QACA,WAAW;AAAA,QACX,CAAC2B,MACQA,aAAgB,UAId,WAAW,gBAHP,WAAW;AAAA,MAI1B;AAGJ,aAAMC,EAAO;AACT,QAAGX,EAAoBW,EAAO,WAAW,KACrCtB,EAAcsB,EAAO,WAAW;AAAA,IAG5C;AAAA,EAAA,CACH,GAEDL,EAAI,UAAwC,WAAWH,EAAgB;AAC3E;"}
@@ -0,0 +1,2 @@
1
+ (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@floating-ui/vue")):typeof define=="function"&&define.amd?define(["exports","vue","@floating-ui/vue"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.Tooltip={},a.Vue,a.FloatingUiVue))})(this,(function(a,t,c){"use strict";const A=["data-tooltip-id"],N={ref:"inner",class:"tooltip-inner"},h=t.defineComponent({__name:"Tooltip",props:{title:{default:void 0},show:{type:Boolean},target:{default:void 0},placement:{default:"top"},strategy:{default:void 0},middleware:{type:Function,default:void 0},flip:{default:void 0},offset:{type:[Number,Object,Function],default:void 0}},setup(e,{expose:o}){const i=e,n=t.useTemplateRef("tooltipEl"),l=t.useTemplateRef("arrowEl"),r=t.ref(!1),p=Math.random().toString(36).slice(2,12),s=t.isRef(i.target)?i.target:t.shallowReadonly(t.ref(i.target)),_=t.computed(()=>{if(s.value instanceof Element)return s.value.getAttribute("data-tooltip-id")});t.watchEffect(()=>{!s.value||_.value||s.value instanceof Element&&(s.value.setAttribute("data-tooltip-id",p),s.value.addEventListener("mouseover",v),s.value.addEventListener("mouseout",x))}),t.watchEffect(()=>{r.value=i.show});const $=t.computed(()=>i.offset?i.offset:()=>{const{height:m}=l.value?getComputedStyle(l.value):{height:"0px"};return{mainAxis:parseInt(m.replace("px",""))}}),{floatingStyles:F,middlewareData:d,placement:C}=c.useFloating(s,n,{placement:i.placement,middleware:i.middleware?.(l)??[c.flip(i.flip),c.offset($.value),c.arrow({element:l})],whileElementsMounted:c.autoUpdate}),O=t.computed(()=>({show:r.value})),L=t.computed(()=>C.value.split("-")[0]),T=t.computed(()=>({top:"bottom",right:"left",bottom:"top",left:"right"})[L.value]),j=t.computed(()=>({top:"rotate(225deg)",right:"rotate(-45deg)",bottom:"rotate(45deg)",left:"rotate(135deg)"}));function v(){r.value=!0}function x(){r.value=!1}return t.onUnmounted(()=>{s.value instanceof Element&&s.value.removeAttribute("data-tooltip-id")}),o({open:v,close:x,tooltipEl:n,arrowEl:l,isShowing:r,hash:p}),(m,M)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createElementVNode("div",{ref_key:"tooltipEl",ref:n,class:t.normalizeClass(["tooltip",O.value]),role:"tooltip","data-tooltip-id":t.unref(p),style:t.normalizeStyle(t.unref(F))},[t.createElementVNode("div",{ref_key:"arrowEl",ref:l,class:"tooltip-arrow",style:t.normalizeStyle({transform:j.value[T.value],...Object.assign({left:t.unref(d).arrow?.x!=null?`${t.unref(d).arrow.x}px`:"",top:t.unref(d).arrow?.y!=null?`${t.unref(d).arrow.y}px`:""},{[T.value]:`calc(${-(l.value?.offsetWidth??0)/2}px)`})})},null,4),t.createElementVNode("div",N,[t.renderSlot(m.$slots,"default",{},()=>[t.createTextVNode(t.toDisplayString(e.title),1)])],512)],14,A)]))}}),f="data-tooltip",E=new RegExp(`^${f}-`);function b(e){return Array.from(e.attributes).map(o=>[o.name,o.value]).filter(([o])=>o==="title"||o.match(E)).map(([o,i])=>[o.replace(new RegExp(E),""),i]).reduce((o,i)=>Object.assign(o,{[i[0]]:i[1]}),{})}function u(e,o){const i=document.createElement("template"),n=t.h(h,Object.assign({target:e},b(e),o));t.render(n,i);const l=e.getAttribute("title");return l&&(e.setAttribute(`${f}-og-title`,l),e.removeAttribute("title")),()=>{n.component&&n.component.exposed?.tooltipEl.value?.remove()}}function g(e){const o=document.querySelectorAll(`[${f}-id="${e.getAttribute(`${f}-id`)}"]`);for(const n of o)n.remove();e.removeAttribute(`${f}-id`);const i=e.getAttribute(`${f}-og-title`);i&&e.setAttribute("title",i)}function w(e){if(!(e instanceof Element))return!1;const o=b(e);return!o.id&&!!o.title}function R(e){return e instanceof Element?e.hasAttribute(`${f}-id`):!1}const y={beforeMount(e,o){u(e,typeof o.value=="string"?{title:o.value}:o.value)},beforeUnmount(e){g(e)}};function S(e){e.mixin({beforeMount(){new MutationObserver(i=>{for(const{addedNodes:n,removedNodes:l}of i)n.forEach(r=>{w(r)&&u(r)}),l.forEach(r=>{R(r)&&g(r)})}).observe(document.body,{childList:!0,subtree:!0})},mounted(){let o=this.$el;this.$el instanceof Text&&(o=this.$el.parentNode);const i=document.createTreeWalker(o,NodeFilter.SHOW_ALL,n=>n instanceof Element?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT);for(;i.nextNode();)w(i.currentNode)&&u(i.currentNode)}}),e.directive("tooltip",y)}a.Tooltip=h,a.TooltipDirective=y,a.TooltipPlugin=S,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
2
+ //# sourceMappingURL=tooltip.umd.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.umd.cjs","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { arrow, autoUpdate, flip as flipFn, FlipOptions, MaybeElement, offset as offsetFn, OffsetOptions, ReferenceElement, useFloating, UseFloatingOptions } from '@floating-ui/vue';\nimport { computed, isRef, onUnmounted, Ref, ref, shallowReadonly, ShallowRef, useTemplateRef, watchEffect } from 'vue';\n\nexport type TooltipProps = {\n title?: string;\n show?: boolean;\n target?: Ref<MaybeElement<ReferenceElement>> | ReferenceElement;\n placement?: UseFloatingOptions['placement'];\n strategy?: UseFloatingOptions['strategy'];\n middleware?: (arrow: Readonly<ShallowRef<HTMLDivElement | null>>) => UseFloatingOptions['middleware'];\n flip?: FlipOptions;\n offset?: OffsetOptions;\n};\n\nconst props = withDefaults(defineProps<TooltipProps>(), {\n title: undefined,\n target: undefined,\n placement: 'top',\n middleware: undefined,\n strategy: undefined,\n flip: undefined,\n offset: undefined,\n});\n\ndefineSlots<{\n default: () => void\n}>();\n\nconst tooltipEl = useTemplateRef<HTMLDivElement>('tooltipEl');\nconst arrowEl = useTemplateRef<HTMLDivElement>('arrowEl');\nconst isShowing = ref(false);\nconst hash = Math.random().toString(36).slice(2, 12);\n\nconst targetEl = isRef(props.target)\n ? props.target\n : shallowReadonly(ref(props.target));\n\nconst id = computed(() => {\n if(!(targetEl.value instanceof Element)) {\n return;\n }\n\n return targetEl.value.getAttribute('data-tooltip-id');\n});\n\n\nwatchEffect(() => {\n if(!targetEl.value || id.value) {\n return;\n }\n\n if(targetEl.value instanceof Element) {\n targetEl.value.setAttribute('data-tooltip-id', hash);\n targetEl.value.addEventListener('mouseover', open);\n targetEl.value.addEventListener('mouseout', close);\n }\n});\n\nwatchEffect(() => {\n isShowing.value = props.show;\n});\n\nconst dynamicOffset = computed<OffsetOptions>(() => {\n if(props.offset) {\n return props.offset;\n }\n\n return () => {\n const { height } = arrowEl.value ? getComputedStyle(arrowEl.value) : { height: '0px' };\n\n return {\n mainAxis: parseInt(height.replace('px', '')),\n };\n };\n});\n\nconst { floatingStyles, middlewareData, placement } = useFloating(targetEl, tooltipEl, {\n placement: props.placement,\n middleware: props.middleware?.(arrowEl) ?? [\n flipFn(props.flip),\n offsetFn(dynamicOffset.value),\n arrow({\n element: arrowEl\n }),\n ],\n whileElementsMounted: autoUpdate\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: isShowing.value\n };\n});\n\ntype Side = 'bottom' | 'left' | 'top' | 'right';\n\nconst side = computed(() => placement.value.split('-')[0] as Side);\n\nconst arrowPosition = computed(() => {\n return {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right'\n }[side.value] as Side;\n});\n\nconst arrowRotation = computed<Record<Side,string>>(() => ({\n top: 'rotate(225deg)',\n right: 'rotate(-45deg)',\n bottom: 'rotate(45deg)',\n left: 'rotate(135deg)',\n}));\n\nfunction open() {\n isShowing.value = true;\n}\n\nfunction close() {\n isShowing.value = false;\n}\n\nonUnmounted(() => {\n if(targetEl.value instanceof Element) {\n targetEl.value.removeAttribute('data-tooltip-id');\n }\n});\n\ndefineExpose({\n open,\n close,\n tooltipEl,\n arrowEl,\n isShowing,\n hash,\n});\n</script>\n\n<template>\n <Teleport to=\"body\">\n <div\n ref=\"tooltipEl\"\n class=\"tooltip\"\n role=\"tooltip\"\n :data-tooltip-id=\"hash\"\n :class=\"tooltipClasses\"\n :style=\"floatingStyles\">\n <div\n ref=\"arrowEl\"\n class=\"tooltip-arrow\"\n :style=\"{\n transform: arrowRotation[arrowPosition],\n ...Object.assign({\n left:\n middlewareData.arrow?.x != null\n ? `${middlewareData.arrow.x}px`\n : '',\n top:\n middlewareData.arrow?.y != null\n ? `${middlewareData.arrow.y}px`\n : ''\n }, {\n [arrowPosition]: `calc(${-(arrowEl?.offsetWidth ?? 0) / 2}px)`\n })\n }\" />\n <div\n ref=\"inner\"\n class=\"tooltip-inner\">\n <slot>{{ title }}</slot>\n </div>\n </div>\n </Teleport>\n</template>","import { h, render, type App, type Directive } from 'vue';\nimport Tooltip, { type TooltipProps } from './Tooltip.vue';\n\nconst prefix = 'data-tooltip';\nconst prefixRegExp = new RegExp(`^${prefix}\\-`);\n\nfunction getAttributes(el: Element): Record<string,string> {\n return Array.from(el.attributes)\n .map(a => [a.name, a.value])\n .filter(([key]) => key === 'title' || key.match(prefixRegExp))\n .map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])\n .reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});\n}\n\nfunction createTooltip(target: Element, props?: TooltipProps) {\n const container = document.createElement('template');\n \n const vnode = h(Tooltip, Object.assign({\n target\n }, getAttributes(target), props));\n\n render(vnode, container);\n\n const title = target.getAttribute('title');\n\n if(title) {\n target.setAttribute(`${prefix}-og-title`, title);\n target.removeAttribute('title');\n }\n\n return () => {\n if(vnode.component) {\n vnode.component.exposed?.tooltipEl.value?.remove();\n }\n };\n}\n\nfunction destroyTooltip(target: Element) {\n const tooltips = document.querySelectorAll(\n `[${prefix}-id=\"${target.getAttribute(`${prefix}-id`)}\"]`\n );\n\n for(const tooltip of tooltips) {\n tooltip.remove();\n }\n\n target.removeAttribute(`${prefix}-id`);\n\n const title = target.getAttribute(`${prefix}-og-title`);\n\n if(title) {\n target.setAttribute('title', title);\n }\n}\n\nfunction shouldCreateTooltip(target: Node): target is Element {\n if(!(target instanceof Element)) {\n return false;\n }\n\n const attrs = getAttributes(target);\n\n return !attrs.id && !!attrs.title;\n}\n\nfunction shouldRemoveTooltip(target: Node): target is Element {\n if(!(target instanceof Element)) {\n return false;\n }\n\n return target.hasAttribute(`${prefix}-id`);\n}\n\nexport const TooltipDirective: Directive<Element, string|TooltipProps> = {\n beforeMount(target, binding) {\n createTooltip(target, typeof binding.value === 'string' ? {\n title: binding.value\n }: binding.value);\n },\n beforeUnmount(target) {\n destroyTooltip(target);\n }\n};\n\nexport function TooltipPlugin(app: App<Element>) {\n app.mixin({\n beforeMount() {\n const observer = new MutationObserver((mutations) => {\n for(const { addedNodes, removedNodes } of mutations) {\n addedNodes.forEach((node) => {\n if(shouldCreateTooltip(node)) {\n createTooltip(node);\n }\n });\n\n removedNodes.forEach((node) => {\n if(shouldRemoveTooltip(node)) {\n destroyTooltip(node);\n }\n });\n }\n });\n \n observer.observe(document.body, {\n childList: true,\n subtree: true\n });\n },\n mounted() {\n let el = this.$el;\n\n if(this.$el instanceof Text) {\n el = this.$el.parentNode;\n }\n\n const walker = document.createTreeWalker(\n el,\n NodeFilter.SHOW_ALL,\n (node: Node) => {\n if(!(node instanceof Element)) {\n return NodeFilter.FILTER_REJECT;\n }\n \n return NodeFilter.FILTER_ACCEPT;\n }\n );\n\n while(walker.nextNode()) {\n if(shouldCreateTooltip(walker.currentNode)) {\n createTooltip(walker.currentNode);\n }\n }\n }\n });\n\n app.directive<Element, string|TooltipProps>('tooltip', TooltipDirective);\n}"],"names":["props","__props","tooltipEl","useTemplateRef","arrowEl","isShowing","ref","hash","targetEl","isRef","shallowReadonly","id","computed","watchEffect","open","close","dynamicOffset","height","floatingStyles","middlewareData","placement","useFloating","flipFn","offsetFn","arrow","autoUpdate","tooltipClasses","side","arrowPosition","arrowRotation","onUnmounted","__expose","_createBlock","_Teleport","_createElementVNode","_normalizeClass","_unref","_normalizeStyle","_hoisted_2","_renderSlot","_ctx","prefix","prefixRegExp","getAttributes","el","a","key","value","carry","attr","createTooltip","target","container","vnode","h","Tooltip","render","title","destroyTooltip","tooltips","tooltip","shouldCreateTooltip","attrs","shouldRemoveTooltip","TooltipDirective","binding","TooltipPlugin","app","mutations","addedNodes","removedNodes","node","walker"],"mappings":"+qBAeA,MAAMA,EAAQC,EAcRC,EAAYC,EAAAA,eAA+B,WAAW,EACtDC,EAAUD,EAAAA,eAA+B,SAAS,EAClDE,EAAYC,EAAAA,IAAI,EAAK,EACrBC,EAAO,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,EAAG,EAAE,EAE7CC,EAAWC,EAAAA,MAAMT,EAAM,MAAM,EAC7BA,EAAM,OACNU,kBAAgBJ,EAAAA,IAAIN,EAAM,MAAM,CAAC,EAEjCW,EAAKC,EAAAA,SAAS,IAAM,CACtB,GAAKJ,EAAS,iBAAi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M,EAElC,MAAO,CAACW,EAAM,IAAM,CAAC,CAACA,EAAM,KAChC,CAEA,SAASC,EAAoBZ,EAAiC,CAC1D,OAAKA,aAAkB,QAIhBA,EAAO,aAAa,GAAGV,CAAM,KAAK,EAH9B,EAIf,CAEO,MAAMuB,EAA6D,CACtE,YAAYb,EAAQc,EAAS,CACzBf,EAAcC,EAAQ,OAAOc,EAAQ,OAAU,SAAW,CACtD,MAAOA,EAAQ,KAAA,EAChBA,EAAQ,KAAK,CACpB,EACA,cAAcd,EAAQ,CAClBO,EAAeP,CAAM,CACzB,CACJ,EAEO,SAASe,EAAcC,EAAmB,CAC7CA,EAAI,MAAM,CACN,aAAc,CACO,IAAI,iBAAkBC,GAAc,CACjD,SAAU,CAAE,WAAAC,EAAY,aAAAC,CAAA,IAAkBF,EACtCC,EAAW,QAASE,GAAS,CACtBV,EAAoBU,CAAI,GACvBrB,EAAcqB,CAAI,CAE1B,CAAC,EAEDD,EAAa,QAASC,GAAS,CACxBR,EAAoBQ,CAAI,GACvBb,EAAea,CAAI,CAE3B,CAAC,CAET,CAAC,EAEQ,QAAQ,SAAS,KAAM,CAC5B,UAAW,GACX,QAAS,EAAA,CACZ,CACL,EACA,SAAU,CACN,IAAI3B,EAAK,KAAK,IAEX,KAAK,eAAe,OACnBA,EAAK,KAAK,IAAI,YAGlB,MAAM4B,EAAS,SAAS,iBACpB5B,EACA,WAAW,SACV2B,GACQA,aAAgB,QAId,WAAW,cAHP,WAAW,aAI1B,EAGJ,KAAMC,EAAO,YACNX,EAAoBW,EAAO,WAAW,GACrCtB,EAAcsB,EAAO,WAAW,CAG5C,CAAA,CACH,EAEDL,EAAI,UAAwC,UAAWH,CAAgB,CAC3E"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@vue-interface/tooltip",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A Vue tooltip component.",
5
+ "readme": "README.md",
5
6
  "type": "module",
6
7
  "main": "./dist/tooltip.umd.js",
7
8
  "module": "./dist/tooltip.js",
@@ -9,17 +10,16 @@
9
10
  "exports": {
10
11
  ".": {
11
12
  "source": "./index.ts",
12
- "types": "./index.ts",
13
+ "types": "./dist/index.d.ts",
13
14
  "import": "./dist/tooltip.js",
14
15
  "require": "./dist/tooltip.umd.js"
15
16
  },
16
- "./tailwindcss": "./tailwindcss/index.cjs",
17
- "./tailwindcss/safelist": "./tailwindcss/safelist.cjs"
17
+ "./css": "./index.css"
18
18
  },
19
19
  "browserslist": "last 2 versions, > 0.5%, ie >= 11",
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "git+https://github.com/vue-interface/tooltip"
22
+ "url": "git+https://github.com/vue-interface/vue-interface.github.io"
23
23
  },
24
24
  "keywords": [
25
25
  "Tooltip",
@@ -31,9 +31,9 @@
31
31
  "author": "Justin Kimbrell",
32
32
  "license": "ISC",
33
33
  "bugs": {
34
- "url": "https://github.com/vue-interface/tooltip"
34
+ "url": "https://github.com/vue-interface/vue-interface.github.io"
35
35
  },
36
- "homepage": "https://github.com/vue-interface/vue-interface",
36
+ "homepage": "https://github.com/vue-interface/vue-interface.github.io",
37
37
  "dependencies": {
38
38
  "@popperjs/core": "^2.4.4"
39
39
  },
@@ -44,6 +44,14 @@
44
44
  "devDependencies": {
45
45
  "@floating-ui/dom": "^1.7.2"
46
46
  },
47
+ "files": [
48
+ "dist",
49
+ "index.css",
50
+ "README.md"
51
+ ],
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
47
55
  "scripts": {
48
56
  "dev": "vite",
49
57
  "build": "vue-tsc && vite build",
package/CHANGELOG.md DELETED
@@ -1,7 +0,0 @@
1
- # @vue-interface/tooltip
2
-
3
- ## 2.0.0
4
-
5
- ### Major Changes
6
-
7
- - 7119322: Add support for TailwindCSS v4
package/docs/tooltip.md DELETED
@@ -1,156 +0,0 @@
1
- ---
2
- title: Tooltip
3
- ---
4
-
5
- <script setup>
6
- import '../index.css'
7
- import { ref, defineComponent, h, getCurrentInstance } from 'vue'
8
- import { Tooltip, TooltipPlugin } from '../index.ts'
9
-
10
- const dynamicEl = ref(false)
11
- const directiveEl = ref(false)
12
-
13
- const WithTooltip = defineComponent({
14
- name: 'WithTooltip',
15
- setup(_, { slots }) {
16
- const el = ref()
17
- return () =>
18
- h(
19
- 'a',
20
- { ref: el, href: '#', class: 'text-blue-500 hover:underline' },
21
- slots.default?.({ el })
22
- )
23
- }
24
- })
25
-
26
- const app = getCurrentInstance()?.appContext.app
27
- if (app) {
28
- app.use(TooltipPlugin)
29
- app.component('Tooltip', Tooltip)
30
- app.component('with-tooltip', WithTooltip)
31
- }
32
- </script>
33
-
34
- # Tooltip
35
-
36
- The `tooltip` component provides flexible tooltips with customizable placement options.
37
-
38
- ## Basic Usage
39
-
40
- Tooltips can be positioned at the top, bottom, left, or right of the target element.
41
-
42
- <div class="flex gap-4">
43
- <!-- #region basicUsage -->
44
- <with-tooltip v-slot="{el}">
45
- Top
46
- <Tooltip :target="el">
47
- Some Tooltip
48
- </Tooltip>
49
- </with-tooltip>
50
- <with-tooltip v-slot="{el}">
51
- Bottom
52
- <Tooltip :target="el" placement="bottom">
53
- Some Tooltip
54
- </Tooltip>
55
- </with-tooltip>
56
- <with-tooltip v-slot="{el}">
57
- Left
58
- <Tooltip :target="el" placement="left">
59
- Some Tooltip
60
- </Tooltip>
61
- </with-tooltip>
62
- <with-tooltip v-slot="{el}">
63
- Right
64
- <Tooltip :target="el" placement="right">
65
- Some Tooltip
66
- </Tooltip>
67
- </with-tooltip>
68
- <!-- #endregion basicUsage -->
69
- </div>
70
-
71
- ::: details Show Code
72
- <<< @/packages/tooltip/docs/tooltip.md#basicUsage{html}
73
- :::
74
-
75
- ## Via Plugin
76
-
77
- Use the Tooltip plugin to automatically create tooltips from `title` attributes.
78
-
79
- <div class="flex gap-4 [&>a]:text-blue-500 [&>a]:hover:underline">
80
- <!-- #region viaPlugin -->
81
- <a href="#" title="Some Tooltip" data-tooltip-placement="top">
82
- Top
83
- </a>
84
- <a href="#" title="Some Tooltip" data-tooltip-placement="bottom">
85
- Bottom
86
- </a>
87
- <a href="#" title="Some Tooltip" data-tooltip-placement="left">
88
- Left
89
- </a>
90
- <a href="#" title="Some Tooltip" data-tooltip-placement="right">
91
- Right
92
- </a>
93
- <!-- #endregion viaPlugin -->
94
- </div>
95
-
96
- ::: details Show Code
97
- <<< @/packages/tooltip/docs/tooltip.md#viaPlugin{html}
98
- :::
99
-
100
- ## Dynamic Elements
101
-
102
- Tooltips work with dynamically mounted and unmounted elements.
103
-
104
- <div class="flex gap-4 [&>button]:p-2 [&>button]:rounded [&>button]:bg-blue-500">
105
- <!-- #region dynamicElements -->
106
- <button @click="dynamicEl = true">Mount Element</button>
107
- <button v-if="dynamicEl" title="Some Tooltip" @click="dynamicEl = false">
108
- Click to Unmount
109
- </button>
110
- <!-- #endregion dynamicElements -->
111
- </div>
112
-
113
- ::: details Show Code
114
- <<< @/packages/tooltip/docs/tooltip.md#dynamicElements{html}
115
- :::
116
-
117
- ## Via Directive
118
-
119
- Use the `v-tooltip` directive for a more concise syntax.
120
-
121
- <div class="flex gap-4 [&>button]:p-2 [&>button]:rounded [&>button]:bg-blue-500">
122
- <!-- #region viaDirective -->
123
- <button @click="directiveEl = true">Mount Element</button>
124
- <button v-if="directiveEl" v-tooltip="'Some Tooltip'" @click="directiveEl = false">
125
- Click to Unmount
126
- </button>
127
- <button v-if="directiveEl" v-tooltip="{
128
- title: 'Some Tooltip',
129
- placement: 'top'
130
- }" @click="directiveEl = false">
131
- Top
132
- </button>
133
- <button v-if="directiveEl" v-tooltip="{
134
- title: 'Some Tooltip',
135
- placement: 'bottom'
136
- }" @click="directiveEl = false">
137
- Bottom
138
- </button>
139
- <button v-if="directiveEl" v-tooltip="{
140
- title: 'Some Tooltip',
141
- placement: 'left'
142
- }" @click="directiveEl = false">
143
- Left
144
- </button>
145
- <button v-if="directiveEl" v-tooltip="{
146
- title: 'Some Tooltip',
147
- placement: 'right'
148
- }" @click="directiveEl = false">
149
- Right
150
- </button>
151
- <!-- #endregion viaDirective -->
152
- </div>
153
-
154
- ::: details Show Code
155
- <<< @/packages/tooltip/docs/tooltip.md#viaDirective{html}
156
- :::
package/index.html DELETED
@@ -1,140 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6
- <title>Tooltip</title>
7
- </head>
8
- <body class="dark:bg-neutral-900 dark:text-white">
9
- <div id="app" class="container mx-auto flex flex-col gap-6">
10
- <h1 class="text-4xl">tooltip</h1>
11
-
12
- <div class="flex gap-4">
13
- <with-tooltip v-slot="{el}">
14
- Top
15
- <Tooltip :target="el">
16
- Some Toolip
17
- </Tooltip>
18
- </with-tooltip>
19
-
20
- <with-tooltip v-slot="{el}">
21
- Bottom
22
- <Tooltip :target="el" placement="bottom">
23
- Some Toolip
24
- </Tooltip>
25
- </with-tooltip>
26
-
27
- <with-tooltip v-slot="{el}">
28
- Left
29
- <Tooltip :target="el" placement="left">
30
- Some Toolip
31
- </Tooltip>
32
- </with-tooltip>
33
-
34
- <with-tooltip v-slot="{el}">
35
- Right
36
- <Tooltip :target="el" placement="right">
37
- Some Toolip
38
- </Tooltip>
39
- </with-tooltip>
40
- </div>
41
-
42
- <h2 class="text-2xl">Via Plugin</h2>
43
-
44
- <div class="flex gap-4 [&>a]:text-blue-500 [&>a]:hover:underline">
45
- <a href="#" title="Some Tooltip" data-tooltip-placement="top">
46
- Top
47
- </a>
48
- <a href="#" title="Some Tooltip" data-tooltip-placement="bottom">
49
- Bottom
50
- </a>
51
- <a href="#" title="Some Tooltip" data-tooltip-placement="left">
52
- Left
53
- </a>
54
- <a href="#" title="Some Tooltip" data-tooltip-placement="right">
55
- Right
56
- </a>
57
- </div>
58
-
59
- <h2 class="text-2xl">Dynamic Elements</h2>
60
-
61
- <div class="flex gap-4 [&>button]:p-2 [&>button]:rounded [&>button]:bg-blue-500">
62
- <button @click="dynamicEl = true">Mount Element</button>
63
-
64
- <button v-if="dynamicEl" title="Some Tooltip" @click="dynamicEl = false">
65
- Click to Unmount
66
- </button>
67
- </div>
68
-
69
- <h2 class="text-2xl">Via Directive</h2>
70
-
71
- <div class="flex gap-4 [&>button]:p-2 [&>button]:rounded [&>button]:bg-blue-500">
72
- <button @click="directiveEl = true">Mount Element</button>
73
-
74
- <button v-if="directiveEl" v-tooltip="'Some Tooltip'" @click="directiveEl = false">
75
- Click to Unmount
76
- </button>
77
-
78
- <button v-if="directiveEl" v-tooltip="{
79
- title: 'Some Tooltip',
80
- placement: 'top'
81
- }" @click="directiveEl = false">
82
- Top
83
- </button>
84
-
85
- <button v-if="directiveEl" v-tooltip="{
86
- title: 'Some Tooltip',
87
- placement: 'bottom'
88
- }" @click="directiveEl = false">
89
- Bottom
90
- </button>
91
-
92
- <button v-if="directiveEl" v-tooltip="{
93
- title: 'Some Tooltip',
94
- placement: 'left'
95
- }" @click="directiveEl = false">
96
- Left
97
- </button>
98
-
99
- <button v-if="directiveEl" v-tooltip="{
100
- title: 'Some Tooltip',
101
- placement: 'right'
102
- }" @click="directiveEl = false">
103
- Right
104
- </button>
105
- </div>
106
- </div>
107
- <script type="module">
108
- import './index.css';
109
- import { createApp, defineComponent, h, ref, onMounted } from 'vue/dist/vue.esm-bundler';
110
- import { Tooltip, TooltipPlugin } from './index';
111
-
112
- const WithTooltip = defineComponent({
113
- setup(props, a) {
114
- const el = ref();
115
-
116
- return () => h('a', {
117
- ref: el,
118
- href: '#',
119
- classList: 'text-blue-500 hover:underline'
120
- }, a.slots.default({ el }))
121
- }
122
- });
123
-
124
- const vue = createApp({
125
- components: {
126
- WithTooltip,
127
- Tooltip
128
- },
129
- data() {
130
- return {
131
- dynamicEl: false,
132
- directiveEl: false,
133
- }
134
- }
135
- })
136
- .use(TooltipPlugin)
137
- .mount('#app');
138
- </script>
139
- </body>
140
- </html>
package/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import Tooltip from './src/Tooltip.vue';
2
- import { TooltipDirective, TooltipPlugin } from './src/TooltipPlugin';
3
-
4
- export {
5
- Tooltip,
6
- TooltipDirective,
7
- TooltipPlugin
8
- };
package/src/Tooltip.vue DELETED
@@ -1,174 +0,0 @@
1
- <script lang="ts" setup>
2
- import { arrow, autoUpdate, flip as flipFn, FlipOptions, MaybeElement, offset as offsetFn, OffsetOptions, ReferenceElement, useFloating, UseFloatingOptions } from '@floating-ui/vue';
3
- import { computed, isRef, onUnmounted, Ref, ref, shallowReadonly, ShallowRef, useTemplateRef, watchEffect } from 'vue';
4
-
5
- export type TooltipProps = {
6
- title?: string;
7
- show?: boolean;
8
- target?: Ref<MaybeElement<ReferenceElement>> | ReferenceElement;
9
- placement?: UseFloatingOptions['placement'];
10
- strategy?: UseFloatingOptions['strategy'];
11
- middleware?: (arrow: Readonly<ShallowRef<HTMLDivElement | null>>) => UseFloatingOptions['middleware'];
12
- flip?: FlipOptions;
13
- offset?: OffsetOptions;
14
- };
15
-
16
- const props = withDefaults(defineProps<TooltipProps>(), {
17
- title: undefined,
18
- target: undefined,
19
- placement: 'top',
20
- middleware: undefined,
21
- strategy: undefined,
22
- flip: undefined,
23
- offset: undefined,
24
- });
25
-
26
- defineSlots<{
27
- default: () => void
28
- }>();
29
-
30
- const tooltipEl = useTemplateRef<HTMLDivElement>('tooltipEl');
31
- const arrowEl = useTemplateRef<HTMLDivElement>('arrowEl');
32
- const isShowing = ref(false);
33
- const hash = Math.random().toString(36).slice(2, 12);
34
-
35
- const targetEl = isRef(props.target)
36
- ? props.target
37
- : shallowReadonly(ref(props.target));
38
-
39
- const id = computed(() => {
40
- if(!(targetEl.value instanceof Element)) {
41
- return;
42
- }
43
-
44
- return targetEl.value.getAttribute('data-tooltip-id');
45
- });
46
-
47
-
48
- watchEffect(() => {
49
- if(!targetEl.value || id.value) {
50
- return;
51
- }
52
-
53
- if(targetEl.value instanceof Element) {
54
- targetEl.value.setAttribute('data-tooltip-id', hash);
55
- targetEl.value.addEventListener('mouseover', open);
56
- targetEl.value.addEventListener('mouseout', close);
57
- }
58
- });
59
-
60
- watchEffect(() => {
61
- isShowing.value = props.show;
62
- });
63
-
64
- const dynamicOffset = computed<OffsetOptions>(() => {
65
- if(props.offset) {
66
- return props.offset;
67
- }
68
-
69
- return () => {
70
- const { height } = arrowEl.value ? getComputedStyle(arrowEl.value) : { height: '0px' };
71
-
72
- return {
73
- mainAxis: parseInt(height.replace('px', '')),
74
- };
75
- };
76
- });
77
-
78
- const { floatingStyles, middlewareData, placement } = useFloating(targetEl, tooltipEl, {
79
- placement: props.placement,
80
- middleware: props.middleware?.(arrowEl) ?? [
81
- flipFn(props.flip),
82
- offsetFn(dynamicOffset.value),
83
- arrow({
84
- element: arrowEl
85
- }),
86
- ],
87
- whileElementsMounted: autoUpdate
88
- });
89
-
90
- const tooltipClasses = computed(() => {
91
- return {
92
- show: isShowing.value
93
- };
94
- });
95
-
96
- type Side = 'bottom' | 'left' | 'top' | 'right';
97
-
98
- const side = computed(() => placement.value.split('-')[0] as Side);
99
-
100
- const arrowPosition = computed(() => {
101
- return {
102
- top: 'bottom',
103
- right: 'left',
104
- bottom: 'top',
105
- left: 'right'
106
- }[side.value] as Side;
107
- });
108
-
109
- const arrowRotation = computed<Record<Side,string>>(() => ({
110
- top: 'rotate(225deg)',
111
- right: 'rotate(-45deg)',
112
- bottom: 'rotate(45deg)',
113
- left: 'rotate(135deg)',
114
- }));
115
-
116
- function open() {
117
- isShowing.value = true;
118
- }
119
-
120
- function close() {
121
- isShowing.value = false;
122
- }
123
-
124
- onUnmounted(() => {
125
- if(targetEl.value instanceof Element) {
126
- targetEl.value.removeAttribute('data-tooltip-id');
127
- }
128
- });
129
-
130
- defineExpose({
131
- open,
132
- close,
133
- tooltipEl,
134
- arrowEl,
135
- isShowing,
136
- hash,
137
- });
138
- </script>
139
-
140
- <template>
141
- <Teleport to="body">
142
- <div
143
- ref="tooltipEl"
144
- class="tooltip"
145
- role="tooltip"
146
- :data-tooltip-id="hash"
147
- :class="tooltipClasses"
148
- :style="floatingStyles">
149
- <div
150
- ref="arrowEl"
151
- class="tooltip-arrow"
152
- :style="{
153
- transform: arrowRotation[arrowPosition],
154
- ...Object.assign({
155
- left:
156
- middlewareData.arrow?.x != null
157
- ? `${middlewareData.arrow.x}px`
158
- : '',
159
- top:
160
- middlewareData.arrow?.y != null
161
- ? `${middlewareData.arrow.y}px`
162
- : ''
163
- }, {
164
- [arrowPosition]: `calc(${-(arrowEl?.offsetWidth ?? 0) / 2}px)`
165
- })
166
- }" />
167
- <div
168
- ref="inner"
169
- class="tooltip-inner">
170
- <slot>{{ title }}</slot>
171
- </div>
172
- </div>
173
- </Teleport>
174
- </template>
@@ -1,137 +0,0 @@
1
- import { h, render, type App, type Directive } from 'vue';
2
- import Tooltip, { type TooltipProps } from './Tooltip.vue';
3
-
4
- const prefix = 'data-tooltip';
5
- const prefixRegExp = new RegExp(`^${prefix}\-`);
6
-
7
- function getAttributes(el: Element): Record<string,string> {
8
- return Array.from(el.attributes)
9
- .map(a => [a.name, a.value])
10
- .filter(([key]) => key === 'title' || key.match(prefixRegExp))
11
- .map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])
12
- .reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});
13
- }
14
-
15
- function createTooltip(target: Element, props?: TooltipProps) {
16
- const container = document.createElement('template');
17
-
18
- const vnode = h(Tooltip, Object.assign({
19
- target
20
- }, getAttributes(target), props));
21
-
22
- render(vnode, container);
23
-
24
- const title = target.getAttribute('title');
25
-
26
- if(title) {
27
- target.setAttribute(`${prefix}-og-title`, title);
28
- target.removeAttribute('title');
29
- }
30
-
31
- return () => {
32
- if(vnode.component) {
33
- vnode.component.exposed?.tooltipEl.value?.remove();
34
- }
35
- };
36
- }
37
-
38
- function destroyTooltip(target: Element) {
39
- const tooltips = document.querySelectorAll(
40
- `[${prefix}-id="${target.getAttribute(`${prefix}-id`)}"]`
41
- );
42
-
43
- for(const tooltip of tooltips) {
44
- tooltip.remove();
45
- }
46
-
47
- target.removeAttribute(`${prefix}-id`);
48
-
49
- const title = target.getAttribute(`${prefix}-og-title`);
50
-
51
- if(title) {
52
- target.setAttribute('title', title);
53
- }
54
- }
55
-
56
- function shouldCreateTooltip(target: Node): target is Element {
57
- if(!(target instanceof Element)) {
58
- return false;
59
- }
60
-
61
- const attrs = getAttributes(target);
62
-
63
- return !attrs.id && !!attrs.title;
64
- }
65
-
66
- function shouldRemoveTooltip(target: Node): target is Element {
67
- if(!(target instanceof Element)) {
68
- return false;
69
- }
70
-
71
- return target.hasAttribute(`${prefix}-id`);
72
- }
73
-
74
- export const TooltipDirective: Directive<Element, string|TooltipProps> = {
75
- beforeMount(target, binding) {
76
- createTooltip(target, typeof binding.value === 'string' ? {
77
- title: binding.value
78
- }: binding.value);
79
- },
80
- beforeUnmount(target) {
81
- destroyTooltip(target);
82
- }
83
- };
84
-
85
- export function TooltipPlugin(app: App<Element>) {
86
- app.mixin({
87
- beforeMount() {
88
- const observer = new MutationObserver((mutations) => {
89
- for(const { addedNodes, removedNodes } of mutations) {
90
- addedNodes.forEach((node) => {
91
- if(shouldCreateTooltip(node)) {
92
- createTooltip(node);
93
- }
94
- });
95
-
96
- removedNodes.forEach((node) => {
97
- if(shouldRemoveTooltip(node)) {
98
- destroyTooltip(node);
99
- }
100
- });
101
- }
102
- });
103
-
104
- observer.observe(document.body, {
105
- childList: true,
106
- subtree: true
107
- });
108
- },
109
- mounted() {
110
- let el = this.$el;
111
-
112
- if(this.$el instanceof Text) {
113
- el = this.$el.parentNode;
114
- }
115
-
116
- const walker = document.createTreeWalker(
117
- el,
118
- NodeFilter.SHOW_ALL,
119
- (node: Node) => {
120
- if(!(node instanceof Element)) {
121
- return NodeFilter.FILTER_REJECT;
122
- }
123
-
124
- return NodeFilter.FILTER_ACCEPT;
125
- }
126
- );
127
-
128
- while(walker.nextNode()) {
129
- if(shouldCreateTooltip(walker.currentNode)) {
130
- createTooltip(walker.currentNode);
131
- }
132
- }
133
- }
134
- });
135
-
136
- app.directive<Element, string|TooltipProps>('tooltip', TooltipDirective);
137
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
- "module": "ESNext",
7
- "skipLibCheck": true,
8
- "moduleResolution": "bundler",
9
- "customConditions": ["source"],
10
- "allowImportingTsExtensions": true,
11
- "resolveJsonModule": true,
12
- "isolatedModules": true,
13
- "noEmit": true,
14
- "strict": true,
15
- "noUnusedLocals": true,
16
- "noUnusedParameters": true,
17
- "noFallthroughCasesInSwitch": true,
18
- "jsx": "preserve",
19
- "jsxImportSource": "vue"
20
- },
21
- "include": [
22
- "**/*.ts",
23
- "**/*.tsx",
24
- "**/*.vue",
25
- ],
26
- "exclude": ["node_modules"]
27
- }
package/vite.config.js DELETED
@@ -1,47 +0,0 @@
1
- import tailwindcss from '@tailwindcss/vite';
2
- import vue from '@vitejs/plugin-vue';
3
- import { pascalCase } from 'change-case';
4
- import path from 'path';
5
- import { defineConfig } from 'vite';
6
- import dts from 'vite-plugin-dts';
7
- import pkg from './package.json';
8
-
9
- const fileName = pkg.name.split('/')[1];
10
-
11
- const external = [
12
- ...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
13
- ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])
14
- ];
15
-
16
- export default ({ command }) => defineConfig({
17
- build: {
18
- sourcemap: command === 'build',
19
- lib: {
20
- entry: path.resolve(__dirname, 'index.ts'),
21
- name: pascalCase(fileName),
22
- fileName,
23
- },
24
- rollupOptions: {
25
- external,
26
- output: {
27
- globals: external.reduce((carry, dep) => {
28
- return Object.assign(carry, {
29
- [dep]: pascalCase(dep)
30
- });
31
- }, {}),
32
- }
33
- },
34
- watch: !process.env.NODE_ENV && {
35
- include: [
36
- './tailwindcss/**/*.js'
37
- ]
38
- }
39
- },
40
- plugins: [
41
- vue(),
42
- dts({
43
- entryRoot: path.resolve(__dirname, './'),
44
- }),
45
- tailwindcss()
46
- ],
47
- });