slider w label

This commit is contained in:
Alex Holliday committed 2026-01-30 00:00:12 +00:00
1 parent e69283e3ed
commit f6971ede69
2 files changed
+40 -18

No files matched your search

+32 -3
View File
@@ -2,9 +2,13 @@ import { forwardRef } from "react";
import Slider from "@mui/material/Slider";
import type { SliderProps } from "@mui/material/Slider";
import { useTheme } from "@mui/material/styles";
import Stack from "@mui/material/Stack";
import { FieldLabel } from "./FieldLabel";
export const SliderInput = forwardRef<HTMLSpanElement, SliderProps>(
function SliderInput({ sx, ...props }, ref) {
export const SliderInput = forwardRef<HTMLSpanElement, SliderProps>(function SliderInput(
{ sx, ...props },
ref
) {
const theme = useTheme();
const additionalSx = Array.isArray(sx) ? sx : sx ? [sx] : [];
@@ -24,7 +28,6 @@ export const SliderInput = forwardRef<HTMLSpanElement, SliderProps>(
},
"& .MuiSlider-thumb": {
backgroundColor: "#fff",
border: `2px solid ${theme.palette.primary.main}`,
"&:hover, &.Mui-focusVisible": {
boxShadow: `0 0 0 8px ${theme.palette.primary.main}20`,
},
@@ -37,5 +40,31 @@ export const SliderInput = forwardRef<HTMLSpanElement, SliderProps>(
]}
/>
);
});
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>
);
}
);
+8 -15
View File
@@ -22,7 +22,7 @@ import {
Select,
Autocomplete,
SwitchComponent as Switch,
SliderInput as Slider,
SliderWithLabel,
} from "@/Components/v2/inputs";
import { useGet } from "@/Hooks/UseApi";
import { useMonitorForm } from "@/Hooks/useMonitorForm";
@@ -372,36 +372,29 @@ const CreateMonitorPage = () => {
name="statusWindowSize"
control={control}
render={({ field }) => (
<Stack spacing={theme.spacing(2)}>
<Typography variant="body2">
{t("pages.createMonitor.form.incidents.option.checks.label")}:{" "}
{field.value}
</Typography>
<Slider
<SliderWithLabel
{...field}
fieldLabel={t("pages.createMonitor.form.incidents.option.checks.label")}
min={1}
max={25}
valueLabelDisplay="auto"
/>
</Stack>
)}
/>
<Controller
name="statusWindowThreshold"
control={control}
render={({ field }) => (
<Stack spacing={theme.spacing(2)}>
<Typography variant="body2">
{t("pages.createMonitor.form.incidents.option.percentage.label")}:{" "}
{field.value}%
</Typography>
<Slider
<SliderWithLabel
{...field}
fieldLabel={t(
"pages.createMonitor.form.incidents.option.percentage.label"
)}
valueSuffix="%"
min={1}
max={100}
valueLabelDisplay="auto"
/>
</Stack>
)}
/>
</Stack>