Packages
phoenix_duskmoon
4.5.0
9.9.2
9.9.1
9.9.0
9.8.0
9.7.1
9.7.0
9.6.4
9.6.3
9.6.2
9.6.1
9.6.0
9.5.4
9.5.3
9.5.2
9.5.1
9.5.0
9.4.3
9.4.2
9.4.1
9.4.0
9.3.0
9.2.0
9.1.4
9.1.3
9.1.1
9.1.1-rc.1
retired
9.0.1
9.0.0-rc.3
9.0.0-rc.2
9.0.0-rc.1
8.0.0
7.2.1
7.2.0
7.1.3
7.1.2
7.1.1
6.3.2
6.3.1
6.3.0
6.2.0
6.1.3
6.1.2
6.1.1
6.1.0
6.0.10
6.0.9
6.0.8
6.0.7
6.0.6
6.0.5
6.0.4
6.0.3
6.0.2
6.0.1
6.0.0
5.2.0-beta.5
5.2.0-beta.4
5.2.0-beta.3
5.2.0-beta.2
5.2.0-beta.1
5.1.0
5.0.6
5.0.5
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.2
4.5.1
4.5.0
4.4.4
4.4.3
4.4.2
4.4.1
4.4.0
4.3.2
4.3.1
4.3.0
4.2.0
4.1.1
4.1.0
4.0.0
Duskmoon UI component library for Phoenix LiveView
Current section
Files
Jump to
Current section
Files
lib/phoenix_duskmoon/tab.ex
defmodule PhoenixDuskmoon.Tab do
@moduledoc """
render tab
"""
use PhoenixDuskmoon, :html
@doc """
Generates tabs
## Example
<.dm_tab active_tab_index={0}>
<:tab>Menu1</:tab>
<:tab>Menu2</:tab>
<:tab_content>Menu1 Content</:tab_content>
<:tab_content>Menu2 Content</:tab_content>
</.dm_tab>
"""
@doc type: :component
attr(:id, :any,
default: false,
doc: """
html attribute id
"""
)
attr(:class, :any,
default: "",
doc: """
html attribute class
"""
)
attr(:header_class, :any,
default: "",
doc: """
header html attribute class
"""
)
attr(:orientation, :string,
default: "horizontal",
values: ["horizontal", "vertical"],
doc: """
header html attribute class
"""
)
attr(:active_tab_index, :integer,
default: 0,
doc: """
the index of active tab, if active_tab_name is not set, this will be used
"""
)
attr(:active_tab_name, :string,
default: "",
doc: """
the name of active tab, use for match tab and tab_content
"""
)
attr(:active_tab_class, :any,
doc: """
class of active tab
"""
)
attr(:content_class, :any,
default: "",
doc: """
tab_content html attribute class
"""
)
slot(:tab,
required: false,
doc: """
Render tab
"""
) do
attr(:id, :any)
attr(:class, :any)
attr(:name, :string)
end
slot(:tab_content,
required: false,
doc: """
Render tab content
"""
) do
attr(:id, :any)
attr(:class, :any)
attr(:name, :string)
end
def dm_tab(assigns) do
assigns =
assigns
|> assign_new(:active_tab_class, fn ->
if assigns[:orientation] == "horizontal" do
"text-blue-400 border-x-0 border-t-0 border-b border-solid border-blue-400"
else
"text-blue-400 border-y-0 border-l-0 border-r border-solid border-blue-400"
end
end)
~H"""
<section
id={@id}
class={[
"flex gap-2",
"w-full px-4",
if(@orientation == "horizontal", do: "flex-col", else: "flex-row"),
@class
]}
>
<header
class={[
"flex justify-start items-center gap-2 sticky top-0",
if(@orientation == "horizontal", do: "flex-row", else: "flex-col"),
@header_class
]}
>
<%= for {tab, i} <- Enum.with_index(@tab) do %>
<span
id={Map.get(tab, :id, false)}
class={[
"flex flex-row",
"py-4 px-2",
Map.get(tab, :class, ""),
if(@active_tab_name != "",
do: if(@active_tab_name == Map.get(tab, :name, ""),
do: @active_tab_class,
else: "cursor-pointer"),
else: if(@active_tab_index == i,
do: @active_tab_class,
else: "cursor-pointer"))
]}
phx-click={Map.get(tab, :phx_click, nil)}
>
<%= render_slot(tab) %>
</span>
<% end %>
</header>
<%= for {tab_content, i} <- Enum.with_index(@tab_content) do %>
<%= if @active_tab_name != "" do %>
<%= if @active_tab_name == Map.get(tab_content, :name, "") do %>
<div id={Map.get(tab_content, :id, false)} class={Map.get(tab_content, :class, "")}>
<%= render_slot(tab_content) %>
</div>
<% end %>
<% else %>
<%= if @active_tab_index == i do %>
<div id={Map.get(tab_content, :id, false)} class={Map.get(tab_content, :class, "")}>
<%= render_slot(tab_content) %>
</div>
<% end %>
<% end %>
<% end %>
</section>
"""
end
end