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
@@ -49,11 +49,14 @@
49
49
  --ring: var(--primary);
50
50
  --chart-pie-active: oklch(0.9137 0.1511 150.96);
51
51
  --chart-pie-inactive: oklch(0.3533 0.0096 164.42);
52
- --chart-1: oklch(0.646 0.222 41.116);
53
- --chart-2: oklch(0.6 0.118 184.704);
54
- --chart-3: oklch(0.398 0.07 227.392);
55
- --chart-4: oklch(0.828 0.189 84.429);
56
- --chart-5: oklch(0.769 0.188 70.08);
52
+ /* Chart series, in this order: velvet, orange, aqua, blue, magenta. Checked
53
+ with a colour-vision validator so neighbours stay apart for colour-blind
54
+ readers; dark mode keeps the same hues, stepped for the dark surface. */
55
+ --chart-1: #793cbb;
56
+ --chart-2: #eb6834;
57
+ --chart-3: #1baf7a;
58
+ --chart-4: #2a78d6;
59
+ --chart-5: #e87ba4;
57
60
  --sidebar: oklch(0.985 0.001 286.32);
58
61
  --sidebar-foreground: oklch(0.141 0.005 285.823);
59
62
  /* Accent for the active nav item; lighter in dark so it clears AA against
@@ -93,11 +96,11 @@
93
96
  --ring: var(--primary);
94
97
  --chart-pie-active: oklch(0.696 0.17 162.48);
95
98
  --chart-pie-inactive: oklch(0.556 0 0);
96
- --chart-1: oklch(0.488 0.243 264.376);
97
- --chart-2: oklch(0.696 0.17 162.48);
98
- --chart-3: oklch(0.769 0.188 70.08);
99
- --chart-4: oklch(0.627 0.265 303.9);
100
- --chart-5: oklch(0.645 0.246 16.439);
99
+ --chart-1: #9362d3;
100
+ --chart-2: #d95926;
101
+ --chart-3: #199e70;
102
+ --chart-4: #3987e5;
103
+ --chart-5: #d55181;
101
104
  --sidebar: oklch(0.21 0.006 285.885);
102
105
  --sidebar-foreground: oklch(0.985 0 0);
103
106
  --sidebar-primary: oklch(0.7 0.15 301.6);
@@ -184,159 +187,91 @@ select:-webkit-autofill {
184
187
  transition: background-color 100000s ease-in-out 0s;
185
188
  }
186
189
 
187
- /* The date picker calendar.
188
- *
189
- * Cally renders in a shadow root, so it is reachable only through the custom
190
- * properties and ::part() names it publishes. All of them are pointed at the
191
- * kit's tokens, which is what makes the calendar follow dark mode with no
192
- * JavaScript.
193
- *
194
- * Layout: ‹ [May ▾] [2012 ▾] › in one header row. The selects sit in Cally's
195
- * heading slot (see date_picker.html.erb), so its own heading and the month's
196
- * heading would only repeat them.
190
+ /* The date picker's calendar: Vanilla Calendar Pro, with its light theme's
191
+ * colours pointed at the kit's tokens. The theme reads every colour from a
192
+ * --vc-* variable, so these follow dark mode and any retheme with no
193
+ * JavaScript. The library's own stylesheet loads with it (vanilla_calendar.ts),
194
+ * so a page without a date picker pays nothing for these.
197
195
  */
198
- calendar-date,
199
- calendar-range {
200
- --color-accent: var(--primary);
201
- --color-text-on-accent: var(--primary-foreground);
196
+ .velvetkit-calendar {
197
+ --vc-bg: var(--popover);
198
+ --vc-color: var(--popover-foreground);
199
+ --vc-header-color: var(--popover-foreground);
200
+ --vc-title-color: var(--popover-foreground);
201
+ --vc-title-color-hover: var(--muted-foreground);
202
+ --vc-title-color-disabled: var(--muted-foreground);
203
+ --vc-focus-outline-color: var(--ring);
204
+ --vc-week-day-color: var(--muted-foreground);
205
+ --vc-week-day-color-hover: var(--foreground);
206
+ --vc-week-day-off-color: var(--muted-foreground);
207
+ --vc-week-day-off-color-hover: var(--foreground);
208
+ --vc-date-bg: transparent;
209
+ --vc-date-color: var(--popover-foreground);
210
+ --vc-date-bg-hover: var(--accent);
211
+ --vc-date-hover-bg: var(--accent);
212
+ --vc-date-hover-edge-bg: color-mix(in oklab, var(--primary) 20%, transparent);
213
+ --vc-date-outside-color: var(--muted-foreground);
214
+ --vc-date-disabled-color: color-mix(in oklab, var(--muted-foreground) 50%, transparent);
215
+ --vc-date-today-bg: var(--accent);
216
+ --vc-date-today-color: var(--primary);
217
+ --vc-date-today-outside-color: var(--muted-foreground);
218
+ --vc-date-selected-bg: var(--primary);
219
+ --vc-date-selected-color: var(--primary-foreground);
220
+ --vc-date-selected-outside-bg: color-mix(in oklab, var(--primary) 20%, transparent);
221
+ --vc-date-selected-outside-color: var(--muted-foreground);
222
+ /* The days inside a range: a tint, so the two ends stand out. */
223
+ --vc-date-range-middle-bg: color-mix(in oklab, var(--primary) 12%, transparent);
224
+ --vc-date-range-middle-color: var(--popover-foreground);
225
+ --vc-date-range-middle-outside-bg: color-mix(in oklab, var(--primary) 6%, transparent);
226
+ --vc-date-range-middle-outside-color: var(--muted-foreground);
227
+ --vc-date-range-middle-weekend-bg: var(--vc-date-range-middle-bg);
228
+ --vc-date-range-middle-weekend-color: var(--vc-date-range-middle-color);
229
+ --vc-date-range-tooltip-bg: var(--popover);
230
+ --vc-date-range-tooltip-color: var(--muted-foreground);
231
+ --vc-date-popup-bg: var(--popover);
232
+ --vc-date-popup-color: var(--popover-foreground);
233
+ /* Weekends look like any other day: in a shop, Saturday is a working day. */
234
+ --vc-date-weekend-color: var(--vc-date-color);
235
+ --vc-date-weekend-bg-hover: var(--accent);
236
+ --vc-date-weekend-hover-bg: var(--accent);
237
+ --vc-date-weekend-hover-edge-bg: var(--vc-date-hover-edge-bg);
238
+ --vc-date-weekend-selected-bg: var(--primary);
239
+ --vc-date-weekend-selected-color: var(--primary-foreground);
240
+ --vc-date-weekend-today-color: var(--primary);
241
+ --vc-date-weekend-outside-color: var(--muted-foreground);
242
+ --vc-date-weekend-outside-bg: transparent;
243
+ --vc-date-weekend-outside-bg-hover: var(--accent);
244
+ --vc-date-weekend-outside-hover-bg: var(--accent);
245
+ --vc-date-weekend-disabled-color: var(--vc-date-disabled-color);
246
+ --vc-date-weekend-disabled-outside-color: var(--vc-date-disabled-color);
247
+ --vc-date-weekend-today-disabled-color: var(--vc-date-disabled-color);
248
+ --vc-date-weekend-today-outside-color: var(--muted-foreground);
249
+ --vc-months-years-bg: transparent;
250
+ --vc-months-years-bg-hover: var(--accent);
251
+ --vc-months-years-bg-selected: var(--primary);
252
+ --vc-months-years-color: var(--popover-foreground);
253
+ --vc-months-years-color-selected: var(--primary-foreground);
254
+ --vc-months-years-color-disabled: var(--vc-date-disabled-color);
255
+ --vc-collapse-color: var(--border);
202
256
  font-family: inherit;
203
- font-size: 0.875rem;
204
- color: var(--popover-foreground);
205
- }
206
-
207
- calendar-date::part(header),
208
- calendar-range::part(header) {
209
- display: flex;
210
- align-items: center;
211
- justify-content: space-between;
212
- gap: 0.25rem;
213
- margin-bottom: 0.5rem;
214
- }
215
-
216
- /* The arrows: ghost icon buttons. */
217
- calendar-date::part(button),
218
- calendar-range::part(button) {
219
- display: inline-grid;
220
- place-items: center;
221
- width: 2rem;
222
- height: 2rem;
223
- padding: 0;
224
- border: 0;
225
- border-radius: var(--radius-md);
226
- background: transparent;
227
- color: var(--muted-foreground);
228
- cursor: pointer;
229
- }
230
-
231
- calendar-date::part(button):hover,
232
- calendar-range::part(button):hover {
233
- background: var(--accent);
234
- color: var(--accent-foreground);
235
- }
236
-
237
- calendar-date::part(button):focus-visible,
238
- calendar-range::part(button):focus-visible {
239
- outline: 2px solid var(--ring);
240
- outline-offset: 1px;
241
- }
242
-
243
- calendar-date::part(disabled),
244
- calendar-range::part(disabled) {
245
- opacity: 0.35;
246
- cursor: default;
247
- }
248
-
249
- calendar-month::part(heading) {
250
- display: none;
251
- }
252
-
253
- calendar-month::part(th) {
254
- padding-bottom: 0.25rem;
255
- font-size: 0.75rem;
256
- font-weight: 500;
257
- color: var(--muted-foreground);
258
257
  }
259
258
 
260
- /* Days. */
261
- calendar-month::part(button) {
262
- width: 2.25rem;
263
- height: 2.25rem;
264
- border: 0;
265
- border-radius: var(--radius-md);
266
- background: transparent;
267
- color: var(--popover-foreground);
268
- font-size: 0.875rem;
269
- cursor: pointer;
270
- }
271
-
272
- calendar-month::part(button):hover {
273
- background: var(--accent);
274
- color: var(--accent-foreground);
275
- }
276
-
277
- calendar-month::part(button):focus-visible {
278
- outline: 2px solid var(--ring);
279
- outline-offset: 1px;
280
- }
281
-
282
- calendar-month::part(outside) {
283
- color: var(--muted-foreground);
284
- opacity: 0.6;
285
- }
286
-
287
- /* Today: a quiet tint rather than a hard box. */
288
- calendar-month::part(today) {
289
- outline: none;
290
- background: var(--accent);
291
- color: var(--primary);
292
- font-weight: 600;
293
- }
294
-
295
- /* The chosen day, after today so it wins when they're the same. */
296
- calendar-month::part(selected) {
297
- background: var(--primary);
298
- color: var(--primary-foreground);
299
- font-weight: 600;
300
- }
301
-
302
- /* Month and year: the reason this library was chosen, since reaching a birth
303
- year is one click rather than a hundred and seventy. Styled like the kit's
304
- fields; the open list is the platform's own. */
305
- calendar-select-month::part(select),
306
- calendar-select-year::part(select) {
307
- appearance: none;
308
- height: 2rem;
309
- padding: 0 1.75rem 0 0.625rem;
310
- border: 1px solid var(--input);
311
- border-radius: var(--radius-md);
312
- background: var(--background)
313
- url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8a93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
314
- no-repeat right 0.5rem center / 0.875rem;
315
- color: var(--foreground);
316
- font: inherit;
317
- font-size: 0.875rem;
318
- font-weight: 500;
319
- cursor: pointer;
259
+ .velvetkit-calendar .vc {
260
+ font-family: inherit;
320
261
  }
321
262
 
322
- calendar-select-month::part(select):hover,
323
- calendar-select-year::part(select):hover {
324
- background-color: var(--accent);
263
+ /* Only the two ends of a range are bold. */
264
+ .velvetkit-calendar [data-vc-date-selected="middle"] .vc-date__btn {
265
+ font-weight: 400;
325
266
  }
326
267
 
327
- calendar-select-month::part(select):focus-visible,
328
- calendar-select-year::part(select):focus-visible {
329
- outline: 2px solid var(--ring);
330
- outline-offset: 1px;
268
+ /* The arrows are drawn dark by the theme; lighten them on a dark page. */
269
+ .dark .velvetkit-calendar .vc-arrow::before {
270
+ filter: invert(1);
331
271
  }
332
272
 
333
- /* The "Month" and "Year" labels stay for screen readers only. */
334
- calendar-select-month::part(label),
335
- calendar-select-year::part(label) {
336
- position: absolute;
337
- width: 1px;
338
- height: 1px;
339
- overflow: hidden;
340
- clip-path: inset(50%);
341
- white-space: nowrap;
273
+ /* UI::Progress with no value: a short bar sliding across the track. */
274
+ @keyframes velvetkit-progress {
275
+ from { transform: translateX(-100%); }
276
+ to { transform: translateX(250%); }
342
277
  }
@@ -12,7 +12,7 @@ class UI::Alert < UI::Base
12
12
  variants(
13
13
  base: "relative w-full rounded-md border p-4 " \
14
14
  "flex items-start gap-3 " \
15
- "[&>i]:translate-y-0.5 [&>i]:shrink-0",
15
+ "[&>svg]:translate-y-0.5 [&>svg]:shrink-0",
16
16
  variants: {
17
17
  variant: {
18
18
  default: "bg-background text-foreground border-input",
@@ -0,0 +1,47 @@
1
+ <%= tag.div(**root_attrs) do %>
2
+ <%= tag.div class: body_classes do %>
3
+ <% if legend? %>
4
+ <%= tag.ul class: legend_classes, aria: { hidden: true } do %>
5
+ <% if circular? %>
6
+ <% slices.each do |slice| %>
7
+ <li class="flex items-center gap-2"><%= tag.span class: slice_swatch(slice) %><span class="min-w-0 flex-1 break-words text-muted-foreground"><%= slice.label %></span><span class="font-medium tabular-nums"><%= slice.text %></span><span class="w-10 text-end tabular-nums text-muted-foreground"><%= slice.share %></span></li>
8
+ <% end %>
9
+ <% else %>
10
+ <% series.each do |entry| %>
11
+ <li class="flex items-center gap-2"><%= tag.span class: swatch_classes(entry) %><%= entry.name %></li>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
15
+ <% end %>
16
+ <%= tag.div class: frame_classes, style: frame_style do %>
17
+ <%= tag.canvas(**canvas_attrs) %>
18
+ <%# It glides from point to point and fades in and out, rather than jumping. %>
19
+ <%= tag.div aria: { hidden: true }, data: { "ui--chart-target": "tooltip" },
20
+ class: "pointer-events-none invisible absolute left-0 top-0 z-10 min-w-32 rounded-md border bg-popover px-3 py-2 text-xs text-popover-foreground opacity-0 shadow-md transition-[opacity,transform,visibility] duration-150 ease-out data-[shown]:visible data-[shown]:opacity-100 motion-reduce:transition-none" %>
21
+ <% end %>
22
+ <% end %>
23
+ <details class="group/data text-sm">
24
+ <%= tag.summary t("ui.chart.show_data", default: "Show the data"), class: "w-fit cursor-pointer rounded-sm text-muted-foreground hover:text-foreground #{UI::Base::FOCUS_RING}" %>
25
+ <div class="mt-2 overflow-x-auto">
26
+ <table class="w-full text-sm tabular-nums">
27
+ <%= tag.caption label, class: "sr-only" %>
28
+ <thead>
29
+ <tr class="border-b">
30
+ <%= tag.th t("ui.chart.category", default: "Category"), scope: "col", class: "py-2 pe-4 text-start font-medium text-muted-foreground" %>
31
+ <% series.each do |entry| %><%= tag.th entry.name, scope: "col", class: "py-2 ps-4 text-end font-medium text-muted-foreground" %><% end %>
32
+ <% if circular? %><%= tag.th t("ui.chart.share", default: "Share"), scope: "col", class: "py-2 ps-4 text-end font-medium text-muted-foreground" %><% end %>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ <% labels.each_with_index do |row, index| %>
37
+ <tr class="border-b last:border-0">
38
+ <%= tag.th row, scope: "row", class: "py-2 pe-4 text-start font-normal" %>
39
+ <% series.each do |entry| %><%= tag.td formatted(entry.data[index]), class: "py-2 ps-4 text-end" %><% end %>
40
+ <% if circular? %><%= tag.td share_text(series.first.data[index]), class: "py-2 ps-4 text-end text-muted-foreground" %><% end %>
41
+ </tr>
42
+ <% end %>
43
+ </tbody>
44
+ </table>
45
+ </div>
46
+ </details>
47
+ <% end %>
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A line, bar, pie or donut chart: sales over a month, stock by category,
4
+ # takings by day, today's takings by payment method.
5
+ #
6
+ # <%= render(UI::Chart.new(type: :line, label: "Sales, this year and last", format: :currency,
7
+ # labels: %w[Jan Feb Mar], series: [
8
+ # { name: "This year", data: [4200, 5100, 4800] },
9
+ # { name: "Last year", data: [3900, 4300, 4500] }
10
+ # ])) %>
11
+ #
12
+ # `type:` is :line, :bar, :pie or :donut, and `stacked: true` piles a bar
13
+ # chart's series on top of each other. A pie or donut is one total split into
14
+ # its parts: one series, a slice for each label, five at most, none below zero.
15
+ # Its legend gives each part's value and share, and a donut shows the total in
16
+ # its middle. `format:` is :number, :currency or :percent (values from 0 to
17
+ # 100), and the values are written in the app's locale: currency uses Rails'
18
+ # own format for it, or `unit:` ("₹"). `nil` leaves a gap.
19
+ #
20
+ # Each series takes the next of five colours, `--chart-1` to `--chart-5`, which
21
+ # change with the theme. A series keeps its colour by its place in the list, so
22
+ # a chart that sometimes leaves one out should give each its `color:` (1 to 5)
23
+ # to stop the others moving up. There's no sixth colour: fold the smallest
24
+ # series into "Other" instead.
25
+ #
26
+ # Two or more series get a legend, and a line ends with its last value. Hover,
27
+ # or focus the chart and use the arrow keys, for the values at each point; the
28
+ # numbers are also in a table under "Show the data", for screen readers too.
29
+ # Chart.js loads when the first chart on a page appears, and each chart draws
30
+ # when it scrolls into view: bars grow from the baseline and a line draws
31
+ # itself from left to right, unless the system asks for reduced motion.
32
+ class UI::Chart < UI::Base
33
+ TYPES = %i[line bar pie donut].freeze
34
+ CIRCULAR = %i[pie donut].freeze
35
+ FORMATS = %i[number currency percent].freeze
36
+ COLORS = 5
37
+
38
+ # Written out in full so Tailwind finds them.
39
+ SWATCHES = { 1 => "bg-chart-1", 2 => "bg-chart-2", 3 => "bg-chart-3", 4 => "bg-chart-4", 5 => "bg-chart-5" }.freeze
40
+
41
+ Series = Struct.new(:name, :data, :color, keyword_init: true)
42
+
43
+ def initialize(labels:, series:, type: :line, label: nil, stacked: false, format: :number, unit: nil, height: 288,
44
+ class: nil, **html_attrs)
45
+ @labels = labels.map(&:to_s)
46
+ @type = TYPES.include?(type.to_sym) ? type.to_sym : :line
47
+ @label = label
48
+ @stacked = stacked && @type == :bar
49
+ @format = FORMATS.include?(format.to_sym) ? format.to_sym : :number
50
+ @unit = unit
51
+ @height = height
52
+ @user_class = binding.local_variable_get(:class)
53
+ @html_attrs = html_attrs
54
+ @series = build_series(series)
55
+ check_slices if circular?
56
+ end
57
+
58
+ attr_reader :labels, :series
59
+
60
+ def legend? = circular? || @series.size > 1
61
+ def line? = @type == :line
62
+ def circular? = CIRCULAR.include?(@type)
63
+ def swatch_classes(entry) = cn(SWATCHES[entry.color], line? ? "h-0.5 w-3.5 rounded-full" : "size-2.5 rounded-sm")
64
+
65
+ # A pie's legend is its slices, each with its value and its share.
66
+ Slice = Struct.new(:label, :color, :text, :share, keyword_init: true)
67
+
68
+ def slices
69
+ entry = @series.first
70
+ @labels.each_with_index.map do |label, index|
71
+ Slice.new(label: label, color: index + 1, text: formatted(entry.data[index]), share: share_text(entry.data[index]))
72
+ end
73
+ end
74
+
75
+ def slice_swatch(slice) = cn(SWATCHES[slice.color], "size-2.5 shrink-0 rounded-sm")
76
+
77
+ def legend_classes
78
+ if circular?
79
+ "flex flex-col gap-2 text-sm sm:w-64 sm:shrink-0"
80
+ else
81
+ "flex flex-wrap gap-x-4 gap-y-1 text-sm text-muted-foreground"
82
+ end
83
+ end
84
+
85
+ # A pie sits beside its legend once there's room; the others keep it above.
86
+ def body_classes
87
+ circular? ? "flex flex-col-reverse gap-4 sm:flex-row sm:items-center sm:gap-8" : "contents"
88
+ end
89
+
90
+ def root_attrs
91
+ attrs = @html_attrs.except(:data)
92
+ attrs[:class] = cn("flex w-full min-w-0 flex-col gap-3", @user_class)
93
+ attrs[:data] = { slot: "chart", type: @type, controller: "ui--chart",
94
+ "ui--chart-config-value": config.to_json,
95
+ # Propshaft digests the filename, so the URL has to come from Ruby.
96
+ "ui--chart-module-url-value": helpers.asset_path("chart_js.js") }
97
+ .merge(@html_attrs[:data] || {})
98
+ attrs
99
+ end
100
+
101
+ def canvas_attrs
102
+ { role: "img", tabindex: 0, class: cn("block rounded-sm", UI::Base::FOCUS_RING),
103
+ aria: { label: "#{label}. #{t('ui.chart.keyboard', default: 'Use the arrow keys to read each value.')}" },
104
+ data: { "ui--chart-target": "canvas",
105
+ action: "keydown->ui--chart#keydown blur->ui--chart#blur" } }
106
+ end
107
+
108
+ def frame_style = "height: #{@height.to_i}px"
109
+ def frame_classes = cn("relative w-full", { "sm:flex-1" => circular? })
110
+
111
+ def label = @label || t("ui.chart.label", default: "Chart")
112
+
113
+ def formatted(value)
114
+ return t("ui.chart.missing", default: "—") if value.nil?
115
+
116
+ case @format
117
+ when :currency then ActiveSupport::NumberHelper.number_to_currency(value, **{ unit: @unit }.compact)
118
+ when :percent then ActiveSupport::NumberHelper.number_to_percentage(value, precision: 1, strip_insignificant_zeros: true)
119
+ else ActiveSupport::NumberHelper.number_to_delimited(value)
120
+ end
121
+ end
122
+
123
+ def share_text(value)
124
+ return t("ui.chart.missing", default: "—") if value.nil? || total.zero?
125
+
126
+ ActiveSupport::NumberHelper.number_to_percentage(value.to_f / total * 100, precision: 0)
127
+ end
128
+
129
+ private
130
+
131
+ def total = @total ||= @series.first.data.compact.sum
132
+
133
+ def check_slices
134
+ raise ArgumentError, "a #{@type} chart shows one series; draw several as bars instead" if @series.size != 1
135
+ if @labels.size > COLORS
136
+ raise ArgumentError, "a #{@type} chart draws up to #{COLORS} slices; fold the rest into one called \"Other\""
137
+ end
138
+ raise ArgumentError, "a #{@type} chart can't show values below zero" if @series.first.data.compact.any?(&:negative?)
139
+ end
140
+
141
+ def build_series(series)
142
+ if series.size > COLORS
143
+ raise ArgumentError, "UI::Chart draws up to #{COLORS} series; fold the rest into one called \"Other\""
144
+ end
145
+
146
+ series.each_with_index.map do |entry, index|
147
+ entry = entry.to_h.symbolize_keys
148
+ data = Array(entry.fetch(:data))
149
+ if data.size != @labels.size
150
+ raise ArgumentError, "series #{entry[:name].inspect} has #{data.size} values for #{@labels.size} labels"
151
+ end
152
+
153
+ color = entry[:color].to_i.between?(1, COLORS) ? entry[:color].to_i : index + 1
154
+ Series.new(name: entry.fetch(:name).to_s, data: data, color: color)
155
+ end
156
+ end
157
+
158
+ # What the controller draws from. The values arrive written out already, so
159
+ # the tooltip shows them the same way as the table.
160
+ def config
161
+ config = { type: @type, stacked: @stacked, labels: @labels,
162
+ series: @series.map { |entry| { name: entry.name, color: entry.color, data: entry.data, text: entry.data.map { |value| formatted(value) } } },
163
+ axis: axis_format }
164
+ return config unless circular?
165
+
166
+ config[:series].first.merge!(colors: (1..@labels.size).to_a, shares: @series.first.data.map { |value| share_text(value) })
167
+ config.merge(total: formatted(total), total_label: t("ui.chart.total", default: "Total"))
168
+ end
169
+
170
+ # Axis ticks aren't data, so the browser writes them, in the same locale and
171
+ # with the same currency sign.
172
+ def axis_format
173
+ { style: @format, locale: I18n.locale.to_s,
174
+ unit: @unit || I18n.t("number.currency.format.unit", default: "$"),
175
+ pattern: I18n.t("number.currency.format.format", default: "%u%n") }
176
+ end
177
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ # A titled section of a UI::Command: "Pages", "Actions". Hidden while none of
6
+ # its items match what's typed.
7
+ class UI::Command::Group < UI::Base
8
+ renders_many :items, "UI::Command::Item"
9
+
10
+ def initialize(heading: nil, class: nil, **html_attrs)
11
+ @heading = heading
12
+ @user_class = binding.local_variable_get(:class)
13
+ @html_attrs = html_attrs
14
+ @heading_id = "ui-command-group-#{SecureRandom.hex(4)}"
15
+ end
16
+
17
+ def call
18
+ tag.div(role: "group", **@html_attrs, class: cn("py-1 [&:not(:first-child)]:border-t", @user_class),
19
+ aria: { labelledby: (@heading_id if @heading) }.compact,
20
+ data: { "ui--command-target": "group", **(@html_attrs[:data] || {}) }) do
21
+ safe_join([
22
+ (tag.div(@heading, id: @heading_id, class: "px-2 pt-1.5 pb-1 text-xs font-medium text-muted-foreground") if @heading),
23
+ safe_join(items.map(&:to_s))
24
+ ])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ # One thing to pick in a UI::Command: a page to go to (`href:`) or an action
6
+ # (`value:`, handled from `ui--command:select`). `keywords:` are other words
7
+ # it's found by. A block replaces how it looks; the label still finds it.
8
+ #
9
+ # `shortcut:` shows the item's shortcut, with UI::Kbd; with `bind: true` the
10
+ # shortcut also picks it from anywhere on the page, palette open or not.
11
+ class UI::Command::Item < UI::Base
12
+ BASE = "relative flex cursor-default select-none items-center gap-3 rounded-md px-2 py-2 text-sm outline-none " \
13
+ "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground " \
14
+ "aria-disabled:pointer-events-none aria-disabled:opacity-50"
15
+
16
+ def initialize(label:, href: nil, value: nil, icon: nil, description: nil, keywords: nil, shortcut: nil, bind: false,
17
+ disabled: false, class: nil, **html_attrs)
18
+ @label = label
19
+ @href = href
20
+ @value = value || href || label
21
+ @icon = icon
22
+ @description = description
23
+ @keywords = Array(keywords).join(" ")
24
+ @shortcut = shortcut
25
+ @bind = bind
26
+ @disabled = disabled
27
+ @user_class = binding.local_variable_get(:class)
28
+ @html_attrs = html_attrs
29
+ @id = html_attrs[:id] || "ui-command-item-#{SecureRandom.hex(4)}"
30
+ end
31
+
32
+ def call
33
+ tag.div(**@html_attrs, id: @id, role: "option", class: cn(BASE, @user_class),
34
+ aria: { disabled: (true if @disabled), selected: "false" }.compact,
35
+ data: { "ui--command-target": "item", value: @value, href: @href, label: @label,
36
+ keywords: (@keywords if @keywords.present?), **(@html_attrs[:data] || {}) }.compact) do
37
+ safe_join([ icon, body, shortcut ].compact)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def icon
44
+ return unless @icon
45
+
46
+ tag.span(render(UI::Icon.new(name: @icon, size: :sm)), class: "flex shrink-0 text-muted-foreground", aria: { hidden: true })
47
+ end
48
+
49
+ def body
50
+ return tag.span(content, class: "min-w-0 flex-1") if content?
51
+
52
+ tag.span(class: "flex min-w-0 flex-1 flex-col") do
53
+ safe_join([ tag.span(@label, class: "truncate"),
54
+ (tag.span(@description, class: "truncate text-xs text-muted-foreground") if @description) ].compact)
55
+ end
56
+ end
57
+
58
+ def shortcut
59
+ return unless @shortcut
60
+
61
+ render(UI::Kbd.new(@shortcut, size: :sm, class: "ms-auto text-muted-foreground",
62
+ bind: (@bind && !@disabled ? "##{@id}" : nil)))
63
+ end
64
+ end
@@ -0,0 +1,41 @@
1
+ <%# frozen_string_literal: true %>
2
+ <% panel = capture do %>
3
+ <div class="<%= panel_class %>" data-ui--command-target="panel">
4
+ <div class="flex items-center gap-2 border-b px-3">
5
+ <%# The magnifying glass turns into a spinner while a server search is slow. %>
6
+ <span class="flex shrink-0 text-muted-foreground" data-ui--command-target="searchIcon" aria-hidden="true"><%= render(UI::Icon.new(name: "search", size: :sm)) %></span>
7
+ <span class="hidden shrink-0 text-muted-foreground" data-ui--command-target="spinner" aria-hidden="true"><%= render(UI::Icon.new(name: "loader", size: :sm, class: "animate-spin motion-reduce:animate-[spin_1.5s_linear_infinite]")) %></span>
8
+ <%= tag.input(type: "text", id: input_id, role: "combobox", autocomplete: "off", spellcheck: "false", placeholder: placeholder,
9
+ class: "h-11 w-full min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground",
10
+ aria: { label: label, expanded: "true", controls: listbox_id, autocomplete: "list" },
11
+ data: { "ui--command-target": "input", action: "input->ui--command#search keydown->ui--command#navigate" }) %>
12
+ </div>
13
+ <div id="<%= listbox_id %>" role="listbox" aria-label="<%= label %>" class="min-h-0 flex-1 scroll-py-1 overflow-y-auto overscroll-contain p-1 <%= "max-h-80" unless dialog? %>"
14
+ data-ui--command-target="list" data-action="click->ui--command#pick pointermove->ui--command#hover">
15
+ <% groups.each do |group| %><%= group %><% end %>
16
+ <div data-ui--command-target="results"></div>
17
+ <p class="py-6 text-center text-sm text-muted-foreground" data-ui--command-target="empty" hidden></p>
18
+ <p class="py-6 text-center text-sm text-muted-foreground" data-ui--command-target="status" role="status" hidden></p>
19
+ </div>
20
+ <% if dialog? %>
21
+ <%# Key hints, so hidden where there's rarely a keyboard. %>
22
+ <div class="hidden items-center gap-4 border-t px-3 py-2 text-xs text-muted-foreground sm:flex" aria-hidden="true">
23
+ <span class="flex items-center gap-1.5"><%= render(UI::Kbd.new("up", size: :sm)) %><%= render(UI::Kbd.new("down", size: :sm)) %><%= t("ui.command.to_move", default: "to move") %></span>
24
+ <span class="flex items-center gap-1.5"><%= render(UI::Kbd.new("enter", size: :sm)) %><%= t("ui.command.to_pick", default: "to pick") %></span>
25
+ <span class="ms-auto flex items-center gap-1.5"><%= render(UI::Kbd.new("esc", size: :sm)) %><%= t("ui.command.to_close", default: "to close") %></span>
26
+ </div>
27
+ <% end %>
28
+ <%# A server result, copied for each one. %>
29
+ <template data-ui--command-target="template">
30
+ <%= render(UI::Command::Item.new(label: "", id: "", data: { remote: true })) %>
31
+ </template>
32
+ </div>
33
+ <% end %>
34
+ <%= tag.div(**root_attrs) do %>
35
+ <% if dialog? %>
36
+ <%= trigger %>
37
+ <dialog class="<%= UI::Command::DIALOG %>" aria-label="<%= label %>" data-ui--command-target="dialog"><%= panel %></dialog>
38
+ <% else %>
39
+ <%= panel %>
40
+ <% end %>
41
+ <% end %>