From c2568b65210033a358270ea773d026f0fed04a79 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 19 Nov 2022 10:55:44 -0500 Subject: [PATCH] move toggle button to live_helpers --- CHANGELOG.md | 1 + lib/cannery_web/live/live_helpers.ex | 49 ++++++++++++++++++++++++++- lib/cannery_web/views/view_helpers.ex | 40 ---------------------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92d78fc..9337c50d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # v0.7.1 - Fix table component alignment and styling +- Fix toggle button styling # v0.7.1 - Add shading to table component diff --git a/lib/cannery_web/live/live_helpers.ex b/lib/cannery_web/live/live_helpers.ex index 4371aa6c..6599bacb 100644 --- a/lib/cannery_web/live/live_helpers.ex +++ b/lib/cannery_web/live/live_helpers.ex @@ -72,10 +72,57 @@ defmodule CanneryWeb.LiveHelpers do """ end - def hide_modal(js \\ %JS{}) do + defp hide_modal(js \\ %JS{}) do js |> JS.hide(to: "#modal", transition: "fade-out") |> JS.hide(to: "#modal-bg", transition: "fade-out") |> JS.hide(to: "#modal-content", transition: "fade-out-scale") end + + @doc """ + A toggle button element that can be directed to a liveview or a + live_component's `handle_event/3`. + + ## Examples + + <.toggle_button action="my_liveview_action" value={@some_value}> + Toggle me! + + <.toggle_button action="my_live_component_action" target={@myself} value={@some_value}> + Whatever you want + + """ + def toggle_button(assigns) do + assigns = assigns |> assign_new(:id, fn -> assigns.action end) + + ~H""" + + """ + end end diff --git a/lib/cannery_web/views/view_helpers.ex b/lib/cannery_web/views/view_helpers.ex index c69d9658..27dbf882 100644 --- a/lib/cannery_web/views/view_helpers.ex +++ b/lib/cannery_web/views/view_helpers.ex @@ -76,46 +76,6 @@ defmodule CanneryWeb.ViewHelpers do def display_emoji(other_emoji), do: other_emoji - @doc """ - A toggle button element that can be directed to a liveview or a - live_component's `handle_event/3`. - - ## Examples - - <.toggle_button action="my_liveview_action" value={@some_value}> - Toggle me! - - <.toggle_button action="my_live_component_action" target={@myself} value={@some_value}> - Whatever you want - - """ - def toggle_button(assigns) do - assigns = assigns |> assign_new(:id, fn -> assigns.action end) - - ~H""" - - """ - end - @doc """ Get a random color in `#ffffff` hex format