keystone_ui 0.34.0 → 0.36.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: ac460729f806dac1343306018aab4560b2c75f39ad05ec5a775886c24f5084fb
4
- data.tar.gz: 89e7107f63d2d0b6f4b2b27907c464b09cc44375d12fc59e7958bae8e99efbb7
3
+ metadata.gz: d7a0b5685fe1dc1107e8e75d274e80401826ed52616ae95c20d6a288fdc5c647
4
+ data.tar.gz: 8220957d8d617f0c32c71b264c84c5bf8b992a3cc2e3bb512f3f4e0a1cbf8bb0
5
5
  SHA512:
6
- metadata.gz: '097bdb96a57af1b3b1f886b522fa4bd3a5be40f89b433be36df0c5c74ae895ba4c5dda568a6bbea8c5e32743ee6d072cd61ba553ee9d381fc90c8917399b768f'
7
- data.tar.gz: e0b238491fc14b93e2cb32e67871290bb8a5a0d606f3663c3c839a62964ce2c8a954d1f6242a158da01713eb7e1b3565f2b3371b46c7e54607cc9e4aae77967a
6
+ metadata.gz: 58889e18335df436f8b13caad57648caf6ed3e13e17b50dc5d6011ae0f8fa85ceb98a9e9fd682f90cd10729ed3d3f20603ed34e438afb09a33090ec4d7493c95
7
+ data.tar.gz: c79c624b0a0a09e83b1f6fcee1566df17c7adf96f8141a20c8ee3ed20b361ab7faa1135be33bcf41f780e68e663e78d9ba833d27af09e72c782d4763a09463da
@@ -15,33 +15,62 @@ export default class extends Controller {
15
15
 
16
16
  toggle(event) {
17
17
  event.stopPropagation()
18
- this.menuTarget.classList.toggle("hidden")
18
+ if (this.menuTarget.classList.contains("hidden")) {
19
+ this.menuTarget.classList.remove("hidden")
20
+ } else {
21
+ this.hideMenu()
22
+ }
19
23
  }
20
24
 
21
25
  close(event) {
22
26
  if (!this.element.contains(event.target)) {
23
- this.menuTarget.classList.add("hidden")
27
+ this.hideMenu()
24
28
  }
25
29
  }
26
30
 
27
- save() {
28
- this.send(this.columnOrder())
31
+ hideMenu() {
32
+ this.menuTarget.classList.add("hidden")
33
+ if (!this.changed) return
34
+
35
+ this.changed = false
36
+ this.send()
37
+ }
38
+
39
+ mark(event) {
40
+ const option = this.optionFor(event)
41
+ option.querySelector("label").classList.toggle("ks-menu-option-hidden", !this.checkboxIn(option).checked)
42
+ this.changed = true
43
+ }
44
+
45
+ optionFor(event) {
46
+ return event.currentTarget.closest('[data-column-picker-target="option"]')
29
47
  }
30
48
 
31
49
  moveUp(event) {
32
- this.move(event, -1)
50
+ const option = this.optionFor(event)
51
+ const previous = option.previousElementSibling
52
+ if (!previous) return
53
+
54
+ option.parentNode.insertBefore(option, previous)
55
+ this.moved()
33
56
  }
34
57
 
35
58
  moveDown(event) {
36
- this.move(event, 1)
59
+ const option = this.optionFor(event)
60
+ const next = option.nextElementSibling
61
+ if (!next) return
62
+
63
+ option.parentNode.insertBefore(next, option)
64
+ this.moved()
37
65
  }
38
66
 
39
- move(event, step) {
40
- const order = this.columnOrder()
41
- const index = this.optionTargets.indexOf(event.currentTarget.closest('[data-column-picker-target="option"]'))
42
- const [key] = order.splice(index, 1)
43
- order.splice(index + step, 0, key)
44
- this.send(order)
67
+ moved() {
68
+ this.changed = true
69
+ const options = this.optionTargets
70
+ options.forEach((option, index) => {
71
+ option.querySelector('[data-action="click->column-picker#moveUp"]').disabled = index === 0
72
+ option.querySelector('[data-action="click->column-picker#moveDown"]').disabled = index === options.length - 1
73
+ })
45
74
  }
46
75
 
47
76
  columnOrder() {
@@ -59,7 +88,7 @@ export default class extends Controller {
59
88
  return option.querySelector("input[type=checkbox]")
60
89
  }
61
90
 
62
- send(columnOrder) {
91
+ send() {
63
92
  if (!this.hasSaveUrlValue) return
64
93
 
65
94
  const token = document.querySelector('meta[name="csrf-token"]')?.content
@@ -69,7 +98,7 @@ export default class extends Controller {
69
98
  "Content-Type": "application/json",
70
99
  "X-CSRF-Token": token
71
100
  },
72
- body: JSON.stringify({ hidden_columns: this.hiddenColumns(), column_order: columnOrder })
101
+ body: JSON.stringify({ hidden_columns: this.hiddenColumns(), column_order: this.columnOrder() })
73
102
  }).then(() => {
74
103
  Turbo.visit(window.location.href, { action: "replace" })
75
104
  })
@@ -3,7 +3,7 @@
3
3
  module Keystone
4
4
  module Ui
5
5
  class BreadcrumbsComponent < ViewComponent::Base
6
- CLASSES = "ks-mobile-header-back hidden lg:block text-sm"
6
+ CLASSES = "ks-mobile-header-back ks-breadcrumbs hidden lg:block text-sm"
7
7
  SEPARATOR = "›"
8
8
 
9
9
  def initialize(trail:, current: nil)
@@ -5,17 +5,19 @@ module Keystone
5
5
  class Column
6
6
  attr_reader :key, :header_text
7
7
 
8
- def initialize(key, header_text, mobile_hidden: false, sortable: false, hideable: false)
8
+ def initialize(key, header_text, mobile_hidden: false, sortable: false, hideable: false, locked: false)
9
9
  @key = key
10
10
  @header_text = header_text
11
11
  @mobile_hidden = mobile_hidden
12
12
  @sortable = sortable
13
13
  @hideable = hideable
14
+ @locked = locked
14
15
  end
15
16
 
16
17
  def mobile_hidden? = @mobile_hidden
17
18
  def sortable? = @sortable
18
- def hideable? = @hideable
19
+ def hideable? = @hideable && !@locked
20
+ def locked? = @locked
19
21
  end
20
22
  end
21
23
  end
@@ -8,11 +8,11 @@
8
8
  <div data-column-picker-target="menu" class="<%= MENU_CLASSES %>">
9
9
  <% hideable_columns.each_with_index do |col, index| %>
10
10
  <div class="<%= OPTION_ROW_CLASSES %>" data-column-picker-target="option">
11
- <label class="<%= OPTION_CLASSES %>">
11
+ <label class="<%= option_classes(col.key) %>">
12
12
  <input type="checkbox"
13
13
  value="<%= col.key %>"
14
14
  <%= "checked" unless hidden?(col.key) %>
15
- data-action="change->column-picker#save"
15
+ data-action="change->column-picker#mark"
16
16
  class="<%= CHECKBOX_CLASSES %>">
17
17
  <%= col.header_text %>
18
18
  </label>
@@ -8,6 +8,7 @@ module Keystone
8
8
  MENU_CLASSES = "ks-menu absolute right-0 z-10 w-56 hidden"
9
9
  OPTION_CLASSES = "ks-menu-option flex items-center text-sm cursor-pointer"
10
10
  CHECKBOX_CLASSES = "ks-menu-checkbox"
11
+ OPTION_HIDDEN_CLASSES = "ks-menu-option-hidden"
11
12
  OPTION_ROW_CLASSES = "flex items-center"
12
13
  MOVE_BUTTON_CLASSES = "ks-menu-move text-sm"
13
14
 
@@ -32,6 +33,10 @@ module Keystone
32
33
  def hidden?(key)
33
34
  @hidden_keys.include?(key.to_sym)
34
35
  end
36
+
37
+ def option_classes(key)
38
+ hidden?(key) ? "#{OPTION_CLASSES} #{OPTION_HIDDEN_CLASSES}" : OPTION_CLASSES
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -1,5 +1,7 @@
1
1
  <% if column_picker %>
2
- <%= render column_picker %>
2
+ <div class="<%= Keystone::Ui::DataTableComponent::TOOLBAR_CLASSES %>">
3
+ <%= render column_picker %>
4
+ </div>
3
5
  <% end %>
4
6
  <div class="<%= Keystone::Ui::DataTableComponent::WRAPPER_CLASSES %>">
5
7
  <table class="relative min-w-full divide-y divide-gray-300 dark:divide-white/15">
@@ -7,6 +7,7 @@ module Keystone
7
7
  BODY_CLASSES = "ks-table-body"
8
8
  HEAD_CLASSES = "ks-table-head"
9
9
  WRAPPER_CLASSES = "ks-table overflow-x-auto"
10
+ TOOLBAR_CLASSES = "ks-table-toolbar flex justify-end"
10
11
  HEADER_CLASSES_FIRST = "ks-table-header ks-table-header-first text-left text-sm"
11
12
  HEADER_CLASSES_MIDDLE = "ks-table-header ks-table-header-middle text-left text-sm"
12
13
  HEADER_CLASSES_LAST = "ks-table-header ks-table-header-last text-right text-sm"
@@ -16,6 +17,8 @@ module Keystone
16
17
  ROW_CLASSES_LAST = "ks-table-cell-last text-right text-sm whitespace-nowrap"
17
18
 
18
19
  MOBILE_HIDDEN_CLASSES = "hidden sm:table-cell"
20
+ HEADER_LOCKED_CLASSES = "ks-table-header-locked sticky left-0"
21
+ CELL_LOCKED_CLASSES = "ks-table-cell-locked sticky left-0"
19
22
 
20
23
  SORT_LINK_CLASSES = "ks-table-sort-link group inline-flex items-center"
21
24
  SORT_ICON_CLASSES = "h-4 w-4 flex-shrink-0"
@@ -75,6 +78,7 @@ module Keystone
75
78
  cells = @columns.map.with_index do |column, index|
76
79
  tokens = [ header_classes_for(index) ]
77
80
  tokens << MOBILE_HIDDEN_CLASSES if column.mobile_hidden?
81
+ tokens << HEADER_LOCKED_CLASSES if index.zero? && column.locked?
78
82
 
79
83
  cell = {
80
84
  label: column.header_text,
@@ -118,6 +122,7 @@ module Keystone
118
122
  @columns.map.with_index do |column, index|
119
123
  tokens = [ row_classes_for(index) ]
120
124
  tokens << MOBILE_HIDDEN_CLASSES if column.mobile_hidden?
125
+ tokens << CELL_LOCKED_CLASSES if index.zero? && column.locked?
121
126
 
122
127
  cell = {
123
128
  value: resolve_value(item, column.key),
@@ -3,7 +3,7 @@
3
3
  module Keystone
4
4
  module Ui
5
5
  class DesktopBackLinkComponent < ViewComponent::Base
6
- CLASSES = "ks-mobile-header-back hidden lg:inline-flex items-center"
6
+ CLASSES = "ks-mobile-header-back ks-page-back hidden lg:inline-flex items-center"
7
7
  LABEL = "Back"
8
8
 
9
9
  def initialize(url:)
@@ -2,11 +2,12 @@
2
2
  <% content_for :form_page_title, @title %>
3
3
  <% content_for :form_page_back_url, @back_url %>
4
4
 
5
- <% if @trail %>
6
- <% content_for :keystone_page_header, render(Keystone::Ui::BreadcrumbsComponent.new(trail: @trail, current: @title)) %>
7
- <% else %>
5
+ <% unless top_level? %>
8
6
  <% content_for :keystone_page_header, render(Keystone::Ui::DesktopBackLinkComponent.new(url: @back_url)) %>
9
7
  <% end %>
8
+ <% if @trail&.any? %>
9
+ <% content_for :keystone_page_header, render(Keystone::Ui::BreadcrumbsComponent.new(trail: @trail, current: @title)) %>
10
+ <% end %>
10
11
 
11
12
  <% content_for :keystone_page_header do %>
12
13
  <div class="<%= DESKTOP_WRAPPER_CLASSES %>">
@@ -17,10 +17,14 @@ module Keystone
17
17
  def before_render
18
18
  @trail ||= KeystoneUi.configuration.supplied_trail(helpers)
19
19
  @back_url ||= @trail&.last&.last
20
- raise KeystoneUi::MissingBackLink, @title unless @back_url
20
+ raise KeystoneUi::MissingBackLink, @title unless @back_url || top_level?
21
21
  raise KeystoneUi::IncompleteTrail, @title if @trail&.any? { |label, href| label.blank? || href.blank? }
22
22
  end
23
23
 
24
+ def top_level?
25
+ @trail == []
26
+ end
27
+
24
28
  def subtitle?
25
29
  !@subtitle.nil?
26
30
  end
@@ -1,6 +1,8 @@
1
1
  <div class="<%= WRAPPER_CLASSES %>">
2
- <%= link_to @back_url, class: BACK_LINK_CLASSES, aria: { label: "Back" } do %>
3
- <%= BACK_ICON.html_safe %>
2
+ <% if @back_url %>
3
+ <%= link_to @back_url, class: BACK_LINK_CLASSES, aria: { label: "Back" } do %>
4
+ <%= BACK_ICON.html_safe %>
5
+ <% end %>
4
6
  <% end %>
5
7
  </div>
6
8
  <span class="<%= TITLE_CLASSES %>">
@@ -3,8 +3,9 @@
3
3
  <% content_for :show_page_back_url, @back_url %>
4
4
  <% content_for :show_page_subtitle, @subtitle if @subtitle.present? %>
5
5
 
6
- <% if @trail %>
7
- <% content_for :keystone_page_header, render(Keystone::Ui::BreadcrumbsComponent.new(trail: @trail, current: @title)) %>
8
- <% else %>
6
+ <% unless top_level? %>
9
7
  <% content_for :keystone_page_header, render(Keystone::Ui::DesktopBackLinkComponent.new(url: @back_url)) %>
10
8
  <% end %>
9
+ <% if @trail&.any? %>
10
+ <% content_for :keystone_page_header, render(Keystone::Ui::BreadcrumbsComponent.new(trail: @trail, current: @title)) %>
11
+ <% end %>
@@ -17,10 +17,14 @@ module Keystone
17
17
  def before_render
18
18
  @trail ||= KeystoneUi.configuration.supplied_trail(helpers)
19
19
  @back_url ||= @trail&.last&.last
20
- raise KeystoneUi::MissingBackLink, @title unless @back_url
20
+ raise KeystoneUi::MissingBackLink, @title unless @back_url || top_level?
21
21
  raise KeystoneUi::IncompleteTrail, @title if @trail&.any? { |label, href| label.blank? || href.blank? }
22
22
  end
23
23
 
24
+ def top_level?
25
+ @trail == []
26
+ end
27
+
24
28
  def subtitle?
25
29
  !@subtitle.nil?
26
30
  end
@@ -3,7 +3,7 @@
3
3
  module KeystoneUi
4
4
  class MissingBackLink < StandardError
5
5
  def initialize(title)
6
- super(%(The page "#{title}" has no Back link. Pass back_url: or trail:, or supply a trail for it through config.trail_supplier.))
6
+ super(%(The page "#{title}" has no Back link. Pass back_url: or trail:, or supply a trail for it through config.trail_supplier. A nav tab's own page passes trail: [].))
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.34.0"
4
+ VERSION = "0.36.0"
5
5
  end
@@ -43,8 +43,9 @@ outer element. See Conventions before using it.
43
43
  takes a block. The outer wrapper for a screen. `max_width:` `:sm` `:md` `:lg`
44
44
  `:xl` `:full`; `padding:` `:standard` or `:none`; `top_offset:` `:sm` `:md`
45
45
  `:lg` `:xl` to clear a fixed navbar. When `ui_form_page` or `ui_show_page` was
46
- called earlier on the same screen, `ui_page` renders their back link or
47
- breadcrumbs, and the form page's title, at its top, above the block.
46
+ called earlier on the same screen, `ui_page` renders their "Back" link, their
47
+ breadcrumbs, and the form page's title, in that order, at its top, above the
48
+ block.
48
49
  - `ui_section(title: nil, subtitle: nil, action: nil, menu: [], spacing: :md, class: nil)`
49
50
  — takes a block. A titled block of content with an optional right-aligned
50
51
  link. `action:` is `{ label:, href: }`; `spacing:` `:sm` `:md` `:lg`.
@@ -73,25 +74,29 @@ outer element. See Conventions before using it.
73
74
  the title and back URL so the navbar can render mobile header context, and
74
75
  hands `ui_page` a "Back" link to `back_url` shown from `lg:` up, then the
75
76
  title and subtitle shown from `md:` up. Call it before `ui_page`, outside
76
- `ui_page`'s block, or none of that appears. Passing `trail:` replaces the
77
- "Back" link with breadcrumbs: the trail's links followed by `title` unlinked,
78
- as `ui_breadcrumbs` renders them. With no `trail:`, it uses the trail the app
79
- supplies for the current request, if the app supplies one. With no
80
- `back_url:`, the back URL is the `href` of the trail's last link. A `trail:`
81
- or `back_url:` passed here always wins over the supplied ones. With no
82
- `back_url:` and no trail from either place, or a trail that is empty or whose
83
- last link has no `href`, rendering raises `KeystoneUi::MissingBackLink`, naming
84
- the page's title. A trail with any link whose label or `href` is `nil` or
85
- blank raises `KeystoneUi::IncompleteTrail`, naming the page's title, even when
86
- `back_url:` is passed.
77
+ `ui_page`'s block, or none of that appears. Passing a non-empty `trail:` adds
78
+ breadcrumbs under the "Back" link: the trail's links followed by `title`
79
+ unlinked, as `ui_breadcrumbs` renders them, shown from `lg:` up. With no
80
+ `trail:`, it uses the trail the app supplies for the current request, if the
81
+ app supplies one. With no `back_url:`, the back URL is the `href` of the
82
+ trail's last link. A `trail:` or `back_url:` passed here always wins over the
83
+ supplied ones. `trail: []` marks the page a navigation tab opens directly: it
84
+ shows no "Back" link and no breadcrumbs, publishes no back URL when no
85
+ `back_url:` is passed, so the mobile header shows no back arrow, and raises
86
+ nothing. With no `back_url:` and no trail from either place, or a trail whose
87
+ last link has no `href`, rendering raises `KeystoneUi::MissingBackLink`,
88
+ naming the page's title. A trail with any link whose label or `href` is `nil`
89
+ or blank raises `KeystoneUi::IncompleteTrail`, naming the page's title, even
90
+ when `back_url:` is passed.
87
91
  - `ui_show_page(title:, back_url: nil, subtitle: nil, trail: nil)` — the shell
88
92
  marker for a detail screen. It renders nothing where it is called. It
89
93
  publishes the title, subtitle, and back URL for the navbar, and hands
90
94
  `ui_page` a "Back" link to `back_url` shown from `lg:` up. Call it before
91
95
  `ui_page`, outside `ui_page`'s block. It shows no title, so put
92
96
  `ui_page_header` inside the `ui_page` block for the desktop title. `trail:`
93
- and `back_url:` work as they do on `ui_form_page`, including the supplied
94
- trail, the fallback to the trail's last link, and the
97
+ and `back_url:` work as they do on `ui_form_page`, including the breadcrumbs
98
+ under the "Back" link, the supplied trail, the fallback to the trail's last
99
+ link, `trail: []` for a navigation tab's own page, and the
95
100
  `KeystoneUi::MissingBackLink` and `KeystoneUi::IncompleteTrail` errors, and
96
101
  the breadcrumbs end with `title` unlinked.
97
102
  - `ui_breadcrumbs(trail:, current: nil)` — a line of links shown only from `lg:`
@@ -116,7 +121,8 @@ outer element. See Conventions before using it.
116
121
  `icon:` is a raw SVG string.
117
122
  - `ui_mobile_header(title:, back_url:, subtitle: nil)` — a back chevron plus
118
123
  centered title for mobile; hidden above `lg:`. Place it in the navbar's
119
- `mobile_left` slot.
124
+ `mobile_left` slot. `back_url:` must be passed, and `nil` renders the title
125
+ with no back chevron.
120
126
  - `ui_action_menu` — no keywords, takes a block. An ellipsis (⋯) button that
121
127
  opens a dropdown of actions, shown at every screen size. Fill the block with
122
128
  `ui_action_menu_item` calls.
@@ -233,27 +239,36 @@ outer element. See Conventions before using it.
233
239
  they were declared. Columns that are not hideable keep their declared place,
234
240
  and the hideable ones fill the remaining places. With no `"column_order"` the
235
241
  columns keep their declared order. Whenever the supplier
236
- returns a save address, the table renders a "Columns" menu above itself that
237
- saves to it, including for a person with nothing saved yet. When the
242
+ returns a save address, the table renders a "Columns" menu in a row above
243
+ itself, aligned right, that saves to it as `ui_column_picker` does, including
244
+ for a person with nothing saved yet. When the
238
245
  supplier returns nothing, when no supplier is set, or when no `key:` is
239
246
  passed, the table renders from `hidden_columns:` with no Columns menu. In
240
247
  every case `hidden_columns:` is the table's default layout.
241
- - `Keystone::Ui::Column.new(key, header_text, mobile_hidden: false, sortable: false, hideable: false)`
248
+ - `Keystone::Ui::Column.new(key, header_text, mobile_hidden: false, sortable: false, hideable: false, locked: false)`
242
249
  — a column with per-column options, for when a `{ key: "Label" }` hash is not
243
250
  enough. `mobile_hidden:` hides the column below `sm:`; `sortable:` opts it into
244
251
  sort headers; `hideable:` lets the Columns menu hide it and move it, and a
245
- saved `"column_order"` place it.
252
+ saved `"column_order"` place it. `locked: true` on the table's first column
253
+ keeps its header and cells in view while the rest of the table scrolls
254
+ sideways. A locked column that is not first renders as an ordinary column. A
255
+ locked column is never hideable, even with `hideable: true`: it is left out of
256
+ the Columns menu, `hidden_columns:` and a saved layout cannot hide it, and a
257
+ saved `"column_order"` cannot move it.
246
258
  - `ui_column_picker(columns:, hidden_columns: [], save_url: nil)` — a "Columns"
247
259
  dropdown with one row per `hideable` column, in the order `columns:` lists
248
260
  them. Each row has a checkbox and an up and a down button that move the
249
261
  column one place; the first row's up button and the last row's down button
250
- are disabled. Pass it the same columns, in the order the table shows them,
251
- and the same hidden keys as the table. On a checkbox change or a move it
252
- sends `PATCH save_url` with JSON
253
- `{ "hidden_columns": ["key", ...], "column_order": ["key", ...] }` and a
254
- `X-CSRF-Token` header, then reloads the page. `column_order` lists every
255
- hideable column's key in the menu's order after the move. With no
256
- `save_url:` it sends nothing. The app must provide that endpoint and persist
262
+ are disabled, and after a move the disabled buttons follow the new first and
263
+ last rows. A hidden column's name renders greyed, and unticking a box greys
264
+ its name at once. Pass it the same columns, in the order the table shows
265
+ them, and the same hidden keys as the table. Ticking, unticking and moving
266
+ change only the open menu and send nothing. When the menu closes, by its
267
+ Columns button or by a click outside it, it sends one `PATCH save_url` with
268
+ JSON `{ "hidden_columns": ["key", ...], "column_order": ["key", ...] }` and a
269
+ `X-CSRF-Token` header, then reloads the page. A menu closed with nothing
270
+ changed sends nothing. `column_order` lists every hideable column's key in
271
+ the menu's order when it closes. With no `save_url:` it sends nothing. The app must provide that endpoint and persist
257
272
  both lists. The picker does not reorder the table: beside a table without
258
273
  `key:`, the app must pass the table and the picker its columns in the saved
259
274
  order itself. A table
@@ -454,8 +469,11 @@ outer element. See Conventions before using it.
454
469
  detail screen without `ui_page` shows no desktop "Back" link or form title.
455
470
  Those shells supply the desktop "Back" link themselves, so never add a
456
471
  second back link or button to those screens. Whether a screen
457
- shows that "Back" link or breadcrumbs, and which parent screens the trail
458
- names, is the developer's choice, so ask before passing `trail:`. Check
472
+ shows breadcrumbs under its "Back" link, and which parent screens the trail
473
+ names, is the developer's choice, so ask before passing `trail:`. A screen
474
+ a navigation tab opens directly, such as a bottom tab's own page, passes
475
+ `trail: []` and no `back_url:`, so it shows no "Back" link and no back
476
+ arrow; which screens those are is the developer's choice, so ask. Check
459
477
  first whether the app's Keystone UI initializer sets a `trail_supplier`,
460
478
  which supplies a trail for every request: if it
461
479
  does, a screen whose supplied trail is right passes neither `trail:` nor
@@ -527,8 +545,16 @@ outer element. See Conventions before using it.
527
545
 
528
546
  6. For a table, decide how columns are declared. Use `{ key: "Label" }` hashes
529
547
  when every column is plain. Switch the whole set to `Keystone::Ui::Column`
530
- objects as soon as one column needs `mobile_hidden:`, `sortable:`, or
531
- `hideable:`.
548
+ objects as soon as one column needs `mobile_hidden:`, `sortable:`,
549
+ `hideable:`, or `locked:`.
550
+
551
+ To keep a wide table's first column, such as a name, in view while the rest
552
+ scrolls sideways, declare it first with `locked: true`. Whether a table locks
553
+ its first column is the developer's choice, so ask rather than pick. If the
554
+ locked column stays in place but the scrolled columns show through its
555
+ cells, the app's keystone_ui-styles version does not define the
556
+ `ks-table-header-locked` and `ks-table-cell-locked` classes, so stop and hand
557
+ that part to `keystone_ui-install`, and add no classes to fix it.
532
558
 
533
559
  For a table whose hideable columns a user should be able to choose and keep,
534
560
  check whether the app's Keystone UI initializer sets a
@@ -539,7 +565,10 @@ outer element. See Conventions before using it.
539
565
  names the table, which columns are hideable, and which it hides by default
540
566
  are the developer's choice, so ask rather than pick. If the app sets no supplier, either use `ui_column_picker`
541
567
  with an endpoint the app owns, as in step 7, or hand setting up a supplier to
542
- `keystone_ui-install`, and ask the developer which.
568
+ `keystone_ui-install`, and ask the developer which. If a Columns menu shows
569
+ no greyed name for a hidden column, the app's keystone_ui-styles version is
570
+ older than 0.11.0, so stop and hand that part to `keystone_ui-install`, and
571
+ add no classes to fix it.
543
572
 
544
573
  7. Wire up anything that posts back. Several helpers render controls whose
545
574
  endpoints the app must own — the column picker's save URL, the pipeline's box
@@ -26,21 +26,24 @@ component updates every page that uses it. It is mobile-first — components shi
26
26
  separate mobile and desktop treatments (a bottom tab bar and mobile header on
27
27
  small screens, a full navigation bar from the `lg:` breakpoint up), because
28
28
  these apps are often viewed in a native webview. The form and show page shells
29
- follow the same split for going back: the mobile header carries the back link on
29
+ follow the same split for going back: the mobile header carries the back arrow on
30
30
  small screens, and from `lg:` up the shell shows a "Back" link. Given a trail of
31
- earlier pages instead, the shell shows breadcrumbs in place of that link, ending
32
- with the page's own title. A page that passes no trail gets the one the app or
31
+ earlier pages, the shell shows breadcrumbs under that "Back" link, ending with
32
+ the page's own title. A page that passes no trail gets the one the app or
33
33
  another gem supplies for the request, if any, and a page that passes no back
34
34
  link goes back to that trail's last link. A trail or back link the page passes
35
35
  itself always wins. Supplying a trail is set up through the install local.
36
36
 
37
- Every form and show page must end up with a Back link. A page with no back
38
- link, no trail and no supplied trail raises `KeystoneUi::MissingBackLink` when it
39
- renders, and the message names the page's title. A trail with a link missing
40
- its label or its address raises `KeystoneUi::IncompleteTrail`, also naming the
41
- page. That link or those breadcrumbs, and the form page's title, appear at the
42
- top of the page container, inside its width and padding, so a page using either
43
- shell also uses the page container.
37
+ A nav tab's own page has nowhere to go back to, and it says so by passing an
38
+ empty trail. Such a page shows no "Back" link and no breadcrumbs, and its mobile
39
+ header shows no back arrow. Every other form and show page must end up with a
40
+ Back link. A page with no back link, no trail and no supplied trail raises
41
+ `KeystoneUi::MissingBackLink` when it renders, and the message names the page's
42
+ title and says an empty trail marks a nav tab's page. A trail with a link
43
+ missing its label or its address raises `KeystoneUi::IncompleteTrail`, also
44
+ naming the page. The "Back" link, the breadcrumbs and the form page's title
45
+ appear at the top of the page container, inside its width and padding, so a
46
+ page using either shell also uses the page container.
44
47
 
45
48
  ## Interface
46
49
 
@@ -124,6 +127,13 @@ holds the catalog.
124
127
  - **The last table column is right-aligned.** In a data table with no actions
125
128
  column, the last column's header is right-aligned like the cells beneath it,
126
129
  so a figure or total placed in that header lines up with the figures below.
130
+ - **A locked first column.** A table column can be marked locked. When it is
131
+ the table's first column, its header and cells stay in view while the rest
132
+ of the table scrolls sideways, styled by keystone_ui-styles' locked header
133
+ and cell classes. A locked column anywhere else renders as an ordinary
134
+ column. A locked column cannot be hidden or moved, so it never appears in the
135
+ "Columns" menu and a saved layout leaves it where it is, even when it is also
136
+ marked hideable.
127
137
  - **Saved table layouts.** A data table can be given a key naming it. A table
128
138
  with a key asks the app, or another gem such as keystone_ui-preferences, for
129
139
  the layout saved under that key for the request. A saved layout lists the
@@ -137,11 +147,14 @@ holds the catalog.
137
147
  out follow the ones it names. Every other column keeps its place, and a
138
148
  layout with no order keeps the order the columns were declared in. When the
139
149
  supplier gives an address to save to, a "Columns" menu appears above the
140
- table and saves the user's choice there, even before anything has been
141
- saved. The menu lists the hideable columns in the order the table shows
142
- them, each with a box to show or hide it and buttons to move it up or down.
143
- Ticking a box or moving a column saves the hidden columns and the order
144
- together, then reloads the page.
150
+ table, at its right, and saves the user's choice there, even before anything
151
+ has been saved. The menu lists the hideable columns in the order the table
152
+ shows them, each with a box to show or hide it and buttons to move it up or
153
+ down. An unticked column's name is greyed at once. Ticking boxes and moving
154
+ columns sends nothing while the menu is open. Closing the menu, with its
155
+ Columns button or by clicking anywhere outside it, saves the hidden columns
156
+ and the order together once, then reloads the page. Closing it with nothing
157
+ changed saves nothing.
145
158
  A table with no key, or an app with no supplier, renders from its own call
146
159
  alone. Setting up the supplier belongs to the install local.
147
160
  - **Suggestions.** A form field can carry a list of suggested values. The
@@ -43,7 +43,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
43
43
  ## How to use it
44
44
 
45
45
  1. Confirm the prerequisites: Ruby >= 3.2 and **tailwindcss-rails v4+** in the
46
- host app. The gem brings ViewComponent and keystone_ui-styles 0.10.0 or later with it.
46
+ host app. The gem brings ViewComponent and keystone_ui-styles 0.12.0 or later with it.
47
47
  Tailwind does not have to be initialized first, because the generator creates
48
48
  the stylesheet if it is missing.
49
49
 
@@ -213,26 +213,31 @@ built on ViewComponent; hook it in before building any screen with those helpers
213
213
  name for the request. A name that is not registered, or `nil`, leaves the
214
214
  page on the default look.
215
215
  - `trail_supplier` — a callable that receives the view and returns the
216
- breadcrumb trail as an array of `[label, href]` pairs, or `nil`. A form or
217
- show page that passes no trail of its own shows the supplied one on `lg:`
218
- screens, ending with the page's title, in place of the desktop "Back" link.
219
- A page that passes no Back link goes back to the trail's last link. A page
220
- that passes its own trail or Back link keeps it. With no supplier, or a
221
- `nil` return, the page shows its Back link. Return `nil`, not an empty
222
- array, for a page with no trail. An empty array replaces the page's Back
223
- link with breadcrumbs holding only its title, and on a page that passes
224
- no Back link it raises `KeystoneUi::MissingBackLink`.
225
- - Every form and show page must end up with a Back link. A page that passes
226
- no Back link and no trail, and gets no trail from the supplier, raises
227
- `KeystoneUi::MissingBackLink` naming the page's title when it renders.
228
- So does a page whose trail's last link has no address.
229
- - Every link the supplier returns needs both a label and an address. A trail
230
- with a blank label or address raises `KeystoneUi::IncompleteTrail` naming
231
- the page's title.
232
- - Ask the developer which code in the app knows each page's trail before
233
- writing the callable. If some form or show pages pass no `back_url:`, ask
234
- where their Back link should come from before enabling the supplier or
235
- leaving it out.
216
+ breadcrumb trail as an array of `[label, href]` pairs, an empty array, or
217
+ `nil`. It is asked only by a form or show page that passes no `trail:`.
218
+ A page that passes its own trail, including an empty one, keeps it.
219
+ - On `lg:` screens a form or show page shows a "Back" link, and under it the
220
+ breadcrumbs ending with the page's title when the trail has any links. A
221
+ page that passes no `back_url:` goes back to the trail's last link. With
222
+ no supplier, or a `nil` return, the page shows only its Back link.
223
+ - An empty trail marks a nav tab's own page, which has nowhere to go back
224
+ to. The page shows no Back link and no breadcrumbs, and raises nothing.
225
+ Return `[]` from the supplier for those
226
+ pages, and `nil` for a page whose Back link comes from its own
227
+ `back_url:`.
228
+ - Every other form and show page must end up with a Back link. A page that
229
+ passes no `back_url:`, and has no trail or a trail whose last link has no
230
+ address, raises `KeystoneUi::MissingBackLink` naming the page's title when
231
+ it renders. The message tells the developer to pass `back_url:` or
232
+ `trail:`, to supply a trail through `trail_supplier`, or to pass
233
+ `trail: []` on a nav tab's own page.
234
+ - Every link in a trail needs both a label and an address. A trail with a
235
+ blank label or address raises `KeystoneUi::IncompleteTrail` naming the
236
+ page's title.
237
+ - Ask the developer which code in the app knows each page's trail, and which
238
+ pages are nav tabs' own pages, before writing the callable. If some form
239
+ or show pages pass no `back_url:`, ask where their Back link should come
240
+ from before enabling the supplier or leaving it out.
236
241
  - `preference_supplier` — a callable that receives the view and a data
237
242
  table's key and returns `{ value:, save_url: }`, or `nil` when the person
238
243
  can neither see nor save a layout for that key. It is asked only for
@@ -243,6 +248,9 @@ built on ViewComponent; hook it in before building any screen with those helpers
243
248
  `"hidden_columns"`, such as `{ "hidden_columns" => ["sku"] }`. That list
244
249
  replaces the hidden columns the table's own call passes, and an empty list
245
250
  shows every column. Only columns marked hideable are hidden.
251
+ - A column marked locked is never hideable, even when it is also marked
252
+ hideable. A saved layout cannot hide it or move it, and the Columns menu
253
+ does not list it.
246
254
  - When `value` is `nil`, or has no `"hidden_columns"` string key, the table
247
255
  keeps the hidden columns its own call passes. A symbol key is not read, so
248
256
  `{ hidden_columns: [...] }` also keeps them.
@@ -257,13 +265,18 @@ built on ViewComponent; hook it in before building any screen with those helpers
257
265
  - When nothing is saved yet for a person who may save a layout, return
258
266
  `{ value: nil, save_url: }`. The table then shows its own default layout
259
267
  with the Columns menu, so the person can save a first layout.
260
- - When `save_url` is present, the table shows a Columns menu above itself.
261
- It lists the hideable columns in the order the table shows them, with the
262
- currently hidden columns unchecked, and gives each column an up and a down
263
- button. Ticking or unticking a column, or moving one, sends a `PATCH` to
264
- `save_url` with the page's CSRF token and the JSON body
265
- `{"hidden_columns": [...], "column_order": [...]}`, then reloads the page.
266
- `column_order` lists every hideable column's name in the menu's order.
268
+ - When `save_url` is present, the table shows a Columns button above its
269
+ right edge. The button opens a menu listing the hideable columns in the
270
+ order the table shows them, with the currently hidden columns unchecked,
271
+ and gives each column an up and a down button.
272
+ - Ticking, unticking and moving columns change only the menu while it is
273
+ open. When the menu is closed, by its Columns button or by a click
274
+ outside it, it sends one `PATCH` to `save_url` if anything was changed
275
+ while it was open, then reloads the page. A menu closed with no change
276
+ sends nothing.
277
+ - The `PATCH` carries the page's CSRF token and the JSON body
278
+ `{"hidden_columns": [...], "column_order": [...]}`. `column_order` lists
279
+ every hideable column's name in the menu's order.
267
280
  - The host must have a route and action at `save_url` that store both lists
268
281
  for that key. The supplier must return them in `value` under the same
269
282
  string keys, `"hidden_columns"` and `"column_order"`, or the saved order
@@ -125,6 +125,7 @@ sources:
125
125
  - app/components/keystone/ui/action_menu_component.rb
126
126
  - app/components/keystone/ui/action_menu_item_component.rb
127
127
  - app/components/keystone/ui/mobile_header_component.rb
128
+ - app/components/keystone/ui/mobile_header_component.html.erb
128
129
  - app/components/keystone/ui/modal_component.rb
129
130
  - app/components/keystone/ui/multi_select_component.rb
130
131
  - app/components/keystone/ui/nav_dropdown_component.rb
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.34.0
4
+ version: 0.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.10.0
18
+ version: 0.12.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.10.0
25
+ version: 0.12.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement