Skip to content

Commit 5aad508

Browse files
feat: add banner component
1 parent 7dd7449 commit 5aad508

File tree

5 files changed

+150
-0
lines changed

5 files changed

+150
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import { Meta } from "@storybook/react";
3+
4+
import { Banner } from "./Banner";
5+
6+
export default {
7+
title: "Components/Banner",
8+
argTypes: {
9+
colorMode: {
10+
control: { type: "radio" },
11+
options: ["light", "dark"],
12+
defaultValue: "light",
13+
},
14+
},
15+
} as Meta;
16+
17+
export const UnmodifiedBanner = (args: { colorMode: "light" | "dark" }) => {
18+
const { colorMode } = args;
19+
const isDark = colorMode === "dark";
20+
21+
return (
22+
<div
23+
className={`${isDark ? "dark" : ""} bg-bdp-background w-full h-[90vh]`}
24+
>
25+
<Banner
26+
headingText="Start your career in bitcoin open source —"
27+
linkText="APPLY TODAY"
28+
linkTo="/"
29+
hasBoss
30+
/>
31+
</div>
32+
);
33+
};

src/components/banner/Banner.tsx

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"use client";
2+
import React from "react";
3+
import { useState } from "react";
4+
import { cn } from "../../utils/cn";
5+
6+
type StyleConfig = {
7+
container?: string;
8+
bannerInfoContainer?: string;
9+
bodyText?: string;
10+
headingText?: string;
11+
link?: string;
12+
icon?: string;
13+
boss?: string;
14+
};
15+
type Links = {
16+
linkText: string;
17+
linkTo: string;
18+
};
19+
type Props = Links & {
20+
bodyText?: string;
21+
headingText: string;
22+
styles?: StyleConfig;
23+
hasBoss?: boolean;
24+
};
25+
26+
const defaultStyles = {
27+
container:
28+
"dark:text-bdp-white dark:shadow-dark-light gap-2 flex items-center justify-between w-full px-2 sm:px-4 shadow-md transition-all duration-200 ease-in-out text-center",
29+
bannerInfoContainer: `flex flex-col flex-[1_1_auto]`,
30+
headingText: "font-semibold text-sm md:text-lg",
31+
bodyText: "text-sm md:text-base",
32+
link: "text-bdp-accent underline font-semibold text-xs md:text-sm",
33+
icon: "text-bdp-lightGrey hover:text-red-500 transition-all duration-200 ease-in-out",
34+
boss: "text-bdp-accent text-base md:text-lg",
35+
} as const;
36+
37+
export function Banner({
38+
bodyText,
39+
headingText,
40+
styles = {},
41+
hasBoss,
42+
...rest
43+
}: Props) {
44+
const [showBanner, setShowBanner] = useState(true);
45+
46+
return (
47+
<div
48+
data-show-banner={showBanner}
49+
data-has-heading={Boolean(headingText)}
50+
className={cn(
51+
defaultStyles.container,
52+
"data-[has-heading='true']:h-16",
53+
"data-[has-heading='false']:h-12",
54+
"data-[show-banner='false']:h-0 overflow-hidden",
55+
styles.container,
56+
)}
57+
>
58+
<div
59+
className={cn(
60+
defaultStyles.bannerInfoContainer,
61+
styles.bannerInfoContainer,
62+
)}
63+
>
64+
{!!headingText && (
65+
<h3 className={cn(defaultStyles.headingText, styles.headingText)}>
66+
{headingText}
67+
{hasBoss && (
68+
<span className={cn(defaultStyles.boss, styles.boss)}> ₿OSS</span>
69+
)}
70+
</h3>
71+
)}
72+
{!!bodyText && (
73+
<p className={cn(defaultStyles.bodyText, styles.bodyText)}>
74+
{bodyText}
75+
</p>
76+
)}
77+
{!!rest.linkText && (
78+
<a className={cn(defaultStyles.link, styles.link)} href={rest.linkTo}>
79+
{rest.linkText}
80+
</a>
81+
)}
82+
</div>
83+
<button
84+
onClick={() => setShowBanner(false)}
85+
data-show-banner={showBanner}
86+
className={cn(
87+
defaultStyles.icon,
88+
"opacity-1",
89+
"data-[show-banner='false']:opacity-0",
90+
styles.icon,
91+
)}
92+
>
93+
<svg
94+
className="h-[20px] w-[20px] md:h-6 md:w-6"
95+
xmlns="http://www.w3.org/2000/svg"
96+
fill="none"
97+
viewBox="0 0 24 24"
98+
stroke="currentColor"
99+
width="24"
100+
height="24"
101+
>
102+
<path
103+
strokeLinecap="round"
104+
strokeLinejoin="round"
105+
strokeWidth="3"
106+
d="M6 18L18 6M6 6l12 12"
107+
></path>
108+
</svg>
109+
</button>
110+
</div>
111+
);
112+
}

src/components/banner/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Banner";

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./components/button";
22
export * from "./components/footer";
33
export * from "./components/carousel";
44
export * from "./components/select";
5+
export * from "./components/banner";

tailwind.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module.exports = {
44
content: ['./src/**/*.{js,jsx,ts,tsx}'],
55
theme: {
66
extend: {
7+
boxShadowColor: {
8+
"dark-light": "rgba(255, 255, 255, 0.05)"
9+
},
710
colors: {
811
bdp: {
912
background: "var(--background)",

0 commit comments

Comments
 (0)