File size: 931 Bytes
75fefa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use client";

import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";

import { cn } from "@/utils/cn";

export default function HeaderWrapper({
  children,
}: {
  children: React.ReactNode;
}) {
  const [shouldShrink, setShouldShrink] = useState(false);
  const pathname = usePathname();

  useEffect(() => {
    const heroContentHeight =
      document.getElementById("hero-content")?.clientHeight;
    const triggerTop = heroContentHeight ? heroContentHeight : 100;

    const onScroll = () => {
      setShouldShrink(window.scrollY > triggerTop);
    };

    onScroll();

    window.addEventListener("scroll", onScroll);
  }, [pathname]);

  return (
    <div
      className={cn(
        "container lg:px-56 px-16 flex justify-between transition-[padding] duration-[200ms] items-center",
        shouldShrink ? "py-20" : "py-20 lg:py-34",
      )}
    >
      {children}
    </div>
  );
}