Skip to content

Commit ed7b4ec

Browse files
committed
try table component
1 parent 41d8a0c commit ed7b4ec

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

app/assets/tailwind/application.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,30 @@
4545
.form-input {
4646
@apply block shadow-sm rounded-md border border-gray-400 outline-hidden px-3 py-2 mt-2 w-full;
4747
}
48+
49+
/* Responsive table that displays as cards on mobile and table on desktop */
50+
.table-responsive {
51+
@apply overflow-x-auto rounded-box border border-base-content/5 bg-base-100;
52+
}
53+
54+
.table-responsive table {
55+
/* @apply du-table du-table-zebra du-table-xs du-table-pin-rows w-full; */
56+
}
57+
58+
.table-responsive thead {
59+
@apply hidden lg:table-header-group;
60+
}
61+
62+
.table-responsive tbody {
63+
@apply block lg:table-row-group;
64+
}
65+
66+
.table-responsive tr {
67+
@apply block lg:table-row lg:mb-0 overflow-hidden lg:overflow-auto;
68+
}
69+
70+
.table-responsive td {
71+
@apply block lg:table-cell lg:text-left;
72+
@apply before:content-[attr(data-label)] before:font-bold before:inline-block before:mr-2;
73+
@apply lg:before:content-none;
74+
}

app/views/organizations/index.html.erb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010
<%#= render collection: @organizations, partial: "organizations/organization", as: :organization %>
1111
</div>
1212

13-
<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100">
14-
<table class="du-table du-table-zebra du-table-xs du-table-pin-rows w-full">
15-
<thead class="hidden lg:table-header-group">
13+
<div class="table-responsive">
14+
<table>
15+
<thead>
1616
<tr>
1717
<th>Name</th>
1818
<th>Members count</th>
1919
<th>Created</th>
2020
<th>Actions</th>
2121
</tr>
2222
</thead>
23-
<tbody class="block lg:table-row-group">
23+
<tbody>
2424
<% @organizations.each do |organization| %>
25-
<tr class="block lg:table-row lg:mb-0 overflow-hidden lg:overflow-auto">
26-
<td class="block lg:table-cell lg:text-left before:content-[attr(data-label)] before:font-bold before:inline-block before:mr-2 lg:before:content-none" data-label="Name:">
25+
<tr>
26+
<td data-label="Name:">
2727
<div class="flex items-center gap-2">
2828
<%= organization_avatar(organization) %>
2929
<%= organization.name %>
3030
</div>
3131
</td>
32-
<td class="block lg:table-cell lg:text-left before:content-[attr(data-label)] before:font-bold before:inline-block before:mr-2 lg:before:content-none" data-label="Members count:"><%= organization.memberships.count %></td>
33-
<td class="block lg:table-cell lg:text-left before:content-[attr(data-label)] before:font-bold before:inline-block before:mr-2 lg:before:content-none" data-label="Created At:"><%= time_ago_in_words(organization.created_at) %> ago</td>
34-
<td class="block lg:table-cell lg:text-left before:content-[attr(data-label)] before:font-bold before:inline-block before:mr-2 lg:before:content-none" data-label="Actions:"><%= link_to "Show", organization_path(organization), class: "text-blue-600 hover:underline" %></td>
32+
<td data-label="Members count:"><%= organization.memberships.count %></td>
33+
<td data-label="Created At:"><%= time_ago_in_words(organization.created_at) %> ago</td>
34+
<td data-label="Actions:"><%= link_to "Show", organization_path(organization), class: "text-blue-600 hover:underline" %></td>
3535
</tr>
3636
<% end %>
3737
</tbody>

0 commit comments

Comments
 (0)