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

fix(frontend): The "Log Out" button can't be reached on the sidebar in landscape mode [Mobile] tm-567 #686

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
13 changes: 10 additions & 3 deletions apps/frontend/src/libs/components/portal/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import styles from "./styles.module.css";

type Properties = {
children: React.ReactNode;
position?: "absolute" | "fixed";
};

const Portal: React.FC<Properties> = ({ children }: Properties) => {
const Portal: React.FC<Properties> = ({
children,
position = "fixed",
}: Properties) => {
const portalContainer = useMemo(() => {
const element = document.createElement("div");
element.classList.add(styles["portal"] as string);
element.classList.add(
styles["portal"] as string,
styles[position] as string,
);

return element;
}, []);
}, [position]);

useEffect(() => {
document.body.append(portalContainer);
Expand Down
8 changes: 8 additions & 0 deletions apps/frontend/src/libs/components/portal/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
left: 0;
z-index: 1000;
}

.fixed {
position: fixed;
}

.absolute {
position: absolute;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SMALL_WIDTH_BREAKPOINT } from "./small-width-breakpoint.constant.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const SMALL_WIDTH_BREAKPOINT = 480;

export { SMALL_WIDTH_BREAKPOINT };
34 changes: 23 additions & 11 deletions apps/frontend/src/libs/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useCallback,
useState,
useToggleScroll,
useWindowWidth,
} from "~/libs/hooks/hooks.js";
import { type MenuItem, type PagePermissions } from "~/libs/types/types.js";
import {
Expand All @@ -21,6 +22,8 @@ import { Button } from "../button/button.js";
import { Icon } from "../icon/icon.js";
import { Image } from "../image/image.js";
import { Link } from "../link/link.js";
import { Portal } from "../portal/portal.js";
import { SMALL_WIDTH_BREAKPOINT } from "./libs/constants/constants.js";
import styles from "./styles.module.css";

type Properties = {
Expand Down Expand Up @@ -58,21 +61,25 @@ const Sidebar: React.FC<Properties> = ({ menuItems, user }: Properties) => {
[user],
);

const windowWidth = useWindowWidth();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad solution. we need to handle it only with css. without any js


const burgerButton = (
<Button
className={getValidClassNames(
styles["burger-button"],
styles[isOpen ? "open" : "close"],
)}
hasVisuallyHiddenLabel
iconName="burger"
label="burger-button"
onClick={handleToggleSidebar}
style="secondary"
/>
);
useToggleScroll(isOpen);

return (
<>
<Button
className={getValidClassNames(
styles["burger-button"],
styles[isOpen ? "open" : "close"],
)}
hasVisuallyHiddenLabel
iconName="burger"
label="burger-button"
onClick={handleToggleSidebar}
style="secondary"
/>
<div
className={getValidClassNames(
styles["sidebar"],
Expand All @@ -85,6 +92,11 @@ const Sidebar: React.FC<Properties> = ({ menuItems, user }: Properties) => {
<Image alt="website logo" className={styles["logo"]} src={logo} />
</Link>
<nav className={styles["menu"]}>
{windowWidth > SMALL_WIDTH_BREAKPOINT ? (
burgerButton
) : (
<Portal position="absolute">{burgerButton}</Portal>
)}
{menuItems.map(({ href, icon, label, pagePermissions }) => {
return (
handleCheckPermissions(pagePermissions) && (
Expand Down
82 changes: 72 additions & 10 deletions apps/frontend/src/libs/components/sidebar/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
flex-direction: column;
height: 100%;
padding: 19px;
padding-right: 10px;
overflow: hidden;
background-color: var(--color-menu);
transition: width 0.3s ease;
transition: 0.3s ease;
}

.menu {
Expand Down Expand Up @@ -98,7 +99,8 @@
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden scroll;
padding-right: 9px;
overflow: hidden;
}

@media screen and (--large-screen) {
Expand Down Expand Up @@ -168,6 +170,10 @@
}
}

.absolute {
position: absolute;
}

@media screen and (--small-screen) {
.sidebar.close {
width: 270px;
Expand All @@ -184,6 +190,26 @@
left: 33px;
z-index: var(--z-index-low);
color: var(--color-button);
transition:
all 0.3s,
color 0s;
}

.burger-button.open {
display: flex;
color: transparent;
visibility: hidden;
}

.burger-button.close {
transition:
all 0.3s,
color 0.3s cubic-bezier(1, -0.03, 1, 0.49);
}

.sidebar,
.content-wrapper {
overflow: unset;
}

.blurred-background {
Expand All @@ -210,6 +236,7 @@

.content-wrapper {
flex-direction: row;
padding-right: 0;
}

.sidebar.close {
Expand Down Expand Up @@ -294,12 +321,12 @@
}

@media screen and (height <= 665px) {
.title-container {
max-height: 46px;
.content-container {
gap: 14px;
}

.sidebar .content-wrapper {
padding-right: 12px;
.content-wrapper {
overflow: hidden scroll;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
overflow: hidden scroll;
overflow: hidden auto;

}
}

Expand All @@ -308,12 +335,47 @@
margin-right: -8px;
}

.sidebar:not(.open) {
padding-top: 80px;
.sidebar:not(.open) .title-container {
height: 0;
min-height: 0;
padding: 0;
}

.burger-button {
position: static;
display: flex;
flex-shrink: 1;
align-items: flex-start;
width: 66px;
height: 100%;
min-height: 37px;
max-height: 103px;
margin: 15px 0 8px 1px;
color: var(--main-white);
}

.sidebar:not(.open) .title-container {
display: none;
.menu-item:first-of-type {
margin-top: 12px;
}

.content-container {
gap: 0;
}

.sidebar:not(.open) .content-container {
flex-direction: column-reverse;
}
}

@media screen and (--small-screen) and (height <= 665) {
.burger-button {
position: absolute;
width: unset;
height: unset;
min-height: unset;
max-height: unset;
margin: 0;
color: var(--color-button);
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/libs/hooks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { useHandleEscPress } from "./use-handle-esc-press/use-handle-esc-press.h
export { useInfiniteScroll } from "./use-infinite-scroll/use-infinite-scroll.hook.js";
export { usePagination } from "./use-pagination/use-pagination.hook.js";
export { useToggleScroll } from "./use-toggle-scroll/use-toggle-scroll.hook.js";
export { useWindowWidth } from "./use-window-width/use-window-width.hook.js";
export {
forwardRef,
useCallback,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect, useState } from "react";

const useWindowWidth = (): number => {
const [windowWidth, setWindowWidth] = useState<number>(window.innerWidth);

useEffect(() => {
const handleResize = (): void => {
setWindowWidth(window.innerWidth);
};

window.addEventListener("resize", handleResize);

return (): void => {
window.removeEventListener("resize", handleResize);
};
}, []);

return windowWidth;
};

export { useWindowWidth };
Loading