livebook/lib/livebook_web/live/output/text_component.ex

39 lines
1.1 KiB
Elixir
Raw Normal View History

defmodule LivebookWeb.Output.TextComponent do
use LivebookWeb, :live_component
@impl true
def render(assigns) do
~H"""
2022-08-02 21:51:02 +08:00
<div
id={"virtualized-text-#{@id}"}
class="relative"
phx-hook="VirtualizedLines"
2022-08-02 21:51:02 +08:00
data-max-height="300"
>
<% # Add a newline to each element, so that multiple lines can be copied properly %>
<div data-template class="hidden" id={"virtualized-text-#{@id}-template"} phx-no-format><%= for line <- ansi_string_to_html_lines(@content) do %><div data-line><%= [
line,
"\n"
] %></div><% end %></div>
2022-08-02 21:51:02 +08:00
<div
data-content
class="overflow-auto whitespace-pre font-editor text-gray-500 tiny-scrollbar"
id={"virtualized-text-#{@id}-content"}
2022-08-02 21:51:02 +08:00
phx-update="ignore"
phx-no-format
2022-10-04 14:46:55 +08:00
>
</div>
<div class="absolute right-2 top-0 z-10">
2022-08-02 21:51:02 +08:00
<button
class="icon-button bg-gray-100"
data-el-clipcopy
2022-08-02 21:51:02 +08:00
phx-click={JS.dispatch("lb:clipcopy", to: "#virtualized-text-#{@id}-template")}
>
<.remix_icon icon="clipboard-line" class="text-lg" />
</button>
</div>
</div>
"""
end
end