keystone_ui 0.97.0 → 0.98.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: 7a6d1b9a708eca00e9bbc2d350357bbc6e143412e710d28e5aa0839c3b9e3b25
4
- data.tar.gz: c16b15329182ef72fcfee00f5f93c7c0627e57900d49e7c793ea6c2fe40212af
3
+ metadata.gz: b06865adca7eac807aac5fbd1f9bce525eb3f6f0252a714eb231659bbb24cd3b
4
+ data.tar.gz: 32d3cd096e09dcdf03988b42876c41624af1a6656d31de729245ef19b50b534c
5
5
  SHA512:
6
- metadata.gz: 03e29e1487956c4e3fa22f3446aff808adf896c0f743e76f92d00159825e0323de173afa73d300f453774c59fd8594ffaecb2e4941d9123930b6c45e54beb005
7
- data.tar.gz: b62f7a4d3a0c19f10e9d61801d0d3d77143de191ab5b01791316c6ba87f39717c7a81697bee2456c9039a51a830b17f3cc1e0afd4f802a79eb715295b7f34ee1
6
+ metadata.gz: d16b34c2ed52eccc7eac83a5ebf3c364572db00738cd725ad364a5947cc8ff20649e607cdaa6db376e1c2a442b8720b0892ccdbe93f08dffed3b8a10b6663491
7
+ data.tar.gz: 481a80996a6e575729110223154d07283f790262fff02842162a57fc4e411a7f8a49b8630c3d9cd8dd8004e9ee22c8917763877c508ee7f759d7e3d368d0bcd6
@@ -2,7 +2,7 @@
2
2
  <% tab_row = capture do %>
3
3
  <nav class="<%= classes %>">
4
4
  <% tabs.each do |tab| %>
5
- <a href="<%= tab[:href] %>" data-turbo-action="replace" class="<%= tab[:current] ? tab_classes : TAB_BASE_CLASSES %>"<% if tab[:current] %> aria-current="page" data-active<% end %>><%= tab[:label] %></a>
5
+ <a href="<%= tab[:href] %>" data-turbo-action="replace" class="<%= tab[:current] ? tab_classes : base_tab_classes %>"<% if tab[:current] %> aria-current="page" data-active<% end %>><%= tab[:label] %><% if tab[:count].to_i.positive? %> <%= count_mark(tab[:count]) %><% end %></a>
6
6
  <% end %>
7
7
  </nav>
8
8
  <% end %>
@@ -4,7 +4,11 @@ module Keystone
4
4
  module Ui
5
5
  class TabSwitcherComponent < ViewComponent::Base
6
6
  TAB_BAR_CLASSES = "ks-tab-bar flex flex-wrap justify-center max-sm:flex-nowrap max-sm:overflow-x-auto max-sm:justify-start"
7
+ START_TAB_BAR_CLASSES = "ks-tab-bar flex flex-wrap justify-start max-sm:flex-nowrap max-sm:overflow-x-auto"
8
+ TAB_BAR_CLASSES_BY_ALIGN = { center: TAB_BAR_CLASSES, start: START_TAB_BAR_CLASSES }.freeze
9
+ SHAPE_CLASSES = { pills: "ks-tab-bar-pills", underline: "ks-tab-bar-underline" }.freeze
7
10
  TAB_BASE_CLASSES = "ks-tab text-sm transition max-sm:shrink-0 max-sm:whitespace-nowrap"
11
+ SHAPED_TAB_BASE_CLASSES = "ks-tab transition max-sm:shrink-0 max-sm:whitespace-nowrap"
8
12
  PANEL_CLASSES = "hidden"
9
13
  LAYOUT_CLASSES = "max-sm:flex max-sm:flex-col"
10
14
  SUMMARY_CLASSES = "max-sm:order-1 max-sm:[&>:first-child]:mt-0 max-sm:[&>:last-child]:mb-0"
@@ -14,8 +18,10 @@ module Keystone
14
18
 
15
19
  attr_reader :tabs
16
20
 
17
- def initialize(tabs:)
21
+ def initialize(tabs:, align: :center, shape: nil)
18
22
  @tabs = tabs
23
+ @align = align
24
+ @shape = shape
19
25
  end
20
26
 
21
27
  def link_tabs?
@@ -23,11 +29,21 @@ module Keystone
23
29
  end
24
30
 
25
31
  def classes
26
- TAB_BAR_CLASSES
32
+ [ TAB_BAR_CLASSES_BY_ALIGN.fetch(@align), SHAPE_CLASSES[@shape] ].compact.join(" ")
33
+ end
34
+
35
+ def base_tab_classes
36
+ @shape ? SHAPED_TAB_BASE_CLASSES : TAB_BASE_CLASSES
27
37
  end
28
38
 
29
39
  def tab_classes
30
- "#{TAB_BASE_CLASSES} ks-tab-active"
40
+ "#{base_tab_classes} ks-tab-active"
41
+ end
42
+
43
+ def count_mark(count)
44
+ return render(BadgeComponent.new(label: count.to_s, variant: :info)) unless @shape
45
+
46
+ content_tag(:span, count, class: "ks-tab-count")
31
47
  end
32
48
 
33
49
  def panel_classes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.97.0"
4
+ VERSION = "0.98.0"
5
5
  end
@@ -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.
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.
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.
@@ -998,9 +998,18 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
998
998
  takes content such as stat cards. From `sm` up it is drawn above the
999
999
  tab row, and below `sm` between the tab row and the panel. It is drawn
1000
1000
  once, so do not draw it twice or add width-specific classes for it.
1001
+ - A link tab takes `count:`, drawn after its label when it is above zero
1002
+ in an info badge, as a navigation item draws its count.
1003
+ - `align: :start` starts the tab row at the left edge on every width
1004
+ instead of centring it from `sm` up.
1005
+ - `shape: :pills` draws each tab as an outlined pill, such as a row of
1006
+ filters, and `shape: :underline` draws the tabs on a line with the
1007
+ chosen tab underlined. In either shape a count is drawn as plain muted
1008
+ text after the label, and the shape sets the tabs' text size, so do not
1009
+ add a text size class.
1001
1010
  - Below `sm` every tab switcher's tab row stays on one line, starts at
1002
1011
  the left edge and scrolls sideways, and from `sm` up it wraps and is
1003
- centred.
1012
+ centred unless `align: :start` is given.
1004
1013
  - `ui_swipe_deck(items:, empty_title: "All done!", empty_subtitle: nil)`
1005
1014
  takes a block yielding the deck, where `deck.item { |item| ... }` renders
1006
1015
  one card's face. Accepting sends a bubbling `swipe-deck:complete` event
@@ -97,6 +97,13 @@ One decision: is keystone_ui set up in the app?
97
97
  to the address of the last entry in that row that has one. An entry can be
98
98
  marked selected, and the row holding it is drawn in the same tint as a data
99
99
  table's current row and announced to screen readers as the current item.
100
+ - **Tab rows.** A tab switcher's tabs are either labels switched in the
101
+ browser or links to addresses, with the chosen link drawn as the current
102
+ tab. A link tab can carry a count shown after its label. The row is centred
103
+ on wider screens, or starts at the left edge when asked. It can be drawn as
104
+ plain tabs, as outlined pills such as a row of filters, or as tabs on a line
105
+ with the chosen one underlined. On a phone every row stays on one line and
106
+ scrolls sideways.
100
107
  - **Bar chart groups.** A bar chart's bars can be put in groups, such as one
101
108
  group per version of what produced them. Groups count from oldest to newest
102
109
  in the order they first appear. Every bar of a group shares one tone, and
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.97.0
4
+ version: 0.98.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.38.0
18
+ version: 0.39.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.38.0
25
+ version: 0.39.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement