Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build a table component #17 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/components/Table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import { FaCheckCircle, FaTimesCircle, FaMinusCircle } from 'react-icons/fa';
import { images } from '../assets';

const sampleImages = [images.AJP_0002, images.AJP_0106, images.AJP_0178, images.AJP_0285]


const winDrawLooseMap = {
1: (<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>),
2: (<FaMinusCircle
color='grey'
style={{
marginRight: '5px'
}}
size={18}
/>),
3: (<FaTimesCircle
color='red'
style={{
marginRight: '5px'
}}
size={18}
/>)
}



const SmallLogoIconImage = () => {
return (
<img
src={sampleImages[Math.floor(Math.random() * sampleImages.length)]}
alt=''
width={17}
height={17}
style={{
marginRight: '2px',
borderRadius: 50
}}
/>
)
}
/**
* Given a json data, i.e and array of objects
* @returns a table taking the keys of the objects as table headers and values as the rows
*/

const THead = ({ headers }) => (<thead><tr>{headers.map(header => (<th scope="col">{header.replaceAll('_', ' ')}</th>))}</tr></thead>);

const TBody = ({ data }) => (
<tbody>
{data.map(dta => (
<tr>
{Object.keys(dta).map(key => {
switch (key) {
case 'Club':
return <th> <SmallLogoIconImage /> {dta[key]} </th>;
case 'Last_5_Matches':
return <td> {dta[key].map(match => winDrawLooseMap[match])}</td>;
default:
return (<td>{dta[key]}</td>);
}
})}
</tr>))}
</tbody>);

const Table = (props) => {
const headers = Object.keys(props.data[0] || {});
return (
<table className="table">
<THead headers={headers} />
<TBody {...props} />
</table>
)

}

export default Table
282 changes: 52 additions & 230 deletions src/containers/Sports/components/standing-table.js
Original file line number Diff line number Diff line change
@@ -1,239 +1,61 @@
import React from 'react';
import { FaCheckCircle, FaTimesCircle, FaMinusCircle } from 'react-icons/fa';
import { images } from '../../../assets';
import Table from '../../../components/Table';

const sampleImages = [images.AJP_0002, images.AJP_0106, images.AJP_0178, images.AJP_0285]
const data = [
{
Club: 'Cheles',
MP: 6,
W: 5,
D: 0,
L: 1,
GF: 20,
GA: 6,
GD: 14,
Points: 15,
Last_5_Matches: [1, 2, 3, 2, 1],
},
{
Club: 'Kapsowar',
MP: 6,
W: 5,
D: 0,
L: 1,
GF: 20,
GA: 6,
GD: 14,
Points: 15,
Last_5_Matches: [1, 2, 3, 2, 1],
},
{
Club: 'Kiplabai',
MP: 6,
W: 5,
D: 0,
L: 1,
GF: 20,
GA: 6,
GD: 14,
Points: 15,
Last_5_Matches: [1, 2, 3, 2, 1],
},
{
Club: 'Kapchesewes',
MP: 6,
W: 5,
D: 0,
L: 1,
GF: 20,
GA: 6,
GD: 14,
Points: 15,
Last_5_Matches: [1, 2, 3, 2, 1],
},
];

const SmallLogoIconImage = () => {
return (
<img
src={sampleImages[Math.floor(Math.random() * sampleImages.length)]}
alt=''
width={17}
height={17}
style={{
marginRight: '2px',
borderRadius: 50
}}
/>
)
}

const StandingTable = () => {
return (
<table className="table">
<thead>
<tr>
<th scope="col">Club</th>
<th scope="col">MP</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">Points</th>
<th scope="col">Last 5 Matches</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
<SmallLogoIconImage />
Cheles
</th>
<td>6</td>
<td>5</td>
<td>0</td>
<td>1</td>
<td>20</td>
<td>6</td>
<td>14</td>
<td>15</td>
<td>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaTimesCircle
color='red'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaMinusCircle
color='grey'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
</td>
</tr>
<tr>
<th scope="row"><SmallLogoIconImage /> Kapsowar</th>
<td>6</td>
<td>5</td>
<td>0</td>
<td>1</td>
<td>20</td>
<td>6</td>
<td>14</td>
<td>15</td>
<td>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaTimesCircle
color='red'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaMinusCircle
color='grey'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
</td>
</tr>
<tr>
<th scope="row"><SmallLogoIconImage /> Kiplabai</th>
<td>6</td>
<td>5</td>
<td>0</td>
<td>1</td>
<td>20</td>
<td>6</td>
<td>14</td>
<td>15</td>
<td>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaTimesCircle
color='red'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaMinusCircle
color='grey'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
</td>
</tr>
<tr>
<th scope="row"><SmallLogoIconImage /> Kapchesewes</th>
<td>6</td>
<td>5</td>
<td>0</td>
<td>1</td>
<td>20</td>
<td>6</td>
<td>14</td>
<td>15</td>
<td>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaTimesCircle
color='red'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaMinusCircle
color='grey'
style={{
marginRight: '5px'
}}
size={18}
/>
<FaCheckCircle
color='green'
style={{
marginRight: '5px'
}}
size={18}
/>
</td>
</tr>
</tbody>
</table>
<Table data={data} />
)
}

Expand Down