|
| 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 | +} |
0 commit comments