velvetkit 0.4.1 → 0.5.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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +143 -2
  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/card/action.html.erb +1 -0
  9. data/registry/app/components/ui/card/action.rb +14 -0
  10. data/registry/app/components/ui/card/content.html.erb +1 -1
  11. data/registry/app/components/ui/card/content.rb +4 -2
  12. data/registry/app/components/ui/card/description.html.erb +1 -1
  13. data/registry/app/components/ui/card/description.rb +4 -2
  14. data/registry/app/components/ui/card/footer.html.erb +1 -1
  15. data/registry/app/components/ui/card/footer.rb +4 -2
  16. data/registry/app/components/ui/card/header.html.erb +1 -1
  17. data/registry/app/components/ui/card/header.rb +9 -2
  18. data/registry/app/components/ui/card/title.html.erb +1 -1
  19. data/registry/app/components/ui/card/title.rb +4 -2
  20. data/registry/app/components/ui/card.html.erb +1 -1
  21. data/registry/app/components/ui/card.rb +49 -3
  22. data/registry/app/components/ui/carousel.html.erb +7 -0
  23. data/registry/app/components/ui/carousel.rb +60 -0
  24. data/registry/app/components/ui/chart.html.erb +3 -3
  25. data/registry/app/components/ui/chart.rb +18 -10
  26. data/registry/app/components/ui/checkbox.html.erb +6 -0
  27. data/registry/app/components/ui/checkbox.rb +11 -4
  28. data/registry/app/components/ui/fieldset.html.erb +6 -0
  29. data/registry/app/components/ui/fieldset.rb +76 -0
  30. data/registry/app/components/ui/gallery/image.rb +14 -1
  31. data/registry/app/components/ui/gallery.html.erb +32 -3
  32. data/registry/app/components/ui/gallery.rb +46 -7
  33. data/registry/app/components/ui/link.rb +1 -1
  34. data/registry/app/components/ui/menu/item.rb +1 -1
  35. data/registry/app/components/ui/radio_group/item.html.erb +1 -1
  36. data/registry/app/components/ui/radio_group/item.rb +5 -1
  37. data/registry/app/components/ui/radio_group.html.erb +1 -1
  38. data/registry/app/components/ui/radio_group.rb +42 -2
  39. data/registry/app/components/ui/scrubber.html.erb +18 -0
  40. data/registry/app/components/ui/scrubber.rb +62 -0
  41. data/registry/app/components/ui/select.html.erb +1 -1
  42. data/registry/app/components/ui/select.rb +16 -1
  43. data/registry/app/components/ui/selection_bar.html.erb +7 -0
  44. data/registry/app/components/ui/selection_bar.rb +75 -0
  45. data/registry/app/components/ui/sidebar/group_label.rb +1 -1
  46. data/registry/app/components/ui/sidebar/inset.rb +5 -2
  47. data/registry/app/components/ui/sidebar/menu_button.rb +24 -9
  48. data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -1
  49. data/registry/app/components/ui/sidebar/menu_item.rb +31 -5
  50. data/registry/app/components/ui/sidebar/menu_sub.rb +59 -0
  51. data/registry/app/components/ui/sidebar.html.erb +3 -3
  52. data/registry/app/components/ui/sidebar.rb +91 -13
  53. data/registry/app/components/ui/switch.rb +2 -2
  54. data/registry/app/components/ui/table/column.html.erb +1 -1
  55. data/registry/app/components/ui/table/column.rb +26 -2
  56. data/registry/app/components/ui/table/head.html.erb +1 -1
  57. data/registry/app/components/ui/table/head.rb +15 -2
  58. data/registry/app/components/ui/table/row.html.erb +1 -1
  59. data/registry/app/components/ui/table/row.rb +19 -5
  60. data/registry/app/components/ui/table.html.erb +2 -2
  61. data/registry/app/components/ui/table.rb +29 -4
  62. data/registry/app/components/ui/tabs/trigger.rb +1 -1
  63. data/registry/app/components/ui/toggle_group.html.erb +1 -1
  64. data/registry/app/components/ui/toggle_group.rb +26 -3
  65. data/registry/app/javascript/controllers/ui/carousel_controller.ts +63 -0
  66. data/registry/app/javascript/controllers/ui/file_field_controller.ts +1 -1
  67. data/registry/app/javascript/controllers/ui/gallery_controller.ts +52 -14
  68. data/registry/app/javascript/controllers/ui/scrubber_controller.ts +188 -0
  69. data/registry/app/javascript/controllers/ui/selection_bar_controller.ts +122 -0
  70. data/registry/app/javascript/controllers/ui/sidebar_controller.ts +102 -32
  71. data/registry/components.yml +12 -4
  72. data/registry/config/locales/velvetkit.en.yml +16 -0
  73. data/registry/icons/lucide/arrow-down.svg +16 -0
  74. data/registry/icons/lucide/arrow-up.svg +16 -0
  75. data/registry/icons/lucide/image.svg +17 -0
  76. data/registry/icons/lucide/star.svg +15 -0
  77. data/registry/icons/phosphor/arrow-down.svg +2 -0
  78. data/registry/icons/phosphor/arrow-up.svg +2 -0
  79. data/registry/icons/phosphor/image.svg +2 -0
  80. data/registry/icons/phosphor/star.svg +2 -0
  81. data/registry/icons/tabler/arrow-down.svg +18 -0
  82. data/registry/icons/tabler/arrow-up.svg +18 -0
  83. data/registry/icons/tabler/photo.svg +19 -0
  84. data/registry/icons/tabler/star.svg +16 -0
  85. data/registry/icons.yml +4 -0
  86. data/registry/test/components/previews/ui/card_preview/edge_to_edge.html.erb +19 -0
  87. data/registry/test/components/previews/ui/card_preview/image.html.erb +12 -0
  88. data/registry/test/components/previews/ui/card_preview/just_content.html.erb +10 -0
  89. data/registry/test/components/previews/ui/card_preview/open_bill.html.erb +18 -0
  90. data/registry/test/components/previews/ui/card_preview/playground.html.erb +17 -0
  91. data/registry/test/components/previews/ui/card_preview/settings_form.html.erb +15 -24
  92. data/registry/test/components/previews/ui/card_preview/sign_in.html.erb +23 -0
  93. data/registry/test/components/previews/ui/card_preview/small.html.erb +17 -0
  94. data/registry/test/components/previews/ui/card_preview/spacing.html.erb +13 -0
  95. data/registry/test/components/previews/ui/card_preview/stats.html.erb +11 -0
  96. data/registry/test/components/previews/ui/card_preview/team.html.erb +21 -0
  97. data/registry/test/components/previews/ui/card_preview.rb +42 -28
  98. data/registry/test/components/previews/ui/carousel_preview/highlights.html.erb +17 -0
  99. data/registry/test/components/previews/ui/carousel_preview.rb +22 -0
  100. data/registry/test/components/previews/ui/chart_preview/whole_dollars.html.erb +19 -0
  101. data/registry/test/components/previews/ui/chart_preview.rb +7 -1
  102. data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +2 -3
  103. data/registry/test/components/previews/ui/fieldset_preview/block_of_fields.html.erb +18 -0
  104. data/registry/test/components/previews/ui/fieldset_preview/groups.html.erb +14 -0
  105. data/registry/test/components/previews/ui/fieldset_preview/model_errors.html.erb +22 -0
  106. data/registry/test/components/previews/ui/fieldset_preview/playground.html.erb +5 -0
  107. data/registry/test/components/previews/ui/fieldset_preview.rb +24 -0
  108. data/registry/test/components/previews/ui/gallery_preview/grid.html.erb +25 -0
  109. data/registry/test/components/previews/ui/gallery_preview.rb +3 -0
  110. data/registry/test/components/previews/ui/scrubber_preview/default.html.erb +24 -0
  111. data/registry/test/components/previews/ui/scrubber_preview.rb +6 -0
  112. data/registry/test/components/previews/ui/selection_bar_preview/floating.html.erb +16 -0
  113. data/registry/test/components/previews/ui/selection_bar_preview/table.html.erb +26 -0
  114. data/registry/test/components/previews/ui/selection_bar_preview.rb +9 -0
  115. data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +5 -4
  116. data/registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb +52 -0
  117. data/registry/test/components/previews/ui/sidebar_preview.rb +3 -0
  118. data/registry/test/components/previews/ui/table_preview/selectable.html.erb +26 -0
  119. data/registry/test/components/previews/ui/table_preview/sortable.html.erb +20 -0
  120. data/registry/test/components/previews/ui/table_preview/sticky_header.html.erb +13 -0
  121. data/registry/test/components/previews/ui/table_preview.rb +9 -0
  122. data/registry/test/components/ui/button_test.rb +2 -2
  123. data/registry/test/components/ui/card/action_test.rb +19 -0
  124. data/registry/test/components/ui/card/content_test.rb +1 -11
  125. data/registry/test/components/ui/card/footer_test.rb +3 -2
  126. data/registry/test/components/ui/card/header_test.rb +3 -4
  127. data/registry/test/components/ui/card/title_test.rb +3 -4
  128. data/registry/test/components/ui/card_test.rb +63 -2
  129. data/registry/test/components/ui/carousel_test.rb +38 -0
  130. data/registry/test/components/ui/chart_test.rb +20 -0
  131. data/registry/test/components/ui/checkbox_test.rb +11 -2
  132. data/registry/test/components/ui/fieldset_test.rb +119 -0
  133. data/registry/test/components/ui/gallery_test.rb +40 -5
  134. data/registry/test/components/ui/link_test.rb +1 -1
  135. data/registry/test/components/ui/number_input_test.rb +1 -1
  136. data/registry/test/components/ui/radio_group_test.rb +106 -0
  137. data/registry/test/components/ui/scrubber_test.rb +43 -0
  138. data/registry/test/components/ui/select_test.rb +21 -0
  139. data/registry/test/components/ui/selection_bar_test.rb +46 -0
  140. data/registry/test/components/ui/sidebar/menu_button_test.rb +9 -0
  141. data/registry/test/components/ui/sidebar_test.rb +79 -1
  142. data/registry/test/components/ui/switch_test.rb +4 -4
  143. data/registry/test/components/ui/toggle_group_test.rb +45 -0
  144. metadata +60 -5
  145. data/registry/test/components/previews/ui/card_preview/complete.html.erb +0 -31
  146. data/registry/test/components/previews/ui/card_preview/default.html.erb +0 -7
  147. data/registry/test/components/previews/ui/card_preview/with_footer.html.erb +0 -13
  148. data/registry/test/components/previews/ui/card_preview/with_header.html.erb +0 -11
@@ -0,0 +1,11 @@
1
+ <div class="grid gap-4 sm:grid-cols-3">
2
+ <% [ [ "Active users", "8,249", "+12%" ], [ "Open tickets", "37", "-4" ], [ "Storage used", "64%", "+2%" ] ].each do |label, value, change| %>
3
+ <%= render(UI::Card.new) do |card| %>
4
+ <% card.with_header do |header| %>
5
+ <% header.with_description { label } %>
6
+ <% header.with_title(class: "text-2xl font-semibold tabular-nums") { value } %>
7
+ <% header.with_action { render(UI::Badge.new(variant: :outline, size: :sm)) { change } } %>
8
+ <% end %>
9
+ <% end %>
10
+ <% end %>
11
+ </div>
@@ -0,0 +1,21 @@
1
+ <%= render(UI::Card.new(class: "max-w-md")) do |card| %>
2
+ <% card.with_header do |header| %>
3
+ <% header.with_title { "Team" } %>
4
+ <% header.with_description { "Who can see this project." } %>
5
+ <% header.with_action { render(UI::Button.new(variant: :outline, size: :sm)) { "Invite" } } %>
6
+ <% end %>
7
+ <% card.with_content do %>
8
+ <ul class="grid gap-3">
9
+ <% [ [ "Maya Okafor", "maya@example.com", "Owner" ], [ "Tomás Reyes", "tomas@example.com", "Editor" ], [ "Li Wei", "li@example.com", "Viewer" ] ].each do |name, email, role| %>
10
+ <li class="flex items-center gap-3">
11
+ <%= render(UI::Avatar.new) { name.split.map(&:first).join } %>
12
+ <div class="min-w-0 flex-1">
13
+ <p class="truncate font-medium"><%= name %></p>
14
+ <p class="truncate text-muted-foreground"><%= email %></p>
15
+ </div>
16
+ <%= render(UI::Badge.new(variant: :secondary, size: :sm)) { role } %>
17
+ </li>
18
+ <% end %>
19
+ </ul>
20
+ <% end %>
21
+ <% end %>
@@ -1,44 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UI::CardPreview < ViewComponent::Preview
4
+ # Drawn here so the previews need no image files.
5
+ def self.photo(from, to)
6
+ svg = "<svg xmlns='http://www.w3.org/2000/svg' width='800' height='450'>" \
7
+ "<defs><linearGradient id='g' x2='1' y2='1'><stop stop-color='#{from}'/><stop offset='1' stop-color='#{to}'/>" \
8
+ "</linearGradient></defs><rect width='800' height='450' fill='url(#g)'/>" \
9
+ "<circle cx='620' cy='120' r='70' fill='#fff' fill-opacity='.35'/>" \
10
+ "<path d='M0 450 240 210l150 140 110-90 300 190z' fill='#000' fill-opacity='.18'/></svg>"
11
+ "data:image/svg+xml,#{ERB::Util.url_encode(svg)}"
12
+ end
13
+
4
14
  # @label Playground
5
15
  # @param title text
6
16
  # @param description text
17
+ # @param size select { choices: [default, sm] }
18
+ # @param spacing select { choices: ["", 3, 4, 5, 6, 8] } "Blank follows the size"
19
+ # @param show_action toggle
20
+ # @param show_image toggle
7
21
  # @param show_footer toggle
8
- def playground(title: "Create project", description: "Deploy your new project in one click.", show_footer: true)
9
- render(UI::Card.new) do |card|
10
- card.with_header do |header|
11
- header.with_title { title }
12
- header.with_description { description }
13
- end
14
- card.with_content do
15
- tag.p(class: "text-sm text-muted-foreground") { "Card body content goes here." }
16
- end
17
- if show_footer
18
- card.with_footer do
19
- tag.div(class: "flex gap-2") do
20
- safe_join([
21
- render(UI::Button.new(variant: :primary, size: :sm)) { "Deploy" },
22
- render(UI::Button.new(variant: :outline, size: :sm)) { "Cancel" }
23
- ])
24
- end
25
- end
26
- end
27
- end
22
+ def playground(title: "Create project", description: "Deploy your new project in one click.", size: :default,
23
+ spacing: "", show_action: true, show_image: false, show_footer: true)
24
+ render_with_template(locals: { title: title, description: description, size: size.to_sym,
25
+ spacing: spacing.presence&.to_i, show_action: show_action,
26
+ show_image: show_image, show_footer: show_footer })
28
27
  end
29
28
 
30
- # @label Default (content only)
31
- def default; render_with_template; end
29
+ # @label Sign In
30
+ def sign_in; render_with_template; end
32
31
 
33
- # @label With Header
34
- def with_header; render_with_template; end
32
+ # @label Small
33
+ def small; render_with_template; end
35
34
 
36
- # @label With Footer
37
- def with_footer; render_with_template; end
35
+ # @label With an Image
36
+ def image; render_with_template; end
38
37
 
39
- # @label Complete (all sections)
40
- def complete; render_with_template; end
38
+ # @label Stats, with a Badge as the Action
39
+ def stats; render_with_template; end
40
+
41
+ # @label Team, with a Button as the Action
42
+ def team; render_with_template; end
41
43
 
42
44
  # @label Settings Form
43
45
  def settings_form; render_with_template; end
46
+
47
+ # @label Spacing
48
+ def spacing; render_with_template; end
49
+
50
+ # @label Content to the Edges
51
+ def edge_to_edge; render_with_template; end
52
+
53
+ # @label Just Content
54
+ def just_content; render_with_template; end
55
+
56
+ # @label Open Bill at a Till
57
+ def open_bill; render_with_template; end
44
58
  end
@@ -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
@@ -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:ring-destructive"
27
- refute_includes classes, "focus:ring-primary"
26
+ assert_includes classes, "focus-visible:ring-destructive"
27
+ refute_includes classes, "focus-visible:ring-primary"
28
28
  end
29
29
 
30
30
  def test_renders_outline_variant