Primitives
Dock
macOS-style dock — icons magnify as the pointer nears them. Pair Dock with DockItem cells.
Motionpointer-distance → size, smoothed by a spring (useSpring)
Install
Install Kineto and follow the theme setup once in your app.
bash
npm install kinetotsx
import { Dock, DockItem } from "kineto/dock";Preview
tsx
"use client";
import * as React from "react";
import {
motion,
useMotionValue,
useSpring,
useTransform,
type HTMLMotionProps,
type MotionValue,
} from "motion/react";
import { cn } from "@/lib/cn";
/* macOS-style dock: icons swell as the pointer nears them and settle back as it leaves. The Dock
* tracks the pointer's x; each DockItem transforms its distance-from-pointer into a size, smoothed
* by a spring. Unorthodox, but memorable — and a natural fit for a motion-first library. */
interface DockContextValue {
mouseX: MotionValue<number>;
baseSize: number;
magnifiedSize: number;
range: number;
}
const DockContext = React.createContext<DockContextValue | null>(null);
export interface DockProps extends HTMLMotionProps<"div"> {
/** Resting icon size in px. */
baseSize?: number;
/** Peak size of the icon directly under the pointer. */
magnifiedSize?: number;
/** Pointer distance (px) over which the magnification falls off. */
range?: number;
}
const Dock = React.forwardRef<HTMLDivElement, DockProps>(
({ className, children, baseSize = 44, magnifiedSize = 72, range = 140, ...props }, ref) => {
const mouseX = useMotionValue(Number.POSITIVE_INFINITY);
return (
<motion.div
ref={ref}
onMouseMove={(e) => mouseX.set(e.clientX)}
onMouseLeave={() => mouseX.set(Number.POSITIVE_INFINITY)}
className={cn(
"mx-auto flex h-16 items-end gap-3 rounded-2xl border border-border bg-card/70 px-3 pb-3 shadow-lift backdrop-blur-xl",
className
)}
{...props}
>
<DockContext.Provider value={{ mouseX, baseSize, magnifiedSize, range }}>
{children as React.ReactNode}
</DockContext.Provider>
</motion.div>
);
}
);
Dock.displayName = "Dock";
export interface DockItemProps extends HTMLMotionProps<"div"> {}
const DockItem = React.forwardRef<HTMLDivElement, DockItemProps>(
({ className, children, ...props }, ref) => {
const ctx = React.useContext(DockContext);
const innerRef = React.useRef<HTMLDivElement>(null);
// Fallback motion value so the hook order is stable even if used outside a Dock.
const fallbackX = useMotionValue(Number.POSITIVE_INFINITY);
const mouseX = ctx?.mouseX ?? fallbackX;
const baseSize = ctx?.baseSize ?? 44;
const magnifiedSize = ctx?.magnifiedSize ?? 72;
const range = ctx?.range ?? 140;
const distance = useTransform(mouseX, (val) => {
const bounds = innerRef.current?.getBoundingClientRect() ?? { x: 0, width: 0 };
return val - bounds.x - bounds.width / 2;
});
const sizeTarget = useTransform(distance, [-range, 0, range], [baseSize, magnifiedSize, baseSize]);
const size = useSpring(sizeTarget, { mass: 0.1, stiffness: 170, damping: 12 });
return (
<motion.div
ref={innerRef}
style={{ width: size, height: size }}
className={cn(
"flex aspect-square items-center justify-center rounded-xl bg-muted text-foreground [&_svg]:size-1/2",
className
)}
{...props}
>
{children}
</motion.div>
);
}
);
DockItem.displayName = "DockItem";
export { Dock, DockItem };src/components/ui/dock.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| baseSize | number | 44 | Resting icon size in px. |
| magnifiedSize | number | 72 | Peak size of the icon under the pointer. |
| range | number | 140 | Pointer distance (px) over which magnification falls off. |