defmodule Paleta.Components.Field do
use Phoenix.Component
alias Paleta.Components.CopyToClipboard
alias Paleta.Components.FromNow
alias Paleta.Utils.StringHelper
attr(:value, :string, required: true)
def id_field(assigns) do
~H"""
ID:
"""
end
attr(:label, :string, required: true)
attr(:value, :string, required: true)
def date_field(assigns) do
~H"""
<%= @label %>:
"""
end
attr(:label, :string, required: true)
attr(:value, :string, required: true)
slot(:inner_block, required: false)
def field(assigns) do
~H"""
<%= @label %>:
<%= @value || render_slot(@inner_block) %>
"""
end
attr(:value, :string, required: true)
attr(:empty_value, :string, default: "")
attr(:class, :string, default: "prose prose-sm dark:prose-invert")
def markdown_field(%{value: value, empty_value: empty_value} = assigns) do
assigns =
assigns
|> assign(:markdown, StringHelper.markdown_to_html(value || empty_value))
~H"""
<%= Phoenix.HTML.raw(@markdown) %>
"""
end
end