keystone_ui 0.67.0 → 0.69.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: 242ba3582b1b737bc9ed499a24fb27d75a7c8df5dd59f341d603ba2a9d99dea3
4
+ data.tar.gz: 020b9c44d78a728488c8033ad8b602df920707c910bc77c60496722a30802e80
5
5
  SHA512:
6
- metadata.gz: cf6f54d40679fef624f92677ea73a6a7d1e971e4862d7fe4a143c2ea3e719b2308cc53f3254791dbf433c24b80294e37c589cc69903579f31a7a8e6069835365
7
- data.tar.gz: 26d67e1aca96aae7cc79faddc7476a6198007a96419a08c8b10cf2a7c1ea522af7d8220ca9920f6cd36165a84c6e911fc73c5596e023739e6aca8359e640371a
6
+ metadata.gz: e760beb28f6a1cc0fe374e0b61c248f3451948315dfa85fa96e6cfb39003b8bc8688a4a1cde74a1d11e51189cc88711ca9c8b067dc96c4d22c4085f1f4e70341
7
+ data.tar.gz: 5a7ed82c290d4e3e93756c7bf0ce6cf44c7d4b04abb6c36692f057df249e36b0a28b885c7e4a42f21f59865096279d7082effdc84cb8f77e8aa078c54afc26e5
@@ -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
 
@@ -16,7 +16,19 @@ module Keystone
16
16
  end
17
17
 
18
18
  def call
19
- link_to(PLUS_ICON.html_safe, content_for(:mobile_action_url), class: LINK_CLASSES, aria: { label: content_for(:mobile_action_label) })
19
+ return link_to(PLUS_ICON.html_safe, url, **options) unless content_for?(:mobile_action_method)
20
+
21
+ button_to(url, method: content_for(:mobile_action_method), **options) { PLUS_ICON.html_safe }
22
+ end
23
+
24
+ private
25
+
26
+ def url
27
+ content_for(:mobile_action_url)
28
+ end
29
+
30
+ def options
31
+ { class: LINK_CLASSES, aria: { label: content_for(:mobile_action_label) } }
20
32
  end
21
33
  end
22
34
  end
@@ -2,6 +2,7 @@
2
2
  <% if action_url %>
3
3
  <% content_for :mobile_action_url, action_url %>
4
4
  <% content_for :mobile_action_label, action_label %>
5
+ <% content_for :mobile_action_method, action_method.to_s if action_method %>
5
6
  <% end %>
6
7
  <div class="<%= wrapper_classes %>">
7
8
  <div>
@@ -16,7 +17,7 @@
16
17
  </div>
17
18
  <% elsif action_url %>
18
19
  <div class="<%= ACTIONS_CLASSES %>">
19
- <%= render Keystone::Ui::ButtonComponent.new(label: action_label, href: action_url) %>
20
+ <%= render Keystone::Ui::ButtonComponent.new(label: action_label, href: action_url, method: action_method || :get) %>
20
21
  </div>
21
22
  <% end %>
22
23
  </div>
@@ -8,13 +8,14 @@ module Keystone
8
8
  SUBTITLE_CLASSES = "ks-page-header-subtitle"
9
9
  ACTIONS_CLASSES = "page-header-actions ks-page-header-actions"
10
10
 
11
- attr_reader :title, :action_url, :action_label
11
+ attr_reader :title, :action_url, :action_label, :action_method
12
12
 
13
- def initialize(title:, subtitle: nil, action_url: nil, action_label: "Add new", class: nil)
13
+ def initialize(title:, subtitle: nil, action_url: nil, action_label: "Add new", action_method: nil, class: nil)
14
14
  @title = title
15
15
  @subtitle = subtitle
16
16
  @action_url = action_url
17
17
  @action_label = action_label
18
+ @action_method = action_method
18
19
  @action_block = nil
19
20
  @extra_classes = binding.local_variable_get(:class)
20
21
  end
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.69.0"
5
5
  end
@@ -168,13 +168,15 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
168
168
  - Ask the developer whether a screen shows breadcrumbs and which parent
169
169
  screens its trail names. Ask which screens a navigation tab opens
170
170
  directly, since those pass `trail: []`.
171
- - `ui_page_header(title:, subtitle: nil, action_url: nil, action_label: "Add new", class: nil)`
171
+ - `ui_page_header(title:, subtitle: nil, action_url: nil, action_label: "Add new", action_method: nil, class: nil)`
172
172
  takes a block yielding the header and is hidden below `sm:`. Call
173
173
  `header.action { ... }` in the block to place a control on its right.
174
174
  `action_url:` declares the screen's main action. It publishes that URL and
175
175
  label for `ui_mobile_action` to pick up, and with no `action` block the
176
176
  header draws them as a button. An `action` block is drawn alone when both
177
- are given.
177
+ are given. `action_method:`, such as `:post`, makes the main action send
178
+ that method: the header's button and `ui_mobile_action`'s icon become
179
+ forms posting to `action_url:`.
178
180
  - `ui_breadcrumbs(trail:, current: nil)` renders `trail:` as links separated
179
181
  by `›`, then `current:` unlinked and marked as the current page, shown
180
182
  only from `lg:` up. On a form or detail screen pass `trail:` to the shell
@@ -455,6 +457,19 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
455
457
  `KeyError`. Colour alone does not reach every reader, so also make the
456
458
  row's meaning readable as text in the row, such as a status badge or a
457
459
  word in a cell.
460
+ - `table.row_detail { |item| ... }` gives a row detail that opens under
461
+ it. The block is ERB, so it may hold helpers such as `ui_value_list`.
462
+ What it renders is drawn in a hidden row under the item's row, in one
463
+ unstyled cell across every column, and a block that renders `nil` or
464
+ nothing but whitespace gives that row no detail and no caret. A row with
465
+ detail opens and closes when it is clicked or when Enter or Space is
466
+ pressed on the caret button at the start of its first cell. A click on a
467
+ link, button, form control, label or `summary` in the row does what it
468
+ always does and leaves the row as it is, so the action menu and linked
469
+ cells still work. An open row stays open through a Turbo refresh morph.
470
+ Use it when a table should show a few columns and still hold more about
471
+ each row, rather than adding columns or a second table, and ask the
472
+ developer what the detail shows.
458
473
  - Sorting needs all three of `sort:` (the current column key),
459
474
  `sort_direction:` (`:asc` or `:desc`) and `sort_url:` (a lambda taking
460
475
  `(column_key, direction)` and returning a URL). Headers then render as
@@ -668,8 +683,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
668
683
  If a piece renders unstyled where it should not — an info button that
669
684
  shows nothing, a breakdown in one run of text, a `:success` or `:danger`
670
685
  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
686
+ others show through, a Columns menu with no greyed name for a hidden
687
+ column, or a table row whose caret does not open its detail — the app's Stimulus controllers or keystone_ui-styles version are
673
688
  out of date. Stop and hand that part to `keystone_ui-install`, and add no
674
689
  classes to fix it.
675
690
 
@@ -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.69.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