Skip to content

Instantly share code, notes, and snippets.

@unixc3t
Last active October 2, 2024 06:40
Show Gist options
  • Save unixc3t/fb19ee2aef64f6667acc1915fcd01ea5 to your computer and use it in GitHub Desktop.
Save unixc3t/fb19ee2aef64f6667acc1915fcd01ea5 to your computer and use it in GitHub Desktop.
phoenix component and sloct_demo
use Phoenix.Component
import Phoenix.HTML
attr :myrows, :list, required: true
slot :mycol, required: true do
attr :label, :string
end
def table_1(assigns) do
~H"""
<%= for col <- @mycol do %>
<%= col.label %>
<% end %>
<%= for my <- @myrows do %>
<%= for col <- @mycol do %>
<%= render_slot(col, my) %>
<% end %>
<% end %>
"""
end
def table_2(assigns) do
~H"""
<%= for col <- @mycol do %>
<%= col.label %>
<% end %>
<.myview myrows={@myrows} mycol={@mycol}>
</.myview>
"""
end
def myview(assigns) do
~H"""
<%= for my <- @myrows do %>
<%= for col <- @mycol do %>
<%= render_slot(col, my) %>
<% end %>
<% end %>
"""
end
---------
<DemographicLive.Show.table_1 myrows={@dhello}>
<:mycol :let={m} label="Name">
<%= m.name %>
</:mycol>
<:mycol :let={m} label="Age">
<%= m.age %>
</:mycol>
</DemographicLive.Show.table_1>
<hr/>
<DemographicLive.Show.table_2 myrows={@dhello}>
<:mycol :let={m} label="Name">
<%= m.name %>
</:mycol>
<:mycol :let={m} label="Age">
<%= m.age %>
</:mycol>
</DemographicLive.Show.table_2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment