slider update

This commit is contained in:
Alex Holliday committed 2026-01-30 18:28:30 +00:00
1 parent f6971ede69
commit f538f61464
2 files changed
+63 -43

No files matched your search

+61 -42
View File
@@ -1,69 +1,88 @@
import Typography from "@mui/material/Typography";
import { forwardRef } from "react"; import { forwardRef } from "react";
import Slider from "@mui/material/Slider"; import Slider from "@mui/material/Slider";
import type { SliderProps } from "@mui/material/Slider"; import type { SliderProps } from "@mui/material/Slider";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import { FieldLabel } from "./FieldLabel"; import { FieldLabel } from "./FieldLabel";
import Box from "@mui/material/Box";
import type { ResponsiveStyleValue } from "@mui/system";
export const SliderInput = forwardRef<HTMLSpanElement, SliderProps>(function SliderInput( interface SliderInputProps extends SliderProps {
{ sx, ...props }, sx?: SliderProps["sx"];
ref showValue?: boolean;
) { }
const theme = useTheme();
const additionalSx = Array.isArray(sx) ? sx : sx ? [sx] : [];
return ( export const SliderInput = forwardRef<HTMLSpanElement, SliderInputProps>(
<Slider ({ sx, showValue = false, ...props }, ref) => {
{...props} const theme = useTheme();
ref={ref} const additionalSx = Array.isArray(sx) ? sx : sx ? [sx] : [];
sx={[
{ return (
"& .MuiSlider-track": { <Stack
backgroundColor: theme.palette.primary.main, gap={theme.spacing(8)}
border: "none", direction={"row"}
}, alignItems={"center"}
"& .MuiSlider-rail": { >
backgroundColor: theme.palette.grey[300], {showValue && <Typography>{props.value}</Typography>}
opacity: 1, <Slider
}, {...props}
"& .MuiSlider-thumb": { ref={ref}
backgroundColor: "#fff", sx={[
"&:hover, &.Mui-focusVisible": { {
boxShadow: `0 0 0 8px ${theme.palette.primary.main}20`, "& .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`,
},
},
"& .MuiSlider-valueLabel": {
backgroundColor: theme.palette.primary.main,
},
}, },
}, ...additionalSx,
"& .MuiSlider-valueLabel": { ]}
backgroundColor: theme.palette.primary.main, />
}, </Stack>
}, );
...additionalSx, }
]} );
/>
);
});
interface SliderWithLabelProps extends SliderProps { interface SliderWithLabelProps extends SliderProps {
fieldLabel?: string; fieldLabel?: string;
required?: boolean; required?: boolean;
showValue?: boolean; showValue?: boolean;
valueSuffix?: string; sliderMaxWidth?: ResponsiveStyleValue<number | string>;
} }
export const SliderWithLabel = forwardRef<HTMLSpanElement, SliderWithLabelProps>( export const SliderWithLabel = forwardRef<HTMLSpanElement, SliderWithLabelProps>(
function SliderWithLabel( (
{ fieldLabel, required, showValue = true, valueSuffix = "", value, ...props }, { fieldLabel, required, showValue = true, value, sliderMaxWidth = "100%", ...props },
ref ref
) { ) => {
const theme = useTheme(); const theme = useTheme();
const labelText = showValue && value !== undefined const labelText = fieldLabel;
? `${fieldLabel}: ${value}${valueSuffix}`
: fieldLabel;
return ( return (
<Stack spacing={theme.spacing(2)}> <Stack spacing={theme.spacing(2)}>
{fieldLabel && <FieldLabel required={required}>{labelText}</FieldLabel>} {fieldLabel && <FieldLabel required={required}>{labelText}</FieldLabel>}
<SliderInput {...props} value={value} ref={ref} /> <Box maxWidth={sliderMaxWidth}>
<SliderInput
{...props}
showValue={showValue}
value={value}
ref={ref}
/>
</Box>
</Stack> </Stack>
); );
} }
+2 -1
View File
@@ -374,6 +374,7 @@ const CreateMonitorPage = () => {
render={({ field }) => ( render={({ field }) => (
<SliderWithLabel <SliderWithLabel
{...field} {...field}
sliderMaxWidth={{ xs: "100%", md: "50%" }}
fieldLabel={t("pages.createMonitor.form.incidents.option.checks.label")} fieldLabel={t("pages.createMonitor.form.incidents.option.checks.label")}
min={1} min={1}
max={25} max={25}
@@ -387,10 +388,10 @@ const CreateMonitorPage = () => {
render={({ field }) => ( render={({ field }) => (
<SliderWithLabel <SliderWithLabel
{...field} {...field}
sliderMaxWidth={{ xs: "100%", md: "50%" }}
fieldLabel={t( fieldLabel={t(
"pages.createMonitor.form.incidents.option.percentage.label" "pages.createMonitor.form.incidents.option.percentage.label"
)} )}
valueSuffix="%"
min={1} min={1}
max={100} max={100}
valueLabelDisplay="auto" valueLabelDisplay="auto"