"use client";
// src/components/VinylLoader/VinylLoader.tsx
import { motion, useReducedMotion } from "motion/react";
import { useId } from "react";
type VinylLoaderProps = {
className?: string;
/** Width in px - height is always 3/4 of the width */
size?: number;
/** Record label, music notes, and power light color */
color?: string;
/** Color of the vinyl itself - try a colored pressing like "#7C3AED" */
vinylColor?: string;
/** Record speed: 33 or 45, like a real turntable (any number works) */
rpm?: number;
/**
* Optional 0-100. When set, the tonearm moves from the outer edge
* to the center of the record as progress goes up, like a song playing.
* At 100 the arm goes back to its rest.
*/
progress?: number;
/** Show music notes floating up from the record */
notes?: boolean;
/** Text under the loader. Pass an empty string to hide it */
label?: string;
};
// viewBox is 160 x 120
const CENTER = { x: 62, y: 60 };
const RECORD_R = 50;
const LABEL_R = 17;
// Tonearm pivot and length - angles below are worked out from these
const PIVOT = { x: 140, y: 18 };
const ARM_LENGTH = 82;
const ANGLE_REST = 4; // stylus on the arm rest, off the record
const ANGLE_OUTER = 30; // stylus on the first groove
const ANGLE_INNER = 46.8; // stylus on the last groove
const ANGLE_LOOP = 35; // where the arm sits in loop mode
// Groove rings, with a few brighter gaps between "tracks"
const GROOVES = Array.from({ length: 12 }, (_, i) => 21 + i * 2.4);
const TRACK_GAPS = [29.5, 38, 45];
// x drift, start delay, size
const NOTES = [
[-14, 0, 1.3],
[10, 1.1, 1],
[-4, 2.2, 1.15],
] as const;
// Wedge from the record center, for the fixed light reflection
function wedge(from: number, to: number) {
const p = (deg: number) => {
const a = (deg * Math.PI) / 180;
return `${CENTER.x + Math.cos(a) * RECORD_R} ${CENTER.y + Math.sin(a) * RECORD_R}`;
};
return `M ${CENTER.x} ${CENTER.y} L ${p(from)} A ${RECORD_R} ${RECORD_R} 0 0 1 ${p(to)} Z`;
}
export function VinylLoader({
className = "",
size = 160,
color = "#8B5CF6",
vinylColor = "#18181B",
rpm = 33,
progress,
notes = true,
label = "Loading",
}: VinylLoaderProps) {
const uid = useId().replace(/:/g, "");
const reduce = useReducedMotion();
const isProgress = typeof progress === "number";
const clamped = isProgress ? Math.min(100, Math.max(0, progress)) : 0;
const finished = isProgress && clamped >= 100;
const armAngle = finished
? ANGLE_REST
: isProgress
? ANGLE_OUTER + (clamped / 100) * (ANGLE_INNER - ANGLE_OUTER)
: ANGLE_LOOP;
// One turn in seconds (33 rpm = 1.8s)
const turn = 60 / Math.min(90, Math.max(10, rpm));
const playing = !reduce && !finished;
const a11y = isProgress
? {
role: "progressbar",
"aria-valuemin": 0,
"aria-valuemax": 100,
"aria-valuenow": Math.round(clamped),
"aria-label": label || "Loading",
}
: { role: "status", "aria-label": label || "Loading" };
return (
<div className={`flex flex-col items-center gap-3 ${className}`} {...a11y}>
<div className="relative" style={{ width: size, aspectRatio: "4 / 3", maxWidth: "100%" }}>
<svg viewBox="0 0 160 120" className="h-full w-full overflow-visible" fill="none" aria-hidden="true">
<defs>
<clipPath id={`record-${uid}`}>
<circle cx={CENTER.x} cy={CENTER.y} r={RECORD_R} />
</clipPath>
</defs>
{/* Turntable body */}
<rect x={4} y={4} width={152} height={112} rx={12} fill="currentColor" fillOpacity={0.05} stroke="currentColor" strokeOpacity={0.3} strokeWidth={2} />
{/* Platter edge */}
<circle cx={CENTER.x} cy={CENTER.y} r={RECORD_R + 3} fill="currentColor" fillOpacity={0.12} />
{/* Record - spins */}
<motion.g
initial={{ rotate: 0 }}
animate={playing ? { rotate: 360 } : { rotate: 0 }}
transition={playing ? { duration: turn, ease: "linear", repeat: Infinity } : { duration: 0 }}
>
<circle cx={CENTER.x} cy={CENTER.y} r={RECORD_R} fill={vinylColor} stroke="#fff" strokeOpacity={0.12} strokeWidth={0.8} />
{GROOVES.map((r) => (
<circle key={r} cx={CENTER.x} cy={CENTER.y} r={r} stroke="#fff" strokeOpacity={0.06} strokeWidth={0.8} />
))}
{TRACK_GAPS.map((r) => (
<circle key={r} cx={CENTER.x} cy={CENTER.y} r={r} stroke="#fff" strokeOpacity={0.14} strokeWidth={0.6} />
))}
{/* Label */}
<circle cx={CENTER.x} cy={CENTER.y} r={LABEL_R} fill={color} />
<circle cx={CENTER.x} cy={CENTER.y} r={LABEL_R - 3.5} stroke="#fff" strokeOpacity={0.3} strokeWidth={0.8} />
{/* Printed marks so you can see it turning */}
<path d={`M ${CENTER.x - 6} ${CENTER.y - 8} H ${CENTER.x + 6}`} stroke="#fff" strokeOpacity={0.85} strokeWidth={2} strokeLinecap="round" />
<path d={`M ${CENTER.x - 4} ${CENTER.y + 7} H ${CENTER.x + 4}`} stroke="#fff" strokeOpacity={0.5} strokeWidth={1.4} strokeLinecap="round" />
<circle cx={CENTER.x} cy={CENTER.y} r={2.2} fill="#D4D4D8" />
</motion.g>
{/* Light reflection - stays still while the record turns, like real vinyl */}
<g clipPath={`url(#record-${uid})`}>
<path d={wedge(-60, -35)} fill="#fff" fillOpacity={0.07} />
<path d={wedge(120, 145)} fill="#fff" fillOpacity={0.07} />
</g>
{/* Music notes floating up */}
{notes && playing &&
NOTES.map(([drift, delay, scale], i) => (
<motion.g
key={i}
initial={{ x: 96, y: 78, opacity: 0, scale: 0 }}
animate={{
x: [96, 96 + drift * 0.4, 96 + drift],
y: [78, 40, -6],
opacity: [0, 1, 0],
scale: [0.4, scale, scale * 0.9],
rotate: [0, drift > 0 ? 12 : -12, 0],
}}
transition={{ duration: 3.3, delay, ease: "easeOut", repeat: Infinity }}
>
<ellipse cx={0} cy={0} rx={3.2} ry={2.4} fill={color} transform="rotate(-20)" />
<path d="M 2.8 -0.8 V -13 Q 8 -11 7 -5.5" stroke={color} strokeWidth={1.6} strokeLinecap="round" />
</motion.g>
))}
{/* Arm rest */}
<rect x={129} y={95} width={10} height={8} rx={2.5} fill="currentColor" fillOpacity={0.2} />
{/* Tonearm - drawn around the pivot at (0, 0) */}
<g transform={`translate(${PIVOT.x} ${PIVOT.y})`}>
<motion.g
initial={{ rotate: ANGLE_REST }}
animate={{ rotate: armAngle }}
transition={reduce ? { duration: 0 } : { type: "spring", stiffness: 40, damping: 12, delay: 0.2 }}
>
{/* Invisible box centered on the pivot, so it rotates around it */}
<rect x={-ARM_LENGTH - 16} y={-ARM_LENGTH - 16} width={(ARM_LENGTH + 16) * 2} height={(ARM_LENGTH + 16) * 2} fill="none" />
{/* Counterweight */}
<rect x={-5} y={-17} width={10} height={11} rx={2.5} fill="#71717A" stroke="#A1A1AA" strokeWidth={1} />
{/* Arm */}
{/* Silver, so it shows on dark vinyl and light backgrounds */}
<path d={`M 0 0 V ${ARM_LENGTH - 9}`} stroke="#52525B" strokeWidth={3.6} strokeLinecap="round" />
<path d={`M 0 0 V ${ARM_LENGTH - 9}`} stroke="#D4D4D8" strokeWidth={2} strokeLinecap="round" />
{/* Headshell */}
<rect x={-3.8} y={ARM_LENGTH - 11} width={7.6} height={12.5} rx={1.8} fill="#3F3F46" stroke="#D4D4D8" strokeWidth={1} />
<circle cx={0} cy={ARM_LENGTH} r={1} fill={color} />
</motion.g>
</g>
{/* Pivot base */}
<circle cx={PIVOT.x} cy={PIVOT.y} r={7} fill="currentColor" fillOpacity={0.15} stroke="currentColor" strokeOpacity={0.4} strokeWidth={1.5} />
<circle cx={PIVOT.x} cy={PIVOT.y} r={2.5} fill="currentColor" fillOpacity={0.6} />
{/* Speed knob and power light */}
<circle cx={128} cy={52} r={5} fill="currentColor" fillOpacity={0.12} stroke="currentColor" strokeOpacity={0.35} strokeWidth={1.2} />
<path d="M 128 48.5 V 51" stroke="currentColor" strokeOpacity={0.6} strokeWidth={1.2} strokeLinecap="round" />
<motion.circle
cx={146}
cy={106}
r={2.4}
fill={color}
animate={playing ? { opacity: [0.35, 1, 0.35] } : { opacity: finished ? 0.25 : 1 }}
transition={playing ? { duration: turn * 1.5, repeat: Infinity, ease: "easeInOut" } : { duration: 0.3 }}
/>
</svg>
</div>
{label && (
<motion.span
aria-hidden="true"
className="text-sm font-medium text-neutral-500 tabular-nums dark:text-neutral-400"
animate={reduce || isProgress ? {} : { opacity: [0.45, 1, 0.45] }}
transition={{ duration: 1.6, repeat: Infinity, ease: "easeInOut" }}
>
{isProgress ? `${label} ${Math.round(clamped)}%` : label}
</motion.span>
)}
</div>
);
}
export default VinylLoader;
// Component Source: https://codekk.devComponent details
Overview, install command, dependencies, and project links.
A vinyl turntable loader for React built with TypeScript, Motion, SVG, and Tailwind CSS v4, designed for music labels, artists, record stores, radio stations, podcasts, DJ sites, and music streaming apps. A record spins on the turntable at a real record speed: 33 rpm by default, or 45 rpm for a single. When the loader appears, the tonearm swings in from its rest and drops onto the record with a soft spring. Music notes float up from the needle, drifting left and right as they fade out, and a small power light pulses on the turntable. The record has fine grooves with brighter gaps between tracks, and the light reflection on the vinyl stays still while the record turns, just like real vinyl under a lamp. Printed marks on the label make the spin easy to see. The color prop sets the record label, notes, and power light to any brand color, and the vinylColor prop gives you colored pressings like red, purple, or clear blue. The optional progress prop turns the loader into a real progress indicator: the tonearm moves from the outer edge of the record toward the center as progress goes up, like a song playing through. At 100% the arm goes back to its rest and the notes stop. The label shows the percentage, and the wrapper switches to role="progressbar" with proper ARIA values. This is useful for track uploads, playlist loading, and audio processing. The turntable uses currentColor and the tonearm is silver, so it works on light and dark themes. Clip IDs come from React's useId, so multiple loaders can share a page without conflicts. When prefers-reduced-motion is enabled, the record stops spinning, the notes are hidden, and the arm sits still on the record. "use client" is included, so it works in Vite, Create React App, and Next.js.
Install
npm create vite@latest my-app -- --template react-ts cd my-app npm install motion npm run devDependencies
Discussion
Feedback, implementation tips, and usage notes.
Comments
Sign in to join the conversation
Similar Components
More from the same category




