From 897148e47f00b9bcfea82aab18513a8b426442eb Mon Sep 17 00:00:00 2001 From: aleidk Date: Sat, 9 Sep 2023 12:55:41 -0300 Subject: [PATCH] add basic table to games page --- src/assets/style/global.css | 8 ++++++ src/components/Table.tsx | 46 ++++++++++++++++++++++++++++++++++ src/pages/games/index.astro | 49 +++++++++++++++++++++++++++++-------- 3 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 src/components/Table.tsx diff --git a/src/assets/style/global.css b/src/assets/style/global.css index fe97efb..faf6162 100644 --- a/src/assets/style/global.css +++ b/src/assets/style/global.css @@ -60,3 +60,11 @@ ul { li:not(:last-child) { margin-bottom: var(--prj-spacing-1); } + +/* TODO: Move to where it belogns */ +th, +td { + padding: 0.25rem 1rem; + border: 1px solid white; + text-align: center; +} diff --git a/src/components/Table.tsx b/src/components/Table.tsx new file mode 100644 index 0000000..1fb046a --- /dev/null +++ b/src/components/Table.tsx @@ -0,0 +1,46 @@ +import React from 'react'; + +type DataItem = Record; + +export interface Header { + key: string; + header: string; + formatter?: (data: DataItem) => JSX.ElementType; +} + +interface Props { + data: DataItem[]; + headers: Header[]; +} + +export default function Table({ data, headers }: Props): JSX.Element { + function getProperty(data: DataItem, header: Header): any { + if (header.key === 'index') { + return 'index'; + } + + return data[header.key]; + } + + return ( + + + + {headers.map((item, idx) => ( + + ))} + + + + + {data.map((item, idx) => ( + + {headers.map((header, hidx) => ( + + ))} + + ))} + +
{item.header}
{getProperty(item.data, header)}
+ ); +} diff --git a/src/pages/games/index.astro b/src/pages/games/index.astro index c101c93..6078628 100644 --- a/src/pages/games/index.astro +++ b/src/pages/games/index.astro @@ -1,20 +1,49 @@ --- -import Layout from '../../layouts/Layout.astro'; import { getCollection } from 'astro:content'; +import Layout from '../../layouts/Layout.astro'; +import Table, { Header } from '../../components/Table.jsx'; const games = await getCollection('games'); + +const headers: Header[] = [ + { + key: 'index', + }, + { + key: 'title', + header: 'Title', + }, + { + key: 'status', + header: 'Status', + }, + { + key: 'times_played', + header: 'Times Played', + }, + { + key: 'registered_hours', + header: 'Registered Hours', + }, +]; ---

Games

- +
+ + + +
+ +