Drawers

You can add the component on any page in the template. You need to follow the steps given below:

Step 1: You need to create a component for drawer list styling, a state and function to handle it's event. Also you need to add the code of drawer in the page where you want to add the component. Please check the code snippet given below, we have added the drawer in the Ecommerce Dashboard:

/**
 * Ecommerce Dashboard
 */

import React, { Component } from 'react'
...

const styles = {
   list: {
      width: 250,
   },
   listFull: {
      width: 'auto',
   },
};

class EcommerceDashboard extends Component {

    // Drawer State
	state = {
      left: false,
   };

   // Drawer Function
   toggleDrawer = (side, open) => () => {
      this.setState({
         [side]: open,
      });
   };
	render() {
		const { match } = this.props;
		const { classes } = this.props;
		const sideList = (
         <div className={classes.list}>
            <List>
					<ListItem button>
						<ListItemIcon>
						<i className="zmdi zmdi-inbox zmdi-hc-lg"></i>
						</ListItemIcon>
						<ListItemText primary="Inbox" />
					</ListItem>
					<ListItem button>
						<ListItemIcon>
						<i className="zmdi zmdi-star zmdi-hc-lg"></i>
						</ListItemIcon>
						<ListItemText primary="Starred" />
					</ListItem>
				</List>
         </div>
      );
		return (
			<div className="ecom-dashboard-wrapper">
				...
				<div className="row">
					<div className="col-sm-6 col-md-4 mb-30
					 ">
					
					    // Drawer Code
						<div>
                           <Button color="primary" className="text-white mr-10 mb-10" variant="contained" onClick={this.toggleDrawer('left', true)}>Open Left</Button>
                        
                           <Drawer open={this.state.left} onClose={this.toggleDrawer('left', false)}>
                              <div tabIndex={0} role="button" onClick={this.toggleDrawer('left', false)}
                                 onKeyDown={this.toggleDrawer('left', false)} >
                                 {sideList}
                              </div>
                           </Drawer>	
						</div>
				   ...
	
// Initialise with style			
export default withStyles(styles)( EcommerceDashboard);

Step 2: Now Import the component from its parent library.

import { withStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import Button from '@material-ui/core/Button';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';

We have given you an example of adding a temporary drawer on the Ecommerce Dashboard.

You can check some other layouts of drawer below. For adding any of the below layout in the template, please check their relative code in the src->routes->components->drawers->component folder.

Last updated