css variables

This commit is contained in:
Vinzenz Schroeter 2024-04-14 12:57:45 +02:00
parent ae1d24e28e
commit cd3c054ee8
17 changed files with 96 additions and 111 deletions

View file

@ -1,4 +1,4 @@
.GadgetRows { .GadgetRows {
justify-content: space-evenly; justify-content: space-evenly;
margin-top: 24px; margin-top: calc(4 * var(--padding-normal));
} }

View file

@ -29,11 +29,14 @@ export default function App() {
setLoggedIn(result !== null); setLoggedIn(result !== null);
}, [nameId, isLoggedIn])(); }, [nameId, isLoggedIn])();
return <Column className='grow'> return <Column className='flex-grow'>
<Row> <Row>
<h1 className='grow'>Tanks!</h1> <h1 className='flex-grow'>CCCB-Tanks!</h1>
<Button
onClick={() => window.open('https://github.com/kaesaecracker/cccb-tanks-cs', '_blank')?.focus()}
text='GitHub'/>
{nameId.name !== '' && {nameId.name !== '' &&
<Button className='PlayerInfo-Reset' onClick={() => setNameId(getNewNameId)} text='logout'/>} <Button onClick={() => setNameId(getNewNameId)} text='logout'/>}
</Row> </Row>
<ClientScreen logout={logout}/> <ClientScreen logout={logout}/>
{nameId.name === '' && <JoinForm setNameId={setNameId} clientId={nameId.id}/>} {nameId.name === '' && <JoinForm setNameId={setNameId} clientId={nameId.id}/>}

View file

@ -1,65 +1,30 @@
.Controls * { .Controls {
display: flex;
text-align: center;
flex-grow: 1;
}
.Controls-Container {
box-sizing: content-box; box-sizing: content-box;
justify-content: center;
align-items: center;
gap: var(--padding-normal);
} }
kbd { kbd {
background: hsl(0, 0%, 96%); --kbd-key-size: 2em;
padding: 10px;
background: var(--color-secondary);
padding: var(--padding-normal);
display: block; display: block;
margin: 5px; width: var(--kbd-key-size);
width: 1.6em; height: var(--kbd-key-size);
height: 1.3em;
text-align: center; text-align: center;
box-shadow: 0 1px rgba(0, 0, 0, .21);
user-select: none; user-select: none;
color: black; color: black;
} }
kbd.up {
margin-left: calc(1.6em + 35px);
}
kbd.space { kbd.space {
margin-top: calc(1.3em + 35px); width: calc(3 * var(--kbd-key-size) + 2 * var(--padding-normal));
width: 14em;
}
kbd:active {
position: relative;
top: 2px;
background: hsl(0, 0%, 94%);
box-shadow: 0 1px rgba(0, 0, 0, .13) inset;
}
.Controls {
display: flex;
color: lightgray;
text-align: center;
align-items: center !important;
}
.control {
margin: 0 1em;
}
.row {
display: flex;
}
.splash {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: radial-gradient(transparent, red);
opacity: 0;
pointer-events: none;
transition: opacity 500ms;
}
.was-killed .splash {
opacity: 1;
transition: opacity 120ms;
} }

View file

@ -60,20 +60,19 @@ export default function Controls({playerId, logout}: {
}, [sendMessage]); }, [sendMessage]);
return <Column className="Controls"> return <Column className="Controls">
<div className="control"> <div className='flex-column Controls-Container'>
<div className="row"> <h3>Move</h3>
<kbd className="up"></kbd> <kbd></kbd>
</div> <div className='flex-row Controls-Container'>
<div className="row">
<kbd></kbd> <kbd></kbd>
<kbd></kbd> <kbd></kbd>
<kbd></kbd> <kbd></kbd>
</div> </div>
</div> </div>
<h3>Move</h3>
<kbd className="space control">Space</kbd> <div className='flex-column Controls-Container'>
<h3>Fire</h3>
<h3>Fire</h3> <kbd className="space">Space</kbd>
</div>
</Column>; </Column>;
} }

View file

@ -2,28 +2,28 @@
@keyframes BlinkJoinForm { @keyframes BlinkJoinForm {
from { from {
font-weight: normal; font-weight: normal;
border-color: rgb(76, 76, 76); border-color: var(--color-secondary);
} }
50% { 50% {
border-color: black; border-color: var(--color-background);
} }
to { to {
font-weight: bold; font-weight: bold;
border-color: green; border-color: var(--color-primary);
} }
} }
.JoinForm { .JoinForm {
border: 8px solid rgb(76, 76, 76); border: solid var(--border-size-thick) var(--color-secondary);
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
background: black; background: var(--color-background);
gap: 16px; gap: 16px;
padding: 16px; padding: 16px;

View file

@ -1,5 +0,0 @@
.Elems {
padding: 8px 8px;
margin: 8px 8px;
}

View file

@ -1,5 +1,4 @@
import {useEffect, useState} from 'react'; import {useEffect, useState} from 'react';
import './PlayerInfo.css'
import {PlayerResponse, getPlayer} from './serverCalls'; import {PlayerResponse, getPlayer} from './serverCalls';
import {Guid} from "./Guid.ts"; import {Guid} from "./Guid.ts";
import Column from "./components/Column.tsx"; import Column from "./components/Column.tsx";
@ -24,7 +23,7 @@ export default function PlayerInfo({playerId, logout}: {
return () => clearInterval(timer); return () => clearInterval(timer);
}, [playerId]); }, [playerId]);
return <Column className='PlayerInfo'> return <Column className='PlayerInfo flex-grow'>
<h3> <h3>
{player ? `Playing as ${player?.name}` : 'loading...'} {player ? `Playing as ${player?.name}` : 'loading...'}
</h3> </h3>

View file

@ -17,10 +17,13 @@ export default function Scoreboard({}: {}) {
return () => clearInterval(timer); return () => clearInterval(timer);
}, [players]); }, [players]);
return <DataTable<PlayerResponse> data={players} columns={[ return <DataTable
{field: 'name'}, data={players}
{field: 'kills', visualize: p => p.scores.kills}, className='flex-grow'
{field: 'deaths', visualize: p => p.scores.deaths}, columns={[
{field: 'k/d', visualize: p => p.scores.kills / p.scores.deaths} {field: 'name'},
]}/> {field: 'kills', visualize: p => p.scores.kills},
{field: 'deaths', visualize: p => p.scores.deaths},
{field: 'k/d', visualize: p => p.scores.kills / p.scores.deaths}
]}/>
} }

View file

@ -1,14 +1,13 @@
.Button { .Button {
border: solid 4px green; border: solid var(--border-size-thin) var(--color-primary);
padding: 8px; padding: var(--padding-normal);
color: green; color: var(--color-primary);
background: transparent; background: var(--color-background);
} }
.Button:hover, .Button:active { .Button:hover, .Button:active {
background-color: green; background-color: var(--color-primary);
color: black; color: var(--color-background);
cursor: pointer; cursor: pointer;
} }

View file

@ -1,7 +1,5 @@
.Column { .Column {
display: flex;
flex-direction: column;
max-height: 100%; max-height: 100%;
align-items: stretch; align-items: stretch;
gap: 8px; gap: var(--padding-normal);
} }

View file

@ -6,7 +6,7 @@ export default function Column({children, className}: {
children: ReactNode, children: ReactNode,
className?: string className?: string
}) { }) {
return <div className={'Column ' + (className ?? '')}> return <div className={'Column flex-column ' + (className ?? '')}>
{children} {children}
</div> </div>
} }

View file

@ -1,3 +1,3 @@
.DataTable { .DataTable > table {
table-layout: auto; table-layout: auto;
} }

View file

@ -39,14 +39,17 @@ function DataTableRow({rowData, columns}: {
</tr>; </tr>;
} }
export default function DataTable<T>({data, columns}: { export default function DataTable<T>({data, columns, className}: {
data: T[], data: T[],
columns: DataTableColumnDefinition<any>[] columns: DataTableColumnDefinition<any>[],
className?: string
}) { }) {
return <table className='DataTable'> return <div className={'DataTable ' + (className ?? '')}>
<TableHead columns={columns}/> <table>
<tbody> <TableHead columns={columns}/>
{data.map((element, index) => <DataTableRow key={index} rowData={element} columns={columns}/>)} <tbody>
</tbody> {data.map((element, index) => <DataTableRow key={index} rowData={element} columns={columns}/>)}
</table> </tbody>
</table>
</div>;
} }

View file

@ -1,7 +1,5 @@
.Row { .Row {
display: flex;
flex-direction: row;
max-width: 100%; max-width: 100%;
align-items: stretch; align-items: stretch;
gap: 8px; gap: var(--padding-normal);
} }

View file

@ -3,7 +3,7 @@ import {ReactNode} from "react";
import './Row.css'; import './Row.css';
export default function Row({children, className}: { children: ReactNode, className?: string }) { export default function Row({children, className}: { children: ReactNode, className?: string }) {
return <div className={'Row ' + (className ?? '')}> return <div className={'Row flex-row ' + (className ?? '')}>
{children} {children}
</div> </div>
} }

View file

@ -1,3 +1,3 @@
.TextInput { .TextInput {
padding: 8px; padding: var(--padding-normal);
} }

View file

@ -12,6 +12,18 @@
text-transform: uppercase; text-transform: uppercase;
} }
:root {
--color-background: black;
--color-primary: green;
--color-secondary: rgb(76, 76, 76);
--color-text: white;
--border-size-thin: 4px;
--border-size-thick: 8px;
--padding-normal: 8px;
}
html, body { html, body {
height: 100%; height: 100%;
@ -20,8 +32,8 @@ html, body {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background-color: black; background-color: var(--color-background);
color: white; color: var(--color-text);
} }
#root { #root {
@ -32,6 +44,17 @@ html, body {
height: 95vh; height: 95vh;
} }
.grow { .flex-grow {
display: flex;
flex-grow: 1; flex-grow: 1;
} }
.flex-column {
display: flex;
flex-direction: column;
}
.flex-row {
display: flex;
flex-direction: row;
}