2021-04-03 21:01:13 +00:00
|
|
|
import classNames from "classnames";
|
2021-03-27 11:24:15 +00:00
|
|
|
import React from "react";
|
2021-03-27 19:01:58 +00:00
|
|
|
import { float, NumericRange, slugify } from "./util";
|
2021-03-27 11:24:15 +00:00
|
|
|
|
2021-03-27 19:01:58 +00:00
|
|
|
export type NumericSliderProps = NumericRange & {
|
2021-03-27 12:11:07 +00:00
|
|
|
id?: string;
|
2021-03-27 11:24:15 +00:00
|
|
|
label: string;
|
|
|
|
onChange: (value: number) => void;
|
|
|
|
value: number;
|
|
|
|
valueSuffix?: string;
|
2021-04-03 21:01:13 +00:00
|
|
|
disabled?: boolean;
|
2021-03-27 11:24:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const NumericSlider: React.FC<NumericSliderProps> = (props) => {
|
2021-03-27 12:11:07 +00:00
|
|
|
const id = props.id || slugify(props.label);
|
|
|
|
|
2021-03-27 11:24:15 +00:00
|
|
|
return (
|
2021-04-03 21:01:13 +00:00
|
|
|
<div
|
|
|
|
className={classNames("thingy", "numeric-slider", {
|
|
|
|
disabled: props.disabled,
|
|
|
|
})}
|
|
|
|
>
|
2021-03-27 12:11:07 +00:00
|
|
|
<label htmlFor={id}>{props.label}: </label>
|
2021-03-29 17:03:54 +00:00
|
|
|
<span className="slider">
|
|
|
|
<input
|
|
|
|
type="range"
|
|
|
|
id={id}
|
|
|
|
min={props.min}
|
|
|
|
max={props.max}
|
|
|
|
value={props.value}
|
|
|
|
step={props.step}
|
2021-04-03 21:01:13 +00:00
|
|
|
disabled={props.disabled}
|
2021-03-29 17:03:54 +00:00
|
|
|
onChange={(e) => props.onChange(float(e.target.value))}
|
|
|
|
/>
|
|
|
|
<span>
|
|
|
|
{" "}
|
|
|
|
{props.value}
|
|
|
|
{props.valueSuffix}
|
|
|
|
</span>
|
2021-03-27 11:24:15 +00:00
|
|
|
</span>
|
2021-03-27 12:34:22 +00:00
|
|
|
</div>
|
2021-03-27 11:24:15 +00:00
|
|
|
);
|
|
|
|
};
|