defmodule LivebookWeb.LayoutHelpers do use LivebookWeb, :html import LivebookWeb.UserHelpers alias Livebook.Hubs.Provider @doc """ The layout used in the non-session pages. """ attr :current_page, :string, required: true attr :current_user, Livebook.Users.User, required: true attr :saved_hubs, :list, required: true slot :inner_block, required: true slot :topbar_action def layout(assigns) do ~H"""
<.live_region role="alert" /> <.sidebar current_page={@current_page} current_user={@current_user} saved_hubs={@saved_hubs} />
<%= if @topbar_action do %> <%= render_slot(@topbar_action) %> <% else %>
<.link navigate={~p"/"} class="flex items-center" aria-label="go to home"> <.remix_icon icon="home-6-line" /> Home
<% end %>
<%= render_slot(@inner_block) %>
<.current_user_modal current_user={@current_user} /> """ end defp sidebar(assigns) do ~H""" """ end defp sidebar_link(assigns) do ~H""" <.link navigate={@to} class={[ "h-7 flex items-center hover:text-white border-l-4 hover:border-white", sidebar_link_text_color(@to, @current), sidebar_link_border_color(@to, @current) ]} > <.remix_icon icon={@icon} class="text-lg leading-6 w-[56px] flex justify-center" /> <%= @title %> """ end defp sidebar_hub_link(assigns) do ~H""" <.link navigate={@to} class={[ "h-7 flex items-center hover:text-white border-l-4 hover:border-white", sidebar_link_text_color(@to, @current), sidebar_link_border_color(@to, @current) ]} >
<%= @hub.emoji %>
<%= @hub.name %> """ end defp sidebar_hub_link_with_tooltip(assigns) do ~H""" <.link {hub_connection_link_opts(@hub.provider, @to, @current)}>
<%= @hub.emoji %>
<%= @hub.name %> """ end defp hub_section(assigns) do ~H"""
HUBS
<%= for hub <- @hubs do %> <%= if Provider.connection_spec(hub.provider) do %> <.sidebar_hub_link_with_tooltip hub={hub} to={~p"/hub/#{hub.id}"} current={@current_page} /> <% else %> <.sidebar_hub_link hub={hub} to={~p"/hub/#{hub.id}"} current={@current_page} /> <% end %> <% end %> <.sidebar_link title="Add Hub" icon="add-line" to={~p"/hub"} current={@current_page} />
""" end defp sidebar_link_text_color(to, current) when to == current, do: "text-white" defp sidebar_link_text_color(_to, _current), do: "text-gray-400" defp sidebar_link_border_color(to, current) when to == current, do: "border-white" defp sidebar_link_border_color(_to, _current), do: "border-transparent" defp hub_connection_link_opts(hub, to, current) do text_color = sidebar_link_text_color(to, current) border_color = sidebar_link_border_color(to, current) class = "h-7 flex items-center hover:text-white #{text_color} border-l-4 #{border_color} hover:border-white" if tooltip = Provider.connection_error(hub) do [navigate: to, data_tooltip: tooltip, class: "tooltip right " <> class] else [navigate: to, class: class] end end @doc """ Renders page title. ## Examples <.title text="Learn" /> """ attr :text, :string, required: true attr :back_navigate, :string, default: nil def title(assigns) do ~H"""

<%= @text %>

""" end end