Advertisement
Guest User

Burger.

a guest
Jun 4th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import {Motion, spring, presets} from 'react-motion';
  3. import NavMenuStyles from './NavMenuStyles';
  4.  
  5. {/*Credit to Duarte Monteiro for this code*/}
  6. class NavMenu extends Component {
  7.     constructor(props) {
  8.         super(props);
  9.         this.state = {
  10.             toggle: false
  11.           }
  12.     }
  13.  
  14.     handleClick() {
  15.         this.setState({toggle: !this.state.toggle})
  16.       }
  17.  
  18.     render () {
  19.  
  20.     const style = {
  21.       overflow: 'visible',
  22.       cursor: 'pointer',
  23.       // disable touch highlighting on devices
  24.       WebkitTapHighlightColor: "rgba(0,0,0,0)",
  25.     }
  26.         return (
  27.             <NavMenuStyles>
  28.             {/* <NavList/> */}
  29.             <svg
  30.         viewBox="0 0 96 96"
  31.         height="1em"
  32.         onClick={this.handleClick.bind(this)}
  33.         style={style}
  34.       >
  35.         <Motion
  36.           style={{
  37.             x: spring(this.state.toggle ? 1 : 0, presets.wobbly ),
  38.             y: spring(this.state.toggle ? 0: 1, presets.wobbly ),
  39.           }}
  40.         >
  41.           {({ x, y }) =>
  42.             <g
  43.               id="navicon"
  44.               fill="none"
  45.               stroke="currentColor"
  46.               strokeWidth="14"
  47.               strokeLinecap="round"
  48.               strokeLinejoin="round"
  49.              >
  50.               <line
  51.                 transform={`translate(${x * 12}, ${x * -7}) rotate(${x * 45}, 7, 26)`}
  52.                 x1="7" y1="26" x2="89" y2="26"
  53.                />
  54.               <line
  55.                 transform={`translate(${x * 12}, ${x * 7}) rotate(${x * -45}, 7, 70)`}
  56.                 x1="7" y1="70" x2="89" y2="70"
  57.                />
  58.               <line
  59.                 transform={`translate(${x * -96})`}
  60.                 opacity={y}
  61.                 x1="7" y1="48" x2="89" y2="48"
  62.                />
  63.             </g>
  64.           }
  65.         </Motion>
  66.       </svg>
  67.  
  68.       </NavMenuStyles>
  69.            
  70.         );
  71.     }
  72.  
  73. }
  74.  
  75. export default NavMenu;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement