Skip to content

Instantly share code, notes, and snippets.

@codebucks27
Last active January 1, 2021 14:37
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 codebucks27/4d1c82332b2a04ab79d2dcb59defdb7c to your computer and use it in GitHub Desktop.
Save codebucks27/4d1c82332b2a04ab79d2dcb59defdb7c to your computer and use it in GitHub Desktop.
import React,{useState} from "react";
import "./styles.css";
import styled from "styled-components";
const MenuLabel = styled.label`
background-color: #B6EDC8;
position: fixed;
top: 6rem;
right: 6rem;
border-radius: 50%;
height: 7rem;
width: 7rem;
cursor: pointer;
z-index: 1000;
box-shadow: 0 1rem 3rem rgba(182, 237, 200, 0.3);
text-align: center;
`;
const Icon = styled.span`
position: relative;
background-color: ${(props) => (props.clicked ? "transparent" : "black")};
width: 3rem;
height: 2px;
display: inline-block;
margin-top: 3.5rem;
transition: all 0.3s;
&::before,
&::after {
content: "";
background-color: black;
width: 3rem;
height: 2px;
display: inline-block;
position: absolute;
left: 0;
transition: all 0.3s;
}
&::before {
top: ${(props) => (props.clicked ? "0" : "-0.8rem")};
transform: ${(props) => (props.clicked ? "rotate(135deg)" : "rotate(0)")};
}
&::after {
top: ${(props) => (props.clicked ? "0" : "0.8rem")};
transform: ${(props) => (props.clicked ? "rotate(-135deg)" : "rotate(0)")};
}
${MenuLabel}:hover &::before {
top: ${(props) => (props.clicked ? "0" : "-1rem")};
}
${MenuLabel}:hover &::after {
top: ${(props) => (props.clicked ? "0" : "1rem")};
}
`;
export default function App() {
const [click, setClick] = useState(false);
const handleClick = () => setClick(!click);
return (
<>
<MenuLabel htmlFor="navi-toggle" onClick={handleClick}>
<Icon clicked={click}>&nbsp;</Icon>
</MenuLabel>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment