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
@@ -2,43 +2,64 @@
2
2
 
3
3
  require "securerandom"
4
4
 
5
- # UI::FileField — a drag-and-drop dropzone over a native file input.
5
+ # UI::FileField — a drag-and-drop dropzone over a native file input, with
6
+ # previews of what's chosen and, optionally, uploads straight to storage.
6
7
  #
7
- # The input itself is sr-only, not hidden: it stays in the accessibility
8
- # tree and keyboard/native-picker behavior (Tab, Enter/Space, the OS file
9
- # dialog) comes from the real <input type="file">, same as every other
10
- # styled-native-control component here. The dropzone is a <label> around it,
11
- # so clicking anywhere in it opens the picker without any JS, and the
12
- # ui--file-field controller only adds what a label can't: drag-over
13
- # highlighting and listing the chosen file names.
8
+ # <%= render(UI::FileField.new(form: f, field: :photos, multiple: true, accept: "image/*",
9
+ # max_size: 5.megabytes, direct_upload: true)) %>
10
+ #
11
+ # The input itself is sr-only, not hidden: it stays in the accessibility tree,
12
+ # and keyboard and the system file dialog come from the real
13
+ # <input type="file">. The dropzone is a <label> around it, so clicking
14
+ # anywhere in it opens the picker with no JavaScript.
15
+ #
16
+ # Each chosen file shows as a tile: a thumbnail for an image, an icon for
17
+ # anything else, its name and size, and a button to take it out again.
18
+ # `accept:` and `max_size:` (bytes) are checked as files are added, dropped
19
+ # ones included, and a file that fails says why instead of being sent.
20
+ # `preview: false` goes back to listing the names under the dropzone.
21
+ #
22
+ # `direct_upload: true` sends each file to storage the moment it's chosen,
23
+ # through Active Storage's direct uploads, with a progress bar on its tile; the
24
+ # form then submits only the uploaded files' signed ids, so a big photo never
25
+ # holds up the form. Sending the form while files are still uploading waits
26
+ # for them, then sends. It needs Active Storage's JavaScript and, for a bucket
27
+ # such as Cloudflare R2 or S3, CORS rules allowing PUT from your site.
28
+ #
29
+ # Bound to a form, the record's current attachments show as tiles too, kept by
30
+ # their signed ids, so removing a tile and saving removes that file.
14
31
  class UI::FileField < UI::Base
15
- def initialize(multiple: false, accept: nil,
32
+ def initialize(multiple: false, accept: nil, preview: true, direct_upload: false, max_size: nil,
16
33
  label: nil, label_size: :default, label_weight: :medium,
17
34
  hint: nil, required: false, error: nil, disabled: false,
18
- form: nil, field: nil,
35
+ form: nil, field: nil, existing: nil,
19
36
  class: nil, **html_attrs)
20
- @form = form
21
- @field = field
22
- @multiple = multiple
23
- @accept = accept
24
- @required = required
25
- @disabled = disabled
26
- @user_class = binding.local_variable_get(:class)
27
- @html_attrs = html_attrs
28
- @wrapper = UI::FormField.new(label: label, hint: hint, error: error,
29
- required: required, disabled: disabled,
30
- label_size: label_size, label_weight: label_weight,
31
- form: form, field: field)
32
- @input_id = @html_attrs[:id] || "ui-file-field-#{SecureRandom.hex(4)}"
37
+ @form = form
38
+ @field = field
39
+ @multiple = multiple
40
+ @accept = accept
41
+ @preview = preview
42
+ @direct_upload = direct_upload
43
+ @max_size = max_size
44
+ @existing = existing
45
+ @required = required
46
+ @disabled = disabled
47
+ @user_class = binding.local_variable_get(:class)
48
+ @html_attrs = html_attrs
49
+ @wrapper = UI::FormField.new(label: label, hint: hint, error: error,
50
+ required: required, disabled: disabled,
51
+ label_size: label_size, label_weight: label_weight,
52
+ form: form, field: field)
53
+ @input_id = @html_attrs[:id] || "ui-file-field-#{SecureRandom.hex(4)}"
33
54
  @html_attrs[:id] = @input_id
34
55
  @wrapper.for = @input_id
35
56
  end
36
57
 
37
58
  attr_reader :wrapper
38
59
 
39
- def form_field?
40
- @form.present? && @field.present?
41
- end
60
+ def form_field? = @form.present? && @field.present?
61
+ def preview? = @preview
62
+ def direct_upload? = @direct_upload
42
63
 
43
64
  def dropzone_classes
44
65
  cn(
@@ -51,6 +72,20 @@ class UI::FileField < UI::Base
51
72
  )
52
73
  end
53
74
 
75
+ def root_data
76
+ { controller: "ui--file-field",
77
+ "ui--file-field-preview-value": preview?,
78
+ "ui--file-field-direct-upload-value": direct_upload?,
79
+ "ui--file-field-url-value": (direct_upload_url if direct_upload?),
80
+ "ui--file-field-name-value": signed_id_name,
81
+ "ui--file-field-multiple-value": @multiple,
82
+ "ui--file-field-accept-value": @accept,
83
+ "ui--file-field-max-size-value": @max_size,
84
+ "ui--file-field-required-value": @required,
85
+ "ui--file-field-labels-value": labels.to_json,
86
+ action: "dragover->ui--file-field#dragOver dragleave->ui--file-field#dragLeave drop->ui--file-field#drop" }.compact
87
+ end
88
+
54
89
  def html_options
55
90
  opts = @html_attrs.dup
56
91
  opts[:type] = "file"
@@ -58,9 +93,10 @@ class UI::FileField < UI::Base
58
93
  opts[:multiple] = true if @multiple
59
94
  opts[:accept] = @accept if @accept
60
95
  opts[:disabled] = true if @disabled
61
- opts[:required] = true if @required
96
+ # A file already kept satisfies `required`; the controller keeps this in step.
97
+ opts[:required] = true if @required && existing_files.empty?
62
98
  opts[:"data-ui--file-field-target"] = "input"
63
- opts[:"data-action"] = "change->ui--file-field#updateNames"
99
+ opts[:"data-action"] = "change->ui--file-field#chosen"
64
100
  opts[:"aria-invalid"] = "true" if wrapper.error?
65
101
  opts[:"aria-describedby"] = wrapper.describedby if wrapper.describedby
66
102
  opts
@@ -70,4 +106,119 @@ class UI::FileField < UI::Base
70
106
  def form_field_options
71
107
  html_options.except(:name, :type)
72
108
  end
109
+
110
+ # ── Kept and uploaded files ──────────────────────────────────────────────
111
+
112
+ # Where a kept or uploaded file's signed id is posted: the field's own
113
+ # name, so Active Storage takes it like an upload.
114
+ def signed_id_name
115
+ name = form_field? ? "#{@form.object_name}[#{@field}]" : @html_attrs[:name].to_s
116
+ return name if name.empty?
117
+
118
+ @multiple && !name.end_with?("[]") ? "#{name}[]" : name
119
+ end
120
+
121
+ # The record's current attachments, or `existing:`: anything with a
122
+ # signed_id, filename, byte_size and content_type.
123
+ def existing_files
124
+ return [] unless preview?
125
+
126
+ @existing_files ||= Array(@existing.nil? ? bound_attachments : @existing).map do |file|
127
+ { signed_id: file.signed_id, name: file.filename.to_s, size: file.byte_size,
128
+ image: file.content_type.to_s.start_with?("image/"), url: file_url(file) }
129
+ end
130
+ end
131
+
132
+ def human_size(bytes) = ActiveSupport::NumberHelper.number_to_human_size(bytes)
133
+
134
+ def labels
135
+ { remove: t("ui.file_field.remove", default: "Remove %{name}"),
136
+ uploading: t("ui.file_field.uploading", default: "Uploading…"),
137
+ uploaded: t("ui.file_field.uploaded", default: "Uploaded"),
138
+ failed: t("ui.file_field.failed", default: "Upload failed"),
139
+ retry: t("ui.file_field.retry", default: "Try again"),
140
+ too_big: t("ui.file_field.too_big", default: "Too big: %{max} at most"),
141
+ max: (human_size(@max_size) if @max_size),
142
+ wrong_type: t("ui.file_field.wrong_type", default: "Not a file this field takes"),
143
+ waiting: t("ui.file_field.waiting", default: "Waiting for the uploads to finish…"),
144
+ added: t("ui.file_field.added", default: "%{name} added"),
145
+ removed: t("ui.file_field.removed", default: "%{name} removed"),
146
+ units: storage_units }
147
+ end
148
+
149
+ def tile_classes
150
+ "group relative flex min-w-0 flex-col overflow-hidden rounded-lg border bg-card text-card-foreground " \
151
+ "data-[state=error]:border-destructive"
152
+ end
153
+
154
+ # One file: its thumbnail or an icon, a button to take it out, a progress
155
+ # bar for an upload, its name and size, and the signed id that keeps it. The
156
+ # controller fills in a blank one for each file chosen.
157
+ def tile(name: "", size: nil, url: nil, image: false, signed_id: nil, state: "kept")
158
+ thumb = image && url.present?
159
+ tag.li(class: tile_classes, data: { "ui--file-field-target": "item", state: state }) do
160
+ safe_join([
161
+ tag.div(class: "relative aspect-square bg-muted") do
162
+ safe_join([
163
+ tag.img(src: url, alt: "", class: "size-full object-cover", hidden: !thumb, data: { role: "thumb" }),
164
+ tag.span(render(UI::Icon.new(name: "file", size: :lg)), hidden: thumb, data: { role: "icon" },
165
+ class: "absolute inset-0 flex items-center justify-center text-muted-foreground"),
166
+ tag.button(render(UI::Icon.new(name: "x", size: :xs)), type: "button",
167
+ aria: { label: labels[:remove].sub("%{name}", name.to_s) },
168
+ class: "absolute end-1.5 top-1.5 flex size-6 items-center justify-center rounded-full border bg-background/90 " \
169
+ "text-foreground shadow-sm hover:bg-background #{UI::Base::FOCUS_RING}",
170
+ data: { action: "ui--file-field#remove", role: "remove" }),
171
+ tag.div(tag.div(class: "h-full w-0 bg-primary transition-[width] duration-200", data: { role: "bar" }),
172
+ hidden: true, role: "progressbar", aria: { valuemin: 0, valuemax: 100, label: name },
173
+ class: "absolute inset-x-0 bottom-0 h-1 bg-foreground/10", data: { role: "progress" })
174
+ ])
175
+ end,
176
+ tag.div(class: "min-w-0 p-2") do
177
+ safe_join([
178
+ tag.p(name, title: name, class: "truncate text-xs font-medium", data: { role: "name" }),
179
+ tag.p(size ? human_size(size) : "", class: "line-clamp-2 text-xs text-muted-foreground group-data-[state=error]:text-destructive",
180
+ data: { role: "meta" }),
181
+ tag.button(labels[:retry], type: "button", hidden: true, data: { action: "ui--file-field#retry", role: "retry" },
182
+ class: "mt-1 rounded-sm text-xs font-medium text-primary underline-offset-4 hover:underline #{UI::Base::FOCUS_RING}")
183
+ ])
184
+ end,
185
+ (tag.input(type: "hidden", name: signed_id_name, value: signed_id, data: { role: "signed" }) if signed_id)
186
+ ])
187
+ end
188
+ end
189
+
190
+ private
191
+
192
+ # The units Rails' number_to_human_size uses, so a size written in the
193
+ # browser matches the ones written here.
194
+ def storage_units
195
+ units = I18n.t("number.human.storage_units.units", default: {})
196
+ { byte: (units[:byte].is_a?(Hash) ? units[:byte][:other] : units[:byte]) || "Bytes",
197
+ kb: units[:kb] || "KB", mb: units[:mb] || "MB", gb: units[:gb] || "GB" }
198
+ end
199
+
200
+ def bound_attachments
201
+ return [] unless form_field? && @form.object.respond_to?(@field)
202
+
203
+ value = @form.object.public_send(@field)
204
+ if value.respond_to?(:attachments) then value.attachments
205
+ elsif value.respond_to?(:attached?) && value.attached? then [ value.attachment ]
206
+ else []
207
+ end
208
+ end
209
+
210
+ # An Active Storage file is shown through the app's blob route; anything
211
+ # else passed as `existing:` brings its own url.
212
+ def file_url(file)
213
+ if defined?(ActiveStorage::Attachment) && file.is_a?(ActiveStorage::Attachment)
214
+ helpers.main_app.rails_blob_path(file)
215
+ else
216
+ file.try(:url)
217
+ end
218
+ end
219
+
220
+ def direct_upload_url
221
+ routes = helpers.respond_to?(:main_app) ? helpers.main_app : helpers
222
+ routes.respond_to?(:rails_direct_uploads_url) ? routes.rails_direct_uploads_url : "/rails/active_storage/direct_uploads"
223
+ end
73
224
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # One image in a UI::Gallery. Holds what the gallery needs to draw it in three
4
+ # places (the main view, its thumbnail and the zoomed view); it draws nothing
5
+ # itself.
6
+ class UI::Gallery::Image < UI::Base
7
+ attr_reader :src, :alt
8
+
9
+ def initialize(src:, alt:, zoom_src: nil, thumbnail_src: nil)
10
+ @src = src
11
+ @alt = alt
12
+ @zoom_src = zoom_src
13
+ @thumbnail_src = thumbnail_src
14
+ end
15
+
16
+ def zoom_src = @zoom_src || @src
17
+ def thumbnail_src = @thumbnail_src || @src
18
+
19
+ def call = nil
20
+ end
@@ -0,0 +1,52 @@
1
+ <%= tag.div(**root_attrs) do %>
2
+ <%= tag.div class: "relative min-w-0" do %>
3
+ <%= tag.ul class: track_classes, data: { "ui--gallery-target": "track", action: "scroll->ui--gallery#scrolled pointerdown->ui--gallery#released" } do %>
4
+ <% images.each_with_index do |image, index| %>
5
+ <%= tag.li class: slide_classes, data: { "ui--gallery-target": "slide", zoom_src: asset_path(image.zoom_src), alt: image.alt } do %>
6
+ <%= tag.button(**slide_button_attrs(image, index)) do %>
7
+ <%= render(UI::Image.new(src: image.src, alt: image.alt, rounded: :none, loading: image_loading(index), class: image_classes, draggable: "false")) %>
8
+ <%= tag.span class: "pointer-events-none absolute end-2 top-2 flex rounded-full bg-background/90 p-1.5 text-foreground", aria: { hidden: true } do %><%= render(UI::Icon.new(name: "zoom-in", size: :sm)) %><% end %>
9
+ <% end %>
10
+ <% end %>
11
+ <% end %>
12
+ <% end %>
13
+ <% if hover_zoom? %>
14
+ <%= tag.div aria: { hidden: true }, class: cn(UI::Gallery::HOVER_REVEAL, "left-0 top-0 z-10 rounded-sm border border-primary/50 bg-primary/15"), data: { "ui--gallery-target": "lens" } %>
15
+ <%= tag.div aria: { hidden: true }, class: cn(UI::Gallery::HOVER_REVEAL, "start-full top-0 z-50 ms-4 origin-[0_50%] scale-95 overflow-hidden rounded-lg border bg-background bg-no-repeat shadow-lg data-[inside]:start-0 data-[inside]:ms-0 data-[shown]:scale-100 rtl:origin-[100%_50%]"), data: { "ui--gallery-target": "pane" } %>
16
+ <% end %>
17
+ <% if multiple? %>
18
+ <%= render(UI::Button.new(**nav_button_attrs(:previous))) do %><%= render(UI::Icon.new(name: "chevron-left", size: :sm, class: "rtl:rotate-180")) %><% end %>
19
+ <%= render(UI::Button.new(**nav_button_attrs(:next))) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %>
20
+ <% end %>
21
+ <% end %>
22
+ <%= tag.p position_text, class: "sr-only", aria: { live: "polite" }, data: { "ui--gallery-target": "status" } %>
23
+ <% if multiple? %>
24
+ <%= tag.ul class: thumbnail_strip_classes do %>
25
+ <% images.each_with_index do |image, index| %>
26
+ <li class="shrink-0"><%= tag.button(**thumbnail_attrs(index)) do %><%= render(UI::Image.new(src: image.thumbnail_src, alt: "", rounded: :none, class: "size-full object-cover", draggable: "false")) %><% end %></li>
27
+ <% end %>
28
+ <% end %>
29
+ <% end %>
30
+ <%= tag.dialog class: dialog_classes, tabindex: -1,
31
+ aria: { label: t("ui.gallery.dialog", default: "Zoomed image") },
32
+ data: { "ui--gallery-target": "dialog", action: "close->ui--gallery#closed cancel->ui--gallery#cancel" } do %>
33
+ <%= tag.div class: viewport_classes,
34
+ data: { "ui--gallery-target": "viewport",
35
+ action: "click->ui--gallery#viewportClick pointerdown->ui--gallery#panStart pointermove->ui--gallery#panMove " \
36
+ "pointerup->ui--gallery#panEnd pointercancel->ui--gallery#panEnd wheel->ui--gallery#wheel" } do %>
37
+ <%= tag.img alt: "", draggable: "false",
38
+ class: "m-auto max-w-none shrink-0 cursor-zoom-in select-none group-data-[zoomed]/viewport:cursor-grab",
39
+ data: { "ui--gallery-target": "zoomImage", action: "load->ui--gallery#layout" } %>
40
+ <% end %>
41
+ <%= tag.p position_text, class: "sr-only", aria: { live: "polite" }, data: { "ui--gallery-target": "zoomStatus" } %>
42
+ <%= tag.div class: "absolute start-4 top-4 z-10 flex gap-2" do %>
43
+ <%= render(UI::Button.new(**zoom_button_attrs(:out, "Zoom out"))) do %><%= render(UI::Icon.new(name: "zoom-out", size: :sm)) %><% end %>
44
+ <%= render(UI::Button.new(**zoom_button_attrs(:in, "Zoom in"))) do %><%= render(UI::Icon.new(name: "zoom-in", size: :sm)) %><% end %>
45
+ <% end %>
46
+ <%= render(UI::Button.new(variant: :ghost, size: :icon, class: cn(UI::Gallery::OVERLAY_BUTTON, "absolute end-4 top-4 z-10"), aria: { label: t("ui.gallery.close", default: "Close") }, data: { action: "ui--gallery#close" })) do %><%= render(UI::Icon.new(name: "x", size: :sm)) %><% end %>
47
+ <% if multiple? %>
48
+ <%= render(UI::Button.new(**overlay_nav_attrs(:previous))) do %><%= render(UI::Icon.new(name: "chevron-left", size: :sm, class: "rtl:rotate-180")) %><% end %>
49
+ <%= render(UI::Button.new(**overlay_nav_attrs(:next))) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %>
50
+ <% end %>
51
+ <% end %>
52
+ <% end %>
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A product's photos: one large image, thumbnails to pick another, and two ways
4
+ # to look closer.
5
+ #
6
+ # <%= render(UI::Gallery.new(label: "Photos of the ceramic mug")) do |gallery| %>
7
+ # <% gallery.with_image(src: "mug.jpg", alt: "Mug, front", zoom_src: "mug-2000.jpg", thumbnail_src: "mug-160.jpg") %>
8
+ # <% gallery.with_image(src: "mug-side.jpg", alt: "Mug, from the side") %>
9
+ # <% end %>
10
+ #
11
+ # The main view is a scroll-snap strip, so it swipes on a touch screen with no
12
+ # script involved. Previous and next wrap round, and arrow keys do the same.
13
+ # Only the first image loads with the page. `zoom_src:` and `thumbnail_src:` are
14
+ # optional, and worth giving: the zoomed image only downloads when someone opens
15
+ # it, so it can be much larger than `src:`.
16
+ #
17
+ # Clicking the image opens it by itself over the dimmed page, with zoom and close
18
+ # in the top corners and previous and next at the sides. There, clicking zooms in
19
+ # on that spot and clicking again zooms out; so do the buttons, the + and - keys,
20
+ # 0 to reset, and pinching a trackpad. A zoomed image pans by dragging or
21
+ # scrolling. Clicking outside it or pressing Escape closes it. The image grows
22
+ # out of its place on the page and returns there, and all the movement stops for
23
+ # anyone whose system asks for reduced motion.
24
+ #
25
+ # `zoom: :hover` adds what big shops do: moving a mouse over the image shows a
26
+ # lens on it and that part magnified beside it, `zoom_scale:` times over (2.5 by
27
+ # default). With no room beside it, the magnified part shows over the image. A
28
+ # click still opens the overlay, which is also what touch screens and the
29
+ # keyboard get, having no mouse to hover with.
30
+ #
31
+ # `aspect:` is :square, :landscape or :portrait, and `fit:` is :contain (the whole
32
+ # photo) or :cover (fills the frame, cropping). A single image gets no thumbnails
33
+ # or arrows.
34
+ class UI::Gallery < UI::Base
35
+ ASPECTS = { square: "aspect-square", landscape: "aspect-video", portrait: "aspect-[4/5]" }.freeze
36
+ FITS = { contain: "object-contain", cover: "object-cover" }.freeze
37
+ ZOOMS = %i[overlay hover].freeze
38
+
39
+ HIDE_SCROLLBAR = "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
40
+
41
+ # The lens and pane fade in and out, rather than blinking on and off with `hidden`.
42
+ HOVER_REVEAL = "pointer-events-none invisible absolute opacity-0 transition-[opacity,scale,visibility] duration-150 " \
43
+ "data-[shown]:visible data-[shown]:opacity-100 motion-reduce:transition-none"
44
+
45
+ # Always light on the dark backdrop, whatever the page's theme, ring included.
46
+ # The border keeps them in sight on a dark page, where the backdrop is black too.
47
+ OVERLAY_BUTTON = "rounded-full border border-white/25 bg-black/60 text-white hover:bg-black/80 hover:text-white " \
48
+ "focus:ring-white disabled:bg-black/60! disabled:text-white/50!"
49
+
50
+ renders_many :images, UI::Gallery::Image
51
+
52
+ def initialize(label: nil, aspect: :square, fit: :contain, zoom: :overlay, zoom_scale: 2.5, class: nil, **html_attrs)
53
+ @label = label
54
+ @aspect = ASPECTS.key?(aspect.to_sym) ? aspect.to_sym : :square
55
+ @fit = FITS.key?(fit.to_sym) ? fit.to_sym : :contain
56
+ @zoom = ZOOMS.include?(zoom.to_sym) ? zoom.to_sym : :overlay
57
+ @zoom_scale = zoom_scale
58
+ @user_class = binding.local_variable_get(:class)
59
+ @html_attrs = html_attrs
60
+ end
61
+
62
+ def render? = images.any?
63
+ def multiple? = images.size > 1
64
+ def hover_zoom? = @zoom == :hover
65
+
66
+ def root_attrs
67
+ attrs = @html_attrs.except(:data, :aria)
68
+ attrs[:role] = "group"
69
+ attrs[:class] = cn("flex w-full min-w-0 flex-col gap-3", @user_class)
70
+ attrs[:aria] = { label: label, roledescription: t("ui.gallery.roledescription", default: "gallery") }
71
+ .merge(@html_attrs[:aria] || {})
72
+ attrs[:data] = { slot: "gallery", controller: "ui--gallery", zoom: @zoom,
73
+ "ui--gallery-zoom-scale-value": @zoom_scale,
74
+ "ui--gallery-position-value": position_format,
75
+ action: "keydown@window->ui--gallery#keydown resize@window->ui--gallery#layout" }
76
+ .merge(@html_attrs[:data] || {})
77
+ attrs
78
+ end
79
+
80
+ def track_classes
81
+ cn("flex snap-x snap-mandatory overflow-x-auto rounded-lg bg-muted", HIDE_SCROLLBAR)
82
+ end
83
+
84
+ def slide_classes = cn("w-full shrink-0 snap-center", ASPECTS[@aspect])
85
+
86
+ def slide_button_attrs(image, index)
87
+ # One tab stop for the strip: the image showing. The rest are out of sight.
88
+ { type: "button", tabindex: index.zero? ? 0 : -1,
89
+ class: cn("group/slide relative block size-full rounded-lg transition-all focus:outline-none",
90
+ "focus:ring-2 focus:ring-inset focus:ring-primary", hover_zoom? ? "cursor-crosshair" : "cursor-zoom-in"),
91
+ aria: { label: phrase(t("ui.gallery.zoom", default: "Zoom image %{current}: %{alt}"), current: index + 1, alt: image.alt),
92
+ haspopup: "dialog" },
93
+ data: { action: slide_action, "ui--gallery-index-param": index } }
94
+ end
95
+
96
+ # Covers the window with nothing of its own: only the image and its buttons sit
97
+ # on the backdrop.
98
+ def dialog_classes
99
+ "m-0 size-full max-h-none max-w-none overflow-hidden bg-transparent p-0 outline-none backdrop:bg-black/80"
100
+ end
101
+
102
+ def viewport_classes
103
+ cn("group/viewport absolute inset-0 flex overflow-auto overscroll-contain", HIDE_SCROLLBAR)
104
+ end
105
+
106
+ def image_classes = cn("size-full", FITS[@fit])
107
+
108
+ # Only the first image loads with the page. The rest wait to be scrolled to.
109
+ def image_loading(index) = index.zero? ? :eager : :lazy
110
+
111
+ # The padding leaves room for the focus ring, and the margin takes it back, so
112
+ # the first thumbnail lines up with the edge of the image.
113
+ def thumbnail_strip_classes = cn("-mx-1 flex gap-2 overflow-x-auto p-1", HIDE_SCROLLBAR)
114
+
115
+ def thumbnail_attrs(index)
116
+ { type: "button",
117
+ class: cn("block size-16 shrink-0 overflow-hidden rounded-md border-2 border-transparent opacity-70 hover:opacity-100",
118
+ "aria-current:border-primary aria-current:opacity-100", UI::Base::FOCUS_RING),
119
+ aria: { label: phrase(t("ui.gallery.thumbnail", default: "Show image %{current}"), current: index + 1),
120
+ current: ("true" if index.zero?) }.compact,
121
+ data: { action: "ui--gallery#select", "ui--gallery-index-param": index, "ui--gallery-target": "thumbnail" } }
122
+ end
123
+
124
+ def nav_button_attrs(direction)
125
+ edge = direction == :previous ? "start-2" : "end-2"
126
+ { variant: :outline, size: :icon,
127
+ class: cn("absolute top-1/2 z-10 hidden -translate-y-1/2 rounded-full bg-background/90 sm:inline-flex", edge),
128
+ aria: { label: nav_label(direction) }, data: { action: "ui--gallery##{direction}" } }
129
+ end
130
+
131
+ def overlay_nav_attrs(direction)
132
+ edge = direction == :previous ? "start-4" : "end-4"
133
+ { variant: :ghost, size: :icon,
134
+ class: cn(OVERLAY_BUTTON, "absolute top-1/2 z-10 -translate-y-1/2", edge),
135
+ aria: { label: nav_label(direction) }, data: { action: "ui--gallery##{direction}" } }
136
+ end
137
+
138
+ def zoom_button_attrs(direction, label)
139
+ { variant: :ghost, size: :icon, class: OVERLAY_BUTTON,
140
+ aria: { label: t("ui.gallery.zoom_#{direction}", default: label) },
141
+ data: { action: "ui--gallery#zoom#{direction.to_s.capitalize}", "ui--gallery-target": "zoom#{direction.to_s.capitalize}" } }
142
+ end
143
+
144
+ def position_text = phrase(position_format, current: 1, total: images.size)
145
+
146
+ private
147
+
148
+ def nav_label(direction) = t("ui.gallery.#{direction}", default: "#{direction.to_s.capitalize} image")
149
+
150
+ def slide_action
151
+ return "ui--gallery#open" unless hover_zoom?
152
+
153
+ "ui--gallery#open pointerenter->ui--gallery#hover pointermove->ui--gallery#hover pointerleave->ui--gallery#hoverEnd"
154
+ end
155
+
156
+ def label = @label || t("ui.gallery.label", default: "Image gallery")
157
+ def position_format = t("ui.gallery.position", default: "Image %{current} of %{total}")
158
+
159
+ # Filled in here rather than by t(), so the controller can be handed the same
160
+ # text with its placeholders still in it.
161
+ def phrase(format, **values)
162
+ values.reduce(format) { |text, (key, value)| text.sub("%{#{key}}", value.to_s) }
163
+ end
164
+ end
@@ -1 +1 @@
1
- <%= tag.i data: (@html_attrs[:data] || {}).merge(lucide: @name), class: classes, aria: aria_attributes, **@html_attrs.except(:data) %>
1
+ <%= svg_tag %>
@@ -1,5 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # UI::Icon — an SVG icon, drawn into the page on the server.
4
+ #
5
+ # Each icon is a file in app/assets/icons, named as your icon library names
6
+ # it: `UI::Icon.new(name: "rocket")` draws app/assets/icons/rocket.svg. The
7
+ # library is the one in config/velvetkit.yml; `velvetkit:add` copies the
8
+ # icons the components draw, and this adds any other:
9
+ #
10
+ # bin/rails generate velvetkit:icons rocket user
11
+ #
12
+ # There is no JavaScript and nothing to register. An icon with no file draws
13
+ # a dashed square (nothing in production) and logs which file is missing.
14
+ #
15
+ # name: the file's name, without .svg
16
+ # size: xs, sm, default, lg or xl
17
+ # label: makes it an image with this accessible name; without one it is
18
+ # decorative and hidden from assistive technology
19
+ #
20
+ # To keep the SVGs somewhere else, set `config.x.velvetkit.icons_path`.
3
21
  class UI::Icon < UI::Base
4
22
  variants(
5
23
  base: "inline-block shrink-0",
@@ -15,27 +33,81 @@ class UI::Icon < UI::Base
15
33
  defaults: { size: :default }
16
34
  )
17
35
 
36
+ # Shown in place of an icon with no file, outside production.
37
+ MISSING = { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2",
38
+ "stroke-dasharray": "3 3", inner: '<rect x="3" y="3" width="18" height="18" rx="2"/>' }.freeze
39
+
40
+ class << self
41
+ def path
42
+ Rails.configuration.x.velvetkit.icons_path || Rails.root.join("app/assets/icons")
43
+ end
44
+
45
+ # The SVG's attributes and markup, or nil if there's no such file. The
46
+ # library's own size and class are dropped: the component sets those.
47
+ def svg(name)
48
+ return unless name.match?(/\A[\w-]+\z/) # a file name, never a path
49
+
50
+ cache = Rails.configuration.cache_classes ? (@svgs ||= {}) : {}
51
+ cache.fetch(name) do
52
+ file = File.join(path, "#{name}.svg")
53
+ next unless File.file?(file)
54
+
55
+ cache[name] = parse(File.read(file))
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def parse(source)
62
+ open_tag, inner = source.gsub(/<!--.*?-->/m, "").match(%r{<svg\b([^>]*)>(.*)</svg>}m)&.captures
63
+ return unless open_tag
64
+
65
+ attributes = open_tag.scan(/([\w:-]+)\s*=\s*"([^"]*)"/).to_h.except("width", "height", "class")
66
+ { attributes: attributes.freeze, inner: inner.gsub(/>\s+</, "><").strip.freeze }.freeze
67
+ end
68
+ end
69
+
18
70
  def initialize(name:, size: :default, label: nil, class: nil, **html_attrs)
19
- @name = name
71
+ @name = name.to_s
20
72
  @size = size
21
73
  @label = label
22
74
  @user_class = binding.local_variable_get(:class)
23
75
  @html_attrs = html_attrs
24
76
  end
25
77
 
78
+ attr_reader :name
79
+
26
80
  def render?
27
81
  @name.present?
28
82
  end
29
83
 
30
- def classes
31
- cn(variant_classes(size: @size), @user_class)
84
+ def svg_tag
85
+ svg = self.class.svg(@name) || missing
86
+ tag.svg(
87
+ svg[:inner].html_safe, # the app's own SVG files
88
+ **svg[:attributes].symbolize_keys,
89
+ **@html_attrs.except(:data, :aria),
90
+ class: cn(variant_classes(size: @size), @user_class),
91
+ data: (@html_attrs[:data] || {}).merge(icon: @name),
92
+ aria: aria_attributes,
93
+ role: (accessible_name ? "img" : nil)
94
+ )
95
+ end
96
+
97
+ private
98
+
99
+ def accessible_name
100
+ @label || @html_attrs.dig(:aria, :label)
32
101
  end
33
102
 
34
103
  def aria_attributes
35
- if @label
36
- { label: @label }
37
- else
38
- { hidden: true }
39
- end
104
+ (accessible_name ? { label: accessible_name } : { hidden: true }).merge(@html_attrs[:aria] || {})
105
+ end
106
+
107
+ def missing
108
+ Rails.logger&.warn("[UI::Icon] no #{@name}.svg in #{self.class.path}: bin/rails generate velvetkit:icons #{@name}")
109
+ return { attributes: { "data-icon-missing" => "" }, inner: "" } if Rails.env.production?
110
+
111
+ { attributes: MISSING.except(:inner).transform_keys(&:to_s).merge("data-icon-missing" => ""), inner: MISSING[:inner] }
40
112
  end
41
113
  end
@@ -0,0 +1,27 @@
1
+ <%# frozen_string_literal: true %>
2
+ <%= tag.kbd(**root_attrs) do %>
3
+ <% if written? %>
4
+ <%= tag.kbd(content, class: key_class) %>
5
+ <% else %>
6
+ <% steps.each_with_index do |combo, step| %>
7
+ <% if step.positive? %><span class="text-[0.85em] opacity-70"><%= t("ui.kbd.then", default: "then") %></span><% end %>
8
+ <span class="inline-flex items-center gap-0.5">
9
+ <% combo.each_with_index do |key, index| %>
10
+ <% if index.positive? %><span class="opacity-60 group-data-[platform=mac]/kbd:hidden" aria-hidden="true">+</span><% end %>
11
+ <% mac, mac_name, other, other_name = key_labels(key, combo) %>
12
+ <% linux, linux_name = linux_labels(key) %>
13
+ <% if linux %>
14
+ <%= key_tag(mac, mac_name, "hidden group-data-[platform=mac]/kbd:inline-flex") %>
15
+ <%= key_tag(other, other_name, "group-data-[platform=mac]/kbd:hidden group-data-[platform=linux]/kbd:hidden") %>
16
+ <%= key_tag(linux, linux_name, "hidden group-data-[platform=linux]/kbd:inline-flex") %>
17
+ <% elsif mac == other && mac_name == other_name %>
18
+ <%= key_tag(mac, mac_name) %>
19
+ <% else %>
20
+ <%= key_tag(mac, mac_name, "hidden group-data-[platform=mac]/kbd:inline-flex") %>
21
+ <%= key_tag(other, other_name, "group-data-[platform=mac]/kbd:hidden") %>
22
+ <% end %>
23
+ <% end %>
24
+ </span>
25
+ <% end %>
26
+ <% end %>
27
+ <% end %>