velvetkit 0.2.1 → 0.3.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 (292) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -7
  3. data/lib/generators/velvetkit/add/add_generator.rb +19 -0
  4. data/lib/generators/velvetkit/helpers.rb +29 -2
  5. data/lib/generators/velvetkit/icons/icons_generator.rb +71 -0
  6. data/lib/generators/velvetkit/install/install_generator.rb +9 -12
  7. data/lib/velvetkit/icons.rb +148 -0
  8. data/lib/velvetkit/registry.rb +5 -2
  9. data/lib/velvetkit/version.rb +1 -1
  10. data/lib/velvetkit.rb +1 -0
  11. data/registry/app/components/ui/alert.rb +1 -1
  12. data/registry/app/components/ui/confirm_dialog.html.erb +13 -0
  13. data/registry/app/components/ui/confirm_dialog.rb +55 -0
  14. data/registry/app/components/ui/empty_state.html.erb +20 -0
  15. data/registry/app/components/ui/empty_state.rb +46 -0
  16. data/registry/app/components/ui/icon.html.erb +1 -1
  17. data/registry/app/components/ui/icon.rb +80 -8
  18. data/registry/app/components/ui/password_input.html.erb +1 -1
  19. data/registry/app/components/ui/stepper/step.html.erb +27 -0
  20. data/registry/app/components/ui/stepper/step.rb +213 -0
  21. data/registry/app/components/ui/stepper.html.erb +19 -0
  22. data/registry/app/components/ui/stepper.rb +145 -0
  23. data/registry/app/components/ui/theme_toggle.rb +2 -4
  24. data/registry/app/components/ui/toast.rb +6 -6
  25. data/registry/app/components/ui/toggle_group/item.html.erb +1 -0
  26. data/registry/app/components/ui/toggle_group/item.rb +85 -0
  27. data/registry/app/components/ui/toggle_group.html.erb +1 -0
  28. data/registry/app/components/ui/toggle_group.rb +79 -0
  29. data/registry/app/javascript/controllers/ui/confirm_dialog_controller.ts +110 -0
  30. data/registry/app/javascript/controllers/ui/stepper_controller.ts +187 -0
  31. data/registry/components.yml +9 -2
  32. data/registry/config/locales/velvetkit.en.yml +11 -0
  33. data/registry/docs/agents.md +7 -4
  34. data/registry/icons/lucide/LICENSE +39 -0
  35. data/registry/icons/lucide/align-center.svg +17 -0
  36. data/registry/icons/lucide/align-left.svg +17 -0
  37. data/registry/icons/lucide/align-right.svg +17 -0
  38. data/registry/icons/lucide/arrow-left.svg +16 -0
  39. data/registry/icons/lucide/arrow-right.svg +16 -0
  40. data/registry/icons/lucide/badge-check.svg +16 -0
  41. data/registry/icons/lucide/bar-chart-3.svg +18 -0
  42. data/registry/icons/lucide/bell.svg +16 -0
  43. data/registry/icons/lucide/bold.svg +15 -0
  44. data/registry/icons/lucide/book-open.svg +16 -0
  45. data/registry/icons/lucide/calendar.svg +18 -0
  46. data/registry/icons/lucide/chart-column.svg +18 -0
  47. data/registry/icons/lucide/check.svg +15 -0
  48. data/registry/icons/lucide/chevron-down.svg +15 -0
  49. data/registry/icons/lucide/chevron-left.svg +15 -0
  50. data/registry/icons/lucide/chevron-right.svg +15 -0
  51. data/registry/icons/lucide/chevrons-up-down.svg +16 -0
  52. data/registry/icons/lucide/circle-alert.svg +17 -0
  53. data/registry/icons/lucide/circle-check.svg +16 -0
  54. data/registry/icons/lucide/cloud.svg +15 -0
  55. data/registry/icons/lucide/credit-card.svg +16 -0
  56. data/registry/icons/lucide/ellipsis-vertical.svg +17 -0
  57. data/registry/icons/lucide/ellipsis.svg +17 -0
  58. data/registry/icons/lucide/eye-off.svg +18 -0
  59. data/registry/icons/lucide/eye.svg +16 -0
  60. data/registry/icons/lucide/file-text.svg +19 -0
  61. data/registry/icons/lucide/folder-kanban.svg +18 -0
  62. data/registry/icons/lucide/git-branch.svg +18 -0
  63. data/registry/icons/lucide/globe.svg +17 -0
  64. data/registry/icons/lucide/graduation-cap.svg +17 -0
  65. data/registry/icons/lucide/grip-vertical.svg +20 -0
  66. data/registry/icons/lucide/home.svg +16 -0
  67. data/registry/icons/lucide/inbox.svg +16 -0
  68. data/registry/icons/lucide/info.svg +17 -0
  69. data/registry/icons/lucide/italic.svg +17 -0
  70. data/registry/icons/lucide/layout-dashboard.svg +18 -0
  71. data/registry/icons/lucide/layout-grid.svg +18 -0
  72. data/registry/icons/lucide/life-buoy.svg +20 -0
  73. data/registry/icons/lucide/list.svg +20 -0
  74. data/registry/icons/lucide/loader.svg +22 -0
  75. data/registry/icons/lucide/lock.svg +16 -0
  76. data/registry/icons/lucide/log-out.svg +17 -0
  77. data/registry/icons/lucide/mail.svg +16 -0
  78. data/registry/icons/lucide/menu.svg +17 -0
  79. data/registry/icons/lucide/message-circle.svg +15 -0
  80. data/registry/icons/lucide/monitor.svg +17 -0
  81. data/registry/icons/lucide/moon.svg +15 -0
  82. data/registry/icons/lucide/newspaper.svg +18 -0
  83. data/registry/icons/lucide/panel-left.svg +16 -0
  84. data/registry/icons/lucide/plus.svg +16 -0
  85. data/registry/icons/lucide/qr-code.svg +26 -0
  86. data/registry/icons/lucide/rocket.svg +18 -0
  87. data/registry/icons/lucide/rotate-cw.svg +16 -0
  88. data/registry/icons/lucide/search.svg +16 -0
  89. data/registry/icons/lucide/settings.svg +16 -0
  90. data/registry/icons/lucide/shield-check.svg +16 -0
  91. data/registry/icons/lucide/shield.svg +15 -0
  92. data/registry/icons/lucide/store.svg +17 -0
  93. data/registry/icons/lucide/sun.svg +23 -0
  94. data/registry/icons/lucide/trash-2.svg +19 -0
  95. data/registry/icons/lucide/underline.svg +16 -0
  96. data/registry/icons/lucide/upload.svg +17 -0
  97. data/registry/icons/lucide/user.svg +16 -0
  98. data/registry/icons/lucide/users.svg +18 -0
  99. data/registry/icons/lucide/workflow.svg +17 -0
  100. data/registry/icons/lucide/x.svg +16 -0
  101. data/registry/icons/phosphor/LICENSE +21 -0
  102. data/registry/icons/phosphor/arrow-clockwise.svg +2 -0
  103. data/registry/icons/phosphor/arrow-left.svg +2 -0
  104. data/registry/icons/phosphor/arrow-right.svg +2 -0
  105. data/registry/icons/phosphor/bell.svg +2 -0
  106. data/registry/icons/phosphor/book-open.svg +2 -0
  107. data/registry/icons/phosphor/calendar-blank.svg +2 -0
  108. data/registry/icons/phosphor/caret-down.svg +2 -0
  109. data/registry/icons/phosphor/caret-left.svg +2 -0
  110. data/registry/icons/phosphor/caret-right.svg +2 -0
  111. data/registry/icons/phosphor/caret-up-down.svg +2 -0
  112. data/registry/icons/phosphor/chart-bar.svg +2 -0
  113. data/registry/icons/phosphor/chat-circle.svg +2 -0
  114. data/registry/icons/phosphor/check-circle.svg +2 -0
  115. data/registry/icons/phosphor/check.svg +2 -0
  116. data/registry/icons/phosphor/cloud.svg +2 -0
  117. data/registry/icons/phosphor/credit-card.svg +2 -0
  118. data/registry/icons/phosphor/desktop.svg +2 -0
  119. data/registry/icons/phosphor/dots-six-vertical.svg +2 -0
  120. data/registry/icons/phosphor/dots-three-vertical.svg +2 -0
  121. data/registry/icons/phosphor/dots-three.svg +2 -0
  122. data/registry/icons/phosphor/envelope.svg +2 -0
  123. data/registry/icons/phosphor/eye-slash.svg +2 -0
  124. data/registry/icons/phosphor/eye.svg +2 -0
  125. data/registry/icons/phosphor/file-text.svg +2 -0
  126. data/registry/icons/phosphor/flow-arrow.svg +2 -0
  127. data/registry/icons/phosphor/gear.svg +2 -0
  128. data/registry/icons/phosphor/git-branch.svg +2 -0
  129. data/registry/icons/phosphor/globe.svg +2 -0
  130. data/registry/icons/phosphor/graduation-cap.svg +2 -0
  131. data/registry/icons/phosphor/grid-four.svg +2 -0
  132. data/registry/icons/phosphor/house.svg +2 -0
  133. data/registry/icons/phosphor/info.svg +2 -0
  134. data/registry/icons/phosphor/kanban.svg +2 -0
  135. data/registry/icons/phosphor/lifebuoy.svg +2 -0
  136. data/registry/icons/phosphor/list.svg +2 -0
  137. data/registry/icons/phosphor/lock.svg +2 -0
  138. data/registry/icons/phosphor/magnifying-glass.svg +2 -0
  139. data/registry/icons/phosphor/moon.svg +2 -0
  140. data/registry/icons/phosphor/newspaper.svg +2 -0
  141. data/registry/icons/phosphor/plus.svg +2 -0
  142. data/registry/icons/phosphor/qr-code.svg +2 -0
  143. data/registry/icons/phosphor/rocket.svg +2 -0
  144. data/registry/icons/phosphor/seal-check.svg +2 -0
  145. data/registry/icons/phosphor/shield-check.svg +2 -0
  146. data/registry/icons/phosphor/shield.svg +2 -0
  147. data/registry/icons/phosphor/sidebar.svg +2 -0
  148. data/registry/icons/phosphor/sign-out.svg +2 -0
  149. data/registry/icons/phosphor/spinner.svg +2 -0
  150. data/registry/icons/phosphor/squares-four.svg +2 -0
  151. data/registry/icons/phosphor/storefront.svg +2 -0
  152. data/registry/icons/phosphor/sun.svg +2 -0
  153. data/registry/icons/phosphor/text-align-center.svg +2 -0
  154. data/registry/icons/phosphor/text-align-left.svg +2 -0
  155. data/registry/icons/phosphor/text-align-right.svg +2 -0
  156. data/registry/icons/phosphor/text-b.svg +2 -0
  157. data/registry/icons/phosphor/text-italic.svg +2 -0
  158. data/registry/icons/phosphor/text-underline.svg +2 -0
  159. data/registry/icons/phosphor/trash.svg +2 -0
  160. data/registry/icons/phosphor/tray.svg +2 -0
  161. data/registry/icons/phosphor/upload-simple.svg +2 -0
  162. data/registry/icons/phosphor/user.svg +2 -0
  163. data/registry/icons/phosphor/users.svg +2 -0
  164. data/registry/icons/phosphor/warning-circle.svg +2 -0
  165. data/registry/icons/phosphor/x.svg +2 -0
  166. data/registry/icons/tabler/LICENSE +21 -0
  167. data/registry/icons/tabler/alert-circle.svg +18 -0
  168. data/registry/icons/tabler/align-center.svg +18 -0
  169. data/registry/icons/tabler/align-left.svg +18 -0
  170. data/registry/icons/tabler/align-right.svg +18 -0
  171. data/registry/icons/tabler/arrow-left.svg +18 -0
  172. data/registry/icons/tabler/arrow-right.svg +18 -0
  173. data/registry/icons/tabler/bell.svg +17 -0
  174. data/registry/icons/tabler/bold.svg +17 -0
  175. data/registry/icons/tabler/book.svg +20 -0
  176. data/registry/icons/tabler/building-store.svg +20 -0
  177. data/registry/icons/tabler/calendar.svg +21 -0
  178. data/registry/icons/tabler/chart-bar.svg +19 -0
  179. data/registry/icons/tabler/check.svg +16 -0
  180. data/registry/icons/tabler/chevron-down.svg +16 -0
  181. data/registry/icons/tabler/chevron-left.svg +16 -0
  182. data/registry/icons/tabler/chevron-right.svg +16 -0
  183. data/registry/icons/tabler/circle-check.svg +17 -0
  184. data/registry/icons/tabler/cloud.svg +16 -0
  185. data/registry/icons/tabler/credit-card.svg +19 -0
  186. data/registry/icons/tabler/device-desktop.svg +19 -0
  187. data/registry/icons/tabler/dots-vertical.svg +18 -0
  188. data/registry/icons/tabler/dots.svg +18 -0
  189. data/registry/icons/tabler/eye-off.svg +18 -0
  190. data/registry/icons/tabler/eye.svg +17 -0
  191. data/registry/icons/tabler/file-text.svg +20 -0
  192. data/registry/icons/tabler/git-branch.svg +21 -0
  193. data/registry/icons/tabler/grip-vertical.svg +21 -0
  194. data/registry/icons/tabler/home.svg +18 -0
  195. data/registry/icons/tabler/inbox.svg +17 -0
  196. data/registry/icons/tabler/info-circle.svg +18 -0
  197. data/registry/icons/tabler/italic.svg +18 -0
  198. data/registry/icons/tabler/layout-dashboard.svg +19 -0
  199. data/registry/icons/tabler/layout-grid.svg +19 -0
  200. data/registry/icons/tabler/layout-kanban.svg +19 -0
  201. data/registry/icons/tabler/layout-sidebar.svg +17 -0
  202. data/registry/icons/tabler/lifebuoy.svg +21 -0
  203. data/registry/icons/tabler/list.svg +21 -0
  204. data/registry/icons/tabler/loader.svg +23 -0
  205. data/registry/icons/tabler/lock.svg +18 -0
  206. data/registry/icons/tabler/logout.svg +18 -0
  207. data/registry/icons/tabler/mail.svg +17 -0
  208. data/registry/icons/tabler/menu-2.svg +18 -0
  209. data/registry/icons/tabler/message-circle.svg +16 -0
  210. data/registry/icons/tabler/moon.svg +16 -0
  211. data/registry/icons/tabler/news.svg +19 -0
  212. data/registry/icons/tabler/plus.svg +17 -0
  213. data/registry/icons/tabler/qrcode.svg +27 -0
  214. data/registry/icons/tabler/rocket.svg +18 -0
  215. data/registry/icons/tabler/rosette-discount-check.svg +17 -0
  216. data/registry/icons/tabler/rotate-clockwise.svg +16 -0
  217. data/registry/icons/tabler/school.svg +17 -0
  218. data/registry/icons/tabler/search.svg +17 -0
  219. data/registry/icons/tabler/selector.svg +17 -0
  220. data/registry/icons/tabler/settings.svg +17 -0
  221. data/registry/icons/tabler/shield-check.svg +17 -0
  222. data/registry/icons/tabler/shield.svg +16 -0
  223. data/registry/icons/tabler/sitemap.svg +20 -0
  224. data/registry/icons/tabler/sun.svg +17 -0
  225. data/registry/icons/tabler/trash.svg +20 -0
  226. data/registry/icons/tabler/underline.svg +17 -0
  227. data/registry/icons/tabler/upload.svg +18 -0
  228. data/registry/icons/tabler/user.svg +17 -0
  229. data/registry/icons/tabler/users.svg +19 -0
  230. data/registry/icons/tabler/world.svg +20 -0
  231. data/registry/icons/tabler/x.svg +17 -0
  232. data/registry/icons.yml +74 -0
  233. data/registry/test/components/previews/ui/confirm_dialog_preview/destructive.html.erb +7 -0
  234. data/registry/test/components/previews/ui/confirm_dialog_preview/in_form.html.erb +6 -0
  235. data/registry/test/components/previews/ui/confirm_dialog_preview/on_link.html.erb +5 -0
  236. data/registry/test/components/previews/ui/confirm_dialog_preview/plain.html.erb +3 -0
  237. data/registry/test/components/previews/ui/confirm_dialog_preview/with_description.html.erb +4 -0
  238. data/registry/test/components/previews/ui/confirm_dialog_preview.rb +20 -0
  239. data/registry/test/components/previews/ui/empty_state_preview/in_card.html.erb +7 -0
  240. data/registry/test/components/previews/ui/empty_state_preview/no_results.html.erb +3 -0
  241. data/registry/test/components/previews/ui/empty_state_preview/outline.html.erb +3 -0
  242. data/registry/test/components/previews/ui/empty_state_preview/with_actions.html.erb +4 -0
  243. data/registry/test/components/previews/ui/empty_state_preview/with_media.html.erb +8 -0
  244. data/registry/test/components/previews/ui/empty_state_preview.rb +26 -0
  245. data/registry/test/components/previews/ui/icon_preview/common.html.erb +19 -3
  246. data/registry/test/components/previews/ui/icon_preview/labelled.html.erb +4 -0
  247. data/registry/test/components/previews/ui/icon_preview/missing.html.erb +3 -0
  248. data/registry/test/components/previews/ui/icon_preview.rb +18 -3
  249. data/registry/test/components/previews/ui/input_group_preview/playground.html.erb +2 -2
  250. data/registry/test/components/previews/ui/input_group_preview.rb +3 -3
  251. data/registry/test/components/previews/ui/stepper_preview/approvals.html.erb +9 -0
  252. data/registry/test/components/previews/ui/stepper_preview/checklist.html.erb +12 -0
  253. data/registry/test/components/previews/ui/stepper_preview/dot_wizard.html.erb +41 -0
  254. data/registry/test/components/previews/ui/stepper_preview/failed_deploy.html.erb +13 -0
  255. data/registry/test/components/previews/ui/stepper_preview/inline.html.erb +31 -0
  256. data/registry/test/components/previews/ui/stepper_preview/onboarding.html.erb +12 -0
  257. data/registry/test/components/previews/ui/stepper_preview/order_tracking.html.erb +10 -0
  258. data/registry/test/components/previews/ui/stepper_preview/price_calculator.html.erb +14 -0
  259. data/registry/test/components/previews/ui/stepper_preview/server_driven.html.erb +20 -0
  260. data/registry/test/components/previews/ui/stepper_preview/sidebar.html.erb +43 -0
  261. data/registry/test/components/previews/ui/stepper_preview/wizard.html.erb +55 -0
  262. data/registry/test/components/previews/ui/stepper_preview.rb +57 -0
  263. data/registry/test/components/previews/ui/toggle_group_preview/icon_only.html.erb +5 -0
  264. data/registry/test/components/previews/ui/toggle_group_preview/in_form.html.erb +11 -0
  265. data/registry/test/components/previews/ui/toggle_group_preview/multiple.html.erb +5 -0
  266. data/registry/test/components/previews/ui/toggle_group_preview/outline.html.erb +5 -0
  267. data/registry/test/components/previews/ui/toggle_group_preview/sizes.html.erb +9 -0
  268. data/registry/test/components/previews/ui/toggle_group_preview/with_icons.html.erb +5 -0
  269. data/registry/test/components/previews/ui/toggle_group_preview.rb +36 -0
  270. data/registry/test/components/ui/accordion/trigger_test.rb +1 -1
  271. data/registry/test/components/ui/alert_test.rb +10 -10
  272. data/registry/test/components/ui/badge_test.rb +3 -3
  273. data/registry/test/components/ui/banner_test.rb +3 -3
  274. data/registry/test/components/ui/breadcrumb/ellipsis_test.rb +2 -2
  275. data/registry/test/components/ui/button_test.rb +17 -14
  276. data/registry/test/components/ui/button_to_test.rb +2 -2
  277. data/registry/test/components/ui/checkbox_test.rb +2 -2
  278. data/registry/test/components/ui/confirm_dialog_test.rb +68 -0
  279. data/registry/test/components/ui/empty_state_test.rb +87 -0
  280. data/registry/test/components/ui/icon_test.rb +60 -20
  281. data/registry/test/components/ui/input_group_test.rb +1 -1
  282. data/registry/test/components/ui/link_test.rb +3 -3
  283. data/registry/test/components/ui/navigation_menu_test.rb +2 -2
  284. data/registry/test/components/ui/session_tabs_test.rb +3 -3
  285. data/registry/test/components/ui/spinner_test.rb +9 -9
  286. data/registry/test/components/ui/stepper_test.rb +239 -0
  287. data/registry/test/components/ui/tabs/trigger_test.rb +2 -2
  288. data/registry/test/components/ui/theme_toggle_test.rb +6 -8
  289. data/registry/test/components/ui/toast_test.rb +11 -10
  290. data/registry/test/components/ui/toggle_group_test.rb +162 -0
  291. metadata +253 -2
  292. data/registry/app/javascript/velvetkit_icons.ts +0 -70
@@ -0,0 +1,14 @@
1
+ <%= render(UI::Card.new(class: "w-full max-w-3xl")) do |card| %>
2
+ <% card.with_header do |header| %>
3
+ <%= render(UI::Card::Title.new) { "Price calculator" } %>
4
+ <%= render(UI::Card::Description.new) { "All printing includes full colour on both sides." } %>
5
+ <% end %>
6
+ <% card.with_content do %>
7
+ <%= render(UI::Stepper.new(current: 3, label: "Price calculator")) do |stepper| %>
8
+ <% stepper.with_step(title: "Size and style") %>
9
+ <% stepper.with_step(title: "Paper type") %>
10
+ <% stepper.with_step(title: "Quantity") %>
11
+ <% stepper.with_step(title: "Packs") %>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <%# The server decides the step. Each panel is a form that posts to it: valid,
2
+ it redirects to the next step; invalid, it renders this again with
3
+ `status: :error` and the field's error, with a 422. Done steps link back.
4
+ While the form is sending, the step shows a spinner. %>
5
+ <div class="w-full max-w-2xl">
6
+ <%= render(UI::Stepper.new(current: 2, label: "Sign up")) do |stepper| %>
7
+ <% stepper.with_step(title: "Account", description: "ada@example.com", href: "#account") %>
8
+ <% stepper.with_step(title: "Workspace", description: "That address is taken", status: :error) do %>
9
+ <%= form_with url: "/demo/signup/workspace", method: :patch, class: "grid gap-4" do %>
10
+ <%= render(UI::Input.new(label: "Workspace URL", name: "workspace[slug]", value: "acme", required: true,
11
+ error: "acme.example.com is taken. Try acme-hq or acme-labs.")) %>
12
+ <div class="flex justify-end gap-2">
13
+ <%= render(UI::Button.new(type: :submit)) { "Continue" } %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
17
+ <% stepper.with_step(title: "Plan") %>
18
+ <% stepper.with_step(title: "Invite") %>
19
+ <% end %>
20
+ </div>
@@ -0,0 +1,43 @@
1
+ <%# `layout: :side`: the steps in a column beside the panels, for a longer
2
+ flow. The last button moves on to the completion instead of posting. %>
3
+ <div class="w-full max-w-4xl rounded-xl border bg-card p-6 sm:p-8">
4
+ <%= render(UI::Stepper.new(orientation: :vertical, layout: :side, label: "Book a speaker")) do |stepper| %>
5
+ <% stepper.with_step(title: "Format", description: "In person or remote") do %>
6
+ <h3 class="text-lg font-semibold">How will the speaker join?</h3>
7
+ <p class="mb-5 text-sm text-muted-foreground">Remote talks can still be watched together in the office.</p>
8
+ <%= render(UI::RadioGroup.new(name: "booking[format]", value: "remote")) do |group| %>
9
+ <% group.with_item(value: "in_person", label: "In person, at our office") %>
10
+ <% group.with_item(value: "remote", label: "Remote, with the team in the office") %>
11
+ <% group.with_item(value: "all_remote", label: "Remote, everyone from home") %>
12
+ <% end %>
13
+ <% end %>
14
+ <% stepper.with_step(title: "Talk", description: "Title and audience") do %>
15
+ <div class="grid gap-4">
16
+ <%= render(UI::Input.new(label: "Title", name: "booking[title]", required: true, placeholder: "Scaling Postgres without sharding")) %>
17
+ <%= render(UI::NativeSelect.new(label: "Audience", name: "booking[audience]", required: true, prompt: "Choose one",
18
+ options: [["Engineering", "engineering"], ["Whole company", "company"], ["Leadership", "leadership"]])) %>
19
+ </div>
20
+ <% end %>
21
+ <% stepper.with_step(title: "Date and time", description: "When it happens") do %>
22
+ <div class="grid gap-4 sm:grid-cols-2">
23
+ <%= render(UI::Input.new(type: :date, label: "Date", name: "booking[date]", required: true)) %>
24
+ <%= render(UI::Input.new(type: :time, label: "Start", name: "booking[time]", required: true, value: "16:00")) %>
25
+ </div>
26
+ <% end %>
27
+ <% stepper.with_step(title: "Speaker", description: "Who to invite") do %>
28
+ <div class="grid gap-4 sm:grid-cols-2">
29
+ <%= render(UI::Input.new(label: "Name", name: "booking[speaker]", required: true)) %>
30
+ <%= render(UI::Input.new(type: :email, label: "Email", name: "booking[email]", required: true)) %>
31
+ </div>
32
+ <% end %>
33
+ <% stepper.with_completion do %>
34
+ <%= render(UI::EmptyState.new(icon: "circle-check", title: "Request sent", description: "We've emailed the speaker. You'll hear back when they accept.", class: "md:p-6")) do %>
35
+ <%= render(UI::Button.new(variant: :outline, data: { action: "ui--stepper#reset" })) { "Book another" } %>
36
+ <% end %>
37
+ <% end %>
38
+ <div class="mt-8 flex items-center gap-2">
39
+ <%= render(UI::Button.new(variant: :ghost, hidden: true, data: { action: "ui--stepper#previous", "ui--stepper-target": "previous" })) { "Back" } %>
40
+ <%= render(UI::Button.new(class: "ml-auto", data: { action: "ui--stepper#next", "ui--stepper-target": "next" })) { "Continue" } %>
41
+ </div>
42
+ <% end %>
43
+ </div>
@@ -0,0 +1,55 @@
1
+ <%# One form, split into steps. Continue checks the fields on the current step
2
+ in the browser (required, pattern, type) and stays put, marking the step,
3
+ if one is wrong. Nothing is sent until "Create project". %>
4
+ <%= form_with url: "/demo/projects", class: "w-full max-w-3xl" do %>
5
+ <%= render(UI::Card.new) do |card| %>
6
+ <% card.with_content(class: "pt-6") do %>
7
+ <%= render(UI::Stepper.new(label: "Create a project")) do |stepper| %>
8
+ <% stepper.with_step(title: "Details", description: "Name and address") do %>
9
+ <div class="grid gap-4 sm:grid-cols-2">
10
+ <%= render(UI::Input.new(label: "Project name", name: "project[name]", required: true, placeholder: "Acme dashboard")) %>
11
+ <%# The address is the part after the slash, so the box shows the rest. %>
12
+ <%= render(UI::FormField.new(label: "Address", required: true, hint: "Lowercase letters, numbers and dashes")) do |field| %>
13
+ <%= render(UI::InputGroup.new) do |group| %>
14
+ <% group.with_addon(align: "inline-start") { "acme.app/" } %>
15
+ <% group.with_field(name: "project[slug]", required: true, pattern: "[a-z0-9]+(-[a-z0-9]+)*", placeholder: "dashboard",
16
+ title: "Lowercase letters, numbers and dashes, like sales-dashboard", autocapitalize: "none",
17
+ spellcheck: false, **field.control_attributes) %>
18
+ <% end %>
19
+ <% end %>
20
+ </div>
21
+ <% end %>
22
+ <% stepper.with_step(title: "Plan", description: "Pick what fits") do %>
23
+ <fieldset class="grid gap-3 sm:grid-cols-3">
24
+ <legend class="sr-only">Plan</legend>
25
+ <% [["hobby", "Hobby", "Free", "One member, 3 projects"],
26
+ ["team", "Team", "$20 a month", "Up to 10 members"],
27
+ ["business", "Business", "$80 a month", "Unlimited members, SSO"]].each do |value, name, price, detail| %>
28
+ <label class="relative flex cursor-pointer flex-col gap-1 rounded-lg border p-4 transition-colors hover:bg-accent/50 has-[:checked]:border-primary has-[:checked]:bg-primary/5 has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-ring/40">
29
+ <input type="radio" name="project[plan]" value="<%= value %>" required class="peer sr-only">
30
+ <span class="text-sm font-medium"><%= name %></span>
31
+ <span class="text-lg font-semibold"><%= price %></span>
32
+ <span class="text-sm text-muted-foreground"><%= detail %></span>
33
+ </label>
34
+ <% end %>
35
+ </fieldset>
36
+ <% end %>
37
+ <% stepper.with_step(title: "Team", description: "Invite people") do %>
38
+ <%= render(UI::Input.new(type: :email, label: "Email addresses", name: "project[invites]", multiple: true,
39
+ placeholder: "dev@acme.com, ops@acme.com", hint: "Optional. Separate them with commas.")) %>
40
+ <% end %>
41
+ <% stepper.with_step(title: "Review", description: "Check and create") do %>
42
+ <%= render(UI::Alert.new(variant: :info)) do |alert| %>
43
+ <% alert.with_title { "Almost there" } %>
44
+ <% alert.with_description { "You can rename the project, change its URL or plan, and invite more people later, from Settings." } %>
45
+ <% end %>
46
+ <% end %>
47
+ <div class="mt-8 flex items-center gap-2 border-t pt-6">
48
+ <%= render(UI::Button.new(variant: :outline, hidden: true, data: { action: "ui--stepper#previous", "ui--stepper-target": "previous" })) do |button| %><% button.with_leading_icon(name: "arrow-left") %>Back<% end %>
49
+ <%= render(UI::Button.new(class: "ml-auto", data: { action: "ui--stepper#next", "ui--stepper-target": "next" })) do |button| %>Continue<% button.with_trailing_icon(name: "arrow-right") %><% end %>
50
+ <%= render(UI::Button.new(type: :submit, class: "ml-auto", hidden: true, data: { "ui--stepper-target": "submit" })) { "Create project" } %>
51
+ </div>
52
+ <% end %>
53
+ <% end %>
54
+ <% end %>
55
+ <% end %>
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The wizards below post to /demo/ paths; the docs site stops those requests
4
+ # and shows a toast instead. The live demo further up the page checks each
5
+ # step on the server.
6
+ class UI::StepperPreview < ViewComponent::Preview
7
+ # @label Playground
8
+ # @param current number { min: 1, max: 5 }
9
+ # @param orientation select { choices: [horizontal, vertical] }
10
+ # @param variant select { choices: [default, dot] }
11
+ # @param align select { choices: [start, center] }
12
+ # @param connector toggle
13
+ # @param descriptions toggle
14
+ def playground(current: 2, orientation: :horizontal, variant: :default, align: :start, connector: true,
15
+ descriptions: true)
16
+ render(UI::Stepper.new(current: current.to_i, orientation: orientation.to_sym, variant: variant.to_sym,
17
+ align: align.to_sym, connector: connector)) do |stepper|
18
+ [ [ "Account", "Name and email" ], [ "Plan", "Pick what fits" ], [ "Payment", "Card details" ],
19
+ [ "Review", "Check and confirm" ] ].each do |title, description|
20
+ stepper.with_step(title: title, description: (description if descriptions))
21
+ end
22
+ end
23
+ end
24
+
25
+ # @label Horizontal
26
+ def price_calculator; render_with_template; end
27
+
28
+ # @label Centered, with Descriptions
29
+ def order_tracking; render_with_template; end
30
+
31
+ # @label Dots
32
+ def onboarding; render_with_template; end
33
+
34
+ # @label Vertical
35
+ def approvals; render_with_template; end
36
+
37
+ # @label With an Error
38
+ def failed_deploy; render_with_template; end
39
+
40
+ # @label Without Lines
41
+ def checklist; render_with_template; end
42
+
43
+ # @label Wizard, Checked in the Browser
44
+ def wizard; render_with_template; end
45
+
46
+ # @label Beside the Form
47
+ def sidebar; render_with_template; end
48
+
49
+ # @label Steps Inline
50
+ def inline; render_with_template; end
51
+
52
+ # @label Dots in a Card
53
+ def dot_wizard; render_with_template; end
54
+
55
+ # @label Server-Driven, with Links Back
56
+ def server_driven; render_with_template; end
57
+ end
@@ -0,0 +1,5 @@
1
+ <%= render(UI::ToggleGroup.new(name: "align", value: "left", variant: :outline, label: "Text alignment")) do |group| %>
2
+ <% group.with_item(value: "left", label: "Align left", icon: "align-left", icon_only: true) %>
3
+ <% group.with_item(value: "center", label: "Align center", icon: "align-center", icon_only: true) %>
4
+ <% group.with_item(value: "right", label: "Align right", icon: "align-right", icon_only: true) %>
5
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <form class="flex max-w-sm flex-col gap-4" action="#" onsubmit="event.preventDefault()">
2
+ <div class="flex flex-col gap-2">
3
+ <span id="visibility-label" class="text-sm font-medium">Visibility</span>
4
+ <%= render(UI::ToggleGroup.new(name: "project[visibility]", value: "team", required: true, variant: :outline, class: "w-full", aria: { labelledby: "visibility-label" })) do |group| %>
5
+ <% group.with_item(value: "private", label: "Private", class: "flex-1") %>
6
+ <% group.with_item(value: "team", label: "Team", class: "flex-1") %>
7
+ <% group.with_item(value: "public", label: "Public", class: "flex-1") %>
8
+ <% end %>
9
+ </div>
10
+ <%= render(UI::Button.new(type: :submit, class: "self-start")) { "Save" } %>
11
+ </form>
@@ -0,0 +1,5 @@
1
+ <%= render(UI::ToggleGroup.new(name: "styles", value: %w[bold], multiple: true, variant: :outline, label: "Text style")) do |group| %>
2
+ <% group.with_item(value: "bold", label: "Bold", icon: "bold", icon_only: true) %>
3
+ <% group.with_item(value: "italic", label: "Italic", icon: "italic", icon_only: true) %>
4
+ <% group.with_item(value: "underline", label: "Underline", icon: "underline", icon_only: true) %>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <%= render(UI::ToggleGroup.new(name: "billing", value: "monthly", variant: :outline, label: "Billing period")) do |group| %>
2
+ <% group.with_item(value: "monthly", label: "Monthly") %>
3
+ <% group.with_item(value: "yearly", label: "Yearly") %>
4
+ <% group.with_item(value: "lifetime", label: "Lifetime", disabled: true) %>
5
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <div class="flex flex-col items-start gap-4">
2
+ <% %i[sm default lg].each do |size| %>
3
+ <%= render(UI::ToggleGroup.new(name: "size-#{size}", value: "b", size: size, label: "#{size} size")) do |group| %>
4
+ <% group.with_item(value: "a", label: "Draft") %>
5
+ <% group.with_item(value: "b", label: "Published") %>
6
+ <% group.with_item(value: "c", label: "Archived") %>
7
+ <% end %>
8
+ <% end %>
9
+ </div>
@@ -0,0 +1,5 @@
1
+ <%= render(UI::ToggleGroup.new(name: "layout", value: "grid", label: "Layout")) do |group| %>
2
+ <% group.with_item(value: "list", label: "List", icon: "list") %>
3
+ <% group.with_item(value: "grid", label: "Grid", icon: "layout-grid") %>
4
+ <% group.with_item(value: "board", label: "Board", icon: "folder-kanban") %>
5
+ <% end %>
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UI::ToggleGroupPreview < ViewComponent::Preview
4
+ # @label Playground
5
+ # @param variant select { choices: [default, outline] }
6
+ # @param size select { choices: [sm, default, lg] }
7
+ # @param multiple toggle
8
+ # @param disabled toggle
9
+ def playground(variant: :default, size: :default, multiple: false, disabled: false)
10
+ render(UI::ToggleGroup.new(name: "period", value: "month", label: "Period", variant: variant.to_sym,
11
+ size: size.to_sym, multiple: multiple, disabled: disabled)) do |group|
12
+ group.with_item(value: "day", label: "Day")
13
+ group.with_item(value: "week", label: "Week")
14
+ group.with_item(value: "month", label: "Month")
15
+ group.with_item(value: "year", label: "Year")
16
+ end
17
+ end
18
+
19
+ # @label Outline
20
+ def outline; render_with_template; end
21
+
22
+ # @label With Icons
23
+ def with_icons; render_with_template; end
24
+
25
+ # @label Icon Only
26
+ def icon_only; render_with_template; end
27
+
28
+ # @label Multiple
29
+ def multiple; render_with_template; end
30
+
31
+ # @label Sizes
32
+ def sizes; render_with_template; end
33
+
34
+ # @label In a Form
35
+ def in_form; render_with_template; end
36
+ end
@@ -27,7 +27,7 @@ class UI::Accordion::TriggerTest < ViewComponent::TestCase
27
27
 
28
28
  def test_renders_chevron_icon
29
29
  render_inline(UI::Accordion::Trigger.new) { "x" }
30
- assert_selector "button i[data-lucide='chevron-right']"
30
+ assert_selector "button svg[data-icon='chevron-right']"
31
31
  end
32
32
 
33
33
  def test_aria_controls_when_content_id_provided
@@ -54,23 +54,23 @@ class UI::AlertTest < ViewComponent::TestCase
54
54
 
55
55
  def test_default_variant_renders_default_icon_info
56
56
  render_inline(UI::Alert.new) { "Default" }
57
- icons = page.all("i", visible: :all)
57
+ icons = page.all("svg", visible: :all)
58
58
  assert_equal 1, icons.size
59
- assert_equal "info", icons.first["data-lucide"]
59
+ assert icons.first.matches_css?("[data-icon='info']")
60
60
  end
61
61
 
62
62
  def test_destructive_variant_renders_circle_alert_icon
63
63
  render_inline(UI::Alert.new(variant: :destructive)) { "Error" }
64
- icons = page.all("i", visible: :all)
64
+ icons = page.all("svg", visible: :all)
65
65
  assert_equal 1, icons.size
66
- assert_equal "circle-alert", icons.first["data-lucide"]
66
+ assert icons.first.matches_css?("[data-icon='circle-alert']")
67
67
  end
68
68
 
69
69
  def test_success_variant_renders_circle_check_icon
70
70
  render_inline(UI::Alert.new(variant: :success)) { "Success" }
71
- icons = page.all("i", visible: :all)
71
+ icons = page.all("svg", visible: :all)
72
72
  assert_equal 1, icons.size
73
- assert_equal "circle-check", icons.first["data-lucide"]
73
+ assert icons.first.matches_css?("[data-icon='circle-check']")
74
74
  end
75
75
 
76
76
  def test_custom_icon_slot_overrides_default
@@ -78,9 +78,9 @@ class UI::AlertTest < ViewComponent::TestCase
78
78
  alert.with_icon(name: "badge-check")
79
79
  "Custom icon"
80
80
  end
81
- icons = page.all("i", visible: :all)
81
+ icons = page.all("svg", visible: :all)
82
82
  assert_equal 1, icons.size
83
- assert_equal "badge-check", icons.first["data-lucide"]
83
+ assert icons.first.matches_css?("[data-icon='badge-check']")
84
84
  end
85
85
 
86
86
  def test_title_slot_renders
@@ -150,9 +150,9 @@ class UI::AlertTest < ViewComponent::TestCase
150
150
 
151
151
  def test_close_button_renders_x_icon
152
152
  render_inline(UI::Alert.new(dismissible: true)) { "Dismissible" }
153
- icons = page.all("[role='alert'] button i")
153
+ icons = page.all("[role='alert'] button svg")
154
154
  assert_equal 1, icons.size
155
- assert_equal "x", icons.first["data-lucide"]
155
+ assert icons.first.matches_css?("[data-icon='x']")
156
156
  end
157
157
 
158
158
  def test_close_button_has_dismiss_action
@@ -73,9 +73,9 @@ class UI::BadgeTest < ViewComponent::TestCase
73
73
  "Verified"
74
74
  end
75
75
  span = page.find("span")
76
- icon = span.find("i", visible: :all)
77
- assert_equal "badge-check", icon["data-lucide"]
78
- assert_match(/<i[^>]*data-lucide="badge-check".*Verified/m, span.native.to_html)
76
+ icon = span.find("svg", visible: :all)
77
+ assert icon.matches_css?("[data-icon='badge-check']")
78
+ assert_match(/<svg[^>]*data-icon="badge-check".*Verified/m, span.native.to_html)
79
79
  end
80
80
 
81
81
  def test_user_class_override_via_tailwind_merge
@@ -78,13 +78,13 @@ class UI::BannerTest < ViewComponent::TestCase
78
78
  render_inline(UI::Banner.new) do |banner|
79
79
  banner.with_leading_icon(name: "info")
80
80
  end
81
- assert_selector "[data-slot='banner'] i[data-lucide='info']"
81
+ assert_selector "[data-slot='banner'] svg[data-icon='info']"
82
82
  end
83
83
 
84
84
  def test_dismiss_button_uses_button_component
85
85
  render_inline(UI::Banner.new) { "Message" }
86
86
  assert_selector "button[aria-label='Dismiss']"
87
- assert_selector "button[aria-label='Dismiss'] i[data-lucide='x']"
87
+ assert_selector "button[aria-label='Dismiss'] svg[data-icon='x']"
88
88
  end
89
89
 
90
90
  def test_dismiss_button_wired_to_controller
@@ -95,7 +95,7 @@ class UI::BannerTest < ViewComponent::TestCase
95
95
 
96
96
  def test_custom_dismiss_icon
97
97
  render_inline(UI::Banner.new(dismiss_icon: "check")) { "x" }
98
- assert_selector "button[aria-label='Dismiss'] i[data-lucide='check']"
98
+ assert_selector "button[aria-label='Dismiss'] svg[data-icon='check']"
99
99
  end
100
100
 
101
101
  def test_dismissible_false_hides_close
@@ -13,7 +13,7 @@ class UI::Breadcrumb::EllipsisTest < ViewComponent::TestCase
13
13
 
14
14
  def test_renders_ellipsis_icon
15
15
  render_inline(UI::Breadcrumb::Ellipsis.new)
16
- assert_selector "li i[data-lucide='ellipsis']"
16
+ assert_selector "li svg[data-icon='ellipsis']"
17
17
  end
18
18
 
19
19
  def test_static_ellipsis_is_fully_decorative
@@ -34,7 +34,7 @@ class UI::Breadcrumb::EllipsisTest < ViewComponent::TestCase
34
34
  "<a href=\"/docs\">Documentation</a>".html_safe
35
35
  end
36
36
  assert_selector "li button[aria-label='More breadcrumb pages']"
37
- assert_selector "li i[data-lucide='ellipsis']"
37
+ assert_selector "li svg[data-icon='ellipsis']"
38
38
  end
39
39
 
40
40
  def test_popover_content_includes_provided_html
@@ -179,11 +179,11 @@ class UI::ButtonTest < ViewComponent::TestCase
179
179
  "Continue"
180
180
  end
181
181
  btn = page.find("button")
182
- icons = btn.all("i", visible: :all)
182
+ icons = btn.all("svg", visible: :all)
183
183
  assert_equal 1, icons.size
184
- assert_equal "arrow-right", icons.first["data-lucide"]
184
+ assert icons.first.matches_css?("[data-icon='arrow-right']")
185
185
  # icon precedes text in DOM order
186
- assert_match(/<i[^>]*data-lucide="arrow-right".*Continue/m, btn.native.to_html)
186
+ assert_match(/<svg[^>]*data-icon="arrow-right".*Continue/m, btn.native.to_html)
187
187
  end
188
188
 
189
189
  def test_trailing_icon_renders_after_content
@@ -192,7 +192,7 @@ class UI::ButtonTest < ViewComponent::TestCase
192
192
  "Next"
193
193
  end
194
194
  btn = page.find("button")
195
- assert_match(/Next.*<i[^>]*data-lucide="arrow-right"/m, btn.native.to_html)
195
+ assert_match(/Next.*<svg[^>]*data-icon="arrow-right"/m, btn.native.to_html)
196
196
  end
197
197
 
198
198
  def test_both_leading_and_trailing_icons
@@ -202,8 +202,10 @@ class UI::ButtonTest < ViewComponent::TestCase
202
202
  "Sign in"
203
203
  end
204
204
  btn = page.find("button")
205
- icons = btn.all("i", visible: :all).map { |i| i["data-lucide"] }
206
- assert_equal [ "lock", "arrow-right" ], icons
205
+ icons = btn.all("svg", visible: :all)
206
+ assert_equal 2, icons.size
207
+ assert icons[0].matches_css?("[data-icon='lock']")
208
+ assert icons[1].matches_css?("[data-icon='arrow-right']")
207
209
  end
208
210
 
209
211
  def test_icon_only_button_renders_icon_without_text_slot
@@ -214,7 +216,7 @@ class UI::ButtonTest < ViewComponent::TestCase
214
216
  classes = btn[:class].split
215
217
  assert_includes classes, "h-9"
216
218
  assert_includes classes, "w-9"
217
- assert_equal "menu", btn.find("i", visible: :all)["data-lucide"]
219
+ assert btn.find("svg", visible: :all).matches_css?("[data-icon='menu']")
218
220
  end
219
221
 
220
222
  def test_loading_replaces_leading_icon_with_animated_loader
@@ -223,10 +225,10 @@ class UI::ButtonTest < ViewComponent::TestCase
223
225
  "Saving"
224
226
  end
225
227
  btn = page.find("button")
226
- icons = btn.all("i", visible: :all)
228
+ icons = btn.all("svg", visible: :all)
227
229
  assert_equal 1, icons.size
228
230
  loader = icons.first
229
- assert_equal "loader", loader["data-lucide"]
231
+ assert loader.matches_css?("[data-icon='loader']")
230
232
  assert_includes loader[:class].split, "animate-spin"
231
233
  end
232
234
 
@@ -237,8 +239,9 @@ class UI::ButtonTest < ViewComponent::TestCase
237
239
  end
238
240
  btn = page.find("button")
239
241
  # only the loader is rendered; trailing icon dropped
240
- icons = btn.all("i", visible: :all).map { |i| i["data-lucide"] }
241
- assert_equal [ "loader" ], icons
242
+ icons = btn.all("svg", visible: :all)
243
+ assert_equal 1, icons.size
244
+ assert icons[0].matches_css?("[data-icon='loader']")
242
245
  end
243
246
 
244
247
  def test_icon_slot_auto_sizes_to_button_size_sm
@@ -246,7 +249,7 @@ class UI::ButtonTest < ViewComponent::TestCase
246
249
  btn.with_leading_icon(name: "lock")
247
250
  "Auth"
248
251
  end
249
- icon = page.find("button i", visible: :all)
252
+ icon = page.find("button svg", visible: :all)
250
253
  classes = icon[:class].split
251
254
  assert_includes classes, "w-3"
252
255
  assert_includes classes, "h-3"
@@ -257,7 +260,7 @@ class UI::ButtonTest < ViewComponent::TestCase
257
260
  btn.with_leading_icon(name: "lock")
258
261
  "Auth"
259
262
  end
260
- icon = page.find("button i", visible: :all)
263
+ icon = page.find("button svg", visible: :all)
261
264
  classes = icon[:class].split
262
265
  assert_includes classes, "w-5"
263
266
  assert_includes classes, "h-5"
@@ -268,7 +271,7 @@ class UI::ButtonTest < ViewComponent::TestCase
268
271
  btn.with_leading_icon(name: "lock", size: :xl)
269
272
  "Big"
270
273
  end
271
- icon = page.find("button i", visible: :all)
274
+ icon = page.find("button svg", visible: :all)
272
275
  classes = icon[:class].split
273
276
  assert_includes classes, "w-8"
274
277
  assert_includes classes, "h-8"
@@ -36,7 +36,7 @@ class UI::ButtonToTest < ViewComponent::TestCase
36
36
  button.with_leading_icon(name: "mail")
37
37
  "Continue"
38
38
  end
39
- assert_selector "button i[data-lucide='mail']"
39
+ assert_selector "button svg[data-icon='mail']"
40
40
  end
41
41
 
42
42
  def test_renders_trailing_icon_slot
@@ -44,7 +44,7 @@ class UI::ButtonToTest < ViewComponent::TestCase
44
44
  button.with_trailing_icon(name: "arrow-right")
45
45
  "Continue"
46
46
  end
47
- assert_selector "button i[data-lucide='arrow-right']"
47
+ assert_selector "button svg[data-icon='arrow-right']"
48
48
  end
49
49
 
50
50
  def test_loading_state_shows_spinner_and_disables
@@ -86,8 +86,8 @@ class UI::CheckboxTest < ViewComponent::TestCase
86
86
  def test_check_icon_inside_overlay
87
87
  render_inline(UI::Checkbox.new(name: "test"))
88
88
  overlay = page.find("span.pointer-events-none")
89
- icon = overlay.find("i", visible: :all)
90
- assert_equal "check", icon["data-lucide"]
89
+ icon = overlay.find("svg", visible: :all)
90
+ assert icon.matches_css?("[data-icon='check']")
91
91
  end
92
92
 
93
93
  def test_user_class_override_via_tailwind_merge
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class UI::ConfirmDialogTest < ViewComponent::TestCase
6
+ def setup_fixtures(*); end
7
+ def teardown_fixtures(*); end
8
+
9
+ def dialog = page.find("dialog", visible: :all)
10
+
11
+ def test_a_native_dialog_wired_to_the_controller
12
+ render_inline(UI::ConfirmDialog.new)
13
+ assert_equal "ui--confirm-dialog", dialog["data-controller"]
14
+ assert_equal "confirm-dialog", dialog["data-slot"]
15
+ assert_equal "ui-confirm-dialog", dialog[:id]
16
+ end
17
+
18
+ def test_labelled_by_its_title_and_described_by_its_description
19
+ render_inline(UI::ConfirmDialog.new)
20
+ id = dialog[:id]
21
+ assert_equal "#{id}-title", dialog["aria-labelledby"]
22
+ assert_equal "#{id}-description", dialog["aria-describedby"]
23
+ assert_selector "h2##{id}-title[data-ui--confirm-dialog-target='title']", visible: :all
24
+ assert_selector "p##{id}-description[hidden]", visible: :all
25
+ end
26
+
27
+ def test_buttons_submit_a_dialog_form_with_their_answer
28
+ render_inline(UI::ConfirmDialog.new)
29
+ assert_selector "dialog form[method='dialog']", visible: :all
30
+ assert_selector "button[type='submit'][value='cancel'][autofocus]", text: "Cancel", visible: :all
31
+ assert_selector "button[type='submit'][value='confirm'][data-ui--confirm-dialog-target='confirm']",
32
+ text: "Confirm", visible: :all
33
+ end
34
+
35
+ def test_a_hidden_destructive_confirm_for_the_controller_to_swap_in
36
+ render_inline(UI::ConfirmDialog.new)
37
+ button = page.find("[data-ui--confirm-dialog-target='destructive']", visible: :all)
38
+ assert button[:hidden]
39
+ assert_includes button[:class].split, "bg-destructive"
40
+ end
41
+
42
+ def test_labels_are_passed_to_the_controller
43
+ render_inline(UI::ConfirmDialog.new(confirm_label: "Yes", cancel_label: "No"))
44
+ assert_equal "Yes", dialog["data-ui--confirm-dialog-confirm-label-value"]
45
+ assert_equal "No", dialog["data-ui--confirm-dialog-cancel-label-value"]
46
+ assert_selector "button[value='cancel']", text: "No", visible: :all
47
+ end
48
+
49
+ def test_labels_come_from_i18n
50
+ # Built from the dotted scope so the namespaced run stores it under its own scope.
51
+ labels = "ui.confirm_dialog".split(".").reverse.inject({ confirm: "OK", cancel: "Never mind" }) { |h, k| { k => h } }
52
+ I18n.backend.store_translations(:en, labels)
53
+ render_inline(UI::ConfirmDialog.new)
54
+ assert_equal "OK", dialog["data-ui--confirm-dialog-confirm-label-value"]
55
+ assert_equal "Never mind", dialog["data-ui--confirm-dialog-cancel-label-value"]
56
+ ensure
57
+ I18n.reload!
58
+ end
59
+
60
+ def test_id_class_and_attrs
61
+ render_inline(UI::ConfirmDialog.new(id: "confirm", class: "p-8", data: { test_id: "c" }))
62
+ assert_equal "confirm", dialog[:id]
63
+ assert_equal "confirm-title", dialog["aria-labelledby"]
64
+ assert_equal "c", dialog["data-test-id"]
65
+ assert_includes dialog[:class].split, "p-8"
66
+ refute_includes dialog[:class].split, "p-4"
67
+ end
68
+ end