index.jsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {styled} from "@mui/material/styles";
  2. import Switch from "@mui/material/Switch";
  3. const AntSwitch = styled(Switch)(({ theme }) => ({
  4. width: 28,
  5. height: 16,
  6. padding: 0,
  7. display: 'flex',
  8. '&:active': {
  9. '& .MuiSwitch-thumb': {
  10. width: 15,
  11. },
  12. '& .MuiSwitch-switchBase.Mui-checked': {
  13. transform: 'translateX(9px)',
  14. },
  15. },
  16. '& .MuiSwitch-switchBase': {
  17. padding: 2,
  18. color: 'rgba(153,164,176,.6)',
  19. transform: 'translateX(-2px)',
  20. '&.Mui-checked': {
  21. transform: 'translateX(12px)',
  22. color: 'var(--primary-color)',
  23. '& + .MuiSwitch-track': {
  24. opacity: 1,
  25. backgroundColor: '#3bc11733',
  26. },
  27. },
  28. },
  29. '& .MuiSwitch-thumb': {
  30. boxShadow: '0 2px 4px 0 rgb(0 35 11 / 20%)',
  31. width: 12,
  32. height: 12,
  33. borderRadius: 6,
  34. transition: theme.transitions.create(['width'], {
  35. duration: 200,
  36. }),
  37. },
  38. '& .MuiSwitch-track': {
  39. borderRadius: 16 / 2,
  40. opacity: 1,
  41. height: '70%',
  42. width:'90%',
  43. marginTop:'10%',
  44. backgroundColor:'rgba(0,0,0,.25)',
  45. boxSizing: 'border-box',
  46. },
  47. }));
  48. export default AntSwitch;