2026-01-29 23:52:21 +00:00
|
|
|
import { forwardRef } from "react";
|
|
|
|
|
import Slider from "@mui/material/Slider";
|
|
|
|
|
import type { SliderProps } from "@mui/material/Slider";
|
|
|
|
|
import { useTheme } from "@mui/material/styles";
|
2026-01-30 00:00:12 +00:00
|
|
|
import Stack from "@mui/material/Stack";
|
|
|
|
|
import { FieldLabel } from "./FieldLabel";
|
2026-01-29 23:52:21 +00:00
|
|
|
|
2026-01-30 00:00:12 +00:00
|
|
|
export const SliderInput = forwardRef<HTMLSpanElement, SliderProps>(function SliderInput(
|
|
|
|
|
{ sx, ...props },
|
|
|
|
|
ref
|
|
|
|
|
) {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const additionalSx = Array.isArray(sx) ? sx : sx ? [sx] : [];
|
2026-01-29 23:52:21 +00:00
|
|
|
|
2026-01-30 00:00:12 +00:00
|
|
|
return (
|
|
|
|
|
<Slider
|
|
|
|
|
{...props}
|
|
|
|
|
ref={ref}
|
|
|
|
|
sx={[
|
|
|
|
|
{
|
|
|
|
|
"& .MuiSlider-track": {
|
|
|
|
|
backgroundColor: theme.palette.primary.main,
|
|
|
|
|
border: "none",
|
|
|
|
|
},
|
|
|
|
|
"& .MuiSlider-rail": {
|
|
|
|
|
backgroundColor: theme.palette.grey[300],
|
|
|
|
|
opacity: 1,
|
|
|
|
|
},
|
|
|
|
|
"& .MuiSlider-thumb": {
|
|
|
|
|
backgroundColor: "#fff",
|
|
|
|
|
"&:hover, &.Mui-focusVisible": {
|
|
|
|
|
boxShadow: `0 0 0 8px ${theme.palette.primary.main}20`,
|
2026-01-29 23:52:21 +00:00
|
|
|
},
|
|
|
|
|
},
|
2026-01-30 00:00:12 +00:00
|
|
|
"& .MuiSlider-valueLabel": {
|
|
|
|
|
backgroundColor: theme.palette.primary.main,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
...additionalSx,
|
|
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
interface SliderWithLabelProps extends SliderProps {
|
|
|
|
|
fieldLabel?: string;
|
|
|
|
|
required?: boolean;
|
|
|
|
|
showValue?: boolean;
|
|
|
|
|
valueSuffix?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const SliderWithLabel = forwardRef<HTMLSpanElement, SliderWithLabelProps>(
|
|
|
|
|
function SliderWithLabel(
|
|
|
|
|
{ fieldLabel, required, showValue = true, valueSuffix = "", value, ...props },
|
|
|
|
|
ref
|
|
|
|
|
) {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
|
|
const labelText = showValue && value !== undefined
|
|
|
|
|
? `${fieldLabel}: ${value}${valueSuffix}`
|
|
|
|
|
: fieldLabel;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack spacing={theme.spacing(2)}>
|
|
|
|
|
{fieldLabel && <FieldLabel required={required}>{labelText}</FieldLabel>}
|
|
|
|
|
<SliderInput {...props} value={value} ref={ref} />
|
|
|
|
|
</Stack>
|
2026-01-29 23:52:21 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|