Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 1 | import { Component } from "react"; |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 2 | import Styles from '../styles/Components/card.module.css'; |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 3 | import react from 'react' |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 4 | import { withRouter } from "next/router"; |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 5 | import handleViewport from 'react-in-viewport'; |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 6 | |
| 7 | class Card extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 8 | constructor(props) { |
| 9 | super(props); |
pineafan | d94d40e | 2022-10-23 19:55:29 +0100 | [diff] [blame] | 10 | this.handleClick = this.handleClick.bind(this); |
| 11 | } |
| 12 | |
| 13 | handleClick(e) { |
| 14 | e.preventDefault(); |
| 15 | if (this.props.url) { |
pineafan | 802daca | 2022-10-24 21:57:29 +0100 | [diff] [blame] | 16 | window.location = this.props.url; |
pineafan | d94d40e | 2022-10-23 19:55:29 +0100 | [diff] [blame] | 17 | } |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 18 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 19 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 20 | render() { |
| 21 | return ( |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 22 | <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{ |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 23 | margin: "0" |
pineafan | d94d40e | 2022-10-23 19:55:29 +0100 | [diff] [blame] | 24 | }} onClick={this.handleClick}> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 25 | <div className={Styles.backgroundGradient} style={{ |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame] | 26 | backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)` |
| 27 | }} /> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 28 | <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} /> |
pineafan | d94d40e | 2022-10-23 19:55:29 +0100 | [diff] [blame] | 29 | <div className={Styles.panel} onClick={this.handleClick}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 30 | <div className={Styles.titleContainer}> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 31 | <img alt="Project icon" className={Styles.image} src={"https://assets.clicks.codes/" + (this.props.icon ? this.props.icon : this.props.wave) + ".svg"} /> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 32 | <h1 className={Styles.title}>{this.props.title}</h1> |
| 33 | </div> |
pineafan | 802daca | 2022-10-24 21:57:29 +0100 | [diff] [blame] | 34 | <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p> |
pineafan | b18f019 | 2022-10-27 22:08:36 +0100 | [diff] [blame] | 35 | <div className={Styles.buttonLayout} onClick={this.showMessage}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 36 | { |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 37 | this.props.buttons ? this.props.buttons.map((button, i) => { |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 38 | return <a |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 39 | key={i} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 40 | className={Styles.button} |
| 41 | style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}} |
pineafan | 25b3333 | 2022-10-29 22:16:35 +0100 | [diff] [blame^] | 42 | href={button.link ? button.link : null} |
| 43 | onClick={button.onClick ? button.onClick : null} |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 44 | target={button.newTab ? "_blank" : undefined} |
pineafan | 0a17873 | 2022-02-09 21:00:05 +0000 | [diff] [blame] | 45 | rel="noreferrer">{button.text} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 46 | </a> |
| 47 | }) : null |
| 48 | } |
| 49 | </div> |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 50 | </div> |
| 51 | </div> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 52 | ); |
| 53 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 54 | } |
| 55 | |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 56 | class CardRowClass extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 57 | constructor(props) { |
| 58 | super(props); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 59 | this.state = { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 60 | shown: false, |
| 61 | childrenShown: Array(this.props.children.length) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | animate() { |
| 66 | const { inViewport } = this.props; |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 67 | if (inViewport) { |
| 68 | this.setState({shown: true}); |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 69 | 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 | } |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 78 | } |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 79 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 80 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 81 | render() { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 82 | if (!this.props.shown) this.animate() |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 83 | return ( |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 84 | <div className={Styles.container}> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 85 | { |
| 86 | react.Children.toArray(this.props.children).map((item, index) => { |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 87 | item = <Card |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 88 | shown={this.state.childrenShown[index]} |
pineafan | b18f019 | 2022-10-27 22:08:36 +0100 | [diff] [blame] | 89 | {...item.props} |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 90 | /> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 91 | return <div className={Styles.item} key={index}>{item}</div> |
| 92 | }) |
| 93 | } |
| 94 | </div> |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 95 | ) |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 96 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 97 | } |
| 98 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 99 | Card = withRouter(Card); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 100 | const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' }); |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 101 | |
| 102 | export { Card, CardRow }; |