petalframework / petal_components

Phoenix + Live View HEEX Components
https://petal.build/components
MIT License
818 stars 94 forks source link

Table component using slots #232

Closed dvic closed 8 months ago

dvic commented 1 year ago

What do you think about this approach for the Table component? https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#module-slot-attributes

copied from above:

<.dyn_table rows={[%{name: "Jane", age: "34"}, %{name: "Bob", age: "51"}]}>
  <:column :let={user} label="Name">
    <%= user.name %>
  </:column>
  <:column :let={user} label="Age">
    <%= user.age %>
  </:column>
</.dyn_table>

instead of

<.table>
  <.tr>
    <.th>Name</.th>
    <.th>Age</.th>
  </.tr>

  <.tr>
    <.td>Jane</.td>
    <.td>34</.td>
  </.tr>

  <.tr>
    <.td>Bob</.td>
    <.td>51</.td>
  </.tr>
</.table>

Maybe we should add this as a <.dyn_table> component? (as it's kind of meant for tables with dynamic columns and rows)

nhobes commented 1 year ago

@dvic this has been added to the Petal Development board:

https://github.com/orgs/petalframework/projects/2

mplatts commented 8 months ago

Done in 1.9.0

I updated the existing table component - should be backwards compatible.

https://petal.build/components/table