keystone_ui 0.59.0 → 0.60.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: fa286726a479f478774e33da15f8ec93767df8e20227a6280e3835e575740333
4
- data.tar.gz: f1e259b398cca001b2174f90ebfe5ed0a9810ea7a9fc5f965d8c7c8abf55eb58
3
+ metadata.gz: cd5a112008a22c8c4a2c46f10929571f013deef9df4d4926d3d17a06d47e09f3
4
+ data.tar.gz: cab1f062cc0f9f68f3a577e82c7a406895e5b50005af4b671fd0e48f4fbbe81c
5
5
  SHA512:
6
- metadata.gz: b6ae5646277a7ddac4b926f709efaac74f4f3097c83cbb07ac8d24ac7a468e31086ba91327eef2da4b9fcaedfb384b8c64f4c22f663343294c3051481ec013e2
7
- data.tar.gz: f27bd1e717b7e0604480eec0d8500f18dfcbcac1dbe4ca8489fe468c0b1e33c1cde6aa807b8fbd6a71513afe2c3cc4ec4d50e73da9135d02eea0623fa28b3199
6
+ metadata.gz: bb84cb09936b8fd5d1695142591e4502fd76ce307b91b692c10d09d516de165b0277d935097aa9c786c62a9bfc14b3531ab14b74cf9ad8dd35d811d7f1d70f83
7
+ data.tar.gz: f4a070003e5b23465001b048265b3abe0d4c5870221bf31e85eb67eeceeb0fc7f4d28d14e89200524010bf17297d11d6c2570075fd16eb636494946f4f0606ff
@@ -2,6 +2,7 @@ import ColorPickerController from "keystone_ui/color_picker_controller"
2
2
  import MultiSelectController from "keystone_ui/multi_select_controller"
3
3
  import SearchSelectController from "keystone_ui/search_select_controller"
4
4
  import SwipeDeckController from "keystone_ui/swipe_deck_controller"
5
+ import SortableListController from "keystone_ui/sortable_list_controller"
5
6
  import ColumnPickerController from "keystone_ui/column_picker_controller"
6
7
  import FileUploadController from "keystone_ui/file_upload_controller"
7
8
  import DropdownController from "keystone_ui/dropdown_controller"
@@ -23,6 +24,7 @@ export function registerControllers(application) {
23
24
  application.register("multi-select", MultiSelectController)
24
25
  application.register("search-select", SearchSelectController)
25
26
  application.register("swipe-deck", SwipeDeckController)
27
+ application.register("sortable-list", SortableListController)
26
28
  application.register("column-picker", ColumnPickerController)
27
29
  application.register("file-upload", FileUploadController)
28
30
  application.register("dropdown", DropdownController)
@@ -40,4 +42,4 @@ export function registerControllers(application) {
40
42
  keepPageThemeInStep()
41
43
  }
42
44
 
43
- export { ColorPickerController, MultiSelectController, SwipeDeckController, ColumnPickerController, FileUploadController, DropdownController, DismissController, ModalController, ClipboardController, TabSwitcherController, AccordionController, StatCardInfoController, InfoController, AutoSubmitController, LineChartController }
45
+ export { ColorPickerController, MultiSelectController, SwipeDeckController, SortableListController, ColumnPickerController, FileUploadController, DropdownController, DismissController, ModalController, ClipboardController, TabSwitcherController, AccordionController, StatCardInfoController, InfoController, AutoSubmitController, LineChartController }
@@ -0,0 +1,61 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["row", "control", "status"]
5
+
6
+ connect() {
7
+ this.controlTargets.forEach((control) => { control.hidden = false })
8
+ }
9
+
10
+ moveUp({ currentTarget }) {
11
+ const row = this.rowHolding(currentTarget)
12
+ const previous = row.previousElementSibling
13
+ if (previous) row.after(previous)
14
+ this.announce(row)
15
+ }
16
+
17
+ moveDown({ currentTarget }) {
18
+ const row = this.rowHolding(currentTarget)
19
+ const next = row.nextElementSibling
20
+ if (next) row.before(next)
21
+ this.announce(row)
22
+ }
23
+
24
+ grab({ currentTarget, pointerId, button }) {
25
+ if (button !== 0 || this.dragged) return
26
+
27
+ currentTarget.setPointerCapture(pointerId)
28
+ this.draggingPointer = pointerId
29
+ this.dragged = this.rowHolding(currentTarget)
30
+ this.startingIndex = this.rowTargets.indexOf(this.dragged)
31
+ this.dragged.dataset.dragging = "true"
32
+ }
33
+
34
+ drag({ clientY, pointerId }) {
35
+ const row = this.dragged
36
+ if (!row || pointerId !== this.draggingPointer) return
37
+ while (row.nextElementSibling && clientY > this.middleOf(row.nextElementSibling)) row.before(row.nextElementSibling)
38
+ while (row.previousElementSibling && clientY < this.middleOf(row.previousElementSibling)) row.after(row.previousElementSibling)
39
+ }
40
+
41
+ drop({ pointerId }) {
42
+ if (!this.dragged || pointerId !== this.draggingPointer) return
43
+ if (this.rowTargets.indexOf(this.dragged) !== this.startingIndex) this.announce(this.dragged)
44
+ delete this.dragged.dataset.dragging
45
+ this.dragged = null
46
+ }
47
+
48
+ middleOf(row) {
49
+ const { top, height } = row.getBoundingClientRect()
50
+ return top + height / 2
51
+ }
52
+
53
+ announce(row) {
54
+ const rows = this.rowTargets
55
+ this.statusTarget.textContent = `${row.dataset.label} is number ${rows.indexOf(row) + 1} of ${rows.length}.`
56
+ }
57
+
58
+ rowHolding(element) {
59
+ return element.closest('[data-sortable-list-target="row"]')
60
+ }
61
+ }
@@ -0,0 +1,26 @@
1
+ <div data-controller="sortable-list">
2
+ <ul aria-label="<%= @label %>">
3
+ <% @rows.each do |row| %>
4
+ <li class="<%= ROW_CLASSES %>" data-sortable-list-target="row" data-label="<%= row[:label] %>">
5
+ <input type="hidden" name="<%= @name %>" value="<%= row[:id] %>">
6
+ <span hidden data-sortable-list-target="control" class="<%= HANDLE_CLASSES %>" data-action="pointerdown->sortable-list#grab pointermove->sortable-list#drag pointerup->sortable-list#drop pointercancel->sortable-list#drop">
7
+ <svg class="<%= ICON_CLASSES %>" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
8
+ <path stroke-linecap="round" d="M4 8h16M4 16h16" />
9
+ </svg>
10
+ </span>
11
+ <span class="<%= LABEL_CLASSES %>"><%= row[:label] %></span>
12
+ <button hidden data-sortable-list-target="control" type="button" class="<%= MOVE_BUTTON_CLASSES %>" aria-label="Move <%= row[:label] %> up" data-action="sortable-list#moveUp">
13
+ <svg class="<%= ICON_CLASSES %>" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
14
+ <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 15.75 7.5-7.5 7.5 7.5" />
15
+ </svg>
16
+ </button>
17
+ <button hidden data-sortable-list-target="control" type="button" class="<%= MOVE_BUTTON_CLASSES %>" aria-label="Move <%= row[:label] %> down" data-action="sortable-list#moveDown">
18
+ <svg class="<%= ICON_CLASSES %>" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
19
+ <path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
20
+ </svg>
21
+ </button>
22
+ </li>
23
+ <% end %>
24
+ </ul>
25
+ <div role="status" class="<%= STATUS_CLASSES %>" data-sortable-list-target="status"></div>
26
+ </div>
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class SortableListComponent < ViewComponent::Base
6
+ ROW_CLASSES = "ks-value-list-row items-center data-dragging:opacity-50"
7
+ LABEL_CLASSES = "ks-paragraph min-w-0 flex-1"
8
+ HANDLE_CLASSES = "ks-tone-muted flex size-11 shrink-0 cursor-grab touch-none select-none items-center justify-center"
9
+ MOVE_BUTTON_CLASSES = "ks-button ks-button-secondary ks-button-sm size-11 shrink-0"
10
+ ICON_CLASSES = "size-5"
11
+ STATUS_CLASSES = "sr-only"
12
+
13
+ def initialize(name:, label:, rows:)
14
+ @name = name
15
+ @label = label
16
+ @rows = rows
17
+ end
18
+ end
19
+ end
20
+ end
@@ -205,6 +205,10 @@ module KeystoneUiHelper
205
205
  render Keystone::Ui::SwipeDeckComponent.new(**args), &block
206
206
  end
207
207
 
208
+ def ui_sortable_list(**args)
209
+ render Keystone::Ui::SortableListComponent.new(**args)
210
+ end
211
+
208
212
  def ui_column_picker(**args)
209
213
  render Keystone::Ui::ColumnPickerComponent.new(**args)
210
214
  end
data/config/importmap.rb CHANGED
@@ -3,6 +3,7 @@ pin "keystone_ui/color_picker_controller", to: "keystone_ui/color_picker_control
3
3
  pin "keystone_ui/multi_select_controller", to: "keystone_ui/multi_select_controller.js"
4
4
  pin "keystone_ui/search_select_controller", to: "keystone_ui/search_select_controller.js"
5
5
  pin "keystone_ui/swipe_deck_controller", to: "keystone_ui/swipe_deck_controller.js"
6
+ pin "keystone_ui/sortable_list_controller", to: "keystone_ui/sortable_list_controller.js"
6
7
  pin "keystone_ui/column_picker_controller", to: "keystone_ui/column_picker_controller.js"
7
8
  pin "keystone_ui/file_upload_controller", to: "keystone_ui/file_upload_controller.js"
8
9
  pin "keystone_ui/dropdown_controller", to: "keystone_ui/dropdown_controller.js"
@@ -58,6 +58,7 @@ module Keystone
58
58
  Keystone::Ui::ColorPickerComponent,
59
59
  Keystone::Ui::MultiSelectComponent,
60
60
  Keystone::Ui::SwipeDeckComponent,
61
+ Keystone::Ui::SortableListComponent,
61
62
  Keystone::Ui::ColumnPickerComponent,
62
63
  Keystone::Ui::FormComponent,
63
64
  Keystone::Ui::FileUploadComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.59.0"
4
+ VERSION = "0.60.0"
5
5
  end
@@ -58,6 +58,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
58
58
  - `ui_color_picker` — a colour swatch that writes a hex value into a hidden input.
59
59
  - `ui_radio_card` — a selectable card backed by a radio input.
60
60
  - `ui_checkbox_row` — a checkbox with its label and hint, toggled by a tap anywhere on the row.
61
+ - `ui_sortable_list` — a list of rows dragged into a new order, submitted with the form it sits in.
61
62
  - `ui_option_card` — a radio whose visible body is whatever its block renders.
62
63
  - `ui_data_table` — a table of records with links, row actions, sorting, hideable columns and the viewer's own row marked.
63
64
  - `Keystone::Ui::Column` — a table column with options a `{ key: "Label" }` hash cannot carry.
@@ -385,6 +386,14 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
385
386
  - A checked `ui_checkbox_row` submits `value` under `name`, an unchecked one
386
387
  submits nothing, and rows sharing an array name such as `"shown[]"`
387
388
  submit the checked values as a list.
389
+ - `ui_sortable_list(name:, label:, rows:)` is one field inside a `ui_form`,
390
+ for putting a short list in order. `rows:` is an array of
391
+ `{ id:, label: }` hashes, `label:` names the list for screen readers, and
392
+ `name:` names a hidden field in each row, so pass an array name such as
393
+ `"order[]"` and a different one for each list on a page. The form submits
394
+ the ids in the order shown, and the list makes no request of its own. A
395
+ row is dragged by its handle, or moved with its Move up and Move down
396
+ buttons. Without JavaScript the form submits the starting order.
388
397
  - `ui_option_card(name:, value:, selected: false, input_data: {}, label_data: {})`
389
398
  takes a block rendering the card's body. `input_data:` and `label_data:`
390
399
  become `data-*` attributes on the input and the label.
@@ -55,6 +55,7 @@ develop:
55
55
  - ui_multi_select
56
56
  - ui_search_select
57
57
  - ui_swipe_deck
58
+ - ui_sortable_list
58
59
  - ui_column_picker
59
60
  - ui_form
60
61
  - ui_file_upload
@@ -165,6 +166,8 @@ sources:
165
166
  - app/components/keystone/ui/settings_link_component.rb
166
167
  - app/components/keystone/ui/show_page_component.rb
167
168
  - app/components/keystone/ui/show_page_component.html.erb
169
+ - app/components/keystone/ui/sortable_list_component.rb
170
+ - app/components/keystone/ui/sortable_list_component.html.erb
168
171
  - app/components/keystone/ui/stat_card_component.rb
169
172
  - app/components/keystone/ui/stat_card_component.html.erb
170
173
  - app/components/keystone/ui/swipe_deck_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.59.0
4
+ version: 0.60.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -68,6 +68,7 @@ files:
68
68
  - app/assets/javascripts/keystone_ui/multi_select_controller.js
69
69
  - app/assets/javascripts/keystone_ui/page_theme.js
70
70
  - app/assets/javascripts/keystone_ui/search_select_controller.js
71
+ - app/assets/javascripts/keystone_ui/sortable_list_controller.js
71
72
  - app/assets/javascripts/keystone_ui/stat_card_info_controller.js
72
73
  - app/assets/javascripts/keystone_ui/swipe_deck_controller.js
73
74
  - app/assets/javascripts/keystone_ui/tab_switcher_controller.js
@@ -198,6 +199,8 @@ files:
198
199
  - app/components/keystone/ui/settings_link_component.rb
199
200
  - app/components/keystone/ui/show_page_component.html.erb
200
201
  - app/components/keystone/ui/show_page_component.rb
202
+ - app/components/keystone/ui/sortable_list_component.html.erb
203
+ - app/components/keystone/ui/sortable_list_component.rb
201
204
  - app/components/keystone/ui/stat_card_component.html.erb
202
205
  - app/components/keystone/ui/stat_card_component.rb
203
206
  - app/components/keystone/ui/swipe_deck_component.html.erb