mysticsymbolic.github.io/lib/numeric-slider.tsx

44 wiersze
1.0 KiB
TypeScript
Czysty Zwykły widok Historia

import classNames from "classnames";
2021-03-27 11:24:15 +00:00
import React from "react";
import { float, NumericRange, slugify } from "./util";
2021-03-27 11:24:15 +00:00
export type NumericSliderProps = NumericRange & {
id?: string;
2021-03-27 11:24:15 +00:00
label: string;
onChange: (value: number) => void;
value: number;
valueSuffix?: string;
disabled?: boolean;
2021-03-27 11:24:15 +00:00
};
export const NumericSlider: React.FC<NumericSliderProps> = (props) => {
const id = props.id || slugify(props.label);
2021-03-27 11:24:15 +00:00
return (
<div
className={classNames("thingy", "numeric-slider", {
disabled: props.disabled,
})}
>
<label htmlFor={id}>{props.label}: </label>
<span className="slider">
<input
type="range"
id={id}
min={props.min}
max={props.max}
value={props.value}
step={props.step}
disabled={props.disabled}
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
);
};