Skip to content

Commit 14e0596

Browse files
committed
styles(website): resolve bugs in menu
1 parent e0023c8 commit 14e0596

7 files changed

Lines changed: 65 additions & 19 deletions

File tree

app/src/app/docs/animations/page.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { SectionLayout } from "@/ui/layout/section"
44
import { CallToAction } from "@/ui/call-to-action"
55

66
<SectionLayout>
7-
<TextEffect className="mb-4 text-3xl/relaxed font-medium" as="h1" preset="fade-in-blur" speedReveal={1.1} speedSegment={0.5}>
7+
<TextEffect
8+
className="mb-4 text-xl/relaxed truncate font-medium base:text-3xl/relaxed"
9+
as="h1"
10+
preset="fade-in-blur"
11+
speedReveal={1.1}
12+
speedSegment={0.5}
13+
>
814
{`@halvaradop/tailwindcss-animations`}
915
</TextEffect>
1016
<TextEffect className="text-muted text-lg" preset="fade-in-blur" speedReveal={1} speedSegment={0.2}>

app/src/app/docs/utilities/page.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { SectionLayout } from "@/ui/layout/section"
44
import { CallToAction } from "@/ui/call-to-action"
55

66
<SectionLayout>
7-
<TextEffect className="mb-4 text-3xl/relaxed font-medium" as="h1" preset="fade-in-blur" speedReveal={1.1} speedSegment={0.5}>
7+
<TextEffect
8+
className="mb-4 text-xl/relaxed truncate font-medium base:text-3xl/relaxed"
9+
as="h1"
10+
preset="fade-in-blur"
11+
speedReveal={1.1}
12+
speedSegment={0.5}
13+
>
814
{`@halvaradop/tailwindcss-utilities`}
915
</TextEffect>
1016
<TextEffect className="text-muted text-lg" preset="fade-in-blur" speedReveal={1} speedSegment={0.2}>

app/src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function RootLayout({ children }: LayoutProps) {
4343
return (
4444
<html className="scroll-smooth" lang="en">
4545
<body
46-
className={`${inter.className} min-h-screen grid grid-rows-[auto,1fr_auto] antialiased relative overflow-x-hidden bg-black scroll:w-2 track:my-2 thumb:rounded thumb:bg-gray-100 has-[header.open]:scroll:bg-gray-300`}
46+
className={`${inter.className} min-h-screen antialiased relative overflow-x-hidden bg-black scrollbar:w-2 track:my-2 thumb:rounded thumb:bg-gray-100 has-[header.open]:scroll:bg-gray-300`}
4747
>
4848
<Header />
4949
{children}

app/src/ui/community/community-cards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const CommunitySection = () => {
1515
<section className="mx-10 border-x border-solid border-border base:mx-16 lg:min-h-[calc(100dvh-4rem)] lg:flex lg:flex-col">
1616
<SegmentAnimation
1717
title="Ways to Contribute"
18-
description="Tailwind CSS v4 brings a modern engine — and our utilities are built for it. We’ve designed every package to integrate seamlessly using the new configuration API, variant generator, and dynamic styling support."
18+
description="Join the @halvaradop/tailwindcss community! Explore ways to contribute, collaborate, and connect with others to help shape the future of our utilities and ecosystem."
1919
/>
2020
<div className="grid text-primary text-left a:border-t a:border-solid a:border-border lg:flex-100 lg:grid-cols-3 lg:a:border-r lg:a:nth-[3]:border-r-0 lg:a:nth-[5]:border-r-0 lg:a:nth-[4]:col-span-2 xl:min-h-[30dvw] xl:a:nth-[2]:border-r">
2121
{communityCards.map((item, idx) => (

app/src/ui/globals.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ It is generating errors to load animations styles
6767
@apply text-primary;
6868
}
6969

70+
body:has(> header.open) {
71+
overflow-y: hidden;
72+
}
73+
7074
main {
7175
&#docs-layout {
7276
@apply text-primary;
@@ -147,5 +151,11 @@ It is generating errors to load animations styles
147151
}
148152
}
149153
}
154+
155+
@media (min-width: 900px) {
156+
body:has(> header.open) {
157+
overflow-y: auto;
158+
}
159+
}
150160
}
151161
}

app/src/ui/header/header-menu.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { motion } from "motion/react"
33
import { itemVariants, menuVariants } from "@/ui/motion-config/menu.motion"
44
import { TextScramble } from "@/ui/motion/text-scramble"
55

6-
export const HeaderMenu = () => {
6+
export const HeaderMenu = ({ onLinkClick }: { onLinkClick?: () => void } = {}) => {
77
return (
88
<motion.div
9-
className="w-10/12 max-w-md absolute inset-y-0 right-0 z-10 border border-solid border-border bg-black [--nav-menu:100%] base:w-auto base:max-w-none base:inset-0 base:relative base:bg-transparent base:border-0 base:[--nav-menu:0%]"
9+
className="w-10/12 max-w-md absolute inset-y-0 right-0 z-20 border border-solid border-border bg-black [--nav-menu:100%] base:w-auto base:max-w-none base:inset-0 base:relative base:bg-transparent base:border-0 base:[--nav-menu:0%]"
1010
variants={menuVariants}
1111
initial="hidden"
1212
animate="visible"
@@ -22,40 +22,44 @@ export const HeaderMenu = () => {
2222
Product
2323
</motion.li>
2424
<motion.li className="[--nav-li:100%] base:[--nav-li:0%]" variants={itemVariants}>
25-
<Link href="/">
25+
<Link href="/" onClick={onLinkClick}>
2626
<TextScramble>HOME</TextScramble>
2727
</Link>
2828
</motion.li>
2929
<motion.li className="[--nav-li:100%] base:[--nav-li:0%]" variants={itemVariants}>
30-
<Link href="/docs">
30+
<Link href="/docs" onClick={onLinkClick}>
3131
<TextScramble>DOCS</TextScramble>
3232
</Link>
3333
</motion.li>
3434
<motion.li className="[--nav-li:100%] base:[--nav-li:0%]" variants={itemVariants}>
35-
<Link href="/docs/utilities">
35+
<Link href="/docs/utilities" onClick={onLinkClick}>
3636
<TextScramble>UTILITIES</TextScramble>
3737
</Link>
3838
</motion.li>
3939
<motion.li className="[--nav-li:100%] base:[--nav-li:0%]" variants={itemVariants}>
40-
<Link href="/docs/animations">
40+
<Link href="/docs/animations" onClick={onLinkClick}>
4141
<TextScramble>ANIMATIONS</TextScramble>
4242
</Link>
4343
</motion.li>
4444
<motion.li className="[--nav-li:100%] base:[--nav-li:0%]" variants={itemVariants}>
45-
<Link href="/community">
45+
<Link href="/community" onClick={onLinkClick}>
4646
<TextScramble>COMMUNITY</TextScramble>
4747
</Link>
4848
</motion.li>
4949
</ul>
5050
<ul className="mt-10 text-fluid-lg grid grid-cols-2 items-center font-medium li:hover:text-primary base:hidden">
5151
<li className="mb-5 text-primary text-xl font-semibold col-span-2">Resources</li>
5252
<li>
53-
<Link href="https://github.com/halvaradop/tailwindcss-utilities" target="_blank">
53+
<Link href="https://github.com/halvaradop/tailwindcss-utilities" target="_blank" onClick={onLinkClick}>
5454
Github
5555
</Link>
5656
</li>
5757
<li>
58-
<Link href="https://www.npmjs.com/package/@halvaradop/tailwindcss-utilities" target="_blank">
58+
<Link
59+
href="https://www.npmjs.com/package/@halvaradop/tailwindcss-utilities"
60+
target="_blank"
61+
onClick={onLinkClick}
62+
>
5963
NPM
6064
</Link>
6165
</li>

app/src/ui/header/header.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22
import Link from "next/link"
33
import Image from "next/image"
4-
import { useEffect, useState } from "react"
4+
import { useCallback, useEffect, useRef, useState } from "react"
55
import { HeaderMenu } from "./header-menu"
66
import { AnimatePresence } from "motion/react"
77
import { merge } from "@halvaradop/ui-core"
@@ -11,11 +11,18 @@ import arrow from "@/assets/arrow.svg"
1111

1212
export const Header = () => {
1313
const [isOpen, setIsOpen] = useState(false)
14+
const menuRef = useRef<HTMLDivElement>(null)
1415

1516
const handleToggleMenu = () => {
1617
setIsOpen(!isOpen)
1718
}
1819

20+
const handleMenuLinkClick = useCallback(() => {
21+
if (window.innerWidth < 900) {
22+
setIsOpen(false)
23+
}
24+
}, [])
25+
1926
useEffect(() => {
2027
const matchScreen = matchMedia("(min-width: 900px)")
2128

@@ -28,27 +35,40 @@ export const Header = () => {
2835
return () => matchScreen.removeEventListener("change", handleSetMatchMedia)
2936
}, [])
3037

38+
useEffect(() => {
39+
if (!isOpen) return
40+
const handleClickOutside = (event: MouseEvent) => {
41+
if (window.innerWidth < 900 && menuRef.current && !menuRef.current.contains(event.target as Node)) {
42+
setIsOpen(false)
43+
}
44+
}
45+
document.addEventListener("mousedown", handleClickOutside)
46+
return () => document.removeEventListener("mousedown", handleClickOutside)
47+
}, [isOpen])
48+
3149
return (
3250
<header
33-
className={merge("flex items-center border-b border-solid border-border", isOpen ? "open" : "")}
51+
className={merge("flex items-center border-b border-solid border-border", isOpen && "open")}
3452
id="halvaradop-tailwindcss-utilities"
3553
>
3654
<nav className="flex-100 h-16 ml-10 px-4 border-x border-solid border-border sm:px-6 md:px-8 base:ml-16 base:px-10 base:flex base:items-center base:justify-between base:relative">
37-
<div className="w-full h-full flex items-center justify-between relative z-20 base:w-fit">
55+
<div className="w-full h-full flex items-center justify-between relative base:w-fit">
3856
<h2 className="text-primary base:text-lg">
3957
<Link href="/">@halvaradop/tailwindcss</Link>
4058
</h2>
4159
</div>
42-
<AnimatePresence mode="wait">{isOpen && <HeaderMenu />}</AnimatePresence>
60+
<div ref={menuRef} style={{ display: "contents" }}>
61+
<AnimatePresence mode="wait">{isOpen && <HeaderMenu onLinkClick={handleMenuLinkClick} />}</AnimatePresence>
62+
</div>
4363
</nav>
4464
<Button
45-
className="w-10 h-16 p-0 relative z-10 hover:bg-transparent base:hidden"
65+
className="w-10 h-16 p-0 relative z-30 hover:bg-transparent base:hidden"
4666
variant="ghost"
4767
onClick={handleToggleMenu}
4868
>
4969
<Image className="hover:cursor-pointer" src={menu} alt="menu icon" />
5070
</Button>
51-
<figure className="group w-10 h-full hidden img:transition-transform img:ease-linear img:duration-300 hover:cursor-pointer base:w-16 base:flex base:items-center base:justify-center base:relative base:overflow-hidden">
71+
<figure className="group w-10 h-16 hidden img:transition-transform img:ease-linear img:duration-300 hover:cursor-pointer base:w-16 base:flex base:items-center base:justify-center base:relative base:overflow-hidden">
5272
<Image
5373
className="-rotate-127 group-hover:-translate-y-14 group-hover:translate-x-14"
5474
src={arrow}

0 commit comments

Comments
 (0)