Skip to content

Instantly share code, notes, and snippets.

@Goloburda
Last active January 31, 2020 14:30
Show Gist options
  • Save Goloburda/c170ee9428112ee245926066a1a782d8 to your computer and use it in GitHub Desktop.
Save Goloburda/c170ee9428112ee245926066a1a782d8 to your computer and use it in GitHub Desktop.
withStyles Material UI.
//Component to style doc: https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/Switch/Switch.js
import Switch from "@material-ui/core/Switch";
import styled from "styled-components";
import { withStyles } from "@material-ui/core/styles";
const StyledSwitch = styled(Switch)`
.MuiSwitch-colorSecondary {
color: green;
:hover {
background: red;
}
}
.MuiSwitch-colorSecondary.Mui-checked + .MuiSwitch-track {
background: green;
opacity: 1;
}
.MuiSwitch-colorSecondary + .MuiSwitch-track {
background: black;
opacity: 1;
}
.MuiSwitch-colorSecondary.Mui-checked {
color: black;
}
`;
const WithStyledSwitch = withStyles({
switchBase: {
color: "blue",
"&:hover": {
background: "red",
color: "white"
},
"&$checked + $track": {
color: "black",
backgroundColor: "pink",
opacity: 1
}
},
colorSecondary: {
"&$checked": {
color: "pink",
"&:hover": {
background: "transparent"
}
}
},
checked: {},
disabled: {},
track: {
background: "blue",
opacity: 1
}
})(Switch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment