Skip to content

Commit

Permalink
Merge pull request #200 from Tizzz-555/navbar-tooltip
Browse files Browse the repository at this point in the history
Navbar Tooltip
  • Loading branch information
hburn7 authored Aug 11, 2024
2 parents e6a2294 + da95c86 commit 6426d2e
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
4 changes: 4 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
--foreground-inactive-hsl: 0, 0%, 6%;
--foreground-active-hsl: 0, 0%, 6%;

--background-navbar-tooltip-hsl: 0, 0%, 100%;

--foreground-nodata-hsl: 210, 2%, 82%;

--color-grey: 0, 0%, 6%;
Expand Down Expand Up @@ -231,6 +233,8 @@

--foreground-nodata-hsl: 240, 3%, 22%;

--background-navbar-tooltip-hsl: 240, 3%, 12%;

--mods-NM-bg: 226, 99%, 65%;
--mods-NM-bg-row: 226, 99%, 65%, 0.15;
--mods-HD-bg: 43, 98%, 60%;
Expand Down
3 changes: 3 additions & 0 deletions components/NavBar/NavBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
cursor: pointer;
}

.iconContainer {
margin-top: 12px;
}
.logoLink,
.actions .userPropic {
height: 1.9rem;
Expand Down
2 changes: 0 additions & 2 deletions components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ModeSwitcher from './ModeSwitcher/ModeSwitcher';
import styles from './NavBar.module.css';
import Routes from './Routes/Routes';
import SearchButton from './SearchButton/SearchButton';
import ThemeSwitcher from './ThemeSwitcher/ThemeSwitcher';
import UserLogged from './UserLogged/UserLogged';

export default function NavBar() {
Expand All @@ -34,7 +33,6 @@ export default function NavBar() {
<div className={styles.actions}>
<SearchButton />
{cookieMode?.value && <ModeSwitcher mode={cookieMode?.value} />}
<ThemeSwitcher />
<UserLogged />
</div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions components/NavBar/ThemeSwitcher/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export default function ThemeSwitcher() {
{theme === 'light' && <Image src={sunSVG} alt="Theme Switcher" fill />}
{theme === 'dark' && <Image src={moonSVG} alt="Theme Switcher" fill />}
{!theme && <></>}
{/* <Image
src={theme === 'light' ? sunSVG : moonSVG}
alt="Theme Switcher"
fill
/> */}
</div>
</button>
);
Expand Down
55 changes: 55 additions & 0 deletions components/NavBar/Tooltip/Tooltip.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.tooltipContainer {
position: relative;
display: inline-block;
height: 100%;
}

.parent {
position: absolute;
z-index: 1000;
top: calc(100% - 0.6rem);
left: calc(
-1 * (1.9rem + (1.4rem / 2))
); /* calc(-1 * (profile image width + (horizontal padding of content below / 2))) */
white-space: nowrap;
opacity: 0;
padding-top: 0.7rem;
visibility: hidden;
}

.tooltipContent {
padding: 1.2rem 1.4rem;
background-color: hsla(var(--background-navbar-tooltip-hsl));
color: hsla(var(--foreground-inactive-hsl));
border-radius: 0.85rem;
box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.1);
font-size: 1.1rem;
display: flex;
font-weight: 400;
flex-direction: column;
gap: 0.8rem;
}

.tooltipContainer:hover > .parent {
opacity: 1;
top: calc(100% - 0.15rem);
visibility: visible;
transition: all 0.2s ease-out;
}

.tooltipContent > div {
display: flex;
align-items: center;
justify-content: center;
}

.tooltipContent > div {
cursor: pointer;
transition: color 0.2s ease;
border-radius: 4px;
color: hsla(var(--foreground-inactive-hsl));
}

.tooltipContent > div:hover {
color: hsla(var(--foreground-active-hsl));
}
37 changes: 37 additions & 0 deletions components/NavBar/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AnimatePresence, motion } from 'framer-motion';
import React, { useEffect, useRef, useState } from 'react';
import styles from './Tooltip.module.css';

export default function Tooltip({ children, content }) {
const [isOpen, setIsOpen] = useState(false);
const tooltipRef = useRef(null);
const timeoutRef = useRef(null);

const handleMouseEnter = () => {
clearTimeout(timeoutRef.current);
setIsOpen(true);
};

const handleMouseLeave = () => {
timeoutRef.current = setTimeout(() => {
setIsOpen(false);
}, 500);
};

useEffect(() => {
return () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
};
}, []);

return (
<div className={styles.tooltipContainer}>
{children}
<div className={styles.parent}>
<div className={styles.tooltipContent}>{content}</div>
</div>
</div>
);
}
28 changes: 21 additions & 7 deletions components/NavBar/UserLogged/UserLogged.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
import { useUser } from '@/util/hooks';
import Image from 'next/image';
import styles from '../NavBar.module.css';
import ThemeSwitcher from '../ThemeSwitcher/ThemeSwitcher';
import Tooltip from './../Tooltip/Tooltip';
const tooltipContent = (
<>
{/* <div>Friends</div> */}
<div>Sign out</div>
<div className={styles.iconContainer}>
<ThemeSwitcher />
</div>
</>
);

export default function UserLogged() {
const user = useUser();

if (user?.osuId)
return (
<div className={styles.userPropic}>
<Image
src={`http://s.ppy.sh/a/${user?.osuId}`}
alt="User Propic"
fill
/>
</div>
<Tooltip content={tooltipContent}>
<div className={styles.userPropic}>
<Image
src={`http://s.ppy.sh/a/${user?.osuId}`}
alt="User Propic"
fill
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
/>
</div>
</Tooltip>
);
}
38 changes: 23 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"chart.js": "^4.4.0",
"chartjs-adapter-date-fns": "^3.0.0",
"clsx": "^2.0.0",
"framer-motion": "^10.16.4",
"framer-motion": "^11.3.21",
"iron-session": "^8.0.1",
"next": "^14.1.2",
"next-themes": "^0.3.0",
Expand Down

0 comments on commit 6426d2e

Please sign in to comment.