defmodule ChesstrainerWeb.LandingComponents do
@moduledoc """
Presentational primitives for the marketing landing page.
Kept separate from `ChesstrainerWeb.CoreComponents`: the landing page uses a
distinct pill-button language, while CoreComponents provides the compact
admin and auth UI.
"""
use Phoenix.Component
import Phoenix.Controller, only: [get_csrf_token: 0]
alias Chesstrainer.FEN
alias Chesstrainer.Themes
alias ChesstrainerWeb.Board.PositionText
@button_variants %{
nav: "nav-cta",
primary: "primary-button",
light: "light-button"
}
@files ~w(a b c d e f g h)
@piece_glyphs %{
"K" => "♔",
"Q" => "♕",
"R" => "♖",
"B" => "♗",
"N" => "♘",
"P" => "♙",
"k" => "♚",
"q" => "♛",
"r" => "♜",
"b" => "♝",
"n" => "♞",
"p" => "♟"
}
@fallback_fen "8/5k2/8/3K4/8/6R1/8/8 w - - 0 1"
@doc """
Renders a landing-page pill button.
Renders a link when given `href`, `navigate`, or `patch`; otherwise a button.
## Examples
<.pill_button variant={:nav} href="/#trainer">Start training
<.pill_button variant={:primary} phx-click="go">Go
"""
attr :rest, :global, include: ~w(href navigate patch method type disabled)
attr :variant, :atom, values: [:nav, :primary, :light], default: :nav
attr :class, :any, default: nil
slot :inner_block, required: true
def pill_button(%{rest: rest} = assigns) do
assigns =
assign(assigns, :class, [Map.fetch!(@button_variants, assigns.variant), assigns.class])
if rest[:href] || rest[:navigate] || rest[:patch] do
~H"""
<.link class={@class} {@rest}>
{render_slot(@inner_block)}
"""
else
~H"""
"""
end
end
@doc """
Renders the mailing-list signup band.
The form posts to `POST /mailing-list` and the controller redirects back to
the `#mailing-list` anchor with a flash. Keeping it a plain form means the
landing page needs no LiveView to collect an address.
"""
def mailing_list_signup(assigns) do
~H"""
Mailing list
Stay in the loop.
Get occasional endgame ideas, new puzzles, and feature updates delivered to your inbox. (Please confirm your email after signing up.)
"""
end
@doc """
Renders a static board preview for the landing page.
Accepts an endgame map with `:fen`, `:color` and `:key`; falls back to a
neutral position when no endgame is given. For an interactive board inside a
LiveView, use `board_grid/1` directly.
"""
attr :endgame, :map, default: nil
attr :date, :any, default: nil
def board_preview(assigns) do
endgame = assigns.endgame
assigns =
assign(assigns,
fen: fen_for(endgame),
turn: turn_label(endgame),
title: title(endgame),
themes: theme_names(endgame),
orientation: orientation(endgame),
date: Calendar.strftime(assigns.date || Date.utc_today(), "%d %b %Y")
)
~H"""