diff --git a/lib/cannery_web/live/tag_live/form_component.ex b/lib/cannery_web/live/tag_live/form_component.ex index 5eeeb36..512e2ef 100644 --- a/lib/cannery_web/live/tag_live/form_component.ex +++ b/lib/cannery_web/live/tag_live/form_component.ex @@ -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 diff --git a/lib/cannery_web/live/tag_live/form_component.html.leex b/lib/cannery_web/live/tag_live/form_component.html.leex index 0c4f448..acd4f0e 100644 --- a/lib/cannery_web/live/tag_live/form_component.html.leex +++ b/lib/cannery_web/live/tag_live/form_component.html.leex @@ -16,13 +16,17 @@ <%= label f, :bg_color, class: "title text-lg text-primary-500" %> - <%= color_input f, :bg_color, class: "mx-auto col-span-2" %> + + <%= color_input f, :bg_color, value: random_color() %> + <%= error_tag f, :bg_color %> <%= label f, :text_color, class: "title text-lg text-primary-500" %> - <%= color_input f, :text_color, class: "mx-auto col-span-2" %> + + <%= color_input f, :text_color, value: "#ffffff" %> + <%= error_tag f, :text_color %>