material-ui offers a variety of components for styling, and there are two approaches to achieving this.
Implement Global Styles
One way is to define styles globally and apply them to the theme. Here's an example taken from the documentation http://www.material-ui.com/#/customization/themes:
import React from 'react';
import {cyan500} from 'material-ui/styles/colors';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import AppBar from 'material-ui/AppBar';
const muiTheme = getMuiTheme({
palette: {
textColor: cyan500,
},
appBar: {
height: 50,
},
});
class Main extends React.Component {
render() {
return (
<MuiThemeProvider muiTheme={muiTheme}>
<AppBar title="My AppBar" />
</MuiThemeProvider>
);
}
}
export default Main;
In the above example, the AppBar component has a height of 50px, which means every instance of the AppBar component will have that height when styled with the muiTheme
. You can find a list of available styles for each component here.
Utilize Style Attribute for Component Styles
For individual component styling, you can use the style attribute to pass specific styles.
Here's another example from the documentation where a margin of 12px is applied to a RaisedButton:
import React from 'react';
import RaisedButton from 'material-ui/RaisedButton';
const style = {
margin: 12,
};
const RaisedButtonExampleSimple = () => (
<div>
<RaisedButton label="Default" style={style} />
<RaisedButton label="Primary" primary={true} style={style} />
<RaisedButton label="Secondary" secondary={true} style={style} />
<RaisedButton label="Disabled" disabled={true} style={style} />
<br />
<br />
<RaisedButton label="Full width" fullWidth={true} />
</div>
);
export default RaisedButtonExampleSimple;
You can define styles in the same file or import them from a separate file for component usage.
If you need to apply multiple styles, you can use the spread operator like so: style={{...style1,...style2}}
. Make sure to check the component properties for available style options to customize different parts of the component.
Refer to the component properties and global style properties for styling guidance. This should assist you in applying the desired styles effectively!