velvetkit 0.4.2 → 0.5.1

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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -2
  3. data/lib/velvetkit/version.rb +1 -1
  4. data/registry/app/components/ui/carousel.html.erb +7 -0
  5. data/registry/app/components/ui/carousel.rb +60 -0
  6. data/registry/app/components/ui/chart.html.erb +3 -3
  7. data/registry/app/components/ui/chart.rb +18 -10
  8. data/registry/app/components/ui/checkbox.html.erb +6 -0
  9. data/registry/app/components/ui/checkbox.rb +9 -2
  10. data/registry/app/components/ui/fieldset.html.erb +6 -0
  11. data/registry/app/components/ui/fieldset.rb +76 -0
  12. data/registry/app/components/ui/gallery/image.rb +14 -1
  13. data/registry/app/components/ui/gallery.html.erb +32 -3
  14. data/registry/app/components/ui/gallery.rb +44 -5
  15. data/registry/app/components/ui/radio_group/item.html.erb +1 -1
  16. data/registry/app/components/ui/radio_group/item.rb +4 -0
  17. data/registry/app/components/ui/radio_group.html.erb +1 -1
  18. data/registry/app/components/ui/radio_group.rb +42 -2
  19. data/registry/app/components/ui/scrubber.html.erb +18 -0
  20. data/registry/app/components/ui/scrubber.rb +62 -0
  21. data/registry/app/components/ui/select.html.erb +1 -1
  22. data/registry/app/components/ui/select.rb +16 -1
  23. data/registry/app/components/ui/selection_bar.html.erb +7 -0
  24. data/registry/app/components/ui/selection_bar.rb +75 -0
  25. data/registry/app/components/ui/sidebar/inset.rb +5 -2
  26. data/registry/app/components/ui/sidebar/menu_button.rb +24 -9
  27. data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -1
  28. data/registry/app/components/ui/sidebar/menu_item.rb +31 -5
  29. data/registry/app/components/ui/sidebar/menu_sub.rb +59 -0
  30. data/registry/app/components/ui/sidebar.html.erb +3 -3
  31. data/registry/app/components/ui/sidebar.rb +91 -13
  32. data/registry/app/components/ui/table/column.html.erb +1 -1
  33. data/registry/app/components/ui/table/column.rb +26 -2
  34. data/registry/app/components/ui/table/head.html.erb +1 -1
  35. data/registry/app/components/ui/table/head.rb +15 -2
  36. data/registry/app/components/ui/table/row.html.erb +1 -1
  37. data/registry/app/components/ui/table/row.rb +19 -5
  38. data/registry/app/components/ui/table.html.erb +2 -2
  39. data/registry/app/components/ui/table.rb +29 -4
  40. data/registry/app/components/ui/toggle_group.html.erb +1 -1
  41. data/registry/app/components/ui/toggle_group.rb +26 -3
  42. data/registry/app/javascript/controllers/ui/carousel_controller.ts +63 -0
  43. data/registry/app/javascript/controllers/ui/file_field_controller.ts +1 -1
  44. data/registry/app/javascript/controllers/ui/gallery_controller.ts +52 -14
  45. data/registry/app/javascript/controllers/ui/scrubber_controller.ts +188 -0
  46. data/registry/app/javascript/controllers/ui/selection_bar_controller.ts +122 -0
  47. data/registry/app/javascript/controllers/ui/sidebar_controller.ts +102 -32
  48. data/registry/components.yml +11 -3
  49. data/registry/config/locales/velvetkit.en.yml +16 -0
  50. data/registry/icons/lucide/arrow-down.svg +16 -0
  51. data/registry/icons/lucide/arrow-up.svg +16 -0
  52. data/registry/icons/lucide/image.svg +17 -0
  53. data/registry/icons/lucide/star.svg +15 -0
  54. data/registry/icons/phosphor/arrow-down.svg +2 -0
  55. data/registry/icons/phosphor/arrow-up.svg +2 -0
  56. data/registry/icons/phosphor/image.svg +2 -0
  57. data/registry/icons/phosphor/star.svg +2 -0
  58. data/registry/icons/tabler/arrow-down.svg +18 -0
  59. data/registry/icons/tabler/arrow-up.svg +18 -0
  60. data/registry/icons/tabler/photo.svg +19 -0
  61. data/registry/icons/tabler/star.svg +16 -0
  62. data/registry/icons.yml +4 -0
  63. data/registry/test/components/previews/ui/carousel_preview/highlights.html.erb +17 -0
  64. data/registry/test/components/previews/ui/carousel_preview.rb +22 -0
  65. data/registry/test/components/previews/ui/chart_preview/whole_dollars.html.erb +19 -0
  66. data/registry/test/components/previews/ui/chart_preview.rb +7 -1
  67. data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +2 -3
  68. data/registry/test/components/previews/ui/fieldset_preview/block_of_fields.html.erb +18 -0
  69. data/registry/test/components/previews/ui/fieldset_preview/groups.html.erb +14 -0
  70. data/registry/test/components/previews/ui/fieldset_preview/model_errors.html.erb +22 -0
  71. data/registry/test/components/previews/ui/fieldset_preview/playground.html.erb +5 -0
  72. data/registry/test/components/previews/ui/fieldset_preview.rb +24 -0
  73. data/registry/test/components/previews/ui/gallery_preview/grid.html.erb +25 -0
  74. data/registry/test/components/previews/ui/gallery_preview.rb +3 -0
  75. data/registry/test/components/previews/ui/scrubber_preview/default.html.erb +24 -0
  76. data/registry/test/components/previews/ui/scrubber_preview.rb +6 -0
  77. data/registry/test/components/previews/ui/selection_bar_preview/floating.html.erb +16 -0
  78. data/registry/test/components/previews/ui/selection_bar_preview/table.html.erb +26 -0
  79. data/registry/test/components/previews/ui/selection_bar_preview.rb +9 -0
  80. data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +5 -4
  81. data/registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb +52 -0
  82. data/registry/test/components/previews/ui/sidebar_preview.rb +3 -0
  83. data/registry/test/components/previews/ui/table_preview/selectable.html.erb +26 -0
  84. data/registry/test/components/previews/ui/table_preview/sortable.html.erb +20 -0
  85. data/registry/test/components/previews/ui/table_preview/sticky_header.html.erb +13 -0
  86. data/registry/test/components/previews/ui/table_preview.rb +9 -0
  87. data/registry/test/components/ui/base_test.rb +27 -0
  88. data/registry/test/components/ui/carousel_test.rb +38 -0
  89. data/registry/test/components/ui/chart_test.rb +20 -0
  90. data/registry/test/components/ui/checkbox_test.rb +11 -2
  91. data/registry/test/components/ui/confirm_dialog_test.rb +3 -0
  92. data/registry/test/components/ui/fieldset_test.rb +119 -0
  93. data/registry/test/components/ui/gallery_test.rb +36 -1
  94. data/registry/test/components/ui/radio_group_test.rb +106 -0
  95. data/registry/test/components/ui/scrubber_test.rb +43 -0
  96. data/registry/test/components/ui/select_test.rb +21 -0
  97. data/registry/test/components/ui/selection_bar_test.rb +46 -0
  98. data/registry/test/components/ui/sidebar/menu_button_test.rb +9 -0
  99. data/registry/test/components/ui/sidebar_test.rb +79 -1
  100. data/registry/test/components/ui/toggle_group_test.rb +45 -0
  101. metadata +47 -1
@@ -0,0 +1,18 @@
1
+ <!-- @license @tabler/icons v3.50.0 - MIT -->
2
+ <svg
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ width="24"
5
+ height="24"
6
+ viewBox="0 0 24 24"
7
+ fill="none"
8
+ stroke="currentColor"
9
+ stroke-width="2"
10
+ stroke-linecap="round"
11
+ stroke-linejoin="round"
12
+ class="icon icon-tabler icons-tabler-outline icon-tabler-arrow-down"
13
+ >
14
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
15
+ <path d="M12 5l0 14" />
16
+ <path d="M18 13l-6 6" />
17
+ <path d="M6 13l6 6" />
18
+ </svg>
@@ -0,0 +1,18 @@
1
+ <!-- @license @tabler/icons v3.50.0 - MIT -->
2
+ <svg
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ width="24"
5
+ height="24"
6
+ viewBox="0 0 24 24"
7
+ fill="none"
8
+ stroke="currentColor"
9
+ stroke-width="2"
10
+ stroke-linecap="round"
11
+ stroke-linejoin="round"
12
+ class="icon icon-tabler icons-tabler-outline icon-tabler-arrow-up"
13
+ >
14
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
15
+ <path d="M12 5l0 14" />
16
+ <path d="M18 11l-6 -6" />
17
+ <path d="M6 11l6 -6" />
18
+ </svg>
@@ -0,0 +1,19 @@
1
+ <!-- @license @tabler/icons v3.50.0 - MIT -->
2
+ <svg
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ width="24"
5
+ height="24"
6
+ viewBox="0 0 24 24"
7
+ fill="none"
8
+ stroke="currentColor"
9
+ stroke-width="2"
10
+ stroke-linecap="round"
11
+ stroke-linejoin="round"
12
+ class="icon icon-tabler icons-tabler-outline icon-tabler-photo"
13
+ >
14
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
15
+ <path d="M15 8h.01" />
16
+ <path d="M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12" />
17
+ <path d="M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5" />
18
+ <path d="M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3" />
19
+ </svg>
@@ -0,0 +1,16 @@
1
+ <!-- @license @tabler/icons v3.50.0 - MIT -->
2
+ <svg
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ width="24"
5
+ height="24"
6
+ viewBox="0 0 24 24"
7
+ fill="none"
8
+ stroke="currentColor"
9
+ stroke-width="2"
10
+ stroke-linecap="round"
11
+ stroke-linejoin="round"
12
+ class="icon icon-tabler icons-tabler-outline icon-tabler-star"
13
+ >
14
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
15
+ <path d="M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873l-6.158 -3.245" />
16
+ </svg>
data/registry/icons.yml CHANGED
@@ -9,8 +9,10 @@
9
9
  align-center: { tabler: align-center, phosphor: text-align-center }
10
10
  align-left: { tabler: align-left, phosphor: text-align-left }
11
11
  align-right: { tabler: align-right, phosphor: text-align-right }
12
+ arrow-down: { tabler: arrow-down, phosphor: arrow-down }
12
13
  arrow-left: { tabler: arrow-left, phosphor: arrow-left }
13
14
  arrow-right: { tabler: arrow-right, phosphor: arrow-right }
15
+ arrow-up: { tabler: arrow-up, phosphor: arrow-up }
14
16
  badge-check: { tabler: rosette-discount-check, phosphor: seal-check }
15
17
  bar-chart-3: { tabler: chart-bar, phosphor: chart-bar }
16
18
  bell: { tabler: bell, phosphor: bell }
@@ -43,6 +45,7 @@ graduation-cap: { tabler: school, phosphor: graduation-cap }
43
45
  grip-vertical: { tabler: grip-vertical, phosphor: dots-six-vertical }
44
46
  home: { tabler: home, phosphor: house }
45
47
  inbox: { tabler: inbox, phosphor: tray }
48
+ image: { tabler: photo, phosphor: image }
46
49
  info: { tabler: info-circle, phosphor: info }
47
50
  italic: { tabler: italic, phosphor: text-italic }
48
51
  keyboard: { tabler: keyboard, phosphor: keyboard }
@@ -76,6 +79,7 @@ settings: { tabler: settings, phosphor: gear }
76
79
  shield: { tabler: shield, phosphor: shield }
77
80
  shield-check: { tabler: shield-check, phosphor: shield-check }
78
81
  store: { tabler: building-store, phosphor: storefront }
82
+ star: { tabler: star, phosphor: star }
79
83
  sun: { tabler: sun, phosphor: sun }
80
84
  sun-moon: { tabler: sun-moon, phosphor: circle-half }
81
85
  trash-2: { tabler: trash, phosphor: trash }
@@ -0,0 +1,17 @@
1
+ <%# Cards with their title over the photo. The buttons show only while
2
+ there's more to see that way; on a touch screen the strip swipes. %>
3
+ <%= render(UI::Carousel.new(label: "Highlights", item_class: "w-56 sm:w-64", class: "max-w-3xl")) do |carousel| %>
4
+ <% [ [ "This week", "4 photos" ], [ "Coast walk", "2025" ], [ "Garden", "Spring" ], [ "City at night", "12 photos" ],
5
+ [ "One year ago", "November 2025" ], [ "Kitchen", "Recipes" ] ].each_with_index do |(title, detail), index| %>
6
+ <% carousel.with_item do %>
7
+ <a href="#" class="relative block aspect-[4/3] overflow-hidden rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2">
8
+ <%= image_tag UI::GalleryPreview.photos[index % 5].last, alt: "", class: "size-full object-cover" %>
9
+ <span class="absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent"></span>
10
+ <span class="absolute inset-x-3 bottom-3 text-white">
11
+ <span class="block text-lg font-semibold leading-tight"><%= title %></span>
12
+ <span class="block text-xs text-white/80"><%= detail %></span>
13
+ </span>
14
+ </a>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::CarouselPreview < ViewComponent::Preview
4
+ # @label Playground
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|
9
+ UI::GalleryPreview.photos.cycle.first(count.to_i).each_with_index do |(title, src), index|
10
+ carousel.with_item do
11
+ tag.a(href: "#", class: "group block space-y-2 rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary") do
12
+ image_tag(src, alt: "", class: "aspect-square w-full rounded-lg object-cover") +
13
+ tag.span("#{title} #{index + 1}", class: "block text-sm font-medium group-hover:underline")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ # @label Highlights
21
+ def highlights; render_with_template; end
22
+ end
@@ -0,0 +1,19 @@
1
+ <%# precision: 0 drops the cents, and show_data: false leaves the table to
2
+ screen readers. The donut stacks over its legend because the card is
3
+ narrow, whatever the window's width. %>
4
+ <div class="grid max-w-3xl gap-4 sm:grid-cols-2">
5
+ <%= render(UI::Card.new) do |card| %>
6
+ <% card.with_header { |header| header.with_title { "Revenue by plan" } } %>
7
+ <% card.with_content do %>
8
+ <%= render(UI::Chart.new(type: :donut, label: "Monthly revenue by plan", format: :currency, precision: 0, show_data: false, height: 200,
9
+ labels: %w[Starter Team Business], series: [ { name: "Revenue", data: [ 1_284, 6_912, 11_520 ] } ])) %>
10
+ <% end %>
11
+ <% end %>
12
+ <%= render(UI::Card.new) do |card| %>
13
+ <% card.with_header { |header| header.with_title { "Monthly revenue" } } %>
14
+ <% card.with_content do %>
15
+ <%= render(UI::Chart.new(type: :line, label: "Monthly revenue", format: :currency, precision: 0, show_data: false, height: 200,
16
+ labels: %w[Jun Jul Aug Sep Oct Nov], series: [ { name: "Revenue", data: [ 14_210, 15_020, 15_880, 16_940, 18_305, 19_716 ] } ])) %>
17
+ <% end %>
18
+ <% end %>
19
+ </div>
@@ -10,7 +10,9 @@ class UI::ChartPreview < ViewComponent::Preview
10
10
  # @param stacked toggle
11
11
  # @param series_count number { min: 1, max: 5 }
12
12
  # @param format select { choices: [number, currency, percent] }
13
- def playground(type: :bar, stacked: false, series_count: 2, format: :number)
13
+ # @param precision number { min: 0, max: 2 }
14
+ # @param show_data toggle
15
+ def playground(type: :bar, stacked: false, series_count: 2, format: :number, precision: nil, show_data: true)
14
16
  names = %w[North South East West Online]
15
17
  # A pie or donut is one series, a slice per label, five at most.
16
18
  circular = %w[pie donut].include?(type.to_s)
@@ -20,6 +22,7 @@ class UI::ChartPreview < ViewComponent::Preview
20
22
  { name: name, data: [ 120, 140, 135, 160, 172, 158 ].first(points).map { |v| v - (i * 18) + ((i * 7) % 11) } }
21
23
  end
22
24
  render(UI::Chart.new(type: type.to_sym, stacked: stacked, format: format.to_sym, label: "Orders by region",
25
+ precision: precision.presence&.to_i, show_data: show_data,
23
26
  labels: MONTHS.first(points), series: series, class: "max-w-2xl"))
24
27
  end
25
28
 
@@ -43,4 +46,7 @@ class UI::ChartPreview < ViewComponent::Preview
43
46
 
44
47
  # @label Donut, with Its Total
45
48
  def donut; render_with_template; end
49
+
50
+ # @label Whole Dollars, in a Narrow Card
51
+ def whole_dollars; render_with_template; end
46
52
  end
@@ -1,9 +1,8 @@
1
1
  <form class="space-y-4 border rounded-md p-6 max-w-sm" action="#" method="post">
2
- <fieldset class="space-y-3">
3
- <legend class="text-sm font-medium mb-2">Notification preferences</legend>
2
+ <%= render(UI::Fieldset.new(legend: "Notification preferences")) do %>
4
3
  <%= render(UI::Checkbox.new(name: "prefs[email]", checked: true, label: "Email notifications")) %>
5
4
  <%= render(UI::Checkbox.new(name: "prefs[push]", label: "Push notifications")) %>
6
5
  <%= render(UI::Checkbox.new(name: "prefs[sms]", disabled: true, label: "SMS (unavailable)")) %>
7
- </fieldset>
6
+ <% end %>
8
7
  <%= render(UI::Button.new(type: :submit)) { "Save preferences" } %>
9
8
  </form>
@@ -0,0 +1,18 @@
1
+ <%# Any controls can share a legend; disabled: turns them all off at once. %>
2
+ <div class="flex flex-col gap-8 max-w-md">
3
+ <%= render(UI::Fieldset.new(legend: "Shipping address", hint: "Where we send your order.")) do %>
4
+ <div class="grid gap-4 sm:grid-cols-2">
5
+ <div class="sm:col-span-2"><%= render(UI::Input.new(name: "address[line1]", label: "Street")) %></div>
6
+ <%= render(UI::Input.new(name: "address[city]", label: "City")) %>
7
+ <%= render(UI::Input.new(name: "address[postcode]", label: "Postcode")) %>
8
+ </div>
9
+ <% end %>
10
+
11
+ <%= render(UI::Fieldset.new(legend: "Billing address", hint: "Same as shipping, so there's nothing to fill in.", disabled: true)) do %>
12
+ <div class="grid gap-4 sm:grid-cols-2">
13
+ <div class="sm:col-span-2"><%= render(UI::Input.new(name: "billing[line1]", label: "Street")) %></div>
14
+ <%= render(UI::Input.new(name: "billing[city]", label: "City")) %>
15
+ <%= render(UI::Input.new(name: "billing[postcode]", label: "Postcode")) %>
16
+ </div>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,14 @@
1
+ <%# RadioGroup and ToggleGroup take legend:, hint: and error: and render through UI::Fieldset themselves. %>
2
+ <div class="flex flex-col gap-8 max-w-sm">
3
+ <%= render(UI::RadioGroup.new(name: "plan", value: "pro", legend: "Plan", hint: "You can change it any time.", required: true)) do |rg| %>
4
+ <% rg.with_item(value: "free", label: "Free") %>
5
+ <% rg.with_item(value: "pro", label: "Pro — $9/mo") %>
6
+ <% rg.with_item(value: "team", label: "Team — $29/mo") %>
7
+ <% end %>
8
+
9
+ <%= render(UI::ToggleGroup.new(name: "layout", value: "grid", legend: "Layout", hint: "How results are shown.")) do |group| %>
10
+ <% group.with_item(value: "list", label: "List") %>
11
+ <% group.with_item(value: "grid", label: "Grid") %>
12
+ <% group.with_item(value: "board", label: "Board") %>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,22 @@
1
+ <%# In an app, @workspace comes back from a failed save. Bound groups show its errors on their own. %>
2
+ <% workspace = Struct.new(:plan, :layout, :channels) do
3
+ include ActiveModel::Validations
4
+ def self.model_name = ActiveModel::Name.new(self, nil, "Workspace")
5
+ validates :plan, :layout, :channels, presence: true
6
+ end.new(nil, nil, []).tap(&:validate) %>
7
+ <%= form_with(model: workspace, url: "#", class: "flex flex-col gap-8 max-w-sm") do |f| %>
8
+ <%= render(UI::RadioGroup.new(form: f, field: :plan, legend: "Plan")) do |rg| %>
9
+ <% rg.with_item(value: "free", label: "Free") %>
10
+ <% rg.with_item(value: "pro", label: "Pro — $9/mo") %>
11
+ <% end %>
12
+
13
+ <%= render(UI::ToggleGroup.new(form: f, field: :layout, legend: "Layout")) do |group| %>
14
+ <% group.with_item(value: "list", label: "List") %>
15
+ <% group.with_item(value: "grid", label: "Grid") %>
16
+ <% end %>
17
+
18
+ <%= render(UI::Fieldset.new(form: f, field: :channels, legend: "Notify me by")) do %>
19
+ <%= render(UI::Checkbox.new(name: "workspace[channels][]", value: "email", label: "Email")) %>
20
+ <%= render(UI::Checkbox.new(name: "workspace[channels][]", value: "push", label: "Push notifications")) %>
21
+ <% end %>
22
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <%= render(UI::Fieldset.new(legend: legend, hint: hint, error: error, required: required, disabled: disabled, class: "max-w-sm")) do %>
2
+ <%= render(UI::Checkbox.new(name: "notify[email]", checked: true, label: "Email")) %>
3
+ <%= render(UI::Checkbox.new(name: "notify[push]", label: "Push notifications")) %>
4
+ <%= render(UI::Checkbox.new(name: "notify[sms]", label: "Text message")) %>
5
+ <% end %>
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::FieldsetPreview < ViewComponent::Preview
4
+ # @label Playground
5
+ # @param legend text
6
+ # @param hint text
7
+ # @param error text
8
+ # @param required toggle
9
+ # @param disabled toggle
10
+ def playground(legend: "Notifications", hint: "Where we tell you about replies and mentions.",
11
+ error: "", required: false, disabled: false)
12
+ render_with_template(locals: { legend: legend, hint: hint.presence, error: error.presence,
13
+ required: required, disabled: disabled })
14
+ end
15
+
16
+ # @label Radio and toggle groups
17
+ def groups; render_with_template; end
18
+
19
+ # @label A block of fields
20
+ def block_of_fields; render_with_template; end
21
+
22
+ # @label Errors from the model
23
+ def model_errors; render_with_template; end
24
+ end
@@ -0,0 +1,25 @@
1
+ <%# strip: false: the page shows the photos its own way, and each tile opens
2
+ the overlay at that photo. Info opens a panel of details beside it, and
3
+ each photo's actions sit in the top bar. %>
4
+ <%= render(UI::Gallery.new(strip: false, label: "Recent photos", class: "max-w-xl")) do |gallery| %>
5
+ <% photos = UI::GalleryPreview.photos %>
6
+ <% photos.each_with_index do |(title, src), index| %>
7
+ <% gallery.with_image(src: src, alt: title) do |image| %>
8
+ <% image.with_info do %>
9
+ <h2 class="text-base font-semibold"><%= title %></h2>
10
+ <dl class="mt-4 grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm">
11
+ <dt class="text-muted-foreground">Taken</dt><dd><%= (Date.new(2026, 11, 14) - index * 3).to_fs(:long) %></dd>
12
+ <dt class="text-muted-foreground">Size</dt><dd>1600 × 1600</dd>
13
+ </dl>
14
+ <% end %>
15
+ <% image.with_action do %>
16
+ <%= render(UI::Button.new(variant: :ghost, size: :icon, class: UI::Gallery::OVERLAY_BUTTON, aria: { label: "Favourite #{title}", pressed: "false" })) do %><%= render(UI::Icon.new(name: "star", size: :sm)) %><% end %>
17
+ <% end %>
18
+ <% end %>
19
+ <% end %>
20
+ <div class="grid grid-cols-3 gap-1">
21
+ <% photos.each_with_index do |(title, src), index| %>
22
+ <%= gallery.trigger(index, class: "aspect-square rounded-md") do %><%= image_tag src, alt: "", class: "size-full object-cover transition-transform duration-200 group-hover/trigger:scale-105" %><% end %>
23
+ <% end %>
24
+ </div>
25
+ <% end %>
@@ -42,4 +42,7 @@ class UI::GalleryPreview < ViewComponent::Preview
42
42
 
43
43
  # @label One Image
44
44
  def single; render_with_template; end
45
+
46
+ # @label Opened From a Grid, With Info
47
+ def grid; render_with_template; end
45
48
  end
@@ -0,0 +1,24 @@
1
+ <%# The list scrolls in its own box here, so the scrubber names it with
2
+ `for:`; on a page that scrolls, leave `for:` out. Each month's heading is
3
+ a mark, years are labelled, and a busy month takes more of the rail. %>
4
+ <% months = (0...18).map { |i| Date.new(2026, 11, 1) << i } %>
5
+ <div class="relative flex h-[32rem] max-w-2xl overflow-hidden rounded-lg border">
6
+ <div id="scrubber-demo-list" class="min-w-0 flex-1 overflow-y-auto">
7
+ <div class="space-y-6 p-4">
8
+ <% months.each_with_index do |month, i| %>
9
+ <section>
10
+ <h3 id="month-<%= month.strftime('%Y-%m') %>" class="sticky top-0 bg-background/95 py-1 text-sm font-medium"><%= month.strftime("%B %Y") %></h3>
11
+ <div class="grid grid-cols-6 gap-1">
12
+ <% ((i * 7) % 11 + 3).times do |n| %><div class="aspect-square rounded-sm bg-muted"></div><% end %>
13
+ </div>
14
+ </section>
15
+ <% end %>
16
+ </div>
17
+ </div>
18
+ <%= render(UI::Scrubber.new(label: "Jump to a month", for: "scrubber-demo-list", class: "shrink-0")) do |scrubber| %>
19
+ <% months.each do |month| %>
20
+ <% scrubber.with_mark(href: "#month-#{month.strftime('%Y-%m')}", label: month.strftime("%B %Y"),
21
+ major: (month.year.to_s if month == months.find { |m| m.year == month.year })) %>
22
+ <% end %>
23
+ <% end %>
24
+ </div>
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::ScrubberPreview < ViewComponent::Preview
4
+ # @label Beside a Scrolling List
5
+ def default; render_with_template; end
6
+ end
@@ -0,0 +1,16 @@
1
+ <%# Any list can be chosen from: give its boxes data-selection="item". Here
2
+ each box shows on hover, and stays once anything is chosen. %>
3
+ <div id="photo-grid" class="group/photos grid max-w-xl grid-cols-3 gap-1 pb-20">
4
+ <% UI::GalleryPreview.photos.cycle.first(9).each_with_index do |(title, src), index| %>
5
+ <label class="group/photo relative block aspect-square cursor-pointer overflow-hidden rounded-md has-[:checked]:ring-4 has-[:checked]:ring-primary has-[:checked]:ring-inset">
6
+ <img src="<%= src %>" alt="" class="size-full object-cover transition-transform group-has-[:checked]/photo:scale-90">
7
+ <span class="absolute start-2 top-2 opacity-0 transition-opacity group-hover/photo:opacity-100 group-data-[selecting]/photos:opacity-100 has-[:checked]:opacity-100 has-[:focus-visible]:opacity-100">
8
+ <%= render(UI::SelectionBar.checkbox(:item, name: "photos[]", value: index, label: "Select #{title} #{index + 1}")) %>
9
+ </span>
10
+ </label>
11
+ <% end %>
12
+ </div>
13
+ <%= render(UI::SelectionBar.new(for: "photo-grid", placement: :floating, label: "Selected photos", class: "absolute")) do |bar| %>
14
+ <% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, class: "rounded-full")) { "Add to album" } %><% end %>
15
+ <% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, class: "rounded-full")) { "Delete" } %><% end %>
16
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <%# Each row has a box, and the header one chooses them all. The bar above
2
+ counts them and holds what to do with them; Shift-click chooses a run, and
3
+ Escape clears. The boxes belong to the "bulk" form, so the buttons post
4
+ them. %>
5
+ <%= form_tag "#", id: "bulk" %></form>
6
+ <div id="customers" class="max-w-2xl">
7
+ <%= render(UI::SelectionBar.new(for: "customers", label: "Selected customers", class: "rounded-t-md border")) do |bar| %>
8
+ <% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, type: :submit, form: "bulk")) { "Export" } %><% end %>
9
+ <% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, type: :submit, form: "bulk", class: "text-destructive")) { "Cancel plans" } %><% end %>
10
+ <% end %>
11
+ <%= render(UI::Table.new(selection: "ids[]", form: "bulk")) do |table| %>
12
+ <% table.with_head do |head| %>
13
+ <% head.with_column { "Customer" } %>
14
+ <% head.with_column { "Plan" } %>
15
+ <% head.with_column(align: :end) { "Seats" } %>
16
+ <% end %>
17
+ <% [ [ 1, "Aditi Rao", "Business", 24 ], [ 2, "Arjun Nair", "Team", 8 ], [ 3, "Chitra Menon", "Starter", 1 ],
18
+ [ 4, "Dev Patel", "Team", 12 ], [ 5, "Esha Iyer", "Business", 31 ] ].each do |id, name, plan, seats| %>
19
+ <% table.with_row(value: id, label: name) do |row| %>
20
+ <% row.with_cell(class: "font-medium") { name } %>
21
+ <% row.with_cell { plan } %>
22
+ <% row.with_cell(align: :end, class: "tabular-nums") { seats.to_s } %>
23
+ <% end %>
24
+ <% end %>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::SelectionBarPreview < ViewComponent::Preview
4
+ # @label Over a Table
5
+ def table; render_with_template; end
6
+
7
+ # @label Floating, Over a Grid of Photos
8
+ def floating; render_with_template; end
9
+ end
@@ -6,7 +6,7 @@
6
6
 
7
7
  Locals:
8
8
  sidebar_id: id on the <aside>; the trigger points aria-controls at it
9
- collapsible: :none or :icon
9
+ collapsible: :icon, :offcanvas or :none
10
10
  state: :expanded or :collapsed
11
11
  groups: [{ label:, items: [{ icon:, text:, active:, icon_class: }] }]
12
12
  brand: captured markup for the sidebar header (optional)
@@ -14,8 +14,8 @@
14
14
  main: captured markup for the content area
15
15
  %>
16
16
  <% sidebar_id = local_assigns.fetch(:sidebar_id, "preview-sidebar") %>
17
- <% collapsible = local_assigns.fetch(:collapsible, :none) %>
18
- <% state = local_assigns.fetch(:state, :expanded) %>
17
+ <% collapsible = local_assigns.fetch(:collapsible, :icon) %>
18
+ <% state = local_assigns.fetch(:state, nil) %>
19
19
  <% groups = local_assigns.fetch(:groups, []) %>
20
20
  <% title = local_assigns.fetch(:title, "Dashboard") %>
21
21
 
@@ -24,7 +24,8 @@
24
24
  escaping to the browser viewport. Without it the sidebar renders outside
25
25
  the preview box. %>
26
26
  <div class="relative h-[600px] overflow-hidden rounded-lg border transform-gpu">
27
- <%= render(UI::Sidebar::Wrapper.new(min_height: :full)) do %>
27
+ <%# A height for the wrapper, so the sidebar fits the frame rather than the window. %>
28
+ <%= render(UI::Sidebar::Wrapper.new(min_height: :none, class: "h-full overflow-y-auto")) do %>
28
29
  <%= render(UI::Sidebar.new(id: sidebar_id, collapsible: collapsible, state: state)) do |sidebar| %>
29
30
  <% if local_assigns[:brand].present? %>
30
31
  <% sidebar.with_sidebar_header { local_assigns[:brand] } %>
@@ -0,0 +1,52 @@
1
+ <%# shape: :pill gives taller links, the current one filled in end to end. A
2
+ sub-menu opens under its link from the arrow beside it, and starts open
3
+ when one of its links is the current page. The footer stays at the bottom
4
+ of the frame, because the wrapper has a height. On a phone the trigger
5
+ opens the sidebar as a drawer over the page. %>
6
+ <div class="relative h-[600px] overflow-hidden rounded-lg border transform-gpu">
7
+ <%= render(UI::Sidebar::Wrapper.new(min_height: :none, class: "h-full overflow-y-auto")) do %>
8
+ <%= render(UI::Sidebar.new(id: "preview-sidebar-pill", collapsible: :icon)) do |sidebar| %>
9
+ <% sidebar.with_sidebar_header do %>
10
+ <div class="flex h-10 items-center gap-2 px-2 font-semibold"><%= render(UI::Icon.new(name: "image", size: :sm)) %><span class="group-data-[collapsible=icon]:hidden">Photos</span></div>
11
+ <% end %>
12
+ <% sidebar.with_sidebar_content do |content| %>
13
+ <% content.with_sidebar_group do |group| %>
14
+ <% group.with_menu do |menu| %>
15
+ <% menu.with_menu_item do |item| %>
16
+ <% item.with_menu_button("#", active: true, shape: :pill) do %><%= render(UI::Icon.new(name: "image")) %><span>Photos</span><% end %>
17
+ <% end %>
18
+ <% menu.with_menu_item do |item| %>
19
+ <% item.with_menu_button("#", shape: :pill) do %><%= render(UI::Icon.new(name: "star")) %><span>Favourites</span><% end %>
20
+ <% end %>
21
+ <% menu.with_menu_item(open: true) do |item| %>
22
+ <% item.with_menu_button("#", shape: :pill) do %><%= render(UI::Icon.new(name: "book-open")) %><span>Albums</span><% end %>
23
+ <% item.with_sub_menu(name: "Albums") do |sub| %>
24
+ <% %w[Coast\ walk Garden City\ at\ night].each do |album| %>
25
+ <% sub.with_item("#") { album } %>
26
+ <% end %>
27
+ <% end %>
28
+ <% end %>
29
+ <% menu.with_menu_item do |item| %>
30
+ <% item.with_menu_button("#", shape: :pill) do %><%= render(UI::Icon.new(name: "trash-2")) %><span>Bin</span><% end %>
31
+ <% end %>
32
+ <% end %>
33
+ <% end %>
34
+ <% end %>
35
+ <% sidebar.with_sidebar_footer do %>
36
+ <div class="space-y-2 px-2 pb-2 group-data-[collapsible=icon]:hidden">
37
+ <%= render(UI::Progress.new(value: 62, label: "Storage")) %>
38
+ <p class="text-xs text-muted-foreground">62 GB of 100 GB used</p>
39
+ </div>
40
+ <% end %>
41
+ <% end %>
42
+ <%= render(UI::Sidebar::Inset.new) do %>
43
+ <header class="flex h-14 shrink-0 items-center gap-2 border-b px-4">
44
+ <%= render(UI::Sidebar::Trigger.new(sidebar_id: "preview-sidebar-pill")) %>
45
+ <span class="text-sm font-medium">Photos</span>
46
+ </header>
47
+ <div class="grid grid-cols-3 gap-1 p-4 sm:grid-cols-4">
48
+ <% 16.times do %><div class="aspect-square rounded-sm bg-muted"></div><% end %>
49
+ </div>
50
+ <% end %>
51
+ <% end %>
52
+ </div>
@@ -12,4 +12,7 @@ class UI::SidebarPreview < ViewComponent::Preview
12
12
 
13
13
  # @label Collapsible
14
14
  def collapsible; render_with_template; end
15
+
16
+ # @label Pill Links, Sub-menus and a Storage Meter
17
+ def pill_links; render_with_template; end
15
18
  end
@@ -0,0 +1,26 @@
1
+ <%# Each row has a box, and the header one chooses them all. The bar above
2
+ counts them and holds what to do with them; Shift-click chooses a run, and
3
+ Escape clears. The boxes belong to the "bulk" form, so the buttons post
4
+ them. %>
5
+ <%= form_tag "#", id: "bulk" %></form>
6
+ <div id="customers" class="max-w-2xl">
7
+ <%= render(UI::SelectionBar.new(for: "customers", label: "Selected customers", class: "rounded-t-md border")) do |bar| %>
8
+ <% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, type: :submit, form: "bulk")) { "Export" } %><% end %>
9
+ <% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, type: :submit, form: "bulk", class: "text-destructive")) { "Cancel plans" } %><% end %>
10
+ <% end %>
11
+ <%= render(UI::Table.new(selection: "ids[]", form: "bulk")) do |table| %>
12
+ <% table.with_head do |head| %>
13
+ <% head.with_column { "Customer" } %>
14
+ <% head.with_column { "Plan" } %>
15
+ <% head.with_column(align: :end) { "Seats" } %>
16
+ <% end %>
17
+ <% [ [ 1, "Aditi Rao", "Business", 24 ], [ 2, "Arjun Nair", "Team", 8 ], [ 3, "Chitra Menon", "Starter", 1 ],
18
+ [ 4, "Dev Patel", "Team", 12 ], [ 5, "Esha Iyer", "Business", 31 ] ].each do |id, name, plan, seats| %>
19
+ <% table.with_row(value: id, label: name) do |row| %>
20
+ <% row.with_cell(class: "font-medium") { name } %>
21
+ <% row.with_cell { plan } %>
22
+ <% row.with_cell(align: :end, class: "tabular-nums") { seats.to_s } %>
23
+ <% end %>
24
+ <% end %>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,20 @@
1
+ <%# Sorting is the server's job: each header links to the list sorted by it,
2
+ and says which way it's sorted now. Here it's sorted by seats, most first;
3
+ in an app, `sort` and `dir` come from params. %>
4
+ <% sort, dir = "seats", "desc" %>
5
+ <% rows = [ [ "Aditi Rao", 24 ], [ "Arjun Nair", 8 ], [ "Chitra Menon", 1 ], [ "Dev Patel", 12 ] ] %>
6
+ <% rows = rows.sort_by { |name, seats| sort == "customer" ? name : seats } %>
7
+ <% rows.reverse! if dir == "desc" %>
8
+ <% link = ->(column) { "?sort=#{column}&dir=#{sort == column && dir == 'asc' ? 'desc' : 'asc'}" } %>
9
+ <%= render(UI::Table.new(class: "max-w-lg")) do |table| %>
10
+ <% table.with_head do |head| %>
11
+ <% head.with_column(sort_href: link.("customer"), sorted: (dir if sort == "customer")) { "Customer" } %>
12
+ <% head.with_column(sort_href: link.("seats"), sorted: (dir if sort == "seats"), align: :end) { "Seats" } %>
13
+ <% end %>
14
+ <% rows.each do |name, seats| %>
15
+ <% table.with_row do |row| %>
16
+ <% row.with_cell { name } %>
17
+ <% row.with_cell(align: :end, class: "tabular-nums") { seats.to_s } %>
18
+ <% end %>
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%# The rows scroll in their own box, under the header. %>
2
+ <%= render(UI::Table.new(sticky_header: true, max_height: "16rem", class: "max-w-lg")) do |table| %>
3
+ <% table.with_head do |head| %>
4
+ <% head.with_column { "Invoice" } %>
5
+ <% head.with_column(align: :end) { "Amount" } %>
6
+ <% end %>
7
+ <% 20.times do |i| %>
8
+ <% table.with_row do |row| %>
9
+ <% row.with_cell { "INV-#{1040 + i}" } %>
10
+ <% row.with_cell(align: :end, class: "tabular-nums") { "$#{(i * 37 % 90 + 10) * 10}.00" } %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
@@ -9,4 +9,13 @@ class UI::TablePreview < ViewComponent::Preview
9
9
 
10
10
  # @label With Caption And Selection
11
11
  def with_caption; render_with_template; end
12
+
13
+ # @label Sortable Columns
14
+ def sortable; render_with_template; end
15
+
16
+ # @label Rows to Select, With a Selection Bar
17
+ def selectable; render_with_template; end
18
+
19
+ # @label Sticky Header
20
+ def sticky_header; render_with_template; end
12
21
  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