From 086f943f38588669bb6339fb2f423c4f0564145b Mon Sep 17 00:00:00 2001 From: De Wet Blomerus Date: Fri, 6 Oct 2023 15:50:42 -0400 Subject: [PATCH] =?UTF-8?q?Turn=20checkbox=20into=20toggle=20=F0=9F=8E=9A?= =?UTF-8?q?=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/core_components.ex | 26 ++++++++++++++++++- .../live/average_live.html.heex | 6 ++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/quick_average_web/components/core_components.ex b/lib/quick_average_web/components/core_components.ex index 2fe0543..f527cb5 100644 --- a/lib/quick_average_web/components/core_components.ex +++ b/lib/quick_average_web/components/core_components.ex @@ -294,7 +294,7 @@ defmodule QuickAverageWeb.CoreComponents do default: "text", values: ~w(checkbox color date datetime-local email file hidden month number password - range radio search select tel text textarea time url week) + range radio search select tel text textarea time url week toggle) attr :value, :any @@ -358,6 +358,30 @@ defmodule QuickAverageWeb.CoreComponents do """ end + def input(%{type: "toggle"} = assigns) do + assigns = + assign_new(assigns, :checked, fn -> + input_equals?(assigns.value, "true") + end) + + ~H""" + + """ + end + def input(%{type: "select"} = assigns) do ~H"""
diff --git a/lib/quick_average_web/live/average_live.html.heex b/lib/quick_average_web/live/average_live.html.heex index 880f6b2..f44de02 100644 --- a/lib/quick_average_web/live/average_live.html.heex +++ b/lib/quick_average_web/live/average_live.html.heex @@ -10,7 +10,11 @@ > <.input field={{f, :name}} type="text" label="Name" maxlength={30} /> - <.input field={{f, :only_viewing}} type="checkbox" label="Only Viewing" /> + <.input + field={{f, :only_viewing}} + type="toggle" + label="Only Viewing 📺" + /> <%= if !@only_viewing do %> <.input