velvetkit 0.2.2 → 0.4.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 (458) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +80 -0
  3. data/README.md +30 -8
  4. data/lib/generators/velvetkit/add/add_generator.rb +77 -0
  5. data/lib/generators/velvetkit/helpers.rb +29 -2
  6. data/lib/generators/velvetkit/icons/icons_generator.rb +71 -0
  7. data/lib/generators/velvetkit/install/install_generator.rb +9 -12
  8. data/lib/velvetkit/icons.rb +148 -0
  9. data/lib/velvetkit/registry.rb +5 -2
  10. data/lib/velvetkit/version.rb +4 -1
  11. data/lib/velvetkit.rb +8 -0
  12. data/registry/app/assets/tailwind/velvetkit.css +90 -155
  13. data/registry/app/components/ui/alert.rb +1 -1
  14. data/registry/app/components/ui/chart.html.erb +47 -0
  15. data/registry/app/components/ui/chart.rb +177 -0
  16. data/registry/app/components/ui/command/group.rb +27 -0
  17. data/registry/app/components/ui/command/item.rb +64 -0
  18. data/registry/app/components/ui/command.html.erb +41 -0
  19. data/registry/app/components/ui/command.rb +122 -0
  20. data/registry/app/components/ui/confirm_dialog.html.erb +13 -0
  21. data/registry/app/components/ui/confirm_dialog.rb +55 -0
  22. data/registry/app/components/ui/date_picker.html.erb +58 -64
  23. data/registry/app/components/ui/date_picker.rb +199 -75
  24. data/registry/app/components/ui/empty_state.html.erb +20 -0
  25. data/registry/app/components/ui/empty_state.rb +46 -0
  26. data/registry/app/components/ui/file_field.html.erb +14 -4
  27. data/registry/app/components/ui/file_field.rb +179 -28
  28. data/registry/app/components/ui/gallery/image.rb +20 -0
  29. data/registry/app/components/ui/gallery.html.erb +52 -0
  30. data/registry/app/components/ui/gallery.rb +164 -0
  31. data/registry/app/components/ui/icon.html.erb +1 -1
  32. data/registry/app/components/ui/icon.rb +80 -8
  33. data/registry/app/components/ui/kbd.html.erb +27 -0
  34. data/registry/app/components/ui/kbd.rb +134 -0
  35. data/registry/app/components/ui/number_input.html.erb +11 -0
  36. data/registry/app/components/ui/number_input.rb +103 -0
  37. data/registry/app/components/ui/password_input.html.erb +1 -1
  38. data/registry/app/components/ui/progress/segment.rb +25 -0
  39. data/registry/app/components/ui/progress.html.erb +25 -0
  40. data/registry/app/components/ui/progress.rb +182 -0
  41. data/registry/app/components/ui/select.html.erb +24 -5
  42. data/registry/app/components/ui/select.rb +44 -5
  43. data/registry/app/components/ui/stepper/step.html.erb +27 -0
  44. data/registry/app/components/ui/stepper/step.rb +213 -0
  45. data/registry/app/components/ui/stepper.html.erb +19 -0
  46. data/registry/app/components/ui/stepper.rb +145 -0
  47. data/registry/app/components/ui/theme_toggle.rb +2 -4
  48. data/registry/app/components/ui/timeline/item.html.erb +21 -0
  49. data/registry/app/components/ui/timeline/item.rb +145 -0
  50. data/registry/app/components/ui/timeline.html.erb +1 -0
  51. data/registry/app/components/ui/timeline.rb +42 -0
  52. data/registry/app/components/ui/toast.rb +6 -6
  53. data/registry/app/components/ui/toggle_group/item.html.erb +1 -0
  54. data/registry/app/components/ui/toggle_group/item.rb +85 -0
  55. data/registry/app/components/ui/toggle_group.html.erb +1 -0
  56. data/registry/app/components/ui/toggle_group.rb +79 -0
  57. data/registry/app/javascript/chart_js.ts +37 -0
  58. data/registry/app/javascript/controllers/ui/_internal/date_format.ts +74 -0
  59. data/registry/app/javascript/controllers/ui/_internal/shortcut.ts +80 -0
  60. data/registry/app/javascript/controllers/ui/chart_controller.ts +585 -0
  61. data/registry/app/javascript/controllers/ui/command_controller.ts +454 -0
  62. data/registry/app/javascript/controllers/ui/confirm_dialog_controller.ts +110 -0
  63. data/registry/app/javascript/controllers/ui/date_picker_controller.ts +247 -82
  64. data/registry/app/javascript/controllers/ui/file_field_controller.ts +288 -16
  65. data/registry/app/javascript/controllers/ui/gallery_controller.ts +568 -0
  66. data/registry/app/javascript/controllers/ui/kbd_controller.ts +60 -0
  67. data/registry/app/javascript/controllers/ui/number_input_controller.ts +111 -0
  68. data/registry/app/javascript/controllers/ui/progress_controller.ts +87 -0
  69. data/registry/app/javascript/controllers/ui/select_controller.ts +198 -8
  70. data/registry/app/javascript/controllers/ui/stepper_controller.ts +187 -0
  71. data/registry/app/javascript/vanilla_calendar.ts +15 -0
  72. data/registry/components.yml +28 -5
  73. data/registry/config/locales/velvetkit.en.yml +84 -0
  74. data/registry/docs/agents.md +7 -4
  75. data/registry/icons/lucide/LICENSE +39 -0
  76. data/registry/icons/lucide/align-center.svg +17 -0
  77. data/registry/icons/lucide/align-left.svg +17 -0
  78. data/registry/icons/lucide/align-right.svg +17 -0
  79. data/registry/icons/lucide/arrow-left.svg +16 -0
  80. data/registry/icons/lucide/arrow-right.svg +16 -0
  81. data/registry/icons/lucide/badge-check.svg +16 -0
  82. data/registry/icons/lucide/bar-chart-3.svg +18 -0
  83. data/registry/icons/lucide/bell.svg +16 -0
  84. data/registry/icons/lucide/bold.svg +15 -0
  85. data/registry/icons/lucide/book-open.svg +16 -0
  86. data/registry/icons/lucide/calendar.svg +18 -0
  87. data/registry/icons/lucide/chart-column.svg +18 -0
  88. data/registry/icons/lucide/check.svg +15 -0
  89. data/registry/icons/lucide/chevron-down.svg +15 -0
  90. data/registry/icons/lucide/chevron-left.svg +15 -0
  91. data/registry/icons/lucide/chevron-right.svg +15 -0
  92. data/registry/icons/lucide/chevrons-up-down.svg +16 -0
  93. data/registry/icons/lucide/circle-alert.svg +17 -0
  94. data/registry/icons/lucide/circle-check.svg +16 -0
  95. data/registry/icons/lucide/cloud.svg +15 -0
  96. data/registry/icons/lucide/credit-card.svg +16 -0
  97. data/registry/icons/lucide/download.svg +17 -0
  98. data/registry/icons/lucide/ellipsis-vertical.svg +17 -0
  99. data/registry/icons/lucide/ellipsis.svg +17 -0
  100. data/registry/icons/lucide/eye-off.svg +18 -0
  101. data/registry/icons/lucide/eye.svg +16 -0
  102. data/registry/icons/lucide/file-plus.svg +18 -0
  103. data/registry/icons/lucide/file-text.svg +19 -0
  104. data/registry/icons/lucide/file.svg +16 -0
  105. data/registry/icons/lucide/folder-kanban.svg +18 -0
  106. data/registry/icons/lucide/folder.svg +15 -0
  107. data/registry/icons/lucide/git-branch.svg +18 -0
  108. data/registry/icons/lucide/globe.svg +17 -0
  109. data/registry/icons/lucide/graduation-cap.svg +17 -0
  110. data/registry/icons/lucide/grip-vertical.svg +20 -0
  111. data/registry/icons/lucide/home.svg +16 -0
  112. data/registry/icons/lucide/inbox.svg +16 -0
  113. data/registry/icons/lucide/info.svg +17 -0
  114. data/registry/icons/lucide/italic.svg +17 -0
  115. data/registry/icons/lucide/keyboard.svg +23 -0
  116. data/registry/icons/lucide/layout-dashboard.svg +18 -0
  117. data/registry/icons/lucide/layout-grid.svg +18 -0
  118. data/registry/icons/lucide/life-buoy.svg +20 -0
  119. data/registry/icons/lucide/list.svg +20 -0
  120. data/registry/icons/lucide/loader.svg +22 -0
  121. data/registry/icons/lucide/lock.svg +16 -0
  122. data/registry/icons/lucide/log-out.svg +17 -0
  123. data/registry/icons/lucide/mail.svg +16 -0
  124. data/registry/icons/lucide/menu.svg +17 -0
  125. data/registry/icons/lucide/message-circle.svg +15 -0
  126. data/registry/icons/lucide/minus.svg +15 -0
  127. data/registry/icons/lucide/monitor.svg +17 -0
  128. data/registry/icons/lucide/moon.svg +15 -0
  129. data/registry/icons/lucide/newspaper.svg +18 -0
  130. data/registry/icons/lucide/package.svg +18 -0
  131. data/registry/icons/lucide/panel-left.svg +16 -0
  132. data/registry/icons/lucide/pause.svg +16 -0
  133. data/registry/icons/lucide/percent.svg +17 -0
  134. data/registry/icons/lucide/plus.svg +16 -0
  135. data/registry/icons/lucide/printer.svg +17 -0
  136. data/registry/icons/lucide/qr-code.svg +26 -0
  137. data/registry/icons/lucide/receipt.svg +17 -0
  138. data/registry/icons/lucide/rocket.svg +18 -0
  139. data/registry/icons/lucide/rotate-cw.svg +16 -0
  140. data/registry/icons/lucide/search.svg +16 -0
  141. data/registry/icons/lucide/settings.svg +16 -0
  142. data/registry/icons/lucide/shield-check.svg +16 -0
  143. data/registry/icons/lucide/shield.svg +15 -0
  144. data/registry/icons/lucide/store.svg +17 -0
  145. data/registry/icons/lucide/sun-moon.svg +19 -0
  146. data/registry/icons/lucide/sun.svg +23 -0
  147. data/registry/icons/lucide/trash-2.svg +19 -0
  148. data/registry/icons/lucide/truck.svg +19 -0
  149. data/registry/icons/lucide/underline.svg +16 -0
  150. data/registry/icons/lucide/upload.svg +17 -0
  151. data/registry/icons/lucide/user-plus.svg +18 -0
  152. data/registry/icons/lucide/user.svg +16 -0
  153. data/registry/icons/lucide/users.svg +18 -0
  154. data/registry/icons/lucide/workflow.svg +17 -0
  155. data/registry/icons/lucide/x.svg +16 -0
  156. data/registry/icons/lucide/zoom-in.svg +18 -0
  157. data/registry/icons/lucide/zoom-out.svg +17 -0
  158. data/registry/icons/phosphor/LICENSE +21 -0
  159. data/registry/icons/phosphor/arrow-clockwise.svg +2 -0
  160. data/registry/icons/phosphor/arrow-left.svg +2 -0
  161. data/registry/icons/phosphor/arrow-right.svg +2 -0
  162. data/registry/icons/phosphor/bell.svg +2 -0
  163. data/registry/icons/phosphor/book-open.svg +2 -0
  164. data/registry/icons/phosphor/calendar-blank.svg +2 -0
  165. data/registry/icons/phosphor/caret-down.svg +2 -0
  166. data/registry/icons/phosphor/caret-left.svg +2 -0
  167. data/registry/icons/phosphor/caret-right.svg +2 -0
  168. data/registry/icons/phosphor/caret-up-down.svg +2 -0
  169. data/registry/icons/phosphor/chart-bar.svg +2 -0
  170. data/registry/icons/phosphor/chat-circle.svg +2 -0
  171. data/registry/icons/phosphor/check-circle.svg +2 -0
  172. data/registry/icons/phosphor/check.svg +2 -0
  173. data/registry/icons/phosphor/circle-half.svg +2 -0
  174. data/registry/icons/phosphor/cloud.svg +2 -0
  175. data/registry/icons/phosphor/credit-card.svg +2 -0
  176. data/registry/icons/phosphor/desktop.svg +2 -0
  177. data/registry/icons/phosphor/dots-six-vertical.svg +2 -0
  178. data/registry/icons/phosphor/dots-three-vertical.svg +2 -0
  179. data/registry/icons/phosphor/dots-three.svg +2 -0
  180. data/registry/icons/phosphor/download-simple.svg +2 -0
  181. data/registry/icons/phosphor/envelope.svg +2 -0
  182. data/registry/icons/phosphor/eye-slash.svg +2 -0
  183. data/registry/icons/phosphor/eye.svg +2 -0
  184. data/registry/icons/phosphor/file-plus.svg +2 -0
  185. data/registry/icons/phosphor/file-text.svg +2 -0
  186. data/registry/icons/phosphor/file.svg +2 -0
  187. data/registry/icons/phosphor/flow-arrow.svg +2 -0
  188. data/registry/icons/phosphor/folder.svg +2 -0
  189. data/registry/icons/phosphor/gear.svg +2 -0
  190. data/registry/icons/phosphor/git-branch.svg +2 -0
  191. data/registry/icons/phosphor/globe.svg +2 -0
  192. data/registry/icons/phosphor/graduation-cap.svg +2 -0
  193. data/registry/icons/phosphor/grid-four.svg +2 -0
  194. data/registry/icons/phosphor/house.svg +2 -0
  195. data/registry/icons/phosphor/info.svg +2 -0
  196. data/registry/icons/phosphor/kanban.svg +2 -0
  197. data/registry/icons/phosphor/keyboard.svg +2 -0
  198. data/registry/icons/phosphor/lifebuoy.svg +2 -0
  199. data/registry/icons/phosphor/list.svg +2 -0
  200. data/registry/icons/phosphor/lock.svg +2 -0
  201. data/registry/icons/phosphor/magnifying-glass-minus.svg +2 -0
  202. data/registry/icons/phosphor/magnifying-glass-plus.svg +2 -0
  203. data/registry/icons/phosphor/magnifying-glass.svg +2 -0
  204. data/registry/icons/phosphor/minus.svg +2 -0
  205. data/registry/icons/phosphor/moon.svg +2 -0
  206. data/registry/icons/phosphor/newspaper.svg +2 -0
  207. data/registry/icons/phosphor/package.svg +2 -0
  208. data/registry/icons/phosphor/pause.svg +2 -0
  209. data/registry/icons/phosphor/percent.svg +2 -0
  210. data/registry/icons/phosphor/plus.svg +2 -0
  211. data/registry/icons/phosphor/printer.svg +2 -0
  212. data/registry/icons/phosphor/qr-code.svg +2 -0
  213. data/registry/icons/phosphor/receipt.svg +2 -0
  214. data/registry/icons/phosphor/rocket.svg +2 -0
  215. data/registry/icons/phosphor/seal-check.svg +2 -0
  216. data/registry/icons/phosphor/shield-check.svg +2 -0
  217. data/registry/icons/phosphor/shield.svg +2 -0
  218. data/registry/icons/phosphor/sidebar.svg +2 -0
  219. data/registry/icons/phosphor/sign-out.svg +2 -0
  220. data/registry/icons/phosphor/spinner.svg +2 -0
  221. data/registry/icons/phosphor/squares-four.svg +2 -0
  222. data/registry/icons/phosphor/storefront.svg +2 -0
  223. data/registry/icons/phosphor/sun.svg +2 -0
  224. data/registry/icons/phosphor/text-align-center.svg +2 -0
  225. data/registry/icons/phosphor/text-align-left.svg +2 -0
  226. data/registry/icons/phosphor/text-align-right.svg +2 -0
  227. data/registry/icons/phosphor/text-b.svg +2 -0
  228. data/registry/icons/phosphor/text-italic.svg +2 -0
  229. data/registry/icons/phosphor/text-underline.svg +2 -0
  230. data/registry/icons/phosphor/trash.svg +2 -0
  231. data/registry/icons/phosphor/tray.svg +2 -0
  232. data/registry/icons/phosphor/truck.svg +2 -0
  233. data/registry/icons/phosphor/upload-simple.svg +2 -0
  234. data/registry/icons/phosphor/user-plus.svg +2 -0
  235. data/registry/icons/phosphor/user.svg +2 -0
  236. data/registry/icons/phosphor/users.svg +2 -0
  237. data/registry/icons/phosphor/warning-circle.svg +2 -0
  238. data/registry/icons/phosphor/x.svg +2 -0
  239. data/registry/icons/tabler/LICENSE +21 -0
  240. data/registry/icons/tabler/alert-circle.svg +18 -0
  241. data/registry/icons/tabler/align-center.svg +18 -0
  242. data/registry/icons/tabler/align-left.svg +18 -0
  243. data/registry/icons/tabler/align-right.svg +18 -0
  244. data/registry/icons/tabler/arrow-left.svg +18 -0
  245. data/registry/icons/tabler/arrow-right.svg +18 -0
  246. data/registry/icons/tabler/bell.svg +17 -0
  247. data/registry/icons/tabler/bold.svg +17 -0
  248. data/registry/icons/tabler/book.svg +20 -0
  249. data/registry/icons/tabler/building-store.svg +20 -0
  250. data/registry/icons/tabler/calendar.svg +21 -0
  251. data/registry/icons/tabler/chart-bar.svg +19 -0
  252. data/registry/icons/tabler/check.svg +16 -0
  253. data/registry/icons/tabler/chevron-down.svg +16 -0
  254. data/registry/icons/tabler/chevron-left.svg +16 -0
  255. data/registry/icons/tabler/chevron-right.svg +16 -0
  256. data/registry/icons/tabler/circle-check.svg +17 -0
  257. data/registry/icons/tabler/cloud.svg +16 -0
  258. data/registry/icons/tabler/credit-card.svg +19 -0
  259. data/registry/icons/tabler/device-desktop.svg +19 -0
  260. data/registry/icons/tabler/dots-vertical.svg +18 -0
  261. data/registry/icons/tabler/dots.svg +18 -0
  262. data/registry/icons/tabler/download.svg +18 -0
  263. data/registry/icons/tabler/eye-off.svg +18 -0
  264. data/registry/icons/tabler/eye.svg +17 -0
  265. data/registry/icons/tabler/file-plus.svg +19 -0
  266. data/registry/icons/tabler/file-text.svg +20 -0
  267. data/registry/icons/tabler/file.svg +17 -0
  268. data/registry/icons/tabler/folder.svg +16 -0
  269. data/registry/icons/tabler/git-branch.svg +21 -0
  270. data/registry/icons/tabler/grip-vertical.svg +21 -0
  271. data/registry/icons/tabler/home.svg +18 -0
  272. data/registry/icons/tabler/inbox.svg +17 -0
  273. data/registry/icons/tabler/info-circle.svg +18 -0
  274. data/registry/icons/tabler/italic.svg +18 -0
  275. data/registry/icons/tabler/keyboard.svg +23 -0
  276. data/registry/icons/tabler/layout-dashboard.svg +19 -0
  277. data/registry/icons/tabler/layout-grid.svg +19 -0
  278. data/registry/icons/tabler/layout-kanban.svg +19 -0
  279. data/registry/icons/tabler/layout-sidebar.svg +17 -0
  280. data/registry/icons/tabler/lifebuoy.svg +21 -0
  281. data/registry/icons/tabler/list.svg +21 -0
  282. data/registry/icons/tabler/loader.svg +23 -0
  283. data/registry/icons/tabler/lock.svg +18 -0
  284. data/registry/icons/tabler/logout.svg +18 -0
  285. data/registry/icons/tabler/mail.svg +17 -0
  286. data/registry/icons/tabler/menu-2.svg +18 -0
  287. data/registry/icons/tabler/message-circle.svg +16 -0
  288. data/registry/icons/tabler/minus.svg +16 -0
  289. data/registry/icons/tabler/moon.svg +16 -0
  290. data/registry/icons/tabler/news.svg +19 -0
  291. data/registry/icons/tabler/package.svg +20 -0
  292. data/registry/icons/tabler/percentage.svg +18 -0
  293. data/registry/icons/tabler/player-pause.svg +17 -0
  294. data/registry/icons/tabler/plus.svg +17 -0
  295. data/registry/icons/tabler/printer.svg +18 -0
  296. data/registry/icons/tabler/qrcode.svg +27 -0
  297. data/registry/icons/tabler/receipt.svg +16 -0
  298. data/registry/icons/tabler/rocket.svg +18 -0
  299. data/registry/icons/tabler/rosette-discount-check.svg +17 -0
  300. data/registry/icons/tabler/rotate-clockwise.svg +16 -0
  301. data/registry/icons/tabler/school.svg +17 -0
  302. data/registry/icons/tabler/search.svg +17 -0
  303. data/registry/icons/tabler/selector.svg +17 -0
  304. data/registry/icons/tabler/settings.svg +17 -0
  305. data/registry/icons/tabler/shield-check.svg +17 -0
  306. data/registry/icons/tabler/shield.svg +16 -0
  307. data/registry/icons/tabler/sitemap.svg +20 -0
  308. data/registry/icons/tabler/sun-moon.svg +21 -0
  309. data/registry/icons/tabler/sun.svg +17 -0
  310. data/registry/icons/tabler/trash.svg +20 -0
  311. data/registry/icons/tabler/truck.svg +18 -0
  312. data/registry/icons/tabler/underline.svg +17 -0
  313. data/registry/icons/tabler/upload.svg +18 -0
  314. data/registry/icons/tabler/user-plus.svg +19 -0
  315. data/registry/icons/tabler/user.svg +17 -0
  316. data/registry/icons/tabler/users.svg +19 -0
  317. data/registry/icons/tabler/world.svg +20 -0
  318. data/registry/icons/tabler/x.svg +17 -0
  319. data/registry/icons/tabler/zoom-in.svg +19 -0
  320. data/registry/icons/tabler/zoom-out.svg +18 -0
  321. data/registry/icons.yml +90 -0
  322. data/registry/test/components/previews/ui/chart_preview/cash_flow.html.erb +6 -0
  323. data/registry/test/components/previews/ui/chart_preview/donut.html.erb +6 -0
  324. data/registry/test/components/previews/ui/chart_preview/margin.html.erb +6 -0
  325. data/registry/test/components/previews/ui/chart_preview/pie.html.erb +6 -0
  326. data/registry/test/components/previews/ui/chart_preview/sales.html.erb +6 -0
  327. data/registry/test/components/previews/ui/chart_preview/stock.html.erb +6 -0
  328. data/registry/test/components/previews/ui/chart_preview/takings.html.erb +8 -0
  329. data/registry/test/components/previews/ui/chart_preview.rb +46 -0
  330. data/registry/test/components/previews/ui/command_preview/_picked.html.erb +14 -0
  331. data/registry/test/components/previews/ui/command_preview/dialog.html.erb +24 -0
  332. data/registry/test/components/previews/ui/command_preview/inline.html.erb +16 -0
  333. data/registry/test/components/previews/ui/command_preview/playground.html.erb +15 -0
  334. data/registry/test/components/previews/ui/command_preview/server_search.html.erb +24 -0
  335. data/registry/test/components/previews/ui/command_preview/shortcuts.html.erb +12 -0
  336. data/registry/test/components/previews/ui/command_preview/till.html.erb +17 -0
  337. data/registry/test/components/previews/ui/command_preview.rb +25 -0
  338. data/registry/test/components/previews/ui/confirm_dialog_preview/destructive.html.erb +7 -0
  339. data/registry/test/components/previews/ui/confirm_dialog_preview/in_form.html.erb +6 -0
  340. data/registry/test/components/previews/ui/confirm_dialog_preview/on_link.html.erb +5 -0
  341. data/registry/test/components/previews/ui/confirm_dialog_preview/plain.html.erb +3 -0
  342. data/registry/test/components/previews/ui/confirm_dialog_preview/with_description.html.erb +4 -0
  343. data/registry/test/components/previews/ui/confirm_dialog_preview.rb +20 -0
  344. data/registry/test/components/previews/ui/date_picker_preview/custom_presets.html.erb +6 -0
  345. data/registry/test/components/previews/ui/date_picker_preview/in_form.html.erb +11 -0
  346. data/registry/test/components/previews/ui/date_picker_preview/range.html.erb +5 -0
  347. data/registry/test/components/previews/ui/date_picker_preview/states.html.erb +4 -3
  348. data/registry/test/components/previews/ui/date_picker_preview.rb +26 -6
  349. data/registry/test/components/previews/ui/empty_state_preview/in_card.html.erb +7 -0
  350. data/registry/test/components/previews/ui/empty_state_preview/no_results.html.erb +3 -0
  351. data/registry/test/components/previews/ui/empty_state_preview/outline.html.erb +3 -0
  352. data/registry/test/components/previews/ui/empty_state_preview/with_actions.html.erb +4 -0
  353. data/registry/test/components/previews/ui/empty_state_preview/with_media.html.erb +8 -0
  354. data/registry/test/components/previews/ui/empty_state_preview.rb +26 -0
  355. data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +1 -1
  356. data/registry/test/components/previews/ui/file_field_preview/product_photos.html.erb +12 -0
  357. data/registry/test/components/previews/ui/file_field_preview/single_image.html.erb +4 -0
  358. data/registry/test/components/previews/ui/file_field_preview.rb +32 -5
  359. data/registry/test/components/previews/ui/gallery_preview/hover_zoom.html.erb +13 -0
  360. data/registry/test/components/previews/ui/gallery_preview/landscape.html.erb +5 -0
  361. data/registry/test/components/previews/ui/gallery_preview/product_page.html.erb +13 -0
  362. data/registry/test/components/previews/ui/gallery_preview/single.html.erb +3 -0
  363. data/registry/test/components/previews/ui/gallery_preview.rb +45 -0
  364. data/registry/test/components/previews/ui/icon_preview/common.html.erb +19 -3
  365. data/registry/test/components/previews/ui/icon_preview/labelled.html.erb +4 -0
  366. data/registry/test/components/previews/ui/icon_preview/missing.html.erb +3 -0
  367. data/registry/test/components/previews/ui/icon_preview.rb +18 -3
  368. data/registry/test/components/previews/ui/input_group_preview/playground.html.erb +2 -2
  369. data/registry/test/components/previews/ui/input_group_preview.rb +3 -3
  370. data/registry/test/components/previews/ui/kbd_preview/bound.html.erb +20 -0
  371. data/registry/test/components/previews/ui/kbd_preview/keys.html.erb +13 -0
  372. data/registry/test/components/previews/ui/kbd_preview/menu.html.erb +13 -0
  373. data/registry/test/components/previews/ui/kbd_preview/search_field.html.erb +8 -0
  374. data/registry/test/components/previews/ui/kbd_preview/shortcuts_list.html.erb +17 -0
  375. data/registry/test/components/previews/ui/kbd_preview/till.html.erb +23 -0
  376. data/registry/test/components/previews/ui/kbd_preview/tooltip_and_buttons.html.erb +14 -0
  377. data/registry/test/components/previews/ui/kbd_preview.rb +32 -0
  378. data/registry/test/components/previews/ui/number_input_preview/cart.html.erb +11 -0
  379. data/registry/test/components/previews/ui/number_input_preview/decimals.html.erb +4 -0
  380. data/registry/test/components/previews/ui/number_input_preview/sizes.html.erb +5 -0
  381. data/registry/test/components/previews/ui/number_input_preview/states.html.erb +7 -0
  382. data/registry/test/components/previews/ui/number_input_preview/stock_adjustment.html.erb +3 -0
  383. data/registry/test/components/previews/ui/number_input_preview.rb +36 -0
  384. data/registry/test/components/previews/ui/progress_preview/file_upload.html.erb +36 -0
  385. data/registry/test/components/previews/ui/progress_preview/free_shipping.html.erb +4 -0
  386. data/registry/test/components/previews/ui/progress_preview/indeterminate.html.erb +4 -0
  387. data/registry/test/components/previews/ui/progress_preview/sizes_and_tones.html.erb +8 -0
  388. data/registry/test/components/previews/ui/progress_preview/steps.html.erb +9 -0
  389. data/registry/test/components/previews/ui/progress_preview/storage.html.erb +8 -0
  390. data/registry/test/components/previews/ui/progress_preview/storage_by_category.html.erb +7 -0
  391. data/registry/test/components/previews/ui/progress_preview/tasks_by_status.html.erb +14 -0
  392. data/registry/test/components/previews/ui/progress_preview/traffic_by_source.html.erb +15 -0
  393. data/registry/test/components/previews/ui/progress_preview.rb +46 -0
  394. data/registry/test/components/previews/ui/select_preview/server_search.html.erb +22 -0
  395. data/registry/test/components/previews/ui/select_preview.rb +5 -0
  396. data/registry/test/components/previews/ui/stepper_preview/approvals.html.erb +9 -0
  397. data/registry/test/components/previews/ui/stepper_preview/checklist.html.erb +12 -0
  398. data/registry/test/components/previews/ui/stepper_preview/dot_wizard.html.erb +41 -0
  399. data/registry/test/components/previews/ui/stepper_preview/failed_deploy.html.erb +13 -0
  400. data/registry/test/components/previews/ui/stepper_preview/inline.html.erb +31 -0
  401. data/registry/test/components/previews/ui/stepper_preview/onboarding.html.erb +12 -0
  402. data/registry/test/components/previews/ui/stepper_preview/order_tracking.html.erb +10 -0
  403. data/registry/test/components/previews/ui/stepper_preview/price_calculator.html.erb +14 -0
  404. data/registry/test/components/previews/ui/stepper_preview/server_driven.html.erb +20 -0
  405. data/registry/test/components/previews/ui/stepper_preview/sidebar.html.erb +43 -0
  406. data/registry/test/components/previews/ui/stepper_preview/wizard.html.erb +55 -0
  407. data/registry/test/components/previews/ui/stepper_preview.rb +57 -0
  408. data/registry/test/components/previews/ui/timeline_preview/activity_log.html.erb +7 -0
  409. data/registry/test/components/previews/ui/timeline_preview/colored.html.erb +7 -0
  410. data/registry/test/components/previews/ui/timeline_preview/colored_by_meaning.html.erb +7 -0
  411. data/registry/test/components/previews/ui/timeline_preview/failed_delivery.html.erb +6 -0
  412. data/registry/test/components/previews/ui/timeline_preview/order_status.html.erb +9 -0
  413. data/registry/test/components/previews/ui/timeline_preview/real_dates.html.erb +5 -0
  414. data/registry/test/components/previews/ui/timeline_preview/stock_history.html.erb +6 -0
  415. data/registry/test/components/previews/ui/timeline_preview.rb +40 -0
  416. data/registry/test/components/previews/ui/toggle_group_preview/icon_only.html.erb +5 -0
  417. data/registry/test/components/previews/ui/toggle_group_preview/in_form.html.erb +11 -0
  418. data/registry/test/components/previews/ui/toggle_group_preview/multiple.html.erb +5 -0
  419. data/registry/test/components/previews/ui/toggle_group_preview/outline.html.erb +5 -0
  420. data/registry/test/components/previews/ui/toggle_group_preview/sizes.html.erb +9 -0
  421. data/registry/test/components/previews/ui/toggle_group_preview/with_icons.html.erb +5 -0
  422. data/registry/test/components/previews/ui/toggle_group_preview.rb +36 -0
  423. data/registry/test/components/ui/accordion/trigger_test.rb +1 -1
  424. data/registry/test/components/ui/alert_test.rb +10 -10
  425. data/registry/test/components/ui/badge_test.rb +3 -3
  426. data/registry/test/components/ui/banner_test.rb +3 -3
  427. data/registry/test/components/ui/breadcrumb/ellipsis_test.rb +2 -2
  428. data/registry/test/components/ui/button_test.rb +17 -14
  429. data/registry/test/components/ui/button_to_test.rb +2 -2
  430. data/registry/test/components/ui/chart_test.rb +187 -0
  431. data/registry/test/components/ui/checkbox_test.rb +2 -2
  432. data/registry/test/components/ui/command/group_test.rb +19 -0
  433. data/registry/test/components/ui/command/item_test.rb +47 -0
  434. data/registry/test/components/ui/command_test.rb +110 -0
  435. data/registry/test/components/ui/confirm_dialog_test.rb +68 -0
  436. data/registry/test/components/ui/date_picker_test.rb +129 -111
  437. data/registry/test/components/ui/empty_state_test.rb +87 -0
  438. data/registry/test/components/ui/file_field_test.rb +105 -9
  439. data/registry/test/components/ui/gallery_test.rb +192 -0
  440. data/registry/test/components/ui/icon_test.rb +60 -20
  441. data/registry/test/components/ui/input_group_test.rb +1 -1
  442. data/registry/test/components/ui/kbd_test.rb +150 -0
  443. data/registry/test/components/ui/link_test.rb +3 -3
  444. data/registry/test/components/ui/navigation_menu_test.rb +2 -2
  445. data/registry/test/components/ui/number_input_test.rb +155 -0
  446. data/registry/test/components/ui/progress_test.rb +188 -0
  447. data/registry/test/components/ui/select_test.rb +62 -0
  448. data/registry/test/components/ui/session_tabs_test.rb +3 -3
  449. data/registry/test/components/ui/spinner_test.rb +9 -9
  450. data/registry/test/components/ui/stepper_test.rb +239 -0
  451. data/registry/test/components/ui/tabs/trigger_test.rb +2 -2
  452. data/registry/test/components/ui/theme_toggle_test.rb +6 -8
  453. data/registry/test/components/ui/timeline_test.rb +175 -0
  454. data/registry/test/components/ui/toast_test.rb +11 -10
  455. data/registry/test/components/ui/toggle_group_test.rb +162 -0
  456. metadata +399 -3
  457. data/registry/app/javascript/cally.ts +0 -8
  458. data/registry/app/javascript/velvetkit_icons.ts +0 -78
@@ -0,0 +1,213 @@
1
+ # frozen_string_literal: true
2
+
3
+ # One step in a UI::Stepper: its indicator, its title and description, and the
4
+ # line on to the next step. Its state comes from the stepper's `current:`
5
+ # unless `status:` sets it. `icon:` draws an icon in place of the number.
6
+ #
7
+ # Every state's look hangs off the step's data-status, so the stepper's
8
+ # controller only has to change that attribute to move someone along.
9
+ class UI::Stepper::Step < UI::Base
10
+ STATUSES = %i[complete current upcoming error loading].freeze
11
+
12
+ # Shown when a panel appears, after the first move, so a page load is still.
13
+ PANEL_CLASSES = "outline-none group-data-[moved]/stepper:animate-in group-data-[moved]/stepper:fade-in " \
14
+ "group-data-[moved]/stepper:duration-300 group-data-[moved]/stepper:slide-in-from-right-4 " \
15
+ "group-data-[direction=back]/stepper:slide-in-from-left-4 motion-reduce:animate-none"
16
+
17
+ # Written out in full, state by state, so Tailwind finds every class. Current
18
+ # and loading look alike: a ring round the step someone is on.
19
+ INDICATOR = {
20
+ default: "size-8 border text-sm font-medium border-transparent bg-muted text-muted-foreground " \
21
+ "group-data-[status=complete]/step:border-primary group-data-[status=complete]/step:bg-primary " \
22
+ "group-data-[status=complete]/step:text-primary-foreground " \
23
+ "group-data-[status=current]/step:border-2 group-data-[status=current]/step:border-primary " \
24
+ "group-data-[status=current]/step:bg-transparent group-data-[status=current]/step:text-primary " \
25
+ "group-data-[status=current]/step:ring-4 group-data-[status=current]/step:ring-primary/15 " \
26
+ "group-data-[status=loading]/step:border-2 group-data-[status=loading]/step:border-primary " \
27
+ "group-data-[status=loading]/step:bg-transparent group-data-[status=loading]/step:text-primary " \
28
+ "group-data-[status=loading]/step:ring-4 group-data-[status=loading]/step:ring-primary/15 " \
29
+ "group-data-[status=error]/step:border-destructive group-data-[status=error]/step:bg-destructive " \
30
+ "group-data-[status=error]/step:text-white group-data-[status=error]/step:ring-4 " \
31
+ "group-data-[status=error]/step:ring-destructive/15",
32
+ dot: "size-3 bg-muted-foreground/30 group-data-[status=complete]/step:bg-primary " \
33
+ "group-data-[status=current]/step:border-2 group-data-[status=current]/step:border-primary " \
34
+ "group-data-[status=current]/step:bg-transparent group-data-[status=current]/step:ring-4 " \
35
+ "group-data-[status=current]/step:ring-primary/15 " \
36
+ "group-data-[status=loading]/step:border-2 group-data-[status=loading]/step:border-primary " \
37
+ "group-data-[status=loading]/step:bg-transparent group-data-[status=loading]/step:ring-4 " \
38
+ "group-data-[status=loading]/step:ring-primary/15 group-data-[status=loading]/step:animate-pulse " \
39
+ "group-data-[status=error]/step:bg-destructive group-data-[status=error]/step:ring-4 " \
40
+ "group-data-[status=error]/step:ring-destructive/15"
41
+ }.freeze
42
+
43
+ # Each glyph shows in its own state only; the swap animates after a move.
44
+ GLYPH = "group-data-[moved]/stepper:animate-in group-data-[moved]/stepper:zoom-in-50 " \
45
+ "group-data-[moved]/stepper:fade-in group-data-[moved]/stepper:duration-300 motion-reduce:animate-none"
46
+
47
+ attr_reader :number, :title
48
+ attr_accessor :panel
49
+
50
+ def initialize(title:, description: nil, href: nil, status: nil, icon: nil, class: nil, **html_attrs)
51
+ @title = title
52
+ @description = description
53
+ @href = href
54
+ @status = status&.to_sym
55
+ @icon = icon
56
+ @user_class = binding.local_variable_get(:class)
57
+ @html_attrs = html_attrs
58
+ end
59
+
60
+ def place(stepper, number, last:)
61
+ @stepper = stepper
62
+ @number = number
63
+ @last = last
64
+ end
65
+
66
+ def status
67
+ return @status if STATUSES.include?(@status)
68
+
69
+ if @number < @stepper.current then :complete
70
+ elsif @number == @stepper.current then :current
71
+ else :upcoming
72
+ end
73
+ end
74
+
75
+ def panel? = panel.present?
76
+ def last? = @last
77
+ def vertical? = @stepper.vertical?
78
+ def dot? = @stepper.dot?
79
+ def center? = !vertical? && @stepper.align == :center
80
+ def link? = @href.present? && %i[complete error].include?(status)
81
+ def navigable? = !link? && @stepper.navigable?
82
+ def title_id = "#{@stepper.id}-step-#{@number}"
83
+ def description? = @description.present?
84
+ def inline_panel? = @stepper.inline? && panel?
85
+ def number_glyph = @icon ? render(UI::Icon.new(name: @icon, size: :sm)) : @number.to_s
86
+
87
+ def item_attrs
88
+ attrs = @html_attrs.except(:data, :aria)
89
+ attrs[:class] = cn("group/step relative min-w-0", item_layout, @user_class)
90
+ attrs[:aria] = { current: ("step" if %i[current loading].include?(status)) }.compact.merge(@html_attrs[:aria] || {})
91
+ attrs[:data] = { slot: "stepper-step", status: status, "ui--stepper-target": "step" }
92
+ .merge(@html_attrs[:data] || {})
93
+ attrs
94
+ end
95
+
96
+ def item_layout
97
+ if vertical?
98
+ cn("flex gap-3", { "pb-8" => !last? && @stepper.connector?, "pb-5" => !last? && !@stepper.connector? })
99
+ elsif center?
100
+ "flex flex-1 flex-col items-center text-center"
101
+ else
102
+ cn("flex flex-col", last? ? "shrink-0" : "flex-1")
103
+ end
104
+ end
105
+
106
+ def indicator_classes
107
+ cn("relative z-10 flex shrink-0 items-center justify-center rounded-full",
108
+ "transition-[background-color,border-color,color,box-shadow] duration-300 motion-reduce:transition-none",
109
+ INDICATOR[@stepper.variant],
110
+ { "mt-1" => dot? && vertical?,
111
+ "group-data-[status=complete]/step:cursor-pointer group-data-[status=complete]/step:hover:ring-4 " \
112
+ "group-data-[status=complete]/step:hover:ring-primary/15" => navigable? })
113
+ end
114
+
115
+ # The number (or the step's icon) for steps to come and the current one; a
116
+ # tick once done, "!" on an error, a spinner while it's being checked.
117
+ def glyph_classes(state)
118
+ shown = {
119
+ number: "group-data-[status=complete]/step:hidden group-data-[status=error]/step:hidden " \
120
+ "group-data-[status=loading]/step:hidden",
121
+ complete: "hidden group-data-[status=complete]/step:flex",
122
+ error: "hidden group-data-[status=error]/step:flex",
123
+ loading: "hidden group-data-[status=loading]/step:flex"
124
+ }
125
+ cn("items-center justify-center", shown[state], { GLYPH => state != :number })
126
+ end
127
+
128
+ def text_classes
129
+ cn("flex min-w-0 flex-col gap-0.5",
130
+ if vertical? then dot? ? "flex-1" : "flex-1 pt-1.5"
131
+ elsif center? then "mt-3 px-2"
132
+ else "mt-3 pr-4"
133
+ end,
134
+ { "sr-only" => !@stepper.labels?, "@max-md/stepper:sr-only" => !vertical? && @stepper.labels? })
135
+ end
136
+
137
+ def title_classes
138
+ cn("text-sm font-medium text-foreground transition-colors duration-300",
139
+ "group-data-[status=upcoming]/step:text-muted-foreground group-data-[status=error]/step:text-destructive",
140
+ { "underline-offset-4 group-hover/link:underline" => link?,
141
+ "underline-offset-4 group-enabled/link:group-hover/link:underline" => navigable? })
142
+ end
143
+
144
+ def description_classes
145
+ "text-sm text-muted-foreground group-data-[status=error]/step:text-destructive/90"
146
+ end
147
+
148
+ # A done step's title is a button back to it, and so (for the mouse) is its
149
+ # indicator. The controller enables it as each step is done.
150
+ def select_attrs
151
+ { type: "button", disabled: status != :complete, data: { action: "ui--stepper#select" },
152
+ class: "group/link flex w-fit cursor-pointer rounded-sm text-start outline-none focus-visible:ring-[3px] " \
153
+ "focus-visible:ring-ring/40 disabled:cursor-default #{'self-center' if center?}" }
154
+ end
155
+
156
+ def indicator_attrs
157
+ attrs = { class: indicator_classes, aria: { hidden: true } }
158
+ attrs[:data] = { action: "click->ui--stepper#select" } if navigable?
159
+ attrs
160
+ end
161
+
162
+ def link_classes
163
+ "group/link flex w-fit rounded-sm outline-none focus-visible:ring-[3px] focus-visible:ring-ring/40"
164
+ end
165
+
166
+ def connector? = @stepper.connector? && !last?
167
+
168
+ # The line on to the next step: a grey track, and a fill that grows along it
169
+ # once this step is done.
170
+ def connector_classes
171
+ if vertical?
172
+ cn("absolute w-0.5 -translate-x-1/2 overflow-hidden rounded-full bg-border",
173
+ dot? ? "left-1.5 top-6 bottom-1" : "left-4 top-10 bottom-2")
174
+ elsif center?
175
+ cn("absolute h-0.5 -translate-y-1/2 overflow-hidden rounded-full bg-border",
176
+ dot? ? "top-1.5 left-[calc(50%+1rem)] right-[calc(-50%+1rem)]"
177
+ : "top-4 left-[calc(50%+1.75rem)] right-[calc(-50%+1.75rem)]")
178
+ else
179
+ "mx-3 h-0.5 flex-1 overflow-hidden rounded-full bg-border"
180
+ end
181
+ end
182
+
183
+ def connector_fill_classes
184
+ # Filled once this step is done, or the next one is: going back to change
185
+ # an answer leaves the way on to the steps already done drawn in.
186
+ cn("block size-full bg-primary transition-transform duration-500 ease-out motion-reduce:transition-none",
187
+ vertical? ? "origin-top scale-y-0 group-data-[status=complete]/step:scale-y-100 " \
188
+ "[li:has(+li[data-status=complete])_&]:scale-y-100"
189
+ : "origin-left scale-x-0 group-data-[status=complete]/step:scale-x-100 " \
190
+ "[li:has(+li[data-status=complete])_&]:scale-x-100 rtl:origin-right")
191
+ end
192
+
193
+ def head_classes
194
+ vertical? || center? ? "contents" : "flex items-center"
195
+ end
196
+
197
+ def panel_attrs
198
+ @stepper.panel_attrs(self).merge(class: cn(PANEL_CLASSES, "pt-4"))
199
+ end
200
+
201
+ # Each state's words for screen readers, shown (to them) only in that state.
202
+ STATUS_TEXT = {
203
+ complete: [ "Completed", "hidden group-data-[status=complete]/step:inline" ],
204
+ current: [ "Current step", "hidden group-data-[status=current]/step:inline" ],
205
+ upcoming: [ "Not started", "hidden group-data-[status=upcoming]/step:inline" ],
206
+ error: [ "Needs attention", "hidden group-data-[status=error]/step:inline" ],
207
+ loading: [ "Checking", "hidden group-data-[status=loading]/step:inline" ]
208
+ }.freeze
209
+
210
+ def status_texts
211
+ STATUS_TEXT.map { |state, (default, shown)| [ t("ui.stepper.#{state}", default: default), "sr-only #{shown}" ] }
212
+ end
213
+ end
@@ -0,0 +1,19 @@
1
+ <%= tag.div(**root_attrs) do %><%= tag.div class: frame_classes do %>
2
+ <%= tag.nav(**nav_attrs) do %>
3
+ <%= tag.ol class: list_classes do %><% steps.each do |step| %><%= step %><% end %><% end %>
4
+ <% if summary? %>
5
+ <%= tag.p summary_text, class: "mt-4 text-sm font-medium text-foreground @md/stepper:hidden", hidden: finished?, aria: { hidden: true }, data: { "ui--stepper-target": "summary" } %>
6
+ <% end %>
7
+ <% end %>
8
+ <% if body? %>
9
+ <%= tag.div class: body_classes do %>
10
+ <% panels.each do |step| %>
11
+ <%= tag.div(step.panel, **panel_attrs(step)) %>
12
+ <% end %>
13
+ <% if completion? %>
14
+ <%= tag.div(completion, **completion_attrs) %>
15
+ <% end %>
16
+ <%= content %>
17
+ <% end %>
18
+ <% end %>
19
+ <% end %><% end %>
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ # The steps of a multi-step flow, each one done, current, still to come, or in
6
+ # trouble. `current:` is the 1-based number of the step someone is on: steps
7
+ # before it are done, and `current: steps + 1` marks them all done. A step can
8
+ # set its own state with `status:` (:complete, :current, :upcoming, :error or
9
+ # :loading), for one that failed or is still being checked.
10
+ #
11
+ # Looks: `variant: :default` draws numbered circles and `:dot` small dots.
12
+ # Horizontal steppers put each title under its step, `align: :start` (at the
13
+ # left of it) or `:center`; `orientation: :vertical` puts it beside, with room
14
+ # for a description and more. `connector: false` drops the lines, and
15
+ # `labels: false` keeps the titles for screen readers only. Where it has less
16
+ # than 28rem (a phone, a narrow card), a horizontal stepper shows just its
17
+ # steps, with "Step 2 of 4" and the current title under them.
18
+ #
19
+ # A step's block is its panel: what someone fills in on that step. Give the
20
+ # steps panels and the stepper moves between them in the browser; a button
21
+ # with `data-action="ui--stepper#next"` checks the panel's fields and moves
22
+ # on, marking the step as an error if one is invalid, and `ui--stepper#previous`
23
+ # goes back, as does clicking a done step (`navigable: false` turns that
24
+ # off). Moving on is only ever by Continue, so a panel is never skipped
25
+ # unchecked. Give a button `data-ui--stepper-target="next"` or `"previous"` and
26
+ # it hides when there's nowhere to go, and `"submit"` shows only on the last
27
+ # step. Panels sit under the steps; `layout: :side` puts a vertical stepper
28
+ # beside them, given the room, and `layout: :inline` puts each one under its
29
+ # step's title. The stepper's own block comes after the panels, for those
30
+ # buttons; `with_completion` is shown once every step is done.
31
+ #
32
+ # To validate on the server instead, render the stepper with the step the
33
+ # server says someone is on and post each panel's form. While a form inside
34
+ # the stepper is submitting, its current step shows a spinner.
35
+ #
36
+ # Give a done step an `href:` to let people go back to it. Screen readers hear
37
+ # each step's state, and the current one has aria-current="step".
38
+ class UI::Stepper < UI::Base
39
+ ORIENTATIONS = %i[horizontal vertical].freeze
40
+
41
+ # The step's block is captured here, as its panel, rather than as the step's
42
+ # content: the stepper puts it after the list, apart from the step.
43
+ renders_many :steps, ->(title:, **opts, &block) {
44
+ UI::Stepper::Step.new(title: title, **opts).tap { |step| step.panel = block&.call }
45
+ }
46
+ renders_one :completion
47
+
48
+ def initialize(current: 1, orientation: :horizontal, variant: :default, align: :start, layout: :stacked,
49
+ connector: true, labels: true, navigable: nil, label: nil, class: nil, **html_attrs)
50
+ @current = current.to_i
51
+ @orientation = ORIENTATIONS.include?(orientation.to_sym) ? orientation.to_sym : :horizontal
52
+ @variant = variant.to_sym == :dot ? :dot : :default
53
+ @align = align.to_sym == :center ? :center : :start
54
+ @layout = layout.to_sym
55
+ @connector = connector
56
+ @labels = labels
57
+ @navigable = navigable
58
+ @label = label
59
+ @user_class = binding.local_variable_get(:class)
60
+ @html_attrs = html_attrs
61
+ end
62
+
63
+ attr_reader :current, :orientation, :variant, :align
64
+
65
+ def vertical? = @orientation == :vertical
66
+ def dot? = @variant == :dot
67
+ def connector? = @connector
68
+ def labels? = @labels
69
+ def side? = vertical? && @layout == :side
70
+ def inline? = vertical? && @layout == :inline
71
+ def finished? = @current > steps.size
72
+
73
+ # Steps with panels go back when a done one is clicked, unless
74
+ # `navigable: false` keeps people on Back.
75
+ def navigable? = @navigable.nil? ? steps.any?(&:panel?) : @navigable
76
+
77
+ def id = @html_attrs[:id] || (@id ||= "ui-stepper-#{SecureRandom.hex(4)}")
78
+
79
+ def before_render
80
+ steps.each_with_index { |step, index| step.place(self, index + 1, last: index == steps.size - 1) }
81
+ end
82
+
83
+ # Panels that sit apart from the list: every layout but :inline, which puts
84
+ # each one inside its step.
85
+ def panels = inline? ? [] : steps.select(&:panel?)
86
+ def body? = panels.any? || completion? || content.present?
87
+
88
+ def root_attrs
89
+ attrs = @html_attrs.except(:data, :aria, :id)
90
+ attrs[:id] = id
91
+ attrs[:class] = cn("group/stepper @container/stepper w-full", @user_class)
92
+ attrs[:data] = {
93
+ slot: "stepper", orientation: @orientation, variant: @variant,
94
+ controller: "ui--stepper",
95
+ "ui--stepper-current-value": @current,
96
+ "ui--stepper-summary-value": t("ui.stepper.summary", default: "Step %{current} of %{total}"),
97
+ action: "keydown->ui--stepper#keydown input->ui--stepper#revalidate change->ui--stepper#revalidate " \
98
+ "turbo:submit-start->ui--stepper#submitting turbo:submit-end->ui--stepper#submitted"
99
+ }.merge(@html_attrs[:data] || {})
100
+ attrs
101
+ end
102
+
103
+ def nav_attrs
104
+ { aria: { label: @label || t("ui.stepper.label", default: "Progress") }.merge(@html_attrs[:aria] || {}),
105
+ class: cn("min-w-0", { "@md/stepper:sticky @md/stepper:top-6 @md/stepper:self-start" => side? }) }
106
+ end
107
+
108
+ # Side by side once the stepper has the room, measured on itself rather
109
+ # than the window, so it works in a card or a docs column too.
110
+ def frame_classes
111
+ side? ? "grid gap-8 @md/stepper:grid-cols-[minmax(10rem,14rem)_1fr] @md/stepper:gap-10" : "contents"
112
+ end
113
+
114
+ def list_classes
115
+ vertical? ? "flex flex-col" : "flex w-full items-start"
116
+ end
117
+
118
+ def body_classes
119
+ cn("min-w-0", { "mt-8" => !side? && !inline? })
120
+ end
121
+
122
+ def panel_attrs(step)
123
+ { id: "#{id}-panel-#{step.number}", hidden: step.number != @current, tabindex: -1, role: "group",
124
+ aria: { labelledby: step.title_id },
125
+ data: { "ui--stepper-target": "panel", step: step.number },
126
+ class: UI::Stepper::Step::PANEL_CLASSES }
127
+ end
128
+
129
+ def completion_attrs
130
+ { hidden: !finished?, tabindex: -1, data: { "ui--stepper-target": "completion" },
131
+ class: UI::Stepper::Step::PANEL_CLASSES }
132
+ end
133
+
134
+ # "Step 2 of 4" and the current title, under a horizontal stepper on a phone,
135
+ # where the titles don't fit. Screen readers get each step's own text instead.
136
+ def summary?
137
+ !vertical? && steps.size > 1
138
+ end
139
+
140
+ def summary_text
141
+ shown = @current.clamp(1, steps.size)
142
+ format = t("ui.stepper.summary", default: "Step %{current} of %{total}")
143
+ "#{format.sub('%{current}', shown.to_s).sub('%{total}', steps.size.to_s)}: #{steps[shown - 1].title}"
144
+ end
145
+ end
@@ -37,10 +37,8 @@ class UI::ThemeToggle < UI::Base
37
37
  }
38
38
  end
39
39
 
40
- # Both icons are rendered and swapped with `dark:` variants rather than by
41
- # changing `data-lucide` at runtime: lucide replaces each <i> with an <svg>
42
- # on first render, so the original element is gone and a later attribute
43
- # change would do nothing.
40
+ # All three icons are rendered and shown by CSS, so the right one is there
41
+ # before any script runs.
44
42
  # The trigger shows the preference (html[data-theme], set before paint by
45
43
  # the theme script): sun for light, which is the default, moon for dark,
46
44
  # and a monitor while following the system.
@@ -0,0 +1,21 @@
1
+ <%= tag.li(**item_attrs) do %>
2
+ <%= tag.span class: marker_classes, aria: { hidden: true } do %>
3
+ <% if !dot? && marker_icon %><%= render(UI::Icon.new(name: marker_icon, size: :sm)) %><% end %>
4
+ <% if !dot? && !marker_icon && status == :current %><%= tag.span class: "size-2 rounded-full bg-current" %><% end %>
5
+ <% end %>
6
+ <% if connector? %><%= tag.span class: connector_classes, aria: { hidden: true } %><% end %>
7
+ <%= tag.div class: text_classes do %>
8
+ <%= tag.div class: "flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5" do %>
9
+ <%= tag.span class: title_classes do %><%= title %><%= tag.span ", #{status_text}", class: "sr-only" %><% end %>
10
+ <% if time? %>
11
+ <% if date? %>
12
+ <%= tag.time time_text, datetime: @time.iso8601, class: "text-xs text-muted-foreground" %>
13
+ <% else %>
14
+ <%= tag.span time_text, class: "text-xs text-muted-foreground" %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+ <% if description? %><%= tag.p description, class: "text-sm text-muted-foreground" %><% end %>
19
+ <% if content? %><%= tag.div content, class: "mt-1.5 text-sm text-foreground" %><% end %>
20
+ <% end %>
21
+ <% end %>
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ # One entry in a UI::Timeline: its marker, its title, when it happened, and the
4
+ # line on to the next entry. Its block is shown under the title, for anything
5
+ # more than `description:` (a link, a note, a badge).
6
+ #
7
+ # `status:` is :complete (the default, since most entries record something that
8
+ # has happened), :current, :upcoming or :error. `icon:` draws an icon in place
9
+ # of the status's own mark; a :dot timeline draws no icons.
10
+ #
11
+ # In a :colored timeline each circle takes the next colour in COLORS, or the one
12
+ # `color:` names, for colours that mean something (:emerald for stock received,
13
+ # :rose for written off). :upcoming and :error keep their own look, so a failure
14
+ # always reads as one.
15
+ #
16
+ # `time:` is a Time or Date, shown with the locale's :long format inside a
17
+ # <time> element; `time_label:` changes the words but keeps the machine-readable
18
+ # date ("2 hours ago"). A String is shown as it is, for what isn't a date yet
19
+ # ("Expected Friday").
20
+ class UI::Timeline::Item < UI::Base
21
+ STATUSES = %i[complete current upcoming error].freeze
22
+
23
+ ICONS = { complete: "check", error: "x" }.freeze
24
+
25
+ # Written out in full, status by status, so Tailwind finds every class.
26
+ MARKER = {
27
+ default: {
28
+ complete: "size-8 bg-primary text-primary-foreground",
29
+ current: "size-8 border-2 border-primary bg-background text-primary ring-4 ring-primary/15",
30
+ upcoming: "size-8 bg-muted text-muted-foreground",
31
+ error: "size-8 bg-destructive text-white ring-4 ring-destructive/15"
32
+ },
33
+ dot: {
34
+ complete: "mt-1 size-3 bg-primary",
35
+ current: "mt-1 size-3 border-2 border-primary bg-background ring-4 ring-primary/15",
36
+ upcoming: "mt-1 size-3 bg-muted-foreground/30",
37
+ error: "mt-1 size-3 bg-destructive ring-4 ring-destructive/15"
38
+ }
39
+ }.freeze
40
+
41
+ # Each colour's circle, then the ring it wears as the current item.
42
+ COLORS = {
43
+ blue: [ "bg-blue-600 text-white", "ring-4 ring-blue-600/20" ],
44
+ emerald: [ "bg-emerald-600 text-white", "ring-4 ring-emerald-600/20" ],
45
+ amber: [ "bg-amber-600 text-white", "ring-4 ring-amber-600/20" ],
46
+ violet: [ "bg-violet-600 text-white", "ring-4 ring-violet-600/20" ],
47
+ rose: [ "bg-rose-600 text-white", "ring-4 ring-rose-600/20" ],
48
+ teal: [ "bg-teal-600 text-white", "ring-4 ring-teal-600/20" ]
49
+ }.freeze
50
+
51
+ TITLE = {
52
+ complete: "text-foreground",
53
+ current: "text-foreground",
54
+ upcoming: "text-muted-foreground",
55
+ error: "text-destructive"
56
+ }.freeze
57
+
58
+ STATUS_TEXT = {
59
+ complete: "Completed",
60
+ current: "In progress",
61
+ upcoming: "Not started",
62
+ error: "Failed"
63
+ }.freeze
64
+
65
+ attr_reader :status, :title, :description, :icon
66
+
67
+ def initialize(title:, description: nil, time: nil, time_label: nil, status: :complete, icon: nil,
68
+ color: nil, class: nil, **html_attrs)
69
+ @title = title
70
+ @description = description
71
+ @time = time
72
+ @time_label = time_label
73
+ @status = STATUSES.include?(status&.to_sym) ? status.to_sym : :complete
74
+ @icon = icon
75
+ @color = color&.to_sym
76
+ @user_class = binding.local_variable_get(:class)
77
+ @html_attrs = html_attrs
78
+ end
79
+
80
+ def place(variant:, index:, last:)
81
+ @variant = variant
82
+ @index = index
83
+ @last = last
84
+ end
85
+
86
+ def dot? = @variant == :dot
87
+ def colored? = @variant == :colored && %i[complete current].include?(@status)
88
+ def color = COLORS.key?(@color) ? @color : COLORS.keys[@index % COLORS.size]
89
+ def connector? = !@last
90
+ def description? = @description.present?
91
+ def time? = @time.present?
92
+ def date? = @time.respond_to?(:iso8601)
93
+ def marker_icon = @icon || ICONS[@status]
94
+
95
+ def time_text
96
+ return @time_label if @time_label.present?
97
+
98
+ date? ? I18n.l(@time, format: :long) : @time.to_s
99
+ end
100
+
101
+ def item_attrs
102
+ attrs = @html_attrs.except(:data, :aria)
103
+ attrs[:class] = cn("relative flex min-w-0 gap-3", { "pb-6" => connector? }, @user_class)
104
+ attrs[:aria] = { current: ("step" if @status == :current) }.compact.merge(@html_attrs[:aria] || {})
105
+ attrs[:data] = { slot: "timeline-item", status: @status }.merge(@html_attrs[:data] || {})
106
+ attrs
107
+ end
108
+
109
+ def marker_classes
110
+ # A circle is taller than a line of text. Its overhang doesn't count towards
111
+ # the item's height, so the text alone sets the gap to the next item, however
112
+ # much text there is. The last item has nothing below to overhang into.
113
+ cn("relative z-10 flex shrink-0 items-center justify-center rounded-full", marker_look,
114
+ { "-mb-2" => !dot? && connector? })
115
+ end
116
+
117
+ def marker_look
118
+ return MARKER[dot? ? :dot : :default][@status] unless colored?
119
+
120
+ fill, ring = COLORS[color]
121
+ cn("size-8", fill, (ring if @status == :current))
122
+ end
123
+
124
+ # Unbroken from this marker to the next one, drawn in while the entry is done
125
+ # (a plain line between colours, which would clash with any one of them).
126
+ # A dot sits 0.25rem down its item, so the line runs that far into the next.
127
+ # Placed from the start edge so it follows the marker in a right-to-left page.
128
+ def connector_classes
129
+ cn("absolute w-0.5",
130
+ dot? ? "start-[calc(0.375rem-1px)] top-4 -bottom-1" : "start-[calc(1rem-1px)] top-8 bottom-0",
131
+ @status == :complete && @variant != :colored ? "bg-primary" : "bg-border")
132
+ end
133
+
134
+ def text_classes
135
+ cn("flex min-w-0 flex-1 flex-col gap-0.5", { "pt-1" => !dot? })
136
+ end
137
+
138
+ def title_classes
139
+ cn("text-sm font-medium", TITLE[@status])
140
+ end
141
+
142
+ def status_text
143
+ t("ui.timeline.#{@status}", default: STATUS_TEXT[@status])
144
+ end
145
+ end
@@ -0,0 +1 @@
1
+ <%= tag.ol(**root_attrs) do %><% items.each do |item| %><%= item %><% end %><% end %>
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # What happened, and what's still to come, as a list down the page: an order's
4
+ # progress, a product's stock history, an account's activity. UI::Stepper is
5
+ # for moving someone through a form; this only records.
6
+ #
7
+ # <%= render(UI::Timeline.new(label: "Order history")) do |timeline| %>
8
+ # <% timeline.with_item(title: "Paid", time: order.paid_at, icon: "credit-card") %>
9
+ # <% timeline.with_item(title: "Shipped", status: :current) do %>
10
+ # <%= link_to "Track parcel", order.tracking_url %>
11
+ # <% end %>
12
+ # <% timeline.with_item(title: "Delivered", status: :upcoming, time: "Expected Friday") %>
13
+ # <% end %>
14
+ #
15
+ # Items show in the order they're given, so newest-first is up to the caller.
16
+ # `variant: :default` draws a circle holding the item's icon or a mark for its
17
+ # status, `:dot` a small dot, for a long log, and `:colored` the same circles in
18
+ # a different colour each. Each item's options are on UI::Timeline::Item.
19
+ class UI::Timeline < UI::Base
20
+ VARIANTS = %i[default dot colored].freeze
21
+
22
+ renders_many :items, UI::Timeline::Item
23
+
24
+ def initialize(variant: :default, label: nil, class: nil, **html_attrs)
25
+ @variant = VARIANTS.include?(variant.to_sym) ? variant.to_sym : :default
26
+ @label = label
27
+ @user_class = binding.local_variable_get(:class)
28
+ @html_attrs = html_attrs
29
+ end
30
+
31
+ def before_render
32
+ items.each_with_index { |item, index| item.place(variant: @variant, index: index, last: index == items.size - 1) }
33
+ end
34
+
35
+ def root_attrs
36
+ attrs = @html_attrs.except(:data, :aria)
37
+ attrs[:class] = cn("flex w-full flex-col", @user_class)
38
+ attrs[:aria] = { label: @label || t("ui.timeline.label", default: "Timeline") }.merge(@html_attrs[:aria] || {})
39
+ attrs[:data] = { slot: "timeline", variant: @variant }.merge(@html_attrs[:data] || {})
40
+ attrs
41
+ end
42
+ end
@@ -43,14 +43,14 @@ class UI::Toast < UI::Base
43
43
  "text-popover-foreground shadow-lg pointer-events-auto duration-300 fill-mode-forwards " \
44
44
  "data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-bottom-2 " \
45
45
  "data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-bottom-2 " \
46
- "[&>i]:translate-y-0.5 [&>i]:shrink-0",
46
+ "[&>svg]:translate-y-0.5 [&>svg]:shrink-0",
47
47
  variants: {
48
48
  variant: {
49
- default: "[&>i]:text-muted-foreground",
50
- success: "[&>i]:text-emerald-600 dark:[&>i]:text-emerald-400",
51
- destructive: "[&>i]:text-destructive",
52
- warning: "[&>i]:text-amber-600 dark:[&>i]:text-amber-400",
53
- info: "[&>i]:text-sky-600 dark:[&>i]:text-sky-400"
49
+ default: "[&>svg]:text-muted-foreground",
50
+ success: "[&>svg]:text-emerald-600 dark:[&>svg]:text-emerald-400",
51
+ destructive: "[&>svg]:text-destructive",
52
+ warning: "[&>svg]:text-amber-600 dark:[&>svg]:text-amber-400",
53
+ info: "[&>svg]:text-sky-600 dark:[&>svg]:text-sky-400"
54
54
  }
55
55
  },
56
56
  defaults: { variant: :default }
@@ -0,0 +1 @@
1
+ <%= tag.label(**label_attrs) do %><%= tag.input(**input_attrs) %><% if icon? %><%= render(UI::Icon.new(name: @icon, size: icon_size)) %><% end %><% if text.present? %><%= tag.span text, class: ("sr-only" if icon_only?) %><% end %><% end %>