v-float 0.7.2 → 0.9.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/LICENSE +20 -20
- package/README.md +346 -327
- package/dist/composables/index.d.ts +1 -3
- package/dist/composables/index.d.ts.map +1 -1
- package/dist/composables/interactions/index.d.ts +2 -2
- package/dist/composables/interactions/index.d.ts.map +1 -1
- package/dist/composables/interactions/navigation-strategies.d.ts +36 -0
- package/dist/composables/interactions/navigation-strategies.d.ts.map +1 -0
- package/dist/composables/interactions/polygon.d.ts +2 -2
- package/dist/composables/interactions/polygon.d.ts.map +1 -1
- package/dist/composables/interactions/use-click.d.ts +2 -2
- package/dist/composables/interactions/use-click.d.ts.map +1 -1
- package/dist/composables/interactions/use-escape-key.d.ts +2 -2
- package/dist/composables/interactions/use-escape-key.d.ts.map +1 -1
- package/dist/composables/interactions/use-focus-trap.d.ts +41 -0
- package/dist/composables/interactions/use-focus-trap.d.ts.map +1 -0
- package/dist/composables/interactions/use-focus.d.ts +30 -25
- package/dist/composables/interactions/use-focus.d.ts.map +1 -1
- package/dist/composables/interactions/use-hover.d.ts +2 -2
- package/dist/composables/interactions/use-hover.d.ts.map +1 -1
- package/dist/composables/interactions/use-list-navigation.d.ts +109 -0
- package/dist/composables/interactions/use-list-navigation.d.ts.map +1 -0
- package/dist/composables/middlewares/arrow.d.ts +1 -2
- package/dist/composables/middlewares/arrow.d.ts.map +1 -1
- package/dist/composables/middlewares/index.d.ts +2 -1
- package/dist/composables/middlewares/index.d.ts.map +1 -1
- package/dist/composables/positioning/index.d.ts +5 -0
- package/dist/composables/positioning/index.d.ts.map +1 -0
- package/dist/composables/positioning/use-arrow.d.ts.map +1 -0
- package/dist/composables/{interactions → positioning}/use-client-point.d.ts +2 -2
- package/dist/composables/positioning/use-client-point.d.ts.map +1 -0
- package/dist/composables/{use-floating-tree.d.ts → positioning/use-floating-tree.d.ts} +134 -11
- package/dist/composables/positioning/use-floating-tree.d.ts.map +1 -0
- package/dist/composables/{use-floating.d.ts → positioning/use-floating.d.ts} +21 -6
- package/dist/composables/positioning/use-floating.d.ts.map +1 -0
- package/dist/composables/utils/is-using-keyboard.d.ts +2 -0
- package/dist/composables/utils/is-using-keyboard.d.ts.map +1 -0
- package/dist/composables/utils/use-active-descendant.d.ts +8 -0
- package/dist/composables/utils/use-active-descendant.d.ts.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +84 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/v-float.es.js +2749 -1836
- package/dist/v-float.umd.js +4 -1
- package/package.json +74 -76
- package/dist/composables/interactions/use-client-point.d.ts.map +0 -1
- package/dist/composables/interactions/utils/browser-detection.d.ts +0 -23
- package/dist/composables/interactions/utils/browser-detection.d.ts.map +0 -1
- package/dist/composables/interactions/utils/element-detection.d.ts +0 -53
- package/dist/composables/interactions/utils/element-detection.d.ts.map +0 -1
- package/dist/composables/interactions/utils/event-utils.d.ts +0 -30
- package/dist/composables/interactions/utils/event-utils.d.ts.map +0 -1
- package/dist/composables/interactions/utils/index.d.ts +0 -11
- package/dist/composables/interactions/utils/index.d.ts.map +0 -1
- package/dist/composables/interactions/utils/tree-context.d.ts +0 -32
- package/dist/composables/interactions/utils/tree-context.d.ts.map +0 -1
- package/dist/composables/use-arrow.d.ts.map +0 -1
- package/dist/composables/use-floating-tree.d.ts.map +0 -1
- package/dist/composables/use-floating.d.ts.map +0 -1
- /package/dist/composables/{use-arrow.d.ts → positioning/use-arrow.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,327 +1,346 @@
|
|
|
1
|
-
# V-Float
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
</
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
<style
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
- **`
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
- **`
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
-
|
|
186
|
-
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
//
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
padding:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
1
|
+
# V-Float
|
|
2
|
+
|
|
3
|
+
[](#project-status)
|
|
4
|
+
|
|
5
|
+
> Work in progress: This library is under active development. APIs may change without notice and breaking changes can land without deprecation windows or warnings. Not recommended for production use yet.
|
|
6
|
+
|
|
7
|
+
A Vue 3 library for positioning floating UI elements like tooltips, popovers, dropdowns, and modals. Built on top
|
|
8
|
+
of [@floating-ui/dom](https://floating-ui.com/) with Vue 3 Composition API.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Precise Positioning**: Pixel-perfect positioning with automatic collision detection
|
|
13
|
+
- **Vue 3 Composables**: Reactive composables designed for the Composition API
|
|
14
|
+
- **Interaction Handling**: Built-in hover, focus, click, and dismiss behaviors
|
|
15
|
+
- **Nested Elements**: Support for floating element trees and hierarchies
|
|
16
|
+
- **Arrow Positioning**: `useArrow` composable for positioning arrow elements
|
|
17
|
+
- **Lightweight**: Tree-shakable with minimal bundle impact
|
|
18
|
+
- **Cross-platform**: Works on desktop, mobile, and touch devices
|
|
19
|
+
- **TypeScript**: Full TypeScript support with comprehensive type definitions
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# With pnpm (recommended)
|
|
25
|
+
pnpm add v-float
|
|
26
|
+
|
|
27
|
+
# With npm
|
|
28
|
+
npm install v-float
|
|
29
|
+
|
|
30
|
+
# With yarn
|
|
31
|
+
yarn add v-float
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### Basic Tooltip
|
|
37
|
+
|
|
38
|
+
```vue
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { useTemplateRef } from "vue"
|
|
41
|
+
import { useFloating, useHover, offset } from "v-float"
|
|
42
|
+
|
|
43
|
+
const anchorEl = useTemplateRef("anchorEl")
|
|
44
|
+
const floatingEl = useTemplateRef("floatingEl")
|
|
45
|
+
|
|
46
|
+
const context = useFloating(anchorEl, floatingEl, {
|
|
47
|
+
placement: "top",
|
|
48
|
+
middlewares: [offset(8)],
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
useHover(context)
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<button ref="anchorEl">Hover me</button>
|
|
56
|
+
|
|
57
|
+
<div v-if="context.open.value" ref="floatingEl" :style="context.floatingStyles.value">
|
|
58
|
+
This is a tooltip
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Dropdown Menu
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<script setup lang="ts">
|
|
67
|
+
import { useTemplateRef } from "vue"
|
|
68
|
+
import { useFloating, useClick, useEscapeKey, offset, flip, shift } from "v-float"
|
|
69
|
+
|
|
70
|
+
const triggerEl = useTemplateRef("triggerEl")
|
|
71
|
+
const menuEl = useTemplateRef("menuEl")
|
|
72
|
+
|
|
73
|
+
const context = useFloating(triggerEl, menuEl, {
|
|
74
|
+
placement: "bottom-start",
|
|
75
|
+
middlewares: [offset(4), flip(), shift({ padding: 8 })],
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
useClick(context)
|
|
79
|
+
useEscapeKey({
|
|
80
|
+
onEscape: () => context.setOpen(false),
|
|
81
|
+
})
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<button ref="triggerEl">Open Menu</button>
|
|
86
|
+
|
|
87
|
+
<div v-if="context.open.value" ref="menuEl" :style="context.floatingStyles.value">
|
|
88
|
+
<div>Menu Item 1</div>
|
|
89
|
+
<div>Menu Item 2</div>
|
|
90
|
+
<div>Menu Item 3</div>
|
|
91
|
+
</div>
|
|
92
|
+
</template>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Tooltip with Arrow
|
|
96
|
+
|
|
97
|
+
```vue
|
|
98
|
+
<script setup lang="ts">
|
|
99
|
+
import { useTemplateRef } from "vue"
|
|
100
|
+
import { useFloating, useHover, useArrow, offset, flip } from "v-float"
|
|
101
|
+
|
|
102
|
+
const anchorEl = useTemplateRef("anchorEl")
|
|
103
|
+
const tooltipEl = useTemplateRef("tooltipEl")
|
|
104
|
+
const arrowEl = useTemplateRef("arrowEl")
|
|
105
|
+
|
|
106
|
+
const context = useFloating(anchorEl, tooltipEl, {
|
|
107
|
+
placement: "top",
|
|
108
|
+
middlewares: [offset(8), flip()],
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
useHover(context)
|
|
112
|
+
|
|
113
|
+
// Arrow middleware is automatically registered
|
|
114
|
+
const { arrowStyles } = useArrow(arrowEl, context, {
|
|
115
|
+
offset: "-4px",
|
|
116
|
+
})
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<template>
|
|
120
|
+
<button ref="anchorEl">Hover me</button>
|
|
121
|
+
|
|
122
|
+
<div
|
|
123
|
+
v-if="context.open.value"
|
|
124
|
+
ref="tooltipEl"
|
|
125
|
+
:style="context.floatingStyles.value"
|
|
126
|
+
class="tooltip"
|
|
127
|
+
>
|
|
128
|
+
This is a tooltip with an arrow
|
|
129
|
+
<div ref="arrowEl" class="arrow" :style="arrowStyles"></div>
|
|
130
|
+
</div>
|
|
131
|
+
</template>
|
|
132
|
+
|
|
133
|
+
<style scoped>
|
|
134
|
+
.tooltip {
|
|
135
|
+
background: white;
|
|
136
|
+
border: 1px solid #ddd;
|
|
137
|
+
border-radius: 4px;
|
|
138
|
+
padding: 8px 12px;
|
|
139
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.arrow {
|
|
143
|
+
position: absolute;
|
|
144
|
+
width: 8px;
|
|
145
|
+
height: 8px;
|
|
146
|
+
background: white;
|
|
147
|
+
border: 1px solid #ddd;
|
|
148
|
+
transform: rotate(45deg);
|
|
149
|
+
z-index: -1;
|
|
150
|
+
}
|
|
151
|
+
</style>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Core Composables
|
|
155
|
+
|
|
156
|
+
### Positioning
|
|
157
|
+
|
|
158
|
+
- **`useFloating`**: Core positioning logic with middleware support
|
|
159
|
+
- **`useArrow`**: Position arrow elements pointing to the anchor
|
|
160
|
+
- **`useFloatingTree`**: Manage nested floating element hierarchies
|
|
161
|
+
|
|
162
|
+
### Interactions
|
|
163
|
+
|
|
164
|
+
- **`useHover`**: Hover interactions with configurable delays
|
|
165
|
+
- **`useFocus`**: Focus/blur event handling for keyboard navigation
|
|
166
|
+
- **`useClick`**: Click event handling with toggle and dismiss options
|
|
167
|
+
- **`useEscapeKey`**: Close on ESC key press with composition handling
|
|
168
|
+
- **`useClientPoint`**: Position floating elements at cursor/touch coordinates
|
|
169
|
+
|
|
170
|
+
### Middleware
|
|
171
|
+
|
|
172
|
+
All [Floating UI middleware](https://floating-ui.com/docs/middleware) are supported:
|
|
173
|
+
|
|
174
|
+
- **`offset`**: Add distance between anchor and floating element
|
|
175
|
+
- **`flip`**: Flip placement when there's insufficient space
|
|
176
|
+
- **`shift`**: Shift floating element to stay in view
|
|
177
|
+
- **`hide`**: Hide floating element when anchor is not visible
|
|
178
|
+
- **`autoPlacement`**: Automatically choose the best placement
|
|
179
|
+
- **`size`**: Resize floating element to fit within viewport
|
|
180
|
+
|
|
181
|
+
**Arrow positioning** is handled by the [`useArrow`](/api/use-arrow) composable, which automatically registers the necessary middleware.
|
|
182
|
+
|
|
183
|
+
## Project Status
|
|
184
|
+
|
|
185
|
+
- WIP and evolving rapidly; expect breaking changes without deprecations.
|
|
186
|
+
- API, docs, and examples are subject to change and may be incomplete.
|
|
187
|
+
- Feedback and contributions are welcome while the API stabilizes.
|
|
188
|
+
|
|
189
|
+
## Advanced Features
|
|
190
|
+
|
|
191
|
+
### Floating Trees
|
|
192
|
+
|
|
193
|
+
For nested floating elements like submenus, use `useFloatingTree` to manage hierarchical structures with a streamlined API that eliminates redundant `useFloating` calls.
|
|
194
|
+
|
|
195
|
+
**Clear Separation of Concerns:**
|
|
196
|
+
|
|
197
|
+
- Use `useFloating` for isolated floating elements
|
|
198
|
+
- Use `useFloatingTree` for hierarchical structures
|
|
199
|
+
|
|
200
|
+
Here's how you can set up a parent menu with a submenu using the new API:
|
|
201
|
+
|
|
202
|
+
```vue
|
|
203
|
+
<script setup lang="ts">
|
|
204
|
+
import { useTemplateRef, ref } from "vue"
|
|
205
|
+
import { useFloatingTree, useHover, useClick, offset, flip, shift } from "v-float"
|
|
206
|
+
|
|
207
|
+
const parentTriggerEl = useTemplateRef("parentTriggerRef")
|
|
208
|
+
const parentMenuEl = useTemplateRef("parentMenuRef")
|
|
209
|
+
const isParentOpen = ref(false)
|
|
210
|
+
|
|
211
|
+
const submenuTriggerEl = useTemplateRef("submenuTriggerRef")
|
|
212
|
+
const submenuEl = useTemplateRef("submenuRef")
|
|
213
|
+
const isSubmenuOpen = ref(false)
|
|
214
|
+
|
|
215
|
+
// 1. Create the floating tree with root context automatically
|
|
216
|
+
const tree = useFloatingTree(parentTriggerEl, parentMenuEl, {
|
|
217
|
+
placement: "bottom-start",
|
|
218
|
+
open: isParentOpen,
|
|
219
|
+
middlewares: [offset(4), flip(), shift({ padding: 8 })],
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
// 2. Add submenu node - no separate useFloating call needed!
|
|
223
|
+
const submenuNode = tree.addNode(submenuTriggerEl, submenuEl, {
|
|
224
|
+
placement: "right-start",
|
|
225
|
+
open: isSubmenuOpen,
|
|
226
|
+
middlewares: [offset(4), flip(), shift({ padding: 8 })],
|
|
227
|
+
parentId: tree.root.id, // Link to parent using parentId in options
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
// 3. Add interactions
|
|
231
|
+
useClick(tree.root, { outsideClick: true })
|
|
232
|
+
useHover(submenuNode, { delay: { open: 100, close: 300 } })
|
|
233
|
+
|
|
234
|
+
// Access floating styles from the contexts
|
|
235
|
+
const { floatingStyles: parentStyles } = tree.rootContext
|
|
236
|
+
const { floatingStyles: submenuStyles } = submenuNode.data
|
|
237
|
+
</script>
|
|
238
|
+
|
|
239
|
+
<template>
|
|
240
|
+
<!-- Parent Menu Trigger -->
|
|
241
|
+
<button ref="parentTriggerEl" @click="isParentOpen = !isParentOpen">Open Menu</button>
|
|
242
|
+
|
|
243
|
+
<!-- Parent Menu -->
|
|
244
|
+
<div v-if="isParentOpen" ref="parentMenuEl" :style="parentStyles" class="menu">
|
|
245
|
+
<div class="menu-item">Menu Item 1</div>
|
|
246
|
+
|
|
247
|
+
<!-- Submenu Trigger -->
|
|
248
|
+
<div
|
|
249
|
+
ref="submenuTriggerEl"
|
|
250
|
+
class="menu-item menu-item--submenu"
|
|
251
|
+
@click="isSubmenuOpen = !isSubmenuOpen"
|
|
252
|
+
>
|
|
253
|
+
Menu Item 2 (Has Submenu)
|
|
254
|
+
|
|
255
|
+
<!-- Submenu -->
|
|
256
|
+
<div v-if="isSubmenuOpen" ref="submenuEl" :style="submenuStyles" class="menu submenu">
|
|
257
|
+
<div class="menu-item">Submenu Item A</div>
|
|
258
|
+
<div class="menu-item">Submenu Item B</div>
|
|
259
|
+
<div class="menu-item">Submenu Item C</div>
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
|
|
263
|
+
<div class="menu-item">Menu Item 3</div>
|
|
264
|
+
</div>
|
|
265
|
+
</template>
|
|
266
|
+
|
|
267
|
+
<style scoped>
|
|
268
|
+
.menu {
|
|
269
|
+
background: white;
|
|
270
|
+
border: 1px solid #ddd;
|
|
271
|
+
border-radius: 4px;
|
|
272
|
+
padding: 4px 0;
|
|
273
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
274
|
+
min-width: 160px;
|
|
275
|
+
z-index: 1000;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.submenu {
|
|
279
|
+
margin-left: 8px;
|
|
280
|
+
z-index: 1010;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.menu-item {
|
|
284
|
+
padding: 8px 12px;
|
|
285
|
+
cursor: pointer;
|
|
286
|
+
user-select: none;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.menu-item:hover {
|
|
290
|
+
background-color: #f5f5f5;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.menu-item--submenu {
|
|
294
|
+
position: relative;
|
|
295
|
+
}
|
|
296
|
+
</style>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**API Benefits:**
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
// Before: Required separate useFloating calls
|
|
303
|
+
const parentContext = useFloating(parentEl, parentFloating, options)
|
|
304
|
+
const tree = useFloatingTree(parentContext)
|
|
305
|
+
const childContext = useFloating(childEl, childFloating, childOptions)
|
|
306
|
+
const childNode = tree.addNode(childContext, parentContext.nodeId)
|
|
307
|
+
|
|
308
|
+
// After: Streamlined API with internal context creation
|
|
309
|
+
const tree = useFloatingTree(parentEl, parentFloating, options)
|
|
310
|
+
const childNode = tree.addNode(childEl, childFloating, {
|
|
311
|
+
...childOptions,
|
|
312
|
+
parentId: tree.root.id,
|
|
313
|
+
})
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
This approach eliminates redundant calls and provides a clearer separation between isolated floating elements (`useFloating`) and hierarchical structures (`useFloatingTree`).
|
|
317
|
+
|
|
318
|
+
## TypeScript Support
|
|
319
|
+
|
|
320
|
+
V-Float is built with TypeScript and provides comprehensive type definitions:
|
|
321
|
+
|
|
322
|
+
## Browser Support
|
|
323
|
+
|
|
324
|
+
- **Modern browsers**: Chrome, Firefox, Safari, Edge
|
|
325
|
+
- **Mobile browsers**: iOS Safari, Chrome Mobile, Samsung Internet
|
|
326
|
+
- **Node.js**: SSR compatible (with proper hydration)
|
|
327
|
+
|
|
328
|
+
## Documentation
|
|
329
|
+
|
|
330
|
+
For complete documentation with interactive examples, visit the [V-Float Documentation](https://vfloat.pages.dev/).
|
|
331
|
+
|
|
332
|
+
## Contributing
|
|
333
|
+
|
|
334
|
+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to
|
|
335
|
+
our [GitHub repository](https://github.com/sherif414/VFloat).
|
|
336
|
+
|
|
337
|
+
## Credits
|
|
338
|
+
|
|
339
|
+
V-Float is built on top of the excellent work of:
|
|
340
|
+
|
|
341
|
+
- [Floating UI](https://floating-ui.com/) - For the core positioning and collision detection algorithms
|
|
342
|
+
- [VueUse](https://vueuse.org/) - For Vue composition utilities and best practices
|
|
343
|
+
|
|
344
|
+
## License
|
|
345
|
+
|
|
346
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|