|
| 1 | +import React from 'react'; |
| 2 | +import { Button } from 'components/Button'; |
| 3 | +import 'theme/styles.scss'; |
| 4 | + |
| 5 | +export type MyCircularProps = { |
| 6 | + title?: string; |
| 7 | + text: string; |
| 8 | + link?: string; |
| 9 | + linkText?: string; |
| 10 | +}; |
| 11 | + |
| 12 | +interface Props { |
| 13 | + data: MyCircularProps[]; |
| 14 | + imgData: string[]; |
| 15 | + textPos?: string; |
| 16 | +} |
| 17 | + |
| 18 | +export class TextWithProfileImage extends React.Component<Props> { |
| 19 | + renderChildren = (data: MyCircularProps[]): React.ReactElement[] => { |
| 20 | + let isRightLeft = true; // Alternate between right-left and left-right layout. |
| 21 | + let key = -1; |
| 22 | + return data.map((entry: MyCircularProps) => { |
| 23 | + isRightLeft = !isRightLeft; |
| 24 | + key += 1; |
| 25 | + |
| 26 | + // Determine if image should be displayed first or after text: |
| 27 | + let posClass = ''; |
| 28 | + switch (this.props.textPos) { |
| 29 | + case 'left': |
| 30 | + posClass = 'left-right-variant'; |
| 31 | + break; |
| 32 | + case 'right': |
| 33 | + posClass = 'right-left-variant'; |
| 34 | + break; |
| 35 | + |
| 36 | + default: |
| 37 | + // The "alternate" case |
| 38 | + posClass = isRightLeft ? 'right-left-variant' : 'left-right-variant'; |
| 39 | + } |
| 40 | + |
| 41 | + return ( |
| 42 | + <div key={key} className={`Block-TextWithProfileImage ${posClass}`}> |
| 43 | + <div className="TextBlock-TextWithProfileImage"> |
| 44 | + {entry.title !== undefined ? <h3>{entry.title}</h3> : <b></b>} |
| 45 | + <p>{entry.text}</p> |
| 46 | + <div className="ButtonBlock-TextWithProfileImage"> |
| 47 | + {this.renderButton(entry.link, entry.linkText)} |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + <img |
| 51 | + className="Img-TextWithProfileImage" |
| 52 | + src={this.props.imgData[key]} |
| 53 | + alt="waterloop" |
| 54 | + ></img> |
| 55 | + <div className="text-w-profile-image-btn-mobile"> |
| 56 | + {this.renderButton(entry.link, entry.linkText)} |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + ); |
| 60 | + }); |
| 61 | + }; |
| 62 | + |
| 63 | + renderButton = ( |
| 64 | + link: string | undefined, |
| 65 | + linkText: string | undefined, |
| 66 | + ): React.ReactElement => { |
| 67 | + if (link !== undefined && linkText !== undefined) { |
| 68 | + return ( |
| 69 | + <Button |
| 70 | + backgroundColor="yellow" |
| 71 | + textColor="black" |
| 72 | + text={linkText} |
| 73 | + onClick={(): Window | null => window.open(link, '_self')} |
| 74 | + /> |
| 75 | + ); |
| 76 | + } |
| 77 | + return <></>; |
| 78 | + }; |
| 79 | + |
| 80 | + render() { |
| 81 | + return <div>{this.renderChildren(this.props.data)}</div>; |
| 82 | + } |
| 83 | +} |
0 commit comments