Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import * as React from 'react';
|
|
import { alpha, styled } from '@mui/material/styles';
|
|
import Slider, { SliderProps } from '@mui/material/Slider';
|
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
import Switch from '@mui/material/Switch';
|
|
|
|
interface StyledSliderProps extends SliderProps {
|
|
success?: boolean;
|
|
}
|
|
|
|
const StyledSlider = styled(Slider, {
|
|
shouldForwardProp: (prop) => prop !== 'success',
|
|
})<StyledSliderProps>(({ theme }) => ({
|
|
width: 300,
|
|
variants: [
|
|
{
|
|
props: ({ success }) => success,
|
|
style: {
|
|
color: theme.palette.success.main,
|
|
'& .MuiSlider-thumb': {
|
|
[`&:hover, &.Mui-focusVisible`]: {
|
|
boxShadow: `0px 0px 0px 8px ${alpha(theme.palette.success.main, 0.16)}`,
|
|
},
|
|
[`&.Mui-active`]: {
|
|
boxShadow: `0px 0px 0px 14px ${alpha(theme.palette.success.main, 0.16)}`,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}));
|
|
|
|
export default function DynamicCSS() {
|
|
const [success, setSuccess] = React.useState(false);
|
|
|
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
setSuccess(event.target.checked);
|
|
};
|
|
|
|
return (
|
|
<React.Fragment>
|
|
<FormControlLabel
|
|
control={
|
|
<Switch
|
|
checked={success}
|
|
onChange={handleChange}
|
|
color="primary"
|
|
value="dynamic-class-name"
|
|
/>
|
|
}
|
|
label="Success"
|
|
/>
|
|
<StyledSlider success={success} defaultValue={30} sx={{ mt: 1 }} />
|
|
</React.Fragment>
|
|
);
|
|
}
|