pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 1 | import React, { useRef } from "react"; |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 2 | import Styles from '../styles/Components/header.module.css'; |
pineafan | 876af7d | 2021-10-14 20:31:21 +0100 | [diff] [blame] | 3 | import Head from 'next/head'; |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 4 | import { useColorMode } from "theme-ui"; |
| 5 | import { useReward } from "react-rewards"; |
| 6 | import ScrollContainer from 'react-indiana-drag-scroll' |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame^] | 7 | import Link from 'next/link' |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 8 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 9 | function Header(props) { |
| 10 | const [ clickTotal, setClickTotal ] = React.useState(0); |
| 11 | |
| 12 | const { reward: reward, isAnimating: isAnimating } = useReward('headerConfetti', 'confetti', { |
| 13 | elementSize: 10, |
| 14 | elementCount: 150, |
| 15 | startVelocity: 35, |
| 16 | lifetime: 300, |
| 17 | decay: 0.95, |
| 18 | spread: 170, |
| 19 | position: "absolute", |
| 20 | colors: ["#F27878", "#E5AB71", "#E5DC71", "#A1CC65", "#68D49E", "#71AFE5", "#6576CC", "#8D58B2", "#BF5E9F"] |
| 21 | }); |
| 22 | const { reward: disappointment, isAnimating: isDisappointmentAnimating } = useReward('disappointmentConfetti', 'confetti', { |
| 23 | elementSize: 25, |
| 24 | elementCount: 1, |
| 25 | startVelocity: 25, |
| 26 | lifetime: 350, |
| 27 | decay: 0.95, |
| 28 | spread: 0, |
| 29 | position: "absolute", |
| 30 | colors: ["#E5AB71"] |
| 31 | }); |
| 32 | |
| 33 | function confetti() { |
| 34 | if (!isAnimating && !isDisappointmentAnimating && props.index) { |
| 35 | setClickTotal(clickTotal + 1); |
| 36 | if (clickTotal > 0 && Math.floor(Math.random() * 3) == 0) { |
| 37 | disappointment(); |
| 38 | } else { |
| 39 | reward(); |
| 40 | } |
| 41 | } |
pineafan | 9b1b68c | 2021-11-05 17:47:27 +0000 | [diff] [blame] | 42 | } |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 43 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 44 | return ( |
| 45 | <div className={Styles.header} style={{ |
| 46 | margin: "0", |
| 47 | minHeight: props.fullscreen ? "calc(100vh - 42px)" : "calc(100vh - (4 * max(2em, 4vw)) - 1em)", |
| 48 | }} id={props.id ? props.id : null}> |
| 49 | <div className={Styles.backgroundGradient} style={{ |
| 50 | backgroundImage: `linear-gradient(69.44deg, #${props.gradient[0]} 0%, #${props.gradient[1]} 100%)`, |
| 51 | }} /> |
| 52 | <Head> |
| 53 | <title>{props.name}</title> |
| 54 | |
| 55 | <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 56 | <meta name="mobile-web-app-capable" content="yes" /> |
| 57 | <meta name="viewport" content="width=device-width, minimal-ui" /> |
| 58 | |
| 59 | <meta name="title" content={props.name} /> |
| 60 | <meta name="og:title" content={props.name} /> |
| 61 | <meta name="description" content={props.embedDescription ? props.embedDescription : props.subtext} /> |
| 62 | <meta name="og:description" content={props.embedDescription ? props.embedDescription : props.subtext} /> |
| 63 | <meta name="author" content="Clicks" /> |
| 64 | <meta name="og:author" content="Clicks" /> |
| 65 | <meta name="image" content={props.embedImage} /> |
| 66 | <meta name="og:image" content={props.embedImage} /> |
| 67 | |
| 68 | <meta name="theme-color" content={"#000000"} /> |
| 69 | <meta name="og-color" content={"#" + props.gradient[1]} /> |
| 70 | <meta name="msapplication-TileColor" content={"#000000"} /> |
| 71 | </Head> |
| 72 | <img draggable={false} alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/${props.wave}.svg`} /> |
| 73 | <div className={Styles.panel}> |
| 74 | <div className={Styles.titleContainer}> |
| 75 | <div onClick={confetti}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 76 | { |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 77 | props.customImage? |
| 78 | <img height="64px" width="64px" alt={props.name} className={Styles.headerImage} style={{borderRadius: props.roundImage ? "100vw" : "0"}} src={props.customImage} /> |
| 79 | : <></> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 80 | } |
| 81 | </div> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 82 | <h1 className={Styles.title}>{props.name}</h1> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 83 | </div> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 84 | <p className={Styles.subtext + " " + (props.buttons.length ? Styles.subtextExtra : null)}>{props.subtext}</p> |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame^] | 85 | <Link href="#skipNav" id="skipNav" style={{display: "none"}} /> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 86 | { props.buttons.length ? |
| 87 | <div className={Styles.buttonOverflow}> |
| 88 | <img className={Styles.indicator + " " + Styles.leftArrow} draggable={false} alt="" src={`https://assets.clicks.codes/web/icons/arrow.svg`}/> |
| 89 | <ScrollContainer |
| 90 | vertical={false} |
| 91 | horizontal={true} |
| 92 | hideScrollbars={true} |
| 93 | nativeMobileScroll={true} |
| 94 | style={{borderRadius: "10px", height: "fit-content"}} |
| 95 | > |
| 96 | <div className={Styles.buttonLayout}> |
| 97 | { |
| 98 | props.buttons ? props.buttons.map((button, index) => { |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame^] | 99 | return <Link |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 100 | key={index} |
| 101 | className={Styles.button} |
| 102 | style={{ backgroundColor: `#${button.color}`, color: `#${button.buttonText}` }} |
| 103 | href={button.link} |
| 104 | onClick={() => { if (button.id) { props.callback(button.id) } }} |
| 105 | target={button.target ? "_blank" : null} |
| 106 | draggable={false} |
| 107 | rel="noreferrer"> |
| 108 | {button.text} |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame^] | 109 | </Link> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 110 | }) : null |
| 111 | } |
| 112 | </div> |
| 113 | </ScrollContainer> |
| 114 | <img className={Styles.indicator + " " + Styles.rightArrow} draggable={false} alt="" src={`https://assets.clicks.codes/web/icons/arrow.svg`}/> |
| 115 | </div> : <></> |
| 116 | } |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 117 | </div> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 118 | <div id="headerConfetti" /> |
| 119 | <div id="disappointmentConfetti" /> |
| 120 | </div> |
| 121 | ) |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | export default Header; |