livebook/lib/livebook_web/live/learn_helpers.ex

37 lines
1 KiB
Elixir
Raw Normal View History

defmodule LivebookWeb.LearnHelpers do
use Phoenix.Component
2023-02-23 02:34:54 +08:00
use LivebookWeb, :verified_routes
@doc """
Renders an learn notebook card.
"""
2023-02-23 02:34:54 +08:00
attr :notebook_info, :map, required: true
def notebook_card(assigns) do
~H"""
2023-02-23 02:34:54 +08:00
<.link
navigate={~p"/learn/notebooks/#{@notebook_info.slug}"}
class="flex flex-col border-2 border-gray-100 hover:border-gray-200 rounded-2xl"
>
2022-10-25 21:33:15 +08:00
<div class="flex items-center justify-center p-6 border-b-2 border-gray-100 rounded-t-2xl h-[150px]">
2022-08-02 21:51:02 +08:00
<img
2023-02-23 02:34:54 +08:00
src={img_src(@notebook_info.details.cover_url)}
2022-08-02 21:51:02 +08:00
class="max-h-full max-w-[75%]"
alt={"#{@notebook_info.title} logo"}
/>
2022-10-25 21:33:15 +08:00
</div>
<div class="px-6 py-4 bg-gray-100 rounded-b-2xl grow">
2022-10-25 21:33:15 +08:00
<span class="text-gray-800 font-semibold"><%= @notebook_info.title %></span>
<p class="mt-2 text-sm text-gray-600">
<%= @notebook_info.details.description %>
</p>
</div>
2023-02-23 02:34:54 +08:00
</.link>
"""
end
2023-02-23 02:34:54 +08:00
defp img_src("data:" <> _ = url), do: url
defp img_src(url), do: url
end