blob: c7f7cca4817729b06fa7eebb6291309f020256df [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);
Samuel Shuert52f37772021-09-02 12:29:40 -050010 }
Samuel Shuert016ea022021-09-01 16:17:24 -050011
pineafanaa9c4fd2022-06-10 19:58:10 +010012 render() {
13 return (
Skyler Grey51363a72022-10-21 23:28:02 +010014 <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{
pineafana5ce9102021-09-02 17:21:31 +010015 margin: "0"
pineafanff3d4522022-05-06 19:51:02 +010016 }} onClick={this.props.url ? () => { this.props.router.push(this.props.url)} : null}>
17 <div className={Styles.backgroundGradient} style={{
pineafana841c762021-11-14 21:21:04 +000018 backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)`
19 }} />
pineafanff3d4522022-05-06 19:51:02 +010020 <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} />
21 <div className={Styles.panel} onClick={() => { this.props.url ? () => { this.props.router.push(this.props.url)} : null}}>
pineafana5ce9102021-09-02 17:21:31 +010022 <div className={Styles.titleContainer}>
pineafanff3d4522022-05-06 19:51:02 +010023 <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 +010024 <h1 className={Styles.title}>{this.props.title}</h1>
25 </div>
26 <p className={Styles.subtext}>{this.props.subtext}</p>
27 <div className={Styles.buttonLayout}>
28 {
Samuel Shuert604e31d2021-09-02 16:06:20 -050029 this.props.buttons ? this.props.buttons.map((button, i) => {
pineafana5ce9102021-09-02 17:21:31 +010030 return <a
Samuel Shuert604e31d2021-09-02 16:06:20 -050031 key={i}
pineafana5ce9102021-09-02 17:21:31 +010032 className={Styles.button}
33 style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}}
Samuel Shuert52f37772021-09-02 12:29:40 -050034 href={button.link}
pineafanaed30242021-09-04 09:33:40 +010035 target={button.newTab ? "_blank" : undefined}
pineafan0a178732022-02-09 21:00:05 +000036 rel="noreferrer">{button.text}
pineafana5ce9102021-09-02 17:21:31 +010037 </a>
38 }) : null
39 }
40 </div>
Samuel Shuert016ea022021-09-01 16:17:24 -050041 </div>
42 </div>
pineafanff3d4522022-05-06 19:51:02 +010043 );
44 }
Samuel Shuert016ea022021-09-01 16:17:24 -050045}
46
pineafan9babd752022-10-21 21:47:52 +010047class CardRowClass extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010048 constructor(props) {
49 super(props);
pineafan9babd752022-10-21 21:47:52 +010050 this.state = {
Skyler Grey51363a72022-10-21 23:28:02 +010051 shown: false,
52 childrenShown: Array(this.props.children.length)
pineafan9babd752022-10-21 21:47:52 +010053 }
54 }
55
56 animate() {
57 const { inViewport } = this.props;
pineafan9babd752022-10-21 21:47:52 +010058 if (inViewport) {
59 this.setState({shown: true});
Skyler Grey51363a72022-10-21 23:28:02 +010060 for (let index = 0; index < this.state.childrenShown.length; index++) {
61 setTimeout(() => {
62 this.setState(state => {
63 let childrenShown = [...state.childrenShown];
64 childrenShown[index] = true;
65 return {childrenShown};
66 })
67 }, 200 * index);
68 }
pineafan9babd752022-10-21 21:47:52 +010069 }
pineafanaa9c4fd2022-06-10 19:58:10 +010070 }
pineafan5b612d92022-02-17 19:22:50 +000071
pineafanaa9c4fd2022-06-10 19:58:10 +010072 render() {
Skyler Grey51363a72022-10-21 23:28:02 +010073 if (!this.props.shown) this.animate()
pineafanaa9c4fd2022-06-10 19:58:10 +010074 return (
pineafan5b612d92022-02-17 19:22:50 +000075 <div className={Styles.container}>
pineafanaa9c4fd2022-06-10 19:58:10 +010076 {
77 react.Children.toArray(this.props.children).map((item, index) => {
pineafan9babd752022-10-21 21:47:52 +010078 item = <Card
Skyler Grey51363a72022-10-21 23:28:02 +010079 shown={this.state.childrenShown[index]}
pineafan9babd752022-10-21 21:47:52 +010080 title={item.props.title}
81 subtext={item.props.subtext}
82 wave={item.props.wave}
83 gradient={item.props.gradient}
84 icon={item.props.icon}
85 buttons={item.props.buttons}
86 buttonText={item.props.buttonText}
87 url={item.props.url}
88 />
pineafanaa9c4fd2022-06-10 19:58:10 +010089 return <div className={Styles.item} key={index}>{item}</div>
90 })
91 }
92 </div>
pineafan5b612d92022-02-17 19:22:50 +000093 )
pineafanaa9c4fd2022-06-10 19:58:10 +010094 }
pineafan5b612d92022-02-17 19:22:50 +000095}
96
pineafanff3d4522022-05-06 19:51:02 +010097Card = withRouter(Card);
pineafan9babd752022-10-21 21:47:52 +010098const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' });
pineafanff3d4522022-05-06 19:51:02 +010099
100export { Card, CardRow };