keystone_ui 0.99.0 → 0.101.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: cb91bd02dbb47370be07dad4d4a5052c1a719678e6b4b53407187847ff3a5697
4
- data.tar.gz: 9a7dfe91f4779e2ae43d3be48a8b3ef2ec7dfdd8f97c74de60dc29491e9b2336
3
+ metadata.gz: 327d7289d20de1a267d20e87c47df21d3dd8069db8c4c39b488a8ceb1cd0bb28
4
+ data.tar.gz: 4a63e3aec691f256b2c2fec24694090581be4184749a39b14a529d19171c006a
5
5
  SHA512:
6
- metadata.gz: 5056738e253f18d5f2ca3d732d727a33523cda10054e181e4f2e9a3d6c892d5064ee416edffc2f738bebbe7cc425e8b5add580503dfd36dafbf9f0a9d1b522a8
7
- data.tar.gz: 40b4f45fc19561b23dbca6e131e071dea1038050eae13470345687baf663157871c4a3036319d747e6a157aaa4e510d61387268c7de6226508997d8897a92c88
6
+ metadata.gz: 283b5ecde2e04ab9d9ef7af31bc036f29d29c0a899674946a13816234512fe224c237f22d3f706c7f3df5667607022949806df2728413c658ac52a08f0716619
7
+ data.tar.gz: 2a659f0c17e30f956d683f2035d60acd9326ba53cb0374b6eef07edadb7990675fec2448b8ad4ddf32014795ecaafafd191f57552c14e55aaeaa785374f63ed8
@@ -1,7 +1,7 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
- static targets = ["tab"]
4
+ static targets = ["tab", "panel"]
5
5
 
6
6
  select(event) {
7
7
  const index = parseInt(event.currentTarget.dataset.index)
@@ -14,6 +14,11 @@ export default class extends Controller {
14
14
  }
15
15
  })
16
16
 
17
+ this.panelTargets.forEach((panel, panelIndex) => {
18
+ panel.hidden = panelIndex !== index
19
+ panel.disabled = panelIndex !== index
20
+ })
21
+
17
22
  this.dispatch("change", { detail: { index } })
18
23
  }
19
24
  }
@@ -23,6 +23,7 @@ module Keystone
23
23
  attr_reader :bars
24
24
 
25
25
  def initialize(bars:, show_values: false, strip: false)
26
+ bars.each { |bar| check_value(bar) }
26
27
  @bars = bars
27
28
  @show_values = show_values
28
29
  @strip = strip
@@ -72,6 +73,10 @@ module Keystone
72
73
 
73
74
  private
74
75
 
76
+ def check_value(bar)
77
+ raise ArgumentError, "Bar chart bar #{bar[:label].inspect} has the negative value #{bar[:value]}, and a bar chart draws no bar below zero" if bar[:value].to_f.negative?
78
+ end
79
+
75
80
  def bar_share
76
81
  strip? ? STRIP_BAR_SHARE : BAR_SHARE
77
82
  end
@@ -20,7 +20,7 @@ module Keystone
20
20
 
21
21
  TEXT_CLASSES = "ks-text-button"
22
22
 
23
- def initialize(label:, href: nil, method: :get, variant: :primary, size: :md, full_width: false, type: :submit, data: nil, name: nil, value: nil, hidden: false, confirm: nil, disabled: false)
23
+ def initialize(label:, href: nil, method: :get, variant: :primary, size: :md, full_width: false, type: :submit, data: nil, name: nil, value: nil, hidden: false, confirm: nil, disabled: false, formaction: nil)
24
24
  @label = label
25
25
  @href = href
26
26
  @method = method.to_sym
@@ -34,6 +34,7 @@ module Keystone
34
34
  @hidden = hidden
35
35
  @confirm = confirm
36
36
  @disabled = disabled
37
+ @formaction = formaction
37
38
  end
38
39
 
39
40
  def classes
@@ -57,6 +58,7 @@ module Keystone
57
58
  options[:type] = @type
58
59
  options[:name] = @name if @name
59
60
  options[:value] = @value if @value
61
+ options[:formaction] = @formaction if @formaction
60
62
  else
61
63
  options[:href] = @href
62
64
  end
@@ -68,6 +68,7 @@ module Keystone
68
68
  @url = url
69
69
  @primary = primary
70
70
  @actions = actions
71
+ actions.each { |action| check_action(action) }
71
72
  @note = note
72
73
  @hint = hint
73
74
  @method = method
@@ -106,11 +107,32 @@ module Keystone
106
107
  end
107
108
 
108
109
  def secondary_button(action)
109
- tag.div(class: [ ACTION_CLASSES, (PHONE_ONLY_CLASSES.fetch(@breakpoint) if action[:phone_only]), PHONE_ORDER_CLASSES.fetch(@breakpoint)[action[:phone_order]] ].compact.join(" ")) do
110
- render ButtonComponent.new(variant: :secondary, **action.except(:phone_only, :phone_order, :phone_label), label: action_label(action))
110
+ tag.div(class: [ ACTION_CLASSES, (PHONE_ONLY_CLASSES.fetch(@breakpoint) if action[:phone_only]), phone_order_classes(action) ].compact.join(" ")) do
111
+ render ButtonComponent.new(variant: :secondary, **button_options(action), label: action_label(action))
111
112
  end
112
113
  end
113
114
 
115
+ def phone_order_classes(action)
116
+ PHONE_ORDER_CLASSES.fetch(@breakpoint).fetch(action[:phone_order]) if action.key?(:phone_order)
117
+ end
118
+
119
+ def button_options(action)
120
+ options = action.except(:phone_only, :phone_order, :phone_label)
121
+ return options unless sends_request?(action)
122
+
123
+ options.except(:href, :method).merge(formaction: action[:href], name: "_method", value: action[:method].to_s)
124
+ end
125
+
126
+ def check_action(action)
127
+ return unless sends_request?(action) && (action.key?(:name) || action.key?(:value))
128
+
129
+ raise ArgumentError, "Decision bar action #{action[:label].inspect} sends a #{action[:method]} to its own link, so it cannot send a name or value of its own"
130
+ end
131
+
132
+ def sends_request?(action)
133
+ action[:href] && action.fetch(:method, :get).to_sym != :get
134
+ end
135
+
114
136
  def action_label(action)
115
137
  return action[:label] unless action[:phone_label]
116
138
 
@@ -8,7 +8,7 @@
8
8
  <% if checkbox? %>
9
9
  <div class="<%= CHECKBOX_WRAPPER_CLASSES %>">
10
10
  <input type="hidden" name="<%= @attribute %>" value="0">
11
- <input type="checkbox" name="<%= @attribute %>" id="<%= field_id %>" value="1" class="<%= CHECKBOX_CLASSES %>"<%= " checked" if @value.to_s == "1" %>>
11
+ <input type="checkbox" name="<%= @attribute %>" id="<%= field_id %>" value="1" class="<%= CHECKBOX_CLASSES %>"<%= " checked" if @value.to_s == "1" %><%= " required" if required? %>>
12
12
  <label for="<%= field_id %>" class="text-sm text-gray-700 dark:text-gray-300"><%= label_text %></label>
13
13
  </div>
14
14
  <% elsif textarea? %>
@@ -17,13 +17,18 @@ module Keystone
17
17
 
18
18
  attr_reader :rows, :chevron
19
19
 
20
- def initialize(rows:, chevron: true)
20
+ def initialize(rows:, chevron: true, new_tab: false)
21
21
  @rows = rows
22
22
  @chevron = chevron
23
+ @new_tab = new_tab
23
24
  end
24
25
 
25
26
  def row_options(row)
26
- { class: [ ROW_CLASSES, (CURRENT_ROW_CLASSES if row[:current]) ].compact.join(" "), aria: { current: ("true" if row[:current]) } }
27
+ { class: [ ROW_CLASSES, (CURRENT_ROW_CLASSES if row[:current]) ].compact.join(" "), aria: { current: ("true" if row[:current]) } }.merge(new_tab_options)
28
+ end
29
+
30
+ def new_tab_options
31
+ @new_tab ? { target: "_blank", rel: "noopener" } : {}
27
32
  end
28
33
 
29
34
  def badge(row)
@@ -18,7 +18,7 @@ module Keystone
18
18
  def call
19
19
  return link_to(PLUS_ICON.html_safe, url, **options) unless content_for?(:mobile_action_method)
20
20
 
21
- button_to(url, method: content_for(:mobile_action_method), **options) { PLUS_ICON.html_safe }
21
+ button_to(url, method: content_for(:mobile_action_method), form: form_options, **options) { PLUS_ICON.html_safe }
22
22
  end
23
23
 
24
24
  private
@@ -27,6 +27,10 @@ module Keystone
27
27
  content_for(:mobile_action_url)
28
28
  end
29
29
 
30
+ def form_options
31
+ content_for?(:mobile_action_confirm) ? { data: { turbo_confirm: content_for(:mobile_action_confirm) } } : {}
32
+ end
33
+
30
34
  def options
31
35
  { class: LINK_CLASSES, aria: { label: content_for(:mobile_action_label) } }
32
36
  end
@@ -9,12 +9,6 @@ module Keystone
9
9
  </svg>
10
10
  SVG
11
11
 
12
- ELLIPSIS_ICON = <<~SVG.freeze
13
- <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
14
- <path stroke-linecap="round" stroke-linejoin="round" d="M12 6.75a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5ZM12 12.75a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5ZM12 18.75a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5Z" />
15
- </svg>
16
- SVG
17
-
18
12
  ROW_CLASSES = "ks-page flex items-center ks-grid-gap-sm lg:hidden print:hidden max-lg:in-[.top-nav]:contents"
19
13
  WRAPPER_CLASSES = "flex items-center lg:hidden print:hidden"
20
14
  BACK_LINK_CLASSES = "ks-mobile-header-back"
@@ -22,15 +16,7 @@ module Keystone
22
16
  SUBTITLE_CLASSES = "ks-mobile-header-subtitle block text-xs truncate"
23
17
  OVERLINE_CLASSES = "ks-mobile-header-subtitle block text-xs truncate"
24
18
  BADGE_CLASSES = "ml-auto shrink-0 self-center"
25
- DROPDOWN_CLASSES = "ks-action-menu hidden absolute right-0 z-50 w-48 origin-top-right"
26
19
 
27
- # Renders the left-side and title of the mobile header.
28
- # Call from the left side of your navbar.
29
- #
30
- # Usage in navbar:
31
- # <% if content_for?(:form_page) %>
32
- # <%= ui_mobile_header_left %>
33
- # <% end %>
34
20
  def initialize(title:, back_url:, subtitle: nil, overline: nil, badge: nil)
35
21
  @title = title
36
22
  @back_url = back_url
@@ -13,7 +13,7 @@ module Keystone
13
13
  CTA_CLASSES = "ks-card-link text-xs"
14
14
  META_CLASSES = "ks-card-meta font-mono text-xs ks-tone-muted"
15
15
  FINDING_CLASSES = "ks-alert ks-alert-warning text-xs"
16
- TONE_CLASSES = { muted: "ks-tone-muted", neutral: "ks-tone-neutral", success: "ks-tone-success", warning: "ks-tone-warning", danger: "ks-tone-danger", info: "ks-tone-info" }.freeze
16
+ TONE_CLASSES = [ :muted, *States::NAMES ].to_h { |tone| [ tone, "ks-tone-#{tone}" ] }.freeze
17
17
 
18
18
  def initialize(id:, title:, score: nil, score_tone: :muted, body: nil, cta: nil, meta: nil, finding: nil, actions: [], compact: false)
19
19
  @id = id
@@ -24,6 +24,10 @@ module Keystone
24
24
  @extra_classes = binding.local_variable_get(:class)
25
25
  end
26
26
 
27
+ def before_render
28
+ raise ArgumentError, "A section's aside needs a title" if aside? && !header?
29
+ end
30
+
27
31
  def spacing_class
28
32
  SPACING_CLASSES.fetch(@spacing)
29
33
  end
@@ -26,13 +26,7 @@ module Keystone
26
26
  <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
27
27
  SVG
28
28
 
29
- VARIANT_CLASSES = {
30
- neutral: "ks-tone-neutral",
31
- success: "ks-tone-success",
32
- danger: "ks-tone-danger",
33
- warning: "ks-tone-warning",
34
- info: "ks-tone-info"
35
- }.freeze
29
+ VARIANT_CLASSES = States::NAMES.to_h { |state| [ state, "ks-tone-#{state}" ] }.freeze
36
30
 
37
31
  attr_reader :label, :value, :suffix, :definition, :calculation, :change, :href, :note
38
32
 
@@ -17,6 +17,11 @@
17
17
  <%= content %>
18
18
  <% end %>
19
19
  <% else %>
20
+ <% tab_panels = capture do %>
21
+ <% panels.each_with_index do |panel, index| %>
22
+ <fieldset class="min-w-0" data-tab-switcher-target="panel"<%= " hidden disabled" unless index.zero? %>><%= panel %></fieldset>
23
+ <% end %>
24
+ <% end %>
20
25
  <div data-controller="tab-switcher"<% if summary? %> class="<%= LAYOUT_CLASSES %>"<% end %>>
21
26
  <% if summary? %>
22
27
  <div class="<%= SUMMARY_CLASSES %>"><%= summary %></div>
@@ -33,9 +38,9 @@
33
38
  <% end %>
34
39
  </div>
35
40
  <% if summary? %>
36
- <div class="<%= CONTENT_CLASSES %>"><%= content %></div>
41
+ <div class="<%= CONTENT_CLASSES %>"><%= content %><%= tab_panels %></div>
37
42
  <% else %>
38
- <%= content %>
43
+ <%= content %><%= tab_panels %>
39
44
  <% end %>
40
45
  </div>
41
46
  <% end %>
@@ -9,12 +9,12 @@ module Keystone
9
9
  SHAPE_CLASSES = { pills: "ks-tab-bar-pills", underline: "ks-tab-bar-underline" }.freeze
10
10
  TAB_BASE_CLASSES = "ks-tab text-sm transition max-sm:shrink-0 max-sm:whitespace-nowrap"
11
11
  SHAPED_TAB_BASE_CLASSES = "ks-tab transition max-sm:shrink-0 max-sm:whitespace-nowrap"
12
- PANEL_CLASSES = "hidden"
13
12
  LAYOUT_CLASSES = "max-sm:flex max-sm:flex-col"
14
13
  SUMMARY_CLASSES = "max-sm:order-1 max-sm:[&>:first-child]:mt-0 max-sm:[&>:last-child]:mb-0"
15
14
  CONTENT_CLASSES = "max-sm:order-1"
16
15
 
17
16
  renders_one :summary
17
+ renders_many :panels
18
18
 
19
19
  attr_reader :tabs
20
20
 
@@ -49,14 +49,6 @@ module Keystone
49
49
 
50
50
  content_tag(:span, count, class: "ks-tab-count")
51
51
  end
52
-
53
- def panel_classes
54
- PANEL_CLASSES
55
- end
56
-
57
- def wrapper_data
58
- { controller: "tab-switcher" }
59
- end
60
52
  end
61
53
  end
62
54
  end
@@ -19,8 +19,11 @@ module Keystone
19
19
  @before = before.to_s.lines(chomp: true)
20
20
  @after = after.to_s.lines(chomp: true)
21
21
  @one_column = one_column
22
+ @comparisons = 0
22
23
  end
23
24
 
25
+ attr_reader :comparisons
26
+
24
27
  def one_column?
25
28
  @one_column
26
29
  end
@@ -60,39 +63,63 @@ module Keystone
60
63
  end
61
64
 
62
65
  def compare
63
- before_index = after_index = 0
64
- rows = []
65
- while before_index < @before.size || after_index < @after.size
66
- if before_index < @before.size && after_index < @after.size && @before[before_index] == @after[after_index]
67
- rows << [ { text: @before[before_index], number: before_index + 1 }, { text: @after[after_index], number: after_index + 1 } ]
68
- before_index += 1
69
- after_index += 1
70
- elsif before_index < @before.size && (after_index == @after.size || shared[before_index + 1][after_index] >= shared[before_index][after_index + 1])
71
- rows << [ { text: @before[before_index], number: before_index + 1, mark: "ks-diff-removed", sign: "-" }, nil ]
72
- before_index += 1
73
- else
74
- rows << [ nil, { text: @after[after_index], number: after_index + 1, mark: "ks-diff-added", sign: "+" } ]
75
- after_index += 1
66
+ edits.map do |step, before_index, after_index|
67
+ case step
68
+ when :same then [ { text: @before[before_index], number: before_index + 1 }, { text: @after[after_index], number: after_index + 1 } ]
69
+ when :remove then [ { text: @before[before_index], number: before_index + 1, mark: "ks-diff-removed", sign: "-" }, nil ]
70
+ else [ nil, { text: @after[after_index], number: after_index + 1, mark: "ks-diff-added", sign: "+" } ]
71
+ end
72
+ end
73
+ end
74
+
75
+ def edits
76
+ before_index = @before.size
77
+ after_index = @after.size
78
+ steps = []
79
+ furthest_reaches.each_with_index.reverse_each do |reach, changes|
80
+ diagonal = before_index - after_index
81
+ previous_diagonal = added_on?(reach, diagonal, changes) ? diagonal + 1 : diagonal - 1
82
+ previous_before = reach[previous_diagonal]
83
+ previous_after = previous_before - previous_diagonal
84
+ while before_index > previous_before && after_index > previous_after
85
+ before_index -= 1
86
+ after_index -= 1
87
+ steps << [ :same, before_index, after_index ]
76
88
  end
89
+ next if changes.zero?
90
+
91
+ steps << (before_index == previous_before ? [ :add, nil, after_index - 1 ] : [ :remove, before_index - 1, nil ])
92
+ before_index = previous_before
93
+ after_index = previous_after
77
94
  end
78
- rows
95
+ steps.reverse
79
96
  end
80
97
 
81
- def shared
82
- @shared ||= begin
83
- table = Array.new(@before.size + 1) { Array.new(@after.size + 1, 0) }
84
- (@before.size - 1).downto(0) do |before_index|
85
- (@after.size - 1).downto(0) do |after_index|
86
- table[before_index][after_index] = if @before[before_index] == @after[after_index]
87
- table[before_index + 1][after_index + 1] + 1
88
- else
89
- [ table[before_index + 1][after_index], table[before_index][after_index + 1] ].max
90
- end
98
+ def furthest_reaches
99
+ reach = { 1 => 0 }
100
+ (0..(@before.size + @after.size)).each_with_object([]) do |changes, reaches|
101
+ reaches << reach.dup
102
+ (-changes).step(changes, 2) do |diagonal|
103
+ before_index = added_on?(reach, diagonal, changes) ? reach[diagonal + 1] : reach[diagonal - 1] + 1
104
+ after_index = before_index - diagonal
105
+ while before_index < @before.size && after_index < @after.size && same_line?(before_index, after_index)
106
+ before_index += 1
107
+ after_index += 1
91
108
  end
109
+ reach[diagonal] = before_index
110
+ return reaches if before_index >= @before.size && after_index >= @after.size
92
111
  end
93
- table
94
112
  end
95
113
  end
114
+
115
+ def same_line?(before_index, after_index)
116
+ @comparisons += 1
117
+ @before[before_index] == @after[after_index]
118
+ end
119
+
120
+ def added_on?(reach, diagonal, changes)
121
+ diagonal == -changes || (diagonal != changes && reach[diagonal - 1] < reach[diagonal + 1])
122
+ end
96
123
  end
97
124
  end
98
125
  end
@@ -132,6 +132,7 @@ module Keystone
132
132
  def check_times(entry)
133
133
  raise ArgumentError, "Timeline entry #{entry[:label].inspect} has no started_at" unless entry[:started_at]
134
134
  raise ArgumentError, "Timeline entry #{entry[:label].inspect} ends before it starts" if entry[:ended_at] && entry[:ended_at] < entry[:started_at]
135
+ raise ArgumentError, "Timeline entry #{entry[:label].inspect} is queued after it starts" if entry[:queued_at] && entry[:queued_at] > entry[:started_at]
135
136
  end
136
137
 
137
138
  def written_duration(seconds)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.99.0"
4
+ VERSION = "0.101.0"
5
5
  end
@@ -81,7 +81,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
81
81
  - `ui_paragraph` — a paragraph of running text.
82
82
  - `ui_value_list` — labelled values, as rows of a label beside its value, such as a ledger or a byline, or as columns of a label above its value.
83
83
  - `ui_alert` — a banner message, optionally dismissible.
84
- - `ui_link_list` — a list of links, each row with a label, an optional subtitle, badge, value and top line, an optional current-row mark, and a chevron that can be left off.
84
+ - `ui_link_list` — a list of links, each row with a label, an optional subtitle, badge, value and top line, an optional current-row mark, and a chevron that can be left off, with every link opening in a new tab when asked.
85
85
  - `ui_empty_state` — what a list or section shows when it has nothing in it, with an optional message and action.
86
86
  - `ui_progress` — a labelled progress bar.
87
87
  - `ui_stat_card` — a single metric tile with optional change, link and info button, or a compact tile for a small grid of figures inside a panel.
@@ -93,7 +93,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
93
93
  - `ui_info` — an inline info button showing a summary, and optional detail, in floating panels.
94
94
  - `ui_breakdown` — a list of amounts ending in their total.
95
95
  - `ui_accordion` — a stack of question-and-answer rows that expand independently.
96
- - `ui_tab_switcher` — a row of tabs that reports which one was selected, or a row of link tabs with optional counts, drawn centred or from the start, as plain tabs, pills or underlined tabs.
96
+ - `ui_tab_switcher` — a row of tabs that reports which one was selected and can show one panel per tab on the same page, or a row of link tabs with optional counts, drawn centred or from the start, as plain tabs, pills or underlined tabs.
97
97
  - `ui_modal` — a hidden dialog the app's own code opens.
98
98
  - `ui_swipe_deck` — a stack of cards accepted or rejected by button or swipe.
99
99
  - `ui_chart_card` — a titled card holding a chart.
@@ -189,10 +189,10 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
189
189
  the main action send that method: the header's button and
190
190
  `ui_mobile_action`'s icon become forms posting to `action_url:`.
191
191
  - `action_confirm:` is a question Turbo asks before the main action goes
192
- ahead, on the header's button and on `ui_bottom_action`'s button, as
193
- `ui_button`'s `confirm:` does. `ui_mobile_action`'s plus icon does not ask
194
- it, so a screen whose action needs a question shows `ui_bottom_action` on
195
- a phone, not the plus icon. It applies only with `action_url:` and is
192
+ ahead, on the header's button, on `ui_bottom_action`'s button and on
193
+ `ui_mobile_action`'s plus icon when `action_method:` is given, as
194
+ `ui_button`'s `confirm:` does. The plus icon of an action with no
195
+ `action_method:` is a link and does not ask it. It applies only with `action_url:` and is
196
196
  ignored when an `action` block is given. Ask the developer whether a
197
197
  screen's main action needs a question and how it is worded.
198
198
  - `subtitle_mono: true` draws the subtitle in a fixed-width font, such as
@@ -236,7 +236,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
236
236
  keywords of `ui_action_menu_item`, and renders an action menu. The link
237
237
  and the menu sit side by side at the right edge of the header, the link
238
238
  first, at every width. `spacing:` is `:sm` `:md` `:lg`. The header, with its
239
- `action:`, `menu:` and aside, renders only when `title:` is given.
239
+ `action:`, `menu:` and aside, renders only when `title:` is given, and an
240
+ aside given with no `title:` raises `ArgumentError`.
240
241
  - The block yields the section, and `section.with_aside { ... }` in it puts
241
242
  short text or a `ui_badge`, such as a sort order or a step's state, in
242
243
  small muted text at the right end of the title line, before the link and
@@ -403,8 +404,11 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
403
404
  `sm:` in its place, `phone_only: true`, which shows the action below
404
405
  `sm:` only, and `phone_order:` 1, 2 or 3, its place in the phone row, so
405
406
  one call can give a desktop row and a phone row that differ in labels,
406
- buttons and order. Do not give an action `href:` with a `method:` other than `:get`,
407
- since that draws a form inside the bar's form. `note:` takes `name:`,
407
+ buttons and order. Any other `phone_order:` raises `KeyError`. An action
408
+ with `href:` and a `method:` such as `:delete` sends the bar's form, note
409
+ included, to its own `href:` with that method, while every other button
410
+ still sends it to `url:` with the bar's `method:`. Such an action cannot
411
+ also take `name:` or `value:`, and giving either raises `ArgumentError`. `note:` takes `name:`,
408
412
  `label:` and `placeholder:` and draws a text field inside its label, sent
409
413
  with the form. `hint:` is a short line of muted text, such as keyboard
410
414
  keys. From `sm:` up it draws a panel holding the note field, the
@@ -459,7 +463,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
459
463
  empty option, worded by `include_blank:` or left blank without it, so
460
464
  never add an empty choice to `options:` as well.
461
465
  - A `:checkbox` renders its label beside the box, submits `"0"` unchecked
462
- and `"1"` checked, and is checked when `value:` is `"1"`.
466
+ and `"1"` checked, and is checked when `value:` is `"1"`. With
467
+ `required: true` the browser will not submit the form while it is
468
+ unticked, as for a terms of service box.
463
469
  - `suggestions:` is an array of strings the browser offers while typing, and
464
470
  the user can still type any value. It applies to `:text` `:number`
465
471
  `:email` `:password` `:date` `:datetime` and is ignored by the other types. Its list
@@ -677,7 +683,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
677
683
 
678
684
  9. Show content and status.
679
685
 
680
- - `ui_button(label:, href: nil, method: :get, variant: :primary, size: :md, full_width: false, type: :submit, data: nil, name: nil, value: nil, hidden: false, confirm: nil, disabled: false)`
686
+ - `ui_button(label:, href: nil, method: :get, variant: :primary, size: :md, full_width: false, type: :submit, data: nil, name: nil, value: nil, hidden: false, confirm: nil, disabled: false, formaction: nil)`
681
687
  renders a link with `href:` and a button without it. `variant:` is
682
688
  `:primary` `:secondary` `:danger` `:text`, `size:` is `:sm` `:md` `:lg`,
683
689
  and `type:`, `name:` and `value:` apply only to the button.
@@ -685,6 +691,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
685
691
  as a Back or Previous control under a form. A button given `name:` and
686
692
  `value:` submits them with its form when pressed. `hidden: true` draws it
687
693
  with the `hidden` attribute, for the app's own script to show.
694
+ `formaction:` makes a button without `href:` send its form to that
695
+ address in place of the form's own when pressed.
688
696
  - `disabled: true` draws a button without `href:` with the `disabled`
689
697
  attribute, so it cannot be pressed and does not submit its form. It is
690
698
  for a button without `href:`: a link ignores the attribute and stays
@@ -738,7 +746,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
738
746
  - `ui_alert(message:, type: :info, title: nil, dismissible: false, class: nil)`
739
747
  — `type:` is `:info` `:success` `:warning` `:error`, and `dismissible: true`
740
748
  adds a close button.
741
- - `ui_link_list(rows:, chevron: true)` — each row is `{ label:, href:,
749
+ - `ui_link_list(rows:, chevron: true, new_tab: false)` — each row is `{ label:, href:,
742
750
  subtitle: nil, badge: nil, value: nil, top_line: nil, current: false }`,
743
751
  and `badge:` takes `ui_badge`'s `{ label:, variant: }`.
744
752
  A row's badge sits above its label below `sm` and beside it from `sm` up.
@@ -749,7 +757,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
749
757
  the label and subtitle wrap. `current: true` marks the
750
758
  row the person has open with `aria-current` and a tint and accent bar.
751
759
  `chevron: false` leaves off every row's chevron, as in a queue beside the
752
- open item. Ask the developer which row is current on each page.
760
+ open item. `new_tab: true` opens every row's link in a new browser tab
761
+ with `rel="noopener"`, so a person reading the terms beside a form keeps
762
+ the form open. Ask the developer which row is current on each page.
753
763
  Use it for a list of records that each open their own page, in place of a
754
764
  hand-written `<ul>` of links.
755
765
  - `ui_empty_state(title:, message: nil, action: nil)` — `action:` is
@@ -872,7 +882,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
872
882
  `height:` `:sm` `:md` `:lg`.
873
883
  - `ui_bar_chart(bars:, show_values: false, strip: false)` — `bars:` is
874
884
  `[{ label:, value:, shaded:, group: }, ...]`, where `shaded: true` draws
875
- a bar faded. It is drawn on the server as an SVG, so use it, not
885
+ a bar faded. A negative `value:` raises `ArgumentError` naming it. It
886
+ is drawn on the server as an SVG, so use it, not
876
887
  `ui_line_chart`, for a chart that must print or show without JavaScript.
877
888
  - Give bars `group:`, such as the version that produced each one, to show
878
889
  groups of bars. Groups count from oldest to newest in the order their
@@ -993,7 +1004,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
993
1004
  `1m 30s` or `1h 5s`.
994
1005
  - Ask the developer which layout a screen uses.
995
1006
  - An entry with no `started_at:` raises `ArgumentError` naming its label,
996
- and so does an entry whose `ended_at:` is before its `started_at:`. Check
1007
+ and so does an entry whose `ended_at:` is before its `started_at:` or
1008
+ whose `queued_at:` is after it. Check
997
1009
  the times before rendering rather than rescuing the error.
998
1010
  - An empty `entries:` draws a centred "No steps" message in place of the
999
1011
  timeline, so it can be rendered for a list that may be empty. The
@@ -1015,8 +1027,17 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
1015
1027
  opens it, so the app's code removes `hidden`.
1016
1028
  - `ui_tab_switcher(tabs:)` takes an array of label strings and a block
1017
1029
  rendered below the tabs. The first tab is active on load, and a click
1018
- sends a `tab-switcher:change` event with the clicked index. Showing and
1019
- hiding the panels is the app's code.
1030
+ sends a `tab-switcher:change` event with the clicked index. Without
1031
+ panels, showing and hiding what each tab holds is the app's code.
1032
+ - `switcher.with_panel { ... }`, called once per label tab inside the
1033
+ tab switcher's block in the order of `tabs:`, draws that tab's panel.
1034
+ The first panel shows on load, and choosing a tab shows its panel and
1035
+ hides the others on the same page, so values typed into fields on any
1036
+ panel are kept. A hidden panel's fields are disabled, so a required
1037
+ field on a hidden tab does not block the form and is not submitted.
1038
+ Use panels for tabs that hold form fields, such as a sign-up form
1039
+ choosing between a password and an emailed code, rather than link tabs,
1040
+ which load a new page and lose what was typed.
1020
1041
  - `ui_tab_switcher(tabs:)` also takes link tabs, an array of hashes
1021
1042
  `{ label:, href:, current: }`. Each is drawn as a link to its `href`, the
1022
1043
  one with `current: true` is drawn active with `aria-current="page"`, and
@@ -100,7 +100,14 @@ One decision: is keystone_ui set up in the app?
100
100
  table's current row and announced to screen readers as the current item.
101
101
  - **Tab rows.** A tab switcher's tabs are either labels switched in the
102
102
  browser or links to addresses, with the chosen link drawn as the current
103
- tab. A link tab can carry a count shown after its label. The row is centred
103
+ tab. Label tabs can each hold a panel on the same page, and choosing a tab
104
+ shows its panel and hides the others, so values typed into fields are kept,
105
+ and the fields of a hidden panel are disabled, so a required field on a
106
+ hidden panel does not stop the form being sent. A panel can be narrower than
107
+ its content, so a wide panel does not widen the page on a phone. A link tab
108
+ can carry a count shown after its label, and a count of zero is shown only
109
+ when the tab asks for it. A tab switcher can hold a summary, drawn above the
110
+ tabs on a wider screen and below them on a phone. The row is centred
104
111
  on wider screens, or starts at the left edge when asked. It can be drawn as
105
112
  plain tabs, as outlined pills such as a row of filters, or as tabs on a line
106
113
  with the chosen one underlined. On a phone every row stays on one line and
@@ -128,7 +135,7 @@ One decision: is keystone_ui set up in the app?
128
135
  style at the right end of the title line, before the action and the menu.
129
136
  The aside never breaks in the middle of a word, and on wider screens a long
130
137
  title wraps beside it while it keeps its full width. Below `sm:` the aside
131
- takes a line of its own under the title and the actions. A section with no title draws no header, so its aside is not shown.
138
+ takes a line of its own under the title and the actions. A section given an aside and no title raises an error, since the header that shows the aside needs a title.
132
139
  - **Going back.** A form or show page shell needs a way back: a back link, a
133
140
  trail of earlier pages shown as breadcrumbs, or a trail the app supplies for
134
141
  the request. A nav tab's own page passes an empty trail and shows no back
@@ -194,7 +201,8 @@ One decision: is keystone_ui set up in the app?
194
201
  layout. Below `sm:` the layout can show it again as a plus icon in the top
195
202
  bar, or as a full-width button in a bar fixed to the bottom of the screen,
196
203
  above the bottom tab bar when the page has one. The bottom bar asks the
197
- header's confirmation question before sending, and the plus icon does not.
204
+ header's confirmation question before sending, and so does the plus icon
205
+ when the action sends a method other than a plain visit.
198
206
  The page leaves room under its last content so the bar does not cover it.
199
207
  A header can mark its action as belonging at the bottom, and then hides its
200
208
  own button below `sm:` so the action is not shown twice. Both forms show
@@ -218,7 +226,10 @@ One decision: is keystone_ui set up in the app?
218
226
  width above a row of the secondary buttons in equal shares, a long label
219
227
  wrapping inside its button, and with no note field or hint. The width at
220
228
  which it switches between the two can be moved from `sm:` to `md:` or `lg:`. Each secondary button can have a shorter label on a phone, be
221
- shown on a phone only, and take another place in the phone row. The page leaves room under its last content so the bar does
229
+ shown on a phone only, and take another place in the phone row. A
230
+ secondary button can also send its own request, such as a delete, to its
231
+ own address, while the other buttons still send the bar's form to the
232
+ bar's address. The page leaves room under its last content so the bar does
222
233
  not cover it. Unlike the main action's bottom bar, it stays shown inside a
223
234
  Hotwire Native web view.
224
235
  - **Action menus.** Each action is a label, an address and an HTTP method. A
@@ -226,7 +237,9 @@ One decision: is keystone_ui set up in the app?
226
237
  changes data is never a bare link. A delete asks for confirmation by default.
227
238
  - **Status states.** A badge and a status dot read one list of five states:
228
239
  neutral, success, danger, warning and info. A state added to that list is
229
- accepted by both, so the two never disagree about which states exist. A badge
240
+ accepted by both, so the two never disagree about which states exist. A stat
241
+ card's tones and a review card's score tones, which add a muted tone, read
242
+ the same list. A badge
230
243
  shows its label as text. A status dot shows only its state's colour, for
231
244
  places with no room for text, and its label is read only by screen readers.
232
245
  Neither accepts a state outside the list: a status dot raises `ArgumentError`
@@ -271,4 +284,4 @@ One decision: is keystone_ui set up in the app?
271
284
  Stimulus controllers, so a host writes no JavaScript. Components that post,
272
285
  such as the column picker and the pipeline, post to endpoints the host or
273
286
  another gem owns.
274
- - Ruby >= 3.2, ViewComponent >= 2.0 and < 5, keystone_ui-styles >= 0.34.0.
287
+ - Ruby >= 3.2, ViewComponent >= 2.0 and < 5, keystone_ui-styles >= 0.42.0.
@@ -52,7 +52,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
52
52
  ## How to use it
53
53
 
54
54
  1. Confirm the prerequisites: Ruby >= 3.2 and **tailwindcss-rails v4+** in the
55
- host app. The gem brings ViewComponent and keystone_ui-styles 0.34.0 or later with it.
55
+ host app. The gem brings ViewComponent and keystone_ui-styles 0.42.0 or later with it.
56
56
  Tailwind does not have to be initialized first, because the generator creates
57
57
  the stylesheet if it is missing.
58
58
 
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.99.0
4
+ version: 0.101.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider