/** * 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", "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 === "frequency") { relabi.waves[index].frequency = Math.exp(value); } if (type === "shape") { relabi.waves[index].shape = WAVE_SHAPE_NAMES[value]; } }, [relabi] ); return ( {relabi?.bounds.map((bound, index) => ( ))} {relabi?.waves.map((wave, index) => ( ))} {relabi?.waves.map((wave, index) => ( WAVE_SHAPE_NAMES[value]} /> ))} ); } /** * 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)} />
);