1- import React , { Component } from 'react'
2- import glam , { Div } from 'glamorous'
3- import './css/ResultTable.css'
4- import Seperator from './Seperator'
5-
6- const ReceiptRow = glam . div ( {
7- display : 'flex' ,
8- flexDirection : 'row' ,
9- justifyContent : 'space-between' ,
10- height : 35 ,
11- color : '#4D4D5C' ,
12- fontFamily : 'PT Sans' ,
13- fontSize : 15 ,
14- } )
15- const LeftColumn = glam . div ( {
16- textAlign : 'left' ,
17- } )
18- const RightColumn = glam . div ( {
19- textAlign : 'right' ,
20- } )
1+ import React , { Component } from "react"
2+ import { Div } from "glamorous"
3+ import "./css/ResultTable.css"
4+ import Seperator from "./Seperator"
5+ import { Link } from 'react-router-dom'
6+ import {
7+ TableStyle ,
8+ FlexSpacingRow ,
9+ LeftColumn ,
10+ RightColumn ,
11+ } from "../atoms/SharedStyles"
2112
2213const HeaderRow = ( { header } ) => {
2314 const { name, value, color } = header
2415 return (
25- < ReceiptRow
16+ < FlexSpacingRow
2617 css = { {
2718 color : color ,
2819 fontSize : 18 ,
@@ -31,23 +22,31 @@ const HeaderRow = ({ header }) => {
3122 >
3223 < LeftColumn > { name } </ LeftColumn >
3324 < RightColumn > { value } </ RightColumn >
34- </ ReceiptRow >
25+ </ FlexSpacingRow >
3526 )
3627}
3728
3829export const RowDivs = ( { rows } ) => {
3930 const rowDivs = [ ]
40- rows . forEach ( ( { name, value } , index ) => {
31+ rows . forEach ( ( { name, value, linkTo , url } , index ) => {
4132 let seperator = undefined
4233 if ( index < rows . length - 1 ) {
4334 seperator = < Seperator />
4435 }
36+ let rightColumn = value => {
37+ if ( linkTo ) {
38+ return < RightColumn > { < Link to = { linkTo } > { value } </ Link > } </ RightColumn >
39+ } else if ( url ) {
40+ return < RightColumn > { < a href = { url } target = 'blank' > { value } </ a > } </ RightColumn >
41+ }
42+ return < RightColumn > { value } </ RightColumn >
43+ }
4544 rowDivs . push (
4645 < Div key = { name } >
47- < ReceiptRow >
46+ < FlexSpacingRow >
4847 < LeftColumn > { name } </ LeftColumn >
49- < RightColumn > { value } </ RightColumn >
50- </ ReceiptRow >
48+ { rightColumn ( value ) }
49+ </ FlexSpacingRow >
5150 { seperator }
5251 </ Div > ,
5352 )
@@ -57,19 +56,13 @@ export const RowDivs = ({ rows }) => {
5756}
5857
5958class ResultTable extends Component {
60- constructor ( { header, rows } ) {
61- super ( )
62- this . state = {
63- header,
64- rows,
65- }
66- }
6759 render ( ) {
60+ const { header, rows } = this . props
6861 return (
69- < Div className = "result-table" >
70- < HeaderRow header = { this . state . header } />
71- < RowDivs rows = { this . state . rows } />
72- </ Div >
62+ < TableStyle >
63+ < HeaderRow header = { header } />
64+ < RowDivs rows = { rows } />
65+ </ TableStyle >
7366 )
7467 }
7568}
0 commit comments