blob: c928baf72b8f61ff9437dd37f0fbf478ad604345 [file] [log] [blame]
Samuel Shuert016ea022021-09-01 16:17:24 -05001import { Component } from "react";
pineafane0283a82022-02-13 10:05:56 +00002import Styles from '../styles/Components/card.module.css';
pineafan5b612d92022-02-17 19:22:50 +00003import react from 'react'
pineafanff3d4522022-05-06 19:51:02 +01004import { withRouter } from "next/router";
pineafan9babd752022-10-21 21:47:52 +01005import handleViewport from 'react-in-viewport';
Samuel Shuert016ea022021-09-01 16:17:24 -05006
7class Card extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +01008 constructor(props) {
9 super(props);
pineafand94d40e2022-10-23 19:55:29 +010010 this.handleClick = this.handleClick.bind(this);
11 }
12
13 handleClick(e) {
14 e.preventDefault();
15 if (this.props.url) {
pineafan802daca2022-10-24 21:57:29 +010016 window.location = this.props.url;
pineafand94d40e2022-10-23 19:55:29 +010017 }
Samuel Shuert52f37772021-09-02 12:29:40 -050018 }
Samuel Shuert016ea022021-09-01 16:17:24 -050019
pineafanaa9c4fd2022-06-10 19:58:10 +010020 render() {
21 return (
Skyler Grey51363a72022-10-21 23:28:02 +010022 <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{
pineafana5ce9102021-09-02 17:21:31 +010023 margin: "0"
pineafand94d40e2022-10-23 19:55:29 +010024 }} onClick={this.handleClick}>
pineafanff3d4522022-05-06 19:51:02 +010025 <div className={Styles.backgroundGradient} style={{
pineafana841c762021-11-14 21:21:04 +000026 backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)`
27 }} />
pineafanff3d4522022-05-06 19:51:02 +010028 <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} />
pineafand94d40e2022-10-23 19:55:29 +010029 <div className={Styles.panel} onClick={this.handleClick}>
pineafana5ce9102021-09-02 17:21:31 +010030 <div className={Styles.titleContainer}>
pineafanff3d4522022-05-06 19:51:02 +010031 <img alt="Project icon" className={Styles.image} src={"https://assets.clicks.codes/" + (this.props.icon ? this.props.icon : this.props.wave) + ".svg"} />
pineafana5ce9102021-09-02 17:21:31 +010032 <h1 className={Styles.title}>{this.props.title}</h1>
33 </div>
pineafan802daca2022-10-24 21:57:29 +010034 <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p>
pineafana5ce9102021-09-02 17:21:31 +010035 <div className={Styles.buttonLayout}>
36 {
Samuel Shuert604e31d2021-09-02 16:06:20 -050037 this.props.buttons ? this.props.buttons.map((button, i) => {
pineafana5ce9102021-09-02 17:21:31 +010038 return <a
Samuel Shuert604e31d2021-09-02 16:06:20 -050039 key={i}
pineafana5ce9102021-09-02 17:21:31 +010040 className={Styles.button}
41 style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}}
Samuel Shuert52f37772021-09-02 12:29:40 -050042 href={button.link}
pineafanaed30242021-09-04 09:33:40 +010043 target={button.newTab ? "_blank" : undefined}
pineafan0a178732022-02-09 21:00:05 +000044 rel="noreferrer">{button.text}
pineafana5ce9102021-09-02 17:21:31 +010045 </a>
46 }) : null
47 }
48 </div>
Samuel Shuert016ea022021-09-01 16:17:24 -050049 </div>
50 </div>
pineafanff3d4522022-05-06 19:51:02 +010051 );
52 }
Samuel Shuert016ea022021-09-01 16:17:24 -050053}
54
pineafan9babd752022-10-21 21:47:52 +010055class CardRowClass extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010056 constructor(props) {
57 super(props);
pineafan9babd752022-10-21 21:47:52 +010058 this.state = {
Skyler Grey51363a72022-10-21 23:28:02 +010059 shown: false,
60 childrenShown: Array(this.props.children.length)
pineafan9babd752022-10-21 21:47:52 +010061 }
62 }
63
64 animate() {
65 const { inViewport } = this.props;
pineafan9babd752022-10-21 21:47:52 +010066 if (inViewport) {
67 this.setState({shown: true});
Skyler Grey51363a72022-10-21 23:28:02 +010068 for (let index = 0; index < this.state.childrenShown.length; index++) {
69 setTimeout(() => {
70 this.setState(state => {
71 let childrenShown = [...state.childrenShown];
72 childrenShown[index] = true;
73 return {childrenShown};
74 })
75 }, 200 * index);
76 }
pineafan9babd752022-10-21 21:47:52 +010077 }
pineafanaa9c4fd2022-06-10 19:58:10 +010078 }
pineafan5b612d92022-02-17 19:22:50 +000079
pineafanaa9c4fd2022-06-10 19:58:10 +010080 render() {
Skyler Grey51363a72022-10-21 23:28:02 +010081 if (!this.props.shown) this.animate()
pineafanaa9c4fd2022-06-10 19:58:10 +010082 return (
pineafan5b612d92022-02-17 19:22:50 +000083 <div className={Styles.container}>
pineafanaa9c4fd2022-06-10 19:58:10 +010084 {
85 react.Children.toArray(this.props.children).map((item, index) => {
pineafan9babd752022-10-21 21:47:52 +010086 item = <Card
Skyler Grey51363a72022-10-21 23:28:02 +010087 shown={this.state.childrenShown[index]}
pineafan9babd752022-10-21 21:47:52 +010088 title={item.props.title}
89 subtext={item.props.subtext}
90 wave={item.props.wave}
91 gradient={item.props.gradient}
92 icon={item.props.icon}
93 buttons={item.props.buttons}
94 buttonText={item.props.buttonText}
95 url={item.props.url}
96 />
pineafanaa9c4fd2022-06-10 19:58:10 +010097 return <div className={Styles.item} key={index}>{item}</div>
98 })
99 }
100 </div>
pineafan5b612d92022-02-17 19:22:50 +0000101 )
pineafanaa9c4fd2022-06-10 19:58:10 +0100102 }
pineafan5b612d92022-02-17 19:22:50 +0000103}
104
pineafanff3d4522022-05-06 19:51:02 +0100105Card = withRouter(Card);
pineafan9babd752022-10-21 21:47:52 +0100106const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' });
pineafanff3d4522022-05-06 19:51:02 +0100107
108export { Card, CardRow };