Skip to content

Commit 26d4df2

Browse files
authored
[BA-1968] Add re-useable banner component (base#2480)
* Add banner component * Default bg color * Make CTA optional
1 parent 5b6a6ca commit 26d4df2

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import Link from 'next/link';
2+
import { Icon } from 'apps/web/src/components/Icon/Icon';
3+
import { useState } from 'react';
4+
5+
type BannerProps = {
6+
bgColor?: string;
7+
textColor?: string;
8+
message: string;
9+
} & (
10+
| {
11+
actionText: string;
12+
actionUrl: string;
13+
}
14+
| {
15+
actionText?: never;
16+
actionUrl?: never;
17+
}
18+
);
19+
20+
export function Banner({
21+
bgColor = 'bg-yellow-20',
22+
textColor = 'text-black',
23+
message,
24+
actionText,
25+
actionUrl,
26+
}: BannerProps) {
27+
const [isOpen, setIsOpen] = useState(true);
28+
29+
const handleClose = () => {
30+
setIsOpen(false);
31+
};
32+
33+
if (!isOpen) {
34+
return null;
35+
}
36+
37+
return (
38+
<div className={`flex w-full flex-row justify-center ${bgColor} ${textColor}`}>
39+
<div
40+
className={`flex w-full max-w-[1440px] flex-row items-center justify-between self-center ${bgColor} p-2 px-6`}
41+
>
42+
<span className="text-xs font-semibold md:text-base">{message}</span>
43+
<div className="flex flex-row items-center gap-4">
44+
{actionText && actionUrl && (
45+
<Link href={actionUrl}>
46+
<span className="text-xs font-semibold underline md:text-base">{actionText}</span>
47+
</Link>
48+
)}
49+
<button
50+
className="cursor-pointer p-2 text-xs"
51+
type="button"
52+
aria-label="Close banner"
53+
onClick={handleClose}
54+
>
55+
<Icon name="close" color="black" width="16" height="16" />
56+
</button>
57+
</div>
58+
</div>
59+
</div>
60+
);
61+
}

0 commit comments

Comments
 (0)