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
@@ -1,62 +1,24 @@
1
1
  = turbo_frame_tag "action-form-modal" do
2
- .p-8.max-w-lg.mx-auto{ class: t.font_family }
3
- %h1.text-xl.mb-6{ class: cp_heading }= @action[:name].to_s.humanize
2
+ .px-4.sm:px-6.lg:px-8.py-6.max-w-lg.mx-auto
3
+ %h1.mb-6{ class: "#{t.page_title} #{t.heading_font}" }= @action[:name].to_s.humanize
4
4
 
5
- = form_tag @form_url, method: :post, class: "space-y-4", data: { turbo_frame: "_top" } do
6
- - @form_fields.each do |field|
7
- .space-y-1
8
- %label.block.text-sm.font-medium{ class: cp_label_text, for: "action_form_#{field.name}" }
9
- = field.label
10
- - if field.required
11
- %span.text-red-500 *
5
+ .p-6{ class: cp_card }
6
+ = form_tag @form_url, method: :post, class: "space-y-5", data: { turbo_frame: "_top" } do
7
+ %p.text-sm{ class: cp_muted_text }= I18n.t("iron_admin.resources.bulk_action_form.selected", count: @bulk_ids.size)
8
+ -# The selection and the index state it was made on go to the action, which returns to that index.
9
+ - @bulk_ids.each do |id|
10
+ = hidden_field_tag "ids[]", id, id: nil
11
+ - iron_admin_hidden_params(iron_admin_index_state).each do |name, value|
12
+ = hidden_field_tag name, value, id: nil
12
13
 
13
- - case field.type
14
- - when :text
15
- = text_field_tag "action_form[#{field.name}]", field.default,
16
- id: "action_form_#{field.name}",
17
- class: cp_filter_input_class,
18
- placeholder: field.placeholder,
19
- required: field.required
20
- - when :textarea
21
- = text_area_tag "action_form[#{field.name}]", field.default,
22
- id: "action_form_#{field.name}",
23
- class: "#{cp_filter_input_class} h-24",
24
- placeholder: field.placeholder,
25
- required: field.required
26
- - when :number
27
- = number_field_tag "action_form[#{field.name}]", field.default,
28
- id: "action_form_#{field.name}",
29
- class: cp_filter_input_class,
30
- placeholder: field.placeholder,
31
- step: "any",
32
- required: field.required
33
- - when :boolean
34
- .flex.items-center.gap-2
35
- = check_box_tag "action_form[#{field.name}]", "1", field.default,
36
- id: "action_form_#{field.name}",
37
- class: "rounded border-gray-300"
38
- %span.text-sm{ class: cp_body_text }= field.label
39
- - when :date
40
- = date_field_tag "action_form[#{field.name}]", field.default,
41
- id: "action_form_#{field.name}",
42
- class: cp_filter_input_class,
43
- required: field.required
44
- - when :datetime
45
- = datetime_field_tag "action_form[#{field.name}]", field.default,
46
- id: "action_form_#{field.name}",
47
- class: cp_filter_input_class,
48
- required: field.required
49
- - when :select
50
- %select{ name: "action_form[#{field.name}]", id: "action_form_#{field.name}",
51
- class: cp_filter_input_class, required: field.required }
52
- %option{ value: "" }= field.placeholder || "Select..."
53
- - (field.options || []).each do |opt|
54
- %option{ value: opt, selected: field.default == opt }= opt.to_s.humanize
14
+ - @form_fields.each do |field|
15
+ = render "iron_admin/form/action_field", field: field, scope: "action_form",
16
+ value: @form_values[field.name], errors: @form_errors[field.name]
55
17
 
56
- - if params[:ids].present?
57
- - Array(params[:ids]).each do |id|
58
- = hidden_field_tag "ids[]", id
59
-
60
- .flex.items-center.gap-3.pt-3.border-t.border-gray-100
61
- %button{ type: "submit", class: cp_btn_primary }= I18n.t("iron_admin.resources.action_form.submit", default: "Execute")
62
- = link_to I18n.t("iron_admin.form.cancel_button"), "javascript:history.back()", class: "text-sm #{cp_link_muted}"
18
+ -# The action's confirmation comes here, once the form is filled in.
19
+ - confirm = @action[:confirm_message].presence || I18n.t("iron_admin.resources.action.confirm")
20
+ .flex.items-center.gap-3.pt-5.border-t{ class: t.card_border }
21
+ %button{ type: "submit", class: cp_btn_primary, data: @action[:confirm] ? { turbo_confirm: confirm } : {} }= I18n.t("iron_admin.resources.action_form.submit", default: "Execute")
22
+ -# A whole-page visit: the index has no action-form-modal frame to load into.
23
+ = link_to I18n.t("iron_admin.form.cancel_button"), resources_path(@resource_class.resource_name, **iron_admin_index_state.symbolize_keys),
24
+ class: cp_btn_secondary, data: { turbo_frame: "_top" }
@@ -1,9 +1,9 @@
1
1
  - form_url = resource_path(@resource_class.resource_name, @record)
2
2
 
3
- .p-4.sm:p-6.lg:p-8.max-w-7xl.mx-auto{ class: t.font_family }
4
- %h1.text-2xl.mb-6{ class: cp_heading }
3
+ .px-4.sm:px-6.lg:px-8.py-6.max-w-7xl.mx-auto
4
+ %h1.mb-6{ class: "#{t.page_title} #{t.heading_font}" }
5
5
  = I18n.t("iron_admin.resources.edit.title", model: @resource_class.model.model_name.human)
6
- %span.text-gray-400= "##{@record.id}"
6
+ %span{ class: cp_muted_text }= "##{@record.id}"
7
7
 
8
8
  .p-6{ class: cp_card }
9
9
  - if (form_component = iron_admin_form_component(@resource_class, record: @record, fields: @fields, url: form_url))
@@ -1,8 +1,10 @@
1
1
  - filters = iron_admin_visible_filters
2
+ - styles = IronAdmin::Resources::Styles
3
+ - controls = IronAdmin::Filters::ControlStyles
2
4
 
3
- .p-4.sm:p-6.lg:p-8.max-w-7xl.mx-auto{ class: t.font_family }
5
+ .px-4.sm:px-6.lg:px-8.py-6.max-w-7xl.mx-auto
4
6
  .flex.items-center.justify-between.gap-3.flex-wrap.mb-6
5
- %h1.text-2xl{ class: cp_heading }= @resource_class.label
7
+ %h1{ class: styles.page_title(t) }= @resource_class.label
6
8
  .flex.items-center.gap-2
7
9
  - if @resource_class.import_enabled? && @resource_class.crud_allowed?(:create, iron_admin_current_user)
8
10
  = link_to resource_import_path(@resource_class.resource_name),
@@ -17,43 +19,44 @@
17
19
  - if @resource_class.all_scopes.any? || @resource_class.searchable_columns.any?
18
20
  .flex.items-center.justify-between.gap-3.flex-wrap.mb-4
19
21
  - if @resource_class.all_scopes.any?
20
- .flex.gap-1.border-b.overflow-x-auto{ class: t.card_border }
22
+ -# A tab keeps the search, filters and sort, and starts back at the first page.
23
+ - scope_tab_state = iron_admin_index_state.except("scope", "page").symbolize_keys
24
+ .flex.gap-1.border-b.overflow-x-auto.cp-scroll-fade{ class: t.card_border }
21
25
  - @resource_class.all_scopes.each do |scope|
22
26
  - active = @current_scope == scope[:name].to_s
23
- = link_to scope[:name].to_s.humanize,
24
- resources_path(@resource_class.resource_name, scope: scope[:name], q: params[:q]),
25
- class: "px-4 py-2 text-sm font-medium border-b-2 -mb-px whitespace-nowrap #{active ? cp_scope_active : cp_scope_inactive}"
27
+ = link_to IronAdmin::ScopeCounts.label(scope, @scope_counts),
28
+ resources_path(@resource_class.resource_name, **scope_tab_state, scope: scope[:name]),
29
+ class: "px-3 py-2 text-sm font-medium border-b-2 -mb-px whitespace-nowrap #{active ? cp_scope_active : cp_scope_inactive}"
26
30
 
27
31
  - if @resource_class.searchable_columns.any? && (search_component = iron_admin_search_component(@resource_class, scope: @current_scope))
28
32
  = render search_component
29
33
  - elsif @resource_class.searchable_columns.any?
30
- = form_tag resources_path(@resource_class.resource_name), method: :get, class: "flex ml-auto" do
34
+ = form_tag resources_path(@resource_class.resource_name), method: :get, class: "flex w-full sm:w-auto sm:ml-auto" do
31
35
  - iron_admin_search_hidden_params(@current_scope).each do |name, value|
32
36
  = hidden_field_tag name, value, id: nil
33
- .relative
34
- .pointer-events-none.absolute.inset-y-0.left-0.flex.items-center{ class: "pl-3.5" }
35
- = heroicon "magnifying-glass", variant: :mini, options: { class: "h-4 w-4 #{cp_muted_text}" }
37
+ .relative.w-full.sm:w-64
38
+ .pointer-events-none.absolute.inset-y-0.left-0.flex.items-center.pl-3
39
+ = heroicon "magnifying-glass", variant: :mini, options: { class: "h-4 w-4 #{t.icon_muted}" }
36
40
  = text_field_tag :q, params[:q],
37
41
  placeholder: I18n.t("iron_admin.resources.index.search_placeholder"),
38
42
  "aria-label": I18n.t("iron_admin.resources.index.search_label", resource: @resource_class.label),
39
- class: cp_search_class
43
+ class: controls.search_input(t)
40
44
 
41
45
  - if filters.any? && (filter_bar_component = iron_admin_filter_bar_component(@resource_class, filters: filters, scope: @current_scope))
42
46
  = render filter_bar_component
43
47
  - elsif filters.any?
44
48
  - has_active_filters = filters.any? { |f| iron_admin_active_filter?(f) }
45
- - select_chevron_style = "background-image: url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e\"); background-position: right 0.5rem center; background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem;"
46
49
  .flex.justify-end.mb-4
47
50
  %details.relative.group{ open: has_active_filters || nil }
48
- %summary.inline-flex.items-center.gap-2.px-4.cursor-pointer.select-none.text-sm.font-medium.rounded-lg.border.shadow-sm.transition.duration-150{ class: "#{cp_label_text} #{t.card_border} #{t.card_bg} py-2.5 hover:bg-gray-50 [&::-webkit-details-marker]:hidden", style: "list-style: none;" }
49
- = heroicon "funnel", variant: :mini, options: { class: "h-4 w-4 #{cp_muted_text}" }
51
+ %summary{ class: controls.trigger(t), style: "list-style: none;" }
52
+ = heroicon "funnel", variant: :mini, options: { class: "h-4 w-4 #{t.icon_muted}" }
50
53
  %span= I18n.t("iron_admin.resources.index.filters_label")
51
54
  - if has_active_filters
52
55
  - active_count = filters.count { |f| iron_admin_active_filter?(f) }
53
- %span{ class: cp_badge_count }
56
+ %span{ class: controls.count(t) }
54
57
  = active_count
55
- = heroicon "chevron-down", variant: :mini, options: { class: "h-4 w-4 text-gray-400 transition-transform group-open:rotate-180" }
56
- .absolute.right-0.top-full.mt-2.w-72.border.z-20{ class: "#{t.border_radius} #{t.card_border} #{t.card_bg} #{t.card_shadow}-lg" }
58
+ = heroicon "chevron-down", variant: :mini, options: { class: "h-4 w-4 #{t.icon_muted} transition-transform group-open:rotate-180" }
59
+ %div{ class: controls.panel(t) }
57
60
  = form_tag resources_path(@resource_class.resource_name), method: :get, class: "p-4" do
58
61
  = hidden_field_tag :scope, @current_scope, id: nil
59
62
  = hidden_field_tag :q, params[:q], id: nil
@@ -66,39 +69,39 @@
66
69
  -# The label names the select, or the value input of an operator filter.
67
70
  - label_for = { date_range: "#{filter_id}_from", string: "#{filter_id}_value", number: "#{filter_id}_value" }.fetch(filter[:type], filter_id)
68
71
  .space-y-1
69
- %label.block.text-xs.font-semibold.uppercase.tracking-wider{ for: label_for, class: cp_muted_text }
72
+ %label{ for: label_for, class: controls.label(t) }
70
73
  = filter_label
71
74
  - case filter[:type]
72
- - when :select
73
- %select.block.w-full.appearance-none.border.px-3.py-2.text-sm.shadow-sm.outline-none.transition.duration-150.ease-in-out{ name: "filters[#{filter[:name]}]", id: filter_id, class: "#{t.border_radius} #{t.input_border} #{t.card_bg} #{cp_body_text} #{cp_focus}", style: select_chevron_style }
74
- %option{ value: "" }= I18n.t("iron_admin.resources.index.all_option")
75
- - filter_options_for(@resource_class, filter).each do |label, value|
76
- %option{ value: value, selected: iron_admin_filter_param(filter[:name]) == value.to_s }= label
77
- - when :boolean
78
- %select.block.w-full.appearance-none.border.px-3.py-2.text-sm.shadow-sm.outline-none.transition.duration-150.ease-in-out{ name: "filters[#{filter[:name]}]", id: filter_id, class: "#{t.border_radius} #{t.input_border} #{t.card_bg} #{cp_body_text} #{cp_focus}", style: select_chevron_style }
75
+ - when :select, :boolean
76
+ %select{ name: "filters[#{filter[:name]}]", id: filter_id, class: controls.select(t) }
79
77
  %option{ value: "" }= I18n.t("iron_admin.resources.index.all_option")
80
78
  - filter_options_for(@resource_class, filter).each do |label, value|
81
79
  %option{ value: value, selected: iron_admin_filter_param(filter[:name]) == value.to_s }= label
82
80
  - when :date_range
81
+ -# The inputs' names say which end each holds; the markers say it on screen.
83
82
  .space-y-2
84
- = date_field_tag "filters[#{filter[:name]}_from]", iron_admin_filter_param("#{filter[:name]}_from"),
85
- class: cp_filter_input_class,
86
- "aria-label": I18n.t("iron_admin.filters.from_label", filter: filter_label),
87
- placeholder: I18n.t("iron_admin.filters.from")
88
- = date_field_tag "filters[#{filter[:name]}_to]", iron_admin_filter_param("#{filter[:name]}_to"),
89
- class: cp_filter_input_class,
90
- "aria-label": I18n.t("iron_admin.filters.to_label", filter: filter_label),
91
- placeholder: I18n.t("iron_admin.filters.to")
83
+ .flex.items-center.gap-2
84
+ %span{ "aria-hidden": "true", class: controls.range_marker(t) }= I18n.t("iron_admin.filters.from")
85
+ = date_field_tag "filters[#{filter[:name]}_from]", iron_admin_filter_param("#{filter[:name]}_from"),
86
+ class: controls.input(t),
87
+ "aria-label": I18n.t("iron_admin.filters.from_label", filter: filter_label),
88
+ placeholder: I18n.t("iron_admin.filters.from")
89
+ .flex.items-center.gap-2
90
+ %span{ "aria-hidden": "true", class: controls.range_marker(t) }= I18n.t("iron_admin.filters.to")
91
+ = date_field_tag "filters[#{filter[:name]}_to]", iron_admin_filter_param("#{filter[:name]}_to"),
92
+ class: controls.input(t),
93
+ "aria-label": I18n.t("iron_admin.filters.to_label", filter: filter_label),
94
+ placeholder: I18n.t("iron_admin.filters.to")
92
95
  - when :string
93
96
  - string_ops = %w[contains equals starts_with ends_with]
94
97
  - current_op = iron_admin_filter_param(filter[:name].to_s, "op") || "contains"
95
98
  - current_val = iron_admin_filter_param(filter[:name].to_s, "value") || ""
96
99
  .space-y-2
97
- %select.block.w-full.appearance-none.border.px-3.py-2.text-sm.shadow-sm.outline-none.transition.duration-150.ease-in-out{ name: "filters[#{filter[:name]}][op]", id: "#{filter_id}_op", "aria-label": I18n.t("iron_admin.filters.operator_label", filter: filter_label), class: "#{t.border_radius} #{t.input_border} #{t.card_bg} #{cp_body_text} #{cp_focus}", style: select_chevron_style }
100
+ %select{ name: "filters[#{filter[:name]}][op]", id: "#{filter_id}_op", "aria-label": I18n.t("iron_admin.filters.operator_label", filter: filter_label), class: controls.select(t) }
98
101
  - string_ops.each do |op|
99
102
  %option{ value: op, selected: current_op == op }= I18n.t("iron_admin.filters.operators.#{op}")
100
103
  = text_field_tag "filters[#{filter[:name]}][value]", current_val,
101
- class: cp_filter_input_class,
104
+ class: controls.input(t),
102
105
  placeholder: filter[:label] || filter[:name].to_s.humanize
103
106
  - when :number
104
107
  - number_ops = %w[equals greater_than less_than between]
@@ -106,90 +109,100 @@
106
109
  - current_val = iron_admin_filter_param(filter[:name].to_s, "value") || ""
107
110
  - current_val_upper = iron_admin_filter_param(filter[:name].to_s, "value_2") || ""
108
111
  .space-y-2{ data: { controller: "filter-operator" } }
109
- %select.block.w-full.appearance-none.border.px-3.py-2.text-sm.shadow-sm.outline-none.transition.duration-150.ease-in-out{ name: "filters[#{filter[:name]}][op]", id: "#{filter_id}_op", "aria-label": I18n.t("iron_admin.filters.operator_label", filter: filter_label), class: "#{t.border_radius} #{t.input_border} #{t.card_bg} #{cp_body_text} #{cp_focus}", style: select_chevron_style, data: { action: "change->filter-operator#toggle", filter_operator_target: "opSelect" } }
112
+ %select{ name: "filters[#{filter[:name]}][op]", id: "#{filter_id}_op", "aria-label": I18n.t("iron_admin.filters.operator_label", filter: filter_label), class: controls.select(t), data: { action: "change->filter-operator#toggle", filter_operator_target: "opSelect" } }
110
113
  - number_ops.each do |op|
111
114
  %option{ value: op, selected: current_op == op }= I18n.t("iron_admin.filters.operators.#{op}")
112
115
  = number_field_tag "filters[#{filter[:name]}][value]", current_val,
113
- class: cp_filter_input_class, step: "any",
116
+ class: controls.input(t), step: "any",
114
117
  placeholder: filter[:label] || filter[:name].to_s.humanize
115
118
  .flex.items-center.gap-2{ data: { filter_operator_target: "betweenRow" }, class: current_op == "between" ? "" : "hidden" }
116
- %span.text-xs{ class: cp_muted_text }= I18n.t("iron_admin.filters.between_separator")
119
+ %span.text-xs{ class: t.muted_text }= I18n.t("iron_admin.filters.between_separator")
117
120
  = number_field_tag "filters[#{filter[:name]}][value_2]", current_val_upper,
118
- class: cp_filter_input_class, step: "any",
121
+ class: controls.input(t), step: "any",
119
122
  "aria-label": I18n.t("iron_admin.filters.upper_value_label", filter: filter_label)
120
- .flex.items-center.gap-3.mt-4.pt-3.border-t.border-gray-100
121
- %button{ type: "submit", class: cp_btn_filter_apply }= I18n.t("iron_admin.resources.index.apply_button")
123
+ %div{ class: controls.footer(t) }
124
+ %button{ type: "submit", class: controls.apply_button(t) }= I18n.t("iron_admin.resources.index.apply_button")
122
125
  = link_to I18n.t("iron_admin.resources.index.clear_button"),
123
126
  resources_path(@resource_class.resource_name, scope: @current_scope, q: params[:q], **iron_admin_index_state.slice("sort", "direction").symbolize_keys),
124
- class: "text-sm #{cp_link_muted}"
127
+ class: controls.clear_button(t)
125
128
 
126
- - has_bulk_actions = @resource_class.defined_bulk_actions.any?
129
+ - has_bulk_actions = @permitted_bulk_actions.any?
127
130
  = turbo_frame_tag "records", data: { turbo_action: "advance" } do
128
131
  -# Submitted to the whole page, so the shell shows the redirect's flash message.
129
- = form_tag "#", method: :post, id: "bulk-actions-form", data: { turbo_frame: "_top", **(has_bulk_actions ? { controller: "cp-bulk-select" } : {}) } do
132
+ -# A bulk action with form fields opens its form with a GET; cp-bulk-select keeps the CSRF token out of its URL.
133
+ -# per_form_csrf_tokens would bind a token for action "#" to the index path. The global token validates on each bulk action route.
134
+ = form_tag "#", method: :post, id: "bulk-actions-form", authenticity_token: form_authenticity_token, data: { turbo_frame: "_top", **(has_bulk_actions ? { controller: "cp-bulk-select", action: "submit->cp-bulk-select#omitTokenFromGet" } : {}) } do
130
135
  - if has_bulk_actions
131
136
  - iron_admin_hidden_params(iron_admin_index_state).each do |name, value|
132
137
  = hidden_field_tag name, value, id: nil
133
- .hidden.items-center.gap-3.mb-4.px-4.py-3.border{ data: { cp_bulk_select_target: "bar" }, class: "#{t.border_radius} #{t.card_border} #{t.card_bg} #{t.card_shadow}" }
134
- %span.text-sm.font-medium{ class: cp_muted_text }
135
- %span{ data: { cp_bulk_select_target: "count" } } 0
138
+ .hidden.flex-wrap.items-center.gap-3.mb-4.px-4.py-2{ data: { cp_bulk_select_target: "bar" }, class: styles.panel(t) }
139
+ %span.text-sm.font-medium{ class: t.muted_text }
140
+ %span.tabular-nums{ data: { cp_bulk_select_target: "count" } } 0
136
141
  = I18n.t("iron_admin.resources.index.selected_label", default: "selected")
137
- .flex.items-center.gap-2
138
- - @resource_class.defined_bulk_actions.each do |action|
139
- %button{ type: "submit", class: "#{t.btn_secondary} px-3 py-1.5 text-sm font-medium rounded-lg inline-flex items-center gap-1",
140
- formaction: resource_bulk_action_path(@resource_class.resource_name, action[:name]) }
142
+ .flex.flex-wrap.items-center.gap-2
143
+ - @permitted_bulk_actions.each do |action|
144
+ -# A bulk action with form fields takes the selection to its form instead of running, and the
145
+ -# form asks for the confirmation on submit. Turbo reads data-turbo-confirm from the button.
146
+ - if action[:form_fields].present?
147
+ - submission = { formaction: resource_bulk_action_form_path(@resource_class.resource_name, action[:name]), formmethod: "get" }
148
+ - else
149
+ - submission = { formaction: resource_bulk_action_path(@resource_class.resource_name, action[:name]) }
150
+ - submission[:data] = { turbo_confirm: action[:confirm_message].presence || I18n.t("iron_admin.resources.action.confirm") } if action[:confirm]
151
+ %button{ type: "submit", class: styles.secondary_button(t), **submission }
141
152
  - if action[:icon]
142
153
  = heroicon action[:icon], variant: :mini, options: { class: "h-4 w-4" }
143
154
  = action[:name].to_s.humanize
144
- - if (table_component = iron_admin_table_component(@resource_class, records: @records, fields: @fields, scope: @current_scope))
155
+ - if (table_component = iron_admin_table_component(@resource_class, records: @records, fields: @fields, scope: @current_scope, bulk_actions: @permitted_bulk_actions))
145
156
  = render table_component
146
157
  - else
147
158
  - sticky = IronAdmin.configuration.sticky_actions_column
148
- - sticky_th = sticky ? "sticky right-0 z-10 #{t.table_header_bg}" : ""
149
- - sticky_td = sticky ? "sticky right-0 z-10 #{t.card_bg}" : ""
150
- - sticky_shadow = sticky ? "shadow-[-4px_0_6px_-4px_rgba(0,0,0,0.08)]" : ""
151
- .overflow-x-auto
152
- %table.min-w-full{ class: "#{cp_table_border} divide-y #{t.card_bg} #{t.border_radius} #{t.card_shadow}" }
153
- %thead{ class: cp_table_header_bg }
159
+ - visible_fields = @fields.select { |field| field.visible?(iron_admin_current_user) }
160
+ %div{ class: styles.table_frame(t) }
161
+ %table{ class: styles.table(t) }
162
+ %thead{ class: t.table_header_bg }
154
163
  %tr
155
164
  - if has_bulk_actions
156
- %th.px-6.py-3.w-4
157
- %input{ type: "checkbox", class: "rounded border-gray-300",
165
+ %th.w-4{ scope: "col", class: t.table_cell_padding }
166
+ %input{ type: "checkbox", class: cp_checkbox_class,
158
167
  "aria-label": I18n.t("iron_admin.resources.index.select_all"),
159
168
  data: { cp_bulk_select_target: "selectAll", action: "change->cp-bulk-select#toggleAll" } }
160
- - @fields.each do |field|
161
- - next unless field.visible?(iron_admin_current_user)
169
+ - visible_fields.each do |field|
162
170
  - sorted = params[:sort] == field.name.to_s
163
171
  - next_dir = sorted && params[:direction] == "asc" ? "desc" : "asc"
164
- %th.px-6.py-3.text-left.text-xs.font-medium.uppercase.tracking-wider{ class: cp_muted_text }
172
+ %th{ scope: "col", class: styles.header_cell(t) }
165
173
  -# A whole-page visit, so the search and filter forms outside the frame get the new sort.
166
174
  = link_to iron_admin_sort_path(@resource_class, @current_scope, field.name, next_dir),
167
- class: "inline-flex items-center gap-1 group", data: { turbo_frame: "_top" } do
175
+ class: "group inline-flex items-center gap-1 #{t.focus_ring}", data: { turbo_frame: "_top" } do
168
176
  = field.name.to_s.humanize
169
177
  - if sorted
170
178
  = heroicon(params[:direction] == "asc" ? "chevron-up" : "chevron-down", variant: :mini, options: { class: "h-3.5 w-3.5" })
171
179
  - else
172
180
  = heroicon "chevron-up-down", variant: :mini, options: { class: "h-3.5 w-3.5 opacity-0 group-hover:opacity-50 transition-opacity" }
173
181
  -# sticky or relative keeps the absolutely positioned sr-only text inside the scrolling table.
174
- %th{ class: "px-6 py-3 #{sticky ? sticky_th : 'relative'} #{sticky_shadow}" }
182
+ %th{ scope: "col", class: "#{t.table_cell_padding} #{sticky ? styles.sticky_header_cell(t) : 'relative'}" }
183
+ -# The cell's own box-shadow would not be painted: an edge box inside it casts it.
184
+ - if sticky
185
+ %span{ "aria-hidden": "true", class: styles.sticky_edge(t) }
175
186
  %span.sr-only= I18n.t("iron_admin.resources.show.actions_label")
176
- %tbody{ class: "#{cp_table_border} divide-y" }
187
+ %tbody{ class: styles.divided(t) }
177
188
  - if @records.empty?
178
189
  %tr
179
- %td.px-6.py-8.text-center.text-sm{ colspan: (@fields.count { |f| f.visible?(iron_admin_current_user) }) + (has_bulk_actions ? 2 : 1), class: cp_muted_text }
190
+ %td.px-4.py-12.text-center.text-sm{ colspan: visible_fields.size + (has_bulk_actions ? 2 : 1), class: t.muted_text }
180
191
  = I18n.t("iron_admin.resources.index.empty_state")
181
192
  - @records.each do |record|
182
- %tr{ class: cp_table_row_hover, **(@resource_class.live_index_enabled? ? { id: "iron_admin_#{@resource_class.resource_name}_row_#{record.id}" } : {}) }
193
+ -# group/row lets the sticky actions cell follow the row's hover (table_sticky_row_hover).
194
+ %tr{ class: "group/row #{t.table_row_hover}", **(@resource_class.live_index_enabled? ? { id: "iron_admin_#{@resource_class.resource_name}_row_#{record.id}" } : {}) }
183
195
  - if has_bulk_actions
184
- %td.px-6.py-4.w-4
185
- %input{ type: "checkbox", name: "ids[]", value: record.id, class: "rounded border-gray-300",
196
+ %td.w-4{ class: t.table_cell_padding }
197
+ %input{ type: "checkbox", name: "ids[]", value: record.id, class: cp_checkbox_class,
186
198
  "aria-label": I18n.t("iron_admin.resources.index.select_record", record: display_record_label(record)),
187
199
  data: { cp_bulk_select_target: "checkbox", action: "change->cp-bulk-select#toggle" } }
188
- - @fields.each do |field|
189
- - next unless field.visible?(iron_admin_current_user)
190
- %td.px-6.py-4.whitespace-nowrap.text-sm{ class: cp_body_text }
200
+ - visible_fields.each do |field|
201
+ %td{ class: styles.cell(t, field) }
191
202
  = display_index_field_value(record, field)
192
- %td.whitespace-nowrap.text-right.text-sm{ class: "px-6 py-4 #{sticky_td} #{sticky_shadow}" }
203
+ %td{ class: "whitespace-nowrap text-right text-sm #{t.table_cell_padding} #{sticky ? styles.sticky_cell(t) : ''}" }
204
+ - if sticky
205
+ %span{ "aria-hidden": "true", class: styles.sticky_edge(t) }
193
206
  = link_to I18n.t("iron_admin.resources.index.view_link"), resource_path(@resource_class.resource_name, record),
194
207
  class: cp_link, data: { turbo_frame: "_top" }
195
208
 
@@ -1,7 +1,7 @@
1
1
  - form_url = resources_path(@resource_class.resource_name)
2
2
 
3
- .p-4.sm:p-6.lg:p-8.max-w-7xl.mx-auto{ class: t.font_family }
4
- %h1.text-2xl.mb-6{ class: cp_heading }= I18n.t("iron_admin.resources.new.title", model: @resource_class.model.model_name.human)
3
+ .px-4.sm:px-6.lg:px-8.py-6.max-w-7xl.mx-auto
4
+ %h1.mb-6{ class: "#{t.page_title} #{t.heading_font}" }= I18n.t("iron_admin.resources.new.title", model: @resource_class.model.model_name.human)
5
5
 
6
6
  .p-6{ class: cp_card }
7
7
  - if (form_component = iron_admin_form_component(@resource_class, record: @record, fields: @fields, url: form_url))
@@ -1,8 +1,10 @@
1
- .p-4.sm:p-6.lg:p-8.max-w-7xl.mx-auto{ class: t.font_family }
1
+ - styles = IronAdmin::Resources::Styles
2
+
3
+ .px-4.sm:px-6.lg:px-8.py-6.max-w-7xl.mx-auto
2
4
  .flex.items-center.justify-between.gap-3.flex-wrap.mb-6
3
- %h1.text-2xl{ class: cp_heading }
5
+ %h1{ class: styles.page_title(t) }
4
6
  = @resource_class.model.model_name.human
5
- %span.text-gray-400= "##{@record.id}"
7
+ %span{ class: cp_muted_text }= "##{@record.id}"
6
8
  .flex.gap-2.flex-wrap
7
9
  - if @resource_class.crud_allowed?(:update, iron_admin_current_user) && @record_reachable
8
10
  = link_to I18n.t("iron_admin.resources.show.edit_button"), edit_resource_path(@resource_class.resource_name, @record),
@@ -12,62 +14,72 @@
12
14
  method: :delete, data: { turbo_confirm: I18n.t("iron_admin.resources.show.delete_confirm") },
13
15
  class: cp_btn_danger
14
16
 
15
- .overflow-hidden{ class: cp_card }
16
- %dl{ class: "#{cp_table_border} divide-y" }
17
+ .overflow-hidden{ class: styles.panel(t) }
18
+ %dl{ class: styles.divided(t) }
17
19
  - @fields.each do |field|
18
20
  - next unless field.visible?(iron_admin_current_user)
19
- .px-6.py-4.flex.flex-col.gap-1{ class: "sm:flex-row sm:items-center" }
20
- %dt.text-sm.font-medium{ class: "sm:w-1/3 #{cp_muted_text}" }= field.name.to_s.humanize
21
- %dd.text-sm.break-words{ class: "sm:w-2/3 #{cp_body_text}" }= display_field_value(@record, field)
21
+ %div{ class: styles::DETAIL_ROW }
22
+ %dt.text-sm.font-medium{ class: "sm:w-1/3 #{t.muted_text} #{t.field_label_transform}" }= field.name.to_s.humanize
23
+ %dd.text-sm.break-words{ class: "sm:w-2/3 #{t.body_text}" }= display_show_field_value(@record, field)
22
24
 
23
25
  - @resource_class.has_one_associations.each do |assoc|
24
- - related_record = @record.public_send(assoc[:name])
26
+ - next unless related_panel_readable?(assoc)
27
+ - related_record = self.related_record(@record, assoc)
25
28
  - next unless related_record
26
- .mt-6.overflow-hidden{ class: cp_card }
27
- .px-6.py-4.border-b.flex.items-center.justify-between{ class: t.card_border }
28
- %h2.text-lg.font-semibold= assoc[:name].to_s.humanize
29
+ .mt-6.overflow-hidden{ class: styles.panel(t) }
30
+ %div{ class: styles.panel_header(t) }
31
+ %h2{ class: styles.panel_title(t) }= assoc[:name].to_s.humanize
29
32
  = link_to I18n.t("iron_admin.resources.show.view_link"),
30
33
  resource_path(assoc[:resource].resource_name, related_record),
31
34
  class: "text-sm #{cp_link}"
32
- %dl{ class: "#{cp_table_border} divide-y" }
35
+ %dl{ class: styles.divided(t) }
33
36
  - assoc[:resource].resolved_fields.first(6).each do |field|
34
37
  - next if field.name == :id
35
38
  - next unless field.visible?(iron_admin_current_user)
36
- .px-6.py-3.flex.flex-col.gap-1{ class: "sm:flex-row sm:items-center" }
37
- %dt.text-sm.font-medium{ class: "sm:w-1/3 #{cp_muted_text}" }= field.name.to_s.humanize
38
- %dd.text-sm.break-words{ class: "sm:w-2/3 #{cp_body_text}" }= display_field_value(related_record, field)
39
+ %div{ class: styles::DETAIL_ROW }
40
+ %dt.text-sm.font-medium{ class: "sm:w-1/3 #{t.muted_text} #{t.field_label_transform}" }= field.name.to_s.humanize
41
+ %dd.text-sm.break-words{ class: "sm:w-2/3 #{t.body_text}" }= display_show_field_value(related_record, field)
39
42
 
40
43
  - @resource_class.habtm_associations.each do |assoc|
41
- - related_records = @record.public_send(assoc[:name])
44
+ - next unless related_panel_readable?(assoc)
45
+ - related_records = self.related_records(@record, assoc)
42
46
  - next if related_records.empty?
43
- .mt-6.overflow-hidden{ class: cp_card }
44
- .px-6.py-4.border-b{ class: t.card_border }
45
- %h2.text-lg.font-semibold= assoc[:name].to_s.humanize
46
- .px-6.py-4
47
- .flex.flex-wrap.gap-2
48
- - related_records.each do |related|
49
- - display = assoc[:display]
50
- - if assoc[:resource]
51
- = link_to display_record_label(related, display),
52
- resource_path(assoc[:resource].resource_name, related),
53
- class: "inline-flex px-3 py-1 text-sm font-medium rounded-full bg-indigo-50 text-indigo-700 hover:bg-indigo-100 transition-colors"
54
- - else
55
- %span.inline-flex.px-3.py-1.text-sm.font-medium.rounded-full.bg-gray-100.text-gray-700
56
- = display_record_label(related, display)
47
+ .mt-6{ class: styles.panel(t) }
48
+ %div{ class: styles.panel_header(t) }
49
+ %h2{ class: styles.panel_title(t) }= assoc[:name].to_s.humanize
50
+ .flex.flex-wrap.gap-2.px-4.py-3
51
+ - related_records.each do |related|
52
+ - display = assoc[:display]
53
+ - if assoc[:resource]
54
+ = link_to display_record_label(related, display),
55
+ resource_path(assoc[:resource].resource_name, related),
56
+ class: "inline-flex items-center px-2 py-0.5 text-xs transition-opacity hover:opacity-75 #{t.badge_shape} #{t.chip} #{t.focus_ring}"
57
+ - else
58
+ %span{ class: "inline-flex items-center px-2 py-0.5 text-xs #{t.badge_shape} #{t.chip}" }
59
+ = display_record_label(related, display)
57
60
 
58
61
  - @resource_class.has_many_associations.each do |assoc|
62
+ - next unless related_panel_readable?(assoc)
59
63
  = render IronAdmin::Resources::RelatedListComponent.new(association: assoc,
60
- records: @record.public_send(assoc[:name]), parent: @record)
64
+ records: self.related_records(@record, assoc), parent: @record)
61
65
 
62
66
  - if @member_actions.any?
63
- .mt-6.p-6{ class: cp_card }
64
- %h2.text-lg.font-semibold.mb-4= I18n.t("iron_admin.resources.show.actions_label")
67
+ .mt-6.p-4{ class: styles.panel(t) }
68
+ %h2.mb-3{ class: styles.panel_title(t) }= I18n.t("iron_admin.resources.show.actions_label")
65
69
  .flex.gap-2.flex-wrap
66
70
  - @member_actions.each do |action|
67
- - confirm = action[:confirm_message].presence || I18n.t("iron_admin.resources.action.confirm")
68
- = button_to resource_action_path(@resource_class.resource_name, @record, action[:name]),
69
- data: action[:confirm] ? { turbo_confirm: confirm } : {},
70
- class: cp_btn_ghost do
71
- - if action[:icon]
72
- = heroicon action[:icon], variant: :outline, options: { class: "h-5 w-5" }
73
- = action[:name].to_s.humanize
71
+ -# An action with form fields opens its form, which asks for the confirmation on submit.
72
+ - if action[:form_fields].present?
73
+ = link_to resource_action_form_path(@resource_class.resource_name, @record, action[:name]),
74
+ class: styles.secondary_button(t) do
75
+ - if action[:icon]
76
+ = heroicon action[:icon], variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
77
+ = action[:name].to_s.humanize
78
+ - else
79
+ - confirm = action[:confirm_message].presence || I18n.t("iron_admin.resources.action.confirm")
80
+ = button_to resource_action_path(@resource_class.resource_name, @record, action[:name]),
81
+ data: action[:confirm] ? { turbo_confirm: confirm } : {},
82
+ class: styles.secondary_button(t) do
83
+ - if action[:icon]
84
+ = heroicon action[:icon], variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
85
+ = action[:name].to_s.humanize
@@ -1,13 +1,21 @@
1
- .p-4.sm:p-6.lg:p-8
2
- %h1.text-2xl.font-bold.mb-6= @query.present? ? "Search results for \"#{@query}\"" : "Search results"
1
+ - styles = IronAdmin::Resources::Styles
2
+
3
+ .px-4.sm:px-6.lg:px-8.py-6.max-w-7xl.mx-auto
4
+ %h1.mb-6{ class: styles.page_title(t) }
5
+ - if @query.present?
6
+ -# <q> draws the language's quotation marks; the query keeps the case it was typed in.
7
+ Search results for
8
+ %q.normal-case= @query
9
+ - else
10
+ Search results
3
11
  - if @results&.any?
4
12
  - @results.each do |group|
5
- .mb-6
6
- %h2.text-lg.font-semibold.mb-2= group[:resource].label
7
- .bg-white.rounded-lg.shadow.divide-y.divide-gray-200
13
+ %section.mb-6
14
+ %h2.mb-2{ class: styles.panel_title(t) }= group[:resource].label
15
+ %div{ class: "#{styles.panel(t)} #{styles.divided(t)}" }
8
16
  - group[:records].each do |record|
9
- = link_to resource_path(group[:resource].resource_name, record),
10
- class: "block px-6 py-4 hover:bg-gray-50 text-sm text-gray-900" do
11
- = display_record_label(record)
17
+ = link_to resource_path(group[:resource].resource_name, record), class: styles.list_row(t) do
18
+ -# In the link color, like the related records of a show page.
19
+ %span{ class: t.link }= display_record_label(record)
12
20
  - elsif @query.present?
13
- .text-center.text-gray-500.py-12 No results found.
21
+ .text-center.py-12.text-sm{ class: t.muted_text } No results found.
@@ -1,27 +1,30 @@
1
1
  -# locals: (pagy:)
2
2
  - if pagy.pages > 1
3
- %nav.flex.items-center.justify-between.border-t.border-gray-200.bg-white.px-4.py-3{ class: "sm:px-6", "aria-label": "Pagination" }
3
+ - link_classes = "relative inline-flex h-8 items-center px-3 text-sm font-medium transition-colors duration-150 #{t.control_radius} #{t.btn_secondary} #{t.focus_ring}"
4
+ -# A link with no href, marked disabled: its faded text is exempt from WCAG contrast.
5
+ - disabled_classes = "relative inline-flex h-8 items-center px-3 text-sm font-medium cursor-not-allowed #{t.control_radius} #{t.border_width} #{t.card_border} #{t.card_bg} #{t.disabled_text}"
6
+ %nav.flex.items-center.justify-between.gap-3.py-1{ "aria-label": "Pagination" }
4
7
  .hidden{ class: "sm:block" }
5
- %p.text-sm.text-gray-700
8
+ %p.text-sm{ class: t.muted_text }
6
9
  Showing
7
- %span.font-medium= pagy.from
10
+ %span.font-medium.tabular-nums{ class: t.body_text }= pagy.from
8
11
  to
9
- %span.font-medium= pagy.to
12
+ %span.font-medium.tabular-nums{ class: t.body_text }= pagy.to
10
13
  of
11
- %span.font-medium= pagy.count
14
+ %span.font-medium.tabular-nums{ class: t.body_text }= pagy.count
12
15
  results
13
16
 
14
- .flex.flex-1.justify-between{ class: "sm:justify-end" }
17
+ .flex.flex-1.justify-between.gap-2{ class: "sm:justify-end" }
15
18
  - if pagy.previous
16
- = link_to url_for(request.query_parameters.merge(page: pagy.previous)), class: "relative inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:outline-offset-0" do
19
+ = link_to url_for(request.query_parameters.merge(page: pagy.previous)), class: link_classes do
17
20
  Previous
18
21
  - else
19
- %span.relative.inline-flex.items-center.rounded-md.bg-white.px-3.py-2.text-sm.font-semibold.text-gray-300.ring-1.ring-inset.ring-gray-300.cursor-not-allowed
22
+ %span{ class: disabled_classes, role: "link", "aria-disabled": "true" }
20
23
  Previous
21
24
 
22
25
  - if pagy.next
23
- = link_to url_for(request.query_parameters.merge(page: pagy.next)), class: "relative ml-3 inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:outline-offset-0" do
26
+ = link_to url_for(request.query_parameters.merge(page: pagy.next)), class: link_classes do
24
27
  Next
25
28
  - else
26
- %span.relative.ml-3.inline-flex.items-center.rounded-md.bg-white.px-3.py-2.text-sm.font-semibold.text-gray-300.ring-1.ring-inset.ring-gray-300.cursor-not-allowed
29
+ %span{ class: disabled_classes, role: "link", "aria-disabled": "true" }
27
30
  Next