keystone_ui 0.67.0 → 0.68.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: e4db5d4f9a772d0b8370d841b7c8a294e5be90cfa2d3264d99e9d1c25ed2ebd7
4
- data.tar.gz: 53019277eb7eb6f1d7f55964e70790fb6742739e4e525709a61b0e7fc001bd87
3
+ metadata.gz: f3adbe1de494b0337aa1e5334b0511552b7f7e1540c7ce124983c869a664a93e
4
+ data.tar.gz: 213811db56e2a2d88ffbe08a318fc1def8a6742f603c3ad2139a18a3e611594c
5
5
  SHA512:
6
- metadata.gz: cf6f54d40679fef624f92677ea73a6a7d1e971e4862d7fe4a143c2ea3e719b2308cc53f3254791dbf433c24b80294e37c589cc69903579f31a7a8e6069835365
7
- data.tar.gz: 26d67e1aca96aae7cc79faddc7476a6198007a96419a08c8b10cf2a7c1ea522af7d8220ca9920f6cd36165a84c6e911fc73c5596e023739e6aca8359e640371a
6
+ metadata.gz: 959c1ba6f2c0cf5687f05607010d5224378aa7a2c6109670783a61d245b21711614f2c812d432de6e380a134fb9a21cdbe93c14c8d051da726e7284485f8a577
7
+ data.tar.gz: 60ad1964614d17a15c267512d1404ff9245fb897ba35d66d128b5c04b33a9f7757eceb527a02066b4537fdcb52192b36c673309cebcb18db1676a7017df3dce9
@@ -17,6 +17,7 @@ import InfoController from "keystone_ui/info_controller"
17
17
  import AutoSubmitController from "keystone_ui/auto_submit_controller"
18
18
  import LineChartController from "keystone_ui/line_chart_controller"
19
19
  import ThemeToggleController from "keystone_ui/theme_toggle_controller"
20
+ import RowDetailController from "keystone_ui/row_detail_controller"
20
21
  import { keepPageThemeInStep } from "keystone_ui/page_theme"
21
22
 
22
23
  export function registerControllers(application) {
@@ -39,6 +40,7 @@ export function registerControllers(application) {
39
40
  application.register("auto-submit", AutoSubmitController)
40
41
  application.register("line-chart", LineChartController)
41
42
  application.register("theme-toggle", ThemeToggleController)
43
+ application.register("row-detail", RowDetailController)
42
44
  keepPageThemeInStep()
43
45
  }
44
46
 
@@ -0,0 +1,24 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ const CONTROLS = "a, button, input, select, textarea, label, summary"
4
+ const KEPT_ATTRIBUTES = ["hidden", "aria-expanded"]
5
+
6
+ export default class extends Controller {
7
+ toggle(event) {
8
+ const button = event.currentTarget.querySelector("[data-row-detail-target=toggle]")
9
+ const control = event.target.closest(CONTROLS)
10
+ if (control && control !== button) return
11
+
12
+ const detail = this.element.querySelector(`[id="${button.getAttribute("aria-controls")}"]`)
13
+ const open = button.getAttribute("aria-expanded") !== "true"
14
+
15
+ button.setAttribute("aria-expanded", String(open))
16
+ detail.hidden = !open
17
+ }
18
+
19
+ keep(event) {
20
+ if (!event.target.getAttribute("data-row-detail-target")) return
21
+
22
+ if (KEPT_ATTRIBUTES.includes(event.detail.attributeName)) event.preventDefault()
23
+ }
24
+ }
@@ -25,7 +25,7 @@
25
25
  <% end %>
26
26
  </tr>
27
27
  </thead>
28
- <tbody class="<%= Keystone::Ui::DataTableComponent::BODY_CLASSES %>">
28
+ <tbody class="<%= Keystone::Ui::DataTableComponent::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>
@@ -44,9 +44,13 @@
44
44
  <% if actions? %><th></th><% end %>
45
45
  </tr>
46
46
  <% end %>
47
- <tr<% if (classes = row_classes(idx)) %> class="<%= classes %>"<% end %><% if current_row?(idx) %> aria-current="true"<% end %>>
48
- <% row_cells[idx].each do |cell| %>
47
+ <% detail = capture(item, &@row_detail_block) if row_detail? %>
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
+ <% row_cells[idx].each_with_index do |cell, cell_index| %>
49
50
  <td class="<%= cell[:classes] %>">
51
+ <% if detail.present? && cell_index.zero? %>
52
+ <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
+ <% end %>
50
54
  <% if cell[:href] %>
51
55
  <a href="<%= cell[:href] %>"><%= cell[:value] %></a>
52
56
  <% else %>
@@ -65,6 +69,11 @@
65
69
  </td>
66
70
  <% end %>
67
71
  </tr>
72
+ <% if detail.present? %>
73
+ <tr id="<%= row_detail_id(idx) %>" hidden data-row-detail-target="detail">
74
+ <td colspan="<%= column_count %>"><%= detail %></td>
75
+ </tr>
76
+ <% end %>
68
77
  <% end %>
69
78
  <% end %>
70
79
  </tbody>
@@ -12,6 +12,7 @@ module Keystone
12
12
  success: "ks-table-row-success",
13
13
  info: "ks-table-row-info"
14
14
  }.freeze
15
+ DETAIL_BUTTON_CLASSES = "ks-disclosure-icon inline-flex align-middle transition-transform aria-expanded:rotate-180"
15
16
  HEAD_CLASSES = "ks-table-head"
16
17
  WRAPPER_CLASSES = "ks-table overflow-x-auto"
17
18
  TOOLBAR_CLASSES = "ks-table-toolbar flex justify-end"
@@ -73,6 +74,18 @@ module Keystone
73
74
  @row_colour_block = block
74
75
  end
75
76
 
77
+ def row_detail(&block)
78
+ @row_detail_block = block
79
+ end
80
+
81
+ def row_detail?
82
+ !!@row_detail_block
83
+ end
84
+
85
+ def row_detail_id(index)
86
+ "row-detail-#{resolve_value(@items[index], :id) || index}"
87
+ end
88
+
76
89
  def row_classes(index)
77
90
  classes = [ (CURRENT_ROW_CLASSES if current_row?(index)), row_colour_class(@items[index]) ].compact
78
91
 
data/config/importmap.rb CHANGED
@@ -18,6 +18,7 @@ pin "keystone_ui/info_controller", to: "keystone_ui/info_controller.js"
18
18
  pin "keystone_ui/auto_submit_controller", to: "keystone_ui/auto_submit_controller.js"
19
19
  pin "keystone_ui/line_chart_controller", to: "keystone_ui/line_chart_controller.js"
20
20
  pin "keystone_ui/theme_toggle_controller", to: "keystone_ui/theme_toggle_controller.js"
21
+ pin "keystone_ui/row_detail_controller", to: "keystone_ui/row_detail_controller.js"
21
22
  pin "keystone_ui/page_theme", to: "keystone_ui/page_theme.js"
22
23
 
23
24
  # Chart.js for the line-chart controller, so host apps don't pin it themselves.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.67.0"
4
+ VERSION = "0.68.0"
5
5
  end
@@ -455,6 +455,19 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
455
455
  `KeyError`. Colour alone does not reach every reader, so also make the
456
456
  row's meaning readable as text in the row, such as a status badge or a
457
457
  word in a cell.
458
+ - `table.row_detail { |item| ... }` gives a row detail that opens under
459
+ it. The block is ERB, so it may hold helpers such as `ui_value_list`.
460
+ What it renders is drawn in a hidden row under the item's row, in one
461
+ unstyled cell across every column, and a block that renders `nil` or
462
+ nothing but whitespace gives that row no detail and no caret. A row with
463
+ detail opens and closes when it is clicked or when Enter or Space is
464
+ pressed on the caret button at the start of its first cell. A click on a
465
+ link, button, form control, label or `summary` in the row does what it
466
+ always does and leaves the row as it is, so the action menu and linked
467
+ cells still work. An open row stays open through a Turbo refresh morph.
468
+ Use it when a table should show a few columns and still hold more about
469
+ each row, rather than adding columns or a second table, and ask the
470
+ developer what the detail shows.
458
471
  - Sorting needs all three of `sort:` (the current column key),
459
472
  `sort_direction:` (`:asc` or `:desc`) and `sort_url:` (a lambda taking
460
473
  `(column_key, direction)` and returning a URL). Headers then render as
@@ -668,8 +681,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
668
681
  If a piece renders unstyled where it should not — an info button that
669
682
  shows nothing, a breakdown in one run of text, a `:success` or `:danger`
670
683
  figure in plain colour, a joined funnel with no band, a locked column the
671
- others show through, or a Columns menu with no greyed name for a hidden
672
- column — the app's Stimulus controllers or keystone_ui-styles version are
684
+ others show through, a Columns menu with no greyed name for a hidden
685
+ column, or a table row whose caret does not open its detail — the app's Stimulus controllers or keystone_ui-styles version are
673
686
  out of date. Stop and hand that part to `keystone_ui-install`, and add no
674
687
  classes to fix it.
675
688
 
@@ -78,6 +78,11 @@ One decision: is keystone_ui set up in the app?
78
78
  it: which hideable columns to hide and their order. With a save address, a
79
79
  "Columns" menu lets the user change it. A locked first column stays in view
80
80
  while the table scrolls sideways and is never hidden or moved.
81
+ - **Row detail.** A data table can give each row more to show than its
82
+ columns. That detail sits in a hidden row under its row, across every column,
83
+ and clicking the row or its caret button opens and closes it. Links, buttons
84
+ and the action menu inside the row work without opening it. A row with no
85
+ detail does not open, and an open row stays open through a Turbo morph.
81
86
  - **Search dropdowns.** A search dropdown picks one record by its id from
82
87
  matches the host serves. As the user types, it requests the host's search
83
88
  address with the text as `q` and expects JSON back: a list of matches, each
@@ -107,8 +112,9 @@ One decision: is keystone_ui set up in the app?
107
112
  scanner finds them. Sizes that depend on data, such as a progress bar's
108
113
  width, use an inline style. The host needs tailwindcss-rails v4+.
109
114
  - **Interactivity is Stimulus.** Dropdowns, search dropdowns, modals, tab
110
- switchers, the column picker, info buttons, charts, copy buttons and the theme toggle ship as
115
+ switchers, the column picker, table row detail, info buttons, charts, copy
116
+ buttons and the theme toggle ship as
111
117
  Stimulus controllers, so a host writes no JavaScript. Components that post,
112
118
  such as the column picker and the pipeline, post to endpoints the host or
113
119
  another gem owns.
114
- - Ruby >= 3.2, ViewComponent >= 2.0 and < 5, keystone_ui-styles >= 0.25.0.
120
+ - Ruby >= 3.2, ViewComponent >= 2.0 and < 5, keystone_ui-styles >= 0.29.0.
@@ -50,7 +50,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
50
50
  ## How to use it
51
51
 
52
52
  1. Confirm the prerequisites: Ruby >= 3.2 and **tailwindcss-rails v4+** in the
53
- host app. The gem brings ViewComponent and keystone_ui-styles 0.25.0 or later with it.
53
+ host app. The gem brings ViewComponent and keystone_ui-styles 0.29.0 or later with it.
54
54
  Tailwind does not have to be initialized first, because the generator creates
55
55
  the stylesheet if it is missing.
56
56
 
@@ -92,8 +92,9 @@ built on ViewComponent; hook it in before building any screen with those helpers
92
92
  - `app/javascript/controllers/index.js not found` — ask the developer where
93
93
  the Stimulus application is set up and add those two lines there. Without
94
94
  them, dropdowns, modals, file uploads, the column picker, the theme toggle,
95
- the info button's popups, the search select's list of matches and the other
96
- interactive components do nothing.
95
+ the info button's popups, the search select's list of matches, a data
96
+ table row's detail toggle and the other interactive components do
97
+ nothing.
97
98
  `registerControllers(application)` also copies `data-theme` and `data-look`
98
99
  from each page Turbo renders onto the `<html>` tag. Without it, a Turbo
99
100
  visit keeps the theme and look of the first page loaded.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.67.0
4
+ version: 0.68.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -67,6 +67,7 @@ files:
67
67
  - app/assets/javascripts/keystone_ui/modal_controller.js
68
68
  - app/assets/javascripts/keystone_ui/multi_select_controller.js
69
69
  - app/assets/javascripts/keystone_ui/page_theme.js
70
+ - app/assets/javascripts/keystone_ui/row_detail_controller.js
70
71
  - app/assets/javascripts/keystone_ui/search_select_controller.js
71
72
  - app/assets/javascripts/keystone_ui/sortable_list_controller.js
72
73
  - app/assets/javascripts/keystone_ui/stat_card_info_controller.js