Skip to content

Commit 23ec5d2

Browse files
authored
Merge pull request #426 from saleyn/table
Avoid unnecessarily traversing lists
2 parents 04c8352 + 558baa7 commit 23ec5d2

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

lib/petal_components/table.ex

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,22 @@ defmodule PetalComponents.Table do
4848

4949
~H"""
5050
<table class={["pc-table--#{@variant}", @class]} {@rest}>
51-
<%= if length(@col) > 0 do %>
51+
<%= if @col != [] do %>
5252
<thead>
5353
<.tr>
5454
<.th :for={col <- @col} class={col[:class]}>{col[:label]}</.th>
5555
</.tr>
5656
</thead>
5757
<tbody id={@id} phx-update={match?(%Phoenix.LiveView.LiveStream{}, @rows) && "stream"}>
58-
<%= if length(@empty_state) > 0 do %>
59-
<.tr id={@id <> "-empty"} class="hidden only:table-row">
60-
<.td
61-
:for={empty_state <- @empty_state}
62-
colspan={length(@col)}
63-
class={empty_state[:row_class]}
64-
>
65-
{render_slot(empty_state)}
66-
</.td>
67-
</.tr>
68-
<% end %>
58+
<.tr :if={@empty_state != []} id={@id <> "-empty"} class="hidden only:table-row">
59+
<.td
60+
:for={empty_state <- @empty_state}
61+
colspan={length(@col)}
62+
class={empty_state[:row_class]}
63+
>
64+
{render_slot(empty_state)}
65+
</.td>
66+
</.tr>
6967
<.tr
7068
:for={row <- @rows}
7169
id={@row_id && @row_id.(row)}

0 commit comments

Comments
 (0)