infotable 1.4.0 → 1.4.1

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: 61eaa702c985b223c91d6da00bf84515ba067ad2a7d8dd3b6fde0c5e9eac7603
4
- data.tar.gz: edda1595d51b8ae913cecd87315a01ebf2f8788df68578ff3b45086b04c942d6
3
+ metadata.gz: f00cd7591b4bc03f8f7443771dc1be2abc2e022602a2a2b14a61090d6eea76aa
4
+ data.tar.gz: 1c48ace8adb272674a1b0138b7aa1744dfe5154695b87ea5e1773cc918d912fc
5
5
  SHA512:
6
- metadata.gz: 7e612ced33027a865095124cad1c1f2798abaab7238cb4c073da90625a7adbfa1068f5ca216e2e753766085ad5e43b6d1723255773ebc9e10dc3acfa63150634
7
- data.tar.gz: 73c8657018df5e58536b75b27e5624ef4868c5a2fb29f72d87a7a258a8cb813c51184188d1b2b6bc9de576cf94605eab850cee545bf76e71eaf53198b0fe2a32
6
+ metadata.gz: 9ed45ecaf4c41b844dd6a7df34e35bcecefe593fa146fbe352ec9c6e4b20501f7661464a383f6a6ae386190e13d6a4cb395765c6ea4450f1d2637f442256c148
7
+ data.tar.gz: 79fae3ddc36f3c98c826eb18fcb9856f810e5d8fd2681eb9244ba3577efa7a397b384eb8bb170c791cd1668c5c5f5e444f546553d55cffb0cd099813555366bd
@@ -848,11 +848,20 @@ export default class extends Controller {
848
848
  const cells = table.querySelectorAll(`th[data-column-name="${escaped}"], td[data-column-name="${escaped}"]`)
849
849
 
850
850
  cells.forEach(cell => {
851
- if (cell.dataset.defaultWidth === undefined) cell.dataset.defaultWidth = cell.style.width
852
- const value = width === null ? cell.dataset.defaultWidth : `${width}px`
853
- cell.style.width = value
854
- cell.style.maxWidth = value
855
- cell.style.minWidth = width === null ? "" : value
851
+ // Remember how the server rendered the cell (action columns have width/min-width but no max-width)
852
+ if (cell.dataset.defaultWidth === undefined) {
853
+ cell.dataset.defaultWidth = cell.style.width
854
+ cell.dataset.defaultMaxWidth = cell.style.maxWidth
855
+ cell.dataset.defaultMinWidth = cell.style.minWidth
856
+ }
857
+
858
+ if (width === null) {
859
+ cell.style.width = cell.dataset.defaultWidth
860
+ cell.style.maxWidth = cell.dataset.defaultMaxWidth
861
+ cell.style.minWidth = cell.dataset.defaultMinWidth
862
+ } else {
863
+ cell.style.width = cell.style.maxWidth = cell.style.minWidth = `${width}px`
864
+ }
856
865
  })
857
866
  }
858
867
 
@@ -28,6 +28,17 @@ module Infotable
28
28
  render partial: "infotable/tables/table", locals: locals
29
29
  end
30
30
 
31
+ # Inline width style for a header/body cell. Data columns are clipped to their width (ellipsis);
32
+ # action columns hold buttons, so their width is only a minimum and the column grows to fit all
33
+ # of them (a clipped "Delete" button is worse than a wider column).
34
+ def infotable_cell_width_style(column, ellipsis: false)
35
+ if %w[action actions].include?(column[:type].to_s)
36
+ "width: 1%; min-width: #{column[:width]}; white-space: nowrap;"
37
+ else
38
+ "width: #{column[:width]}; max-width: #{column[:width]}; overflow: hidden;#{' text-overflow: ellipsis;' if ellipsis}"
39
+ end
40
+ end
41
+
31
42
  # Format cell value based on column definition
32
43
  def format_cell_value(record, column, table_class = nil)
33
44
  value = (table_class || Infotable::Base).cell_value(record, column)
@@ -29,7 +29,7 @@
29
29
  <% table_class.columns.each do |column| %>
30
30
  <td data-column-name="<%= column[:name] %>"
31
31
  data-default-visible="<%= column[:visible] %>"
32
- style="width: <%= column[:width] %>; max-width: <%= column[:width] %>; overflow: hidden; text-overflow: ellipsis;"
32
+ style="<%= infotable_cell_width_style(column, ellipsis: true) %>"
33
33
  class="<%= cell_padding %> whitespace-nowrap <%= text_size %> text-gray-700 dark:text-gray-300">
34
34
  <%= format_cell_value(record, column, table_class) %>
35
35
  </td>
@@ -34,7 +34,7 @@
34
34
  data-column-name="<%= column[:name] %>"
35
35
  data-default-visible="<%= column[:visible] %>"
36
36
  <%= tag.attributes(data: { default_pinned: column[:pinned] }) if column[:pinned] %>
37
- style="width: <%= column[:width] %>; max-width: <%= column[:width] %>; overflow: hidden;"
37
+ style="<%= infotable_cell_width_style(column) %>"
38
38
  class="<%= header_padding %> text-left text-xs font-semibold text-gray-900 dark:text-gray-100 tracking-wider select-none bg-gray-50 dark:bg-gray-800 sticky top-0 z-20">
39
39
  <% if column[:sortable] %>
40
40
  <% sort_index = current_sorts.index { |name, _| name == column[:name].to_s } %>
@@ -1,3 +1,3 @@
1
1
  module Infotable
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Cieślar