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
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IronAdmin
4
+ module Resources
5
+ # Classes of the page titles, panels and tables of the resource, search and audit
6
+ # pages, built from theme properties.
7
+ module Styles
8
+ # Field types whose table cells line up their digits.
9
+ # @return [Array<Symbol>]
10
+ NUMERIC_TYPES = %i[number currency].freeze
11
+
12
+ # A label and value row of a show page panel. The label sits at the top of the row, beside
13
+ # the first line of a long value.
14
+ # @return [String]
15
+ DETAIL_ROW = "flex flex-col gap-1 px-4 py-3 sm:flex-row sm:items-start"
16
+
17
+ # The box a table scrolls sideways in, inside its {.table_panel}: rounded like the panel, with
18
+ # the engine's fade at the edge it can still scroll toward. The fade masks this box, so the
19
+ # panel's border, on the box around it, keeps its color.
20
+ # @return [String]
21
+ SCROLL_FRAME = "overflow-x-auto rounded-[inherit] cp-scroll-fade"
22
+
23
+ module_function
24
+
25
+ # @param theme [IronAdmin::Configuration::Theme]
26
+ # @return [String] The page's h1
27
+ def page_title(theme)
28
+ "#{theme.page_title} #{theme.heading_font}"
29
+ end
30
+
31
+ # @param theme [IronAdmin::Configuration::Theme]
32
+ # @return [String] A white card holding a table, a list or detail rows
33
+ def panel(theme)
34
+ "#{theme.card_bg} #{theme.border_width} #{theme.card_border} #{theme.border_radius} #{theme.card_shadow}"
35
+ end
36
+
37
+ # @param theme [IronAdmin::Configuration::Theme]
38
+ # @return [String] The title row of a panel
39
+ def panel_header(theme)
40
+ "flex items-center justify-between gap-3 px-4 py-3 border-b #{theme.card_border}"
41
+ end
42
+
43
+ # @param theme [IronAdmin::Configuration::Theme]
44
+ # @return [String] The h2 of a panel
45
+ def panel_title(theme)
46
+ "#{theme.card_title} #{theme.heading_font}"
47
+ end
48
+
49
+ # @param theme [IronAdmin::Configuration::Theme]
50
+ # @return [String] The panel a table scrolls in
51
+ def table_frame(theme)
52
+ "overflow-x-auto #{panel(theme)} #{theme.table_frame}"
53
+ end
54
+
55
+ # @param theme [IronAdmin::Configuration::Theme]
56
+ # @return [String] The panel of a table that scrolls in a {SCROLL_FRAME} inside it
57
+ def table_panel(theme)
58
+ "#{panel(theme)} #{theme.table_frame}"
59
+ end
60
+
61
+ # @param theme [IronAdmin::Configuration::Theme]
62
+ # @return [String] The table, its head divided from its body
63
+ def table(theme)
64
+ "min-w-full divide-y #{theme.table_head_divider}"
65
+ end
66
+
67
+ # @param theme [IronAdmin::Configuration::Theme]
68
+ # @return [String] A table body, list or detail list whose rows are divided
69
+ def divided(theme)
70
+ "divide-y #{theme.table_border}"
71
+ end
72
+
73
+ # @param theme [IronAdmin::Configuration::Theme]
74
+ # @return [String] A link that fills a row of a divided panel; the first and last
75
+ # take the panel's radius, so their hover background keeps its corners
76
+ def list_row(theme)
77
+ "block px-4 py-3 text-sm first:rounded-t-[inherit] last:rounded-b-[inherit] " \
78
+ "#{theme.body_text} #{theme.item_hover} #{theme.focus_ring}"
79
+ end
80
+
81
+ # @param theme [IronAdmin::Configuration::Theme]
82
+ # @return [String] A header cell
83
+ def header_cell(theme)
84
+ "text-left whitespace-nowrap #{theme.table_cell_padding} #{theme.table_header_text} #{theme.label_transform}"
85
+ end
86
+
87
+ # @param theme [IronAdmin::Configuration::Theme]
88
+ # @param field [IronAdmin::Field, nil] The cell's field; numeric ones line up their digits
89
+ # @return [String] A body cell
90
+ def cell(theme, field = nil)
91
+ classes = "whitespace-nowrap text-sm #{theme.table_cell_padding} #{theme.body_text}"
92
+ NUMERIC_TYPES.include?(field&.type) ? "#{classes} tabular-nums" : classes
93
+ end
94
+
95
+ # @param theme [IronAdmin::Configuration::Theme]
96
+ # @return [String] A body cell of secondary information
97
+ def muted_cell(theme)
98
+ "whitespace-nowrap text-sm #{theme.table_cell_padding} #{theme.muted_text}"
99
+ end
100
+
101
+ # @param theme [IronAdmin::Configuration::Theme]
102
+ # @return [String] The header cell of the sticky actions column; its shadow is on a {.sticky_edge}
103
+ def sticky_header_cell(theme)
104
+ "sticky right-0 z-10 #{theme.table_header_bg}"
105
+ end
106
+
107
+ # @param theme [IronAdmin::Configuration::Theme]
108
+ # @return [String] A body cell of the sticky actions column; its shadow is on a {.sticky_edge}
109
+ def sticky_cell(theme)
110
+ "sticky right-0 z-10 #{theme.card_bg} #{theme.table_sticky_row_hover}"
111
+ end
112
+
113
+ # Browsers do not paint the box-shadow of a table cell in a table that collapses its borders,
114
+ # as IronAdmin's tables do (Tailwind's preflight), so a box laid over each sticky cell casts
115
+ # the theme's table_sticky_shadow. It has no background, so only the shadow outside it shows.
116
+ #
117
+ # @param theme [IronAdmin::Configuration::Theme]
118
+ # @return [String] The box inside a sticky actions cell that casts the column's edge shadow
119
+ def sticky_edge(theme)
120
+ "pointer-events-none absolute inset-0 #{theme.table_sticky_shadow}"
121
+ end
122
+
123
+ # @param theme [IronAdmin::Configuration::Theme]
124
+ # @return [String] A secondary button, such as a bulk or member action, like the form buttons
125
+ def secondary_button(theme)
126
+ Form::ControlClasses.button(theme, :secondary)
127
+ end
128
+
129
+ # @param theme [IronAdmin::Configuration::Theme]
130
+ # @return [String] A ghost button, such as the audit log's Clear link, like the form buttons
131
+ def ghost_button(theme)
132
+ Form::ControlClasses.button(theme, :ghost)
133
+ end
134
+ end
135
+ end
136
+ end
@@ -4,5 +4,5 @@
4
4
  .flex-1.text-sm
5
5
  = message || content
6
6
  - if dismissible
7
- %button.shrink-0.opacity-70.hover:opacity-100.transition-opacity{ type: "button", "aria-label": dismiss_label, data: { action: "cp-alert#dismiss" } }
8
- = heroicon "x-mark", variant: :mini, options: { class: "h-5 w-5" }
7
+ %button{ type: "button", class: dismiss_classes, "aria-label": dismiss_label, data: { action: "cp-alert#dismiss" } }
8
+ = heroicon "x-mark", variant: :mini, options: { class: "h-4 w-4" }
@@ -2,7 +2,8 @@
2
2
 
3
3
  module IronAdmin
4
4
  module Ui
5
- # Renders a styled alert/notification message.
5
+ # Renders a styled alert/notification message, colored by the theme's
6
+ # +alert_palette+ entry for its type.
6
7
  #
7
8
  # @example Success alert
8
9
  # render IronAdmin::Ui::AlertComponent.new(
@@ -30,33 +31,13 @@ module IronAdmin
30
31
  # @return [Boolean] Whether alert can be dismissed
31
32
  attr_reader :dismissible
32
33
 
33
- # Type configurations with colors and icons.
34
+ # Icon of each type. The colors come from the theme's +alert_palette+.
34
35
  # @return [Hash{Symbol => Hash}]
35
36
  TYPES = {
36
- success: {
37
- bg: "bg-green-50",
38
- border: "border-green-200",
39
- text: "text-green-800",
40
- icon: "check-circle",
41
- },
42
- error: {
43
- bg: "bg-red-50",
44
- border: "border-red-200",
45
- text: "text-red-800",
46
- icon: "x-circle",
47
- },
48
- warning: {
49
- bg: "bg-yellow-50",
50
- border: "border-yellow-200",
51
- text: "text-yellow-800",
52
- icon: "exclamation-triangle",
53
- },
54
- info: {
55
- bg: "bg-blue-50",
56
- border: "border-blue-200",
57
- text: "text-blue-800",
58
- icon: "information-circle",
59
- },
37
+ success: { icon: "check-circle" },
38
+ error: { icon: "x-circle" },
39
+ warning: { icon: "exclamation-triangle" },
40
+ info: { icon: "information-circle" },
60
41
  }.freeze
61
42
 
62
43
  # Types announced with +role="alert"+; the others use +role="status"+.
@@ -77,13 +58,22 @@ module IronAdmin
77
58
  # @api private
78
59
  # @return [Hash] Configuration for the current alert type
79
60
  def type_config
80
- TYPES[@type] || TYPES[:info]
61
+ TYPES[palette_type]
81
62
  end
82
63
 
83
64
  # @api private
84
- # @return [String] CSS classes for alert container
65
+ # @return [String] CSS classes for alert container: the theme's palette
66
+ # entry for the type (else its +:info+ entry), border width, radius and alert shadow
85
67
  def alert_classes
86
- "#{type_config[:bg]} #{type_config[:border]} #{type_config[:text]} border #{theme.border_radius} p-4"
68
+ palette = theme.alert_palette.to_h
69
+ colors = palette[palette_type] || palette[:info]
70
+ "#{colors} #{theme.border_width} #{theme.border_radius} #{theme.alert_shadow} px-4 py-3"
71
+ end
72
+
73
+ # @api private
74
+ # @return [String] CSS classes for the dismiss button
75
+ def dismiss_classes
76
+ "-m-1 shrink-0 p-1 opacity-70 transition-opacity hover:opacity-100 #{theme.control_radius} #{theme.focus_ring}"
87
77
  end
88
78
 
89
79
  # @api private
@@ -100,9 +90,15 @@ module IronAdmin
100
90
  end
101
91
 
102
92
  # @api private
103
- # @return [IronAdmin::Configuration::Theme] Theme configuration
93
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
104
94
  def theme
105
- IronAdmin.configuration.theme
95
+ IronAdmin.current_theme
96
+ end
97
+
98
+ # @api private
99
+ # @return [Symbol] The alert type, or +:info+ for an unknown one
100
+ def palette_type
101
+ TYPES.key?(@type) ? @type : :info
106
102
  end
107
103
 
108
104
  # @api private
@@ -2,7 +2,7 @@
2
2
 
3
3
  module IronAdmin
4
4
  module Ui
5
- # Displays a colored badge/tag for status indicators and labels.
5
+ # A status badge in the theme's +badge_palette+ colors, with a +badge_dot_palette+ dot.
6
6
  #
7
7
  # @example Basic usage
8
8
  # render IronAdmin::Ui::BadgeComponent.new(text: "Active", color: :green)
@@ -19,27 +19,17 @@ module IronAdmin
19
19
  # @return [Symbol] The size (:sm, :md, :lg)
20
20
  attr_reader :size
21
21
 
22
- # Available color themes mapped to Tailwind classes.
22
+ # Badge classes of the built-in Neutral theme by color name, kept for code that
23
+ # reads them. Badges use the current theme's +badge_palette+.
23
24
  # @return [Hash{Symbol => String}]
24
- COLORS = {
25
- green: "bg-green-100 text-green-800",
26
- red: "bg-red-100 text-red-800",
27
- yellow: "bg-yellow-100 text-yellow-800",
28
- blue: "bg-blue-100 text-blue-800",
29
- indigo: "bg-indigo-100 text-indigo-800",
30
- purple: "bg-purple-100 text-purple-800",
31
- pink: "bg-pink-100 text-pink-800",
32
- orange: "bg-orange-100 text-orange-800",
33
- teal: "bg-teal-100 text-teal-800",
34
- gray: "bg-gray-100 text-gray-800",
35
- }.freeze
25
+ COLORS = IronAdmin::Configuration::Theme.new.badge_palette.freeze
36
26
 
37
27
  # Available sizes mapped to Tailwind classes.
38
28
  # @return [Hash{Symbol => String}]
39
29
  SIZES = {
40
- sm: "px-2 py-0.5 text-xs",
41
- md: "px-2.5 py-0.5 text-sm",
42
- lg: "px-3 py-1 text-sm",
30
+ sm: "px-1.5 py-0.5 text-xs",
31
+ md: "px-2 py-0.5 text-xs",
32
+ lg: "px-2.5 py-1 text-sm",
43
33
  }.freeze
44
34
 
45
35
  # @param text [String] The badge text
@@ -52,9 +42,22 @@ module IronAdmin
52
42
  end
53
43
 
54
44
  # @api private
55
- # @return [String] CSS color classes for badge
45
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
46
+ def theme
47
+ IronAdmin.current_theme
48
+ end
49
+
50
+ # @api private
51
+ # @return [String] The +config.badge_colors+ classes of the color, else the theme's
52
+ # palette classes of the color (gray for an unknown color)
56
53
  def color_classes
57
- IronAdmin.configuration.badge_colors[@color] || COLORS[@color] || COLORS[:gray]
54
+ configured_classes || theme.badge_palette.fetch(palette_color, "")
55
+ end
56
+
57
+ # @api private
58
+ # @return [String, nil] Dot classes; nil without a theme dot or with +config.badge_colors+ classes
59
+ def dot_classes
60
+ theme.badge_dot_palette[palette_color] unless configured_classes
58
61
  end
59
62
 
60
63
  # @api private
@@ -66,7 +69,24 @@ module IronAdmin
66
69
  # Renders the badge span.
67
70
  # @return [String] HTML content
68
71
  def call
69
- tag.span(text, class: "inline-flex items-center font-medium rounded-full #{color_classes} #{size_classes}")
72
+ tag.span(class: "inline-flex items-center gap-1.5 #{size_classes} #{theme.badge_shape} #{color_classes}") do
73
+ safe_join([dot, text].compact)
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def configured_classes
80
+ IronAdmin.configuration.badge_colors[@color]
81
+ end
82
+
83
+ def palette_color
84
+ theme.badge_palette.key?(@color) ? @color : :gray
85
+ end
86
+
87
+ def dot
88
+ classes = dot_classes
89
+ tag.span(class: "h-1.5 w-1.5 shrink-0 rounded-full #{classes}", "aria-hidden": "true") if classes
70
90
  end
71
91
  end
72
92
  end
@@ -51,20 +51,29 @@ module IronAdmin
51
51
  # Variant style mappings (uses theme configuration).
52
52
  # @return [Hash{Symbol => Proc}]
53
53
  VARIANTS = {
54
- primary: -> { IronAdmin.configuration.theme.btn_primary },
55
- secondary: -> { IronAdmin.configuration.theme.btn_secondary },
56
- danger: -> { IronAdmin.configuration.theme.btn_danger },
57
- ghost: -> { IronAdmin.configuration.theme.btn_ghost },
54
+ primary: -> { IronAdmin.current_theme.btn_primary },
55
+ secondary: -> { IronAdmin.current_theme.btn_secondary },
56
+ danger: -> { IronAdmin.current_theme.btn_danger },
57
+ ghost: -> { IronAdmin.current_theme.btn_ghost },
58
58
  }.freeze
59
59
 
60
- # Size class mappings.
60
+ # Size class mappings (md is 36px high).
61
61
  # @return [Hash{Symbol => String}]
62
62
  SIZES = {
63
- sm: "px-3 py-1.5 text-sm",
64
- md: "px-4 py-2 text-sm",
65
- lg: "px-5 py-2.5 text-base",
63
+ sm: "h-8 px-3 text-sm",
64
+ md: "h-9 px-3.5 text-sm",
65
+ lg: "h-10 px-4 text-base",
66
66
  }.freeze
67
67
 
68
+ # Variants whose theme classes carry their own focus outline (+btn_primary+);
69
+ # the others get the theme's +focus_ring+.
70
+ # @return [Array<Symbol>]
71
+ OWN_FOCUS_VARIANTS = %i[primary].freeze
72
+
73
+ # Variants drawn without the theme's +control_shadow+, like the ghost form buttons.
74
+ # @return [Array<Symbol>]
75
+ FLAT_VARIANTS = %i[ghost].freeze
76
+
68
77
  # @param text [String, nil] Button text
69
78
  # @param variant [Symbol] Style variant (default: :primary)
70
79
  # @param size [Symbol] Size variant (default: :md)
@@ -103,14 +112,26 @@ module IronAdmin
103
112
  # @api private
104
113
  # @return [String] Base CSS classes for all button variants
105
114
  def base_classes
106
- "inline-flex items-center justify-center gap-2 font-medium rounded-lg transition-colors duration-150 " \
107
- "focus:outline-none focus:ring-2 focus:ring-offset-1 disabled:opacity-50 disabled:cursor-not-allowed"
115
+ "inline-flex shrink-0 items-center justify-center gap-2 font-medium whitespace-nowrap transition-colors " \
116
+ "duration-150 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed #{IronAdmin.current_theme.control_radius}"
117
+ end
118
+
119
+ # @api private
120
+ # @return [String] The theme's +focus_ring+, unless the variant's classes carry their own
121
+ def focus_classes
122
+ OWN_FOCUS_VARIANTS.include?(known_variant) ? "" : IronAdmin.current_theme.focus_ring
123
+ end
124
+
125
+ # @api private
126
+ # @return [String] The theme's +control_shadow+, except for flat (ghost) buttons
127
+ def shadow_classes
128
+ FLAT_VARIANTS.include?(known_variant) ? "" : IronAdmin.current_theme.control_shadow
108
129
  end
109
130
 
110
131
  # @api private
111
132
  # @return [String] Combined CSS classes for button
112
133
  def button_classes
113
- "#{base_classes} #{variant_classes} #{size_classes}"
134
+ [base_classes, variant_classes, focus_classes, shadow_classes, size_classes].compact_blank.join(" ")
114
135
  end
115
136
 
116
137
  # @api private
@@ -138,6 +159,11 @@ module IronAdmin
138
159
 
139
160
  private
140
161
 
162
+ # An unknown variant renders as primary (see #variant_classes).
163
+ def known_variant
164
+ VARIANTS.key?(@variant) ? @variant : :primary
165
+ end
166
+
141
167
  def button_content
142
168
  safe_join([icon_element, text_element].compact)
143
169
  end
@@ -34,15 +34,15 @@ module IronAdmin
34
34
  end
35
35
 
36
36
  # @api private
37
- # @return [IronAdmin::Configuration::Theme] Theme configuration
37
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
38
38
  def theme
39
- IronAdmin.configuration.theme
39
+ IronAdmin.current_theme
40
40
  end
41
41
 
42
42
  # @api private
43
43
  # @return [String] CSS classes for card container
44
44
  def card_classes
45
- classes = ["overflow-hidden", theme.border_radius, theme.card_bg, "border", theme.card_border]
45
+ classes = ["overflow-hidden", theme.border_radius, theme.card_bg, theme.border_width, theme.card_border]
46
46
  classes << theme.card_shadow if shadow
47
47
  classes.join(" ")
48
48
  end
@@ -3,6 +3,6 @@
3
3
  = trigger
4
4
 
5
5
  %div{ class: dropdown_classes, data: { dropdown_target: "menu" }, hidden: true }
6
- .py-1{ role: "menu" }
6
+ %div{ role: "menu" }
7
7
  - items.each do |item|
8
8
  = item
@@ -20,26 +20,38 @@ module IronAdmin
20
20
  # @return [Integer] Dropdown width in Tailwind units
21
21
  attr_reader :width
22
22
 
23
+ # Width class of each supported +width+. Tailwind generates only the class
24
+ # names written in full in the engine's sources, so others fall back to w-48.
25
+ # @return [Hash{Integer => String}]
26
+ WIDTHS = {
27
+ 32 => "w-32", 40 => "w-40", 44 => "w-44", 48 => "w-48", 52 => "w-52", 56 => "w-56",
28
+ 60 => "w-60", 64 => "w-64", 72 => "w-72", 80 => "w-80", 96 => "w-96",
29
+ }.freeze
30
+
31
+ # Position and transform origin of each alignment.
32
+ # @return [Hash{Symbol => String}]
33
+ ALIGNMENTS = { right: "right-0 origin-top-right", left: "left-0 origin-top-left" }.freeze
34
+
23
35
  # @param align [Symbol] Alignment (default: :right)
24
- # @param width [Integer] Width (default: 48)
36
+ # @param width [Integer] Width in Tailwind units, one of {WIDTHS} (default: 48)
25
37
  def initialize(align: :right, width: 48)
26
38
  @align = align
27
39
  @width = width
28
40
  end
29
41
 
30
42
  # @api private
31
- # @return [IronAdmin::Configuration::Theme] Theme configuration
43
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
32
44
  def theme
33
- IronAdmin.configuration.theme
45
+ IronAdmin.current_theme
34
46
  end
35
47
 
36
48
  # @api private
37
- # @return [String] CSS classes for dropdown panel
49
+ # @return [String] CSS classes for dropdown panel: a theme surface lifted
50
+ # by the theme's +popover_shadow+
38
51
  def dropdown_classes
39
- align_class = align == :right ? "right-0" : "left-0"
40
- width_class = "w-#{width}"
41
- "absolute #{align_class} mt-2 #{width_class} origin-top-#{align} #{theme.border_radius} " \
42
- "#{theme.card_bg} border #{theme.card_border} #{theme.card_shadow}-lg z-50"
52
+ position = ALIGNMENTS[align.to_sym] || ALIGNMENTS[:right]
53
+ "absolute #{position} z-50 mt-1.5 #{WIDTHS.fetch(width, "w-48")} p-1 #{theme.popover_background} " \
54
+ "#{theme.border_width} #{theme.card_border} #{theme.border_radius} #{theme.popover_shadow}"
43
55
  end
44
56
 
45
57
  # Individual dropdown menu item.
@@ -69,13 +81,21 @@ module IronAdmin
69
81
  end
70
82
 
71
83
  # @api private
72
- # @return [String] CSS classes for menu item
84
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
85
+ def theme
86
+ IronAdmin.current_theme
87
+ end
88
+
89
+ # @api private
90
+ # @return [String] CSS classes for menu item: the theme's +danger_item+
91
+ # when destructive, else its body text and +item_hover+
73
92
  def item_classes
74
- base = "flex items-center gap-2 w-full px-4 py-2 text-sm text-left transition-colors duration-150"
93
+ base = "flex w-full items-center gap-2 px-2 py-1.5 text-left text-sm transition-colors duration-150 " \
94
+ "#{theme.control_radius} #{theme.focus_ring}"
75
95
  if destructive
76
- "#{base} text-red-600 hover:bg-red-50"
96
+ "#{base} #{theme.danger_item}"
77
97
  else
78
- "#{base} text-gray-700 hover:bg-gray-50"
98
+ "#{base} #{theme.body_text} #{theme.item_hover}"
79
99
  end
80
100
  end
81
101
 
@@ -102,7 +122,8 @@ module IronAdmin
102
122
  def icon_element
103
123
  return unless icon
104
124
 
105
- helpers.heroicon(icon, variant: :outline, options: { class: "h-4 w-4" })
125
+ classes = destructive ? "h-4 w-4 shrink-0" : "h-4 w-4 shrink-0 #{theme.icon_muted}"
126
+ helpers.heroicon(icon, variant: :outline, options: { class: classes })
106
127
  end
107
128
  end
108
129
  end
@@ -1,12 +1,11 @@
1
1
  .text-center.py-12
2
- .mx-auto.flex.items-center.justify-center.h-12.w-12.rounded-full.bg-gray-100
3
- = heroicon icon, variant: :outline, options: { class: "h-6 w-6 #{theme.muted_text}" }
4
- %h3.mt-4.text-sm.font-semibold{ class: theme.body_text }
2
+ .mx-auto.flex.h-10.w-10.items-center.justify-center{ class: "#{theme.surface_muted} #{theme.border_width} #{theme.card_border} #{theme.border_radius}" }
3
+ = heroicon icon, variant: :outline, options: { class: "h-5 w-5 #{theme.icon_muted}" }
4
+ %h3.mt-4{ class: "#{theme.card_title} #{theme.heading_font}" }
5
5
  = title
6
6
  - if description
7
7
  %p.mt-1.text-sm{ class: theme.muted_text }
8
8
  = description
9
9
  - if has_action?
10
10
  .mt-6
11
- = link_to action_href, class: "#{theme.btn_primary} px-4 py-2 text-sm font-medium rounded-lg" do
12
- = action_text
11
+ = render IronAdmin::Ui::ButtonComponent.new(text: action_text, href: action_href)
@@ -40,9 +40,9 @@ module IronAdmin
40
40
  end
41
41
 
42
42
  # @api private
43
- # @return [IronAdmin::Configuration::Theme] Theme configuration
43
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
44
44
  def theme
45
- IronAdmin.configuration.theme
45
+ IronAdmin.current_theme
46
46
  end
47
47
 
48
48
  # @api private
@@ -1,19 +1,19 @@
1
1
  %div{ class: "fixed inset-0 z-50 overflow-y-auto", data: dismissible ? { controller: "cp-modal", action: "keydown.esc@window->cp-modal#close" } : {}, role: "dialog", aria: { modal: true } }
2
2
  .flex.min-h-full.items-center.justify-center.p-4
3
3
  -# Backdrop
4
- .fixed.inset-0.transition-opacity{ class: "bg-gray-500/75", data: dismissible ? { action: "click->cp-modal#close" } : {} }
4
+ .fixed.inset-0.transition-opacity{ class: theme.overlay_bg, data: dismissible ? { action: "click->cp-modal#close" } : {} }
5
5
 
6
6
  -# Modal panel
7
7
  %div{ class: modal_classes }
8
8
  -# Header
9
9
  - if title? || dismissible
10
- .flex.items-center.justify-between.px-6.py-4.border-b{ class: theme.card_border }
10
+ .flex.items-center.justify-between.gap-4.px-6.py-4.border-b{ class: theme.card_border }
11
11
  - if title?
12
- %h3.text-lg.font-semibold{ class: theme.body_text }
12
+ %h3{ class: "#{theme.card_title} #{theme.heading_font}" }
13
13
  = title
14
14
  - if dismissible
15
- %button.text-gray-400.hover:text-gray-500.transition-colors{ type: "button", "aria-label": close_label, data: { action: "cp-modal#close" } }
16
- = heroicon "x-mark", variant: :outline, options: { class: "h-6 w-6" }
15
+ %button.-mr-2.ml-auto.inline-flex.h-8.w-8.shrink-0.items-center.justify-center{ type: "button", class: "#{theme.control_radius} #{theme.btn_ghost} #{theme.focus_ring}", "aria-label": close_label, data: { action: "cp-modal#close" } }
16
+ = heroicon "x-mark", variant: :outline, options: { class: "h-5 w-5" }
17
17
 
18
18
  -# Content
19
19
  .px-6.py-4
@@ -38,9 +38,9 @@ module IronAdmin
38
38
  end
39
39
 
40
40
  # @api private
41
- # @return [IronAdmin::Configuration::Theme] Theme configuration
41
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
42
42
  def theme
43
- IronAdmin.configuration.theme
43
+ IronAdmin.current_theme
44
44
  end
45
45
 
46
46
  # @api private
@@ -50,9 +50,11 @@ module IronAdmin
50
50
  end
51
51
 
52
52
  # @api private
53
- # @return [String] CSS classes for modal container
53
+ # @return [String] CSS classes for modal container: a theme surface lifted
54
+ # by the theme's +popover_shadow+
54
55
  def modal_classes
55
- "relative #{theme.card_bg} #{theme.border_radius} #{theme.card_shadow}-xl w-full #{size_classes}"
56
+ "relative w-full #{size_classes} #{theme.popover_background} #{theme.border_width} #{theme.card_border} " \
57
+ "#{theme.border_radius} #{theme.popover_shadow}"
56
58
  end
57
59
 
58
60
  # @api private
@@ -1,20 +1,20 @@
1
- %nav.flex.items-center.justify-between{ aria: { label: "Pagination" } }
1
+ %nav.flex.flex-wrap.items-center.justify-between.gap-3{ aria: { label: "Pagination" } }
2
2
  .text-sm{ class: theme.muted_text }
3
3
  Showing
4
- %span.font-medium= pagy_obj.from
4
+ %span.font-medium.tabular-nums{ class: theme.body_text }= pagy_obj.from
5
5
  to
6
- %span.font-medium= pagy_obj.to
6
+ %span.font-medium.tabular-nums{ class: theme.body_text }= pagy_obj.to
7
7
  of
8
- %span.font-medium= pagy_obj.count
8
+ %span.font-medium.tabular-nums{ class: theme.body_text }= pagy_obj.count
9
9
  results
10
10
 
11
- .isolate.inline-flex.-space-x-px.rounded-md.shadow-sm
11
+ .flex.items-center.gap-1
12
12
  - if pagy_obj.previous
13
- = link_to page_url(pagy_obj.previous), class: "#{nav_link_classes} rounded-l-md", "aria-label": "Previous" do
14
- = heroicon "chevron-left", variant: :mini, options: { class: "h-5 w-5" }
13
+ = link_to page_url(pagy_obj.previous), class: nav_link_classes, "aria-label": "Previous" do
14
+ = heroicon "chevron-left", variant: :mini, options: { class: "h-4 w-4" }
15
15
  - else
16
- %span{ class: "#{nav_link_classes(disabled: true)} rounded-l-md" }
17
- = heroicon "chevron-left", variant: :mini, options: { class: "h-5 w-5" }
16
+ %span{ class: nav_link_classes(disabled: true) }
17
+ = heroicon "chevron-left", variant: :mini, options: { class: "h-4 w-4" }
18
18
 
19
19
  - series.each do |item|
20
20
  - case item
@@ -23,11 +23,11 @@
23
23
  - when String
24
24
  %span{ class: page_link_classes(active: true), "aria-current": "page" }= item
25
25
  - when :gap
26
- %span{ class: "#{page_link_classes} cursor-default" } ...
26
+ %span{ class: gap_classes } ...
27
27
 
28
28
  - if pagy_obj.next
29
- = link_to page_url(pagy_obj.next), class: "#{nav_link_classes} rounded-r-md", "aria-label": "Next" do
30
- = heroicon "chevron-right", variant: :mini, options: { class: "h-5 w-5" }
29
+ = link_to page_url(pagy_obj.next), class: nav_link_classes, "aria-label": "Next" do
30
+ = heroicon "chevron-right", variant: :mini, options: { class: "h-4 w-4" }
31
31
  - else
32
- %span{ class: "#{nav_link_classes(disabled: true)} rounded-r-md" }
33
- = heroicon "chevron-right", variant: :mini, options: { class: "h-5 w-5" }
32
+ %span{ class: nav_link_classes(disabled: true) }
33
+ = heroicon "chevron-right", variant: :mini, options: { class: "h-4 w-4" }