4
4
:class ="
5
5
cn(
6
6
'supports-backdrop-blur:bg-white/10 supports-backdrop-blur:dark:bg-black/10 mx-auto mt-8 flex h-[58px] w-max rounded-2xl border p-2 backdrop-blur-md transition-all gap-4',
7
- $props.class,
7
+ orientation === 'vertical' && 'flex-col w-[58px] h-max',
8
+ props.class,
8
9
dockClass,
9
10
)
10
11
"
16
17
</template >
17
18
18
19
<script setup lang="ts">
19
- import { ref , computed } from " vue" ;
20
+ import { ref , computed , type HTMLAttributes } from " vue" ;
20
21
import { cn } from " ~/lib/utils" ;
22
+ import type { DataOrientation , Direction } from " ./types" ;
23
+ import {
24
+ MOUSE_X_INJECTION_KEY ,
25
+ MOUSE_Y_INJECTION_KEY ,
26
+ MAGNIFICATION_INJECTION_KEY ,
27
+ DISTANCE_INJECTION_KEY ,
28
+ ORIENTATION_INJECTION_KEY ,
29
+ } from " ./injectionKeys" ;
21
30
22
- const props = defineProps ({
23
- class: {
24
- type: String ,
25
- default: " " ,
26
- },
27
- magnification: {
28
- type: Number ,
29
- default: 60 ,
30
- },
31
- distance: {
32
- type: Number ,
33
- default: 140 ,
34
- },
35
- direction: {
36
- type: String ,
37
- default: " middle" ,
38
- },
31
+ interface DockProps {
32
+ class? : HTMLAttributes [" class" ];
33
+ magnification? : number ;
34
+ distance? : number ;
35
+ direction? : Direction ;
36
+ orientation? : DataOrientation ;
37
+ }
38
+
39
+ const props = withDefaults (defineProps <DockProps >(), {
40
+ magnification: 60 ,
41
+ distance: 140 ,
42
+ direction: " middle" ,
43
+ orientation: " horizontal" ,
39
44
});
40
45
41
46
const dockRef = ref <HTMLElement | null >(null );
42
47
const mouseX = ref (Infinity );
48
+ const mouseY = ref (Infinity );
49
+ const magnification = computed (() => props .magnification );
50
+ const distance = computed (() => props .distance );
43
51
44
52
const dockClass = computed (() => ({
45
53
" items-start" : props .direction === " top" ,
@@ -50,14 +58,19 @@ const dockClass = computed(() => ({
50
58
function onMouseMove(e : MouseEvent ) {
51
59
requestAnimationFrame (() => {
52
60
mouseX .value = e .pageX ;
61
+ mouseY .value = e .pageY ;
53
62
});
54
63
}
55
64
56
65
function onMouseLeave() {
57
- mouseX .value = Infinity ;
66
+ requestAnimationFrame (() => {
67
+ mouseX .value = Infinity ;
68
+ mouseY .value = Infinity ;
69
+ });
58
70
}
59
-
60
- provide (" mouseX" , mouseX );
61
- provide (" magnification" , props .magnification );
62
- provide (" distance" , props .distance );
71
+ provide (MOUSE_X_INJECTION_KEY , mouseX );
72
+ provide (MOUSE_Y_INJECTION_KEY , mouseY );
73
+ provide (ORIENTATION_INJECTION_KEY , props .orientation );
74
+ provide (MAGNIFICATION_INJECTION_KEY , magnification );
75
+ provide (DISTANCE_INJECTION_KEY , distance );
63
76
</script >
0 commit comments