A free, open source, and extensible speech-to-text application that works completely offline.
import React from "react";
import { useTranslation } from "react-i18next";
import { SettingContainer } from "./SettingContainer";
import { ResetButton } from "./ResetButton";
interface SliderProps {
value: number;
onChange: (value: number) => void;
min: number;
max: number;
step?: number;
disabled?: boolean;
label: string;
description: string;
descriptionMode?: "inline" | "tooltip";
grouped?: boolean;
showValue?: boolean;
formatValue?: (value: number) => string;
onReset?: () => void;
isResetting?: boolean;
}
export const Slider: React.FC<SliderProps> = ({
value,
onChange,
min,
max,
step = 0.01,
disabled = false,
label,
description,
descriptionMode = "tooltip",
grouped = false,
showValue = true,
formatValue = (v) => v.toFixed(2),
onReset,
isResetting = false,
}) => {
const { t } = useTranslation();
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange(parseFloat(e.target.value));
};
return (
<SettingContainer
title={label}
description={description}
descriptionMode={descriptionMode}
grouped={grouped}
layout="horizontal"
disabled={disabled}
>
<div className="w-full">
<div className="flex items-center space-x-1 h-6">
<input
type="range"
aria-label={label}
min={min}
max={max}
step={step}
value={value}
onChange={handleChange}
disabled={disabled}
className="flex-grow h-2 rounded-lg appearance-none cursor-pointer focus:outline-none focus:ring-2 focus:ring-logo-primary disabled:opacity-50 disabled:cursor-not-allowed"
style={{
background: `linear-gradient(to right, var(--color-background-ui) ${
((value - min) / (max - min)) * 100
}%, var(--color-line) ${((value - min) / (max - min)) * 100}%)`,
}}
/>
{showValue && (
<span className="text-sm font-medium text-text w-12 text-end">
{formatValue(value)}
</span>
)}
{onReset && (
<ResetButton
onClick={onReset}
disabled={disabled || isResetting}
ariaLabel={t("common.resetSetting", { setting: label })}
/>
)}
</div>
</div>
</SettingContainer>
);
};