Skip to content

Instantly share code, notes, and snippets.

@wschenk
Created November 29, 2017 19:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wschenk/378f430e8554259c4dbe2c17ce07972f to your computer and use it in GitHub Desktop.
Save wschenk/378f430e8554259c4dbe2c17ce07972f to your computer and use it in GitHub Desktop.
create-react-app material-ui navbar example
import React, {Component} from 'react'
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import Typography from 'material-ui/Typography';
import IconButton from 'material-ui/IconButton';
import MenuIcon from 'material-ui-icons/Menu';
import AccountCircle from 'material-ui-icons/AccountCircle';
const styles = theme => ({
root: {
marginTop: theme.spacing.unit *3,
width: '100%'
},
flex: {
flex: 1
},
menuButton: {
marginLeft: -12,
marginRight: 20
}
})
class Navbar extends Component {
render() {
const {classes} = this.props;
return (
<AppBar position="static" elevation={0}>
<Toolbar>
<IconButton className={classes.menuButton} color="contrast" onClick={this.props.toggleDrawer}><MenuIcon/></IconButton>
<Typography className={classes.flex} type="title" color="inherit">
Material-UI Demo App
</Typography>
<div>
<IconButton color="contrast" onClick={this.props.login}>
<AccountCircle/>
</IconButton>
</div>
</Toolbar>
</AppBar>
)
}
}
Navbar.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(Navbar);
@arungm1987
Copy link

you can create a file with AppBar.js and copy above code and then in any other page you can include by importing it as import AppBar from './Appbar';

@NehaChaudhary311
Copy link

Where do I define login and toggleDrawer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment