switch.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Switch, SwitchProps, styled } from "@mui/material";
  2. const PublicShareSwitch = styled((props: SwitchProps) => (
  3. <Switch
  4. focusVisibleClassName=".Mui-focusVisible"
  5. disableRipple
  6. {...props}
  7. />
  8. ))(({ theme }) => ({
  9. width: 40,
  10. height: 24,
  11. padding: 0,
  12. "& .MuiSwitch-switchBase": {
  13. padding: 0,
  14. margin: 2,
  15. transitionDuration: "300ms",
  16. "&.Mui-checked": {
  17. transform: "translateX(16px)",
  18. color: "#fff",
  19. "& + .MuiSwitch-track": {
  20. backgroundColor:
  21. theme.palette.mode === "dark" ? "#2ECA45" : "#65C466",
  22. opacity: 1,
  23. border: 0,
  24. },
  25. "&.Mui-disabled + .MuiSwitch-track": {
  26. opacity: 0.5,
  27. },
  28. },
  29. "&.Mui-focusVisible .MuiSwitch-thumb": {
  30. color: "#33cf4d",
  31. border: "6px solid #fff",
  32. },
  33. "&.Mui-disabled .MuiSwitch-thumb": {
  34. color:
  35. theme.palette.mode === "light"
  36. ? theme.palette.grey[100]
  37. : theme.palette.grey[600],
  38. },
  39. "&.Mui-disabled + .MuiSwitch-track": {
  40. opacity: theme.palette.mode === "light" ? 0.7 : 0.3,
  41. },
  42. },
  43. "& .MuiSwitch-thumb": {
  44. boxSizing: "border-box",
  45. width: 20,
  46. height: 20,
  47. },
  48. "& .MuiSwitch-track": {
  49. borderRadius: 22 / 2,
  50. backgroundColor:
  51. theme.palette.mode === "light"
  52. ? "#E9E9EA"
  53. : theme.colors.fill.muted,
  54. opacity: 1,
  55. transition: theme.transitions.create(["background-color"], {
  56. duration: 500,
  57. }),
  58. },
  59. }));
  60. export default PublicShareSwitch;