mirror of
https://github.com/woutdp/live_svelte
synced 2026-05-24 09:28:21 +00:00
23 lines
467 B
Elixir
23 lines
467 B
Elixir
defmodule LiveSvelte.LiveJson do
|
|
use Phoenix.Component
|
|
|
|
attr(
|
|
:live_json_props,
|
|
:map,
|
|
default: %{},
|
|
doc: "LiveJSON props to pass to the svelte component"
|
|
)
|
|
|
|
slot(:inner_block)
|
|
|
|
def live_json(assigns) do
|
|
~H"""
|
|
<%= if @live_json_props != %{} do %>
|
|
<div id={id("lj")} phx-hook="LiveJSON" />
|
|
<% end %>
|
|
<%= render_slot(@inner_block) %>
|
|
"""
|
|
end
|
|
|
|
defp id(name), do: "#{name}-#{System.unique_integer([:positive])}"
|
|
end
|