Skip to content

Instantly share code, notes, and snippets.

@emmabostian
Created January 12, 2020 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmabostian/e4e260041d535a9b217e58ed8957e452 to your computer and use it in GitHub Desktop.
Save emmabostian/e4e260041d535a9b217e58ed8957e452 to your computer and use it in GitHub Desktop.
import React, { useState } from "react";
import ReactDOM from "react-dom";
import { useSpring } from "react-spring";
import { MenuRight, MenuFull } from "./Menu";
import "./styles.css";
function App() {
const [rightMenuVisible, setRightMenuVisible] = useState(false);
const [fullMenuVisible, setFullMenuVisible] = useState(false);
const rightMenuAnimation = useSpring({
opacity: rightMenuVisible ? 1 : 0,
transform: rightMenuVisible ? `translateX(0)` : `translateX(100%)`
});
const fullMenuAnimation = useSpring({
transform: fullMenuVisible ? `translateY(0)` : `translateY(-100%)`,
opacity: fullMenuVisible ? 1 : 0
});
return (
<div className="App">
<button
className="menu-button"
onClick={() => setRightMenuVisible(!rightMenuVisible)}
>
{rightMenuVisible ? "Close" : "Side Menu"}
</button>
<button
className="menu-button menu-button--full"
onClick={() => setFullMenuVisible(!fullMenuVisible)}
>
{fullMenuVisible ? "Close" : "Full Menu"}
</button>
<MenuRight style={rightMenuAnimation} />
<MenuFull style={fullMenuAnimation} />
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment