defmodule LiveBeatsWeb.LiveHelpers do import Phoenix.LiveView import Phoenix.LiveView.Helpers alias LiveBeatsWeb.Router.Helpers, as: Routes alias Phoenix.LiveView.JS def home_path(socket) do Routes.song_index_path(socket, :index, socket.assigns.current_user.username) end def spinner(assigns) do ~H""" """ end def icon(assigns) do assigns = assigns |> assign_new(:outlined, fn -> false end) |> assign_new(:class, fn -> "w-4 h-4" end) ~H""" <%= if @outlined do %> <%= apply(Heroicons.Outline, @name, [assigns_to_attributes(assigns, [:outlined, :name])]) %> <% else %> <%= apply(Heroicons.Solid, @name, [assigns_to_attributes(assigns, [:outlined, :name])]) %> <% end %> """ end def link(%{redirect_to: to} = assigns) do opts = assigns |> assigns_to_attributes() |> Keyword.put(:to, to) assigns = assign(assigns, :opts, opts) ~H""" <%= live_redirect @opts do %><%= render_slot(@inner_block) %><% end %> """ end def link(%{patch_to: to} = assigns) do opts = assigns |> assigns_to_attributes() |> Keyword.put(:to, to) assigns = assign(assigns, :opts, opts) ~H""" <%= live_patch @opts do %><%= render_slot(@inner_block) %><% end %> """ end def link(%{} = assigns) do opts = assigns |> assigns_to_attributes() |> Keyword.put(:to, assigns[:href] || "#") assigns = assign(assigns, :opts, opts) ~H""" <%= Phoenix.HTML.Link.link @opts do %><%= render_slot(@inner_block) %><% end %> """ end def show_mobile_sidebar(js \\ %JS{}) do js |> JS.show(to: "#mobile-sidebar-container", transition: "fade-in") |> JS.show( to: "#mobile-sidebar", display: "flex", time: 300, transition: {"transition ease-in-out duration-300 transform", "-translate-x-full", "translate-x-0"} ) end def hide_mobile_sidebar(js \\ %JS{}) do js |> JS.hide(to: "#mobile-sidebar-container", transition: "fade-out") |> JS.hide( to: "#mobile-sidebar", time: 300, transition: {"transition ease-in-out duration-300 transform", "translate-x-0", "-translate-x-full"} ) end def hide(js \\ %JS{}, selector) do JS.hide(js, to: selector, time: 300, transition: {"transition ease-in duration-300", "transform opacity-100 scale-100", "transform opacity-0 scale-95"} ) end def show_dropdown(to) do JS.show( to: to, transition: {"transition ease-out duration-120", "transform opacity-0 scale-95", "transform opacity-100 scale-100"} ) end def hide_dropdown(to) do JS.hide( to: to, transition: {"transition ease-in duration-120", "transform opacity-100 scale-100", "transform opacity-0 scale-95"} ) end def show_modal(js \\ %JS{}, id) when is_binary(id) do js |> JS.show( to: "##{id}", display: "inline-block", transition: {"ease-out duration-300", "opacity-0", "opacity-100"} ) |> JS.show( to: "##{id}-container", display: "inline-block", transition: {"ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", "opacity-100 translate-y-0 sm:scale-100"} ) |> js_exec("##{id}-confirm", "focus", []) end def hide_modal(js \\ %JS{}, id) do js |> JS.remove_class("fade-in", to: "##{id}") |> JS.hide( to: "##{id}", transition: {"ease-in duration-200", "opacity-100", "opacity-0"} ) |> JS.hide( to: "##{id}-container", transition: {"ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} ) |> JS.dispatch("click", to: "##{id} [data-modal-return]") end def modal(assigns) do assigns = assigns |> assign_new(:show, fn -> false end) |> assign_new(:patch_to, fn -> nil end) |> assign_new(:redirect_to, fn -> nil end) |> assign_new(:on_cancel, fn -> %JS{} end) |> assign_new(:on_confirm, fn -> %JS{} end) # slots |> assign_new(:title, fn -> [] end) |> assign_new(:confirm, fn -> [] end) |> assign_new(:cancel, fn -> [] end) |> assign_rest(~w(id show patch_to redirect_to on_cancel on_confirm title confirm cancel)a) ~H"""
<%= render_slot(@inner_block) %>
<%= col.label %> | <% end %>
---|
<%= render_slot(col, row) %>
|
<% end %>
<%= col.label %> | <% end %>
---|