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) { |
| 16 | this.props.router.push(this.props.url); |
| 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> |
| 34 | <p className={Styles.subtext}>{this.props.subtext}</p> |
| 35 | <div className={Styles.buttonLayout}> |
| 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}`}} |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 42 | href={button.link} |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 43 | target={button.newTab ? "_blank" : undefined} |
pineafan | 0a17873 | 2022-02-09 21:00:05 +0000 | [diff] [blame] | 44 | rel="noreferrer">{button.text} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 45 | </a> |
| 46 | }) : null |
| 47 | } |
| 48 | </div> |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 49 | </div> |
| 50 | </div> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 51 | ); |
| 52 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 53 | } |
| 54 | |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 55 | class CardRowClass extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 56 | constructor(props) { |
| 57 | super(props); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 58 | this.state = { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 59 | shown: false, |
| 60 | childrenShown: Array(this.props.children.length) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | animate() { |
| 65 | const { inViewport } = this.props; |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 66 | if (inViewport) { |
| 67 | this.setState({shown: true}); |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 68 | 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 | } |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 77 | } |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 78 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 79 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 80 | render() { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 81 | if (!this.props.shown) this.animate() |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 82 | return ( |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 83 | <div className={Styles.container}> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 84 | { |
| 85 | react.Children.toArray(this.props.children).map((item, index) => { |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 86 | item = <Card |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 87 | shown={this.state.childrenShown[index]} |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 88 | 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 | /> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 97 | return <div className={Styles.item} key={index}>{item}</div> |
| 98 | }) |
| 99 | } |
| 100 | </div> |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 101 | ) |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 102 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 103 | } |
| 104 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 105 | Card = withRouter(Card); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 106 | const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' }); |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 107 | |
| 108 | export { Card, CardRow }; |