iron_admin 0.7.0 → 0.8.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 (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +129 -1
  3. data/README.md +48 -1
  4. data/UPGRADING.md +495 -8
  5. data/app/assets/tailwind/iron_admin/engine.css +79 -4
  6. data/app/components/iron_admin/dashboards/activity_feed_component/item_component.html.haml +6 -9
  7. data/app/components/iron_admin/dashboards/activity_feed_component.html.haml +6 -5
  8. data/app/components/iron_admin/dashboards/activity_feed_component.rb +21 -24
  9. data/app/components/iron_admin/dashboards/chart_component.html.haml +3 -5
  10. data/app/components/iron_admin/dashboards/chart_component.rb +86 -24
  11. data/app/components/iron_admin/dashboards/concerns/themed_card.rb +39 -0
  12. data/app/components/iron_admin/dashboards/metric_card_component.html.haml +8 -7
  13. data/app/components/iron_admin/dashboards/metric_card_component.rb +2 -0
  14. data/app/components/iron_admin/dashboards/progress_component.html.haml +11 -7
  15. data/app/components/iron_admin/dashboards/progress_component.rb +11 -6
  16. data/app/components/iron_admin/dashboards/quick_links_component/link_component.html.haml +8 -9
  17. data/app/components/iron_admin/dashboards/quick_links_component.html.haml +6 -5
  18. data/app/components/iron_admin/dashboards/quick_links_component.rb +4 -12
  19. data/app/components/iron_admin/dashboards/recent_table_component.html.haml +15 -10
  20. data/app/components/iron_admin/dashboards/recent_table_component.rb +49 -0
  21. data/app/components/iron_admin/dashboards/stats_grid_component/stat_component.html.haml +13 -14
  22. data/app/components/iron_admin/dashboards/stats_grid_component.html.haml +1 -0
  23. data/app/components/iron_admin/dashboards/stats_grid_component.rb +9 -11
  24. data/app/components/iron_admin/filters/bar_component.html.haml +8 -6
  25. data/app/components/iron_admin/filters/bar_component.rb +56 -9
  26. data/app/components/iron_admin/filters/control_styles.rb +82 -0
  27. data/app/components/iron_admin/filters/date_range_component.html.haml +9 -4
  28. data/app/components/iron_admin/filters/date_range_component.rb +10 -6
  29. data/app/components/iron_admin/filters/search_component.html.haml +4 -4
  30. data/app/components/iron_admin/filters/search_component.rb +3 -5
  31. data/app/components/iron_admin/filters/select_filter_component.html.haml +1 -1
  32. data/app/components/iron_admin/filters/select_filter_component.rb +5 -16
  33. data/app/components/iron_admin/form/belongs_to_autocomplete_component.html.haml +9 -5
  34. data/app/components/iron_admin/form/belongs_to_autocomplete_component.rb +10 -8
  35. data/app/components/iron_admin/form/belongs_to_component.html.haml +2 -2
  36. data/app/components/iron_admin/form/belongs_to_component.rb +4 -18
  37. data/app/components/iron_admin/form/checkbox_component.rb +2 -3
  38. data/app/components/iron_admin/form/concerns/form_input_behavior.rb +1 -1
  39. data/app/components/iron_admin/form/control_classes.rb +108 -0
  40. data/app/components/iron_admin/form/date_picker_component.rb +3 -7
  41. data/app/components/iron_admin/form/field_wrapper_component.html.haml +3 -3
  42. data/app/components/iron_admin/form/field_wrapper_component.rb +3 -3
  43. data/app/components/iron_admin/form/nested_form_component.html.haml +4 -5
  44. data/app/components/iron_admin/form/nested_form_component.rb +12 -2
  45. data/app/components/iron_admin/form/select_component.html.haml +1 -1
  46. data/app/components/iron_admin/form/select_component.rb +2 -16
  47. data/app/components/iron_admin/form/text_input_component.rb +1 -5
  48. data/app/components/iron_admin/form/textarea_component.rb +1 -5
  49. data/app/components/iron_admin/layout/flash_component.html.haml +1 -1
  50. data/app/components/iron_admin/layout/flash_component.rb +4 -3
  51. data/app/components/iron_admin/layout/navbar_component.html.haml +15 -9
  52. data/app/components/iron_admin/layout/navbar_component.rb +29 -1
  53. data/app/components/iron_admin/layout/shell_component.html.haml +4 -4
  54. data/app/components/iron_admin/layout/shell_component.rb +16 -3
  55. data/app/components/iron_admin/layout/sidebar_component.html.haml +21 -25
  56. data/app/components/iron_admin/layout/sidebar_component.rb +76 -1
  57. data/app/components/iron_admin/layout/theme_switcher_component.html.haml +15 -0
  58. data/app/components/iron_admin/layout/theme_switcher_component.rb +74 -0
  59. data/app/components/iron_admin/resources/actions_component.html.haml +15 -8
  60. data/app/components/iron_admin/resources/actions_component.rb +34 -2
  61. data/app/components/iron_admin/resources/breadcrumb_component.html.haml +3 -3
  62. data/app/components/iron_admin/resources/breadcrumb_component.rb +8 -7
  63. data/app/components/iron_admin/resources/bulk_actions_component.html.haml +9 -8
  64. data/app/components/iron_admin/resources/bulk_actions_component.rb +47 -4
  65. data/app/components/iron_admin/resources/data_table_component.html.haml +15 -15
  66. data/app/components/iron_admin/resources/data_table_component.rb +34 -3
  67. data/app/components/iron_admin/resources/related_list_component.html.haml +7 -7
  68. data/app/components/iron_admin/resources/related_list_component.rb +26 -2
  69. data/app/components/iron_admin/resources/show_field_component.html.haml +3 -3
  70. data/app/components/iron_admin/resources/show_field_component.rb +10 -4
  71. data/app/components/iron_admin/resources/styles.rb +136 -0
  72. data/app/components/iron_admin/ui/alert_component.html.haml +2 -2
  73. data/app/components/iron_admin/ui/alert_component.rb +27 -31
  74. data/app/components/iron_admin/ui/badge_component.rb +40 -20
  75. data/app/components/iron_admin/ui/button_component.rb +37 -11
  76. data/app/components/iron_admin/ui/card_component.rb +3 -3
  77. data/app/components/iron_admin/ui/dropdown_component.html.haml +1 -1
  78. data/app/components/iron_admin/ui/dropdown_component.rb +34 -13
  79. data/app/components/iron_admin/ui/empty_state_component.html.haml +4 -5
  80. data/app/components/iron_admin/ui/empty_state_component.rb +2 -2
  81. data/app/components/iron_admin/ui/modal_component.html.haml +5 -5
  82. data/app/components/iron_admin/ui/modal_component.rb +6 -4
  83. data/app/components/iron_admin/ui/pagination_component.html.haml +14 -14
  84. data/app/components/iron_admin/ui/pagination_component.rb +26 -9
  85. data/app/components/iron_admin/ui/scopes_component.html.haml +2 -2
  86. data/app/components/iron_admin/ui/scopes_component.rb +44 -11
  87. data/app/components/iron_admin/ui/tooltip_component.rb +11 -4
  88. data/app/controllers/iron_admin/application_controller.rb +58 -4
  89. data/app/controllers/iron_admin/audit_controller.rb +30 -6
  90. data/app/controllers/iron_admin/concerns/action_executable.rb +37 -0
  91. data/app/controllers/iron_admin/concerns/assignable_references.rb +149 -0
  92. data/app/controllers/iron_admin/concerns/authorizable.rb +11 -0
  93. data/app/controllers/iron_admin/concerns/blank_password_filterable.rb +21 -0
  94. data/app/controllers/iron_admin/concerns/event_emittable.rb +47 -7
  95. data/app/controllers/iron_admin/concerns/filterable.rb +34 -9
  96. data/app/controllers/iron_admin/concerns/nested_permittable.rb +5 -3
  97. data/app/controllers/iron_admin/concerns/nested_tenant_check.rb +159 -0
  98. data/app/controllers/iron_admin/concerns/polymorphic_references.rb +131 -0
  99. data/app/controllers/iron_admin/concerns/scopeable.rb +54 -7
  100. data/app/controllers/iron_admin/concerns/searchable.rb +3 -3
  101. data/app/controllers/iron_admin/concerns/tenant_assignable.rb +118 -0
  102. data/app/controllers/iron_admin/concerns/tenant_containment.rb +146 -0
  103. data/app/controllers/iron_admin/exports_controller.rb +2 -2
  104. data/app/controllers/iron_admin/imports_controller.rb +1 -1
  105. data/app/controllers/iron_admin/resources_controller.rb +48 -41
  106. data/app/controllers/iron_admin/search_controller.rb +1 -2
  107. data/app/controllers/iron_admin/themes_controller.rb +50 -0
  108. data/app/controllers/iron_admin/tools_controller.rb +58 -5
  109. data/app/helpers/iron_admin/action_form_helper.rb +19 -0
  110. data/app/helpers/iron_admin/application_helper.rb +93 -16
  111. data/app/helpers/iron_admin/assignable_records_helper.rb +32 -0
  112. data/app/helpers/iron_admin/component_overrides_helper.rb +9 -4
  113. data/app/helpers/iron_admin/field_display_helper.rb +88 -43
  114. data/app/helpers/iron_admin/related_records_helper.rb +51 -0
  115. data/app/helpers/iron_admin/theme_helper.rb +56 -46
  116. data/app/javascript/iron_admin/controllers/cp_bulk_select_controller.js +12 -0
  117. data/app/javascript/iron_admin/controllers/cp_chart_controller.js +4 -0
  118. data/app/javascript/iron_admin/controllers/cp_disclosure_controller.js +19 -0
  119. data/app/javascript/iron_admin/controllers/cp_search_shortcut_controller.js +39 -0
  120. data/app/javascript/iron_admin/index.js +4 -0
  121. data/app/views/iron_admin/audit/index.html.haml +78 -81
  122. data/app/views/iron_admin/dashboard/index.html.haml +10 -9
  123. data/app/views/iron_admin/form/_action_field.html.haml +50 -0
  124. data/app/views/iron_admin/form/_nested_row.html.haml +18 -13
  125. data/app/views/iron_admin/imports/new.html.haml +14 -13
  126. data/app/views/iron_admin/imports/preview.html.haml +24 -21
  127. data/app/views/iron_admin/resources/_form.html.haml +70 -68
  128. data/app/views/iron_admin/resources/action_form.html.haml +16 -59
  129. data/app/views/iron_admin/resources/bulk_action_form.html.haml +20 -58
  130. data/app/views/iron_admin/resources/edit.html.haml +3 -3
  131. data/app/views/iron_admin/resources/index.html.haml +87 -74
  132. data/app/views/iron_admin/resources/new.html.haml +2 -2
  133. data/app/views/iron_admin/resources/show.html.haml +53 -41
  134. data/app/views/iron_admin/search/index.html.haml +17 -9
  135. data/app/views/iron_admin/shared/_pagination.html.haml +13 -10
  136. data/app/views/iron_admin/shared/error.html.haml +16 -12
  137. data/app/views/iron_admin/tools/action_form.html.haml +9 -55
  138. data/app/views/iron_admin/tools/show.html.haml +4 -5
  139. data/app/views/layouts/iron_admin/_document_head.html.haml +24 -0
  140. data/app/views/layouts/iron_admin/application.html.haml +4 -17
  141. data/app/views/layouts/iron_admin/minimal.html.haml +7 -0
  142. data/config/importmap.rb +2 -0
  143. data/config/locales/en.yml +23 -0
  144. data/config/routes.rb +1 -0
  145. data/docs/FAQ.md +87 -37
  146. data/docs/README.md +8 -2
  147. data/docs/components/README.md +6 -2
  148. data/docs/components/dashboard-components.md +24 -35
  149. data/docs/components/filter-components.md +44 -92
  150. data/docs/components/form-components.md +16 -32
  151. data/docs/components/resource-components.md +46 -27
  152. data/docs/components/ui-components.md +44 -26
  153. data/docs/getting-started/installation.md +5 -1
  154. data/docs/getting-started/quick-start.md +36 -23
  155. data/docs/guides/authentication.md +182 -42
  156. data/docs/guides/components.md +97 -15
  157. data/docs/guides/custom-adapters.md +24 -4
  158. data/docs/guides/dashboard.md +68 -44
  159. data/docs/guides/export.md +24 -8
  160. data/docs/guides/extending.md +206 -51
  161. data/docs/guides/fields.md +229 -70
  162. data/docs/guides/imports.md +33 -18
  163. data/docs/guides/resources.md +333 -111
  164. data/docs/guides/theming.md +930 -58
  165. data/docs/guides/troubleshooting.md +7 -3
  166. data/docs/plugin-system-design.md +8 -7
  167. data/docs/reference/configuration.md +51 -16
  168. data/docs/reference/routes.md +1 -0
  169. data/docs/reference/theme-properties.md +101 -38
  170. data/lib/generators/iron_admin/install/templates/initializer.rb.tt +7 -2
  171. data/lib/generators/iron_admin/install_audit/templates/create_iron_admin_audit_entries.rb.tt +2 -0
  172. data/lib/iron_admin/action_field.rb +11 -0
  173. data/lib/iron_admin/adapters/active_record.rb +95 -0
  174. data/lib/iron_admin/adapters/base.rb +107 -0
  175. data/lib/iron_admin/adapters/http/query.rb +21 -0
  176. data/lib/iron_admin/adapters/http.rb +84 -4
  177. data/lib/iron_admin/adapters/mongoid.rb +96 -2
  178. data/lib/iron_admin/audit_log.rb +64 -6
  179. data/lib/iron_admin/authentication_warning.rb +31 -0
  180. data/lib/iron_admin/concerns/filter_definable.rb +15 -1
  181. data/lib/iron_admin/concerns/nestable.rb +25 -0
  182. data/lib/iron_admin/concerns/scope_countable.rb +56 -0
  183. data/lib/iron_admin/concerns/soft_deletable.rb +28 -9
  184. data/lib/iron_admin/configuration/components.rb +14 -3
  185. data/lib/iron_admin/configuration/theme/neutral_defaults.rb +179 -0
  186. data/lib/iron_admin/configuration/theme.rb +292 -87
  187. data/lib/iron_admin/configuration.rb +340 -45
  188. data/lib/iron_admin/dashboard.rb +22 -38
  189. data/lib/iron_admin/engine.rb +16 -2
  190. data/lib/iron_admin/errors.rb +3 -0
  191. data/lib/iron_admin/field.rb +78 -17
  192. data/lib/iron_admin/field_inferrer.rb +61 -3
  193. data/lib/iron_admin/field_override_warning.rb +67 -0
  194. data/lib/iron_admin/import/import_preview.rb +56 -7
  195. data/lib/iron_admin/import/importer.rb +91 -14
  196. data/lib/iron_admin/import/tenant_precheck.rb +67 -0
  197. data/lib/iron_admin/plugin/registration.rb +64 -0
  198. data/lib/iron_admin/plugin_registry.rb +3 -2
  199. data/lib/iron_admin/policy.rb +22 -12
  200. data/lib/iron_admin/policy_coverage_warning.rb +46 -0
  201. data/lib/iron_admin/request_context.rb +18 -0
  202. data/lib/iron_admin/resource.rb +218 -77
  203. data/lib/iron_admin/resource_registry.rb +86 -13
  204. data/lib/iron_admin/scope_counts.rb +73 -0
  205. data/lib/iron_admin/tenant_scope.rb +30 -0
  206. data/lib/iron_admin/tool.rb +61 -12
  207. data/lib/iron_admin/tool_context.rb +10 -6
  208. data/lib/iron_admin/version.rb +1 -1
  209. data/lib/iron_admin.rb +29 -2
  210. metadata +37 -7
@@ -11,15 +11,20 @@
11
11
  @source "../../../javascript/**/*.js";
12
12
  @source "../../../../lib/iron_admin/**/*.rb";
13
13
 
14
- /* Inline SVG backgrounds used by ThemeHelper#cp_select_class and #cp_checkbox_class. */
14
+ /* Inline SVG backgrounds used by IronAdmin::Form::ControlClasses (selects, checkboxes, radios). */
15
15
  /* A Tailwind bg-[url(...)] class holding them does not fit in one source line, */
16
16
  /* and Tailwind generates nothing for a class split across string literals. */
17
+ /* The chevron is zinc-500, and zinc-400 under a theme whose color_scheme is "dark". */
17
18
  @layer components {
18
19
  .cp-select-chevron {
19
- background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2020%2020%22%20fill%3D%22%236b7280%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20d%3D%22M5.23%207.21a.75.75%200%20011.06.02L10%2011.168l3.71-3.938a.75.75%200%20111.08%201.04l-4.25%204.5a.75.75%200%2001-1.08%200l-4.25-4.5a.75.75%200%2001.02-1.06z%22%20clip-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E");
20
- background-position: right 0.5rem center;
20
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2020%2020%22%20fill%3D%22%2371717a%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20d%3D%22M5.23%207.21a.75.75%200%20011.06.02L10%2011.168l3.71-3.938a.75.75%200%20111.08%201.04l-4.25%204.5a.75.75%200%2001-1.08%200l-4.25-4.5a.75.75%200%2001.02-1.06z%22%20clip-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E");
21
+ background-position: right 0.625rem center;
21
22
  background-repeat: no-repeat;
22
- background-size: 1.25rem 1.25rem;
23
+ background-size: 1rem 1rem;
24
+ }
25
+
26
+ .scheme-dark .cp-select-chevron {
27
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2020%2020%22%20fill%3D%22%23a1a1aa%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20d%3D%22M5.23%207.21a.75.75%200%20011.06.02L10%2011.168l3.71-3.938a.75.75%200%20111.08%201.04l-4.25%204.5a.75.75%200%2001-1.08%200l-4.25-4.5a.75.75%200%2001.02-1.06z%22%20clip-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E");
23
28
  }
24
29
 
25
30
  .cp-checkbox-mark:checked {
@@ -28,4 +33,74 @@
28
33
  background-repeat: no-repeat;
29
34
  background-size: 100% 100%;
30
35
  }
36
+
37
+ .cp-radio-mark:checked {
38
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22white%22%3E%3Ccircle%20cx%3D%228%22%20cy%3D%228%22%20r%3D%223%22%2F%3E%3C%2Fsvg%3E");
39
+ background-position: center;
40
+ background-repeat: no-repeat;
41
+ background-size: 100% 100%;
42
+ }
43
+ }
44
+
45
+ /* Rich text (Action Text's Trix). Trix's stylesheet is not in a cascade layer, so its rules win */
46
+ /* over every Tailwind utility; these rules are not in a layer either. A theme's rich_text_editor */
47
+ /* marks the editor with cp-rich-text, and revert-layer hands the border and radius that Trix sets */
48
+ /* back to the theme's classes. Under a dark color scheme the toolbar's black icons are inverted. */
49
+ trix-editor.cp-rich-text {
50
+ border: revert-layer;
51
+ border-radius: revert-layer;
52
+ }
53
+
54
+ /* Trix scrolls its row of button groups sideways when it is wider than the field, and its */
55
+ /* buttons are not focusable, so keyboard users could not reach the groups past the edge. */
56
+ /* In IronAdmin's rich text field (cp-rich-text-field) the groups wrap onto more rows instead. */
57
+ .cp-rich-text-field trix-toolbar .trix-button-row {
58
+ flex-wrap: wrap;
59
+ overflow-x: visible;
60
+ column-gap: 0.5rem;
61
+ }
62
+
63
+ .cp-rich-text-field trix-toolbar .trix-button-group:not(:first-child) {
64
+ margin-left: 0;
65
+ }
66
+
67
+ .scheme-dark trix-toolbar .trix-button--icon::before {
68
+ filter: invert(1);
69
+ }
70
+
71
+ /* Scroll frames (cp-scroll-fade): a table or a row of tabs wider than its frame scrolls sideways, */
72
+ /* and phones hide the scrollbar. The frame fades out at each edge it can still scroll toward. */
73
+ /* A scroll timeline drives the fade, so a frame that fits, or a browser without scroll */
74
+ /* timelines, shows none. The fade is a mask, so it suits any theme's colors; a mask also hides */
75
+ /* focus outlines, so it lifts while the frame or a control in it has the keyboard focus. */
76
+ @property --cp-fade-start {
77
+ syntax: "<length>";
78
+ inherits: false;
79
+ initial-value: 0px;
80
+ }
81
+
82
+ @property --cp-fade-end {
83
+ syntax: "<length>";
84
+ inherits: false;
85
+ initial-value: 0px;
86
+ }
87
+
88
+ @keyframes cp-scroll-fade {
89
+ 0% { --cp-fade-start: 0px; --cp-fade-end: 2rem; }
90
+ 8% { --cp-fade-start: 2rem; }
91
+ 92% { --cp-fade-end: 2rem; }
92
+ 100% { --cp-fade-start: 2rem; --cp-fade-end: 0px; }
93
+ }
94
+
95
+ @supports (animation-timeline: scroll()) {
96
+ .cp-scroll-fade {
97
+ mask-image: linear-gradient(to right, transparent, #000 var(--cp-fade-start), #000 calc(100% - var(--cp-fade-end)), transparent);
98
+ animation: cp-scroll-fade linear both;
99
+ animation-timeline: scroll(self inline);
100
+ }
101
+
102
+ .cp-scroll-fade:focus-visible,
103
+ .cp-scroll-fade:has(:focus-visible) {
104
+ mask-image: none;
105
+ }
31
106
  }
@@ -1,10 +1,7 @@
1
- %li.px-6.py-4{ class: href ? "hover:bg-gray-50 transition-colors" : "" }
2
- - wrapper = href ? link_to(href, class: "flex items-center gap-4") : tag.div(class: "flex items-center gap-4")
3
- = wrapper do
4
- .shrink-0.p-2.rounded-full{ class: icon_classes }
1
+ %li
2
+ -# A link when the item has an href, else a div; content_tag leaves out a nil href.
3
+ = content_tag(href ? :a : :div, class: row_classes, href: href) do
4
+ .flex.h-7.w-7.shrink-0.items-center.justify-center{ class: icon_classes }
5
5
  = heroicon icon, variant: :mini, options: { class: "h-4 w-4" }
6
- .flex-1.min-w-0
7
- %p.text-sm{ class: theme.body_text }
8
- = description
9
- %time.text-xs{ class: theme.muted_text, datetime: timestamp }
10
- = formatted_timestamp
6
+ %p.min-w-0.flex-1.text-sm{ class: theme.body_text }= description
7
+ %time.shrink-0.text-xs.tabular-nums{ class: theme.muted_text, datetime: timestamp }= formatted_timestamp
@@ -1,8 +1,9 @@
1
- %div{ class: "#{theme.card_bg} border #{theme.card_border} #{theme.border_radius} #{theme.card_shadow}" }
2
- .px-6.py-4.border-b{ class: theme.card_border }
3
- %h3.text-lg.font-semibold{ class: theme.body_text }
4
- = title
1
+ %div{ class: card_classes }
2
+ -# py-3.5 goes in the class string: in HAML's dot syntax ".py-3.5" is the classes "py-3" and "5".
3
+ %div{ class: "border-b px-5 py-3.5 #{theme.card_border}" }
4
+ %h2{ class: title_classes }= title
5
5
 
6
- %ul.divide-y{ class: theme.card_border, role: "list" }
6
+ -# divide-y takes its color from table_border: a border color on the list would leave the dividers in currentColor.
7
+ %ul.divide-y{ class: theme.table_border, role: "list" }
7
8
  - items.each do |item|
8
9
  = item
@@ -4,6 +4,8 @@ module IronAdmin
4
4
  module Dashboards
5
5
  # Renders an activity feed on the dashboard.
6
6
  class ActivityFeedComponent < ViewComponent::Base
7
+ include Concerns::ThemedCard
8
+
7
9
  renders_many :items, "ItemComponent"
8
10
 
9
11
  # @return [String] Feed title
@@ -14,12 +16,6 @@ module IronAdmin
14
16
  @title = title
15
17
  end
16
18
 
17
- # @api private
18
- # @return [IronAdmin::Configuration::Theme] Theme configuration
19
- def theme
20
- IronAdmin.configuration.theme
21
- end
22
-
23
19
  # @api private
24
20
  # @return [Boolean] Whether to render the component
25
21
  def render?
@@ -29,10 +25,12 @@ module IronAdmin
29
25
  # Individual activity feed item component.
30
26
  # @api private
31
27
  class ItemComponent < ViewComponent::Base
28
+ include Concerns::ThemedCard
29
+
32
30
  # @return [String] Icon name
33
31
  attr_reader :icon
34
32
 
35
- # @return [Symbol] Icon color
33
+ # @return [Symbol] Icon color, a key of the theme's badge palette
36
34
  attr_reader :icon_color
37
35
 
38
36
  # @return [String] Item description
@@ -44,20 +42,11 @@ module IronAdmin
44
42
  # @return [String, nil] Optional link URL
45
43
  attr_reader :href
46
44
 
47
- # Color classes for icon backgrounds.
48
- # @api private
49
- COLORS = {
50
- green: "bg-green-100 text-green-600",
51
- red: "bg-red-100 text-red-600",
52
- blue: "bg-blue-100 text-blue-600",
53
- yellow: "bg-yellow-100 text-yellow-600",
54
- gray: "bg-gray-100 text-gray-600",
55
- }.freeze
56
-
57
45
  # @param description [String] Item description
58
46
  # @param timestamp [Time, String] Item timestamp
59
47
  # @param icon [String] Heroicon name (default: "circle-stack")
60
- # @param icon_color [Symbol] Icon color (default: :blue)
48
+ # @param icon_color [Symbol] Icon color, a key of the theme's badge palette such as
49
+ # :green, :red, :yellow or :gray (default: :blue)
61
50
  # @param href [String, nil] Optional link URL
62
51
  def initialize(description:, timestamp:, icon: "circle-stack", icon_color: :blue, href: nil)
63
52
  @description = description
@@ -67,16 +56,24 @@ module IronAdmin
67
56
  @href = href
68
57
  end
69
58
 
59
+ # The icon tile is tinted like a badge of the same color; an unknown color is gray.
60
+ #
70
61
  # @api private
71
- # @return [IronAdmin::Configuration::Theme] Theme configuration
72
- def theme
73
- IronAdmin.configuration.theme
62
+ # @return [String] Icon tile colors from the theme's badge palette, and its radius
63
+ def icon_classes
64
+ palette = theme.badge_palette
65
+ "#{palette.fetch(icon_color) { palette[:gray] }} #{theme.control_radius}"
74
66
  end
75
67
 
68
+ # Only a row with an href is a link, so only it highlights on hover and shows a focus ring.
69
+ # It uses table_row_hover, not item_hover, so the muted time keeps AA contrast.
70
+ #
76
71
  # @api private
77
- # @return [String] CSS classes for icon background color
78
- def icon_classes
79
- COLORS[@icon_color] || COLORS[:gray]
72
+ # @return [String] Classes of the row
73
+ def row_classes
74
+ return "flex items-center gap-3 px-5 py-3" unless href
75
+
76
+ "flex items-center gap-3 px-5 py-3 transition-colors #{theme.table_row_hover} #{theme.focus_ring}"
80
77
  end
81
78
 
82
79
  # @api private
@@ -1,6 +1,4 @@
1
- %div{ class: "#{theme.card_bg} border #{theme.card_border} #{theme.border_radius} #{theme.card_shadow} p-6",
2
- data: { controller: "cp-chart", cp_chart_config_value: chart_config } }
3
- %h3.text-lg.font-semibold.mb-4{ class: theme.body_text }
4
- = title
1
+ %div{ class: "#{card_classes} p-5", data: { controller: "cp-chart", cp_chart_config_value: chart_config } }
2
+ %h2.mb-4{ class: title_classes }= title
5
3
  %div{ style: "height: #{height}px; position: relative;" }
6
- %canvas{ data: { cp_chart_target: "canvas" } }
4
+ %canvas{ role: "img", aria: { label: title }, data: { cp_chart_target: "canvas" } }
@@ -5,6 +5,8 @@ module IronAdmin
5
5
  module Dashboards
6
6
  # Renders a chart on the dashboard.
7
7
  class ChartComponent < ViewComponent::Base
8
+ include Concerns::ThemedCard
9
+
8
10
  # @return [String] Chart title
9
11
  attr_reader :title
10
12
 
@@ -35,6 +37,11 @@ module IronAdmin
35
37
  # @return [Array<Symbol>]
36
38
  SINGLE_SERIES_TYPES = %i[line area radar].freeze
37
39
 
40
+ # Bar types: their bars are one series, so they share one color unless the chart
41
+ # passes its own `colors:`.
42
+ # @return [Array<Symbol>]
43
+ BAR_TYPES = %i[bar horizontal_bar].freeze
44
+
38
45
  # Types whose area is filled by default. `:line` stays filled for
39
46
  # backward compatibility (it was filled before `:area` was introduced);
40
47
  # `:area` is the explicit, intention-revealing name for a filled line.
@@ -45,6 +52,14 @@ module IronAdmin
45
52
  # @return [Array<Symbol>]
46
53
  LEGEND_TYPES = %i[pie doughnut polar_area].freeze
47
54
 
55
+ # Types drawn on x and y axes.
56
+ # @return [Array<Symbol>]
57
+ CARTESIAN_TYPES = %i[line area bar horizontal_bar].freeze
58
+
59
+ # Types drawn on a radial scale.
60
+ # @return [Array<Symbol>]
61
+ RADIAL_TYPES = %i[radar polar_area].freeze
62
+
48
63
  # @param title [String] Chart title
49
64
  # @param type [Symbol] Chart type (default: :line)
50
65
  # @param data [Array] Chart data
@@ -60,12 +75,6 @@ module IronAdmin
60
75
  @height = height
61
76
  end
62
77
 
63
- # @api private
64
- # @return [IronAdmin::Configuration::Theme] Theme configuration
65
- def theme
66
- IronAdmin.configuration.theme
67
- end
68
-
69
78
  # @api private
70
79
  # @return [String] Unique chart element ID
71
80
  def chart_id
@@ -80,22 +89,9 @@ module IronAdmin
80
89
  type: chart_js_type,
81
90
  data: {
82
91
  labels: labels,
83
- datasets: [{
84
- data: data,
85
- borderColor: border,
86
- backgroundColor: dataset_background(border),
87
- fill: filled?,
88
- tension: 0.3,
89
- }],
90
- },
91
- options: {
92
- responsive: true,
93
- maintainAspectRatio: false,
94
- indexAxis: index_axis,
95
- plugins: {
96
- legend: { display: legend? },
97
- },
92
+ datasets: [dataset(border)],
98
93
  },
94
+ options: chart_options,
99
95
  }.to_json
100
96
  end
101
97
 
@@ -132,12 +128,78 @@ module IronAdmin
132
128
 
133
129
  private
134
130
 
135
- # Resolves the dataset background: a single semi-transparent fill for
136
- # single-series charts, or the full color palette for multi-slice charts.
131
+ # The outline width is left out unless the theme sets one, so Chart.js keeps its defaults.
132
+ # @param border [String] Resolved border color
133
+ # @return [Hash] The chart's one dataset
134
+ def dataset(border)
135
+ set = {
136
+ data: data,
137
+ borderColor: dataset_border(border),
138
+ backgroundColor: dataset_background(border),
139
+ fill: filled?,
140
+ tension: 0.3,
141
+ }
142
+ width = theme.chart_border_width
143
+ width ? set.merge(borderWidth: width) : set
144
+ end
145
+
146
+ # Grid, tick and legend colors come from the theme, so dark themes get readable charts.
147
+ # @return [Hash] Chart.js options
148
+ def chart_options
149
+ options = {
150
+ responsive: true,
151
+ maintainAspectRatio: false,
152
+ indexAxis: index_axis,
153
+ plugins: {
154
+ legend: { display: legend?, labels: legend_labels },
155
+ },
156
+ }
157
+ scales = scale_options
158
+ scales ? options.merge(scales: scales) : options
159
+ end
160
+
161
+ # @return [Hash] Chart.js legend label options: the theme's text color and point style
162
+ def legend_labels
163
+ { color: theme.chart_text_color, usePointStyle: true, pointStyle: theme.chart_point_style }
164
+ end
165
+
166
+ # Pie and doughnut charts get no scales: Chart.js would draw axes for them. Cartesian
167
+ # charts draw grid lines across the value axis only, as the category axis needs none.
168
+ # @return [Hash, nil] Chart.js scale options in the theme's colors
169
+ def scale_options
170
+ grid = theme.chart_grid_color
171
+ text = theme.chart_text_color
172
+ if CARTESIAN_TYPES.include?(type)
173
+ value = { grid: { color: grid }, border: { color: grid }, ticks: { color: text } }
174
+ category = value.merge(grid: { color: grid, display: false })
175
+ index_axis == "y" ? { x: value, y: category } : { x: category, y: value }
176
+ elsif RADIAL_TYPES.include?(type)
177
+ ticks = { color: text, backdropColor: "transparent" }
178
+ { r: { grid: { color: grid }, angleLines: { color: grid }, pointLabels: { color: text }, ticks: ticks } }
179
+ end
180
+ end
181
+
182
+ # Multi-slice charts outline each slice in its own color, unless the theme sets a
183
+ # chart_slice_border_color: the line color would ring every slice, and every legend entry.
184
+ # @param border [String] Resolved border color
185
+ # @return [String, Array<String>] Border color(s) for the dataset
186
+ def dataset_border(border)
187
+ return border unless legend?
188
+
189
+ theme.chart_slice_border_color.presence || resolved_colors
190
+ end
191
+
192
+ # Resolves the dataset background: a single semi-transparent fill for line,
193
+ # area and radar charts, the theme's first chart color for the bars of a bar
194
+ # chart (one series: a color per bar would suggest categories), or the full
195
+ # palette for multi-slice charts and for bars given their own `colors:`.
137
196
  # @param border [String] Resolved border color
138
197
  # @return [String, Array<String>] Background color(s) for the dataset
139
198
  def dataset_background(border)
140
- SINGLE_SERIES_TYPES.include?(type) ? line_fill_color(border) : resolved_colors
199
+ return line_fill_color(border) if SINGLE_SERIES_TYPES.include?(type)
200
+ return theme.chart_colors.first if BAR_TYPES.include?(type) && @colors.nil?
201
+
202
+ resolved_colors
141
203
  end
142
204
 
143
205
  # @return [Array<String>] Color palette resolved from per-chart, theme, or default
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IronAdmin
4
+ module Dashboards
5
+ # Concerns shared by the dashboard components.
6
+ module Concerns
7
+ # Theme classes shared by the dashboard widgets, so every card, title,
8
+ # label and icon tile on the dashboard reads the same theme properties.
9
+ #
10
+ # @api private
11
+ module ThemedCard
12
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
13
+ def theme
14
+ IronAdmin.current_theme
15
+ end
16
+
17
+ # @return [String] Card surface, border, radius and shadow
18
+ def card_classes
19
+ "#{theme.card_bg} #{theme.border_width} #{theme.card_border} #{theme.border_radius} #{theme.card_shadow}"
20
+ end
21
+
22
+ # @return [String] Widget title (h2): size, weight, color and font
23
+ def title_classes
24
+ "#{theme.card_title} #{theme.heading_font}"
25
+ end
26
+
27
+ # @return [String] Small label above a figure: size, weight, color and case
28
+ def label_classes
29
+ "#{theme.metric_label} #{theme.label_transform}"
30
+ end
31
+
32
+ # @return [String] Tile behind a widget icon: background, icon color and radius
33
+ def icon_tile_classes
34
+ "#{theme.metric_icon} #{theme.control_radius}"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,8 +1,9 @@
1
- -# The value sits on its own full-width row and never wraps: a narrow xl card would split a number in two.
2
- .bg-white.rounded-lg.shadow.p-6{ **(live? ? { id: live_target_id } : {}) }
3
- .flex.items-start.justify-between.gap-4
4
- %p.min-w-0.break-words.text-sm.font-medium.text-gray-500= label
1
+ -# Label on top, figure below on its own full-width row. The figure has no break-words, so a narrow
2
+ -# xl card never splits a number, and its size comes from the theme's metric_value alone.
3
+ %div{ class: "#{card_classes} p-5", **(live? ? { id: live_target_id } : {}) }
4
+ .flex.items-center.justify-between.gap-3
5
+ %p.min-w-0.break-words{ class: label_classes }= label
5
6
  - if icon
6
- .shrink-0.p-3.bg-indigo-50.rounded-lg
7
- = heroicon icon, variant: :outline, options: { class: "h-6 w-6 text-indigo-600" }
8
- %p.mt-2.text-3xl.font-bold.text-gray-900{ class: "xl:text-2xl 2xl:text-3xl" }= formatted_value
7
+ .flex.h-8.w-8.shrink-0.items-center.justify-center{ class: icon_tile_classes }
8
+ = heroicon icon, variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
9
+ %p.mt-2{ class: theme.metric_value }= formatted_value
@@ -4,6 +4,8 @@ module IronAdmin
4
4
  module Dashboards
5
5
  # Renders a metric card with name and formatted value.
6
6
  class MetricCardComponent < ViewComponent::Base
7
+ include Concerns::ThemedCard
8
+
7
9
  # @param name [String, Symbol] Metric name
8
10
  # @param value [Numeric] Metric value
9
11
  # @param format [Symbol] Format (:number, :currency, :percentage)
@@ -1,7 +1,11 @@
1
- %div{ class: "#{theme.card_bg} border #{theme.card_border} #{theme.border_radius} #{theme.card_shadow} p-6" }
2
- .flex.items-center.justify-between.mb-2
3
- %h3.text-sm.font-medium{ class: theme.muted_text }= title
4
- %span.text-sm.font-semibold{ class: theme.body_text }= "#{formatted_value} / #{formatted_max}"
5
- .w-full.bg-gray-200.rounded-full.h-2.5
6
- %div{ class: "h-2.5 rounded-full", style: "width: #{percentage}%; background-color: #{bar_color};" }
7
- %p.mt-2.text-xs.text-right{ class: theme.muted_text }= "#{percentage}%"
1
+ -# Laid out like the metric cards: label on top, figure below, then the bar.
2
+ %div{ class: "#{card_classes} p-5" }
3
+ %h2{ class: label_classes }= title
4
+ .mt-2.flex.items-baseline.justify-between.gap-3
5
+ %p.min-w-0
6
+ %span{ class: theme.metric_value }= formatted_value
7
+ %span.whitespace-nowrap.text-sm.tabular-nums{ class: theme.muted_text }= "/ #{formatted_max}"
8
+ %p.shrink-0.text-sm.font-medium.tabular-nums{ class: theme.muted_text }= "#{percentage}%"
9
+ -# h-1.5 goes in the class string: in HAML's dot syntax ".h-1.5" is the classes "h-1" and "5".
10
+ %div{ class: "mt-3 h-1.5 overflow-hidden #{theme.progress_track} #{theme.control_radius}", role: "progressbar", aria: bar_aria }
11
+ .h-full{ class: theme.control_radius, style: "width: #{percentage}%; background-color: #{bar_color};" }
@@ -4,6 +4,8 @@ module IronAdmin
4
4
  module Dashboards
5
5
  # Renders a progress (gauge) widget showing a value as a proportion of a target.
6
6
  class ProgressComponent < ViewComponent::Base
7
+ include Concerns::ThemedCard
8
+
7
9
  # @return [String] Widget title
8
10
  attr_reader :title
9
11
 
@@ -49,16 +51,19 @@ module IronAdmin
49
51
  format_number(max)
50
52
  end
51
53
 
54
+ # The bar reports the percentage, which stays within 0..100 even past the target,
55
+ # and reads out the value and the target as text.
56
+ #
52
57
  # @api private
53
- # @return [String] CSS color for the filled bar
54
- def bar_color
55
- @color || theme.chart_border_color
58
+ # @return [Hash{Symbol => Object}] ARIA attributes of the progress bar
59
+ def bar_aria
60
+ { label: title, valuemin: 0, valuemax: 100, valuenow: percentage, valuetext: "#{formatted_value} / #{formatted_max}" }
56
61
  end
57
62
 
58
63
  # @api private
59
- # @return [IronAdmin::Configuration::Theme] Theme configuration
60
- def theme
61
- IronAdmin.configuration.theme
64
+ # @return [String] CSS color for the filled bar
65
+ def bar_color
66
+ @color || theme.chart_border_color
62
67
  end
63
68
 
64
69
  private
@@ -1,11 +1,10 @@
1
- = link_to href, class: "flex items-center gap-4 px-6 py-4 hover:bg-gray-50 transition-colors group" do
1
+ -# table_row_hover, not item_hover: the muted description needs AA contrast on the hover background.
2
+ = link_to href, class: "flex items-center gap-3 px-5 py-3 transition-colors #{theme.table_row_hover} #{theme.focus_ring}" do
2
3
  - if icon
3
- .shrink-0.p-2.rounded-lg.bg-indigo-50.group-hover:bg-indigo-100.transition-colors
4
- = heroicon icon, variant: :outline, options: { class: "h-5 w-5 text-indigo-600" }
5
- .flex-1.min-w-0
6
- %p.text-sm.font-medium{ class: theme.body_text }
7
- = label
4
+ .flex.h-8.w-8.shrink-0.items-center.justify-center{ class: icon_tile_classes }
5
+ = heroicon icon, variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
6
+ .min-w-0.flex-1
7
+ %p.text-sm.font-medium{ class: theme.body_text }= label
8
8
  - if description
9
- %p.text-sm{ class: theme.muted_text }
10
- = description
11
- = heroicon "chevron-right", variant: :mini, options: { class: "h-5 w-5 #{theme.muted_text} group-hover:text-gray-700" }
9
+ %p.text-sm{ class: theme.muted_text }= description
10
+ = heroicon "chevron-right", variant: :mini, options: { class: "h-4 w-4 shrink-0 #{theme.icon_muted}" }
@@ -1,8 +1,9 @@
1
- %div{ class: "#{theme.card_bg} border #{theme.card_border} #{theme.border_radius} #{theme.card_shadow}" }
2
- .px-6.py-4.border-b{ class: theme.card_border }
3
- %h3.text-lg.font-semibold{ class: theme.body_text }
4
- = title
1
+ %div{ class: card_classes }
2
+ -# py-3.5 goes in the class string: in HAML's dot syntax ".py-3.5" is the classes "py-3" and "5".
3
+ %div{ class: "border-b px-5 py-3.5 #{theme.card_border}" }
4
+ %h2{ class: title_classes }= title
5
5
 
6
- .divide-y{ class: theme.card_border }
6
+ -# divide-y takes its color from table_border: a border color on the list would leave the dividers in currentColor.
7
+ .divide-y{ class: theme.table_border }
7
8
  - links.each do |link|
8
9
  = link
@@ -4,6 +4,8 @@ module IronAdmin
4
4
  module Dashboards
5
5
  # Renders a quick links section on the dashboard.
6
6
  class QuickLinksComponent < ViewComponent::Base
7
+ include Concerns::ThemedCard
8
+
7
9
  renders_many :links, "LinkComponent"
8
10
 
9
11
  # @return [String] Section title
@@ -14,12 +16,6 @@ module IronAdmin
14
16
  @title = title
15
17
  end
16
18
 
17
- # @api private
18
- # @return [IronAdmin::Configuration::Theme] Theme configuration
19
- def theme
20
- IronAdmin.configuration.theme
21
- end
22
-
23
19
  # @api private
24
20
  # @return [Boolean] Whether to render the component
25
21
  def render?
@@ -29,6 +25,8 @@ module IronAdmin
29
25
  # Individual quick link item component.
30
26
  # @api private
31
27
  class LinkComponent < ViewComponent::Base
28
+ include Concerns::ThemedCard
29
+
32
30
  # @return [String] Link label
33
31
  attr_reader :label
34
32
 
@@ -51,12 +49,6 @@ module IronAdmin
51
49
  @icon = icon
52
50
  @description = description
53
51
  end
54
-
55
- # @api private
56
- # @return [IronAdmin::Configuration::Theme] Theme configuration
57
- def theme
58
- IronAdmin.configuration.theme
59
- end
60
52
  end
61
53
  end
62
54
  end
@@ -1,14 +1,19 @@
1
- .bg-white.rounded-lg.shadow
2
- .px-6.py-4.border-b.border-gray-200
3
- %h3.text-lg.font-semibold= "Recent #{label}"
4
- .overflow-x-auto
5
- %table.min-w-full.divide-y.divide-gray-200
6
- %thead.bg-gray-50
1
+ -# overflow-hidden keeps the row hover inside the card's rounded corners. The card is a size
2
+ -# container: its cells fit its own width, wherever a dashboard layout puts it.
3
+ %div{ class: "#{card_classes} overflow-hidden @container" }
4
+ -# Padded like the cells, so the title starts where the first column does.
5
+ .border-b{ class: "#{theme.card_border} #{theme.table_cell_padding}" }
6
+ %h2{ class: title_classes }= "Recent #{label}"
7
+ -# A table wider than the card scrolls sideways; cp-scroll-fade fades the edge it can scroll toward.
8
+ .overflow-x-auto.cp-scroll-fade{ class: theme.table_frame }
9
+ -# divide-y takes its color from table_head_border (else table_border): a border color on the table would leave the dividers in currentColor.
10
+ %table.min-w-full.divide-y{ class: theme.table_head_divider }
11
+ %thead{ class: theme.table_header_bg }
7
12
  %tr
8
13
  - fields.each do |field|
9
- %th.px-6.py-3.text-left.text-xs.font-medium.text-gray-500.uppercase= field.name.to_s.humanize
10
- %tbody.divide-y.divide-gray-200
14
+ %th.text-left.whitespace-nowrap{ scope: "col", class: header_cell_classes }= field.name.to_s.humanize
15
+ %tbody.divide-y{ class: theme.table_border }
11
16
  - ordered_records.each do |record|
12
- %tr.hover:bg-gray-50
17
+ %tr{ class: theme.table_row_hover }
13
18
  - fields.each do |field|
14
- %td.px-6.py-4.text-sm.text-gray-900= display_value(record, field)
19
+ %td.text-sm{ class: cell_classes(field) }= display_value(record, field)