File size: 1,818 Bytes
e008c35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use client";

import type { VisualizerControls } from "@/lib/types";

type ControlsPanelProps = {
  controls: VisualizerControls;
  onChange: (controls: VisualizerControls) => void;
};

const controlFields = [
  { key: "scale", label: "Tile Scale", min: 0.25, max: 2.5, step: 0.05 },
  { key: "opacity", label: "Blend Opacity", min: 0.1, max: 1, step: 0.01 },
  { key: "rotation", label: "Rotation", min: -90, max: 90, step: 1 },
] satisfies Array<{
  key: keyof VisualizerControls;
  label: string;
  min: number;
  max: number;
  step: number;
}>;

export function ControlsPanel({ controls, onChange }: ControlsPanelProps) {
  return (
    <section className="panel-section">
      <div className="section-heading">
        <h2>Adjustments</h2>
      </div>
      <div className="controls-stack">
        {controlFields.map((field) => (
          <label className="range-field" key={field.key}>
            <div className="range-header">
              <span className="range-label">{field.label}</span>
              <span className="range-value">
                {formatValue(field.key, controls[field.key])}
              </span>
            </div>
            <input
              max={field.max}
              min={field.min}
              onChange={(event) =>
                onChange({
                  ...controls,
                  [field.key]: Number(event.target.value),
                })
              }
              step={field.step}
              type="range"
              value={controls[field.key]}
            />
          </label>
        ))}
      </div>
    </section>
  );
}

function formatValue(key: keyof VisualizerControls, value: number) {
  if (key === "opacity") return `${Math.round(value * 100)}%`;
  if (key === "rotation") return `${value}°`;
  return `${value.toFixed(2)}×`;
}