@vingy/vueltip 1.2.0 → 1.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 CHANGED
@@ -19,9 +19,11 @@ pnpm add vueltip
19
19
  Register the tooltip in your app:
20
20
 
21
21
  ```ts
22
- import Vueltip from 'vueltip'
22
+ import { vueltipPlugin, vueltipDirective } from 'vueltip'
23
23
 
24
- createApp(App).use(Vueltip)
24
+ createApp(App)
25
+ .use(vueltipPlugin, { component: Tooltip })
26
+ .directive('tooltip', vueltipDirective)
25
27
  ```
26
28
 
27
29
  ## Usage
@@ -49,19 +51,18 @@ First, create a tooltip component using the \`useTooltip\` composable:
49
51
  </template>
50
52
 
51
53
  <script setup>
52
- import { ref } from 'vue'
53
- import { useTooltip } from 'vueltip'
54
+ import { useTemplateRef } from 'vue'
55
+ import { useVueltip } from 'vueltip'
54
56
 
55
- const tooltipElement = ref()
56
- const arrowElement = ref()
57
+ const tooltipElement = useTemplateRef('tooltipElement')
58
+ const arrowElement = useTemplateRef('arrowElement')
57
59
 
58
60
  const { tooltipStyles, arrowStyles, show, content } =
59
- useTooltip({
61
+ useVueltip({
60
62
  tooltipElement,
61
63
  arrowElement,
62
64
  offset: 8,
63
65
  padding: 8,
64
- arrowSize: 10,
65
66
  })
66
67
  </script>
67
68
 
@@ -89,14 +90,16 @@ Import and register the tooltip component and plugin in your app's entry point:
89
90
  // main.ts
90
91
  import { createApp } from 'vue'
91
92
  import App from './App.vue'
92
- import Vueltip from 'vueltip'
93
+ import { vueltipPlugin, vueltipDirective } from 'vueltip'
93
94
  import Tooltip from './components/Tooltip.vue'
94
95
 
95
96
  const app = createApp(App)
96
97
 
97
- app.use(Vueltip, {
98
- component: Tooltip,
99
- })
98
+ app
99
+ .use(vueltipPlugin, {
100
+ component: Tooltip,
101
+ })
102
+ .directive('tooltip', vueltipDirective)
100
103
 
101
104
  app.mount('#app')
102
105
  ```
@@ -105,20 +108,23 @@ app.mount('#app')
105
108
 
106
109
  Now you can use the `v-tooltip` directive on any element:
107
110
 
108
- ```ts
111
+ ```vue
109
112
  <template>
110
113
  <div>
111
- <button v-tooltip="{ text: 'Click me to submit' }">
112
- Submit
113
- </button>
114
+ <button v-tooltip="'Click me to submit'">Submit</button>
114
115
 
115
116
  <input
116
- v-tooltip="{ text: 'Enter your email address' }"
117
+ v-tooltip="'Enter your email address'"
117
118
  type="email"
118
119
  placeholder="Email"
119
120
  />
120
121
 
121
- <span v-tooltip="{ text: 'This is a helpful tooltip' }">
122
+ <span
123
+ v-tooltip="{
124
+ content: 'This is a helpful tooltip',
125
+ placement: 'right',
126
+ }"
127
+ >
122
128
  Hover over me
123
129
  </span>
124
130
  </div>
@@ -126,3 +132,53 @@ Now you can use the `v-tooltip` directive on any element:
126
132
  ```
127
133
 
128
134
  See the demo app in [demo/](../../demo/).
135
+
136
+ ## Options
137
+
138
+ ### Plugin Options
139
+
140
+ The `vueltipPlugin` accepts the following options:
141
+
142
+ | Option | Type | Default | Description |
143
+ | -------------------------- | -------------------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------- |
144
+ | `component` | `Component` | Required | The Vue component to render as the tooltip |
145
+ | `showDelay` | `number` | `0` | Delay in milliseconds before the tooltip appears on hover |
146
+ | `hideDelay` | `number` | `200` | Delay in milliseconds before the tooltip disappears when the cursor leaves |
147
+ | `defaultPlacement` | `Placement` | `'top'` | Default tooltip placement: `'top'`, `'bottom'`, `'left'`, `'right'`, etc. |
148
+ | `defaultTruncateDetection` | `'x' \| 'y' \| 'both' \| 'none'` | `'both'` | Direction(s) to check for text truncation (`'x'` for horizontal, `'y'` for vertical, `'both'`, or `'none'` to disable) |
149
+ | `handleDialogModals` | `boolean` | `false` | Whether to handle tooltips within HTML `<dialog>` elements with the `open` attribute (modal dialogs) |
150
+ | `placementAttribute` | `string` | `'vueltip-placement'` | HTML attribute name for tooltip placement overrides |
151
+ | `keyAttribute` | `string` | `'vueltip-key'` | HTML attribute name for tooltip identification |
152
+ | `truncateAttribute` | `string` | `'vueltip-truncate'` | HTML attribute name for truncate detection overrides |
153
+
154
+ ### useVueltip Composable Options
155
+
156
+ The `useVueltip` composable accepts the following options:
157
+
158
+ | Option | Type | Default | Description |
159
+ | ----------------- | -------------------------- | -------- | ---------------------------------------------------------- |
160
+ | `tooltipElement` | `Ref<HTMLElement \| null>` | Required | Reference to the tooltip container element |
161
+ | `arrowElement` | `Ref<HTMLElement \| null>` | Optional | Reference to the arrow element for positioning |
162
+ | `offset` | `number` | `0` | Offset distance between the tooltip and the target element |
163
+ | `padding` | `number` | `0` | Padding between the tooltip and the viewport edges |
164
+ | `arrowSize` | `number` | `0` | Size of the arrow element (used for proper positioning) |
165
+ | `floatingOptions` | `UseFloatingOptions` | `{}` | Advanced options for the underlying Floating UI library |
166
+
167
+ ### Directive Options
168
+
169
+ The `v-tooltip` directive accepts bindings in two formats:
170
+
171
+ **Simple string (text only):**
172
+
173
+ ```ts
174
+ v-tooltip="'Tooltip text'"
175
+ ```
176
+
177
+ **Object with options:**
178
+
179
+ ```ts
180
+ v-tooltip="{
181
+ content: 'Tooltip text',
182
+ placement: 'right' // Placement: 'top', 'bottom', 'left', 'right', etc.
183
+ }"
184
+ ```
package/dist/index.d.mts CHANGED
@@ -244,12 +244,16 @@ declare type UseFloatingOptions<T extends ReferenceElement = ReferenceElement> =
244
244
  whileElementsMounted?: (reference: T, floating: FloatingElement, update: () => void) => () => void;
245
245
  };
246
246
  //#endregion
247
+ //#region ../shared/dist/types.d.mts
248
+ //#region src/types.d.ts
249
+ type Maybe<T> = T | null | undefined; //#endregion
250
+ //#endregion
247
251
  //#region src/types.d.ts
248
252
  interface Content {
249
- text: string;
253
+ text: Maybe<string>;
250
254
  }
251
- type Binding = string | {
252
- content: string | Content;
255
+ type Binding = Maybe<string> | {
256
+ content: Maybe<string | Content>;
253
257
  placement: Placement;
254
258
  };
255
259
  type Modifier = 'x' | 'y' | 'none' | 'both';
@@ -278,10 +282,6 @@ declare module 'vue' {
278
282
  }
279
283
  }
280
284
  //#endregion
281
- //#region ../shared/dist/types.d.mts
282
- //#region src/types.d.ts
283
- type Maybe<T> = T | null | undefined; //#endregion
284
- //#endregion
285
285
  //#region src/composables.d.ts
286
286
  declare const useVueltip: ({
287
287
  tooltipElement,
package/dist/index.mjs CHANGED
@@ -1548,7 +1548,7 @@ const onMouseover = ensureEventTarget((target) => ensureKey(target, (key) => {
1548
1548
  const content = getContent(key);
1549
1549
  if (!content) return;
1550
1550
  const { text } = content;
1551
- if (elementContainsText(target, text) && !isTruncated(target)) return;
1551
+ if (!text || elementContainsText(target, text) && !isTruncated(target)) return;
1552
1552
  const placement = target.getAttribute(getOption("placementAttribute"));
1553
1553
  tooltipKey.value = key;
1554
1554
  hoveredElement.value = target;
@@ -1561,10 +1561,16 @@ const onMouseout = ensureEventTarget((target) => {
1561
1561
 
1562
1562
  //#endregion
1563
1563
  //#region src/directive.ts
1564
- const toContent = (value) => typeof value === "string" ? { text: value } : typeof value.content === "string" ? { text: value.content } : value.content;
1564
+ const toContent = (value) => {
1565
+ if (value == null) return { text: value };
1566
+ if (typeof value === "string") return { text: value };
1567
+ if (value.content == null) return { text: value.content };
1568
+ if (typeof value.content === "string") return { text: value.content };
1569
+ return value.content;
1570
+ };
1565
1571
  const extractPlacement = (binding) => {
1566
1572
  const { value, arg } = binding;
1567
- if (typeof value !== "string" && "placement" in value) return value.placement;
1573
+ if (value && typeof value !== "string" && "placement" in value) return value.placement;
1568
1574
  if (!arg) return getOption("defaultPlacement");
1569
1575
  return arg;
1570
1576
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vingy/vueltip",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Headless tooltip which only shows when necessary.",
5
5
  "keywords": [
6
6
  "composition-api",