keystone_ui 0.61.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: 1162e3083759cf27249c3868a38a062293ef0d2eb810f05638949dfecb32df98
4
- data.tar.gz: edf6931a9e8ec09beb70e6b40397cf4cfa1bcb63fdcfb45f0526ccb84a41b652
3
+ metadata.gz: '0359f881db7160fc60d97b6496ecd4131d5450e7c66bfe1e0e94f9df35587a1d'
4
+ data.tar.gz: 7eab7185a552a901d6f6858ee45d8b01f4ef06241b32f96f749953b8377a5aa1
5
5
  SHA512:
6
- metadata.gz: 0bc9dbdbf3b83401432103e6781c30dc8736957f139ace11f2475d71a5a4ee9d69f307b91c93a5494c5853c01877fb7ea6ca7576dea00a468fb7265981cac0db
7
- data.tar.gz: '083b71c45bad44f4af0b3a581d7f7c2e73ae39eb63036590dd0bb9f97e8904f6d57cb08f72a1254ef935f386c097c461386e8e7cc47e27694dd0a6eae69c361a'
6
+ metadata.gz: 1e99aa1db1e7b14f3f1037223faec2577ced190386f0262336c279865026cc8d5598d6f58e36e00cf6d18ec80146efce621824d1e52c3bb8cc1be8f8abcc4e32
7
+ data.tar.gz: 4cc34ebcc7c2a81b5433029becd7e6568c4480cede78661843a78f62da45f861d50bb6f5f3379e402f530a2bbe4adfd34ad7f6304c2e8514c346a2a44adbf5cd
@@ -44,7 +44,7 @@
44
44
  <% if actions? %><th></th><% end %>
45
45
  </tr>
46
46
  <% end %>
47
- <tr<% if current_row?(idx) %> class="<%= Keystone::Ui::DataTableComponent::CURRENT_ROW_CLASSES %>" aria-current="true"<% end %>>
47
+ <tr<% if (classes = row_classes(idx)) %> class="<%= classes %>"<% end %><% if current_row?(idx) %> aria-current="true"<% end %>>
48
48
  <% row_cells[idx].each do |cell| %>
49
49
  <td class="<%= cell[:classes] %>">
50
50
  <% if cell[:href] %>
@@ -6,6 +6,12 @@ module Keystone
6
6
  EMPTY_CELL_CLASSES = "ks-table-cell-middle text-sm"
7
7
  BODY_CLASSES = "ks-table-body"
8
8
  CURRENT_ROW_CLASSES = "ks-table-row-current"
9
+ ROW_COLOUR_CLASSES = {
10
+ danger: "ks-table-row-danger",
11
+ warning: "ks-table-row-warning",
12
+ success: "ks-table-row-success",
13
+ info: "ks-table-row-info"
14
+ }.freeze
9
15
  HEAD_CLASSES = "ks-table-head"
10
16
  WRAPPER_CLASSES = "ks-table overflow-x-auto"
11
17
  TOOLBAR_CLASSES = "ks-table-toolbar flex justify-end"
@@ -63,6 +69,16 @@ module Keystone
63
69
  @actions_block = block
64
70
  end
65
71
 
72
+ def row_colour(&block)
73
+ @row_colour_block = block
74
+ end
75
+
76
+ def row_classes(index)
77
+ classes = [ (CURRENT_ROW_CLASSES if current_row?(index)), row_colour_class(@items[index]) ].compact
78
+
79
+ classes.join(" ") unless classes.empty?
80
+ end
81
+
66
82
  def actions?
67
83
  !!@actions_block
68
84
  end
@@ -208,6 +224,12 @@ module Keystone
208
224
  [ *classes.split.grep_v(/\Atext-(left|right)\z/), ALIGN_CLASSES.fetch(column.align) ].join(" ")
209
225
  end
210
226
 
227
+ def row_colour_class(item)
228
+ colour = @row_colour_block&.call(item)
229
+
230
+ ROW_COLOUR_CLASSES.fetch(colour) if colour
231
+ end
232
+
211
233
  def wrapped(classes, column)
212
234
  return classes unless column.wrap?
213
235
 
@@ -0,0 +1,9 @@
1
+ <div class="<%= WRAPPER_CLASSES %>">
2
+ <h2 class="<%= TITLE_CLASSES %>"><%= @title %></h2>
3
+ <% if @message %>
4
+ <p class="<%= MESSAGE_CLASSES %>"><%= @message %></p>
5
+ <% end %>
6
+ <% if @action %>
7
+ <%= render action_button %>
8
+ <% end %>
9
+ </div>
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class EmptyStateComponent < ViewComponent::Base
6
+ WRAPPER_CLASSES = "ks-empty-state flex flex-col items-center text-center"
7
+ TITLE_CLASSES = "ks-heading-sm"
8
+ MESSAGE_CLASSES = "ks-paragraph ks-tone-muted"
9
+
10
+ def initialize(title:, message: nil, action: nil)
11
+ @title = title
12
+ @message = message
13
+ @action = action
14
+ end
15
+
16
+ def action_button
17
+ ButtonComponent.new(label: @action.fetch(:label), href: @action.fetch(:href), variant: :secondary)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ <div class="ks-value-list">
2
+ <% rows.each do |row| %>
3
+ <%= link_to row.fetch(:href), class: ROW_CLASSES do %>
4
+ <span class="<%= TEXT_CLASSES %>">
5
+ <span class="<%= LABEL_CLASSES %>"><%= row.fetch(:label) %></span>
6
+ <% if row[:subtitle] %>
7
+ <span class="<%= SUBTITLE_CLASSES %>"><%= row[:subtitle] %></span>
8
+ <% end %>
9
+ </span>
10
+ <% if row[:badge] %>
11
+ <%= render badge(row) %>
12
+ <% end %>
13
+ <% if row[:value] %>
14
+ <span class="<%= VALUE_CLASSES %>"><%= row[:value] %></span>
15
+ <% end %>
16
+ <%= Keystone::Ui::SettingsLinkComponent::CHEVRON_ICON.html_safe %>
17
+ <% end %>
18
+ <% end %>
19
+ </div>
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class LinkListComponent < ViewComponent::Base
6
+ ROW_CLASSES = "ks-value-list-row items-center no-underline"
7
+ TEXT_CLASSES = "min-w-0 flex-1"
8
+ LABEL_CLASSES = "ks-paragraph ks-settings-link-label block"
9
+ SUBTITLE_CLASSES = "ks-value-list-note"
10
+ VALUE_CLASSES = "ks-value-list-value shrink-0"
11
+
12
+ attr_reader :rows
13
+
14
+ def initialize(rows:)
15
+ @rows = rows
16
+ end
17
+
18
+ def badge(row)
19
+ BadgeComponent.new(**row[:badge])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -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 %>
@@ -113,6 +113,14 @@ module KeystoneUiHelper
113
113
  render Keystone::Ui::AlertComponent.new(**args)
114
114
  end
115
115
 
116
+ def ui_empty_state(**args)
117
+ render Keystone::Ui::EmptyStateComponent.new(**args)
118
+ end
119
+
120
+ def ui_link_list(**args)
121
+ render Keystone::Ui::LinkListComponent.new(**args)
122
+ end
123
+
116
124
  def ui_form_page(**args)
117
125
  render Keystone::Ui::FormPageComponent.new(**args)
118
126
  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
@@ -58,6 +58,8 @@ module Keystone
58
58
  Keystone::Ui::ColorPickerComponent,
59
59
  Keystone::Ui::MultiSelectComponent,
60
60
  Keystone::Ui::SwipeDeckComponent,
61
+ Keystone::Ui::EmptyStateComponent,
62
+ Keystone::Ui::LinkListComponent,
61
63
  Keystone::Ui::SortableListComponent,
62
64
  Keystone::Ui::ColumnPickerComponent,
63
65
  Keystone::Ui::FormComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.61.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
@@ -72,6 +72,8 @@ not available in the app yet, that is `keystone_ui-install`'s job.
72
72
  - `ui_paragraph` — a paragraph of running text.
73
73
  - `ui_value_list` — rows of a label and its value, such as a ledger or a byline.
74
74
  - `ui_alert` — a banner message, optionally dismissible.
75
+ - `ui_link_list` — a list of links, each row with a label, an optional subtitle, badge and value, and a chevron.
76
+ - `ui_empty_state` — what a list or section shows when it has nothing in it, with an optional message and action.
75
77
  - `ui_progress` — a labelled progress bar.
76
78
  - `ui_stat_card` — a single metric tile with optional change, link and info button.
77
79
  - `ui_copy_button` — a button that copies text to the clipboard.
@@ -249,7 +251,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
249
251
  and keeps it from `lg:` up, for a page that shows its own title in
250
252
  `ui_mobile_header`. It defaults to `false`, which keeps the logo at every
251
253
  width.
252
- - `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.
253
256
  `ui_nav_dropdown(title:, area:, active: false)` takes a block holding the
254
257
  menu links.
255
258
  - `ui_bottom_nav` takes no keywords and a block of
@@ -444,6 +447,13 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
444
447
  actions column whose block holds only `ui_action_menu_item` calls. With no
445
448
  actions column, the last column is right-aligned, so put a column of
446
449
  amounts last.
450
+ - `table.row_colour { |item| ... }` tints a whole row. The block returns
451
+ `:danger`, `:warning`, `:success`, `:info` or `nil` for each item. A named
452
+ colour tints every cell of that row in the same colour as the badge of
453
+ that name, `nil` leaves the row plain, and any other value raises
454
+ `KeyError`. Colour alone does not reach every reader, so also make the
455
+ row's meaning readable as text in the row, such as a status badge or a
456
+ word in a cell.
447
457
  - Sorting needs all three of `sort:` (the current column key),
448
458
  `sort_direction:` (`:asc` or `:desc`) and `sort_url:` (a lambda taking
449
459
  `(column_key, direction)` and returning a URL). Headers then render as
@@ -505,6 +515,13 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
505
515
  - `ui_alert(message:, type: :info, title: nil, dismissible: false, class: nil)`
506
516
  — `type:` is `:info` `:success` `:warning` `:error`, and `dismissible: true`
507
517
  adds a close button.
518
+ - `ui_link_list(rows:)` — each row is `{ label:, href:, subtitle: nil,
519
+ badge: nil, value: nil }`, and `badge:` takes `ui_badge`'s `{ label:, variant: }`.
520
+ Use it for a list of records that each open their own page, in place of a
521
+ hand-written `<ul>` of links.
522
+ - `ui_empty_state(title:, message: nil, action: nil)` — `action:` is
523
+ `{ label:, href: }` and draws a secondary button. Use it in place of a bare
524
+ "Nothing yet" paragraph wherever a list or section can be empty.
508
525
  - `ui_progress(value:, max:, label: nil)` shows `value / max` as a percent,
509
526
  rounded and capped at 100.
510
527
  - `ui_copy_button(text:, label: "Copy", success_message: "Copied!", error_message: "Failed!")`.
@@ -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
@@ -32,6 +32,8 @@ develop:
32
32
  - ui_form_field
33
33
  - ui_page_header
34
34
  - ui_alert
35
+ - ui_empty_state
36
+ - ui_link_list
35
37
  - ui_form_page
36
38
  - ui_show_page
37
39
  - ui_breadcrumbs
@@ -91,6 +93,10 @@ sources:
91
93
  - app/helpers/keystone_ui_helper.rb
92
94
  - app/components/keystone/ui/accordion_component.rb
93
95
  - app/components/keystone/ui/alert_component.rb
96
+ - app/components/keystone/ui/empty_state_component.rb
97
+ - app/components/keystone/ui/empty_state_component.html.erb
98
+ - app/components/keystone/ui/link_list_component.rb
99
+ - app/components/keystone/ui/link_list_component.html.erb
94
100
  - app/components/keystone/ui/badge_component.rb
95
101
  - app/components/keystone/ui/bottom_nav_component.rb
96
102
  - app/components/keystone/ui/bottom_nav_item_component.rb
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.61.0
4
+ version: 0.63.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.28.0
18
+ version: 0.29.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.28.0
25
+ version: 0.29.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +128,8 @@ files:
128
128
  - app/components/keystone/ui/desktop_back_link_component.rb
129
129
  - app/components/keystone/ui/disclosure_component.html.erb
130
130
  - app/components/keystone/ui/disclosure_component.rb
131
+ - app/components/keystone/ui/empty_state_component.html.erb
132
+ - app/components/keystone/ui/empty_state_component.rb
131
133
  - app/components/keystone/ui/feature_grid_component.html.erb
132
134
  - app/components/keystone/ui/feature_grid_component.rb
133
135
  - app/components/keystone/ui/figure_component.html.erb
@@ -154,6 +156,8 @@ files:
154
156
  - app/components/keystone/ui/input_component.rb
155
157
  - app/components/keystone/ui/line_chart_component.html.erb
156
158
  - app/components/keystone/ui/line_chart_component.rb
159
+ - app/components/keystone/ui/link_list_component.html.erb
160
+ - app/components/keystone/ui/link_list_component.rb
157
161
  - app/components/keystone/ui/mobile_action_component.rb
158
162
  - app/components/keystone/ui/mobile_actions_component.html.erb
159
163
  - app/components/keystone/ui/mobile_actions_component.rb