keystone_ui 0.62.0 → 0.63.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: ed9d023bcbe1fa1c7175f1fcd8e843687157c1b80be8ce777639d9433ffce70a
4
- data.tar.gz: 38a651714ca10fd0334e31ef27df4a5e032c6d3ffb33f0ca460891f6ce7bb2a2
3
+ metadata.gz: '0359f881db7160fc60d97b6496ecd4131d5450e7c66bfe1e0e94f9df35587a1d'
4
+ data.tar.gz: 7eab7185a552a901d6f6858ee45d8b01f4ef06241b32f96f749953b8377a5aa1
5
5
  SHA512:
6
- metadata.gz: e24326e4bb89982a00fa1904c83501d049be460083c0daa0d0450b2c79acffd7897edbb165b9d5a2a0c363520daad1e353cbf6362d409f1ad71325abd3aeeff5
7
- data.tar.gz: 67434fa06fbe9aa35a0a98a39d931306adf26443971ce816fd92c05d64c6c149481b1028c198ae2c9f284348cebd61410d9d4416441da9ab9c7fe32726f9d73d
6
+ metadata.gz: 1e99aa1db1e7b14f3f1037223faec2577ced190386f0262336c279865026cc8d5598d6f58e36e00cf6d18ec80146efce621824d1e52c3bb8cc1be8f8abcc4e32
7
+ data.tar.gz: 4cc34ebcc7c2a81b5433029becd7e6568c4480cede78661843a78f62da45f861d50bb6f5f3379e402f530a2bbe4adfd34ad7f6304c2e8514c346a2a44adbf5cd
@@ -1 +1 @@
1
- <%= link_to @label, @href, class: link_classes %>
1
+ <%= link_to @href, class: link_classes do %><%= @label %><% if counted? %><%= render count_badge %><% end %><% end %>
@@ -5,10 +5,11 @@ module Keystone
5
5
  class NavItemComponent < ViewComponent::Base
6
6
  attr_reader :label, :href
7
7
 
8
- def initialize(label:, href:, active: false)
8
+ def initialize(label:, href:, active: false, count: nil)
9
9
  @label = label
10
10
  @href = href
11
11
  @active = active
12
+ @count = count
12
13
  end
13
14
 
14
15
  ACTIVE_CLASS = "active"
@@ -16,6 +17,14 @@ module Keystone
16
17
  def link_classes
17
18
  [ "ks-nav-item", (ACTIVE_CLASS if @active) ].compact.join(" ")
18
19
  end
20
+
21
+ def counted?
22
+ @count.to_i.positive?
23
+ end
24
+
25
+ def count_badge
26
+ BadgeComponent.new(label: @count.to_s, variant: :info)
27
+ end
19
28
  end
20
29
  end
21
30
  end
@@ -9,13 +9,13 @@
9
9
  <% groups.each do |group| %>
10
10
  <% if group.standalone %>
11
11
  <% tab = group.tabs.first %>
12
- <a class="<%= sidebar_tab_classes(tab) %>" href="<%= tab.href %>"><%= tab.label %></a>
12
+ <a class="<%= sidebar_tab_classes(tab) %>" href="<%= tab.href %>"><%= tab.label %><% if tab.count.to_i.positive? %> <%= render Keystone::Ui::BadgeComponent.new(label: tab.count.to_s, variant: :info) %><% end %></a>
13
13
  <% else %>
14
14
  <details class="<%= SIDEBAR_GROUP_CLASSES %>"<%= " open" if group.active %>>
15
15
  <summary class="<%= sidebar_group_label_classes(group) %>"><%= group.label %></summary>
16
16
  <div class="<%= SIDEBAR_GROUP_TABS_CLASSES %>">
17
17
  <% group.tabs.each do |tab| %>
18
- <a class="<%= sidebar_tab_classes(tab) %>" href="<%= tab.href %>"><%= tab.label %></a>
18
+ <a class="<%= sidebar_tab_classes(tab) %>" href="<%= tab.href %>"><%= tab.label %><% if tab.count.to_i.positive? %> <%= render Keystone::Ui::BadgeComponent.new(label: tab.count.to_s, variant: :info) %><% end %></a>
19
19
  <% end %>
20
20
  </div>
21
21
  </details>
@@ -42,11 +42,11 @@
42
42
  <% groups.each do |group| %>
43
43
  <% if group.standalone %>
44
44
  <% tab = group.tabs.first %>
45
- <%= render Keystone::Ui::NavItemComponent.new(label: tab.label, href: tab.href, active: tab.active) %>
45
+ <%= render Keystone::Ui::NavItemComponent.new(label: tab.label, href: tab.href, active: tab.active, count: tab.count) %>
46
46
  <% else %>
47
47
  <%= render Keystone::Ui::NavDropdownComponent.new(title: group.label, area: group.label, active: group.active) do %>
48
48
  <% group.tabs.each do |tab| %>
49
- <%= render Keystone::Ui::NavItemComponent.new(label: tab.label, href: tab.href, active: tab.active) %>
49
+ <%= render Keystone::Ui::NavItemComponent.new(label: tab.label, href: tab.href, active: tab.active, count: tab.count) %>
50
50
  <% end %>
51
51
  <% end %>
52
52
  <% end %>
@@ -31,9 +31,9 @@ module KeystoneUi
31
31
  @navigation_groups << group
32
32
  end
33
33
 
34
- def navigation_tab(key, label:, href:, permitted:)
34
+ def navigation_tab(key, label:, href:, permitted:, count: nil)
35
35
  group = NavigationGroup.new(label, standalone: true)
36
- group.tab(key, label: label, href: href, permitted: permitted)
36
+ group.tab(key, label: label, href: href, permitted: permitted, count: count)
37
37
  @navigation_groups << group
38
38
  end
39
39
 
@@ -2,10 +2,14 @@
2
2
 
3
3
  module KeystoneUi
4
4
  class NavigationGroup
5
- Tab = Struct.new(:key, :label, :href, :permitted, keyword_init: true) do
5
+ Tab = Struct.new(:key, :label, :href, :permitted, :count, keyword_init: true) do
6
6
  def href_for(view)
7
7
  href.respond_to?(:call) ? href.call(view) : href
8
8
  end
9
+
10
+ def count_for(view)
11
+ count&.call(view)
12
+ end
9
13
  end
10
14
 
11
15
  attr_reader :label, :tabs
@@ -24,8 +28,8 @@ module KeystoneUi
24
28
  tabs.select { |tab| tab.permitted.call(view) }
25
29
  end
26
30
 
27
- def tab(key, label:, href:, permitted:)
28
- @tabs << Tab.new(key: key, label: label, href: href, permitted: permitted)
31
+ def tab(key, label:, href:, permitted:, count: nil)
32
+ @tabs << Tab.new(key: key, label: label, href: href, permitted: permitted, count: count)
29
33
  end
30
34
  end
31
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.62.0"
4
+ VERSION = "0.63.0"
5
5
  end
@@ -5,7 +5,7 @@ require "keystone_ui/navigation_order"
5
5
  module KeystoneUi
6
6
  class VisibleNavigation
7
7
  Group = Struct.new(:label, :tabs, :active, :standalone, keyword_init: true)
8
- Tab = Struct.new(:label, :href, :active, keyword_init: true)
8
+ Tab = Struct.new(:label, :href, :active, :count, keyword_init: true)
9
9
 
10
10
  def initialize(declared_groups, view:, saved_order:, current_tab:)
11
11
  @declared_groups = declared_groups
@@ -32,7 +32,7 @@ module KeystoneUi
32
32
  end
33
33
 
34
34
  def visible_tab(tab)
35
- Tab.new(label: tab.label, href: tab.href_for(@view), active: tab.key == @current_tab)
35
+ Tab.new(label: tab.label, href: tab.href_for(@view), active: tab.key == @current_tab, count: tab.count_for(@view))
36
36
  end
37
37
  end
38
38
  end
@@ -251,7 +251,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
251
251
  and keeps it from `lg:` up, for a page that shows its own title in
252
252
  `ui_mobile_header`. It defaults to `false`, which keeps the logo at every
253
253
  width.
254
- - `ui_nav_item(label:, href:, active: false)` is one desktop link.
254
+ - `ui_nav_item(label:, href:, active: false, count: nil)` is one desktop
255
+ link, with `count:` shown in a badge after the label when above zero.
255
256
  `ui_nav_dropdown(title:, area:, active: false)` takes a block holding the
256
257
  menu links.
257
258
  - `ui_bottom_nav` takes no keywords and a block of
@@ -327,6 +327,10 @@ built on ViewComponent; hook it in before building any screen with those helpers
327
327
  `href:`, when two tabs share a key, or when a group has no tabs. Drawing
328
328
  the declared groups in the layout is done with the navigation helper,
329
329
  which belongs to `keystone_ui-develop`.
330
+ - Both `group.tab` and `navigation_tab` take an optional `count:`, a
331
+ callable given the view that returns a number. A count above zero shows in
332
+ an info badge after the tab's label in the top bar and the sidebar. It runs
333
+ on every page, so keep it to one cheap query.
330
334
  - `navigation_tab key, label:, href:, permitted:` — declares one tab
331
335
  outside any group, such as a Console or Clients tab, in its place among
332
336
  the groups. The navigation helper draws it as a plain link in the top bar
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.62.0
4
+ version: 0.63.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider