@@ -4,16 +4,12 @@ import {
44 motion ,
55 MotionValue ,
66 useMotionValue ,
7- useSpring ,
8- useTransform ,
9- type SpringOptions ,
107 AnimatePresence ,
118} from "motion/react" ;
129import React , {
1310 Children ,
1411 cloneElement ,
1512 useEffect ,
16- useMemo ,
1713 useRef ,
1814 useState ,
1915} from "react" ;
@@ -28,59 +24,32 @@ export type DockItemData = {
2824export type DockProps = {
2925 items : DockItemData [ ] ;
3026 className ?: string ;
31- distance ?: number ;
3227 panelHeight ?: number ;
3328 baseItemSize ?: number ;
34- dockHeight ?: number ;
35- magnification ?: number ;
36- spring ?: SpringOptions ;
3729} ;
3830
3931type DockItemProps = {
4032 className ?: string ;
4133 children : React . ReactNode ;
4234 onClick ?: ( ) => void ;
43- mouseX : MotionValue ;
44- spring : SpringOptions ;
45- distance : number ;
4635 baseItemSize : number ;
47- magnification : number ;
4836} ;
4937
5038function DockItem ( {
5139 children,
5240 className = "" ,
5341 onClick,
54- mouseX,
55- spring,
56- distance,
57- magnification,
5842 baseItemSize,
5943} : DockItemProps ) {
6044 const ref = useRef < HTMLDivElement > ( null ) ;
6145 const isHovered = useMotionValue ( 0 ) ;
6246
63- const mouseDistance = useTransform ( mouseX , ( val ) => {
64- const rect = ref . current ?. getBoundingClientRect ( ) ?? {
65- x : 0 ,
66- width : baseItemSize ,
67- } ;
68- return val - rect . x - baseItemSize / 2 ;
69- } ) ;
70-
71- const targetSize = useTransform (
72- mouseDistance ,
73- [ - distance , 0 , distance ] ,
74- [ baseItemSize , magnification , baseItemSize ]
75- ) ;
76- const size = useSpring ( targetSize , spring ) ;
77-
7847 return (
7948 < motion . div
8049 ref = { ref }
8150 style = { {
82- width : size ,
83- height : size ,
51+ width : baseItemSize ,
52+ height : baseItemSize ,
8453 } }
8554 onHoverStart = { ( ) => isHovered . set ( 1 ) }
8655 onHoverEnd = { ( ) => isHovered . set ( 0 ) }
@@ -153,37 +122,15 @@ function DockIcon({ children, className = "" }: DockIconProps) {
153122export default function Dock ( {
154123 items,
155124 className = "" ,
156- spring = { mass : 0.1 , stiffness : 150 , damping : 12 } ,
157- magnification = 70 ,
158- distance = 200 ,
159125 panelHeight = 64 ,
160- dockHeight = 256 ,
161126 baseItemSize = 50 ,
162127} : DockProps ) {
163- const mouseX = useMotionValue ( Infinity ) ;
164- const isHovered = useMotionValue ( 0 ) ;
165-
166- const maxHeight = useMemo (
167- ( ) => Math . max ( dockHeight , magnification + magnification / 2 + 4 ) ,
168- [ magnification , dockHeight ]
169- ) ;
170- const heightRow = useTransform ( isHovered , [ 0 , 1 ] , [ panelHeight , maxHeight ] ) ;
171- const height = useSpring ( heightRow , spring ) ;
172-
173128 return (
174129 < motion . div
175- style = { { height, scrollbarWidth : "none" } }
130+ style = { { height : panelHeight , scrollbarWidth : "none" } }
176131 className = "mx-2 flex max-w-full items-center dock-container"
177132 >
178133 < motion . div
179- onMouseMove = { ( { pageX } ) => {
180- isHovered . set ( 1 ) ;
181- mouseX . set ( pageX ) ;
182- } }
183- onMouseLeave = { ( ) => {
184- isHovered . set ( 0 ) ;
185- mouseX . set ( Infinity ) ;
186- } }
187134 className = { `${ className } absolute bottom-2 left-1/2 transform -translate-x-1/2 flex items-end w-fit gap-4 rounded-2xl bg-black/30 backdrop-blur-md border border-gray-700/50 pb-2 px-4 shadow-2xl` }
188135 style = { { height : panelHeight } }
189136 role = "toolbar"
@@ -194,10 +141,6 @@ export default function Dock({
194141 key = { index }
195142 onClick = { item . onClick }
196143 className = { item . className }
197- mouseX = { mouseX }
198- spring = { spring }
199- distance = { distance }
200- magnification = { magnification }
201144 baseItemSize = { baseItemSize }
202145 >
203146 < DockIcon > { item . icon } </ DockIcon >
0 commit comments