blob: ff46351d022ed9ed26f74b9b94880e70f2ff0985 [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'
pineafana5ce9102021-09-02 17:21:31 +01007
pineafanff3d4522022-05-06 19:51:02 +01008function 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);
pineafan9babd752022-10-21 21:47:52 +010035 if (clickTotal > 0 && Math.floor(Math.random() * 3) === 0) {
pineafanff3d4522022-05-06 19:51:02 +010036 disappointment();
37 } else {
38 reward();
39 }
40 }
pineafan9b1b68c2021-11-05 17:47:27 +000041 }
pineafana5ce9102021-09-02 17:21:31 +010042
pineafanff3d4522022-05-06 19:51:02 +010043 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}>
pineafana5ce9102021-09-02 17:21:31 +010075 {
pineafanff3d4522022-05-06 19:51:02 +010076 props.customImage?
77 <img height="64px" width="64px" alt={props.name} className={Styles.headerImage} style={{borderRadius: props.roundImage ? "100vw" : "0"}} src={props.customImage} />
78 : <></>
pineafana5ce9102021-09-02 17:21:31 +010079 }
80 </div>
pineafanff3d4522022-05-06 19:51:02 +010081 <h1 className={Styles.title}>{props.name}</h1>
pineafana5ce9102021-09-02 17:21:31 +010082 </div>
pineafanff3d4522022-05-06 19:51:02 +010083 <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 }
pineafana5ce9102021-09-02 17:21:31 +0100116 </div>
pineafanff3d4522022-05-06 19:51:02 +0100117 <div id="headerConfetti" />
118 <div id="disappointmentConfetti" />
119 </div>
120 )
pineafana5ce9102021-09-02 17:21:31 +0100121}
122
123export default Header;