File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,10 +4,16 @@ import { ScheduleSection } from "@/components/schedule-section"
44import { SponsorsSection } from "@/components/sponsors-section"
55import { ArchiveSection } from "@/components/archive-section"
66import { FAQSection } from "@/components/faq-section"
7+ import { StickyBanner } from "@/components/ui/sticky-banner"
78
89export default function Home ( ) {
910 return (
1011 < main className = "h-screen snap-y snap-mandatory overflow-y-auto bg-black text-foreground" >
12+ < StickyBanner className = "bg-accent" >
13+ < p className = "mx-0 max-w-[90%] text-accent-foreground drop-shadow-md" >
14+ Venue Update: HackJPS 2026 will now be held entirely virtual due to unspecified venue issues.
15+ </ p >
16+ </ StickyBanner >
1117 < div className = "flex min-h-screen flex-col snap-start" >
1218 < HeroSection />
1319 </ div >
Original file line number Diff line number Diff line change 1+ import { StickyBanner } from "@/components/ui/sticky-banner" ;
2+
3+ export default function StickyBannerDemo ( ) {
4+ return (
5+ < div className = "relative flex h-[60vh] w-full flex-col overflow-y-auto" >
6+ < StickyBanner className = "bg-gradient-to-b from-blue-500 to-blue-600" >
7+ < p className = "mx-0 max-w-[90%] text-white drop-shadow-md" >
8+ Announcing $10M seed funding from project mayhem ventures.{ " " }
9+ < a href = "#" className = "transition duration-200 hover:underline" >
10+ Read announcement
11+ </ a >
12+ </ p >
13+ </ StickyBanner >
14+ < DummyContent />
15+ </ div >
16+ ) ;
17+ }
18+
19+ const DummyContent = ( ) => {
20+ return (
21+ < div className = "relative mx-auto flex w-full max-w-7xl flex-col gap-10 py-8" >
22+ < div className = "h-96 w-full animate-pulse rounded-lg bg-neutral-100 dark:bg-neutral-800" />
23+ < div className = "h-96 w-full animate-pulse rounded-lg bg-neutral-100 dark:bg-neutral-800" />
24+ < div className = "h-96 w-full animate-pulse rounded-lg bg-neutral-100 dark:bg-neutral-800" />
25+ </ div >
26+ ) ;
27+ } ;
Original file line number Diff line number Diff line change 1+ "use client" ;
2+ import React , { SVGProps , useState } from "react" ;
3+ import { motion , useMotionValueEvent , useScroll } from "motion/react" ;
4+ import { cn } from "@/lib/utils" ;
5+
6+ export const StickyBanner = ( {
7+ className,
8+ children,
9+ hideOnScroll = false ,
10+ } : {
11+ className ?: string ;
12+ children : React . ReactNode ;
13+ hideOnScroll ?: boolean ;
14+ } ) => {
15+ const [ open , setOpen ] = useState ( true ) ;
16+ const { scrollY } = useScroll ( ) ;
17+
18+ useMotionValueEvent ( scrollY , "change" , ( latest ) => {
19+ console . log ( latest ) ;
20+ if ( hideOnScroll && latest > 40 ) {
21+ setOpen ( false ) ;
22+ } else {
23+ setOpen ( true ) ;
24+ }
25+ } ) ;
26+
27+ return (
28+ < motion . div
29+ className = { cn (
30+ "sticky inset-x-0 top-0 z-40 flex min-h-10 w-full items-center justify-center bg-transparent px-4 py-1" ,
31+ className ,
32+ ) }
33+ initial = { {
34+ y : - 100 ,
35+ opacity : 0 ,
36+ } }
37+ animate = { {
38+ y : open ? 0 : - 100 ,
39+ opacity : open ? 1 : 0 ,
40+ } }
41+ transition = { {
42+ duration : 0.3 ,
43+ ease : "easeInOut" ,
44+ } }
45+ >
46+ { children }
47+
48+ < motion . button
49+ initial = { {
50+ scale : 0 ,
51+ } }
52+ animate = { {
53+ scale : 1 ,
54+ } }
55+ className = "absolute top-1/2 right-2 -translate-y-1/2 cursor-pointer"
56+ onClick = { ( ) => setOpen ( ! open ) }
57+ >
58+ < CloseIcon className = "h-5 w-5 text-white" />
59+ </ motion . button >
60+ </ motion . div >
61+ ) ;
62+ } ;
63+
64+ const CloseIcon = ( props : SVGProps < SVGSVGElement > ) => {
65+ return (
66+ < svg
67+ xmlns = "http://www.w3.org/2000/svg"
68+ width = "24"
69+ height = "24"
70+ viewBox = "0 0 24 24"
71+ fill = "none"
72+ stroke = "currentColor"
73+ strokeWidth = "2"
74+ strokeLinecap = "round"
75+ strokeLinejoin = "round"
76+ { ...props }
77+ >
78+ < path stroke = "none" d = "M0 0h24v24H0z" fill = "none" />
79+ < path d = "M18 6l-12 12" />
80+ < path d = "M6 6l12 12" />
81+ </ svg >
82+ ) ;
83+ } ;
You can’t perform that action at this time.
0 commit comments