Skip to content

Commit

Permalink
Feat/ock banners (#635)
Browse files Browse the repository at this point in the history
* 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
brendan-defi authored Jul 15, 2024
1 parent bc3dfc1 commit a675314
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import logEvent, {

import styles from './styles.module.css';

const href = 'https://www.base.org/onchainsummer?utm_source=DocsSite&utm_campaign=onchainsummer';
type BannerName = `${string}Banner`;

export function OcsBanner() {
const [isBannerVisible, setIsBannerVisible] = useLocalStorage('isOcsBannerVisible', true);
type BannerProps = {
href: string;
text: string;
bannerName: BannerName;
};

export default function Banner({ href, text, bannerName}: BannerProps) {
const [isBannerVisible, setIsBannerVisible] = useLocalStorage(`${bannerName}Visible'`, true);

const linkClick = useCallback(() => {
logEvent(
'ocsbanner',
bannerName,
{
action: ActionType.click,
componentType: ComponentType.banner,
Expand Down Expand Up @@ -44,7 +50,7 @@ export function OcsBanner() {
aria-label="Onchain Summer Buildathon Banner"
onClick={linkClick}
>
<span className={styles.bannerText}>Build Onchain this Summer!</span>
<span className={styles.bannerText}>{text}</span>
</a>
<div className={styles.bannerIconContainer}>
<a
Expand Down
10 changes: 8 additions & 2 deletions apps/base-docs/src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React from 'react';

import NavbarLayout from '@theme/Navbar/Layout';
import NavbarContent from '@theme/Navbar/Content';
import { OcsBanner } from '../../components/OnchainSummer/OcsBanner';
import Banner from '../../components/Banner/Banner';

export default function Navbar() {
return (
<>
<OcsBanner />
<Banner
bannerName="onchainKitBanner"
href="https://onchainkit.xyz/?utm_source=basedocs&utm_medium=banner"
text="Build on Base in minutes with OnchainKit!"
/>
<NavbarLayout>
<NavbarContent />
</NavbarLayout>
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/components/Layout/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from 'next/router';
import { Logo } from '../../Logo/Logo';
import DesktopNav from './DesktopNav';
import MobileMenu from './MobileMenu';
import { OcsBanner } from 'apps/web/src/components/Layout/Nav/OcsBanner';
import Banner from 'base-ui/components/Layout/Nav/Banner';

type NavProps = {
color: 'white' | 'black';
Expand All @@ -15,7 +15,11 @@ export function Nav({ color }: NavProps) {

return (
<>
<OcsBanner />
<Banner
bannerName="onchainKitBanner"
href="https://onchainkit.xyz/?utm_source=basedotorg&utm_medium=banner"
text="Build on Base in minutes with OnchainKit!"
/>
<nav className="bg-transparent z-10 flex h-24 w-full max-w-[1440px] flex-row items-center justify-between gap-16 self-center p-8">
<Link href="/" aria-label="Base Homepage">
<Logo color={color} path={pathname} width="106px" />
Expand Down
65 changes: 65 additions & 0 deletions libs/base-ui/components/Layout/Nav/Banner.tsx
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>
);
}

0 comments on commit a675314

Please sign in to comment.