2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.SectionComponent do
|
|
|
|
use LivebookWeb, :live_component
|
2021-02-11 23:35:32 +08:00
|
|
|
|
|
|
|
def render(assigns) do
|
|
|
|
~L"""
|
2021-03-11 22:28:18 +08:00
|
|
|
<div data-element="section" data-section-id="<%= @section.id %>">
|
2021-03-20 21:10:15 +08:00
|
|
|
<div class="flex space-x-4 items-center" data-element="section-headline">
|
|
|
|
<h2 class="flex-grow text-gray-800 font-semibold text-2xl px-1 -ml-1 rounded-lg border border-transparent hover:border-blue-200 focus:border-blue-300"
|
|
|
|
data-element="section-name"
|
|
|
|
id="section-<%= @section.id %>-name"
|
|
|
|
contenteditable
|
|
|
|
spellcheck="false"
|
|
|
|
phx-blur="set_section_name"
|
|
|
|
phx-value-section_id="<%= @section.id %>"
|
|
|
|
phx-hook="ContentEditable"
|
|
|
|
data-update-attribute="phx-value-name"><%= @section.name %></h2>
|
|
|
|
<%# ^ Note it's important there's no space between <h2> and </h2>
|
|
|
|
because we want the content to exactly match @section.name. %>
|
|
|
|
<div class="flex space-x-2 items-center" data-element="section-actions">
|
2021-03-23 05:15:40 +08:00
|
|
|
<span class="tooltip top" aria-label="Delete">
|
2021-03-23 21:10:34 +08:00
|
|
|
<button class="icon-button" phx-click="delete_section" phx-value-section_id="<%= @section.id %>" tabindex="-1">
|
|
|
|
<%= remix_icon("delete-bin-6-line", class: "text-xl") %>
|
2021-03-23 05:15:40 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
2021-02-11 23:35:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-18 22:11:24 +08:00
|
|
|
<div class="container py-2">
|
2021-03-20 21:10:15 +08:00
|
|
|
<div class="flex flex-col space-y-1">
|
2021-03-04 05:56:28 +08:00
|
|
|
<%= live_component @socket, LivebookWeb.InsertCellComponent,
|
2021-02-11 23:35:32 +08:00
|
|
|
id: "#{@section.id}:0",
|
|
|
|
section_id: @section.id,
|
2021-02-18 22:11:24 +08:00
|
|
|
index: 0,
|
|
|
|
persistent: @section.cells == [] %>
|
2021-02-11 23:35:32 +08:00
|
|
|
<%= for {cell, index} <- Enum.with_index(@section.cells) do %>
|
2021-03-04 05:56:28 +08:00
|
|
|
<%= live_component @socket, LivebookWeb.CellComponent,
|
2021-02-11 23:35:32 +08:00
|
|
|
id: cell.id,
|
2021-03-04 05:23:48 +08:00
|
|
|
session_id: @session_id,
|
2021-02-11 23:35:32 +08:00
|
|
|
cell: cell,
|
2021-03-11 22:28:18 +08:00
|
|
|
cell_info: @cell_infos[cell.id] %>
|
2021-03-04 05:56:28 +08:00
|
|
|
<%= live_component @socket, LivebookWeb.InsertCellComponent,
|
2021-02-11 23:35:32 +08:00
|
|
|
id: "#{@section.id}:#{index + 1}",
|
|
|
|
section_id: @section.id,
|
2021-02-18 22:11:24 +08:00
|
|
|
index: index + 1,
|
|
|
|
persistent: false %>
|
2021-02-11 23:35:32 +08:00
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|