1
0
mirror of https://github.com/algora-io/tv.git synced 2025-02-14 01:59:50 +02:00
algora-tv/lib/algora_web/live/layout_component.ex
Zafer Cesur 7684f3fc37
migrate core components to latest (#1)
* upgrade core components to latest

* adapt styles for dark mode

* restore custom components

* use new components & patterns

* delete icon component

* update tailwind config

* delete phoenix.css

* add ::selection style

* delete obsolete title_bar comp
2024-03-02 18:04:44 +03:00

49 lines
1.4 KiB
Elixir

defmodule AlgoraWeb.LayoutComponent do
@moduledoc """
Component for rendering content inside layout without full DOM patch.
"""
use AlgoraWeb, :live_component
def show_modal(module, attrs) do
send_update(__MODULE__, id: "layout", show: Enum.into(attrs, %{module: module}))
end
def hide_modal do
send_update(__MODULE__, id: "layout", show: nil)
end
def update(%{id: id} = assigns, socket) do
show =
case assigns[:show] do
%{module: _module, confirm: {text, attrs}} = show ->
show
|> Map.put_new(:title, show[:title])
|> Map.put_new(:on_cancel, show[:on_cancel] || %JS{})
|> Map.put_new(:on_confirm, show[:on_confirm] || %JS{})
|> Map.put_new(:patch, nil)
|> Map.put_new(:navigate, nil)
|> Map.merge(%{confirm_text: text, confirm_attrs: attrs})
nil ->
nil
end
{:ok, assign(socket, id: id, show: show)}
end
def render(assigns) do
~H"""
<div class={unless @show, do: "hidden"}>
<%= if @show do %>
<.modal show id={@id} on_cancel={@show.on_cancel} on_confirm={@show.on_confirm}>
<:title><%= @show.title %></:title>
<.live_component module={@show.module} {@show} />
<:cancel>Cancel</:cancel>
<:confirm {@show.confirm_attrs}><%= @show.confirm_text %></:confirm>
</.modal>
<% end %>
</div>
"""
end
end