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); |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 10 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 11 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 12 | render() { |
| 13 | return ( |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 14 | <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{ |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 15 | margin: "0" |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 16 | }} onClick={this.props.url ? () => { this.props.router.push(this.props.url)} : null}> |
| 17 | <div className={Styles.backgroundGradient} style={{ |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame] | 18 | backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)` |
| 19 | }} /> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 20 | <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}}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 22 | <div className={Styles.titleContainer}> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 23 | <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] | 24 | <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 Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 29 | this.props.buttons ? this.props.buttons.map((button, i) => { |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 30 | return <a |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 31 | key={i} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 32 | className={Styles.button} |
| 33 | style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}} |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 34 | href={button.link} |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 35 | target={button.newTab ? "_blank" : undefined} |
pineafan | 0a17873 | 2022-02-09 21:00:05 +0000 | [diff] [blame] | 36 | rel="noreferrer">{button.text} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 37 | </a> |
| 38 | }) : null |
| 39 | } |
| 40 | </div> |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 41 | </div> |
| 42 | </div> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 43 | ); |
| 44 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 45 | } |
| 46 | |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 47 | class CardRowClass extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 48 | constructor(props) { |
| 49 | super(props); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 50 | this.state = { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 51 | shown: false, |
| 52 | childrenShown: Array(this.props.children.length) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | animate() { |
| 57 | const { inViewport } = this.props; |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 58 | if (inViewport) { |
| 59 | this.setState({shown: true}); |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 60 | 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 | } |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 69 | } |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 70 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 71 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 72 | render() { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 73 | if (!this.props.shown) this.animate() |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 74 | return ( |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 75 | <div className={Styles.container}> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 76 | { |
| 77 | react.Children.toArray(this.props.children).map((item, index) => { |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 78 | item = <Card |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 79 | shown={this.state.childrenShown[index]} |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 80 | 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 | /> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 89 | return <div className={Styles.item} key={index}>{item}</div> |
| 90 | }) |
| 91 | } |
| 92 | </div> |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 93 | ) |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 94 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 95 | } |
| 96 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 97 | Card = withRouter(Card); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 98 | const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' }); |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 99 | |
| 100 | export { Card, CardRow }; |