keystone_ui 0.54.0 → 0.56.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: 43359bd6e64474a6d13c8d40ce91b0d92883f73f941db147f88ba5a51a7f83e2
4
- data.tar.gz: e204d14c0526bc5ffae69c2fdaa58e094b879a39e035553c09b9ca125a52d270
3
+ metadata.gz: 1d60dc9eb75d07285fc1f90e102456631d1462851a5fcb2af7f2b28a3ddcc550
4
+ data.tar.gz: 65b03bbda334318e51b71014cbc1d9b2fa5b10841eb5d62c9cb963da5d7532ee
5
5
  SHA512:
6
- metadata.gz: 16845938b705f24c366616906e2d5ae19530143e59e1e411f167bc8c39bf41380975653fc4f10e4e2bee1ea521db1988dff5a71b8f36c954ccac43328f7e31c7
7
- data.tar.gz: 1fa972e398b10bc3c74eaa5b241b46cdf5581139a23f2d2f7044317568aefa72c5d92e7b61e6cb1f0f263e8c32b8e5b977e776b0769ae73645f808281254665d
6
+ metadata.gz: 4316551b415b8ea4b392ad4929d7c6601ce7e2cc0a9284a83b060201d772f8c8257d20f819f1cc433dc3fc3b008d43fae47c28ce4c206cb026e48433cf926a36
7
+ data.tar.gz: e34615f42f57d85cfcc9602624c8c3e8a4fd86e56cc4decec8835796330d27fe6994b0de3c92b18d5ad98162f6c1459761aefce6fefc71a96bb24fdeba2a1056
@@ -44,7 +44,7 @@
44
44
  <% if actions? %><th></th><% end %>
45
45
  </tr>
46
46
  <% end %>
47
- <tr>
47
+ <tr<% if current_row?(idx) %> class="<%= Keystone::Ui::DataTableComponent::CURRENT_ROW_CLASSES %>" aria-current="true"<% end %>>
48
48
  <% row_cells[idx].each do |cell| %>
49
49
  <td class="<%= cell[:classes] %>">
50
50
  <% if cell[:href] %>
@@ -5,6 +5,7 @@ module Keystone
5
5
  class DataTableComponent < ViewComponent::Base
6
6
  EMPTY_CELL_CLASSES = "ks-table-cell-middle text-sm"
7
7
  BODY_CLASSES = "ks-table-body"
8
+ CURRENT_ROW_CLASSES = "ks-table-row-current"
8
9
  HEAD_CLASSES = "ks-table-head"
9
10
  WRAPPER_CLASSES = "ks-table overflow-x-auto"
10
11
  TOOLBAR_CLASSES = "ks-table-toolbar flex justify-end"
@@ -30,8 +31,9 @@ module Keystone
30
31
  SORT_DESC_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .75.75v10.638l3.96-4.158a.75.75 0 1 1 1.08 1.04l-5.25 5.5a.75.75 0 0 1-1.08 0l-5.25-5.5a.75.75 0 0 1 1.08-1.04l3.96 4.158V3.75A.75.75 0 0 1 10 3Z" clip-rule="evenodd" /></svg>'
31
32
  SORT_NEUTRAL_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .55.24l3.25 3.5a.75.75 0 1 1-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 0 1-1.1-1.02l3.25-3.5A.75.75 0 0 1 10 3Zm-3.76 9.2a.75.75 0 0 1 1.06.04l2.7 2.908 2.7-2.908a.75.75 0 1 1 1.1 1.02l-3.25 3.5a.75.75 0 0 1-1.1 0l-3.25-3.5a.75.75 0 0 1 .04-1.06Z" clip-rule="evenodd" /></svg>'
32
33
 
33
- def initialize(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil)
34
+ def initialize(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil)
34
35
  @items = items.to_a
36
+ @current_index = @items.index(current_row) unless current_row.nil?
35
37
  @group_by = group_by
36
38
  @group_totals = group_totals.to_h.transform_keys(&:to_s)
37
39
  @total = total&.to_h&.transform_keys(&:to_s)
@@ -142,6 +144,10 @@ module Keystone
142
144
  end
143
145
  end
144
146
 
147
+ def current_row?(index)
148
+ index == @current_index
149
+ end
150
+
145
151
  def empty?
146
152
  @items.empty?
147
153
  end
@@ -1,6 +1,6 @@
1
1
  <div class="<%= WRAPPER_CLASSES %>">
2
2
  <% unless checkbox? %>
3
- <label class="<%= LABEL_CLASSES %>">
3
+ <label for="<%= field_id %>" class="<%= LABEL_CLASSES %>">
4
4
  <%= label_text %><% if required? %><span class="<%= REQUIRED_CLASSES %>">*</span><% end %>
5
5
  </label>
6
6
  <% end %>
@@ -12,9 +12,9 @@
12
12
  <span class="text-sm text-gray-700 dark:text-gray-300"><%= label_text %></span>
13
13
  </div>
14
14
  <% elsif textarea? %>
15
- <textarea name="<%= @attribute %>" rows="3" class="<%= Keystone::Ui::TextareaComponent::BASE_CLASSES %>"<% if @placeholder %> placeholder="<%= @placeholder %>"<% end %>><%= @value %></textarea>
15
+ <textarea name="<%= @attribute %>" id="<%= field_id %>" rows="3" class="<%= Keystone::Ui::TextareaComponent::BASE_CLASSES %>"<% if @placeholder %> placeholder="<%= @placeholder %>"<% end %>><%= @value %></textarea>
16
16
  <% elsif select? %>
17
- <select name="<%= @attribute %>" class="<%= Keystone::Ui::SelectComponent::BASE_CLASSES %>">
17
+ <select name="<%= @attribute %>" id="<%= field_id %>" class="<%= Keystone::Ui::SelectComponent::BASE_CLASSES %>">
18
18
  <% unless required? %><option value=""><%= blank_option_text %></option><% end %>
19
19
  <% select_options.each do |label, value| %>
20
20
  <option value="<%= value %>" <%= "selected" if @value.to_s == value.to_s %>><%= label %></option>
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/string/inflections"
4
+
3
5
  module Keystone
4
6
  module Ui
5
7
  class FormFieldComponent < ViewComponent::Base
@@ -11,7 +13,7 @@ module Keystone
11
13
  CHECKBOX_CLASSES = "ks-checkbox"
12
14
  CHECKBOX_WRAPPER_CLASSES = "ks-form-field-checkbox flex items-center"
13
15
 
14
- def initialize(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false, suggestions: [])
16
+ def initialize(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false, suggestions: [], autofocus: false, autocomplete: nil, autocapitalize: nil, inputmode: nil)
15
17
  @attribute = attribute
16
18
  @label = label
17
19
  @type = type
@@ -27,6 +29,10 @@ module Keystone
27
29
  @include_blank = include_blank.to_s
28
30
  @disabled = disabled
29
31
  @suggestions = Array(suggestions)
32
+ @autofocus = autofocus
33
+ @autocomplete = autocomplete
34
+ @autocapitalize = autocapitalize
35
+ @inputmode = inputmode
30
36
  end
31
37
 
32
38
  def label_text
@@ -74,7 +80,7 @@ module Keystone
74
80
  end
75
81
 
76
82
  def input_options
77
- options = { name: @attribute.to_s, class: Keystone::Ui::InputComponent::BASE_CLASSES }
83
+ options = { name: @attribute.to_s, id: field_id, class: Keystone::Ui::InputComponent::BASE_CLASSES }
78
84
  unless textarea?
79
85
  options[:type] = Keystone::Ui::InputComponent::TYPE_MAP.fetch(@type)
80
86
  end
@@ -84,6 +90,11 @@ module Keystone
84
90
  options[:max] = @max unless @max.nil?
85
91
  options[:step] = @step unless @step.nil?
86
92
  options[:disabled] = true if @disabled
93
+ options[:required] = true if required?
94
+ options[:autofocus] = true if @autofocus
95
+ options[:autocomplete] = @autocomplete unless @autocomplete.nil?
96
+ options[:autocapitalize] = @autocapitalize unless @autocapitalize.nil?
97
+ options[:inputmode] = @inputmode unless @inputmode.nil?
87
98
  options[:list] = suggestions_id if suggestions?
88
99
  options
89
100
  end
@@ -96,6 +107,10 @@ module Keystone
96
107
  @suggestions
97
108
  end
98
109
 
110
+ def field_id
111
+ @attribute.to_s.parameterize
112
+ end
113
+
99
114
  def suggestions_id
100
115
  "#{@attribute.to_s.parameterize}-suggestions"
101
116
  end
@@ -24,7 +24,7 @@ module Keystone
24
24
  value.strftime(DATETIME_FORMAT)
25
25
  end
26
26
 
27
- def initialize(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil)
27
+ def initialize(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil, autofocus: false, autocomplete: nil, autocapitalize: nil, inputmode: nil, required: false)
28
28
  @name = name
29
29
  @type = type
30
30
  @value = value
@@ -33,6 +33,11 @@ module Keystone
33
33
  @min = min
34
34
  @max = max
35
35
  @step = step
36
+ @autofocus = autofocus
37
+ @autocomplete = autocomplete
38
+ @autocapitalize = autocapitalize
39
+ @inputmode = inputmode
40
+ @required = required
36
41
  end
37
42
 
38
43
  def classes
@@ -57,6 +62,11 @@ module Keystone
57
62
  options[:min] = @min unless @min.nil?
58
63
  options[:max] = @max unless @max.nil?
59
64
  options[:step] = @step unless @step.nil?
65
+ options[:autofocus] = true if @autofocus
66
+ options[:autocomplete] = @autocomplete unless @autocomplete.nil?
67
+ options[:autocapitalize] = @autocapitalize unless @autocapitalize.nil?
68
+ options[:inputmode] = @inputmode unless @inputmode.nil?
69
+ options[:required] = true if @required
60
70
  options
61
71
  end
62
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.54.0"
4
+ VERSION = "0.56.0"
5
5
  end
@@ -58,7 +58,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
58
58
  - `ui_radio_card` — a selectable card backed by a radio input.
59
59
  - `ui_checkbox_row` — a checkbox with its label and hint, toggled by a tap anywhere on the row.
60
60
  - `ui_option_card` — a radio whose visible body is whatever its block renders.
61
- - `ui_data_table` — a table of records with links, row actions, sorting and hideable columns.
61
+ - `ui_data_table` — a table of records with links, row actions, sorting, hideable columns and the viewer's own row marked.
62
62
  - `Keystone::Ui::Column` — a table column with options a `{ key: "Label" }` hash cannot carry.
63
63
  - `ui_column_picker` — a Columns menu that saves which columns are hidden and their order to an app endpoint.
64
64
  - `ui_button` — a link or a button styled as a button, or a button sending a POST, PATCH or DELETE request.
@@ -268,7 +268,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
268
268
  - `ui_form(action:, method: :post, multipart: false, data: nil)` takes a
269
269
  block. `method:` may be `:patch`, `:put` or `:delete`, sent as Rails
270
270
  expects. Set `multipart: true` when the form holds a file upload.
271
- - `ui_form_field(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false, suggestions: [])`
271
+ - `ui_form_field(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false, suggestions: [], autofocus: false, autocomplete: nil, autocapitalize: nil, inputmode: nil)`
272
272
  is the default way to render a field. `type:` is `:text` `:number`
273
273
  `:email` `:password` `:date` `:datetime` `:textarea` `:checkbox` `:select`.
274
274
  - A `:datetime` field is a `datetime-local` input for a date and a time of
@@ -290,11 +290,31 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
290
290
  `:email` `:password` `:date` `:datetime` and is ignored by the other types. Its list
291
291
  is identified by `attribute:`, so two fields with suggestions on one
292
292
  screen need different `attribute:` values.
293
+ - The field's label is tied to its input, textarea or select through an
294
+ `id` built from `attribute:`, so tapping the label focuses the input and
295
+ a screen reader reads the label. `"player[email]"` gets the id
296
+ `player-email`, so two fields on one screen need different `attribute:`
297
+ values.
298
+ - `required: true` marks the label with an asterisk and, on a `:text`
299
+ `:number` `:email` `:password` `:date` `:datetime` field, sets the
300
+ input's `required` attribute so the browser will not send the form with
301
+ it empty.
302
+ - `autofocus: true` puts the cursor in the input when the page opens. Give
303
+ it to one field per page at most.
304
+ - `autocomplete:`, `autocapitalize:` and `inputmode:` are written onto the
305
+ input as given, such as `autocomplete: "email"`, `autocapitalize: "none"`
306
+ and `inputmode: "numeric"`. They let a phone suggest a saved value, stop
307
+ capitalizing the first letter, and open the right keyboard.
308
+ - `autofocus:`, `autocomplete:`, `autocapitalize:` and `inputmode:` apply to
309
+ the same types as `suggestions:` and are ignored by `:textarea`
310
+ `:checkbox` and `:select`.
293
311
  - A value that must be one of a fixed list is a `:select`, and a free value
294
312
  with common choices is a text field with `suggestions:`. Ask the developer
295
313
  which a field is and which values it offers.
296
- - `ui_input(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil)`
297
- takes `:text` `:number` `:email` `:password` `:date` `:datetime`.
314
+ - `ui_input(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil, autofocus: false, autocomplete: nil, autocapitalize: nil, inputmode: nil, required: false)`
315
+ takes `:text` `:number` `:email` `:password` `:date` `:datetime`. Its
316
+ `autofocus:` `autocomplete:` `autocapitalize:` and `inputmode:` work as on
317
+ `ui_form_field`, and `required: true` sets the `required` attribute.
298
318
  `ui_textarea(name:, value: nil, rows: 3, placeholder: nil, disabled: false)`
299
319
  and `ui_select(name:, options: [], selected: nil, include_blank: nil, disabled: false)`
300
320
  are the bare forms of the other two. Use them only where a label does not
@@ -367,7 +387,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
367
387
 
368
388
  8. Build tables.
369
389
 
370
- - `ui_data_table(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil)`
390
+ - `ui_data_table(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil)`
371
391
  takes a block yielding the table. `items:` are records or hashes, and a
372
392
  cell's value is the column key called on the item, or `item[key]`.
373
393
  `group_by:` lists rows under heading rows named by that key's value,
@@ -394,6 +414,12 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
394
414
  `sort_direction:` (`:asc` or `:desc`) and `sort_url:` (a lambda taking
395
415
  `(column_key, direction)` and returning a URL). Headers then render as
396
416
  links that flip direction.
417
+ - `current_row:` takes the item whose row is the viewer's own, such as
418
+ their entry on a scoreboard or leaderboard. That row carries the
419
+ `ks-table-row-current` class, which keystone_ui-styles colours, and
420
+ `aria-current="true"`, so a screen reader announces it. The item
421
+ is compared with `==` and only the first equal row is marked, so pass the
422
+ same record or an equal hash. Use it instead of a "You" badge in a cell.
397
423
  - `hidden_columns:` is the table's default layout and drops only hideable
398
424
  columns. The declared order is the default order.
399
425
  - For a table whose columns a user chooses and keeps, check whether the
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.54.0
4
+ version: 0.56.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.27.0
18
+ version: 0.28.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.27.0
25
+ version: 0.28.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement