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 | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 10 | this.state = { |
| 11 | shown: false |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | animateIn() { |
| 16 | setTimeout(() => { |
| 17 | this.setState({shown: true}); |
| 18 | }, this.props.delay * 200); |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 19 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 20 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 21 | render() { |
| 22 | return ( |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 23 | <div className={Styles.card + " " + (this.state.shown ? Styles.shown : null)} style={{ |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 24 | margin: "0" |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 25 | }} onClick={this.props.url ? () => { this.props.router.push(this.props.url)} : null}> |
| 26 | <div className={Styles.backgroundGradient} style={{ |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame] | 27 | backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)` |
| 28 | }} /> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 29 | <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}}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 31 | <div className={Styles.titleContainer}> |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 32 | <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] | 33 | <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 Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 38 | this.props.buttons ? this.props.buttons.map((button, i) => { |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 39 | return <a |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 40 | key={i} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 41 | className={Styles.button} |
| 42 | style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}} |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 43 | href={button.link} |
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 = { |
| 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 | } |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 76 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 77 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 78 | render() { |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 79 | if (!this.state.shown) this.animate() |
| 80 | else console.log("not animating") |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 81 | return ( |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 82 | <div className={Styles.container}> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 83 | { |
| 84 | react.Children.toArray(this.props.children).map((item, index) => { |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 85 | 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 | /> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 96 | return <div className={Styles.item} key={index}>{item}</div> |
| 97 | }) |
| 98 | } |
| 99 | </div> |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 100 | ) |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 101 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 102 | } |
| 103 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 104 | Card = withRouter(Card); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 105 | const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' }); |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 106 | |
| 107 | export { Card, CardRow }; |