Menu

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 state and functions to handle it's events. Also you need to add the code of menu in the page where you want to add the component. Please check the code snippet given below, we have added the menu in the Ecommerce Dashboard:

/**
 * Ecommerce Dashboard
 */

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

export default class EcommerceDashboard extends Component {
    // Menu State
	state = {
      anchorEl: null,
      selectedIndex: 1,
   };
      
   // Menu Functions
   handleClickListItem = event => {
      this.setState({ anchorEl: event.currentTarget });
   };
   handleMenuItemClick = (event, index) => {
      this.setState({ selectedIndex: index, anchorEl: null });
   };
   handleClose = () => {
      this.setState({ anchorEl: null });
   };
   handleClick = event => {
      this.setState({ anchorEl: event.currentTarget });
   };
	render() {
	   ...
		const { anchorEl } = this.state;
		return (
         ...
                        // Menu Code
						<div>
							<Button variant="contained" color="primary" className="text-white" aria-owns={anchorEl ? 'simple-menu' : null} aria-haspopup="true" onClick={this.handleClick} >
								Open Menu
							</Button>
							<Menu id="simple-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={this.handleClose} >
								<MenuItem onClick={this.handleClose}>Profile</MenuItem>
								<MenuItem onClick={this.handleClose}>My account</MenuItem>
								<MenuItem onClick={this.handleClose}>Logout</MenuItem>
							</Menu>
						</div>
				...

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

import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import Button from '@material-ui/core/Button';

We have given you an example of adding a simple menu on the Ecommerce Dashboard.

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

Last updated