keystone_ui 0.96.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: 7f8538f59f354ba28a22af1978d841fa009a30c8303082fbaeaab72fe5b26aed
4
- data.tar.gz: 4c175286b7c9d777579c37c505d86701dc6866b900f317ecbdfc5cafa2c284b1
3
+ metadata.gz: b06865adca7eac807aac5fbd1f9bce525eb3f6f0252a714eb231659bbb24cd3b
4
+ data.tar.gz: 32d3cd096e09dcdf03988b42876c41624af1a6656d31de729245ef19b50b534c
5
5
  SHA512:
6
- metadata.gz: ffe084ecc25acc64e9f21ba09714e9ccfef06861a77eaababf7705753a442a10aafa5ad6a42aad96ab3e61b68b4dc71770213d75a473971a6aeabf7a46348c0d
7
- data.tar.gz: 661ad787b150952dfb6646eb4e7e1430aabf63334442ce47bed952d538a1dfd270d33e77f7bc463bdef9716f972a4d9753c71d35ed0f0da8244f2929441777b2
6
+ metadata.gz: d16b34c2ed52eccc7eac83a5ebf3c364572db00738cd725ad364a5947cc8ff20649e607cdaa6db376e1c2a442b8720b0892ccdbe93f08dffed3b8a10b6663491
7
+ data.tar.gz: 481a80996a6e575729110223154d07283f790262fff02842162a57fc4e411a7f8a49b8630c3d9cd8dd8004e9ee22c8917763877c508ee7f759d7e3d368d0bcd6
@@ -1,13 +1,15 @@
1
- <div class="<%= Keystone::Ui::BarChartComponent::FRAME_CLASSES %>" role="img">
1
+ <div class="<%= frame_classes %>" role="img">
2
2
  <div class="<%= Keystone::Ui::BarChartComponent::PLOT_ROW_CLASSES %>">
3
- <svg class="<%= Keystone::Ui::BarChartComponent::AXIS_CLASSES %>">
4
- <% ticks.each do |tick| %>
5
- <text class="ks-bar-chart-text" data-axis-tick x="100%" dx="-6" y="<%= tick[:y].round(2) %>%" dominant-baseline="middle" text-anchor="end"><%= tick[:label] %></text>
6
- <% end %>
7
- </svg>
3
+ <% unless strip? %>
4
+ <svg class="<%= Keystone::Ui::BarChartComponent::AXIS_CLASSES %>">
5
+ <% ticks.each do |tick| %>
6
+ <text class="ks-bar-chart-text" data-axis-tick x="100%" dx="-6" y="<%= tick[:y].round(2) %>%" dominant-baseline="middle" text-anchor="end"><%= tick[:label] %></text>
7
+ <% end %>
8
+ </svg>
9
+ <% end %>
8
10
  <div class="<%= Keystone::Ui::BarChartComponent::PLOT_CLASSES %>">
9
11
  <svg class="<%= Keystone::Ui::BarChartComponent::LAYER_CLASSES %>" viewBox="0 0 100 100" preserveAspectRatio="none">
10
- <% ticks.each do |tick| %>
12
+ <% grid_lines.each do |tick| %>
11
13
  <line class="ks-bar-chart-grid" x1="0" x2="100" y1="<%= tick[:y].round(2) %>" y2="<%= tick[:y].round(2) %>" vector-effect="non-scaling-stroke"></line>
12
14
  <% end %>
13
15
  <% drawn_bars.each do |bar| %>
@@ -24,10 +26,12 @@
24
26
  </div>
25
27
  </div>
26
28
  <div class="<%= Keystone::Ui::BarChartComponent::LABEL_ROW_CLASSES %>">
27
- <span class="<%= Keystone::Ui::BarChartComponent::LABEL_SPACER_CLASSES %>"></span>
29
+ <% unless strip? %>
30
+ <span class="<%= Keystone::Ui::BarChartComponent::LABEL_SPACER_CLASSES %>"></span>
31
+ <% end %>
28
32
  <svg class="<%= Keystone::Ui::BarChartComponent::LABELS_CLASSES %>">
29
- <% drawn_bars.each do |bar| %>
30
- <text class="ks-bar-chart-text" data-bar-label x="<%= bar[:center].round(2) %>%" y="100%" dy="-6" text-anchor="middle"><%= bar[:label] %></text>
33
+ <% labelled_bars.each do |bar| %>
34
+ <text class="ks-bar-chart-text" data-bar-label x="<%= bar[:label_x].round(2) %>%" y="100%" dy="-6" text-anchor="<%= bar[:label_anchor] %>"><%= bar[:label] %></text>
31
35
  <% end %>
32
36
  </svg>
33
37
  </div>
@@ -4,6 +4,7 @@ module Keystone
4
4
  module Ui
5
5
  class BarChartComponent < ViewComponent::Base
6
6
  FRAME_CLASSES = "ks-bar-chart flex aspect-[5/2] max-h-80 w-full flex-col"
7
+ STRIP_FRAME_CLASSES = "ks-bar-chart flex h-[114px] w-full flex-col"
7
8
  PLOT_ROW_CLASSES = "flex min-h-0 flex-1"
8
9
  AXIS_CLASSES = "h-full w-10 shrink-0 overflow-visible"
9
10
  PLOT_CLASSES = "relative min-w-0 flex-1"
@@ -14,14 +15,25 @@ module Keystone
14
15
  FULL = 100.0
15
16
  HEADROOM = 8.0
16
17
  BAR_SHARE = 0.7
18
+ STRIP_BAR_SHARE = 0.92
17
19
  TICK_COUNT = 4
18
20
  ROUND_STEPS = [ 1, 2, 2.5, 5, 10 ].freeze
21
+ GROUP_TONES = 5
19
22
 
20
23
  attr_reader :bars
21
24
 
22
- def initialize(bars:, show_values: false)
25
+ def initialize(bars:, show_values: false, strip: false)
23
26
  @bars = bars
24
27
  @show_values = show_values
28
+ @strip = strip
29
+ end
30
+
31
+ def strip?
32
+ @strip
33
+ end
34
+
35
+ def frame_classes
36
+ strip? ? STRIP_FRAME_CLASSES : FRAME_CLASSES
25
37
  end
26
38
 
27
39
  def show_values?
@@ -31,12 +43,26 @@ module Keystone
31
43
  def drawn_bars
32
44
  bars.each_with_index.map do |bar, index|
33
45
  height = bar[:value].to_f / axis_max * (FULL - HEADROOM)
34
- { x: (index * band) + (band * (1 - BAR_SHARE) / 2), y: FULL - height, width: band * BAR_SHARE, height: height,
35
- center: (index * band) + (band / 2), label: bar[:label], value: bar[:value],
36
- classes: [ "ks-bar-chart-bar", ("ks-bar-chart-bar-shaded" if bar[:shaded]) ].compact.join(" ") }
46
+ x = (index * band) + (band * (1 - bar_share) / 2)
47
+ center = (index * band) + (band / 2)
48
+ { x: x, y: FULL - height, width: band * bar_share, height: height, center: center,
49
+ label: bar[:label], label_x: bar.key?(:group) ? x : center, label_anchor: bar.key?(:group) ? "start" : "middle", value: bar[:value],
50
+ classes: [ "ks-bar-chart-bar", ("ks-bar-chart-bar-shaded" if bar[:shaded]), group_class(bar) ].compact.join(" ") }
51
+ end
52
+ end
53
+
54
+ def labelled_bars
55
+ drawn_bars.each_with_index.filter_map do |bar, index|
56
+ next unless starts_group?(index)
57
+
58
+ newest_group_start?(index) ? bar.merge(label_x: FULL, label_anchor: "end") : bar
37
59
  end
38
60
  end
39
61
 
62
+ def grid_lines
63
+ strip? ? [ { y: FULL } ] : ticks
64
+ end
65
+
40
66
  def ticks
41
67
  (0..(axis_max / step).round).map do |position|
42
68
  value = (step * position).round(6)
@@ -46,6 +72,35 @@ module Keystone
46
72
 
47
73
  private
48
74
 
75
+ def bar_share
76
+ strip? ? STRIP_BAR_SHARE : BAR_SHARE
77
+ end
78
+
79
+ def newest_group_start?(index)
80
+ groups.size > 1 && bars[index].key?(:group) && bars[index][:group] == groups.last
81
+ end
82
+
83
+ def starts_group?(index)
84
+ index.zero? || !bars[index].key?(:group) || bars[index][:group] != bars[index - 1][:group]
85
+ end
86
+
87
+ def group_class(bar)
88
+ return unless bar.key?(:group)
89
+
90
+ "ks-bar-chart-bar-group-#{group_tone(groups.index(bar[:group]))}"
91
+ end
92
+
93
+ def group_tone(position)
94
+ return GROUP_TONES if groups.size == 1
95
+ return [ 1, position - groups.size + 1 + GROUP_TONES ].max if groups.size > GROUP_TONES
96
+
97
+ 1 + (position * (GROUP_TONES - 1).to_f / (groups.size - 1)).round
98
+ end
99
+
100
+ def groups
101
+ @groups ||= bars.map { |bar| bar[:group] }.uniq
102
+ end
103
+
49
104
  def axis_max
50
105
  step * (largest / step).ceil
51
106
  end
@@ -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.96.0"
4
+ VERSION = "0.98.0"
5
5
  end
@@ -93,12 +93,12 @@ 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.
100
100
  - `ui_line_chart` — a line chart with one line per series, over labels or dates.
101
- - `ui_bar_chart` — a bar chart drawn on the server, which needs no JavaScript and prints.
101
+ - `ui_bar_chart` — a bar chart drawn on the server, which needs no JavaScript and prints, with bars optionally grouped into tones from oldest to newest and one label per group, and optionally drawn as a short strip with no value axis.
102
102
  - `ui_funnel` — a conversion funnel drawn as bars or one joined shape.
103
103
  - `ui_bucket` — an upright container filled toward a goal.
104
104
  - `ui_bucket_series` — a wrapping row of buckets.
@@ -843,10 +843,22 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
843
843
 
844
844
  - `ui_chart_card(title:, height: :md)` takes a block holding a chart, with
845
845
  `height:` `:sm` `:md` `:lg`.
846
- - `ui_bar_chart(bars:, show_values: false)` — `bars:` is
847
- `[{ label:, value:, shaded: }, ...]`, where `shaded: true` draws a bar
848
- faded. It is drawn on the server as an SVG, so use it, not
846
+ - `ui_bar_chart(bars:, show_values: false, strip: false)` — `bars:` is
847
+ `[{ label:, value:, shaded:, group: }, ...]`, where `shaded: true` draws
848
+ a bar faded. It is drawn on the server as an SVG, so use it, not
849
849
  `ui_line_chart`, for a chart that must print or show without JavaScript.
850
+ - Give bars `group:`, such as the version that produced each one, to show
851
+ groups of bars. Groups count from oldest to newest in the order their
852
+ values first appear, and run in tones from grey to the accent, with no
853
+ two of five or fewer groups sharing a tone. With more than five, every
854
+ group older than the newest four is grey. Only a group's first bar
855
+ writes its label, starting at its left edge, so pass `""` for the rest,
856
+ such as `{ label: "v21 → 0.80", value: 0.66, group: "v21" }` followed by
857
+ `{ label: "", value: 0.68, group: "v21" }`. The newest group's label
858
+ ends at the chart's right edge. Never colour bars by hand.
859
+ - Pass `strip: true` for a short strip of bars 114px tall with no value
860
+ axis and no grid lines, only a baseline, and the bars nearly touching,
861
+ such as a trend under a page's main content.
850
862
  - `ui_line_chart(series:, labels: nil, dates: nil, height: :md)` —
851
863
  `series:` is `[{ name:, data:, color:, dashed: }, ...]`, where `color:`
852
864
  is a CSS colour and `dashed: true` is optional. Pass exactly one of
@@ -986,9 +998,18 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
986
998
  takes content such as stat cards. From `sm` up it is drawn above the
987
999
  tab row, and below `sm` between the tab row and the panel. It is drawn
988
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.
989
1010
  - Below `sm` every tab switcher's tab row stays on one line, starts at
990
1011
  the left edge and scrolls sideways, and from `sm` up it wraps and is
991
- centred.
1012
+ centred unless `align: :start` is given.
992
1013
  - `ui_swipe_deck(items:, empty_title: "All done!", empty_subtitle: nil)`
993
1014
  takes a block yielding the deck, where `deck.item { |item| ... }` renders
994
1015
  one card's face. Accepting sends a bubbling `swipe-deck:complete` event
@@ -97,6 +97,23 @@ 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.
107
+ - **Bar chart groups.** A bar chart's bars can be put in groups, such as one
108
+ group per version of what produced them. Groups count from oldest to newest
109
+ in the order they first appear. Every bar of a group shares one tone, and
110
+ the tones run from grey for the oldest to the accent for the newest, with
111
+ no two of five or fewer groups sharing one. Past five, every group older
112
+ than the newest four is grey. Only the first bar of each group carries a
113
+ label under the axis, starting at that bar's left edge, apart from the
114
+ newest group's label, which ends at the chart's right edge. A bar chart can
115
+ also be drawn as a short strip with no value axis and no grid lines, only a
116
+ baseline, and its bars nearly touching.
100
117
  - **Value lists.** A value list shows labelled values, each a label and a value
101
118
  with an optional note, a fallback shown when the value is empty, a total
102
119
  marking and a check mark for a value that is right. By default each pair is a
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.96.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.37.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.37.0
25
+ version: 0.39.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement