I use makeStyles to style a custom card but the MUI default styles are overriding them, when I use !important my styles are applying otherwise they are getting overridden.
const useStyles = makeStyles({
'dashboard-card': {
boxSizing: 'border-box',
borderRadius: '20px',
boxShadow:
'0px 4px 4px rgba(50, 50, 71, 0.08), 0px 4px 8px rgba(50, 50, 71, 0.06)',
},
});
type DashboardCardProps = {
children: JSX.Element | JSX.Element[];
className?: string;
};
const DashboardCard = ({ children, className }: DashboardCardProps) => {
const classes = useStyles();
return <Card className={`${className} ${classes['dashboard-card']}`}>{children}</Card>;
};
export default DashboardCard;
Is there any way how can I get around this, is it possible to remove the default stylings from the theme?
const theme = createTheme({
palette: {
primary: {
light: '#21B8F9',
main: '#103B66',
dark: '#000032',
},
},
components: {
MuiCard: {
styleOverrides : {
root: {}
}
},
MuiPaper: {
styleOverrides: {
root: {}
}
}
},
typography: {
fontFamily: ['Source Sans Pro', 'Noto Sans HK'].join(','),
},
});
Related
I want to change all my Material UI Select component's dropdown menu style with createTheme, but it doesn't work.
Below is my code. Did I get something wrong?
import { createTheme } from '#mui/material/styles';
const theme = createTheme({
// palette, typography, etc.
components: {
MuiSelect: {
defaultProps: {
MenuProps: {
PaperProps: {
style: {
boxShadow: '0px 0px 10px rgba(0, 0, 0, 0.2)',
},
},
},
},
styleOverrides: {
// do something
},
},
},
});
I'm trying to create my own theme with Material-Ui v.5.4.0. And I faced with problem. I can't change TextField focused border color and width. I spend hours for research and didn't find working solution. And I started to think is it even possible to do that in theme? But it's not logical.
My current theme code:
import { createTheme } from '#mui/material/styles'
// Colors
const blue = '#5A5BD4'
const blueDark = '#4f4fd8'
// Parameters
const buttonsBorderRadius = 20
const buttonPadding = '5px 15px'
const inputBorderRadius = 10
const theme = createTheme({
components: {
// Buttons
MuiButton: {
variants: [
// Blue button
{
props: { variant: 'blueButton' },
style: {
backgroundColor: blue,
color: '#ffffff',
borderRadius: buttonsBorderRadius,
textTransform: 'none',
padding: buttonPadding,
'&:hover': {
backgroundColor: blueDark
}
}
},
// Transparent button
{
props: { variant: 'transparentButton' },
style: {
color: blue,
borderRadius: buttonsBorderRadius,
textTransform: 'none',
padding: buttonPadding
}
}
]
},
// Inputs
MuiOutlinedInput: {
styleOverrides: {
root: {
borderRadius: inputBorderRadius,
'& fieldset': {
border: `1px solid ${blue}`
}
},
focus: {
border: `1px solid ${blueDark}`
}
}
}
}
})
export default theme
My input code:
<TextField
size='small'
variant='outlined'
label={t('paslelbimo_data_nuo')}
type='date'
InputLabelProps={{
shrink: true
}}
fullWidth
value={publicationDateFrom}
onChange={(e) => setPublicationDateFrom(e.target.value)}
/>
Since I wasn't able to tell exactly what your desired effect was on focus vs not focused, I decided to just create a generic example, with overly dramatic styling, that may be useful to modify for your needs:
Essentially, I'm just overriding .MuiOutlinedInput-notchedOutline for both the focused an unfocused states:
const theme = createTheme({
components: {
// Inputs
MuiOutlinedInput: {
styleOverrides: {
root: {
...
"& .MuiOutlinedInput-notchedOutline": {
border: `5px solid green`,
},
"&.Mui-focused": {
"& .MuiOutlinedInput-notchedOutline": {
border: `5px dotted red`,
},
}
},
}
}
}
});
Working example CodeSandbox: https://codesandbox.io/s/customstyles-material-demo-forked-uri26?file=/theme.js:84-531
I am using a Material UI React component called TextareaAutosize:
<TextareaAutosize
minRows={2}
style={resize: 'none'}
defaultValue={<span style={{fontSize: "20px", color: "blue"}}>Content Body</span>}
/>
Instead of getting Content Body in the TextareaAutosize component, I'm getting this as the default value:
How do I add styling to the defaultValue?
Edit code on Stack Blitz: https://stackblitz.com/edit/react-fnx6we?file=demo.js
EDIT: For clarification, I want ONLY the defaultValue to have the styling I applied. When the user starts typing or removes the defaultValue and starts typing, the styling of the defaultValue should NOT be applied.
defaultValue parameter accepts String values only. Use parameter style to define additional styling. Or use jss like styling for components (check #mui/styles) EDIT: to change styling of the element "on the fly" you will need to use additional variables and functions. Check demo on code on Stack Blitz.
import React, { useState } from 'react';
import TextareaAutosize from '#mui/material/TextareaAutosize';
import { makeStyles } from '#mui/styles';
const useStyles = makeStyles({
textAreaWithStyle: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
fontSize: '20px',
color: 'blue',
resize: 'none',
},
textAreaWithoutStyle: {
resize: 'none',
},
});
export default function MaxHeightTextarea() {
const classes = useStyles();
const [valueOfInput, setValueOfInput] = useState('Default Text');
const returnStyleBasedOnInput = () => {
if (valueOfInput === 'Default Text') {
return classes.textAreaWithStyle;
} else {
return classes.textAreaWithoutStyle;
}
};
const checkIfDefaultValueInTextAreaAndRemooveIt = () => {
if (valueOfInput === 'Default Text') {
setValueOfInput('');
}
};
const onInputChange = (e) => {
setValueOfInput(e.target.value);
};
return (
<TextareaAutosize
maxRows={4}
className={returnStyleBasedOnInput()}
value={valueOfInput}
onChange={onInputChange}
onClick={checkIfDefaultValueInTextAreaAndRemooveIt}
/>
);
}
Edit code on Stack Blitz: https://stackblitz.com/edit/react-fnx6we-3vdn7i?file=demo.js
How add custom scrollbar in material ui.?
I have search many things to add such scrollbar finally i have got this.
thank you everyone.
import React from "react";
import { Box} from "#material-ui/core";
import { makeStyles } from "#material-ui/core/styles";
const useStyles = makeStyles((theme) => ({
root: {
"&::-webkit-scrollbar": {
width: 7,
},
"&::-webkit-scrollbar-track": {
boxShadow: `inset 0 0 6px rgba(0, 0, 0, 0.3)`,
},
"&::-webkit-scrollbar-thumb": {
backgroundColor: "darkgrey",
outline: `1px solid slategrey`,
},
},
}));
export default const Customscroll= (props) => {
const classes = useStyles();
return (
<Box className={classes.root}>
</Box>
);
};
I am trying to change the color of the all the Button's in the project by overriding the theme css. The color of the button has changed but hover color is still transparent, how can I override it ?
Is there any other way to this apart from adding a class to each of my buttons.
Also shouldn't all the variants of a button follow the css of the root?
const theme = createMuiTheme({
palette: {
primary: {
light: '#35C37D',
main: '#35C37D',
dark: '#35C37D',
// contrastText: will be calculated to contrast with palette.primary.main
},
secondary: {
light: '#35C37D',
main: '#35C37D',
// dark: will be calculated from palette.secondary.main,
contrastText: '#35C37D',
},
// error: will use the default color
},
overrides: {
MuiButton: {
// Name of the rule
root: {
// Some CSS
background: 'rgba(53, 195, 125, 100)',
borderRadius: 0,
border: 0,
colorInherit: '#fff',
color: 'white',
height: 40,
padding: '0 30px',
boxShadow: '4px 9px 26px 0 rgba(16,124,71,0.10)',
'&:hover': {
textDecoration: 'none',
backgroundColor: '#35C37D',
// Reset on touch devices, it doesn't add specificity
'#media (hover: none)': {
backgroundColor: '#35C37D',
},
},
},
textPrimary: {
color: '#fff',
},
textSecondary: {
color: '#fff',
},
contained: {
color: '#fff',
},
containedPrimary: {
color: '#fff',
},
containedSecondary: {
color: '#fff',
},
raised: {
color: '#fff',
},
colorInherit: {
color: '#fff',
},
},
},
typography: {
fontFamily: 'azo-sans-web',
// The default font size of the Material Specification.
fontSize: 14, // px
fontWeightLight: 300,
fontWeightRegular: 400,
fontWeightMedium: 500,
// Tell Material-UI what's the font-size on the html element.
// 16px is the default font-size used by browsers.
htmlFontSize: 16,
},
});
I figured it out.
Here is the code sandbox if anyone cares https://codesandbox.io/s/y2qyk9rn4x
Just need to add this for each variant:
outlined: {
"&:hover": {
backgroundColor: "#35C37D"
}
},