From f96956cf5e257c98f498f2c0fc359d16b382bf25 Mon Sep 17 00:00:00 2001 From: shibao Date: Sun, 12 Sep 2021 18:16:24 -0400 Subject: [PATCH] add random color generation to tags --- lib/cannery_web/live/tag_live/form_component.ex | 9 +++++++++ lib/cannery_web/live/tag_live/form_component.html.leex | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/cannery_web/live/tag_live/form_component.ex b/lib/cannery_web/live/tag_live/form_component.ex index 5eeeb36a..512e2ef2 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 0c4f448a..acd4f0e8 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 %>