Previews

No matching results.

x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<div class="p-8 space-y-4">
<turbo-frame id="users-table">
<form data-turbo-frame="users-table" action="#" accept-charset="UTF-8" method="get">
<input type="hidden" name="sort" id="sort" value="name" autocomplete="off" />
<input type="hidden" name="dir" id="dir" value="asc" autocomplete="off" />
<div class="flex items-center gap-2 flex-wrap">
<input type="text" name="search" id="search" value="Alice" placeholder="Search by name…" class="midwest-input" autocomplete="off" aria-label="Search" />
<select name="role" id="role" class="midwest-input" aria-label="Role"><option value="">All roles</option>
<option value="Designer">Designer</option>
<option value="Engineer">Engineer</option>
<option value="Manager">Manager</option></select>
<input type="submit" name="commit" value="Filter" class="midwest-btn" data-disable-with="Filter" />
<a class="midwest-btn variant-ghost" href="?sort=name&dir=asc">Clear</a>
</div>
</form>
<div class="flex items-center gap-2 text-sm text-gray-11">
<span>Active filters:</span>
<span class="midwest-badge size-default theme-primary">
<span class="value">Alice</span>
</span>
</div>
<div data-controller="midwest-table" class="midwest-table-wrapper">
<div class="midwest-table-loading-overlay" aria-hidden="true">
<div class="midwest-loading-icon" role="img" aria-label="Loading" decorative="true">
<div class="midwest-loading-icon-inner">
<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->
<svg viewbox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="Midwest-LoadingIcon__Svg" focusable="false" aria-hidden="true">
<circle cx="15" cy="15" r="15">
<animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate>
<animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate>
</circle>
<circle cx="60" cy="15" r="9" fill-opacity="0.3">
<animate attributename="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcmode="linear" repeatcount="indefinite"></animate>
<animate attributename="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcmode="linear" repeatcount="indefinite"></animate>
</circle>
<circle cx="105" cy="15" r="15">
<animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate>
<animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate>
</circle>
</svg>
</div>
</div>
</div>
<div class="midwest-table-scroll">
<table class="midwest-table">
<caption class="sr-only">Users</caption>
<thead class="midwest-table-head">
<tr>
<th scope="col" class="midwest-table-th align-start sortable sorted" aria-sort="ascending">
<a class="midwest-table-sort-link" href="?sort=name&dir=desc&search=Alice">
Name
<span class="midwest-table-sort-icon" aria-hidden="true"></span>
</a>
</th>
<th scope="col" class="midwest-table-th align-start sortable" aria-sort="none">
<a class="midwest-table-sort-link" href="?sort=email&dir=asc&search=Alice">
Email
<span class="midwest-table-sort-icon" aria-hidden="true"></span>
</a>
</th>
<th scope="col" class="midwest-table-th align-start sortable" aria-sort="none">
<a class="midwest-table-sort-link" href="?sort=role&dir=asc&search=Alice">
Role
<span class="midwest-table-sort-icon" aria-hidden="true"></span>
</a>
</th>
</tr>
</thead>
<tbody class="midwest-table-body">
<tr class="midwest-table-row">
<td class="midwest-table-td align-start">
Alice Johnson
</td>
<td class="midwest-table-td align-start">
alice@example.com
</td>
<td class="midwest-table-td align-start">
Engineer
</td>
</tr>
<tr class="midwest-table-row">
<td class="midwest-table-td align-start">
Alice Chan
</td>
<td class="midwest-table-td align-start">
achan@example.com
</td>
<td class="midwest-table-td align-start">
Designer
</td>
</tr>
</tbody>
</table>
</div>
<div class="midwest-table-pagination">
<nav class="midwest-pagination variant-default" aria-label="Pagination">
<div class="midwest-pagination-controls">
<span class="midwest-pagination-btn is-prev is-disabled" aria-disabled="true" aria-label="Previous page">
<div class="midwest-icon " aria-hidden="true">
<div class="midwest-icon-inner">
<svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" role="img" aria-label="Arrow back"><title>Arrow back</title>
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M244 400L100 256l144-144M120 256h292"></path></svg>
</div>
</div>
</span>
<span class="midwest-pagination-btn is-current" aria-current="page">1</span>
<a class="midwest-pagination-btn" aria-label="Go to page 2" href="?sort=name&dir=asc&search=Alice&page=2">2</a>
<a class="midwest-pagination-btn" aria-label="Go to page 3" href="?sort=name&dir=asc&search=Alice&page=3">3</a>
<a class="midwest-pagination-btn is-next" aria-label="Go to next page" href="?sort=name&dir=asc&search=Alice&page=2">
<div class="midwest-icon " aria-hidden="true">
<div class="midwest-icon-inner">
<svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" role="img" aria-label="Arrow forward"><title>Arrow forward</title>
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M268 112l144 144-144 144M392 256H100"></path></svg>
</div>
</div>
</a> </div>
</nav>
</div>
</div>
</turbo-frame></div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<%
# --------------------------------------------------------------------------
# Midwest::TurboTable — filtering usage guide
#
# 1. Declare filter params in the turbo_table macro:
#
# turbo_table :users,
# default_sort: :name,
# allowed_sorts: %i[name email role created_at],
# filter_params: %i[search role]
#
# 2. Apply filters in the action:
#
# def index
# scope = User.order(table_order).page(table_page)
# scope = scope.where("name ILIKE ?", "%#{table_filter(:search)}%") if table_filter(:search)
# scope = scope.where(role: table_filter(:role)) if table_filter(:role)
# @users = scope
# end
#
# 3. In your view, wrap everything in turbo_frame_tag and use
# midwest_filter_form_tag to render the filter controls.
# Sort/page/per_page state is preserved as hidden inputs automatically.
# --------------------------------------------------------------------------
# Simulated state for the preview (normally comes from the concern helpers)
current_sort = :name
current_direction = :asc
current_page = 1
current_search = 'Alice'
current_role = nil
frame_id = 'users-table'
sort_url = ->(col) {
dir = (current_sort == col && current_direction == :asc) ? 'desc' : 'asc'
"?sort=#{col}&dir=#{dir}&search=#{current_search}"
}
row_class = Struct.new(:id, :name, :email, :role, keyword_init: true)
all_rows = [
row_class.new(id: 1, name: 'Alice Johnson', email: 'alice@example.com', role: 'Engineer'),
row_class.new(id: 2, name: 'Bob Smith', email: 'bob@example.com', role: 'Designer'),
row_class.new(id: 3, name: 'Carol White', email: 'carol@example.com', role: 'Manager'),
row_class.new(id: 4, name: 'David Lee', email: 'david@example.com', role: 'Engineer'),
row_class.new(id: 5, name: 'Alice Chan', email: 'achan@example.com', role: 'Designer'),
]
# Simulate the search filter
rows = all_rows.select { |r| r.name.downcase.include?(current_search.downcase) }
roles = all_rows.map(&:role).uniq.sort
active_filters = current_search.present? || current_role.present?
%>
<div class="p-8 space-y-4">
<%# In a real view this would be: turbo_frame_tag midwest_table_frame_id %>
<%= turbo_frame_tag frame_id do %>
<%# In a real view this would be: midwest_filter_form_tag do %>
<%= form_tag('#', method: :get, data: { turbo_frame: frame_id }) do %>
<%= hidden_field_tag :sort, current_sort %>
<%= hidden_field_tag :dir, current_direction %>
<div class="flex items-center gap-2 flex-wrap">
<%= text_field_tag :search, current_search,
placeholder: 'Search by name…',
class: 'midwest-input',
autocomplete: 'off',
'aria-label': 'Search' %>
<%= select_tag :role,
options_for_select([['All roles', '']] + roles.map { |r| [r, r] }, current_role),
class: 'midwest-input',
'aria-label': 'Role' %>
<%= submit_tag 'Filter', class: 'midwest-btn' %>
<% if active_filters %>
<%= link_to 'Clear', '?sort=name&dir=asc', class: 'midwest-btn variant-ghost' %>
<% end %>
</div>
<% end %>
<% if active_filters %>
<div class="flex items-center gap-2 text-sm text-gray-11">
<span>Active filters:</span>
<% if current_search.present? %>
<%= midwest_badge(current_search) %>
<% end %>
</div>
<% end %>
<%= midwest_table(collection: rows, caption: 'Users') do |t| %>
<% t.with_column 'Name', key: :name, sortable: true, sorted: current_sort == :name, sort_direction: current_direction, sort_url: sort_url.call(:name) %>
<% t.with_column 'Email', key: :email, sortable: true, sorted: current_sort == :email, sort_direction: current_direction, sort_url: sort_url.call(:email) %>
<% t.with_column 'Role', key: :role, sortable: true, sorted: current_sort == :role, sort_direction: current_direction, sort_url: sort_url.call(:role) %>
<% t.with_empty_state do %>
No users match your filters.
<%= link_to 'Clear filters', '#' %>
<% end %>
<% t.with_pagination do %>
<%= midwest_pagination(current_page: current_page, total_pages: 3,
page_url: ->(p) { "?sort=#{current_sort}&dir=#{current_direction}&search=#{current_search}&page=#{p}" }) %>
<% end %>
<% end %>
<% end %>
</div>

No assets to display.
Add a .js or .css file alongside the component to see it here.

Accessibility

Figma embed for Table/with_filters

Annotate a preview to embed its Figma design here:

@figma "https://figma.com/..."