defmodule LivebookWeb.NotebookComponents do
use LivebookWeb, :html
@doc """
Renders a learn notebook card.
"""
attr :notebook_info, :map, required: true
def learn_notebook_card(assigns) do
~H"""
<.link
navigate={~p"/learn/notebooks/#{@notebook_info.slug}"}
class="flex flex-col border-2 border-gray-100 hover:border-gray-200 rounded-2xl"
>
{@notebook_info.title}
{@notebook_info.details.description}
"""
end
@doc """
Resolves the given image source into a URL.
"""
@spec learn_img_src(Livebook.Notebook.Learn.image_source()) :: String.t()
def learn_img_src({:url, url}), do: url
def learn_img_src({:static, filename}), do: ~p"/images/#{filename}"
@doc """
Renders an icon for the given cell.
"""
attr :cell_type, :atom, required: true
attr :language, :atom, default: nil
def cell_icon(assigns)
def cell_icon(%{cell_type: :code, language: :elixir} = assigns) do
~H"""
<.language_icon language="elixir" class="w-full h-full text-[#663299]" />
"""
end
def cell_icon(%{cell_type: :code, language: :erlang} = assigns) do
~H"""
<.language_icon language="erlang" class="w-full h-full text-[#a90533]" />
"""
end
def cell_icon(%{cell_type: :markdown} = assigns) do
~H"""
<.language_icon language="markdown" class="w-full h-full text-[#3e64ff]" />
"""
end
def cell_icon(%{cell_type: :smart} = assigns) do
~H"""
<.remix_icon icon="flashlight-line text-red-900" />
"""
end
@doc """
Renders an icon for the given language.
"""
attr :language, :string, required: true
attr :class, :string, default: nil
def language_icon(%{language: "elixir"} = assigns) do
~H"""
"""
end
def language_icon(%{language: "erlang"} = assigns) do
~H"""
"""
end
def language_icon(%{language: "markdown"} = assigns) do
~H"""
"""
end
end