1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Clean up moves display

This commit is contained in:
Daniel Barber 2018-05-11 15:51:05 -04:00
parent 950e7a86f1
commit 6243259d27
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
15 changed files with 102 additions and 31 deletions

View File

@ -1,13 +1,3 @@
:root {
--board-size: 90vmin;
}
@media (min-aspect-ratio: 10/11) {
:root {
--board-size: 80vmin;
}
}
@mixin move-indicator {
border-radius: 50%;
content: "";
@ -25,6 +15,7 @@
border-spacing: 1px;
box-shadow: 0 calc(var(--board-size) / 200) calc(var(--board-size) / 40) $board-shadow-color;
color: $white-square-color;
grid-area: board;
height: var(--board-size);
padding: calc(var(--board-size) / 20);
position: relative;

View File

@ -0,0 +1,7 @@
.game-grid {
display: grid;
grid-gap: $base-spacing;
grid-template-areas: "board moves";
grid-template-columns: min-content 1fr;
grid-template-rows: var(--board-size);
}

View File

@ -6,6 +6,6 @@
}
.your-turn {
font-weight: bold;
background-color: $your-turn-background-color;
font-weight: bold;
}

View File

@ -0,0 +1,6 @@
.heading {
font-family: $heading-font-family;
font-size: modular-scale(1);
line-height: $heading-line-height;
margin: 0 0 $small-spacing;
}

View File

@ -1,6 +1,7 @@
html {
background: $background-color;
color: mix($background-color, $foreground-color, 20%);
font-weight: 300;
}
a {
@ -11,7 +12,6 @@ h1,
h2,
h3,
h4 {
font-variant: small-caps;
font-weight: 300;
}

View File

@ -0,0 +1,16 @@
.move-list {
grid-area: moves;
overflow-y: auto;
}
.move-list__line-number {
color: mix($background-color, $foreground-color);
font-variant-numeric: tabular-nums;
font-feature-settings: "tnum";
}
.move-list__header--white,
.move-list__move--white,
.move-list__line-number {
text-align: right;
}

16
assets/css/_tables.scss Normal file
View File

@ -0,0 +1,16 @@
.table--condensed {
width: auto;
caption {
text-align: left;
}
tr {
border: 0;
}
th,
td {
padding: 0 $base-spacing 0 0;
}
}

View File

@ -0,0 +1,3 @@
.visually-hidden {
display: none;
}

View File

@ -28,3 +28,14 @@ $available-outline-color: rgba(lighten($available-square-color, 20%), 0.5);
$colours: "black" "white";
$pieces: king queen bishop knight rook pawn;
:root {
--board-size: 90vmin;
}
@media (min-aspect-ratio: 10/11) {
:root {
--board-size: 80vmin;
}
}

View File

@ -1,11 +1,18 @@
@import "bourbon/bourbon";
@import "base/base";
@import "vendor/family";
@import "base/base";
@import "variables";
@import "utilities";
@import "tables";
@import "headings";
@import "layout";
@import "nav";
@import "game_list";
@import "board";
@import "move_list";
@import "game_grid";

View File

@ -1,6 +1,5 @@
table {
border-collapse: collapse;
margin: $base-spacing 0;
table-layout: fixed;
text-align: left;
width: 100%;

View File

@ -35,7 +35,7 @@ class App extends React.Component {
const { store, gameId } = this.props;
return (
<div>
<div className="game-grid">
<ChessBoard
gameId={gameId}
store={store}

View File

@ -1,6 +1,7 @@
import React from "react";
import { connect } from "react-redux";
import _ from "lodash";
import { connect } from "react-redux";
import classNames from "classnames";
const pieceToNotation = (piece) => {
const pieces = {
@ -15,10 +16,14 @@ const pieceToNotation = (piece) => {
return pieces[piece.type];
};
const moveClass = (move) => {
return classNames("move-list__move", "move-list__move--" + move.piece.colour);
}
const renderMove = (move) => {
if (move != undefined) {
return (
<td className="move">
<td className={moveClass(move)}>
{pieceToNotation(move.piece)}
{move.piece_captured ? "x" : ""}
{move.to}
@ -28,9 +33,12 @@ const renderMove = (move) => {
};
const renderMoves = (moves) => {
let lineNumber = 1;
return _.map(moves, (move) => {
return (
<tr key={move[0].id}>
<th scope="row" className="move-list__line-number">{lineNumber++}.</th>
{renderMove(move[0])}
{renderMove(move[1])}
</tr>
@ -40,17 +48,26 @@ const renderMoves = (moves) => {
const MoveList = (props) => {
return (
<table className="move-list">
<div className="move-list">
<table className="table table--condensed">
<caption className="heading">Moves</caption>
<thead>
<tr>
<th>White</th>
<th>Black</th>
<th className="move-list__line-number">
<span className="visually-hidden">Move no.</span>
</th>
<th className="move-list__header--white">White</th>
<th className="move-list__header--black">Black</th>
</tr>
</thead>
<tbody>
{renderMoves(props.moves)}
</tbody>
</table>
</div>
);
};

View File

@ -1,6 +1,6 @@
<h2><%= gettext "Listing games" %></h2>
<table class="table">
<table class="table table--games-list">
<tbody>
<%= for game <- @games do %>
<tr class="<%= turn_class(@conn, game) %>">

View File

@ -1,5 +1,3 @@
<p><%= link gettext("Back to games"), to: game_path(@conn, :index) %></p>
<h2><%= gettext "Game with %{name}", name: opponent(@conn, @game).name %></h2>
<div id="app" data-game-id="<%= @game.id %>">