feat: add table styling and components

This commit is contained in:
sirlolcat 2022-06-07 00:40:42 +04:30
parent bc7f5deea8
commit c12f213cd0
4 changed files with 87 additions and 106 deletions

View File

@ -9,7 +9,7 @@ function App(): JSX.Element {
padding: 0; padding: 0;
} }
html, body { html, body {
background-color: RGB(132, 151, 149); background-color: RGB(255, 255, 253);
color: RGB(227, 226, 215); color: RGB(227, 226, 215);
width: 100%; width: 100%;
height: 100%; height: 100%;

View File

@ -1,66 +1,23 @@
import { useMemo } from "react";
import styled from "styled-components"; import styled from "styled-components";
import useAllItems from "../hooks/useAllItems";
import ItemsTable from './ItemsTable'; import ItemsTable from './ItemsTable';
import Button from './Button'; import Button from './Button';
import useTableController from "../hooks/useTableController";
function ItemsSection(): JSX.Element { function ItemsSection(): JSX.Element {
const ItemsSection = styled.section` const ItemsSection = styled.section`
height: 85vh; height: 100vh;
ul { display: flex;
display: flex; flex-flow: column wrap;
flex-direction: row; justify-content: center;
flex-wrap: wrap; margin: 0 5%;
width: 100%; role: 'region';
height: 100%;
color: white;
justify-content: center;
align-items: center;
}
li {
list-style: none;
display: inline-block;
height: 10%;
width: 40%;
border: 1px solid white;
margin: 3% 3%;
}
`; `;
const { items } = useAllItems(); const { columns, data } = useTableController();
const data = useMemo(() => items, [items]);
const columns = useMemo(() => [
{
Header: "Details",
columns: [
{
Header: 'Name',
accessor: 'name',
},
{
Header: 'Conjured',
accessor: 'isConjured'
}
],
},
{
Header: "Item Info",
columns: [
{
Header: 'Quality',
accessor: 'quality'
},
{
Header: 'Days Left',
accessor: 'sellIn'
}
],
}
], []);
return ( return (
<ItemsSection> <ItemsSection>
<ItemsTable columns={columns} data={data}/> <ItemsTable columns={columns} data={data} />
<Button /> <Button />
</ItemsSection> </ItemsSection>
); );

View File

@ -3,25 +3,37 @@ import styled from "styled-components";
import { TTable } from "../types"; import { TTable } from "../types";
function ItemTable({ columns, data }: TTable): JSX.Element { function ItemTable({ columns, data }: TTable): JSX.Element {
const ItemsSection = styled.section` const ItemsTable = styled.table`
height: 85vh; @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;500&family=Ubuntu:wght@300;400;500&display=swap');
ul { height: 60%;
display: flex; border: 1px solid RGB(12, 16, 36);
flex-direction: row; border-radius: 10px;
flex-wrap: wrap; min-height: 30%;
width: 100%; color: RGB(12, 16, 36);
height: 100%; th, td, tr {
color: white; font-family: 'Roboto', sans-serif;
justify-content: center; outline: none;
align-items: center; border: none;
border-collapse: collapse;
text-align: center;
font-size: 1.2rem;
} }
li {
list-style: none;
display: inline-block; th {
height: 10%; font-weight: 300;
width: 40%; }
border: 1px solid white;
margin: 3% 3%; tr {
font-weight: 100;
}
tr:nth-child(n):hover {
background-color: #f2f2f2;
}
tr:nth-child(2n + 1) {
background-color: RGB(245, 245, 243);
} }
`; `;
const { const {
@ -36,10 +48,9 @@ function ItemTable({ columns, data }: TTable): JSX.Element {
}); });
return ( return (
<ItemsTable {...getTableProps()}>
<table {...getTableProps()} style={{ border: 'solid 1px blue' }}> <thead className="header">
<thead>
{headerGroups.map(headerGroup => ( {headerGroups.map(headerGroup => (
@ -47,27 +58,9 @@ function ItemTable({ columns, data }: TTable): JSX.Element {
{headerGroup.headers.map(column => ( {headerGroup.headers.map(column => (
<th <th {...column.getHeaderProps()}>
{...column.getHeaderProps()}
style={{
borderBottom: 'solid 3px red',
background: 'aliceblue',
color: 'black',
fontWeight: 'bold',
}}
>
{column.render('Header')} {column.render('Header')}
</th>
</th>
))} ))}
@ -95,15 +88,6 @@ function ItemTable({ columns, data }: TTable): JSX.Element {
{...cell.getCellProps()} {...cell.getCellProps()}
style={{
padding: '10px',
border: 'solid 1px gray',
background: 'papayawhip',
}}
> >
@ -123,8 +107,7 @@ function ItemTable({ columns, data }: TTable): JSX.Element {
</tbody> </tbody>
</table> </ItemsTable>
) )
} }

View File

@ -0,0 +1,41 @@
import { useMemo } from "react";
import { useStore } from "../model";
import { TTable } from "../types";
function useTableController(): TTable {
const { state } = useStore();
const { items } = state;
const data = useMemo(() => items, [items]);
const columns = useMemo(() => [
{
Header: "Items",
columns: [
{
Header: 'Name',
accessor: 'name',
},
{
Header: 'Conjured',
accessor: 'isConjured',
Cell: ({ cell: { value } }: any) => { return value ? 'Yes' : 'No' },
},
{
Header: 'Quality',
accessor: 'quality'
},
{
Header: 'Days Left',
accessor: 'sellIn'
}
],
},
], []);
return {
columns,
data
}
}
export default useTableController;