Logoreact-timeline-editor
API Reference

Loop Zone API

Complete API reference for the LoopZoneOverlay component.

Overview

LoopZoneOverlay renders a draggable repeat region overlay on top of <Timeline>. Requirements:

  1. Mounted as a sibling to <Timeline> inside a position: relative wrapper
  2. Given the same geometry props as <Timeline> (scale, scaleWidth, startLeft)
  3. Kept in sync with the timeline's scrollLeft via the onScroll callback

Props Reference

PropTypeRequiredDefaultDescription
scalenumber✅1Duration represented by one scale unit (seconds). Must match <Timeline> scale prop
scaleWidthnumber✅160Width in pixels of one scale unit. Must match <Timeline> scaleWidth prop
startLeftnumber✅20Left inset in pixels before the first scale mark begins. Must match <Timeline> startLeft prop
scrollLeftnumber✅—Current horizontal scroll offset of the timeline. Track this via the onScroll callback on <Timeline>
loopStartnumber✅—Loop region start time in seconds. This is a controlled prop — manage it in parent state.
loopEndnumber✅—Loop region end time in seconds. Must be greater than loopStart. This is a controlled prop — manage it in parent state.
onLoopStartChange(time: number) => void✅—Called when the user drags the start handle to a new time value. Update your loopStart state here.
onLoopEndChange(time: number) => void✅—Called when the user drags the end handle to a new time value. Update your loopEnd state here.
configLoopZoneConfig—{}Fine-grained control over the band color, opacity, handle color, and boundary line appearance.
renderHandle(props: LoopHandleRenderProps) => ReactNode——Custom render function for the drag handles. Replaces the default SVG grip pill.
classNamestring——Additional CSS class name appended to the overlay root element.
styleReact.CSSProperties——Inline styles applied to the overlay root element.

LoopZoneConfig

OptionTypeDefaultDescription
bandColorstring'#10b981'CSS color of the loop region shaded band.
bandOpacitynumber0.07Opacity of the loop region band (0–1). Keep this low (< 0.15) so underlying blocks remain visible.
bandBorderColorstring—Border/stripe color used on the band's edges and stripe pattern. Falls back to bandColor when not set.
handleColorstring—CSS color of the default drag handle grip pills. Falls back to bandColor when not set. Has no effect when renderHandle is provided.
showBoundaryLinesbooleantrueWhether to render the dashed vertical boundary lines extending through the edit rows below the time ruler.
boundaryLineColorstring'rgba(16, 185, 129, 0.4)'CSS color of the dashed boundary lines.

LoopHandleRenderProps

When you provide renderHandle, your function receives these props:

PropertyTypeDescription
type'start' | 'end'Which boundary this handle controls. Use to differentiate styling between the two handles.
timenumberThe current time value (in seconds) for this boundary. Useful for displaying a tooltip or label.
onMouseDown(e: React.MouseEvent) => voidAttach this to your draggable element's onMouseDown to activate dragging. The overlay provides all pixel math and handles document mouse events internally.

Usage Example

import React, { useState } from "react";
import { Timeline, LoopZoneOverlay } from "@keplar-404/react-timeline-editor";

export const App = () => {
  const [loopStart, setLoopStart] = useState(2);
  const [loopEnd, setLoopEnd] = useState(8);
  const [scrollLeft, setScrollLeft] = useState(0);

  const scale = 1;
  const scaleWidth = 160;
  const startLeft = 20;

  return (
    <div style={{ position: "relative" }}>
      <Timeline
        scale={scale}
        scaleWidth={scaleWidth}
        startLeft={startLeft}
        editorData={[]}
        effects={{}}
        onScroll={(p) => setScrollLeft(p.scrollLeft)}
      />

      <LoopZoneOverlay
        scale={scale}
        scaleWidth={scaleWidth}
        startLeft={startLeft}
        scrollLeft={scrollLeft}
        loopStart={loopStart}
        loopEnd={loopEnd}
        onLoopStartChange={setLoopStart}
        onLoopEndChange={setLoopEnd}
        config={{
          bandColor: "#10b981",
          bandOpacity: 0.12,
          showBoundaryLines: true,
        }}
      />
    </div>
  );
};

Custom Handle Renderer

<LoopZoneOverlay
  {/* ...other props... */}
  renderHandle={({ type, time, onMouseDown }) => (
    <div
      className={`handle handle-${type}`}
      onMouseDown={onMouseDown}
      style={{ cursor: 'ew-resize', background: 'purple' }}
      title={`${type === 'start' ? 'Loop start' : 'Loop end'}: ${time.toFixed(2)}s`}
    >
      {type === 'start' ? '⟨' : '⟩'}
    </div>
  )}
/>

On this page