add random color generation to tags

This commit is contained in:
shibao 2021-09-12 18:16:24 -04:00 committed by oliviasculley
parent b8255a91bd
commit f96956cf5e
2 changed files with 15 additions and 2 deletions

View File

@ -55,4 +55,13 @@ defmodule CanneryWeb.TagLive.FormComponent do
{:noreply, socket |> assign(changeset: changeset)}
end
end
@doc """
Returns a random tag color in `#ffffff` hex format
"""
@spec random_color() :: String.t()
def random_color() do
["#cc0066", "#ff6699", "#6666ff", "#0066cc", "#00cc66", "#669900", "#ff9900", "#996633"]
|> Enum.random()
end
end

View File

@ -16,13 +16,17 @@
</span>
<%= label f, :bg_color, class: "title text-lg text-primary-500" %>
<%= color_input f, :bg_color, class: "mx-auto col-span-2" %>
<span class="mx-auto col-span-2" phx-update="ignore">
<%= color_input f, :bg_color, value: random_color() %>
</span>
<span class="col-span-3">
<%= error_tag f, :bg_color %>
</span>
<%= label f, :text_color, class: "title text-lg text-primary-500" %>
<%= color_input f, :text_color, class: "mx-auto col-span-2" %>
<span class="mx-auto col-span-2" phx-update="ignore">
<%= color_input f, :text_color, value: "#ffffff" %>
</span>
<span class="col-span-3">
<%= error_tag f, :text_color %>
</span>