File tree Expand file tree Collapse file tree
apps/web/src/components/Banner Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments