velvetkit 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -7
  3. data/lib/generators/velvetkit/add/add_generator.rb +19 -0
  4. data/lib/generators/velvetkit/helpers.rb +29 -2
  5. data/lib/generators/velvetkit/icons/icons_generator.rb +71 -0
  6. data/lib/generators/velvetkit/install/install_generator.rb +9 -12
  7. data/lib/velvetkit/icons.rb +148 -0
  8. data/lib/velvetkit/registry.rb +5 -2
  9. data/lib/velvetkit/version.rb +1 -1
  10. data/lib/velvetkit.rb +1 -0
  11. data/registry/app/components/ui/alert.rb +1 -1
  12. data/registry/app/components/ui/confirm_dialog.html.erb +13 -0
  13. data/registry/app/components/ui/confirm_dialog.rb +55 -0
  14. data/registry/app/components/ui/empty_state.html.erb +20 -0
  15. data/registry/app/components/ui/empty_state.rb +46 -0
  16. data/registry/app/components/ui/icon.html.erb +1 -1
  17. data/registry/app/components/ui/icon.rb +80 -8
  18. data/registry/app/components/ui/password_input.html.erb +1 -1
  19. data/registry/app/components/ui/stepper/step.html.erb +27 -0
  20. data/registry/app/components/ui/stepper/step.rb +213 -0
  21. data/registry/app/components/ui/stepper.html.erb +19 -0
  22. data/registry/app/components/ui/stepper.rb +145 -0
  23. data/registry/app/components/ui/theme_toggle.rb +2 -4
  24. data/registry/app/components/ui/toast.rb +6 -6
  25. data/registry/app/components/ui/toggle_group/item.html.erb +1 -0
  26. data/registry/app/components/ui/toggle_group/item.rb +85 -0
  27. data/registry/app/components/ui/toggle_group.html.erb +1 -0
  28. data/registry/app/components/ui/toggle_group.rb +79 -0
  29. data/registry/app/javascript/controllers/ui/confirm_dialog_controller.ts +110 -0
  30. data/registry/app/javascript/controllers/ui/stepper_controller.ts +187 -0
  31. data/registry/components.yml +9 -2
  32. data/registry/config/locales/velvetkit.en.yml +11 -0
  33. data/registry/docs/agents.md +7 -4
  34. data/registry/icons/lucide/LICENSE +39 -0
  35. data/registry/icons/lucide/align-center.svg +17 -0
  36. data/registry/icons/lucide/align-left.svg +17 -0
  37. data/registry/icons/lucide/align-right.svg +17 -0
  38. data/registry/icons/lucide/arrow-left.svg +16 -0
  39. data/registry/icons/lucide/arrow-right.svg +16 -0
  40. data/registry/icons/lucide/badge-check.svg +16 -0
  41. data/registry/icons/lucide/bar-chart-3.svg +18 -0
  42. data/registry/icons/lucide/bell.svg +16 -0
  43. data/registry/icons/lucide/bold.svg +15 -0
  44. data/registry/icons/lucide/book-open.svg +16 -0
  45. data/registry/icons/lucide/calendar.svg +18 -0
  46. data/registry/icons/lucide/chart-column.svg +18 -0
  47. data/registry/icons/lucide/check.svg +15 -0
  48. data/registry/icons/lucide/chevron-down.svg +15 -0
  49. data/registry/icons/lucide/chevron-left.svg +15 -0
  50. data/registry/icons/lucide/chevron-right.svg +15 -0
  51. data/registry/icons/lucide/chevrons-up-down.svg +16 -0
  52. data/registry/icons/lucide/circle-alert.svg +17 -0
  53. data/registry/icons/lucide/circle-check.svg +16 -0
  54. data/registry/icons/lucide/cloud.svg +15 -0
  55. data/registry/icons/lucide/credit-card.svg +16 -0
  56. data/registry/icons/lucide/ellipsis-vertical.svg +17 -0
  57. data/registry/icons/lucide/ellipsis.svg +17 -0
  58. data/registry/icons/lucide/eye-off.svg +18 -0
  59. data/registry/icons/lucide/eye.svg +16 -0
  60. data/registry/icons/lucide/file-text.svg +19 -0
  61. data/registry/icons/lucide/folder-kanban.svg +18 -0
  62. data/registry/icons/lucide/git-branch.svg +18 -0
  63. data/registry/icons/lucide/globe.svg +17 -0
  64. data/registry/icons/lucide/graduation-cap.svg +17 -0
  65. data/registry/icons/lucide/grip-vertical.svg +20 -0
  66. data/registry/icons/lucide/home.svg +16 -0
  67. data/registry/icons/lucide/inbox.svg +16 -0
  68. data/registry/icons/lucide/info.svg +17 -0
  69. data/registry/icons/lucide/italic.svg +17 -0
  70. data/registry/icons/lucide/layout-dashboard.svg +18 -0
  71. data/registry/icons/lucide/layout-grid.svg +18 -0
  72. data/registry/icons/lucide/life-buoy.svg +20 -0
  73. data/registry/icons/lucide/list.svg +20 -0
  74. data/registry/icons/lucide/loader.svg +22 -0
  75. data/registry/icons/lucide/lock.svg +16 -0
  76. data/registry/icons/lucide/log-out.svg +17 -0
  77. data/registry/icons/lucide/mail.svg +16 -0
  78. data/registry/icons/lucide/menu.svg +17 -0
  79. data/registry/icons/lucide/message-circle.svg +15 -0
  80. data/registry/icons/lucide/monitor.svg +17 -0
  81. data/registry/icons/lucide/moon.svg +15 -0
  82. data/registry/icons/lucide/newspaper.svg +18 -0
  83. data/registry/icons/lucide/panel-left.svg +16 -0
  84. data/registry/icons/lucide/plus.svg +16 -0
  85. data/registry/icons/lucide/qr-code.svg +26 -0
  86. data/registry/icons/lucide/rocket.svg +18 -0
  87. data/registry/icons/lucide/rotate-cw.svg +16 -0
  88. data/registry/icons/lucide/search.svg +16 -0
  89. data/registry/icons/lucide/settings.svg +16 -0
  90. data/registry/icons/lucide/shield-check.svg +16 -0
  91. data/registry/icons/lucide/shield.svg +15 -0
  92. data/registry/icons/lucide/store.svg +17 -0
  93. data/registry/icons/lucide/sun.svg +23 -0
  94. data/registry/icons/lucide/trash-2.svg +19 -0
  95. data/registry/icons/lucide/underline.svg +16 -0
  96. data/registry/icons/lucide/upload.svg +17 -0
  97. data/registry/icons/lucide/user.svg +16 -0
  98. data/registry/icons/lucide/users.svg +18 -0
  99. data/registry/icons/lucide/workflow.svg +17 -0
  100. data/registry/icons/lucide/x.svg +16 -0
  101. data/registry/icons/phosphor/LICENSE +21 -0
  102. data/registry/icons/phosphor/arrow-clockwise.svg +2 -0
  103. data/registry/icons/phosphor/arrow-left.svg +2 -0
  104. data/registry/icons/phosphor/arrow-right.svg +2 -0
  105. data/registry/icons/phosphor/bell.svg +2 -0
  106. data/registry/icons/phosphor/book-open.svg +2 -0
  107. data/registry/icons/phosphor/calendar-blank.svg +2 -0
  108. data/registry/icons/phosphor/caret-down.svg +2 -0
  109. data/registry/icons/phosphor/caret-left.svg +2 -0
  110. data/registry/icons/phosphor/caret-right.svg +2 -0
  111. data/registry/icons/phosphor/caret-up-down.svg +2 -0
  112. data/registry/icons/phosphor/chart-bar.svg +2 -0
  113. data/registry/icons/phosphor/chat-circle.svg +2 -0
  114. data/registry/icons/phosphor/check-circle.svg +2 -0
  115. data/registry/icons/phosphor/check.svg +2 -0
  116. data/registry/icons/phosphor/cloud.svg +2 -0
  117. data/registry/icons/phosphor/credit-card.svg +2 -0
  118. data/registry/icons/phosphor/desktop.svg +2 -0
  119. data/registry/icons/phosphor/dots-six-vertical.svg +2 -0
  120. data/registry/icons/phosphor/dots-three-vertical.svg +2 -0
  121. data/registry/icons/phosphor/dots-three.svg +2 -0
  122. data/registry/icons/phosphor/envelope.svg +2 -0
  123. data/registry/icons/phosphor/eye-slash.svg +2 -0
  124. data/registry/icons/phosphor/eye.svg +2 -0
  125. data/registry/icons/phosphor/file-text.svg +2 -0
  126. data/registry/icons/phosphor/flow-arrow.svg +2 -0
  127. data/registry/icons/phosphor/gear.svg +2 -0
  128. data/registry/icons/phosphor/git-branch.svg +2 -0
  129. data/registry/icons/phosphor/globe.svg +2 -0
  130. data/registry/icons/phosphor/graduation-cap.svg +2 -0
  131. data/registry/icons/phosphor/grid-four.svg +2 -0
  132. data/registry/icons/phosphor/house.svg +2 -0
  133. data/registry/icons/phosphor/info.svg +2 -0
  134. data/registry/icons/phosphor/kanban.svg +2 -0
  135. data/registry/icons/phosphor/lifebuoy.svg +2 -0
  136. data/registry/icons/phosphor/list.svg +2 -0
  137. data/registry/icons/phosphor/lock.svg +2 -0
  138. data/registry/icons/phosphor/magnifying-glass.svg +2 -0
  139. data/registry/icons/phosphor/moon.svg +2 -0
  140. data/registry/icons/phosphor/newspaper.svg +2 -0
  141. data/registry/icons/phosphor/plus.svg +2 -0
  142. data/registry/icons/phosphor/qr-code.svg +2 -0
  143. data/registry/icons/phosphor/rocket.svg +2 -0
  144. data/registry/icons/phosphor/seal-check.svg +2 -0
  145. data/registry/icons/phosphor/shield-check.svg +2 -0
  146. data/registry/icons/phosphor/shield.svg +2 -0
  147. data/registry/icons/phosphor/sidebar.svg +2 -0
  148. data/registry/icons/phosphor/sign-out.svg +2 -0
  149. data/registry/icons/phosphor/spinner.svg +2 -0
  150. data/registry/icons/phosphor/squares-four.svg +2 -0
  151. data/registry/icons/phosphor/storefront.svg +2 -0
  152. data/registry/icons/phosphor/sun.svg +2 -0
  153. data/registry/icons/phosphor/text-align-center.svg +2 -0
  154. data/registry/icons/phosphor/text-align-left.svg +2 -0
  155. data/registry/icons/phosphor/text-align-right.svg +2 -0
  156. data/registry/icons/phosphor/text-b.svg +2 -0
  157. data/registry/icons/phosphor/text-italic.svg +2 -0
  158. data/registry/icons/phosphor/text-underline.svg +2 -0
  159. data/registry/icons/phosphor/trash.svg +2 -0
  160. data/registry/icons/phosphor/tray.svg +2 -0
  161. data/registry/icons/phosphor/upload-simple.svg +2 -0
  162. data/registry/icons/phosphor/user.svg +2 -0
  163. data/registry/icons/phosphor/users.svg +2 -0
  164. data/registry/icons/phosphor/warning-circle.svg +2 -0
  165. data/registry/icons/phosphor/x.svg +2 -0
  166. data/registry/icons/tabler/LICENSE +21 -0
  167. data/registry/icons/tabler/alert-circle.svg +18 -0
  168. data/registry/icons/tabler/align-center.svg +18 -0
  169. data/registry/icons/tabler/align-left.svg +18 -0
  170. data/registry/icons/tabler/align-right.svg +18 -0
  171. data/registry/icons/tabler/arrow-left.svg +18 -0
  172. data/registry/icons/tabler/arrow-right.svg +18 -0
  173. data/registry/icons/tabler/bell.svg +17 -0
  174. data/registry/icons/tabler/bold.svg +17 -0
  175. data/registry/icons/tabler/book.svg +20 -0
  176. data/registry/icons/tabler/building-store.svg +20 -0
  177. data/registry/icons/tabler/calendar.svg +21 -0
  178. data/registry/icons/tabler/chart-bar.svg +19 -0
  179. data/registry/icons/tabler/check.svg +16 -0
  180. data/registry/icons/tabler/chevron-down.svg +16 -0
  181. data/registry/icons/tabler/chevron-left.svg +16 -0
  182. data/registry/icons/tabler/chevron-right.svg +16 -0
  183. data/registry/icons/tabler/circle-check.svg +17 -0
  184. data/registry/icons/tabler/cloud.svg +16 -0
  185. data/registry/icons/tabler/credit-card.svg +19 -0
  186. data/registry/icons/tabler/device-desktop.svg +19 -0
  187. data/registry/icons/tabler/dots-vertical.svg +18 -0
  188. data/registry/icons/tabler/dots.svg +18 -0
  189. data/registry/icons/tabler/eye-off.svg +18 -0
  190. data/registry/icons/tabler/eye.svg +17 -0
  191. data/registry/icons/tabler/file-text.svg +20 -0
  192. data/registry/icons/tabler/git-branch.svg +21 -0
  193. data/registry/icons/tabler/grip-vertical.svg +21 -0
  194. data/registry/icons/tabler/home.svg +18 -0
  195. data/registry/icons/tabler/inbox.svg +17 -0
  196. data/registry/icons/tabler/info-circle.svg +18 -0
  197. data/registry/icons/tabler/italic.svg +18 -0
  198. data/registry/icons/tabler/layout-dashboard.svg +19 -0
  199. data/registry/icons/tabler/layout-grid.svg +19 -0
  200. data/registry/icons/tabler/layout-kanban.svg +19 -0
  201. data/registry/icons/tabler/layout-sidebar.svg +17 -0
  202. data/registry/icons/tabler/lifebuoy.svg +21 -0
  203. data/registry/icons/tabler/list.svg +21 -0
  204. data/registry/icons/tabler/loader.svg +23 -0
  205. data/registry/icons/tabler/lock.svg +18 -0
  206. data/registry/icons/tabler/logout.svg +18 -0
  207. data/registry/icons/tabler/mail.svg +17 -0
  208. data/registry/icons/tabler/menu-2.svg +18 -0
  209. data/registry/icons/tabler/message-circle.svg +16 -0
  210. data/registry/icons/tabler/moon.svg +16 -0
  211. data/registry/icons/tabler/news.svg +19 -0
  212. data/registry/icons/tabler/plus.svg +17 -0
  213. data/registry/icons/tabler/qrcode.svg +27 -0
  214. data/registry/icons/tabler/rocket.svg +18 -0
  215. data/registry/icons/tabler/rosette-discount-check.svg +17 -0
  216. data/registry/icons/tabler/rotate-clockwise.svg +16 -0
  217. data/registry/icons/tabler/school.svg +17 -0
  218. data/registry/icons/tabler/search.svg +17 -0
  219. data/registry/icons/tabler/selector.svg +17 -0
  220. data/registry/icons/tabler/settings.svg +17 -0
  221. data/registry/icons/tabler/shield-check.svg +17 -0
  222. data/registry/icons/tabler/shield.svg +16 -0
  223. data/registry/icons/tabler/sitemap.svg +20 -0
  224. data/registry/icons/tabler/sun.svg +17 -0
  225. data/registry/icons/tabler/trash.svg +20 -0
  226. data/registry/icons/tabler/underline.svg +17 -0
  227. data/registry/icons/tabler/upload.svg +18 -0
  228. data/registry/icons/tabler/user.svg +17 -0
  229. data/registry/icons/tabler/users.svg +19 -0
  230. data/registry/icons/tabler/world.svg +20 -0
  231. data/registry/icons/tabler/x.svg +17 -0
  232. data/registry/icons.yml +74 -0
  233. data/registry/test/components/previews/ui/confirm_dialog_preview/destructive.html.erb +7 -0
  234. data/registry/test/components/previews/ui/confirm_dialog_preview/in_form.html.erb +6 -0
  235. data/registry/test/components/previews/ui/confirm_dialog_preview/on_link.html.erb +5 -0
  236. data/registry/test/components/previews/ui/confirm_dialog_preview/plain.html.erb +3 -0
  237. data/registry/test/components/previews/ui/confirm_dialog_preview/with_description.html.erb +4 -0
  238. data/registry/test/components/previews/ui/confirm_dialog_preview.rb +20 -0
  239. data/registry/test/components/previews/ui/empty_state_preview/in_card.html.erb +7 -0
  240. data/registry/test/components/previews/ui/empty_state_preview/no_results.html.erb +3 -0
  241. data/registry/test/components/previews/ui/empty_state_preview/outline.html.erb +3 -0
  242. data/registry/test/components/previews/ui/empty_state_preview/with_actions.html.erb +4 -0
  243. data/registry/test/components/previews/ui/empty_state_preview/with_media.html.erb +8 -0
  244. data/registry/test/components/previews/ui/empty_state_preview.rb +26 -0
  245. data/registry/test/components/previews/ui/icon_preview/common.html.erb +19 -3
  246. data/registry/test/components/previews/ui/icon_preview/labelled.html.erb +4 -0
  247. data/registry/test/components/previews/ui/icon_preview/missing.html.erb +3 -0
  248. data/registry/test/components/previews/ui/icon_preview.rb +18 -3
  249. data/registry/test/components/previews/ui/input_group_preview/playground.html.erb +2 -2
  250. data/registry/test/components/previews/ui/input_group_preview.rb +3 -3
  251. data/registry/test/components/previews/ui/stepper_preview/approvals.html.erb +9 -0
  252. data/registry/test/components/previews/ui/stepper_preview/checklist.html.erb +12 -0
  253. data/registry/test/components/previews/ui/stepper_preview/dot_wizard.html.erb +41 -0
  254. data/registry/test/components/previews/ui/stepper_preview/failed_deploy.html.erb +13 -0
  255. data/registry/test/components/previews/ui/stepper_preview/inline.html.erb +31 -0
  256. data/registry/test/components/previews/ui/stepper_preview/onboarding.html.erb +12 -0
  257. data/registry/test/components/previews/ui/stepper_preview/order_tracking.html.erb +10 -0
  258. data/registry/test/components/previews/ui/stepper_preview/price_calculator.html.erb +14 -0
  259. data/registry/test/components/previews/ui/stepper_preview/server_driven.html.erb +20 -0
  260. data/registry/test/components/previews/ui/stepper_preview/sidebar.html.erb +43 -0
  261. data/registry/test/components/previews/ui/stepper_preview/wizard.html.erb +55 -0
  262. data/registry/test/components/previews/ui/stepper_preview.rb +57 -0
  263. data/registry/test/components/previews/ui/toggle_group_preview/icon_only.html.erb +5 -0
  264. data/registry/test/components/previews/ui/toggle_group_preview/in_form.html.erb +11 -0
  265. data/registry/test/components/previews/ui/toggle_group_preview/multiple.html.erb +5 -0
  266. data/registry/test/components/previews/ui/toggle_group_preview/outline.html.erb +5 -0
  267. data/registry/test/components/previews/ui/toggle_group_preview/sizes.html.erb +9 -0
  268. data/registry/test/components/previews/ui/toggle_group_preview/with_icons.html.erb +5 -0
  269. data/registry/test/components/previews/ui/toggle_group_preview.rb +36 -0
  270. data/registry/test/components/ui/accordion/trigger_test.rb +1 -1
  271. data/registry/test/components/ui/alert_test.rb +10 -10
  272. data/registry/test/components/ui/badge_test.rb +3 -3
  273. data/registry/test/components/ui/banner_test.rb +3 -3
  274. data/registry/test/components/ui/breadcrumb/ellipsis_test.rb +2 -2
  275. data/registry/test/components/ui/button_test.rb +17 -14
  276. data/registry/test/components/ui/button_to_test.rb +2 -2
  277. data/registry/test/components/ui/checkbox_test.rb +2 -2
  278. data/registry/test/components/ui/confirm_dialog_test.rb +68 -0
  279. data/registry/test/components/ui/empty_state_test.rb +87 -0
  280. data/registry/test/components/ui/icon_test.rb +60 -20
  281. data/registry/test/components/ui/input_group_test.rb +1 -1
  282. data/registry/test/components/ui/link_test.rb +3 -3
  283. data/registry/test/components/ui/navigation_menu_test.rb +2 -2
  284. data/registry/test/components/ui/session_tabs_test.rb +3 -3
  285. data/registry/test/components/ui/spinner_test.rb +9 -9
  286. data/registry/test/components/ui/stepper_test.rb +239 -0
  287. data/registry/test/components/ui/tabs/trigger_test.rb +2 -2
  288. data/registry/test/components/ui/theme_toggle_test.rb +6 -8
  289. data/registry/test/components/ui/toast_test.rb +11 -10
  290. data/registry/test/components/ui/toggle_group_test.rb +162 -0
  291. metadata +253 -2
  292. data/registry/app/javascript/velvetkit_icons.ts +0 -78
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d08ba86d71423280c8ee7e6402a9bfd41f0bc169e104b9f4d79d0dc233900a7e
4
- data.tar.gz: b429da49e5336283efd3c237197a68ae8124ff272f06f539b73c320583b176a5
3
+ metadata.gz: f62bf151307c243a489390029439a9ded5f33d3b66a93749b81db24b90a33186
4
+ data.tar.gz: f86a8beed40c9571617bcb3ab2c6be4b7061cf8e7425d3d7bec735ec9d4f938c
5
5
  SHA512:
6
- metadata.gz: 83049f0da572339daf86fce1e387624a3cf9531e9c1bb95f173625d2bef5660d3e44740bf3ecd91fe090bb1b7736dc7b5d0770d4c5a91d0dc803b14f304fda50
7
- data.tar.gz: 598f00a866bd796c3af74e60bd652f9fd35f069f80d41aaee233f81e2b5a31541e2c5c863d41c5cdcdb0aa85f124006b3313f728231d406697b7a3d6302bb248
6
+ metadata.gz: 6e46ecf7c1c83c29d7c89b302b123156b977e7696d97758601a0060e2679a521c0557071b679b5d04cf808dcba1ebcb19785c706b2d46cef2107665402e2f0b3
7
+ data.tar.gz: d59fdf785470d1bf690295b369905034545770339bc2a25031a092a3845488be66d8ee23560e43ec40d76cbcfe993c30c98cff1ee0fad689a39a49f181d38233
data/README.md CHANGED
@@ -139,15 +139,14 @@ bin/rails generate velvetkit:install --namespace=Kit # or under Kit::
139
139
 
140
140
  `install` does the following:
141
141
 
142
- - writes `config/velvetkit.yml` with the namespace
142
+ - writes `config/velvetkit.yml` with the namespace and icon library
143
143
  - adds `view_component` and `tailwind_merge` to the Gemfile
144
144
  - adds an acronym inflection when the namespace needs one (`UI`, not `Kit`)
145
145
  - copies the base component, design tokens (`app/assets/tailwind/velvetkit.css`),
146
- translations (`config/locales/velvetkit.en.yml`) and Lucide icon setup
147
- (`app/javascript/velvetkit_icons.ts`), and imports the CSS and icons from
148
- your entry points
149
- - installs `@hotwired/stimulus`, `lucide` and `tw-animate-css` with your
150
- package manager, which it picks from your lockfile
146
+ and translations (`config/locales/velvetkit.en.yml`), and imports the CSS
147
+ from your Tailwind entry point
148
+ - installs `@hotwired/stimulus` and `tw-animate-css` with your package
149
+ manager, which it picks from your lockfile
151
150
 
152
151
  ### Add components
153
152
 
@@ -162,6 +161,8 @@ bin/rails generate velvetkit:add --all # everything
162
161
  - copies the component, its templates and sub-components
163
162
  - copies its Stimulus controllers and any lazily-loaded entry points (AG Grid
164
163
  for `data_grid`, Cally for `date_picker`)
164
+ - copies the SVG of every icon it draws into `app/assets/icons`, named for
165
+ your icon library
165
166
  - copies its Minitest tests and Lookbook previews. A preview that shows
166
167
  components you haven't added is skipped, and `add` tells you which.
167
168
  - registers its controllers in `app/javascript/controllers/index.js` when
@@ -169,10 +170,27 @@ bin/rails generate velvetkit:add --all # everything
169
170
  - installs any npm packages it needs, and adds any gems it needs (`pagy` for
170
171
  `pagination`) to the Gemfile
171
172
 
172
- Options: `--namespace=Kit`, `--skip-tests`, `--skip-previews`,
173
+ Options: `--namespace=Kit`, `--icons=tabler`, `--skip-tests`, `--skip-previews`,
173
174
  `--skip-packages` (list the packages instead of installing them), and the usual
174
175
  `--force`/`--skip` for files that already exist.
175
176
 
177
+ ### Icons
178
+
179
+ Components draw their icons from one library: Lucide (the default), Tabler or
180
+ Phosphor. Choose it with `velvetkit:install --icons=phosphor`. Like shadcn/ui,
181
+ the choice is made when components are copied: they're written with Lucide
182
+ names, and `add` renames every icon for your library and copies its SVG into
183
+ `app/assets/icons`. `Icon` draws the SVG into the page on the server, so
184
+ there's no icon JavaScript.
185
+
186
+ ```bash
187
+ bin/rails generate velvetkit:icons rocket user # add icons for your own views
188
+ bin/rails generate velvetkit:icons # or every one they draw that has no SVG
189
+ ```
190
+
191
+ See [Icons](https://velvetkit.com/docs/icons) for switching libraries and
192
+ upgrading from 0.2.
193
+
176
194
  ### AI agents
177
195
 
178
196
  `install` also writes three files so coding agents use your components
@@ -21,12 +21,18 @@ module Velvetkit
21
21
 
22
22
  class_option :namespace, type: :string,
23
23
  desc: "Module for the components (default: #{CONFIG_FILE}, else UI)"
24
+ class_option :icons, type: :string,
25
+ desc: "Icon library: #{Icons::LIBRARIES.keys.join(', ')} (default: #{CONFIG_FILE}, else lucide)"
24
26
  class_option :all, type: :boolean, default: false, desc: "Add every component"
25
27
  class_option :skip_tests, type: :boolean, default: false, desc: "Don't copy component tests"
26
28
  class_option :skip_previews, type: :boolean, default: false, desc: "Don't copy Lookbook previews"
27
29
  class_option :skip_packages, type: :boolean, default: false,
28
30
  desc: "List the npm packages to add instead of installing them"
29
31
 
32
+ def check_icon_library
33
+ icon_library
34
+ end
35
+
30
36
  def list_components
31
37
  return if requested.any?
32
38
 
@@ -51,10 +57,19 @@ module Velvetkit
51
57
  say_status :skip, "#{name} preview, it also shows #{needs.join(', ')}", :yellow
52
58
  else
53
59
  registry.preview_files(name).each { |file| copy_from_registry(file) }
60
+ copied_previews.concat(registry.preview_files(name))
54
61
  end
55
62
  end
56
63
  end
57
64
 
65
+ # The icons the components and their previews draw, as SVGs in the
66
+ # app's icon library.
67
+ def copy_icon_files
68
+ return if resolved.empty?
69
+
70
+ copy_icons(resolved.flat_map { |name| registry.component_files(name) } + copied_previews)
71
+ end
72
+
58
73
  # Apps that list controllers in a manifest (jsbundling with
59
74
  # stimulus:manifest:update) need each one registered; apps that load the
60
75
  # directory (importmap, eagerLoadControllersFrom) need nothing.
@@ -99,6 +114,10 @@ module Velvetkit
99
114
  @resolved ||= requested.empty? ? [] : registry.resolve(requested)
100
115
  end
101
116
 
117
+ def copied_previews
118
+ @copied_previews ||= []
119
+ end
120
+
102
121
  def requested
103
122
  options[:all] ? registry.names : components
104
123
  end
@@ -15,6 +15,8 @@ module Velvetkit
15
15
  "package-lock.json" => "npm install"
16
16
  }.freeze
17
17
 
18
+ ICONS_DIR = "app/assets/icons"
19
+
18
20
  private
19
21
 
20
22
  def registry
@@ -27,12 +29,37 @@ module Velvetkit
27
29
  end
28
30
 
29
31
  def configured_namespace
32
+ configured("namespace")
33
+ end
34
+
35
+ # --icons, else config/velvetkit.yml, else lucide.
36
+ def icon_library
37
+ @icon_library ||= Icons.library!(options[:icons] || configured("icons"))
38
+ rescue Error => e
39
+ raise Thor::Error, e.message
40
+ end
41
+
42
+ def configured(key)
30
43
  config = File.join(destination_root, CONFIG_FILE)
31
- YAML.load_file(config)&.fetch("namespace", nil) if File.exist?(config)
44
+ YAML.load_file(config)&.fetch(key, nil) if File.exist?(config)
32
45
  end
33
46
 
47
+ # Ruby and templates get the app's icon names, then its namespace.
34
48
  def copy_from_registry(file)
35
- create_file kit_namespace.rewrite_path(file), kit_namespace.rewrite(registry.read(file))
49
+ source = registry.read(file)
50
+ source = registry.icons.rewrite(source, icon_library) if file.end_with?(".rb", ".erb")
51
+ create_file kit_namespace.rewrite_path(file), kit_namespace.rewrite(source)
52
+ end
53
+
54
+ # The SVG of every icon the files draw, in the app's library.
55
+ def copy_icons(files)
56
+ icons = registry.icons
57
+ names = files.select { |file| file.end_with?(".rb", ".erb") }
58
+ .flat_map { |file| icons.names_in(registry.read(file)) }.uniq.sort
59
+ names.select { |icon| icons.name(icon, icon_library) }.each do |icon|
60
+ create_file File.join(ICONS_DIR, "#{icons.name(icon, icon_library)}.svg"),
61
+ registry.read(icons.svg_file(icon, icon_library))
62
+ end
36
63
  end
37
64
 
38
65
  def install_packages(packages)
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require_relative "../helpers"
5
+
6
+ module Velvetkit
7
+ module Generators
8
+ # Puts icon SVGs in app/assets/icons, where the Icon component reads them.
9
+ #
10
+ # Names are the app's icon library's own (config/velvetkit.yml). An icon
11
+ # the kit already ships is copied from the gem; any other is downloaded
12
+ # from the npm CDN, pinned to the version the kit was built against.
13
+ class IconsGenerator < Rails::Generators::Base
14
+ include Helpers
15
+
16
+ SOURCES = "app/{components,views,helpers}/**/*.{rb,erb}"
17
+
18
+ desc <<~DESC
19
+ Add icons to app/assets/icons, from the library in #{CONFIG_FILE}.
20
+
21
+ Name them, or run with none to add every icon the app's own
22
+ components, views and helpers draw that has no SVG yet.
23
+
24
+ bin/rails generate velvetkit:icons rocket user
25
+ bin/rails generate velvetkit:icons
26
+ DESC
27
+
28
+ argument :names, type: :array, default: [], banner: "icon icon ..."
29
+
30
+ class_option :icons, type: :string,
31
+ desc: "Icon library: #{Icons::LIBRARIES.keys.join(', ')} (default: #{CONFIG_FILE}, else lucide)"
32
+
33
+ def add_icons
34
+ wanted = names.any? ? names : (drawn - present)
35
+ return say_status(:icons, "every icon drawn has an SVG in #{ICONS_DIR}", :green) if wanted.empty?
36
+
37
+ failed = wanted.uniq.reject { |name| add(name) }
38
+ return if failed.empty?
39
+
40
+ say_status :error, "no SVG for #{failed.join(', ')}. Browse #{icon_library}'s icons at " \
41
+ "#{Icons::LIBRARIES.dig(icon_library, :browse)}", :red
42
+ end
43
+
44
+ private
45
+
46
+ def add(name)
47
+ create_file File.join(ICONS_DIR, "#{name}.svg"), shipped(name) || Icons.download(name, icon_library)
48
+ true
49
+ rescue Velvetkit::Error => e
50
+ say_status :missing, e.message, :yellow
51
+ false
52
+ end
53
+
54
+ # The gem's copy, when the kit draws this icon itself.
55
+ def shipped(name)
56
+ file = File.join(registry.root, "icons", icon_library, "#{name}.svg")
57
+ File.read(file) if name.match?(/\A#{Icons::NAME}\z/o) && File.file?(file)
58
+ end
59
+
60
+ def drawn
61
+ Dir.glob(SOURCES, base: destination_root).flat_map do |file|
62
+ registry.icons.names_in(File.read(File.join(destination_root, file)))
63
+ end.uniq.sort
64
+ end
65
+
66
+ def present
67
+ Dir.glob("*.svg", base: File.join(destination_root, ICONS_DIR)).map { |file| file.delete_suffix(".svg") }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -11,13 +11,16 @@ module Velvetkit
11
11
 
12
12
  desc <<~DESC
13
13
  Set the app up for VelvetKit: choose the namespace, and add the base
14
- component, design tokens, translations and icons every component uses.
14
+ component, design tokens and translations every component uses, and
15
+ choose the icon library the components draw from.
15
16
 
16
- bin/rails generate velvetkit:install --namespace=Kit
17
+ bin/rails generate velvetkit:install --namespace=Kit --icons=phosphor
17
18
  DESC
18
19
 
19
20
  class_option :namespace, type: :string, default: Namespace::CANONICAL,
20
21
  desc: "Module to put the components under"
22
+ class_option :icons, type: :string, default: Icons::CANONICAL,
23
+ desc: "Icon library: #{Icons::LIBRARIES.keys.join(', ')}"
21
24
  class_option :skip_tests, type: :boolean, default: false, desc: "Don't copy the base component's test"
22
25
  class_option :skip_packages, type: :boolean, default: false,
23
26
  desc: "List the npm packages to add instead of installing them"
@@ -27,8 +30,10 @@ module Velvetkit
27
30
  def write_config
28
31
  create_file CONFIG_FILE, <<~YAML
29
32
  # VelvetKit — https://velvetkit.com
30
- # `bin/rails generate velvetkit:add` puts components under this module.
33
+ # `bin/rails generate velvetkit:add` puts components under this module,
34
+ # with their icons from this library (#{Icons::LIBRARIES.keys.join(', ')}).
31
35
  namespace: #{kit_namespace.name}
36
+ icons: #{icon_library}
32
37
  YAML
33
38
  end
34
39
 
@@ -74,16 +79,8 @@ module Velvetkit
74
79
  inject_into_file entry, %(@import "#{path}";\n), after: /@import ["']tailwindcss["'];?\n/
75
80
  end
76
81
 
77
- def import_icons
78
- entry = %w[app/javascript/application.js app/javascript/application.ts].find { |file| exists?(file) }
79
- return say_status(:js, "import ./velvetkit_icons from your JavaScript entry point", :yellow) unless entry
80
- return if read(entry).include?("velvetkit_icons")
81
-
82
- append_to_file entry, %(import "./velvetkit_icons"\n)
83
- end
84
-
85
82
  def add_base_component
86
- invoke "velvetkit:add", [ "base" ], namespace: kit_namespace.name, skip_tests: options[:skip_tests], skip_packages: true
83
+ invoke "velvetkit:add", [ "base" ], namespace: kit_namespace.name, icons: icon_library, skip_tests: options[:skip_tests], skip_packages: true
87
84
  end
88
85
 
89
86
  def add_packages
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "net/http"
5
+
6
+ module Velvetkit
7
+ # The icon libraries an app can choose, and how the kit's icons get there.
8
+ #
9
+ # Like shadcn/ui, the choice is made when components are copied, not at
10
+ # runtime. The registry is written with Lucide names; on the way into an
11
+ # app whose config/velvetkit.yml says `icons: phosphor`, every icon name
12
+ # in a component, its test and its preview is swapped for Phosphor's
13
+ # (`circle-alert` → `warning-circle`), and the SVGs it draws are copied to
14
+ # app/assets/icons. After that the app's code names its own library's
15
+ # icons and nothing looks anything up.
16
+ #
17
+ # registry/icons.yml lists every icon the kit and its previews draw, by its
18
+ # Lucide name, with its name in each other library. registry/icons/<library>/
19
+ # holds the SVGs, fetched by `rake icons:sync`.
20
+ class Icons
21
+ CANONICAL = "lucide"
22
+
23
+ # Where each library's SVGs are published, one file per icon.
24
+ LIBRARIES = {
25
+ "lucide" => { package: "lucide-static", version: "0.545.0", file: "icons/%s.svg",
26
+ license: "ISC", browse: "https://lucide.dev/icons" },
27
+ "tabler" => { package: "@tabler/icons", version: "3.50.0", file: "icons/outline/%s.svg",
28
+ license: "MIT", browse: "https://tabler.io/icons" },
29
+ "phosphor" => { package: "@phosphor-icons/core", version: "2.1.1", file: "assets/regular/%s.svg",
30
+ license: "MIT", browse: "https://phosphoricons.com" }
31
+ }.freeze
32
+
33
+ NAME = /[a-z0-9]+(?:-[a-z0-9]+)*/
34
+
35
+ # Each way the kit's source names an icon, in a `name` group (`symbol`
36
+ # for `name: :x`). Only that group is renamed.
37
+ #
38
+ # UI::Icon.new(name: "check") with_leading_icon(name: :x)
39
+ # dismiss_icon: "x" { icon: "sun" }
40
+ # svg[data-icon='x'] (tests)
41
+ PATTERNS = [
42
+ /(?:Icon\.new|_icon)\(\s*name:\s*"(?<name>#{NAME})"/,
43
+ /(?:Icon\.new|_icon)\(\s*name:\s*:(?<symbol>[a-z0-9_]+)\b/,
44
+ /\b(?:\w+_)?icon:\s*"(?<name>#{NAME})"/,
45
+ /data-icon=\\?['"](?<name>#{NAME})/
46
+ ].freeze
47
+
48
+ # DEFAULT_ICONS = { default: "info", destructive: "circle-alert" }
49
+ MAP = /ICONS\s*=\s*\{(?<body>.*?)\}/m
50
+
51
+ def self.library!(name)
52
+ name = (name || CANONICAL).to_s
53
+ return name if LIBRARIES.key?(name)
54
+
55
+ raise Error, "Unknown icon library #{name.inspect}. Available: #{LIBRARIES.keys.join(', ')}"
56
+ end
57
+
58
+ attr_reader :root
59
+
60
+ def initialize(root)
61
+ @root = root
62
+ @names = YAML.load_file(File.join(root, "icons.yml"))
63
+ end
64
+
65
+ # Every icon the registry knows, by its Lucide name.
66
+ def canonical
67
+ @names.keys
68
+ end
69
+
70
+ # An icon's name in `library`, or nil if the registry doesn't map it.
71
+ def name(icon, library)
72
+ return (@names.key?(icon) ? icon : nil) if library == CANONICAL
73
+
74
+ @names.dig(icon, library)
75
+ end
76
+
77
+ # The Lucide names the source draws. Comments don't count.
78
+ def names_in(source)
79
+ code = without_comments(source)
80
+ names = PATTERNS.flat_map { |pattern| code.to_enum(:scan, pattern).map { icon_in(Regexp.last_match) } }
81
+ code.scan(MAP).flatten.each { |body| names += body.scan(/"(#{NAME})"/o).flatten }
82
+ names.uniq
83
+ end
84
+
85
+ # The source with every icon the registry maps renamed for `library`.
86
+ # Names it doesn't map are left alone.
87
+ def rewrite(source, library)
88
+ return source if library == CANONICAL
89
+
90
+ rename = ->(icon) { name(icon, library) || icon }
91
+ source = PATTERNS.reduce(source) do |text, pattern|
92
+ text.gsub(pattern) do |match|
93
+ found = Regexp.last_match
94
+ icon = icon_in(found)
95
+ next match if rename.call(icon) == icon
96
+
97
+ group = found.names.first
98
+ from = found.begin(group) - found.begin(0)
99
+ to = found.end(group) - found.begin(0)
100
+ # A symbol (`name: :x`) becomes a string: most names have a dash.
101
+ from -= 1 if group == "symbol"
102
+ match[0...from] + (group == "symbol" ? %("#{rename.call(icon)}") : rename.call(icon)) + match[to..]
103
+ end
104
+ end
105
+ source.gsub(MAP) { |map| map.gsub(/"(#{NAME})"/o) { %("#{rename.call(Regexp.last_match(1))}") } }
106
+ end
107
+
108
+ # The registry's copy of an icon's SVG, by its Lucide name.
109
+ def svg_file(icon, library)
110
+ File.join("icons", library, "#{name(icon, library)}.svg")
111
+ end
112
+
113
+ # An icon's SVG, by its name in `library`, from the npm CDN. Tagged with
114
+ # its license, which the ISC and MIT licenses ask copies to keep.
115
+ def self.download(icon, library)
116
+ raise Error, "#{icon.inspect} isn't an icon name" unless icon.match?(/\A#{NAME}\z/o)
117
+
118
+ spec = LIBRARIES.fetch(library)
119
+ uri = URI("https://unpkg.com/#{spec[:package]}@#{spec[:version]}/#{format(spec[:file], icon)}")
120
+ response = fetch(uri)
121
+ unless response.is_a?(Net::HTTPSuccess)
122
+ raise Error, "#{library} has no icon named #{icon.inspect} (#{uri} answered #{response.code}). " \
123
+ "Browse them at #{spec[:browse]}"
124
+ end
125
+
126
+ svg = response.body.sub(/\A\s*<!--.*?-->\s*/m, "").strip
127
+ "<!-- @license #{spec[:package]} v#{spec[:version]} - #{spec[:license]} -->\n#{svg}\n"
128
+ end
129
+
130
+ def self.fetch(uri, redirects = 3)
131
+ response = Net::HTTP.get_response(uri)
132
+ return response unless response.is_a?(Net::HTTPRedirection) && redirects.positive?
133
+
134
+ fetch(URI.join(uri, response["location"]), redirects - 1)
135
+ end
136
+ private_class_method :fetch
137
+
138
+ private
139
+
140
+ def icon_in(match)
141
+ match.names.include?("symbol") ? match[:symbol].tr("_", "-") : match[:name]
142
+ end
143
+
144
+ def without_comments(source)
145
+ source.gsub(/<%#.*?%>/m, "").lines.grep_v(/\A\s*#/).join
146
+ end
147
+ end
148
+ end
@@ -18,9 +18,8 @@ module Velvetkit
18
18
  FOUNDATION = %w[
19
19
  config/locales/velvetkit.en.yml
20
20
  app/assets/tailwind/velvetkit.css
21
- app/javascript/velvetkit_icons.ts
22
21
  ].freeze
23
- FOUNDATION_PACKAGES = %w[@hotwired/stimulus lucide tw-animate-css].freeze
22
+ FOUNDATION_PACKAGES = %w[@hotwired/stimulus tw-animate-css].freeze
24
23
 
25
24
  attr_reader :root
26
25
 
@@ -29,6 +28,10 @@ module Velvetkit
29
28
  @catalog = YAML.load_file(File.join(root, "components.yml"))
30
29
  end
31
30
 
31
+ def icons
32
+ @icons ||= Icons.new(root)
33
+ end
34
+
32
35
  def names
33
36
  @catalog.fetch("components").keys
34
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Velvetkit
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/velvetkit.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "velvetkit/version"
4
4
  require "velvetkit/namespace"
5
5
  require "velvetkit/registry"
6
+ require "velvetkit/icons"
6
7
  require "velvetkit/reference"
7
8
 
8
9
  # VelvetKit copies ViewComponent UI components into a Rails app, one at a time
@@ -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,13 @@
1
+ <%= tag.dialog(**dialog_attrs) do %>
2
+ <%= tag.form method: "dialog", class: PANEL, data: { state: "closed", "ui--confirm-dialog-target": "panel" } do %>
3
+ <div class="flex flex-col gap-2 text-center sm:text-left">
4
+ <%= tag.h2 id: title_id, class: "text-lg font-semibold leading-none tracking-tight", data: { "ui--confirm-dialog-target": "title" } %>
5
+ <%= tag.p id: description_id, hidden: true, class: "text-sm text-muted-foreground", data: { "ui--confirm-dialog-target": "description" } %>
6
+ </div>
7
+ <div class="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
8
+ <%= render(UI::Button.new(type: :submit, variant: :outline, value: "cancel", autofocus: true, data: { "ui--confirm-dialog-target": "cancel" })) { cancel_label } %>
9
+ <%= render(UI::Button.new(type: :submit, value: "confirm", data: { "ui--confirm-dialog-target": "confirm" })) { confirm_label } %>
10
+ <%= render(UI::Button.new(type: :submit, variant: :destructive, value: "confirm", hidden: true, data: { "ui--confirm-dialog-target": "destructive" })) { confirm_label } %>
11
+ </div>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A styled replacement for the browser's confirm() box that Turbo shows for
4
+ # `data-turbo-confirm`. Render one in your layout and every link, form and
5
+ # button_to that already asks for confirmation uses it, with no other change:
6
+ #
7
+ # <%= render(UI::ConfirmDialog.new) %>
8
+ #
9
+ # <%= button_to "Delete", project_path(@project), method: :delete,
10
+ # data: { turbo_confirm: "Delete this project?",
11
+ # confirm_description: "Its pages and files go too. This can't be undone.",
12
+ # confirm_button: "Delete project", confirm_variant: "destructive" } %>
13
+ #
14
+ # The confirm message is the dialog's title. Optional data attributes, on the
15
+ # same element as data-turbo-confirm, fill in the rest: `confirm-description`,
16
+ # `confirm-button` and `confirm-cancel` (the button labels), and
17
+ # `confirm-variant="destructive"` for a red confirm button.
18
+ #
19
+ # It's a native <dialog>: Escape and clicking outside cancel, focus is trapped
20
+ # inside and returns to the trigger, and Cancel has focus when it opens so a
21
+ # stray Enter never confirms.
22
+ class UI::ConfirmDialog < UI::Base
23
+ PANEL = "relative flex w-full max-w-md flex-col gap-6 rounded-lg border bg-background p-6 shadow-lg " \
24
+ "data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95"
25
+
26
+ def initialize(confirm_label: nil, cancel_label: nil, class: nil, **html_attrs)
27
+ @confirm_label = confirm_label
28
+ @cancel_label = cancel_label
29
+ @user_class = binding.local_variable_get(:class)
30
+ @html_attrs = html_attrs
31
+ @id = html_attrs[:id] || "ui-confirm-dialog"
32
+ end
33
+
34
+ def confirm_label = @confirm_label || t("ui.confirm_dialog.confirm", default: "Confirm")
35
+ def cancel_label = @cancel_label || t("ui.confirm_dialog.cancel", default: "Cancel")
36
+ def title_id = "#{@id}-title"
37
+ def description_id = "#{@id}-description"
38
+
39
+ def dialog_attrs
40
+ attrs = @html_attrs.except(:data)
41
+ attrs[:id] = @id
42
+ attrs[:class] = cn(
43
+ "fixed inset-0 m-0 h-full max-h-none w-full max-w-none border-0 bg-transparent p-4 overflow-visible " \
44
+ "open:flex open:items-center open:justify-center backdrop:bg-black/60 backdrop:backdrop-blur-[1px]",
45
+ @user_class
46
+ )
47
+ attrs[:aria] = { labelledby: title_id, describedby: description_id }
48
+ attrs[:data] = {
49
+ slot: "confirm-dialog", controller: "ui--confirm-dialog",
50
+ "ui--confirm-dialog-confirm-label-value": confirm_label,
51
+ "ui--confirm-dialog-cancel-label-value": cancel_label
52
+ }.merge(@html_attrs[:data] || {})
53
+ attrs
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ <%= tag.div class: classes, data: { slot: "empty-state" }.merge(@html_attrs[:data] || {}), **@html_attrs.except(:data) do %>
2
+ <% if header? %>
3
+ <div class="flex max-w-sm flex-col items-center gap-2">
4
+ <% if media? %>
5
+ <div class="mb-2"><%= media %></div>
6
+ <% elsif icon? %>
7
+ <div class="mb-2 flex size-12 items-center justify-center rounded-lg bg-muted text-foreground">
8
+ <%= render(UI::Icon.new(name: @icon, size: :lg)) %>
9
+ </div>
10
+ <% end %>
11
+ <% if @title.present? %><%= heading %><% end %>
12
+ <% if @description.present? %>
13
+ <p class="text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary"><%= @description %></p>
14
+ <% end %>
15
+ </div>
16
+ <% end %>
17
+ <% if content.present? %>
18
+ <div class="flex flex-wrap items-center justify-center gap-2"><%= content %></div>
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # What a page shows in place of a list with nothing in it: an icon, a title,
4
+ # a line saying why, and the buttons that get someone started. The block is
5
+ # the actions row; `with_media` replaces the icon with an avatar, image or
6
+ # anything else.
7
+ #
8
+ # `variant: :outline` draws a dashed border, for an empty area inside a page
9
+ # rather than the whole page. `heading_level:` sets the title's <h1>–<h6> so
10
+ # it fits the page's outline (default 3).
11
+ class UI::EmptyState < UI::Base
12
+ variants(
13
+ base: "flex w-full flex-col items-center justify-center gap-6 rounded-lg p-6 text-center text-balance md:p-12",
14
+ variants: {
15
+ variant: {
16
+ default: "",
17
+ outline: "border border-dashed"
18
+ }
19
+ },
20
+ defaults: { variant: :default }
21
+ )
22
+
23
+ renders_one :media
24
+
25
+ def initialize(title: nil, description: nil, icon: nil, variant: :default, heading_level: 3,
26
+ class: nil, **html_attrs)
27
+ @title = title
28
+ @description = description
29
+ @icon = icon
30
+ @variant = variant
31
+ @heading_level = heading_level.to_i.clamp(1, 6)
32
+ @user_class = binding.local_variable_get(:class)
33
+ @html_attrs = html_attrs
34
+ end
35
+
36
+ def classes
37
+ cn(variant_classes(variant: @variant), @user_class)
38
+ end
39
+
40
+ def heading
41
+ content_tag(:"h#{@heading_level}", @title, class: "text-lg font-semibold tracking-tight text-foreground")
42
+ end
43
+
44
+ def icon? = @icon.present?
45
+ def header? = media? || icon? || @title.present? || @description.present?
46
+ 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 %>