Skip to content

Commit

Permalink
feat:implement hamburger icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehoya committed Mar 14, 2024
1 parent 370a18c commit 27b06cc
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/components/c-hamburger-icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client';

import { useState, useEffect } from 'react';
import * as S from './page.styled';

export default function CHamburgerIcon() {
const [active, setActive] = useState(false);

return (
<S.Container
onClick={() => {
setActive(active => !active);
}}
>
<S.Bar $active={active}></S.Bar>
<S.Bar $active={active}></S.Bar>
<S.Bar $active={active}></S.Bar>
<S.Bar $active={active}></S.Bar>
</S.Container>
);
}
59 changes: 59 additions & 0 deletions src/components/c-hamburger-icon/page.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import styled, { css } from 'styled-components';

export const Container = styled.div`
@media screen and (min-width: 1260px) {
display: none;
}
width: 30px;
height: 50px;
cursor: pointer;
transition: 0.3s ease-in-out;
float: right;
z-index: 9990;
position: absolute;
top: 30px;
left: 30px;
`;

const barSettings = ($active: boolean) => css`
${$active &&
css`
&:nth-child(1),
&:nth-child(4) {
opacity: 0;
}
&:nth-child(2) {
transform: rotate(45deg);
top: 12px;
}
&:nth-child(3) {
transform: rotate(-45deg);
top: 12px;
}
`}
${!$active &&
css`
&:nth-child(1) {
top: 0;
}
&:nth-child(2),
&:nth-child(3) {
top: 12px;
}
&:nth-child(4) {
top: 24px;
}
`}
`;

export const Bar = styled.span<{ $active: boolean }>`
position: absolute;
height: 6px;
border-radius: 3px;
width: 100%;
background-color: #111111;
top: 0;
transition: 0.2s;
${({ $active }) => barSettings($active)}
`;

0 comments on commit 27b06cc

Please sign in to comment.