velvetkit 0.5.0 → 0.6.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -18
  3. data/lib/velvetkit/version.rb +1 -1
  4. data/registry/app/components/ui/accordion/trigger.rb +1 -1
  5. data/registry/app/components/ui/badge.rb +1 -1
  6. data/registry/app/components/ui/base.rb +2 -2
  7. data/registry/app/components/ui/button.rb +1 -1
  8. data/registry/app/components/ui/carousel.html.erb +9 -4
  9. data/registry/app/components/ui/carousel.rb +42 -1
  10. data/registry/app/components/ui/checkbox.rb +2 -2
  11. data/registry/app/components/ui/file_tree/file_item.html.erb +9 -0
  12. data/registry/app/components/ui/file_tree/file_item.rb +50 -0
  13. data/registry/app/components/ui/file_tree/folder.html.erb +9 -0
  14. data/registry/app/components/ui/file_tree/folder.rb +76 -0
  15. data/registry/app/components/ui/file_tree.html.erb +1 -0
  16. data/registry/app/components/ui/file_tree.rb +93 -0
  17. data/registry/app/components/ui/gallery.rb +4 -4
  18. data/registry/app/components/ui/link.rb +1 -1
  19. data/registry/app/components/ui/menu/item.rb +1 -1
  20. data/registry/app/components/ui/radio_group/item.rb +1 -1
  21. data/registry/app/components/ui/rating.html.erb +16 -0
  22. data/registry/app/components/ui/rating.rb +200 -0
  23. data/registry/app/components/ui/sidebar/group_label.rb +1 -1
  24. data/registry/app/components/ui/sidebar/menu_button.rb +1 -1
  25. data/registry/app/components/ui/sidebar/menu_item.rb +1 -1
  26. data/registry/app/components/ui/sidebar/menu_sub.rb +1 -1
  27. data/registry/app/components/ui/switch.rb +2 -2
  28. data/registry/app/components/ui/tabs/trigger.rb +1 -1
  29. data/registry/app/javascript/controllers/ui/carousel_controller.ts +59 -1
  30. data/registry/app/javascript/controllers/ui/file_tree_controller.ts +189 -0
  31. data/registry/app/javascript/controllers/ui/rating_controller.ts +117 -0
  32. data/registry/components.yml +4 -0
  33. data/registry/config/locales/velvetkit.en.yml +13 -0
  34. data/registry/test/components/previews/ui/carousel_preview/with_indicators.html.erb +10 -0
  35. data/registry/test/components/previews/ui/carousel_preview.rb +7 -3
  36. data/registry/test/components/previews/ui/file_tree_preview/changes.html.erb +13 -0
  37. data/registry/test/components/previews/ui/file_tree_preview/from_data.html.erb +14 -0
  38. data/registry/test/components/previews/ui/file_tree_preview/picking_a_file.html.erb +25 -0
  39. data/registry/test/components/previews/ui/file_tree_preview/without_guides.html.erb +10 -0
  40. data/registry/test/components/previews/ui/file_tree_preview.rb +41 -0
  41. data/registry/test/components/previews/ui/image_preview/radii.html.erb +3 -3
  42. data/registry/test/components/previews/ui/image_preview/sizing.html.erb +9 -4
  43. data/registry/test/components/previews/ui/image_preview.rb +14 -1
  44. data/registry/test/components/previews/ui/rating_preview/in_form.html.erb +6 -0
  45. data/registry/test/components/previews/ui/rating_preview/model_errors.html.erb +20 -0
  46. data/registry/test/components/previews/ui/rating_preview/playground.html.erb +5 -0
  47. data/registry/test/components/previews/ui/rating_preview/scores.html.erb +18 -0
  48. data/registry/test/components/previews/ui/rating_preview/sizes.html.erb +6 -0
  49. data/registry/test/components/previews/ui/rating_preview.rb +28 -0
  50. data/registry/test/components/ui/base_test.rb +27 -0
  51. data/registry/test/components/ui/button_test.rb +2 -2
  52. data/registry/test/components/ui/carousel_test.rb +48 -0
  53. data/registry/test/components/ui/confirm_dialog_test.rb +3 -0
  54. data/registry/test/components/ui/file_tree_test.rb +187 -0
  55. data/registry/test/components/ui/gallery_test.rb +4 -4
  56. data/registry/test/components/ui/link_test.rb +1 -1
  57. data/registry/test/components/ui/number_input_test.rb +1 -1
  58. data/registry/test/components/ui/rating_test.rb +271 -0
  59. data/registry/test/components/ui/switch_test.rb +4 -4
  60. metadata +25 -1
@@ -68,6 +68,8 @@ components:
68
68
  description: A group of controls under one legend, with a hint and an error message for the group.
69
69
  file_field:
70
70
  description: A drag-and-drop file picker with previews, and direct upload to storage, standalone or with a form builder.
71
+ file_tree:
72
+ description: Folders and files in a tree that opens and closes, with arrow keys to move through it.
71
73
  form_field:
72
74
  description: A label, hint and error message wired to any form control.
73
75
  gallery:
@@ -105,6 +107,8 @@ components:
105
107
  description: A bar showing how far along a task is, or that it's still going.
106
108
  radio_group:
107
109
  description: A set of radio buttons.
110
+ rating:
111
+ description: A score in stars, shown to the half star with its count, or chosen with a radio for each star.
108
112
  native_select:
109
113
  description: The browser's own select, styled closed; best for phones' system pickers.
110
114
  scan_input:
@@ -33,6 +33,8 @@ en:
33
33
  roledescription: 'carousel'
34
34
  previous: 'Previous'
35
35
  next: 'Next'
36
+ indicators: 'Choose a slide'
37
+ indicator: 'Go to slide %{number}'
36
38
  chart:
37
39
  label: 'Chart'
38
40
  keyboard: 'Use the arrow keys to read each value.'
@@ -80,6 +82,15 @@ en:
80
82
  progress:
81
83
  label: 'Progress'
82
84
  value_text: '%{percent}%'
85
+ rating:
86
+ name: 'Rating'
87
+ label: 'Rated %{value} out of %{max}'
88
+ option: '%{count} out of %{max}'
89
+ thanks: 'Thank you for your rating'
90
+ score: '%{value}/%{max}'
91
+ count:
92
+ one: '%{count} rating'
93
+ other: '%{count} ratings'
83
94
  slider:
84
95
  from: 'Minimum'
85
96
  to: 'Maximum'
@@ -170,6 +181,8 @@ en:
170
181
  position: 'Image %{current} of %{total}'
171
182
  open: 'Open %{alt}'
172
183
  info: 'Info'
184
+ file_tree:
185
+ label: 'Files'
173
186
  file_field:
174
187
  browse: 'Click to upload'
175
188
  drop: 'or drag and drop'
@@ -0,0 +1,10 @@
1
+ <%# One photo at a time, with an indicator for each. The indicators are the way
2
+ through on a phone, where the buttons don't show; turn them on with
3
+ `indicators: true`. %>
4
+ <%= render(UI::Carousel.new(label: "Featured", item_class: "basis-full", indicators: true, class: "max-w-2xl")) do |carousel| %>
5
+ <% UI::GalleryPreview.photos.each do |title, src| %>
6
+ <% carousel.with_item do %>
7
+ <%= image_tag src, alt: title, class: "aspect-[16/9] w-full rounded-xl object-cover" %>
8
+ <% end %>
9
+ <% end %>
10
+ <% end %>
@@ -3,9 +3,10 @@
3
3
  class UI::CarouselPreview < ViewComponent::Preview
4
4
  # @label Playground
5
5
  # @param count number { min: 1, max: 12 }
6
- # @param item_class select { choices: [w-48, w-64, basis-1/2, basis-1/3] }
7
- def playground(count: 8, item_class: "w-48")
8
- render(UI::Carousel.new(label: "Albums", item_class: item_class, class: "max-w-2xl")) do |carousel|
6
+ # @param item_class select { choices: [w-48, w-64, basis-1/2, basis-1/3, basis-full] }
7
+ # @param indicators toggle
8
+ def playground(count: 8, item_class: "w-48", indicators: false)
9
+ render(UI::Carousel.new(label: "Albums", item_class: item_class, indicators: indicators, class: "max-w-2xl")) do |carousel|
9
10
  UI::GalleryPreview.photos.cycle.first(count.to_i).each_with_index do |(title, src), index|
10
11
  carousel.with_item do
11
12
  tag.a(href: "#", class: "group block space-y-2 rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary") do
@@ -19,4 +20,7 @@ class UI::CarouselPreview < ViewComponent::Preview
19
20
 
20
21
  # @label Highlights
21
22
  def highlights; render_with_template; end
23
+
24
+ # @label With indicators
25
+ def with_indicators; render_with_template; end
22
26
  end
@@ -0,0 +1,13 @@
1
+ <%# The block shows at the end of a file's row. %>
2
+ <%= render(UI::FileTree.new(label: "Changed files", class: "max-w-xs")) do |tree| %>
3
+ <% tree.with_folder(name: "app", open: true) do |app| %>
4
+ <% app.with_folder(name: "controllers", open: true) do |controllers| %>
5
+ <% controllers.with_file(name: "orders_controller.rb", value: "app/controllers/orders_controller.rb") do %><span class="text-amber-600 dark:text-amber-400">M</span><% end %>
6
+ <% end %>
7
+ <% app.with_folder(name: "models", open: true) do |models| %>
8
+ <% models.with_file(name: "order.rb", value: "app/models/order.rb") do %><span class="text-amber-600 dark:text-amber-400">M</span><% end %>
9
+ <% models.with_file(name: "refund.rb", value: "app/models/refund.rb", active: true) do %><span class="text-emerald-600 dark:text-emerald-400">A</span><% end %>
10
+ <% end %>
11
+ <% end %>
12
+ <% tree.with_file(name: "legacy_export.rb", value: "legacy_export.rb") do %><span class="text-destructive">D</span><% end %>
13
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <%# A hash with `children:` is a folder; any other is a file. %>
2
+ <%= render(UI::FileTree.new(label: "Documents", class: "max-w-xs", items: [
3
+ { name: "Contracts", children: [
4
+ { name: "2025", children: [
5
+ { name: "Acme MSA.pdf", value: "contracts/2025/acme-msa.pdf" },
6
+ { name: "Globex NDA.pdf", value: "contracts/2025/globex-nda.pdf" }
7
+ ] },
8
+ { name: "2026", children: [
9
+ { name: "Initech SOW.pdf", value: "contracts/2026/initech-sow.pdf", active: true }
10
+ ] }
11
+ ] },
12
+ { name: "Invoices", children: [] },
13
+ { name: "Brand guide.pdf", value: "brand-guide.pdf", icon: "file-text" }
14
+ ])) %>
@@ -0,0 +1,25 @@
1
+ <div id="file-tree-picking-demo" class="grid max-w-2xl gap-4 sm:grid-cols-[14rem_1fr]">
2
+ <%= render(UI::FileTree.new(label: "Source")) do |tree| %>
3
+ <% tree.with_folder(name: "src") do |src| %>
4
+ <% src.with_folder(name: "lib") do |lib| %>
5
+ <% lib.with_file(name: "format.ts", value: "src/lib/format.ts") %>
6
+ <% lib.with_file(name: "money.ts", value: "src/lib/money.ts") %>
7
+ <% end %>
8
+ <% src.with_file(name: "index.ts", value: "src/index.ts", active: true) %>
9
+ <% end %>
10
+ <% tree.with_file(name: "package.json", value: "package.json") %>
11
+ <% tree.with_file(name: "tsconfig.json", value: "tsconfig.json") %>
12
+ <% end %>
13
+ <div class="rounded-lg border bg-muted/40 p-4 font-mono text-sm">
14
+ <p class="text-muted-foreground">Selected</p>
15
+ <p data-demo="path" class="mt-1 text-foreground">src/index.ts</p>
16
+ </div>
17
+ </div>
18
+ <script>
19
+ (() => {
20
+ const root = document.getElementById("file-tree-picking-demo");
21
+ root.addEventListener("ui--file-tree:select", (event) => {
22
+ root.querySelector('[data-demo="path"]').textContent = event.detail.value;
23
+ });
24
+ })();
25
+ </script>
@@ -0,0 +1,10 @@
1
+ <%= render(UI::FileTree.new(label: "Project files", guides: false, class: "max-w-xs")) do |tree| %>
2
+ <% tree.with_folder(name: "app", open: true) do |app| %>
3
+ <% app.with_folder(name: "views", open: true) do |views| %>
4
+ <% views.with_file(name: "index.html.erb", value: "app/views/index.html.erb") %>
5
+ <% views.with_file(name: "show.html.erb", value: "app/views/show.html.erb", active: true) %>
6
+ <% end %>
7
+ <% app.with_file(name: "application.rb", value: "app/application.rb") %>
8
+ <% end %>
9
+ <% tree.with_file(name: "Gemfile", value: "Gemfile") %>
10
+ <% end %>
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::FileTreePreview < ViewComponent::Preview
4
+ # @label Playground
5
+ # @param guides toggle
6
+ # @param open toggle "Open every folder, whatever the active file"
7
+ # @param links toggle "Files are links, not rows to pick"
8
+ def playground(guides: true, open: false, links: true)
9
+ href = ->(path) { "#/blob/#{path}" if links }
10
+ open = open || nil
11
+ render(UI::FileTree.new(label: "Project files", guides: guides, class: "max-w-xs")) do |tree|
12
+ tree.with_folder(name: "app", open: open) do |app|
13
+ app.with_folder(name: "components", open: open) do |components|
14
+ components.with_file(name: "button.rb", href: href.("app/components/button.rb"), active: true)
15
+ components.with_file(name: "button.html.erb", href: href.("app/components/button.html.erb"))
16
+ components.with_file(name: "card.rb", href: href.("app/components/card.rb"))
17
+ end
18
+ app.with_folder(name: "models", open: open) do |models|
19
+ models.with_file(name: "user.rb", href: href.("app/models/user.rb"))
20
+ end
21
+ end
22
+ tree.with_folder(name: "config", open: open) do |config|
23
+ config.with_file(name: "routes.rb", href: href.("config/routes.rb"))
24
+ end
25
+ tree.with_file(name: "Gemfile", href: href.("Gemfile"))
26
+ tree.with_file(name: "README.md", href: href.("README.md"), icon: "file-text")
27
+ end
28
+ end
29
+
30
+ # @label From Data
31
+ def from_data; render_with_template; end
32
+
33
+ # @label Picking a File
34
+ def picking_a_file; render_with_template; end
35
+
36
+ # @label Changes, with Badges
37
+ def changes; render_with_template; end
38
+
39
+ # @label Without Guides
40
+ def without_guides; render_with_template; end
41
+ end
@@ -1,7 +1,7 @@
1
- <div class="flex flex-wrap items-end gap-6">
2
- <% %i[none sm md lg xl full].each do |r| %>
1
+ <div class="flex flex-wrap gap-6">
2
+ <% %i[none xs sm md lg xl full].each do |r| %>
3
3
  <div class="flex flex-col items-center gap-2">
4
- <%= render(UI::Image.new(src: "/icon.png", rounded: r, width: "48px", height: "48px")) %>
4
+ <%= render(UI::Image.new(src: UI::ImagePreview.photo, alt: "Mountains at sunset", rounded: r, width: "96px", height: "96px")) %>
5
5
  <span class="text-xs text-muted-foreground"><%= r %></span>
6
6
  </div>
7
7
  <% end %>
@@ -1,9 +1,14 @@
1
- <%# Dimensions land on the <img> itself, not on a wrapper. %>
2
- <div class="flex flex-wrap items-end gap-6">
1
+ <%# Dimensions land on the <img> itself, not on a wrapper; the height follows the image's own ratio. %>
2
+ <div class="flex flex-wrap items-end gap-8">
3
3
  <% ["48px", "96px", "160px"].each do |w| %>
4
4
  <div class="flex flex-col items-center gap-2">
5
- <%= render(UI::Image.new(src: "/icon.png", rounded: :md, width: w)) %>
6
- <span class="text-xs text-muted-foreground">width: <%= w %></span>
5
+ <%= render(UI::Image.new(src: UI::ImagePreview.photo, alt: "Mountains at sunset", rounded: :md, width: w)) %>
6
+ <div class="flex items-center text-muted-foreground" style="width: <%= w %>" aria-hidden="true">
7
+ <span class="h-2 border-l border-current"></span>
8
+ <span class="flex-1 border-t border-current"></span>
9
+ <span class="h-2 border-r border-current"></span>
10
+ </div>
11
+ <span class="text-xs text-muted-foreground"><%= w %></span>
7
12
  </div>
8
13
  <% end %>
9
14
  </div>
@@ -1,11 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UI::ImagePreview < ViewComponent::Preview
4
+ # Drawn here so the previews need no image files. It fills its frame edge to
5
+ # edge (`slice`), so the corners show the radius and the size reads at a glance.
6
+ def self.photo
7
+ svg = "<svg xmlns='http://www.w3.org/2000/svg' width='400' height='300' viewBox='0 0 400 300' " \
8
+ "preserveAspectRatio='xMidYMid slice'>" \
9
+ "<defs><linearGradient id='sky' x2='0' y2='1'><stop stop-color='#c4b5fd'/><stop offset='1' stop-color='#fde68a'/>" \
10
+ "</linearGradient></defs><rect width='400' height='300' fill='url(#sky)'/>" \
11
+ "<circle cx='290' cy='110' r='42' fill='#f59e0b'/>" \
12
+ "<path d='M0 300V190l90-80 70 60 80-90 90 100 70-50v170z' fill='#7c3aed'/>" \
13
+ "<path d='M0 300V240l110-60 90 50 100-40 100 60v50z' fill='#4c1d95'/></svg>"
14
+ "data:image/svg+xml,#{ERB::Util.url_encode(svg)}"
15
+ end
16
+
4
17
  # @label Playground
5
18
  # @param rounded select { choices: [none, xs, sm, md, lg, xl, full] }
6
19
  # @param width text
7
20
  def playground(rounded: :sm, width: "160px")
8
- render(UI::Image.new(src: "/icon.png", rounded: rounded.to_sym, width: width))
21
+ render(UI::Image.new(src: self.class.photo, alt: "Mountains at sunset", rounded: rounded.to_sym, width: width))
9
22
  end
10
23
 
11
24
  # @label Radii
@@ -0,0 +1,6 @@
1
+ <%# A radio for each star: it posts with the form and needs no JavaScript. Arrow keys move between the stars. %>
2
+ <form class="flex max-w-sm flex-col gap-6" action="#" onsubmit="event.preventDefault()">
3
+ <%= render(UI::Rating.new(name: "review[rating]", legend: "Your rating", hint: "How did the kettle work for you?", required: true, size: :lg)) %>
4
+ <%= render(UI::Textarea.new(name: "review[body]", label: "Review", rows: 3)) %>
5
+ <%= render(UI::Button.new(type: :submit, class: "self-start")) { "Post review" } %>
6
+ </form>
@@ -0,0 +1,20 @@
1
+ <%# In an app, @review comes back from a failed save. Bound, the field shows its errors on its own,
2
+ and choosing a score clears them; `thanks: true` then says thank you. Resetting the form brings
3
+ the errors back: the reset button is only here to try it again. The messages are kept from
4
+ widening the field, so the button stays beside the stars. %>
5
+ <% review = Struct.new(:rating, :delivery) do
6
+ include ActiveModel::Validations
7
+ def self.model_name = ActiveModel::Name.new(self, nil, "Review")
8
+ validates :rating, presence: true
9
+ end.new(nil, 4).tap(&:validate) %>
10
+ <%= form_with(model: review, url: "#", class: "flex max-w-sm flex-col gap-6") do |f| %>
11
+ <div class="flex items-center gap-2 [&_fieldset>p]:w-0 [&_fieldset>p]:whitespace-nowrap">
12
+ <%= render(UI::Rating.new(form: f, field: :rating, legend: true, required: true, thanks: true, show_value: true)) %>
13
+ <button type="reset" title="Start again" aria-label="Start again"
14
+ class="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-primary">
15
+ <%# Not one of the kit's controls, so only the icon: a ring only from the keyboard. %>
16
+ <%= render(UI::Icon.new(name: "rotate-cw", size: :sm)) %>
17
+ </button>
18
+ </div>
19
+ <%= render(UI::Rating.new(form: f, field: :delivery, legend: "Delivery", hint: "Was it on time and well packed?")) %>
20
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if field %>
2
+ <%= render(UI::Rating.new(name: "rating", value: value, max: max, size: size, disabled: disabled, show_value: show_value, legend: "Your rating")) %>
3
+ <% else %>
4
+ <%= render(UI::Rating.new(value: value, max: max, size: size, show_value: show_value, count: count)) %>
5
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <%# Shown to the nearest half star. A screen reader hears one image, "Rated 4.5 out of 5", and the count.
2
+ The last is a field to choose one: `show_value: true` keeps the score beside it to the one chosen, and
3
+ it resets with the form. The reset button is only here to try it again. %>
4
+ <div class="flex flex-col gap-3">
5
+ <%= render(UI::Rating.new(value: 5, show_value: true, count: 2_481)) %>
6
+ <%= render(UI::Rating.new(value: 4.5, show_value: true, count: 312)) %>
7
+ <%= render(UI::Rating.new(value: 3.7, show_value: true, count: 46)) %>
8
+ <%= render(UI::Rating.new(value: 2, show_value: true, count: 1)) %>
9
+ <%= render(UI::Rating.new(value: nil, show_value: true, count: 0)) %>
10
+ <form action="#" onsubmit="event.preventDefault()" class="flex items-center gap-2">
11
+ <%= render(UI::Rating.new(name: "rating", show_value: true)) %>
12
+ <button type="reset" title="Start again" aria-label="Start again"
13
+ class="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-primary">
14
+ <%# Not one of the kit's controls, so only the icon: a ring only from the keyboard. %>
15
+ <%= render(UI::Icon.new(name: "rotate-cw", size: :sm)) %>
16
+ </button>
17
+ </form>
18
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class="flex flex-col gap-4">
2
+ <%= render(UI::Rating.new(value: 4.5, size: :sm, show_value: true, count: 89)) %>
3
+ <%= render(UI::Rating.new(value: 4.5, show_value: true, count: 89)) %>
4
+ <%= render(UI::Rating.new(value: 4.5, size: :lg, class: "text-base", show_value: true, count: 89)) %>
5
+ <%= render(UI::Rating.new(name: "size_lg", value: 4, size: :lg, label: "Large rating")) %>
6
+ </div>
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::RatingPreview < ViewComponent::Preview
4
+ # @label Playground
5
+ # @param field toggle
6
+ # @param value number
7
+ # @param max number
8
+ # @param size select { choices: [sm, default, lg] }
9
+ # @param show_value toggle
10
+ # @param count number
11
+ # @param disabled toggle
12
+ def playground(field: false, value: 3.5, max: 5, size: :default, show_value: true, count: 128, disabled: false)
13
+ render_with_template(locals: { field: field, value: value, max: max.to_i.clamp(1, 10), size: size.to_sym,
14
+ show_value: show_value, count: count.presence, disabled: disabled })
15
+ end
16
+
17
+ # @label Scores
18
+ def scores; render_with_template; end
19
+
20
+ # @label Sizes
21
+ def sizes; render_with_template; end
22
+
23
+ # @label In a Form
24
+ def in_form; render_with_template; end
25
+
26
+ # @label Errors from the Model
27
+ def model_errors; render_with_template; end
28
+ end
@@ -95,4 +95,31 @@ class UI::BaseTest < ViewComponent::TestCase
95
95
  btn = page.find("button")
96
96
  refute_includes btn[:class], "border-2"
97
97
  end
98
+
99
+ # The ring on click is VelvetKit's signature (AGENTS.md, "Focus rings"):
100
+ # 0.5.0 moved it to :focus-visible by mistake and 0.5.1 put it back. If this
101
+ # fails, don't rewrite it to match; ask the maintainer first.
102
+ def test_the_focus_ring_shows_on_click
103
+ assert_includes UI::Base::FOCUS_RING, "focus:ring-2"
104
+ assert_includes UI::Base::FOCUS_RING, "focus:ring-primary"
105
+ refute_match(/focus-visible:ring/, UI::Base::FOCUS_RING)
106
+ end
107
+
108
+ # Components whose ring is keyboard-only, each a deliberate choice made
109
+ # before 0.5. A new one needs the maintainer's sign-off, then a place here.
110
+ KEYBOARD_ONLY_RINGS = %w[
111
+ input_group/addon navigation_menu/item navigation_menu/link scrubber
112
+ session_tabs/tab slider stepper/step
113
+ ].freeze
114
+
115
+ def test_no_other_component_has_a_keyboard_only_ring
116
+ # Beside base.rb, wherever the kit is (the namespaced run renames ui/).
117
+ root = File.dirname(Object.const_source_location(UI::Base.name).first)
118
+ keyboard_only = Dir.glob("**/*.{rb,html.erb}", base: root).select do |file|
119
+ File.read(File.join(root, file)).match?(/focus-visible:ring/)
120
+ end.map { _1.sub(/\.(rb|html\.erb)\z/, "") }.uniq.sort
121
+
122
+ assert_equal KEYBOARD_ONLY_RINGS.sort, keyboard_only,
123
+ "The focus ring shows on click as well as on Tab (AGENTS.md). Ask the maintainer before using :focus-visible."
124
+ end
98
125
  end
@@ -23,8 +23,8 @@ class UI::ButtonTest < ViewComponent::TestCase
23
23
  assert_includes classes, "bg-destructive"
24
24
  refute_includes classes, "bg-primary"
25
25
  # destructive variant overrides the default focus ring color
26
- assert_includes classes, "focus-visible:ring-destructive"
27
- refute_includes classes, "focus-visible:ring-primary"
26
+ assert_includes classes, "focus:ring-destructive"
27
+ refute_includes classes, "focus:ring-primary"
28
28
  end
29
29
 
30
30
  def test_renders_outline_variant
@@ -30,6 +30,54 @@ class UI::CarouselTest < ViewComponent::TestCase
30
30
  assert_selector "button[aria-label=Next][hidden][aria-controls='#{track}'] svg[data-icon='chevron-right']", visible: :all
31
31
  end
32
32
 
33
+ def test_no_indicators_unless_asked
34
+ render_carousel
35
+ assert_no_selector "[data-ui--carousel-target=indicator]", visible: :all
36
+ assert_no_selector "[role=group]", visible: :all
37
+ end
38
+
39
+ def test_indicators_a_hidden_one_for_each_card_until_the_controller_shows_them
40
+ render_carousel(indicators: true)
41
+ track = page.find("ul")[:id]
42
+ group = page.find("[role=group][aria-label='Choose a slide']")
43
+ indicators = group.all("button[type=button][hidden][data-ui--carousel-target=indicator]", visible: :all)
44
+ assert_equal [ "Go to slide 1", "Go to slide 2", "Go to slide 3" ], indicators.map { _1[:"aria-label"] }
45
+ assert_equal %w[0 1 2], indicators.map { _1[:"data-ui--carousel-index-param"] }
46
+ assert indicators.all? { _1[:"aria-controls"] == track && _1[:"data-action"] == "ui--carousel#go" }
47
+ end
48
+
49
+ # The indicators draw no focus ring: the lit one shows which card is in view.
50
+ def test_an_indicator_draws_no_focus_ring
51
+ render_carousel(indicators: true)
52
+ classes = page.first("[data-ui--carousel-target=indicator]", visible: :all)[:class].split
53
+ refute classes.any? { _1.include?("focus") || _1.include?("ring") }
54
+ assert_includes classes, "outline-none"
55
+ end
56
+
57
+ # The controller sets --fill as the strip scrolls; the indicator widens and fills
58
+ # with it, with no transition to trail behind the scroll.
59
+ def test_an_indicator_widens_and_fills_with_the_scroll
60
+ render_carousel(indicators: true)
61
+ indicator = page.first("[data-ui--carousel-target=indicator]", visible: :all)
62
+ classes = indicator[:class].split
63
+ assert_includes classes, "w-[calc(0.5rem+1rem*var(--fill,0))]"
64
+ refute classes.any? { _1.start_with?("transition") }
65
+ assert_includes indicator.find("span[aria-hidden=true]", visible: :all)[:class].split, "opacity-[var(--fill,0)]"
66
+ end
67
+
68
+ # The indicators sit under the strip, so the buttons centre on the strip alone.
69
+ def test_the_buttons_centre_on_the_strip_not_the_indicators
70
+ render_carousel(indicators: true)
71
+ assert_selector "[role=region] > div.relative > ul + button + button", visible: :all
72
+ assert_selector "[role=region] > div.relative + [role=group]", visible: :all
73
+ end
74
+
75
+ # 0.6.0 called them dots.
76
+ def test_dots_still_turns_on_the_indicators
77
+ render_carousel(dots: true)
78
+ assert_selector "[data-ui--carousel-target=indicator]", count: 3, visible: :all
79
+ end
80
+
33
81
  def test_gap_class_and_attributes
34
82
  render_carousel(gap: 6, class: "mt-4", id: "highlights")
35
83
  assert_selector "#highlights.mt-4"
@@ -49,6 +49,9 @@ class UI::ConfirmDialogTest < ViewComponent::TestCase
49
49
  def test_labels_come_from_i18n
50
50
  # Built from the dotted scope so the namespaced run stores it under its own scope.
51
51
  labels = "ui.confirm_dialog".split(".").reverse.inject({ confirm: "OK", cancel: "Never mind" }) { |h, k| { k => h } }
52
+ # Load the locale files first: I18n loads them on its first lookup, which
53
+ # would put the kit's own labels back over these when this test runs first.
54
+ I18n.backend.eager_load!
52
55
  I18n.backend.store_translations(:en, labels)
53
56
  render_inline(UI::ConfirmDialog.new)
54
57
  assert_equal "OK", dialog["data-ui--confirm-dialog-confirm-label-value"]