keystone_ui 0.53.0 → 0.55.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: e7f6b6d63755b597d7b876ddba35bd4f6bbdb6039b0b16be57197cf4af01ea48
4
- data.tar.gz: c2093a32f35bf5beb3a469cfffe14033e491f8e6435bb32003b203652574f990
3
+ metadata.gz: f5b386ab0f7c078b363565555aba8cd927ace939f39ed67b908c4d1b2978f7d2
4
+ data.tar.gz: 52b8ae3921a2f695ede0d7fc2e4d799727c2512aae8aff6291b242ded37ef251
5
5
  SHA512:
6
- metadata.gz: ac7541139dd31e4269cbca2dc13e3201d6c44ffd9b4a8088f90a2361f15cee3e627d808277b31e7a5981c0c19d56fa453cb186350870cf48d5416d7ef0ab6a2b
7
- data.tar.gz: bf3cb63e70d990d5b01bee266a2446d15cd8f7b710b63c767e129134312d9f6e999d6e56ef6d709614ff4a63699b303e231cbebed874001ce4c03f7c46756401
6
+ metadata.gz: 3f961b433f998ead9d4e13f7e9cdc4e923efeb732c8b77f14987ce64e26423df7fef1307285893ffe89f68706572a179b3196e33dafc53bb7b7852a5b9b879f8
7
+ data.tar.gz: 28cf2cff0b421d1e84bb83edeff44a50c249349ceabb80d4f2216b19751804fdab85caa6c04e3814db3ae005accad2d5116bf648b0ce8d7bb14d019844de7cb1
@@ -16,9 +16,13 @@ module Keystone
16
16
  lg: "ks-button-lg"
17
17
  }.freeze
18
18
 
19
- def initialize(label:, href: nil, variant: :primary, size: :md, type: :submit, data: nil)
19
+ FULL_WIDTH_CLASSES = "w-full"
20
+
21
+ def initialize(label:, href: nil, method: :get, variant: :primary, size: :md, full_width: false, type: :submit, data: nil)
20
22
  @label = label
21
23
  @href = href
24
+ @method = method.to_sym
25
+ @full_width = full_width
22
26
  @variant = variant
23
27
  @size = size
24
28
  @type = type.to_s
@@ -31,7 +35,7 @@ module Keystone
31
35
  else
32
36
  VARIANT_CLASSES.fetch(@variant)
33
37
  end
34
- [ BASE_CLASSES, variant_css, SIZE_CLASSES.fetch(@size) ].join(" ")
38
+ [ BASE_CLASSES, variant_css, SIZE_CLASSES.fetch(@size), (FULL_WIDTH_CLASSES if @full_width) ].compact.join(" ")
35
39
  end
36
40
 
37
41
  def tag_name
@@ -52,6 +56,20 @@ module Keystone
52
56
  def button?
53
57
  @href.nil?
54
58
  end
59
+
60
+ def call
61
+ return button_to(@href, method: @method, class: classes, form_class: form_classes) { @label } if request?
62
+
63
+ content_tag(tag_name, @label, **tag_options)
64
+ end
65
+
66
+ def form_classes
67
+ FULL_WIDTH_CLASSES if @full_width
68
+ end
69
+
70
+ def request?
71
+ @href && @method != :get
72
+ end
55
73
  end
56
74
  end
57
75
  end
@@ -44,7 +44,7 @@
44
44
  <% if actions? %><th></th><% end %>
45
45
  </tr>
46
46
  <% end %>
47
- <tr>
47
+ <tr<% if current_row?(idx) %> class="<%= Keystone::Ui::DataTableComponent::CURRENT_ROW_CLASSES %>" aria-current="true"<% end %>>
48
48
  <% row_cells[idx].each do |cell| %>
49
49
  <td class="<%= cell[:classes] %>">
50
50
  <% if cell[:href] %>
@@ -5,6 +5,7 @@ module Keystone
5
5
  class DataTableComponent < ViewComponent::Base
6
6
  EMPTY_CELL_CLASSES = "ks-table-cell-middle text-sm"
7
7
  BODY_CLASSES = "ks-table-body"
8
+ CURRENT_ROW_CLASSES = "ks-table-row-current"
8
9
  HEAD_CLASSES = "ks-table-head"
9
10
  WRAPPER_CLASSES = "ks-table overflow-x-auto"
10
11
  TOOLBAR_CLASSES = "ks-table-toolbar flex justify-end"
@@ -30,8 +31,9 @@ module Keystone
30
31
  SORT_DESC_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .75.75v10.638l3.96-4.158a.75.75 0 1 1 1.08 1.04l-5.25 5.5a.75.75 0 0 1-1.08 0l-5.25-5.5a.75.75 0 0 1 1.08-1.04l3.96 4.158V3.75A.75.75 0 0 1 10 3Z" clip-rule="evenodd" /></svg>'
31
32
  SORT_NEUTRAL_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .55.24l3.25 3.5a.75.75 0 1 1-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 0 1-1.1-1.02l3.25-3.5A.75.75 0 0 1 10 3Zm-3.76 9.2a.75.75 0 0 1 1.06.04l2.7 2.908 2.7-2.908a.75.75 0 1 1 1.1 1.02l-3.25 3.5a.75.75 0 0 1-1.1 0l-3.25-3.5a.75.75 0 0 1 .04-1.06Z" clip-rule="evenodd" /></svg>'
32
33
 
33
- def initialize(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil)
34
+ def initialize(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil)
34
35
  @items = items.to_a
36
+ @current_index = @items.index(current_row) unless current_row.nil?
35
37
  @group_by = group_by
36
38
  @group_totals = group_totals.to_h.transform_keys(&:to_s)
37
39
  @total = total&.to_h&.transform_keys(&:to_s)
@@ -142,6 +144,10 @@ module Keystone
142
144
  end
143
145
  end
144
146
 
147
+ def current_row?(index)
148
+ index == @current_index
149
+ end
150
+
145
151
  def empty?
146
152
  @items.empty?
147
153
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class PictureComponent < ViewComponent::Base
6
+ IMAGE_CLASSES = "mx-auto max-h-[50svh]"
7
+
8
+ def initialize(src:, alt:, full_size_url: nil)
9
+ @src = src
10
+ @alt = alt
11
+ @full_size_url = full_size_url
12
+ end
13
+
14
+ def call
15
+ image = tag.img(src: @src, alt: @alt, class: IMAGE_CLASSES)
16
+ return image unless @full_size_url
17
+
18
+ link_to(image, @full_size_url, target: "_blank", rel: "noopener")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -245,6 +245,10 @@ module KeystoneUiHelper
245
245
  render Keystone::Ui::FigureComponent.new(**args)
246
246
  end
247
247
 
248
+ def ui_picture(**args)
249
+ render Keystone::Ui::PictureComponent.new(**args)
250
+ end
251
+
248
252
  def ui_heading(**args)
249
253
  render Keystone::Ui::HeadingComponent.new(**args)
250
254
  end
@@ -71,7 +71,8 @@ module Keystone
71
71
  Keystone::Ui::DesktopBackLinkComponent,
72
72
  Keystone::Ui::BreadcrumbsComponent,
73
73
  Keystone::Ui::InfoComponent,
74
- Keystone::Ui::BreakdownComponent
74
+ Keystone::Ui::BreakdownComponent,
75
+ Keystone::Ui::PictureComponent
75
76
  ].freeze
76
77
 
77
78
  # Constants that hold non-CSS values (e.g. HTML input type maps)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.53.0"
4
+ VERSION = "0.55.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: keystone_ui-develop
3
- description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels and goal buckets, amounts shown in green or red as a gain or loss, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
3
+ description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels and goal buckets, amounts shown in green or red as a gain or loss, pictures held to half the screen, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
4
4
  tools: Bash, Read, Write, Edit, Grep
5
5
  scope: UI — pages, forms, tables, navigation, dashboards
6
6
  ---
@@ -58,12 +58,13 @@ not available in the app yet, that is `keystone_ui-install`'s job.
58
58
  - `ui_radio_card` — a selectable card backed by a radio input.
59
59
  - `ui_checkbox_row` — a checkbox with its label and hint, toggled by a tap anywhere on the row.
60
60
  - `ui_option_card` — a radio whose visible body is whatever its block renders.
61
- - `ui_data_table` — a table of records with links, row actions, sorting and hideable columns.
61
+ - `ui_data_table` — a table of records with links, row actions, sorting, hideable columns and the viewer's own row marked.
62
62
  - `Keystone::Ui::Column` — a table column with options a `{ key: "Label" }` hash cannot carry.
63
63
  - `ui_column_picker` — a Columns menu that saves which columns are hidden and their order to an app endpoint.
64
- - `ui_button` — a link or a button styled as a button.
64
+ - `ui_button` — a link or a button styled as a button, or a button sending a POST, PATCH or DELETE request.
65
65
  - `ui_badge` — a coloured pill holding a short label.
66
66
  - `ui_figure` — one amount as inline text, coloured as a gain or a loss.
67
+ - `ui_picture` — an image never taller than half the screen, optionally opening its full-size file.
67
68
  - `ui_heading` — a heading at one of three sizes, with an optional short note on its right.
68
69
  - `ui_caption` — small uppercase muted text placed above a title or a figure.
69
70
  - `ui_paragraph` — a paragraph of running text.
@@ -366,7 +367,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
366
367
 
367
368
  8. Build tables.
368
369
 
369
- - `ui_data_table(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil)`
370
+ - `ui_data_table(items:, columns:, empty_message: nil, sort: nil, sort_direction: nil, sort_url: nil, hidden_columns: [], key: nil, group_by: nil, group_totals: {}, total: nil, current_row: nil)`
370
371
  takes a block yielding the table. `items:` are records or hashes, and a
371
372
  cell's value is the column key called on the item, or `item[key]`.
372
373
  `group_by:` lists rows under heading rows named by that key's value,
@@ -393,6 +394,12 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
393
394
  `sort_direction:` (`:asc` or `:desc`) and `sort_url:` (a lambda taking
394
395
  `(column_key, direction)` and returning a URL). Headers then render as
395
396
  links that flip direction.
397
+ - `current_row:` takes the item whose row is the viewer's own, such as
398
+ their entry on a scoreboard or leaderboard. That row carries the
399
+ `ks-table-row-current` class, which keystone_ui-styles colours, and
400
+ `aria-current="true"`, so a screen reader announces it. The item
401
+ is compared with `==` and only the first equal row is marked, so pass the
402
+ same record or an equal hash. Use it instead of a "You" badge in a cell.
396
403
  - `hidden_columns:` is the table's default layout and drops only hideable
397
404
  columns. The declared order is the default order.
398
405
  - For a table whose columns a user chooses and keeps, check whether the
@@ -421,10 +428,24 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
421
428
 
422
429
  9. Show content and status.
423
430
 
424
- - `ui_button(label:, href: nil, variant: :primary, size: :md, type: :submit, data: nil)`
431
+ - `ui_button(label:, href: nil, method: :get, variant: :primary, size: :md, full_width: false, type: :submit, data: nil)`
425
432
  renders a link with `href:` and a button without it. `variant:` is
426
433
  `:primary` `:secondary` `:danger`, `size:` is `:sm` `:md` `:lg`, and
427
434
  `type:` applies only to the button.
435
+ - With `href:` and `method:` `:post` `:patch` `:put` or `:delete`, it
436
+ renders a button inside its own small form that sends that request to
437
+ `href:` when tapped. Do not write a form around it. It cannot sit inside
438
+ another form, since a form cannot hold a form. `type:` and `data:` are not
439
+ used on it.
440
+ - `full_width: true` makes the button as wide as its row at every screen
441
+ width, and for a button sending a request its form too. Use it for large
442
+ choices stacked down a phone screen.
443
+ - `ui_picture(src:, alt:, full_size_url: nil)` shows an image centred and
444
+ never taller than half the visible screen, so what follows it stays in
445
+ view. `alt:` is the text read out in place of the image. With
446
+ `full_size_url:`, tapping the picture opens that address in a new tab, so
447
+ pass `src:` a smaller version and `full_size_url:` the original file. Ask
448
+ the developer which version of an uploaded image each address points at.
428
449
  - `ui_badge(label:, variant: :neutral, class: nil)` — `variant:` is
429
450
  `:neutral` `:success` `:danger` `:warning` `:info`.
430
451
  - `ui_alert(message:, type: :info, title: nil, dismissible: false, class: nil)`
@@ -66,6 +66,7 @@ develop:
66
66
  - ui_calculation
67
67
  - ui_info
68
68
  - ui_figure
69
+ - ui_picture
69
70
  - ui_heading
70
71
  - ui_caption
71
72
  - ui_paragraph
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.53.0
4
+ version: 0.55.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.27.0
18
+ version: 0.28.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.27.0
25
+ version: 0.28.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +97,6 @@ files:
97
97
  - app/components/keystone/ui/bucket_component.rb
98
98
  - app/components/keystone/ui/bucket_series_component.html.erb
99
99
  - app/components/keystone/ui/bucket_series_component.rb
100
- - app/components/keystone/ui/button_component.html.erb
101
100
  - app/components/keystone/ui/button_component.rb
102
101
  - app/components/keystone/ui/calculation_component.html.erb
103
102
  - app/components/keystone/ui/calculation_component.rb
@@ -180,6 +179,7 @@ files:
180
179
  - app/components/keystone/ui/panel_component.rb
181
180
  - app/components/keystone/ui/paragraph_component.html.erb
182
181
  - app/components/keystone/ui/paragraph_component.rb
182
+ - app/components/keystone/ui/picture_component.rb
183
183
  - app/components/keystone/ui/pipeline_component.html.erb
184
184
  - app/components/keystone/ui/pipeline_component.rb
185
185
  - app/components/keystone/ui/progress_component.html.erb
@@ -1 +0,0 @@
1
- <%= content_tag(tag_name, @label, **tag_options) %>