Skip to content

Commit f621b14

Browse files
committed
docs(vueltip): add more comprehensive docs
1 parent 36adc3f commit f621b14

1 file changed

Lines changed: 74 additions & 18 deletions

File tree

packages/vueltip/README.md

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ pnpm add vueltip
1919
Register the tooltip in your app:
2020

2121
```ts
22-
import Vueltip from 'vueltip'
22+
import { vueltipPlugin, vueltipDirective } from 'vueltip'
2323

24-
createApp(App).use(Vueltip)
24+
createApp(App)
25+
.use(vueltipPlugin, { component: Tooltip })
26+
.directive('tooltip', vueltipDirective)
2527
```
2628

2729
## Usage
@@ -49,19 +51,18 @@ First, create a tooltip component using the \`useTooltip\` composable:
4951
</template>
5052

5153
<script setup>
52-
import { ref } from 'vue'
53-
import { useTooltip } from 'vueltip'
54+
import { useTemplateRef } from 'vue'
55+
import { useVueltip } from 'vueltip'
5456

55-
const tooltipElement = ref()
56-
const arrowElement = ref()
57+
const tooltipElement = useTemplateRef('tooltipElement')
58+
const arrowElement = useTemplateRef('arrowElement')
5759

5860
const { tooltipStyles, arrowStyles, show, content } =
59-
useTooltip({
61+
useVueltip({
6062
tooltipElement,
6163
arrowElement,
6264
offset: 8,
6365
padding: 8,
64-
arrowSize: 10,
6566
})
6667
</script>
6768

@@ -89,14 +90,16 @@ Import and register the tooltip component and plugin in your app's entry point:
8990
// main.ts
9091
import { createApp } from 'vue'
9192
import App from './App.vue'
92-
import Vueltip from 'vueltip'
93+
import { vueltipPlugin, vueltipDirective } from 'vueltip'
9394
import Tooltip from './components/Tooltip.vue'
9495

9596
const app = createApp(App)
9697

97-
app.use(Vueltip, {
98-
component: Tooltip,
99-
})
98+
app
99+
.use(vueltipPlugin, {
100+
component: Tooltip,
101+
})
102+
.directive('tooltip', vueltipDirective)
100103

101104
app.mount('#app')
102105
```
@@ -105,24 +108,77 @@ app.mount('#app')
105108

106109
Now you can use the `v-tooltip` directive on any element:
107110

108-
```ts
111+
```vue
109112
<template>
110113
<div>
111-
<button v-tooltip="{ text: 'Click me to submit' }">
112-
Submit
113-
</button>
114+
<button v-tooltip="'Click me to submit'">Submit</button>
114115
115116
<input
116-
v-tooltip="{ text: 'Enter your email address' }"
117+
v-tooltip="'Enter your email address'"
117118
type="email"
118119
placeholder="Email"
119120
/>
120121
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+
>
122128
Hover over me
123129
</span>
124130
</div>
125131
</template>
126132
```
127133

128134
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+
```

0 commit comments

Comments
 (0)