keystone_ui 0.70.0 → 0.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5355c29793674a40bcd010200e66a7f6e99ec08de1b802aab127ad42e7e0d9b7
|
|
4
|
+
data.tar.gz: '09001801fe0132be8e69116ab38b2dbe7031978ee144a0f707d35ec711a4e952'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95ce9153bafe6c8cc3a5d7e84216713f20ef8c23f6d960a97728dd1f431a0fd2f7edf9efc031f47545c588a6ca379ce1b189dd7d72c99e0b3a8946d4ef96a28b
|
|
7
|
+
data.tar.gz: 11657cd55a53830686b48b3eaf4bf9240872e4a1754fe2f1e0edf2d827eeb3976424daae2ba499d3b259425aa6e16377c03dabc3e6d2320904ae3d09c0ad2618
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
<% end %>
|
|
6
6
|
<div class="<%= Keystone::Ui::DataTableComponent::WRAPPER_CLASSES %>">
|
|
7
|
-
<table class="
|
|
8
|
-
<thead class="<%=
|
|
7
|
+
<table class="<%= table_classes %> divide-y divide-gray-300 dark:divide-white/15">
|
|
8
|
+
<thead class="<%= head_classes %>">
|
|
9
9
|
<tr>
|
|
10
10
|
<% header_cells.each do |cell| %>
|
|
11
11
|
<th scope="<%= cell[:scope] %>" class="<%= cell[:classes] %>">
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<% end %>
|
|
26
26
|
</tr>
|
|
27
27
|
</thead>
|
|
28
|
-
<tbody class="<%=
|
|
28
|
+
<tbody class="<%= body_classes %>"<% if row_detail? %> data-controller="row-detail" data-action="turbo:before-morph-attribute->row-detail#keep"<% end %>>
|
|
29
29
|
<% if empty? %>
|
|
30
30
|
<% if @empty_message %>
|
|
31
31
|
<tr>
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
<% else %>
|
|
38
38
|
<% @items.each_with_index do |item, idx| %>
|
|
39
39
|
<% if (group = group_starting_at(idx)) %>
|
|
40
|
-
<tr class="<%=
|
|
40
|
+
<tr class="<%= summary_row_classes %>" data-table-group>
|
|
41
41
|
<% group_cells(group).each do |cell| %>
|
|
42
|
-
<th scope="colgroup" class="<%= cell[:classes] %>"><%= cell[:value] %></th>
|
|
42
|
+
<th scope="colgroup" class="<%= cell[:classes] %>"><% if cell[:label] %><span class="<%= Keystone::Ui::DataTableComponent::CELL_LABEL_CLASSES %>"><%= cell[:label] %></span><% end %><%= cell[:value] %></th>
|
|
43
43
|
<% end %>
|
|
44
44
|
<% if actions? %><th></th><% end %>
|
|
45
45
|
</tr>
|
|
@@ -48,6 +48,9 @@
|
|
|
48
48
|
<tr<% if (classes = row_classes(idx)) %> class="<%= classes %>"<% end %><% if current_row?(idx) %> aria-current="true"<% end %><% if detail.present? %> data-action="click->row-detail#toggle"<% end %>>
|
|
49
49
|
<% row_cells[idx].each_with_index do |cell, cell_index| %>
|
|
50
50
|
<td class="<%= cell[:classes] %>">
|
|
51
|
+
<% if cell[:label] %>
|
|
52
|
+
<span class="<%= Keystone::Ui::DataTableComponent::CELL_LABEL_CLASSES %>"><%= cell[:label] %></span>
|
|
53
|
+
<% end %>
|
|
51
54
|
<% if detail.present? && cell_index.zero? %>
|
|
52
55
|
<button type="button" class="<%= Keystone::Ui::DataTableComponent::DETAIL_BUTTON_CLASSES %>" aria-label="Show detail" aria-expanded="false" aria-controls="<%= row_detail_id(idx) %>" data-row-detail-target="toggle"><%= Keystone::Ui::DisclosureComponent::CARET_ICON.html_safe %></button>
|
|
53
56
|
<% end %>
|
|
@@ -59,7 +62,7 @@
|
|
|
59
62
|
</td>
|
|
60
63
|
<% end %>
|
|
61
64
|
<% if actions? %>
|
|
62
|
-
<td class="<%=
|
|
65
|
+
<td class="<%= actions_cell_classes %>">
|
|
63
66
|
<% row_actions = capture(item, &@actions_block) %>
|
|
64
67
|
<% if row_actions.present? %>
|
|
65
68
|
<%= render Keystone::Ui::ActionMenuComponent.new do %>
|
|
@@ -70,18 +73,18 @@
|
|
|
70
73
|
<% end %>
|
|
71
74
|
</tr>
|
|
72
75
|
<% if detail.present? %>
|
|
73
|
-
<tr id="<%= row_detail_id(idx) %>" hidden data-row-detail-target="detail">
|
|
74
|
-
<td colspan="<%= column_count %>"><%= detail %></td>
|
|
76
|
+
<tr id="<%= row_detail_id(idx) %>"<% if phone_list_block_classes %> class="<%= phone_list_block_classes %>"<% end %> hidden data-row-detail-target="detail">
|
|
77
|
+
<td<% if phone_list_block_classes %> class="<%= phone_list_block_classes %>"<% end %> colspan="<%= column_count %>"><%= detail %></td>
|
|
75
78
|
</tr>
|
|
76
79
|
<% end %>
|
|
77
80
|
<% end %>
|
|
78
81
|
<% end %>
|
|
79
82
|
</tbody>
|
|
80
83
|
<% if total_cells.any? %>
|
|
81
|
-
<tfoot class="<%=
|
|
82
|
-
<tr
|
|
84
|
+
<tfoot class="<%= summary_row_classes %>">
|
|
85
|
+
<tr<% if phone_list_block_classes %> class="<%= phone_list_block_classes %>"<% end %>>
|
|
83
86
|
<% total_cells.each do |cell| %>
|
|
84
|
-
<th scope="row" class="<%= cell[:classes] %>"><%= cell[:value] %></th>
|
|
87
|
+
<th scope="row" class="<%= cell[:classes] %>"><% if cell[:label] %><span class="<%= Keystone::Ui::DataTableComponent::CELL_LABEL_CLASSES %>"><%= cell[:label] %></span><% end %><%= cell[:value] %></th>
|
|
85
88
|
<% end %>
|
|
86
89
|
<% if actions? %><th></th><% end %>
|
|
87
90
|
</tr>
|
|
@@ -14,6 +14,7 @@ module Keystone
|
|
|
14
14
|
}.freeze
|
|
15
15
|
DETAIL_BUTTON_CLASSES = "ks-disclosure-icon inline-flex align-middle transition-transform aria-expanded:rotate-180"
|
|
16
16
|
HEAD_CLASSES = "ks-table-head"
|
|
17
|
+
TABLE_CLASSES = "relative min-w-full"
|
|
17
18
|
WRAPPER_CLASSES = "ks-table overflow-x-auto"
|
|
18
19
|
TOOLBAR_CLASSES = "ks-table-toolbar flex justify-end"
|
|
19
20
|
HEADER_CLASSES_FIRST = "ks-table-header ks-table-header-first text-left text-sm"
|
|
@@ -29,6 +30,11 @@ module Keystone
|
|
|
29
30
|
HEADER_LOCKED_CLASSES = "ks-table-header-locked sticky left-0"
|
|
30
31
|
CELL_LOCKED_CLASSES = "ks-table-cell-locked sticky left-0"
|
|
31
32
|
|
|
33
|
+
PHONE_LIST_HEAD_CLASSES = "max-sm:hidden"
|
|
34
|
+
PHONE_LIST_BLOCK_CLASSES = "max-sm:block"
|
|
35
|
+
PHONE_LIST_CELL_CLASSES = "max-sm:block max-sm:text-left max-sm:whitespace-normal"
|
|
36
|
+
CELL_LABEL_CLASSES = "ks-caption block sm:hidden"
|
|
37
|
+
|
|
32
38
|
SORT_LINK_CLASSES = "ks-table-sort-link group inline-flex items-center"
|
|
33
39
|
SORT_ICON_CLASSES = "h-4 w-4 flex-shrink-0"
|
|
34
40
|
SORT_ICON_ACTIVE = "ks-table-sort-icon-active"
|
|
@@ -38,7 +44,7 @@ module Keystone
|
|
|
38
44
|
SORT_DESC_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .75.75v10.638l3.96-4.158a.75.75 0 1 1 1.08 1.04l-5.25 5.5a.75.75 0 0 1-1.08 0l-5.25-5.5a.75.75 0 0 1 1.08-1.04l3.96 4.158V3.75A.75.75 0 0 1 10 3Z" clip-rule="evenodd" /></svg>'
|
|
39
45
|
SORT_NEUTRAL_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .55.24l3.25 3.5a.75.75 0 1 1-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 0 1-1.1-1.02l3.25-3.5A.75.75 0 0 1 10 3Zm-3.76 9.2a.75.75 0 0 1 1.06.04l2.7 2.908 2.7-2.908a.75.75 0 1 1 1.1 1.02l-3.25 3.5a.75.75 0 0 1-1.1 0l-3.25-3.5a.75.75 0 0 1 .04-1.06Z" clip-rule="evenodd" /></svg>'
|
|
40
46
|
|
|
41
|
-
def initialize(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil)
|
|
47
|
+
def initialize(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil, phone_list: false)
|
|
42
48
|
@items = items.to_a
|
|
43
49
|
@current_index = @items.index(current_row) unless current_row.nil?
|
|
44
50
|
@group_by = group_by
|
|
@@ -55,6 +61,7 @@ module Keystone
|
|
|
55
61
|
@sort_url = sort_url
|
|
56
62
|
@actions_block = nil
|
|
57
63
|
@link_blocks = {}
|
|
64
|
+
@phone_list = phone_list
|
|
58
65
|
end
|
|
59
66
|
|
|
60
67
|
def before_render
|
|
@@ -87,11 +94,35 @@ module Keystone
|
|
|
87
94
|
end
|
|
88
95
|
|
|
89
96
|
def row_classes(index)
|
|
90
|
-
classes = [ (CURRENT_ROW_CLASSES if current_row?(index)), row_colour_class(@items[index]) ].compact
|
|
97
|
+
classes = [ (CURRENT_ROW_CLASSES if current_row?(index)), row_colour_class(@items[index]), (PHONE_LIST_BLOCK_CLASSES if @phone_list) ].compact
|
|
91
98
|
|
|
92
99
|
classes.join(" ") unless classes.empty?
|
|
93
100
|
end
|
|
94
101
|
|
|
102
|
+
def table_classes
|
|
103
|
+
phone_list_classes(TABLE_CLASSES, PHONE_LIST_BLOCK_CLASSES)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def body_classes
|
|
107
|
+
phone_list_classes(BODY_CLASSES, PHONE_LIST_BLOCK_CLASSES)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def summary_row_classes
|
|
111
|
+
phone_list_classes(HEAD_CLASSES, PHONE_LIST_BLOCK_CLASSES)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def phone_list_block_classes
|
|
115
|
+
PHONE_LIST_BLOCK_CLASSES if @phone_list
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def actions_cell_classes
|
|
119
|
+
phone_list_classes(ROW_CLASSES_LAST, PHONE_LIST_BLOCK_CLASSES)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def head_classes
|
|
123
|
+
phone_list_classes(HEAD_CLASSES, PHONE_LIST_HEAD_CLASSES)
|
|
124
|
+
end
|
|
125
|
+
|
|
95
126
|
def actions?
|
|
96
127
|
!!@actions_block
|
|
97
128
|
end
|
|
@@ -159,11 +190,13 @@ module Keystone
|
|
|
159
190
|
tokens = [ row_classes_for(index) ]
|
|
160
191
|
tokens << MOBILE_HIDDEN_CLASSES if column.mobile_hidden?
|
|
161
192
|
tokens << CELL_LOCKED_CLASSES if index.zero? && column.locked?
|
|
193
|
+
tokens << PHONE_LIST_CELL_CLASSES if @phone_list && !column.mobile_hidden?
|
|
162
194
|
|
|
163
195
|
cell = {
|
|
164
196
|
value: resolve_value(item, column.key),
|
|
165
197
|
classes: wrapped(aligned(tokens.join(" "), column), column)
|
|
166
198
|
}
|
|
199
|
+
cell[:label] = column.header_text if @phone_list
|
|
167
200
|
|
|
168
201
|
link_block = @link_blocks[column.key]
|
|
169
202
|
cell[:href] = link_block.call(item) if link_block
|
|
@@ -196,19 +229,27 @@ module Keystone
|
|
|
196
229
|
return [] unless @total
|
|
197
230
|
|
|
198
231
|
@columns.map.with_index do |column, index|
|
|
199
|
-
{ value: @total[column.key.to_s], classes: aligned(header_classes_for(index), column) }
|
|
232
|
+
{ value: @total[column.key.to_s], classes: phone_list_classes(aligned(header_classes_for(index), column), PHONE_LIST_CELL_CLASSES), label: summary_label(index, column) }
|
|
200
233
|
end
|
|
201
234
|
end
|
|
202
235
|
|
|
203
236
|
def group_cells(name)
|
|
204
237
|
subtotals = @group_totals.fetch(name.to_s, {}).to_h.transform_keys(&:to_s)
|
|
205
238
|
@columns.map.with_index do |column, index|
|
|
206
|
-
{ value: index.zero? ? name : subtotals[column.key.to_s], classes: aligned(header_classes_for(index), column) }
|
|
239
|
+
{ value: index.zero? ? name : subtotals[column.key.to_s], classes: phone_list_classes(aligned(header_classes_for(index), column), PHONE_LIST_CELL_CLASSES), label: summary_label(index, column) }
|
|
207
240
|
end
|
|
208
241
|
end
|
|
209
242
|
|
|
210
243
|
private
|
|
211
244
|
|
|
245
|
+
def summary_label(index, column)
|
|
246
|
+
column.header_text if @phone_list && !index.zero?
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def phone_list_classes(classes, phone_list_classes)
|
|
250
|
+
@phone_list ? "#{classes} #{phone_list_classes}" : classes
|
|
251
|
+
end
|
|
252
|
+
|
|
212
253
|
def apply_saved_layout
|
|
213
254
|
saved = KeystoneUi.configuration.supplied_preference(helpers, @key)
|
|
214
255
|
return unless saved
|
data/lib/keystone_ui/version.rb
CHANGED
|
@@ -435,7 +435,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
|
|
|
435
435
|
|
|
436
436
|
8. Build tables.
|
|
437
437
|
|
|
438
|
-
- `ui_data_table(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil)`
|
|
438
|
+
- `ui_data_table(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil, phone_list: false)`
|
|
439
439
|
takes a block yielding the table. `items:` are records or hashes, and a
|
|
440
440
|
cell's value is the column key called on the item, or `item[key]`.
|
|
441
441
|
`group_by:` lists rows under heading rows named by that key's value,
|
|
@@ -443,6 +443,15 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
|
|
|
443
443
|
subtotals in each heading row, and `total:` (`{ column_key => value }`)
|
|
444
444
|
ends the table with a total row. Pass every subtotal and total already
|
|
445
445
|
calculated. `align: :start` or `:end` on a `Column` aligns it left or right.
|
|
446
|
+
- `phone_list: true` shows the table as a list below `sm:`. The heading
|
|
447
|
+
row is hidden there, each row is one item, and each cell sits on its own
|
|
448
|
+
line under its column's heading, starting at the left and wrapping. A
|
|
449
|
+
row's links, badges, detail button and action menu stay in its item, and
|
|
450
|
+
group subtotals and totals after the first carry their headings. Sorting
|
|
451
|
+
is not reachable below `sm:`, since the sort links are in the heading row.
|
|
452
|
+
From `sm:` up the table is unchanged, and a table without it is unchanged
|
|
453
|
+
at every width. It is chosen table by table, so ask the developer which
|
|
454
|
+
tables show as a list on a phone.
|
|
446
455
|
- `columns:` takes `{ key: "Label" }` hashes when every column is plain.
|
|
447
456
|
Switch the whole set to `Keystone::Ui::Column` objects once one column
|
|
448
457
|
needs an option.
|