Skip to content

Commit 21a5d3a

Browse files
authored
Merge pull request #283 from karannfr/prod
added feat: #268 dynamic banner
2 parents 9e71373 + 5cf223e commit 21a5d3a

7 files changed

Lines changed: 181 additions & 120 deletions

File tree

src/components/BannerAlert.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/components/BannerDevsoc.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/components/FreshersBanner.tsx

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/components/Navbar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ArrowDownLeftIcon, Pin, ArrowUpRight, ChevronDown } from "lucide-react"
1010
import FloatingNavbar from "./FloatingNavbar";
1111
import PWAInstallButton from "./ui/PWAInstallButton";
1212
import SearchBarChild from "./Searchbar/searchbar-child";
13-
import FresherBanner from "@/components/FreshersBanner"
13+
import Banner from "@/components/bannerDismiss"
1414
import type { ICourses } from "@/interface";
1515
import {
1616
DropdownMenu,
@@ -92,7 +92,15 @@ function Navbar() {
9292

9393
return (
9494
<div className="sticky top-0 z-[50] w-full bg-[#B2B8FF] dark:bg-[#130E1F]">
95-
<FresherBanner/>
95+
<Banner
96+
bannerId="freshers"
97+
bgColor="#fef3c7"
98+
textColor="#5a3000"
99+
iconColor="#d97706"
100+
accentColor="#78350f"
101+
title="Attention Freshers!"
102+
message="If papers for your subject are not yet available, click on your subject and explore related subjects until papers become available, as these are newly introduced courses."
103+
/>
96104
<div className="flex items-center justify-between bg-inherit px-4 py-4 md:px-8 md:py-5">
97105
{}
98106
<div className="flex items-center gap-4 relative">

src/components/bannerDismiss.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"use client";
2+
3+
import { Info, X } from "lucide-react";
4+
import { useEffect, useState } from "react";
5+
6+
interface BannerProps {
7+
bannerId: string;
8+
bgColor?: string;
9+
textColor?: string;
10+
iconColor?: string;
11+
accentColor?: string;
12+
message: string;
13+
title: string;
14+
}
15+
16+
export default function Banner({
17+
bannerId,
18+
bgColor = "#fef3c7",
19+
textColor = "#5a3000",
20+
iconColor = "#d97706",
21+
accentColor = "#78350f",
22+
message,
23+
title,
24+
}: BannerProps) {
25+
const [visible, setVisible] = useState(false);
26+
27+
useEffect(() => {
28+
const bannerStatus = localStorage.getItem("banner_" + bannerId);
29+
if (bannerStatus !== "dismissed") {
30+
setVisible(true);
31+
}
32+
}, [bannerId]);
33+
34+
const closeBanner = () => {
35+
localStorage.setItem("banner_" + bannerId, "dismissed");
36+
setVisible(false);
37+
};
38+
39+
if (!visible) return null;
40+
41+
return (
42+
<div className="z-[60] w-full shadow-sm" style={{ backgroundColor: bgColor, color: textColor }}>
43+
<div className="relative mx-auto flex max-w-screen-2xl flex-col items-start justify-between gap-3 px-4 py-3 sm:justify-center sm:flex-row sm:items-center sm:gap-4 md:px-8 md:py-3">
44+
<div className="flex items-center gap-2">
45+
<Info className="h-5 w-5" style={{ color: iconColor }} />
46+
<span className="font-semibold text-base tracking-wide" style={{ color: accentColor }}>
47+
{title}
48+
</span>
49+
</div>
50+
51+
<p className="text-sm flex-1 sm:text-right">{message}</p>
52+
53+
<button
54+
onClick={closeBanner}
55+
className="absolute right-4 top-4 transition hover:opacity-75 sm:static sm:self-start"
56+
aria-label="Dismiss banner"
57+
style={{ color: accentColor }}
58+
>
59+
<X className="h-5 w-5" />
60+
</button>
61+
</div>
62+
</div>
63+
);
64+
}

src/components/bannerEvent.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use client";
2+
3+
import { Button } from "./ui/button";
4+
import Image from "next/image";
5+
import Link from "next/link";
6+
7+
interface EventBannerProps {
8+
bgColor?: string;
9+
textColor?: string;
10+
buttonColor?: string;
11+
mobileText?: string;
12+
desktopText?: string;
13+
buttonText?: string;
14+
link: string;
15+
icon: string;
16+
}
17+
18+
export default function EventBanner({
19+
bgColor = "#ba4343",
20+
textColor = "#ffffff",
21+
buttonColor = "#AA7AE7",
22+
mobileText = "Join the biggest hackathon of the year!",
23+
desktopText = "DevSOC'25 registrations are now LIVE! Don't miss out 🚀",
24+
buttonText = "Register Now",
25+
link,
26+
icon,
27+
}: EventBannerProps) {
28+
return (
29+
<div
30+
className="z-50 flex h-fit w-full items-center justify-center px-6 py-3 text-center sm:h-14 sm:py-0 md:sticky md:top-0 md:justify-between md:text-left"
31+
style={{ backgroundColor: bgColor, color: textColor }}
32+
>
33+
<div className="flex items-center gap-x-2">
34+
<Image
35+
src={icon}
36+
alt="event logo"
37+
height={40}
38+
width={40}
39+
className="md:hidden"
40+
/>
41+
<span className="hidden text-sm font-medium md:block">
42+
{desktopText}
43+
</span>
44+
<Link
45+
href={link}
46+
className="block text-sm font-medium md:hidden underline"
47+
rel="noopener noreferrer"
48+
target="_blank"
49+
>
50+
{mobileText}
51+
</Link>
52+
</div>
53+
<div className="hidden md:block">
54+
<Button style={{ backgroundColor: buttonColor }}>
55+
<Link
56+
className="flex items-center gap-x-2"
57+
href={link}
58+
rel="noopener noreferrer"
59+
target="_blank"
60+
>
61+
<Image src={icon} alt="icon" height={20} width={20} />
62+
<span className="font-yerk text-xs">{buttonText}</span>
63+
</Link>
64+
</Button>
65+
</div>
66+
</div>
67+
);
68+
}

src/components/bannerPermanent.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use client";
2+
3+
import { Info } from "lucide-react";
4+
5+
interface BannerProps {
6+
bgColor?: string;
7+
textColor?: string;
8+
iconColor?: string;
9+
title: string;
10+
message: string;
11+
}
12+
13+
export default function Banner({
14+
bgColor = "#AA7AE7",
15+
textColor = "#ffffff",
16+
iconColor = "#ffffff",
17+
title,
18+
message,
19+
}: BannerProps) {
20+
return (
21+
<div
22+
className="z-50 w-full px-6 py-3 shadow-sm md:sticky md:top-0"
23+
style={{ backgroundColor: bgColor, color: textColor }}
24+
>
25+
<div className="mx-auto flex max-w-screen-xl flex-col items-center justify-between gap-2 sm:flex-row sm:gap-0">
26+
<div className="flex items-center gap-2">
27+
<Info className="h-5 w-5" style={{ color: iconColor }} />
28+
<span className="font-semibold tracking-wide text-base sm:text-lg">
29+
{title}
30+
</span>
31+
</div>
32+
33+
<p className="text-center text-sm sm:text-base sm:text-right font-medium" style={{ color: textColor + "e6" }}>
34+
{message}
35+
</p>
36+
</div>
37+
</div>
38+
);
39+
}

0 commit comments

Comments
 (0)