-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created Banner component, fixed linter error in Icons * Implemented Banner for OnchainKit * Added strictly typed bannerName argument to Banner component * updated Banner implementation on base web * Updated Banner on base-web * Added event tracking to Banner clicks * linted libs Banner * Implemented Banner on base-docs * deleted OcsBanner given new generic implementation * fixed local storage property name on base docs Banner * added text underline to banner
- Loading branch information
1 parent
bc3dfc1
commit a675314
Showing
5 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { useCallback } from 'react'; | ||
import Link from 'next/link'; | ||
import { useLocalStorage } from 'usehooks-ts'; | ||
import { usePathname } from 'next/navigation'; | ||
|
||
import { Icon } from 'base-ui/index'; | ||
import logEvent, { | ||
ActionType, | ||
AnalyticsEventImportance, | ||
ComponentType, | ||
} from 'base-ui/utils/logEvent'; | ||
|
||
type BannerName = `${string}Banner`; | ||
|
||
type BannerProps = { | ||
bannerName: BannerName; | ||
href: string; | ||
text: string; | ||
}; | ||
|
||
export default function Banner({ href, text, bannerName }: BannerProps) { | ||
const [isBannerVisible, setIsBannerVisible] = useLocalStorage(`${bannerName}Visible`, true); | ||
const pathname = usePathname(); | ||
const isOnPage = pathname === href.split('?')[0]; | ||
|
||
const linkClick = useCallback(() => { | ||
logEvent( | ||
bannerName, | ||
{ | ||
action: ActionType.click, | ||
componentType: ComponentType.banner, | ||
context: 'navbar', | ||
}, | ||
AnalyticsEventImportance.high, | ||
); | ||
}, [logEvent, ActionType, ComponentType, AnalyticsEventImportance]); | ||
|
||
const hideBanner = useCallback(() => { | ||
setIsBannerVisible(false); | ||
}, [setIsBannerVisible]); | ||
|
||
if (!isBannerVisible || isOnPage) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="bg-yellow-20 z-10 flex w-full flex-row justify-center text-black"> | ||
<div className="bg-yellow-20 z-10 flex w-full max-w-[1440px] flex-row items-center justify-between self-center p-2 pl-8 pr-6"> | ||
<Link href={href} onClick={linkClick}> | ||
<span className="text-xs underline md:text-base">{text}</span> | ||
</Link> | ||
<div className="flex flex-row items-center gap-4"> | ||
<button | ||
className="cursor-pointer p-2 text-sm" | ||
onClick={hideBanner} | ||
onKeyDown={hideBanner} | ||
type="button" | ||
> | ||
<Icon name="close" color="black" width="16" height="16" /> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |