blob: 40438941caf5d1c16e6262083b9340930bcbffb4 [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);
pineafan9babd752022-10-21 21:47:52 +010010 this.state = {
11 shown: false
12 }
13 }
14
15 animateIn() {
16 setTimeout(() => {
17 this.setState({shown: true});
18 }, this.props.delay * 200);
Samuel Shuert52f37772021-09-02 12:29:40 -050019 }
Samuel Shuert016ea022021-09-01 16:17:24 -050020
pineafanaa9c4fd2022-06-10 19:58:10 +010021 render() {
22 return (
pineafan9babd752022-10-21 21:47:52 +010023 <div className={Styles.card + " " + (this.state.shown ? Styles.shown : null)} style={{
pineafana5ce9102021-09-02 17:21:31 +010024 margin: "0"
pineafanff3d4522022-05-06 19:51:02 +010025 }} onClick={this.props.url ? () => { this.props.router.push(this.props.url)} : null}>
26 <div className={Styles.backgroundGradient} style={{
pineafana841c762021-11-14 21:21:04 +000027 backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)`
28 }} />
pineafanff3d4522022-05-06 19:51:02 +010029 <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} />
30 <div className={Styles.panel} onClick={() => { this.props.url ? () => { this.props.router.push(this.props.url)} : null}}>
pineafana5ce9102021-09-02 17:21:31 +010031 <div className={Styles.titleContainer}>
pineafanff3d4522022-05-06 19:51:02 +010032 <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 +010033 <h1 className={Styles.title}>{this.props.title}</h1>
34 </div>
35 <p className={Styles.subtext}>{this.props.subtext}</p>
36 <div className={Styles.buttonLayout}>
37 {
Samuel Shuert604e31d2021-09-02 16:06:20 -050038 this.props.buttons ? this.props.buttons.map((button, i) => {
pineafana5ce9102021-09-02 17:21:31 +010039 return <a
Samuel Shuert604e31d2021-09-02 16:06:20 -050040 key={i}
pineafana5ce9102021-09-02 17:21:31 +010041 className={Styles.button}
42 style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}}
Samuel Shuert52f37772021-09-02 12:29:40 -050043 href={button.link}
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 = {
60 shown: false
61 }
62 }
63
64 animate() {
65 const { inViewport } = this.props;
66 console.log(inViewport)
67 if (inViewport) {
68 this.setState({shown: true});
69 react.Children.toArray(
70 react.Children.toArray(this.props.children)[0]
71 .props.children).forEach((item) => {
72 item.ref.current.animateIn();
73 }
74 );
75 }
pineafanaa9c4fd2022-06-10 19:58:10 +010076 }
pineafan5b612d92022-02-17 19:22:50 +000077
pineafanaa9c4fd2022-06-10 19:58:10 +010078 render() {
pineafan9babd752022-10-21 21:47:52 +010079 if (!this.state.shown) this.animate()
80 else console.log("not animating")
pineafanaa9c4fd2022-06-10 19:58:10 +010081 return (
pineafan5b612d92022-02-17 19:22:50 +000082 <div className={Styles.container}>
pineafanaa9c4fd2022-06-10 19:58:10 +010083 {
84 react.Children.toArray(this.props.children).map((item, index) => {
pineafan9babd752022-10-21 21:47:52 +010085 item = <Card
86 delay={index}
87 title={item.props.title}
88 subtext={item.props.subtext}
89 wave={item.props.wave}
90 gradient={item.props.gradient}
91 icon={item.props.icon}
92 buttons={item.props.buttons}
93 buttonText={item.props.buttonText}
94 url={item.props.url}
95 />
pineafanaa9c4fd2022-06-10 19:58:10 +010096 return <div className={Styles.item} key={index}>{item}</div>
97 })
98 }
99 </div>
pineafan5b612d92022-02-17 19:22:50 +0000100 )
pineafanaa9c4fd2022-06-10 19:58:10 +0100101 }
pineafan5b612d92022-02-17 19:22:50 +0000102}
103
pineafanff3d4522022-05-06 19:51:02 +0100104Card = withRouter(Card);
pineafan9babd752022-10-21 21:47:52 +0100105const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' });
pineafanff3d4522022-05-06 19:51:02 +0100106
107export { Card, CardRow };