mirror of
https://github.com/logos-storage/logos-storage-marketplace-ui.git
synced 2026-01-19 13:53:12 +00:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { ChangeEvent, FormEvent, useState } from "react";
|
|
import "./Range.css";
|
|
|
|
type Props = {
|
|
label?: string;
|
|
max: number;
|
|
labels: string[];
|
|
className?: string;
|
|
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
defaultValue?: number | string;
|
|
value?: number | string;
|
|
};
|
|
|
|
export function Range({
|
|
label,
|
|
max,
|
|
onChange,
|
|
defaultValue,
|
|
value,
|
|
className = "",
|
|
}: Props) {
|
|
const [val, setVal] = useState(value);
|
|
|
|
const onInput = (e: FormEvent<HTMLInputElement>) => {
|
|
setVal(parseInt(e.currentTarget.value, 10));
|
|
};
|
|
|
|
return (
|
|
<div className={className}>
|
|
{label}
|
|
<input
|
|
type="range"
|
|
max={max}
|
|
min={1}
|
|
className="range glow"
|
|
onChange={onChange}
|
|
defaultValue={defaultValue}
|
|
value={value}
|
|
style={{ "--val": val } as React.CSSProperties}
|
|
onInput={onInput}
|
|
/>
|
|
{/* <div className="range-labels">
|
|
{labels.map((l) => (
|
|
<div className="range-label" key={l}>
|
|
{l}
|
|
</div>
|
|
))}
|
|
</div> */}
|
|
</div>
|
|
);
|
|
}
|