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