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 | b7c7974 | 2022-11-06 18:08:36 +0000 | [diff] [blame] | 20 | getButtonRow() { |
| 21 | return this.props.buttons ? this.props.buttons.map((button, i) => { |
| 22 | return <a |
| 23 | key={i} |
| 24 | className={Styles.button} |
| 25 | style={{backgroundColor:`#${button.color}`, color:`#${this.props.buttonText}`}} |
| 26 | href={button.link ? button.link : null} |
| 27 | onClick={button.onClick ? button.onClick : null} |
| 28 | target={button.newTab ? "_blank" : undefined} |
| 29 | rel="noreferrer">{button.text} |
| 30 | </a> |
| 31 | }) : null |
| 32 | } |
| 33 | |
| 34 | getTitleBlock() { |
| 35 | let icons = null; |
| 36 | if (this.props.icon && this.props.icon[0].length > 1) { |
| 37 | icons = <div className={Styles.iconRow}>{this.props.icon.map((icon, i) => { |
| 38 | return <img key={i} alt={this.props.title} className={Styles.image} src={`https://assets.clicks.codes/${icon}.svg`} /> |
| 39 | })}</div> |
| 40 | } else if (this.props.icon) { |
| 41 | icons = <img alt={this.props.title} className={Styles.image} src={`https://assets.clicks.codes/${this.props.icon}.svg`} /> |
| 42 | } else if (this.props.wave) { |
Skyler Grey | a47a4f7 | 2023-03-13 23:14:16 +0000 | [diff] [blame] | 43 | icons = <img alt={this.props.title} className={Styles.image} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} /> |
pineafan | b7c7974 | 2022-11-06 18:08:36 +0000 | [diff] [blame] | 44 | } |
| 45 | return <>{icons}</>; |
| 46 | } |
| 47 | getBand() { |
| 48 | if (this.props.band) { |
| 49 | return <div className={Styles.band} style={{ |
| 50 | backgroundColor: `#${this.props.band.color ?? "F27878"}`, |
| 51 | bottom: this.props.buttons ? `calc(25% + 5px)` : "40px" |
| 52 | }}> |
| 53 | <p style={{color: "#" + (this.props.band.textColor ?? "FFFFFF")}}>{this.props.band.text ?? ""}</p> |
| 54 | </div> |
| 55 | } |
| 56 | } |
| 57 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 58 | render() { |
pineafan | b7c7974 | 2022-11-06 18:08:36 +0000 | [diff] [blame] | 59 | let overwriteAlign = { |
| 60 | "left": "flex-start", |
| 61 | "center": "center", |
| 62 | "right": "flex-end" |
| 63 | }[this.props.overwritePosition ?? "right"]; |
| 64 | if (this.props.border) { |
| 65 | return ( |
| 66 | <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null) + " " + Styles.dashed} style={{ |
| 67 | margin: "0", opacity: `0`, boxShadow: "none", borderColor: `#${this.props.border}` |
| 68 | }}> |
| 69 | <div className={Styles.noPanel}> |
| 70 | <div className={Styles.titleContainer}> |
| 71 | { |
| 72 | (this.props.icon || this.props.wave) |
| 73 | ? <img alt="Project icon" className={Styles.image} src={"https://assets.clicks.codes/" + (this.props.icon ? this.props.icon : this.props.wave) + ".svg"} /> |
| 74 | : null |
| 75 | } |
| 76 | <h1 className={Styles.title}>{this.props.title}</h1> |
| 77 | </div> |
| 78 | <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p> |
| 79 | {this.getBand()} |
| 80 | <div className={Styles.buttonLayout} onClick={this.showMessage} style={{ |
| 81 | justifyContent: overwriteAlign |
| 82 | }}> |
| 83 | {this.getButtonRow()} |
| 84 | </div> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 85 | </div> |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 86 | </div> |
pineafan | b7c7974 | 2022-11-06 18:08:36 +0000 | [diff] [blame] | 87 | ); |
| 88 | } else { |
| 89 | return ( |
| 90 | <div className={Styles.card + " " + (this.props.shown ? Styles.shown : null)} style={{ |
| 91 | margin: "0" |
| 92 | }} onClick={this.handleClick}> |
| 93 | <div className={Styles.backgroundGradient} style={{ |
| 94 | backgroundImage: `linear-gradient(69.44deg, #${this.props.gradient[0]} 0%, #${this.props.gradient[1]} 100%)` |
| 95 | }} /> |
| 96 | <img alt="" className={Styles.backgroundImage} src={`https://assets.clicks.codes/web/waves/card/${this.props.wave}.svg`} draggable={false} /> |
| 97 | <div className={Styles.panel} onClick={this.handleClick}> |
| 98 | <div className={Styles.titleContainer}> |
| 99 | { this.getTitleBlock() } |
| 100 | <h1 className={Styles.title}>{this.props.title}</h1> |
| 101 | </div> |
| 102 | <p className={Styles.subtext + " " + (this.props.buttons ? null : Styles.longText)}>{this.props.subtext}</p> |
| 103 | {this.getBand()} |
| 104 | <div className={Styles.buttonLayout} onClick={this.showMessage} style={{ |
| 105 | justifyContent: overwriteAlign |
| 106 | }}> |
| 107 | {this.getButtonRow()} |
| 108 | </div> |
| 109 | </div> |
| 110 | </div> |
| 111 | ); |
| 112 | } |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 113 | } |
Samuel Shuert | 016ea02 | 2021-09-01 16:17:24 -0500 | [diff] [blame] | 114 | } |
| 115 | |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 116 | class CardRowClass extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 117 | constructor(props) { |
| 118 | super(props); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 119 | this.state = { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 120 | shown: false, |
| 121 | childrenShown: Array(this.props.children.length) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | animate() { |
| 126 | const { inViewport } = this.props; |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 127 | if (inViewport) { |
| 128 | this.setState({shown: true}); |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 129 | for (let index = 0; index < this.state.childrenShown.length; index++) { |
| 130 | setTimeout(() => { |
| 131 | this.setState(state => { |
| 132 | let childrenShown = [...state.childrenShown]; |
| 133 | childrenShown[index] = true; |
| 134 | return {childrenShown}; |
| 135 | }) |
| 136 | }, 200 * index); |
| 137 | } |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 138 | } |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 139 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 140 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 141 | render() { |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 142 | if (!this.props.shown) this.animate() |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 143 | return ( |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 144 | <div className={Styles.container}> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 145 | { |
| 146 | react.Children.toArray(this.props.children).map((item, index) => { |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 147 | item = <Card |
Skyler Grey | 51363a7 | 2022-10-21 23:28:02 +0100 | [diff] [blame] | 148 | shown={this.state.childrenShown[index]} |
pineafan | b18f019 | 2022-10-27 22:08:36 +0100 | [diff] [blame] | 149 | {...item.props} |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 150 | /> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 151 | return <div className={Styles.item} key={index}>{item}</div> |
| 152 | }) |
| 153 | } |
| 154 | </div> |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 155 | ) |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 156 | } |
pineafan | 5b612d9 | 2022-02-17 19:22:50 +0000 | [diff] [blame] | 157 | } |
| 158 | |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 159 | Card = withRouter(Card); |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 160 | const CardRow = handleViewport(CardRowClass, { rootMargin: '-1.0px' }); |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 161 | |
| 162 | export { Card, CardRow }; |