mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
* commented out lesson and learning strip until lessons are established * reword the hero section * change layout and working on puzzle section - remove top div as it was redundant * amend flash message on replay * switch cancel session for return home * remove system theme toggle since this is the default, leaving only light and dark toggles * add keyboard and screen reader support for play (#72) First draft covering the accessibility work in #72:\n\n- labelled SAN/UCI move input, validated against the tablebase and applied\n by the board hook, plus an accessible promotion picker\n- live-region announcements for moves, checks, checkmates and solve/fail,\n and a hidden text summary of the position\n- accessible labels, focus ring, skip link, keyboard-friendly review table\n and non-colour grade cues\n- WCAG AA text contrast roles and a responsive play surface\n- regression tests for move entry, announcements and link-style CTAs
71 lines
1.7 KiB
Elixir
71 lines
1.7 KiB
Elixir
defmodule ChesstrainerWeb.Board.BoardComponent do
|
|
@moduledoc """
|
|
Chess board component
|
|
"""
|
|
|
|
use Phoenix.Component
|
|
import ChesstrainerWeb.Board.SquareComponent
|
|
|
|
alias ChesstrainerWeb.Board.PositionText
|
|
|
|
attr :game, :map, required: true
|
|
|
|
attr :myself, :any, default: nil
|
|
|
|
attr :interactive, :boolean,
|
|
default: true,
|
|
doc: "emit square-click events (only useful inside a board LiveView)"
|
|
|
|
attr :class, :string,
|
|
default: "w-[388px] mt-6",
|
|
doc: "sizing and spacing for the board wrapper"
|
|
|
|
def board(assigns) do
|
|
files_list = [:a, :b, :c, :d, :e, :f, :g, :h]
|
|
|
|
assigns =
|
|
assigns
|
|
|> assign(:files_list, files_list)
|
|
|> assign(
|
|
:files,
|
|
case assigns.game.orientation do
|
|
:white -> files_list
|
|
:black -> Enum.reverse(files_list)
|
|
end
|
|
)
|
|
|> assign(
|
|
:ranks,
|
|
case assigns.game.orientation do
|
|
:white -> Enum.reverse(1..8)
|
|
:black -> 1..8
|
|
end
|
|
)
|
|
|
|
~H"""
|
|
<div class={["m-auto left-0 right-0", @class]}>
|
|
<div
|
|
class="border border-2 border-zinc-700 grid grid-rows-8 grid-cols-8"
|
|
role="img"
|
|
aria-label={"Chess position. #{PositionText.summary(Map.get(@game, :fen))}"}
|
|
>
|
|
<%= for rank <- @ranks do %>
|
|
<%= for file <- @files do %>
|
|
<% square = {file, rank} %>
|
|
<% piece = Map.get(@game.board, square) %>
|
|
<.square
|
|
file={file}
|
|
rank={rank}
|
|
piece={piece}
|
|
files_list={@files_list}
|
|
move_from_square={@game.move_from_square}
|
|
myself={@myself}
|
|
interactive={@interactive}
|
|
/>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
"""
|
|
end
|
|
end
|