blob: e90a73f9c435b871bafc32c452d016bdcd8bcc68 [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>
pineafanb18f0192022-10-27 22:08:36 +010035 <div className={Styles.buttonLayout} onClick={this.showMessage}>
pineafana5ce9102021-09-02 17:21:31 +010036 {
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}`}}
pineafan25b33332022-10-29 22:16:35 +010042 href={button.link ? button.link : null}
43 onClick={button.onClick ? button.onClick : null}
pineafanaed30242021-09-04 09:33:40 +010044 target={button.newTab ? "_blank" : undefined}
pineafan0a178732022-02-09 21:00:05 +000045 rel="noreferrer">{button.text}
pineafana5ce9102021-09-02 17:21:31 +010046 </a>
47 }) : null
48 }
49 </div>
Samuel Shuert016ea022021-09-01 16:17:24 -050050 </div>
51 </div>
pineafanff3d4522022-05-06 19:51:02 +010052 );
53 }
Samuel Shuert016ea022021-09-01 16:17:24 -050054}
55
pineafan9babd752022-10-21 21:47:52 +010056class CardRowClass extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010057 constructor(props) {
58 super(props);
pineafan9babd752022-10-21 21:47:52 +010059 this.state = {
Skyler Grey51363a72022-10-21 23:28:02 +010060 shown: false,
61 childrenShown: Array(this.props.children.length)
pineafan9babd752022-10-21 21:47:52 +010062 }
63 }
64
65 animate() {
66 const { inViewport } = this.props;
pineafan9babd752022-10-21 21:47:52 +010067 if (inViewport) {
68 this.setState({shown: true});
Skyler Grey51363a72022-10-21 23:28:02 +010069 for (let index = 0; index < this.state.childrenShown.length; index++) {
70 setTimeout(() => {
71 this.setState(state => {
72 let childrenShown = [...state.childrenShown];
73 childrenShown[index] = true;
74 return {childrenShown};
75 })
76 }, 200 * index);
77 }
pineafan9babd752022-10-21 21:47:52 +010078 }
pineafanaa9c4fd2022-06-10 19:58:10 +010079 }
pineafan5b612d92022-02-17 19:22:50 +000080
pineafanaa9c4fd2022-06-10 19:58:10 +010081 render() {
Skyler Grey51363a72022-10-21 23:28:02 +010082 if (!this.props.shown) this.animate()
pineafanaa9c4fd2022-06-10 19:58:10 +010083 return (
pineafan5b612d92022-02-17 19:22:50 +000084 <div className={Styles.container}>
pineafanaa9c4fd2022-06-10 19:58:10 +010085 {
86 react.Children.toArray(this.props.children).map((item, index) => {
pineafan9babd752022-10-21 21:47:52 +010087 item = <Card
Skyler Grey51363a72022-10-21 23:28:02 +010088 shown={this.state.childrenShown[index]}
pineafanb18f0192022-10-27 22:08:36 +010089 {...item.props}
pineafan9babd752022-10-21 21:47:52 +010090 />
pineafanaa9c4fd2022-06-10 19:58:10 +010091 return <div className={Styles.item} key={index}>{item}</div>
92 })
93 }
94 </div>
pineafan5b612d92022-02-17 19:22:50 +000095 )
pineafanaa9c4fd2022-06-10 19:58:10 +010096 }
pineafan5b612d92022-02-17 19:22:50 +000097}
98
pineafanff3d4522022-05-06 19:51:02 +010099Card = withRouter(Card);
pineafan9babd752022-10-21 21:47:52 +0100100const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' });
pineafanff3d4522022-05-06 19:51:02 +0100101
102export { Card, CardRow };