/** * Relabi controls * @module src/ui/Controls.jsx; */ import * as React from "react"; import { useCallback, useRef } from "react"; import Slider from "rc-slider"; import TooltipSlider, { handleRender } from "./TooltipSlider.tsx"; import "rc-slider/assets/index.css"; const WAVE_SHAPE_NAMES = ["sine", "triangle", "saw", "reverse_saw", "square"]; export default function Controls({ relabi }) { /** * Handle updating a slider */ const onChange = useCallback( (type, index) => (value) => { if (type === "bound") { relabi.bounds[index].level = value; } if (type === "shape") { relabi.waves[index].shape = WAVE_SHAPE_NAMES[value]; } if (type === "frequency") { relabi.waves[index].frequency = Math.exp(value); } if (type === "weight") { relabi.waves[index].weight = value; } if (type === "settings") { relabi.settings[index] = index === "speed" ? Math.exp(value) : value; } }, [relabi] ); if (!relabi) { return null; } return ( {relabi?.bounds.map((bound, index) => ( -value} defaultValue={bound.level} color={bound.color} reverse /> ))} {relabi?.waves.map((wave, index) => ( Math.exp(value).toFixed(1)} color={"#8a8"} /> ))} {relabi?.waves.map((wave, index) => ( WAVE_SHAPE_NAMES[value]} /> ))} {relabi?.waves.map((wave, index) => ( ))} Math.exp(value).toFixed(1)} color={"#a88"} /> ); } /** * UI Elements */ const ControlRow = ({ children }) => (
{children}
); const ControlBox = ({ children }) => (
{children}
); const SliderRow = ({ children }) => (
{children}
); const Label = ({ children }) => (
{children}
); const ControlSlider = ({ type, index, min, max, step, reverse, defaultValue, color, onChange, tipFormatter, }) => (
value)} />
);