@vingy/vueltip 0.1.0 → 0.3.0

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/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Vueltip
2
+
3
+ A headless tooltip component for Vue.js.
4
+
5
+ ## Features
6
+
7
+ - **Dynamic Visibility**: The tooltip does not display when the tooltip text is identical to the element's content, unless the content is truncated.
8
+ - **Single Tooltip Instance**: A single tooltip is used, which is repositioned within the window as needed.
9
+ - **Headless Design**: Fully customizable; bring your own component(s) for rendering.
10
+
11
+ ## Quick Start
12
+
13
+ To install Vueltip, use npm or yarn:
14
+
15
+ ```bash
16
+ pnpm add vueltip
17
+ ```
18
+
19
+ Register the tooltip in your app:
20
+
21
+ ```ts
22
+ import Vueltip from 'vueltip'
23
+
24
+ createApp(App).use(Vueltip)
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### 1. Create a Tooltip Component
30
+
31
+ First, create a tooltip component using the \`useTooltip\` composable:
32
+
33
+ ```ts
34
+ <!-- Tooltip.vue -->
35
+ <template>
36
+ <div
37
+ ref="tooltipElement"
38
+ v-show="show"
39
+ :style="tooltipStyles"
40
+ class="tooltip"
41
+ >
42
+ {{ content }}
43
+ <div
44
+ ref="arrowElement"
45
+ :style="arrowStyles"
46
+ class="tooltip-arrow"
47
+ />
48
+ </div>
49
+ </template>
50
+
51
+ <script setup>
52
+ import { ref } from 'vue'
53
+ import { useTooltip } from 'vueltip'
54
+
55
+ const tooltipElement = ref()
56
+ const arrowElement = ref()
57
+
58
+ const { tooltipStyles, arrowStyles, show, content } =
59
+ useTooltip({
60
+ tooltipElement,
61
+ arrowElement,
62
+ offset: 8,
63
+ padding: 8,
64
+ arrowSize: 10,
65
+ })
66
+ </script>
67
+
68
+ <style scoped>
69
+ .tooltip {
70
+ background: #333;
71
+ color: white;
72
+ padding: 8px 12px;
73
+ border-radius: 4px;
74
+ font-size: 14px;
75
+ z-index: 9999;
76
+ }
77
+
78
+ .tooltip-arrow {
79
+ background: #333;
80
+ }
81
+ </style>
82
+ ```
83
+
84
+ ### 2. Register in Your App
85
+
86
+ Import and register the tooltip component and plugin in your app's entry point:
87
+
88
+ ```ts
89
+ // main.ts
90
+ import { createApp } from 'vue'
91
+ import App from './App.vue'
92
+ import Vueltip from 'vueltip'
93
+ import Tooltip from './components/Tooltip.vue'
94
+
95
+ const app = createApp(App)
96
+
97
+ app.use(Vueltip, {
98
+ component: Tooltip,
99
+ })
100
+
101
+ app.mount('#app')
102
+ ```
103
+
104
+ ### 3. Use the Directive
105
+
106
+ Now you can use the `v-tooltip` directive on any element:
107
+
108
+ ```ts
109
+ <template>
110
+ <div>
111
+ <button v-tooltip="{ text: 'Click me to submit' }">
112
+ Submit
113
+ </button>
114
+
115
+ <input
116
+ v-tooltip="{ text: 'Enter your email address' }"
117
+ type="email"
118
+ placeholder="Email"
119
+ />
120
+
121
+ <span v-tooltip="{ text: 'This is a helpful tooltip' }">
122
+ Hover over me
123
+ </span>
124
+ </div>
125
+ </template>
126
+ ```
127
+
128
+ See the demo app in [demo/](../../demo/).
@@ -0,0 +1,36 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __exportAll = (all, no_symbols) => {
7
+ let target = {};
8
+ for (var name in all) {
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ }
14
+ if (!no_symbols) {
15
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ }
17
+ return target;
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
22
+ key = keys[i];
23
+ if (!__hasOwnProp.call(to, key) && key !== except) {
24
+ __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ }
30
+ }
31
+ return to;
32
+ };
33
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
34
+
35
+ //#endregion
36
+ export { __reExport as n, __exportAll as t };
@@ -0,0 +1,301 @@
1
+ import { n as __reExport, t as __exportAll } from "./chunk-CtajNgzt.mjs";
2
+ import * as Vue from "vue";
3
+ import { App, Component, ShallowRef, StyleValue } from "vue";
4
+
5
+ //#region ../../node_modules/.pnpm/@floating-ui+utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.d.mts
6
+ declare type AlignedPlacement = `${Side}-${Alignment}`;
7
+ declare type Alignment = 'start' | 'end';
8
+ declare type Axis = 'x' | 'y';
9
+ declare type ClientRectObject = Prettify$1<Rect & SideObject>;
10
+ declare type Coords = { [key in Axis]: number };
11
+ declare type Dimensions = { [key in Length]: number };
12
+ declare interface ElementRects {
13
+ reference: Rect;
14
+ floating: Rect;
15
+ }
16
+ declare type Length = 'width' | 'height';
17
+ declare type Padding = number | Prettify$1<Partial<SideObject>>;
18
+ declare type Placement = Prettify$1<Side | AlignedPlacement>;
19
+ declare type Prettify$1<T> = { [K in keyof T]: T[K] } & {};
20
+ declare type Rect = Prettify$1<Coords & Dimensions>;
21
+ declare type Side = 'top' | 'right' | 'bottom' | 'left';
22
+ declare type SideObject = { [key in Side]: number };
23
+ declare type Strategy = 'absolute' | 'fixed';
24
+ //#endregion
25
+ //#region ../../node_modules/.pnpm/@floating-ui+core@1.7.4/node_modules/@floating-ui/core/dist/floating-ui.core.d.mts
26
+ declare type Boundary = any;
27
+ /**
28
+ * Function option to derive middleware options from state.
29
+ */
30
+ declare type Derivable<T> = (state: MiddlewareState$1) => T;
31
+ /**
32
+ * Resolves with an object of overflow side offsets that determine how much the
33
+ * element is overflowing a given clipping boundary on each side.
34
+ * - positive = overflowing the boundary by that number of pixels
35
+ * - negative = how many pixels left before it will overflow
36
+ * - 0 = lies flush with the boundary
37
+ * @see https://floating-ui.com/docs/detectOverflow
38
+ */
39
+ declare function detectOverflow(state: MiddlewareState$1, options?: DetectOverflowOptions | Derivable<DetectOverflowOptions>): Promise<SideObject>;
40
+ declare interface DetectOverflowOptions {
41
+ /**
42
+ * The clipping element(s) or area in which overflow will be checked.
43
+ * @default 'clippingAncestors'
44
+ */
45
+ boundary?: Boundary;
46
+ /**
47
+ * The root clipping area in which overflow will be checked.
48
+ * @default 'viewport'
49
+ */
50
+ rootBoundary?: RootBoundary;
51
+ /**
52
+ * The element in which overflow is being checked relative to a boundary.
53
+ * @default 'floating'
54
+ */
55
+ elementContext?: ElementContext;
56
+ /**
57
+ * Whether to check for overflow using the alternate element's boundary
58
+ * (`clippingAncestors` boundary only).
59
+ * @default false
60
+ */
61
+ altBoundary?: boolean;
62
+ /**
63
+ * Virtual padding for the resolved overflow detection offsets.
64
+ * @default 0
65
+ */
66
+ padding?: Padding;
67
+ }
68
+ declare type ElementContext = 'reference' | 'floating';
69
+ declare interface Elements$1 {
70
+ reference: ReferenceElement$1;
71
+ floating: FloatingElement$1;
72
+ }
73
+ declare type FloatingElement$1 = any;
74
+ declare type Middleware$1 = {
75
+ name: string;
76
+ options?: any;
77
+ fn: (state: MiddlewareState$1) => Promisable$1<MiddlewareReturn>;
78
+ };
79
+ declare interface MiddlewareData {
80
+ [key: string]: any;
81
+ arrow?: Partial<Coords> & {
82
+ centerOffset: number;
83
+ alignmentOffset?: number;
84
+ };
85
+ autoPlacement?: {
86
+ index?: number;
87
+ overflows: Array<{
88
+ placement: Placement;
89
+ overflows: Array<number>;
90
+ }>;
91
+ };
92
+ flip?: {
93
+ index?: number;
94
+ overflows: Array<{
95
+ placement: Placement;
96
+ overflows: Array<number>;
97
+ }>;
98
+ };
99
+ hide?: {
100
+ referenceHidden?: boolean;
101
+ escaped?: boolean;
102
+ referenceHiddenOffsets?: SideObject;
103
+ escapedOffsets?: SideObject;
104
+ };
105
+ offset?: Coords & {
106
+ placement: Placement;
107
+ };
108
+ shift?: Coords & {
109
+ enabled: { [key in Axis]: boolean };
110
+ };
111
+ }
112
+ declare interface MiddlewareReturn extends Partial<Coords> {
113
+ data?: {
114
+ [key: string]: any;
115
+ };
116
+ reset?: boolean | {
117
+ placement?: Placement;
118
+ rects?: boolean | ElementRects;
119
+ };
120
+ }
121
+ declare interface MiddlewareState$1 extends Coords {
122
+ initialPlacement: Placement;
123
+ placement: Placement;
124
+ strategy: Strategy;
125
+ middlewareData: MiddlewareData;
126
+ elements: Elements$1;
127
+ rects: ElementRects;
128
+ platform: {
129
+ detectOverflow: typeof detectOverflow;
130
+ } & Platform;
131
+ }
132
+ /**
133
+ * Platform interface methods to work with the current platform.
134
+ * @see https://floating-ui.com/docs/platform
135
+ */
136
+ declare interface Platform {
137
+ getElementRects: (args: {
138
+ reference: ReferenceElement$1;
139
+ floating: FloatingElement$1;
140
+ strategy: Strategy;
141
+ }) => Promisable$1<ElementRects>;
142
+ getClippingRect: (args: {
143
+ element: any;
144
+ boundary: Boundary;
145
+ rootBoundary: RootBoundary;
146
+ strategy: Strategy;
147
+ }) => Promisable$1<Rect>;
148
+ getDimensions: (element: any) => Promisable$1<Dimensions>;
149
+ convertOffsetParentRelativeRectToViewportRelativeRect?: (args: {
150
+ elements?: Elements$1;
151
+ rect: Rect;
152
+ offsetParent: any;
153
+ strategy: Strategy;
154
+ }) => Promisable$1<Rect>;
155
+ getOffsetParent?: (element: any) => Promisable$1<any>;
156
+ isElement?: (value: any) => Promisable$1<boolean>;
157
+ getDocumentElement?: (element: any) => Promisable$1<any>;
158
+ getClientRects?: (element: any) => Promisable$1<Array<ClientRectObject>>;
159
+ isRTL?: (element: any) => Promisable$1<boolean>;
160
+ getScale?: (element: any) => Promisable$1<{
161
+ x: number;
162
+ y: number;
163
+ }>;
164
+ detectOverflow?: typeof detectOverflow;
165
+ }
166
+ declare type Promisable$1<T> = T | Promise<T>;
167
+ declare type ReferenceElement$1 = any;
168
+ declare type RootBoundary = 'viewport' | 'document' | Rect;
169
+ //#endregion
170
+ //#region ../../node_modules/.pnpm/@floating-ui+dom@1.7.5/node_modules/@floating-ui/dom/dist/floating-ui.dom.d.mts
171
+ declare interface Elements {
172
+ reference: ReferenceElement;
173
+ floating: FloatingElement;
174
+ }
175
+ declare type FloatingElement = HTMLElement;
176
+ declare type Middleware = Prettify<Omit<Middleware$1, 'fn'> & {
177
+ fn(state: MiddlewareState): Promisable<MiddlewareReturn>;
178
+ }>;
179
+ declare type MiddlewareState = Prettify<Omit<MiddlewareState$1, 'elements'> & {
180
+ elements: Elements;
181
+ }>;
182
+ declare type Prettify<T> = { [K in keyof T]: T[K] } & {};
183
+ declare type Promisable<T> = T | Promise<T>;
184
+ declare type ReferenceElement = Element | VirtualElement;
185
+ /**
186
+ * Custom positioning reference element.
187
+ * @see https://floating-ui.com/docs/virtual-elements
188
+ */
189
+ declare interface VirtualElement {
190
+ getBoundingClientRect(): ClientRectObject;
191
+ getClientRects?(): Array<ClientRectObject> | DOMRectList;
192
+ contextElement?: Element;
193
+ }
194
+ declare namespace index_d_exports {
195
+ export { V as Vue, Vue2, del, install, isVue2, isVue3, set };
196
+ }
197
+ import * as import_vue from "vue";
198
+ declare const isVue2: boolean;
199
+ declare const isVue3: boolean;
200
+ declare const Vue2: any;
201
+ declare const install: (vue?: any) => void;
202
+ /**
203
+ * @deprecated To avoid bringing in all the tree-shakable modules, this API has been deprecated. Use `Vue2` or named exports instead.
204
+ * Refer to https://github.com/vueuse/vue-demi/issues/41
205
+ */
206
+ declare const V: typeof Vue;
207
+ declare function set<T>(target: any, key: any, val: T): T;
208
+ declare function del(target: any, key: any): void;
209
+ //#endregion
210
+ //#region ../../node_modules/.pnpm/@floating-ui+vue@1.1.10_vue@3.5.28_typescript@5.9.3_/node_modules/@floating-ui/vue/dist/floating-ui.vue.d.mts
211
+ declare type MaybeReadonlyRef<T> = T | Readonly<index_d_exports.Ref<T>>;
212
+ declare type MaybeReadonlyRefOrGetter<T> = MaybeReadonlyRef<T> | (() => T);
213
+ declare type UseFloatingOptions<T extends ReferenceElement = ReferenceElement> = {
214
+ /**
215
+ * Represents the open/close state of the floating element.
216
+ * @default true
217
+ */
218
+ open?: MaybeReadonlyRefOrGetter<boolean | undefined>;
219
+ /**
220
+ * Where to place the floating element relative to its reference element.
221
+ * @default 'bottom'
222
+ */
223
+ placement?: MaybeReadonlyRefOrGetter<Placement | undefined>;
224
+ /**
225
+ * The type of CSS position property to use.
226
+ * @default 'absolute'
227
+ */
228
+ strategy?: MaybeReadonlyRefOrGetter<Strategy | undefined>;
229
+ /**
230
+ * These are plain objects that modify the positioning coordinates in some fashion, or provide useful data for the consumer to use.
231
+ * @default undefined
232
+ */
233
+ middleware?: MaybeReadonlyRefOrGetter<Middleware[] | undefined>;
234
+ /**
235
+ * Whether to use `transform` instead of `top` and `left` styles to
236
+ * position the floating element (`floatingStyles`).
237
+ * @default true
238
+ */
239
+ transform?: MaybeReadonlyRefOrGetter<boolean | undefined>;
240
+ /**
241
+ * Callback to handle mounting/unmounting of the elements.
242
+ * @default undefined
243
+ */
244
+ whileElementsMounted?: (reference: T, floating: FloatingElement, update: () => void) => () => void;
245
+ };
246
+ //#endregion
247
+ //#region src/types.d.ts
248
+ interface Content {
249
+ text: string;
250
+ }
251
+ type Options = {
252
+ /** @default 'tooltip-placement' */placementAttribute: string; /** @default 'tooltip-key' */
253
+ keyAttribute: string; /** @default 0 */
254
+ showDelay: number; /** @default 200 */
255
+ hideDelay: number; /** @default false */
256
+ handleDialogModals: boolean;
257
+ };
258
+ type UseTooltipOptions = {
259
+ tooltipElement: Readonly<ShallowRef<HTMLElement | null>>;
260
+ arrowElement?: Readonly<ShallowRef<HTMLElement | null>>;
261
+ offset?: number;
262
+ padding?: number;
263
+ arrowSize?: number;
264
+ floatingOptions?: UseFloatingOptions<HTMLElement>;
265
+ };
266
+ //#endregion
267
+ //#region src/composables.d.ts
268
+ declare const useTooltip: ({
269
+ tooltipElement,
270
+ arrowElement,
271
+ offset: _offset,
272
+ padding,
273
+ arrowSize,
274
+ floatingOptions
275
+ }: UseTooltipOptions) => {
276
+ tooltipStyles: Readonly<Vue.Ref<{
277
+ position: Strategy;
278
+ top: string;
279
+ left: string;
280
+ transform?: string;
281
+ willChange?: string;
282
+ }, {
283
+ position: Strategy;
284
+ top: string;
285
+ left: string;
286
+ transform?: string;
287
+ willChange?: string;
288
+ }>>;
289
+ arrowStyles: Vue.ComputedRef<StyleValue>;
290
+ show: Vue.ComputedRef<boolean>;
291
+ content: Vue.Ref<Maybe<Content>, Maybe<Content>>;
292
+ };
293
+ //#endregion
294
+ //#region src/plugin.d.ts
295
+ declare const tooltipPlugin: {
296
+ install: (app: App, options: Partial<Options> & {
297
+ component: Component;
298
+ }) => void;
299
+ };
300
+ //#endregion
301
+ export { type Content, tooltipPlugin, useTooltip };