I use a component to render the top navigation bar. That bar contains three menu items. I’d like to highlight the current item with is_active={true}
.
My problem is that I have no idea how to call the component with the needed information having a clean and easy to understand code solution which doesn’t contain of a million if/else structures.
I would like to do something like <.top_navigation active_tab="home" />
or something similar. I can solve this but my solution is not elegant (a lot of if/else). What is an elegant solution for this problem?
@doc """
Top navigation bar.
## Examples
<.top_navigation />
"""
attr :active_nav_tab, :string, default: "", doc: "current navigation tab"
attr :current_user, :map, default: %{}, doc: "current user"
def top_navigation(assigns) do
~H"""
<div class="border-y border-brand-silver-100">
<nav class="grid grid-cols-3 gap-1">
<.home_nav_item is_active={true} />
<.chat_nav_item current_user ={@current_user} />
<.user_profile_item current_user ={@current_user} />
</nav>
</div>
"""
end