From d13f2873d53f615b2d497ab1e6d0fc12159a804a Mon Sep 17 00:00:00 2001 From: julian laplace Date: Tue, 9 May 2023 19:26:47 +0200 Subject: add controls --- src/ui/Controls.jsx | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 src/ui/Controls.jsx (limited to 'src/ui/Controls.jsx') diff --git a/src/ui/Controls.jsx b/src/ui/Controls.jsx new file mode 100644 index 0000000..f999e4f --- /dev/null +++ b/src/ui/Controls.jsx @@ -0,0 +1,171 @@ +/** + * 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)} + /> +
+); -- cgit v1.2.3-70-g09d2