keystone_ui 0.99.0 → 0.100.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: '0040955f96b3a7ec54489372d7842d86f9b099d41c7fd6f26acd6e1b2fc6ffed'
4
+ data.tar.gz: eef2890bb1a7f67dd1035b223f583d21a473aa9c126a9bc3f92f772a87a2ea5a
5
5
  SHA512:
6
- metadata.gz: 5056738e253f18d5f2ca3d732d727a33523cda10054e181e4f2e9a3d6c892d5064ee416edffc2f738bebbe7cc425e8b5add580503dfd36dafbf9f0a9d1b522a8
7
- data.tar.gz: 40b4f45fc19561b23dbca6e131e071dea1038050eae13470345687baf663157871c4a3036319d747e6a157aaa4e510d61387268c7de6226508997d8897a92c88
6
+ metadata.gz: 48abd5b626786f17663321345fddb275a4e048205cd63a365314179e7e926f0d6ef244b1b741eb665682d29af1931f3d4078e8b7e80527810fa757ab61551207
7
+ data.tar.gz: f0853879c5cbae9cb200d801ac96e74b5df4c190c6cb050591ec063bf319ae720942d7d7745bc4161ddf2dd819f223d9d9ef303c5cdf26889a4b96c8d15f9538
@@ -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
  }
@@ -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)
@@ -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 %>
@@ -15,6 +15,7 @@ module Keystone
15
15
  CONTENT_CLASSES = "max-sm:order-1"
16
16
 
17
17
  renders_one :summary
18
+ renders_many :panels
18
19
 
19
20
  attr_reader :tabs
20
21
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.99.0"
4
+ VERSION = "0.100.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.
@@ -459,7 +459,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
459
459
  empty option, worded by `include_blank:` or left blank without it, so
460
460
  never add an empty choice to `options:` as well.
461
461
  - A `:checkbox` renders its label beside the box, submits `"0"` unchecked
462
- and `"1"` checked, and is checked when `value:` is `"1"`.
462
+ and `"1"` checked, and is checked when `value:` is `"1"`. With
463
+ `required: true` the browser will not submit the form while it is
464
+ unticked, as for a terms of service box.
463
465
  - `suggestions:` is an array of strings the browser offers while typing, and
464
466
  the user can still type any value. It applies to `:text` `:number`
465
467
  `:email` `:password` `:date` `:datetime` and is ignored by the other types. Its list
@@ -738,7 +740,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
738
740
  - `ui_alert(message:, type: :info, title: nil, dismissible: false, class: nil)`
739
741
  — `type:` is `:info` `:success` `:warning` `:error`, and `dismissible: true`
740
742
  adds a close button.
741
- - `ui_link_list(rows:, chevron: true)` — each row is `{ label:, href:,
743
+ - `ui_link_list(rows:, chevron: true, new_tab: false)` — each row is `{ label:, href:,
742
744
  subtitle: nil, badge: nil, value: nil, top_line: nil, current: false }`,
743
745
  and `badge:` takes `ui_badge`'s `{ label:, variant: }`.
744
746
  A row's badge sits above its label below `sm` and beside it from `sm` up.
@@ -749,7 +751,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
749
751
  the label and subtitle wrap. `current: true` marks the
750
752
  row the person has open with `aria-current` and a tint and accent bar.
751
753
  `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.
754
+ open item. `new_tab: true` opens every row's link in a new browser tab
755
+ with `rel="noopener"`, so a person reading the terms beside a form keeps
756
+ the form open. Ask the developer which row is current on each page.
753
757
  Use it for a list of records that each open their own page, in place of a
754
758
  hand-written `<ul>` of links.
755
759
  - `ui_empty_state(title:, message: nil, action: nil)` — `action:` is
@@ -1015,8 +1019,17 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
1015
1019
  opens it, so the app's code removes `hidden`.
1016
1020
  - `ui_tab_switcher(tabs:)` takes an array of label strings and a block
1017
1021
  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.
1022
+ sends a `tab-switcher:change` event with the clicked index. Without
1023
+ panels, showing and hiding what each tab holds is the app's code.
1024
+ - `switcher.with_panel { ... }`, called once per label tab inside the
1025
+ tab switcher's block in the order of `tabs:`, draws that tab's panel.
1026
+ The first panel shows on load, and choosing a tab shows its panel and
1027
+ hides the others on the same page, so values typed into fields on any
1028
+ panel are kept. A hidden panel's fields are disabled, so a required
1029
+ field on a hidden tab does not block the form and is not submitted.
1030
+ Use panels for tabs that hold form fields, such as a sign-up form
1031
+ choosing between a password and an emailed code, rather than link tabs,
1032
+ which load a new page and lose what was typed.
1020
1033
  - `ui_tab_switcher(tabs:)` also takes link tabs, an array of hashes
1021
1034
  `{ label:, href:, current: }`. Each is drawn as a link to its `href`, the
1022
1035
  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
@@ -271,4 +278,4 @@ One decision: is keystone_ui set up in the app?
271
278
  Stimulus controllers, so a host writes no JavaScript. Components that post,
272
279
  such as the column picker and the pipeline, post to endpoints the host or
273
280
  another gem owns.
274
- - Ruby >= 3.2, ViewComponent >= 2.0 and < 5, keystone_ui-styles >= 0.34.0.
281
+ - 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.100.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider