Skyler Turner | f536121 | 2021-09-14 20:33:58 +0100 | [diff] [blame] | 1 | import react, { Component, cloneElement } from "react"; |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 2 | import Styles from '../styles/tilerow.module.css'; |
Samuel Shuert | 8aac601 | 2021-09-02 13:21:30 -0500 | [diff] [blame] | 3 | |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 4 | class TileRow extends Component { |
Skyler Turner | f536121 | 2021-09-14 20:33:58 +0100 | [diff] [blame] | 5 | constructor(props) { |
| 6 | super(props); |
| 7 | } |
| 8 | render() { |
| 9 | return ( |
| 10 | <div className={Styles.container}> |
| 11 | { |
| 12 | react.Children.toArray(this.props.children).map((item, index) => { |
Skyler Turner | 58e7da4 | 2021-09-14 20:41:21 +0100 | [diff] [blame^] | 13 | if (this.props.divless !== false) { // Intentional comparison to false, initially had a default of false, now has a default of true |
Skyler Turner | f536121 | 2021-09-14 20:33:58 +0100 | [diff] [blame] | 14 | const className = (item.props.className ? item.props.className + " " : "") + Styles.item |
Samuel Shuert | 8aac601 | 2021-09-02 13:21:30 -0500 | [diff] [blame] | 15 | |
Skyler Turner | f536121 | 2021-09-14 20:33:58 +0100 | [diff] [blame] | 16 | const key = index; |
Samuel Shuert | 8aac601 | 2021-09-02 13:21:30 -0500 | [diff] [blame] | 17 | |
Skyler Turner | f536121 | 2021-09-14 20:33:58 +0100 | [diff] [blame] | 18 | const props = { |
| 19 | className, |
| 20 | key |
| 21 | } |
| 22 | |
| 23 | return cloneElement(item, props); |
| 24 | } else { |
| 25 | return <div className={Styles.item + " " + Styles.fitItemWidth} key={index}>{item}</div>; |
| 26 | } |
| 27 | }) |
| 28 | } |
| 29 | </div> |
| 30 | ) |
| 31 | } |
Samuel Shuert | 8aac601 | 2021-09-02 13:21:30 -0500 | [diff] [blame] | 32 | } |
Skyler Turner | f536121 | 2021-09-14 20:33:58 +0100 | [diff] [blame] | 33 | export default TileRow; |