Why Material UI Theme overrides doesn't work? - reactjs

I use the material UI "createTheme" function. When ı write overrides for button and switch it's doesn't work. Material UI's None of the overrides features work but the theme palette, font-size working. Why it doesn't work? Thanks in advance.
// My overrides
overrides: {
MuiButton: {
primary: {
background: "pink",
},
sizeSmall: {
height: 22.5,
fontSize: 10,
padding: "0 15px",
},
sizeLarge: {
height: 37,
padding: "0 30px",
fontSize: 16,
},
text: {
background: "#1AD971",
borderRadius: 4,
border: 0,
color: "white",
padding: "0 22px",
height: 30,
textAlign: "center",
lineHeight: 1,
fontSize: 14,
fontWeight: 400,
"&:hover": {
backgroundColor: "#0BBF5D",
},
},
contained: {
backgroundColor: "#FFFFFF",
color: "#000000",
borderRadius: 30,
},
outlined: {
color: "#1AD971",
border: "1px solid #1AD971",
borderRadius: "15px",
},
},
MuiSwitch: {
switchBase: {
color: "#73889D",
},
colorSecondary: {
"&$checked": {
color: "#FFFFFF",
},
},
track: {
opacity: 1,
backgroundColor: "#213348",
"$checked$checked + &": {
opacity: 1,
backgroundColor: "#FFC231",
},
},
},
},

If you are working on MUI version 5, as mentioned in the comment above, you should be using the below code
const theme = createTheme({
components: {
MuiButton: {
styleOverrides: {
root: {
border: '1px solid #ff4742',
background: 'white',
borderRadius: 12,
border: 0,
color: 'black',
height: 48,
padding: '0 30px',
fontWeight: 'bold',
boxShadow: '1px 2px 4px rgb(0 0 0 / 10%)',
}
}
},
}});

Related

Need to remove underline on hover and on focus MUI TimePicker

Cannot find a way to remove underline when using material-ui TimePicker and overriding styles.
Here is how i am overriding styles:
const muiTimePickerStyle = createTheme({
overrides: {
MuiTextField: {
root: {
width: "100%",
'&:after': {
underline: "none",
textDecoration: "none",
}
}
},
MuiInput: {
root: {
borderRadius: 0,
backgroundColor: "#fff",
border: '1px solid pink',
fontSize: 16,
padding: '10px 12px',
width: '100%',
underline: "none",
textDecoration: "none",
'&:hover': {
}
},
underline: {
underline: "none",
'&:hover': {
}
}
}
}
});
My code in CodeSandbox
Here's what you are looking for. I've added the after effect too if you wanted to remove the blue line when active.
underline: {
'&:hover:not(.Mui-disabled):before': {
borderBottom: 'none'
},
'&:after': {
borderBottom: 'none'
}
}
Enjoy

problem in withStyle defined in Material UI because of difference className in server and client

I'm using nextjs and Sass. All of my styles are worked fine but just when I'm using withStyles this warning appears
const LikeButton = withStyles((theme: Theme) => ({
root: {
color: "#666666",
fontSize: "1.3125rem!important",
fontWeight: 700,
maxWidth: "51px!important",
width: "51px!important",
minWidth: "51px!important",
backgroundColor: "#fcfbfa",
marginLeft: "1rem",
border: "1px solid #dcdcdc",
"& svg": {
fill: "currentColor",
color: "currentColor",
},
"&:hover": {
color: theme.palette.secondary.main,
backgroundColor: "#fcfbfa",
},
"&.Mui-disabled": {
backgroundColor: "#e6e6e6",
color: "#666666!important",
},
},
}))(Button);
I did all solutions mentioned in this link
https://www.mashen.zone/thread-3621719.htm
but didn't solve.

Using keyframes in JSS

I'm trying to apply an animation to an arrow in a react component using JSS. I can't seem to get the keyframes correct and getting the error TypeError: container.addRule(...).addRule is not a function
const useStyles = createUseStyles({
'#keyframes sdb05': {
from: {
transform: 'rotate(-45deg) translate(0, 0)',
opacity: 0
},
to: {
transform: 'rotate(-45deg) translate(-20px, 20px)',
opacity: 1
}
},
arrow:{
animationName: '$sdb05',
zIndex: 2,
display: 'inline-block',
'-webkit-transform': 'translate(0, -50%)',
transform: 'translate(0, -50%)',
color: '#fff',
letterSpacing: '.1em',
textDecoration: 'none',
transition: 'opacity .3s',
width: 50,
height: 50,
backgroundColor: 'rgb(255,255,255, 0.5)',
borderRadius: '50%',
'&:after': {
position: 'absolute',
bottom: 0,
left: 0,
content: '',
width: '100%',
height: '80%',
background: '-webkit-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,.8) 80%,rgba(0,0,0,.8) 100%)'
},
'& a': {
'& span':{
position: 'absolute',
top: 8,
left: '50%',
width: 24,
height: 24,
marginLeft: -12,
borderLeft: '2px solid #000',
borderBottom: '2px solid #000',
'-webkit-transform': 'rotate(-45deg)',
transform: 'rotate(-45deg)',
'-webkit-animation': 'sdb05 1.5s infinite',
'animation': 'sdb05 1.5s infinite',
boxSizing: 'border-box'
},
'&:hover': {
opacity: .5
}
}
}
});
const Arrow = () => {
const classes = useStyles();
return (
<div className={classes.arrow}>
<span></span>
</div>
);
};
How can I correctly set my keyframes to enable the animation?
The animation should function like this: link
If you are using JSS v10 or higher, the code you posted now is correct, you can see what is being generated in the browser and here https://cssinjs.org/repl
Now you have some problem with the actual animation, not with JSS.
Add the #keyframes on the top level, not inside of the rule

Tailwind CSS :before pseudo class

I've now been working in circles trying to understand what is happening. I'm making a design library using storybook with Tailwind. I can't seem to get the :before pseudo class to work. No matter where I place it in the styling, then it's never rendered.
An example is that I am trying to make a component which uses react-slick, and want to style the navigation:
'& .slick-dots': {
bottom: -30,
display: 'block',
left: 4,
listStyle: 'none',
margin: 0,
padding: 0,
position: 'absolute',
textAlign: 'center',
width: '100%',
'& li': {
cursor: 'pointer',
display: 'inline-block',
height: 20,
margin: '0 5px',
padding: 0,
position: 'relative',
width: 20,
'& button': {
border: 0,
background: 'transparent',
display: 'block',
height: 20,
width: 20,
outline: 'none',
lineHeight: 0,
fontSize: 0,
color: 'transparent',
padding: 5,
cursor: 'pointer',
'&:before': {
position: 'absolute',
top: 0,
left: 0,
content: '',
width: 20,
height: 20,
fontFamily: 'sans-serif',
fontSize: 20,
lineHeight: 20,
textAlign: 'center',
color: '#000000',
opacity: 0.75,
display: 'inline-block',
},
},
},
},
Found the problem. The :before pseudo class won't render unless there is content, but in the case of css in js, then content needs to look like this content: '"text"', and not content: 'text',
Another way is to define your content in the tailwind.config.js
theme: {
extend: {
content: {
'arrowNeonGreen': 'url("../src/images/icons/arrow-neon-green.svg")',
},
fontSize: {
...
You can render it using the following className. Make sure to include an inline-block and width.
<Link className="after:content-arrowNeonGreen after:inline-block after:w-8">Learn More</Link>
You can also apply a hover state like this hover:after:content-arrowNeonGreen
<Link className="hover:after:content-arrowNeonGreen after:content-arrowBlack after:inline-block after:w-8">Learn More</Link>
to get the :before class to work, you have to use tailwindcss-pseudo-elements package to customize your pseudo elements. check the docs below
https://www.npmjs.com/package/tailwindcss-pseudo-elements

TypeError withstyles is not a function react export default

I am trying to import withstyles from material-ui and then, use the default function withstyles but always have the same error.
import { withStyles } from "material-ui/styles/withStyles";
import { loginPageStyle } from "../assets/jss/material-kit-react/views/loginPage.jsx";
export default withStyles(loginPageStyle)(LoginPage);
And here you can see the error. I try to debug with chrome console but can not find any solution yet.
Using "material-ui": "1.0.0-beta.45"
That is the loginPageStyle.. It is an example from material-kit
import { container } from "../../material-kit-react.jsx";
const signupPageStyle = {
container: {
...container,
zIndex: "2",
position: "relative",
paddingTop: "20vh",
color: "#FFFFFF"
},
cardHidden: {
opacity: "0",
transform: "translate3d(0, -60px, 0)"
},
pageHeader: {
minHeight: "100vh",
height: "auto",
display: "inherit",
position: "relative",
margin: "0",
padding: "0",
border: "0",
alignItems: "center",
"&:before": {
background: "rgba(0, 0, 0, 0.5)"
},
"&:before,&:after": {
position: "absolute",
zIndex: "1",
width: "100%",
height: "100%",
display: "block",
left: "0",
top: "0",
content: '""'
}
},
form: {
margin: "0"
},
cardHeader: {
width: "auto",
textAlign: "center",
marginLeft: "20px",
marginRight: "20px",
marginTop: "-40px",
padding: "20px 0",
marginBottom: "15px",
},
socialIcons: {
maxWidth: "24px",
marginTop: "0",
width: "100%",
transform: "none",
left: "0",
top: "0",
height: "100%",
lineHeight: "41px",
fontSize: "20px"
},
divider: {
marginTop: "30px",
marginBottom: "0px",
textAlign: "center"
},
cardFooter: {
paddingTop: "0rem",
border: "0",
borderRadius: "6px",
justifyContent: "center !important"
},
socialLine: {
marginTop: "1rem",
textAlign: "center",
padding: "0",
},
inputIconsColor: {
color: "#495057",
}
};
export default signupPageStyle;
Import like
import { withStyles } from '#material-ui/core/styles';

Resources