defmodule Shino.UI.Tabs do @moduledoc """ Provides tabs related components. > Displays a set of layered sections of content-known as tab panels—that are > displayed one at a time. ## Examples ```heex account password Account Password ``` Above tabs should be usable, but to avoid of the flash of unstyled content, extra classes should be added for tabs content. ```heex account password Account Password ``` ## References * [@radix-ui/primitives - Tabs](https://www.radix-ui.com/primitives/docs/components/tabs) * [shadcn/ui - Tabs](https://ui.shadcn.com/docs/components/tabs) """ use Shino.UI, :component @doc """ The root contains all the parts of a form. """ attr :id, :string, required: true attr :default_value, :string, required: true attr :class, :string, default: nil attr :rest, :global slot :inner_block, required: true def root(assigns) do ~H"""
<%= render_slot(@inner_block, {@id, @default_value}) %>
""" end @doc """ Renders a wrapper for tabs' triggers. """ attr :class, :string, default: nil attr :rest, :global slot :inner_block, required: true def list(assigns) do ~H"""
<%= render_slot(@inner_block) %>
""" end @doc """ Renders a tab trigger. """ attr :root, :string, required: true, doc: "id of root tabs tag" attr :value, :string, required: true, doc: "target value of tab content" attr :class, :string, default: nil attr :rest, :global slot :inner_block, required: true def trigger(assigns) do ~H""" """ end @doc """ Renders the content associated to a tab. """ attr :value, :string, required: true, doc: "unique for tab content" attr :class, :string, default: nil attr :rest, :global slot :inner_block, required: true def content(assigns) do ~H"""
<%= render_slot(@inner_block) %>
""" end defp show_tab(root, value) do %JS{} |> JS.set_attribute({"data-state", "inactive"}, to: "##{root} .tabs-trigger:not([data-value=#{value}])" ) |> JS.set_attribute({"data-state", "active"}, to: "##{root} .tabs-trigger[data-value=#{value}]" ) |> JS.hide(to: "##{root} .tabs-content:not([data-value=#{value}])") |> JS.show(to: "##{root} .tabs-content[data-value=#{value}]") end end