blob: 5738a4ab956b8f771b4d4cefdc0aa502e7a9b75d [file] [log] [blame]
pineafanff3d4522022-05-06 19:51:02 +01001import React, { useRef } from "react";
pineafane0283a82022-02-13 10:05:56 +00002import Styles from '../styles/Components/header.module.css';
pineafan876af7d2021-10-14 20:31:21 +01003import Head from 'next/head';
pineafanff3d4522022-05-06 19:51:02 +01004import { useColorMode } from "theme-ui";
5import { useReward } from "react-rewards";
6import ScrollContainer from 'react-indiana-drag-scroll'
pineafanfd93e6e2022-05-06 20:30:09 +01007import Link from 'next/link'
pineafana5ce9102021-09-02 17:21:31 +01008
pineafanff3d4522022-05-06 19:51:02 +01009function 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 }
pineafan9b1b68c2021-11-05 17:47:27 +000042 }
pineafana5ce9102021-09-02 17:21:31 +010043
pineafanff3d4522022-05-06 19:51:02 +010044 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}>
pineafana5ce9102021-09-02 17:21:31 +010076 {
pineafanff3d4522022-05-06 19:51:02 +010077 props.customImage?
78 <img height="64px" width="64px" alt={props.name} className={Styles.headerImage} style={{borderRadius: props.roundImage ? "100vw" : "0"}} src={props.customImage} />
79 : <></>
pineafana5ce9102021-09-02 17:21:31 +010080 }
81 </div>
pineafanff3d4522022-05-06 19:51:02 +010082 <h1 className={Styles.title}>{props.name}</h1>
pineafana5ce9102021-09-02 17:21:31 +010083 </div>
pineafanff3d4522022-05-06 19:51:02 +010084 <p className={Styles.subtext + " " + (props.buttons.length ? Styles.subtextExtra : null)}>{props.subtext}</p>
pineafanfd93e6e2022-05-06 20:30:09 +010085 <Link href="#skipNav" id="skipNav" style={{display: "none"}} />
pineafanff3d4522022-05-06 19:51:02 +010086 { 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) => {
pineafanfd93e6e2022-05-06 20:30:09 +010099 return <Link
pineafanff3d4522022-05-06 19:51:02 +0100100 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}
pineafanfd93e6e2022-05-06 20:30:09 +0100109 </Link>
pineafanff3d4522022-05-06 19:51:02 +0100110 }) : 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 }
pineafana5ce9102021-09-02 17:21:31 +0100117 </div>
pineafanff3d4522022-05-06 19:51:02 +0100118 <div id="headerConfetti" />
119 <div id="disappointmentConfetti" />
120 </div>
121 )
pineafana5ce9102021-09-02 17:21:31 +0100122}
123
124export default Header;