Reputation: 355
I'm using the material-table (https://material-table.com/).
My issue is that I want to change the table border-radius and table shadow, apparently, this option does not exist using 'option feature'
But when I inspect the table I could modify radius and shadow as you can see below :
I'm wondering how to override these values from Reactjs :
const useStyles = makeStyles(theme => ({
root: {
}
}));
const MainTable = props => {
const {className, params, ...rest} = props
(...)
return (
<MaterialTable
className={classes.MuiPaperRounded}
columns={[
{title: 'Equipement', field: 'equipement'},
{title: 'TAG', field: 'tag'},
{title: 'Nombre de points de mesures', field: 'nombreDePointsDeMesures'},
{title: 'Mesuré', field: 'mesure', type: 'boolean'}
]}
data={rows}
icons={(...)}
options={{
tableLayout: {backgroundColor: 'green'},
}}
title="Routine vibration"
/>
);
};
Upvotes: 8
Views: 37002
Reputation: 1060
You can override the component entirely with your own if you want (here we put a Box instead for example):
<MaterialTable title="Available Options"
isLoading={loading}
icons={tableIcons}
columns={tableColumns}
data={tableData}
components={{
Container: props => <Box>{props.children}</Box>
}}
... the rest of your settings
Upvotes: 0
Reputation: 901
The correct way to override theme styles is described in the docs at https://mui.com/material-ui/customization/theme-components/#global-style-overrides.
For your scenario the override would be:
const theme = createTheme({
components: {
// Name of the component
MuiPaper: {
styleOverrides: {
// Name of the slot
root: {
// Some CSS
borderRadius: "100px",
boxShadow: "10px 10px 5px 0px rgba(0,0,0,0.75)",
},
},
},
},
});
Upvotes: 3
Reputation: 11
root: {
display: 'flex'
"&.MuiPaper-root":{
backgroundColor:"#fafafa" //as an Example
}
},
//that was working
Upvotes: 1
Reputation: 15146
If it's difficult to customize styles inside third party component,
Use nesting selector with className from outside would be fine.
For your example:
"& .MuiPaper-root"
Full code:
import React from "react";
import "./styles.css";
import { makeStyles } from "@material-ui/core";
import MaterialTable from "material-table";
const useStyles = makeStyles(theme => ({
root: {
"& .MuiPaper-root": {
borderRadius: "100px",
boxShadow: "10px 10px 5px 0px rgba(0,0,0,0.75);"
}
}
}));
export default function App() {
const classes = useStyles();
return (
<div className={classes.root}>
<MaterialTable />
</div>
);
}
Upvotes: 19