import { memo } from "react"; interface ProgressBarProps { progress: number; onSeek: (ratio: number) => void; } export const ProgressBar = memo(function ProgressBar({ progress, onSeek, }: ProgressBarProps) { const seekFromClientX = (clientX: number, element: HTMLElement): void => { const rect = element.getBoundingClientRect(); if (rect.width <= 0) return; onSeek((clientX - rect.left) / rect.width); }; return (
{ seekFromClientX(e.clientX, e.currentTarget as HTMLElement); }} onPointerDown={(e) => { if (e.pointerType === "mouse" && e.button !== 0) return; e.currentTarget.setPointerCapture(e.pointerId); seekFromClientX(e.clientX, e.currentTarget); }} onPointerMove={(e) => { if (!e.currentTarget.hasPointerCapture(e.pointerId)) return; seekFromClientX(e.clientX, e.currentTarget); }} onPointerUp={(e) => { if (e.currentTarget.hasPointerCapture(e.pointerId)) { e.currentTarget.releasePointerCapture(e.pointerId); } }} onPointerCancel={(e) => { if (e.currentTarget.hasPointerCapture(e.pointerId)) { e.currentTarget.releasePointerCapture(e.pointerId); } }} >
); });