Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sidebar toggle button in mobile environment #161

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/layouts/Article/Article.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
width: 100%;
min-width: 200px;
max-width: 980px;
padding: $size-article-padding-small;
padding: $size-article-padding-large $size-article-padding-small;
margin: 0 auto;

@include screen(lg) {
Expand Down
25 changes: 24 additions & 1 deletion src/components/layouts/Aside/Aside.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
'use client';

import { useState } from 'react';
import { HiOutlineMenuAlt2 } from 'react-icons/hi';

import styles from './Aside.module.scss';

export default function Aside({ children }) {
return <aside className={styles.aside}>{children}</aside>;
const [visible, setVisible] = useState(false);

return (
<>
<aside className={`${styles.aside} ${visible ? styles.visible : ''}`}>
{children}
</aside>
<div
className={`${styles.div} ${visible ? styles.visible : ''}`}
onClick={() => {
setVisible(prevState => !prevState);
}}
>
<HiOutlineMenuAlt2 />
</div>
</>
);
}

// TODO: Add `useMemo` Hook to `${visible ? styles.visible : ''}`.
43 changes: 43 additions & 0 deletions src/components/layouts/Aside/Aside.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$transition: transform 0.75s ease-in-out;

.aside {
@include selector-scrollbar($size-2);

Expand All @@ -6,9 +8,50 @@
height: calc(100vh - $size-header-height);
background-color: var(--color-bg-default);
border-right: $border-default;
transition: $transition;
transform: translateX(-100%);

&.visible {
transform: translateX(0);
}

> ul:not(:last-child) {
margin: 16px 0;
border-bottom: $border-default;
}

@include screen(xl) {
transform: translateX(0);
}
}

.div {
@include props-flex-center;

position: fixed;
top: $size-header-height;
z-index: 1;
width: 32px;
height: 32px;
background-color: var(--color-bg-inset);
border-right: $border-default;
border-bottom: $border-default;
border-bottom-right-radius: $size-border-radius;
transition: $transition;
transform: translateX(0);

&.visible {
transform: translateX($size-sidebar-width);
}

> svg {
width: 100%;
height: 100%;
margin: $size-4;
}

@include screen(xl) {
opacity: 0;
transform: translateX($size-sidebar-width);
}
}
5 changes: 0 additions & 5 deletions src/components/layouts/Body/Body.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
> aside {
z-index: 1;
grid-area: 2 / 1 / 3 / 2;
transform: translateX(-100%); // TODO: Move to `Aside` component.
}

> main {
grid-area: 2 / 1 / 3 / 3;
}

@include screen(xl) {
> aside {
transform: translateX(0); // TODO: Move to `Aside` component.
}

> main {
grid-area: 2 / 2 / 3 / 3;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/layouts/Nav/Nav.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
top: $size-header-height;
box-sizing: border-box;
height: calc(100vh - $size-header-height);
padding: $size-article-padding-small;
padding: $size-article-padding-large $size-article-padding-small;
background-color: var(--color-bg-inset);
border-left: $border-default;

Expand Down