index.js (1799B)
1 import React from 'react'; 2 import PropTypes from 'prop-types'; 3 import styles from './styles.module.css'; 4 5 export class CalcOut extends React.Component { 6 render() { 7 if (this.props.mode === 'basic') { 8 return ( 9 <div className={styles.basicOut}> 10 <div className={styles.h1}>{this.props.output}</div> 11 <div className={styles.h3}>{this.props.input}</div> 12 </div> 13 ); 14 } else if (this.props.mode === 'select') { 15 return ( 16 <div className={styles.selectOut}> 17 <span className={styles.h2}>Mode Select</span> 18 </div> 19 ); 20 } else { 21 if (typeof this.props.output !== 'object') { 22 return ( 23 <div className={styles.out}> 24 <span className={styles.h2}>{this.props.output}</span> 25 </div> 26 ); 27 } else { 28 let outputBreaks = []; 29 for (let i = 0; i < this.props.output.length; i++) { 30 if (i + 1 === this.props.output.length) { 31 outputBreaks.push(this.props.output[i]) 32 } else { 33 outputBreaks.push(this.props.output[i], <br />) 34 } 35 } 36 return ( 37 <div className={styles.out}> 38 <span className={styles.h2}>{outputBreaks}</span> 39 </div> 40 ); 41 } 42 } 43 } 44 } 45 46 CalcOut.propTypes = { 47 mode: PropTypes.string.isRequired, 48 output: PropTypes.oneOfType([ 49 PropTypes.string, 50 PropTypes.number, 51 PropTypes.array 52 ]), 53 input: PropTypes.string 54 };