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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +129 -1
- data/README.md +48 -1
- data/UPGRADING.md +495 -8
- data/app/assets/tailwind/iron_admin/engine.css +79 -4
- data/app/components/iron_admin/dashboards/activity_feed_component/item_component.html.haml +6 -9
- data/app/components/iron_admin/dashboards/activity_feed_component.html.haml +6 -5
- data/app/components/iron_admin/dashboards/activity_feed_component.rb +21 -24
- data/app/components/iron_admin/dashboards/chart_component.html.haml +3 -5
- data/app/components/iron_admin/dashboards/chart_component.rb +86 -24
- data/app/components/iron_admin/dashboards/concerns/themed_card.rb +39 -0
- data/app/components/iron_admin/dashboards/metric_card_component.html.haml +8 -7
- data/app/components/iron_admin/dashboards/metric_card_component.rb +2 -0
- data/app/components/iron_admin/dashboards/progress_component.html.haml +11 -7
- data/app/components/iron_admin/dashboards/progress_component.rb +11 -6
- data/app/components/iron_admin/dashboards/quick_links_component/link_component.html.haml +8 -9
- data/app/components/iron_admin/dashboards/quick_links_component.html.haml +6 -5
- data/app/components/iron_admin/dashboards/quick_links_component.rb +4 -12
- data/app/components/iron_admin/dashboards/recent_table_component.html.haml +15 -10
- data/app/components/iron_admin/dashboards/recent_table_component.rb +49 -0
- data/app/components/iron_admin/dashboards/stats_grid_component/stat_component.html.haml +13 -14
- data/app/components/iron_admin/dashboards/stats_grid_component.html.haml +1 -0
- data/app/components/iron_admin/dashboards/stats_grid_component.rb +9 -11
- data/app/components/iron_admin/filters/bar_component.html.haml +8 -6
- data/app/components/iron_admin/filters/bar_component.rb +56 -9
- data/app/components/iron_admin/filters/control_styles.rb +82 -0
- data/app/components/iron_admin/filters/date_range_component.html.haml +9 -4
- data/app/components/iron_admin/filters/date_range_component.rb +10 -6
- data/app/components/iron_admin/filters/search_component.html.haml +4 -4
- data/app/components/iron_admin/filters/search_component.rb +3 -5
- data/app/components/iron_admin/filters/select_filter_component.html.haml +1 -1
- data/app/components/iron_admin/filters/select_filter_component.rb +5 -16
- data/app/components/iron_admin/form/belongs_to_autocomplete_component.html.haml +9 -5
- data/app/components/iron_admin/form/belongs_to_autocomplete_component.rb +10 -8
- data/app/components/iron_admin/form/belongs_to_component.html.haml +2 -2
- data/app/components/iron_admin/form/belongs_to_component.rb +4 -18
- data/app/components/iron_admin/form/checkbox_component.rb +2 -3
- data/app/components/iron_admin/form/concerns/form_input_behavior.rb +1 -1
- data/app/components/iron_admin/form/control_classes.rb +108 -0
- data/app/components/iron_admin/form/date_picker_component.rb +3 -7
- data/app/components/iron_admin/form/field_wrapper_component.html.haml +3 -3
- data/app/components/iron_admin/form/field_wrapper_component.rb +3 -3
- data/app/components/iron_admin/form/nested_form_component.html.haml +4 -5
- data/app/components/iron_admin/form/nested_form_component.rb +12 -2
- data/app/components/iron_admin/form/select_component.html.haml +1 -1
- data/app/components/iron_admin/form/select_component.rb +2 -16
- data/app/components/iron_admin/form/text_input_component.rb +1 -5
- data/app/components/iron_admin/form/textarea_component.rb +1 -5
- data/app/components/iron_admin/layout/flash_component.html.haml +1 -1
- data/app/components/iron_admin/layout/flash_component.rb +4 -3
- data/app/components/iron_admin/layout/navbar_component.html.haml +15 -9
- data/app/components/iron_admin/layout/navbar_component.rb +29 -1
- data/app/components/iron_admin/layout/shell_component.html.haml +4 -4
- data/app/components/iron_admin/layout/shell_component.rb +16 -3
- data/app/components/iron_admin/layout/sidebar_component.html.haml +21 -25
- data/app/components/iron_admin/layout/sidebar_component.rb +76 -1
- data/app/components/iron_admin/layout/theme_switcher_component.html.haml +15 -0
- data/app/components/iron_admin/layout/theme_switcher_component.rb +74 -0
- data/app/components/iron_admin/resources/actions_component.html.haml +15 -8
- data/app/components/iron_admin/resources/actions_component.rb +34 -2
- data/app/components/iron_admin/resources/breadcrumb_component.html.haml +3 -3
- data/app/components/iron_admin/resources/breadcrumb_component.rb +8 -7
- data/app/components/iron_admin/resources/bulk_actions_component.html.haml +9 -8
- data/app/components/iron_admin/resources/bulk_actions_component.rb +47 -4
- data/app/components/iron_admin/resources/data_table_component.html.haml +15 -15
- data/app/components/iron_admin/resources/data_table_component.rb +34 -3
- data/app/components/iron_admin/resources/related_list_component.html.haml +7 -7
- data/app/components/iron_admin/resources/related_list_component.rb +26 -2
- data/app/components/iron_admin/resources/show_field_component.html.haml +3 -3
- data/app/components/iron_admin/resources/show_field_component.rb +10 -4
- data/app/components/iron_admin/resources/styles.rb +136 -0
- data/app/components/iron_admin/ui/alert_component.html.haml +2 -2
- data/app/components/iron_admin/ui/alert_component.rb +27 -31
- data/app/components/iron_admin/ui/badge_component.rb +40 -20
- data/app/components/iron_admin/ui/button_component.rb +37 -11
- data/app/components/iron_admin/ui/card_component.rb +3 -3
- data/app/components/iron_admin/ui/dropdown_component.html.haml +1 -1
- data/app/components/iron_admin/ui/dropdown_component.rb +34 -13
- data/app/components/iron_admin/ui/empty_state_component.html.haml +4 -5
- data/app/components/iron_admin/ui/empty_state_component.rb +2 -2
- data/app/components/iron_admin/ui/modal_component.html.haml +5 -5
- data/app/components/iron_admin/ui/modal_component.rb +6 -4
- data/app/components/iron_admin/ui/pagination_component.html.haml +14 -14
- data/app/components/iron_admin/ui/pagination_component.rb +26 -9
- data/app/components/iron_admin/ui/scopes_component.html.haml +2 -2
- data/app/components/iron_admin/ui/scopes_component.rb +44 -11
- data/app/components/iron_admin/ui/tooltip_component.rb +11 -4
- data/app/controllers/iron_admin/application_controller.rb +58 -4
- data/app/controllers/iron_admin/audit_controller.rb +30 -6
- data/app/controllers/iron_admin/concerns/action_executable.rb +37 -0
- data/app/controllers/iron_admin/concerns/assignable_references.rb +149 -0
- data/app/controllers/iron_admin/concerns/authorizable.rb +11 -0
- data/app/controllers/iron_admin/concerns/blank_password_filterable.rb +21 -0
- data/app/controllers/iron_admin/concerns/event_emittable.rb +47 -7
- data/app/controllers/iron_admin/concerns/filterable.rb +34 -9
- data/app/controllers/iron_admin/concerns/nested_permittable.rb +5 -3
- data/app/controllers/iron_admin/concerns/nested_tenant_check.rb +159 -0
- data/app/controllers/iron_admin/concerns/polymorphic_references.rb +131 -0
- data/app/controllers/iron_admin/concerns/scopeable.rb +54 -7
- data/app/controllers/iron_admin/concerns/searchable.rb +3 -3
- data/app/controllers/iron_admin/concerns/tenant_assignable.rb +118 -0
- data/app/controllers/iron_admin/concerns/tenant_containment.rb +146 -0
- data/app/controllers/iron_admin/exports_controller.rb +2 -2
- data/app/controllers/iron_admin/imports_controller.rb +1 -1
- data/app/controllers/iron_admin/resources_controller.rb +48 -41
- data/app/controllers/iron_admin/search_controller.rb +1 -2
- data/app/controllers/iron_admin/themes_controller.rb +50 -0
- data/app/controllers/iron_admin/tools_controller.rb +58 -5
- data/app/helpers/iron_admin/action_form_helper.rb +19 -0
- data/app/helpers/iron_admin/application_helper.rb +93 -16
- data/app/helpers/iron_admin/assignable_records_helper.rb +32 -0
- data/app/helpers/iron_admin/component_overrides_helper.rb +9 -4
- data/app/helpers/iron_admin/field_display_helper.rb +88 -43
- data/app/helpers/iron_admin/related_records_helper.rb +51 -0
- data/app/helpers/iron_admin/theme_helper.rb +56 -46
- data/app/javascript/iron_admin/controllers/cp_bulk_select_controller.js +12 -0
- data/app/javascript/iron_admin/controllers/cp_chart_controller.js +4 -0
- data/app/javascript/iron_admin/controllers/cp_disclosure_controller.js +19 -0
- data/app/javascript/iron_admin/controllers/cp_search_shortcut_controller.js +39 -0
- data/app/javascript/iron_admin/index.js +4 -0
- data/app/views/iron_admin/audit/index.html.haml +78 -81
- data/app/views/iron_admin/dashboard/index.html.haml +10 -9
- data/app/views/iron_admin/form/_action_field.html.haml +50 -0
- data/app/views/iron_admin/form/_nested_row.html.haml +18 -13
- data/app/views/iron_admin/imports/new.html.haml +14 -13
- data/app/views/iron_admin/imports/preview.html.haml +24 -21
- data/app/views/iron_admin/resources/_form.html.haml +70 -68
- data/app/views/iron_admin/resources/action_form.html.haml +16 -59
- data/app/views/iron_admin/resources/bulk_action_form.html.haml +20 -58
- data/app/views/iron_admin/resources/edit.html.haml +3 -3
- data/app/views/iron_admin/resources/index.html.haml +87 -74
- data/app/views/iron_admin/resources/new.html.haml +2 -2
- data/app/views/iron_admin/resources/show.html.haml +53 -41
- data/app/views/iron_admin/search/index.html.haml +17 -9
- data/app/views/iron_admin/shared/_pagination.html.haml +13 -10
- data/app/views/iron_admin/shared/error.html.haml +16 -12
- data/app/views/iron_admin/tools/action_form.html.haml +9 -55
- data/app/views/iron_admin/tools/show.html.haml +4 -5
- data/app/views/layouts/iron_admin/_document_head.html.haml +24 -0
- data/app/views/layouts/iron_admin/application.html.haml +4 -17
- data/app/views/layouts/iron_admin/minimal.html.haml +7 -0
- data/config/importmap.rb +2 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +1 -0
- data/docs/FAQ.md +87 -37
- data/docs/README.md +8 -2
- data/docs/components/README.md +6 -2
- data/docs/components/dashboard-components.md +24 -35
- data/docs/components/filter-components.md +44 -92
- data/docs/components/form-components.md +16 -32
- data/docs/components/resource-components.md +46 -27
- data/docs/components/ui-components.md +44 -26
- data/docs/getting-started/installation.md +5 -1
- data/docs/getting-started/quick-start.md +36 -23
- data/docs/guides/authentication.md +182 -42
- data/docs/guides/components.md +97 -15
- data/docs/guides/custom-adapters.md +24 -4
- data/docs/guides/dashboard.md +68 -44
- data/docs/guides/export.md +24 -8
- data/docs/guides/extending.md +206 -51
- data/docs/guides/fields.md +229 -70
- data/docs/guides/imports.md +33 -18
- data/docs/guides/resources.md +333 -111
- data/docs/guides/theming.md +930 -58
- data/docs/guides/troubleshooting.md +7 -3
- data/docs/plugin-system-design.md +8 -7
- data/docs/reference/configuration.md +51 -16
- data/docs/reference/routes.md +1 -0
- data/docs/reference/theme-properties.md +101 -38
- data/lib/generators/iron_admin/install/templates/initializer.rb.tt +7 -2
- data/lib/generators/iron_admin/install_audit/templates/create_iron_admin_audit_entries.rb.tt +2 -0
- data/lib/iron_admin/action_field.rb +11 -0
- data/lib/iron_admin/adapters/active_record.rb +95 -0
- data/lib/iron_admin/adapters/base.rb +107 -0
- data/lib/iron_admin/adapters/http/query.rb +21 -0
- data/lib/iron_admin/adapters/http.rb +84 -4
- data/lib/iron_admin/adapters/mongoid.rb +96 -2
- data/lib/iron_admin/audit_log.rb +64 -6
- data/lib/iron_admin/authentication_warning.rb +31 -0
- data/lib/iron_admin/concerns/filter_definable.rb +15 -1
- data/lib/iron_admin/concerns/nestable.rb +25 -0
- data/lib/iron_admin/concerns/scope_countable.rb +56 -0
- data/lib/iron_admin/concerns/soft_deletable.rb +28 -9
- data/lib/iron_admin/configuration/components.rb +14 -3
- data/lib/iron_admin/configuration/theme/neutral_defaults.rb +179 -0
- data/lib/iron_admin/configuration/theme.rb +292 -87
- data/lib/iron_admin/configuration.rb +340 -45
- data/lib/iron_admin/dashboard.rb +22 -38
- data/lib/iron_admin/engine.rb +16 -2
- data/lib/iron_admin/errors.rb +3 -0
- data/lib/iron_admin/field.rb +78 -17
- data/lib/iron_admin/field_inferrer.rb +61 -3
- data/lib/iron_admin/field_override_warning.rb +67 -0
- data/lib/iron_admin/import/import_preview.rb +56 -7
- data/lib/iron_admin/import/importer.rb +91 -14
- data/lib/iron_admin/import/tenant_precheck.rb +67 -0
- data/lib/iron_admin/plugin/registration.rb +64 -0
- data/lib/iron_admin/plugin_registry.rb +3 -2
- data/lib/iron_admin/policy.rb +22 -12
- data/lib/iron_admin/policy_coverage_warning.rb +46 -0
- data/lib/iron_admin/request_context.rb +18 -0
- data/lib/iron_admin/resource.rb +218 -77
- data/lib/iron_admin/resource_registry.rb +86 -13
- data/lib/iron_admin/scope_counts.rb +73 -0
- data/lib/iron_admin/tenant_scope.rb +30 -0
- data/lib/iron_admin/tool.rb +61 -12
- data/lib/iron_admin/tool_context.rb +10 -6
- data/lib/iron_admin/version.rb +1 -1
- data/lib/iron_admin.rb +29 -2
- metadata +37 -7
|
@@ -7,6 +7,7 @@ module IronAdmin
|
|
|
7
7
|
include IronAdmin::ApplicationHelper
|
|
8
8
|
include IronAdmin::FieldDisplayHelper
|
|
9
9
|
include IronAdmin::ThemeHelper
|
|
10
|
+
include Concerns::ThemedCard
|
|
10
11
|
|
|
11
12
|
# Number of columns shown when the resource declares no index fields.
|
|
12
13
|
DEFAULT_COLUMN_COUNT = 4
|
|
@@ -17,6 +18,24 @@ module IronAdmin
|
|
|
17
18
|
# Field types too long or too sensitive for a compact table.
|
|
18
19
|
SKIPPED_TYPES = %i[textarea rich_text markdown code json key_value boolean_group file files password hidden].freeze
|
|
19
20
|
|
|
21
|
+
# Field types whose cells align their digits.
|
|
22
|
+
NUMERIC_TYPES = %i[number currency].freeze
|
|
23
|
+
|
|
24
|
+
# In a card narrower than 64rem every cell keeps one line and the table scrolls sideways.
|
|
25
|
+
# In a wider card (the card is a size container) the table fits it: association cells
|
|
26
|
+
# wrap, and so does the label column (a field named in LABEL_FIELDS), while the other
|
|
27
|
+
# columns keep their single line.
|
|
28
|
+
WRAPPING_TYPES = %i[belongs_to polymorphic_belongs_to].freeze
|
|
29
|
+
|
|
30
|
+
# Fields that label a record, like the first of ApplicationHelper::DISPLAY_METHODS; in a
|
|
31
|
+
# wide card their cells wrap.
|
|
32
|
+
LABEL_FIELDS = %i[name title label].freeze
|
|
33
|
+
|
|
34
|
+
# Long text: in a wide card its cell keeps one line in a column that takes the room the
|
|
35
|
+
# others leave (at least 12rem), cut with an ellipsis, so it neither widens the table nor
|
|
36
|
+
# makes the rows taller.
|
|
37
|
+
TRUNCATED_TYPES = %i[textarea rich_text markdown].freeze
|
|
38
|
+
|
|
20
39
|
# @param resource_name [Symbol, String] Resource name
|
|
21
40
|
# @param records [ActiveRecord::Relation, Array] Records to display. An unordered
|
|
22
41
|
# relation is listed newest first.
|
|
@@ -63,11 +82,41 @@ module IronAdmin
|
|
|
63
82
|
display_index_field_value(record, field)
|
|
64
83
|
end
|
|
65
84
|
|
|
85
|
+
# Case and letter spacing come from label_transform, as in every small label.
|
|
86
|
+
#
|
|
87
|
+
# @api private
|
|
88
|
+
# @return [String] Classes of a header cell
|
|
89
|
+
def header_cell_classes
|
|
90
|
+
"#{theme.table_header_text} #{theme.label_transform} #{theme.table_cell_padding}"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @api private
|
|
94
|
+
# @param field [IronAdmin::Field] The cell's field
|
|
95
|
+
# @return [String] Classes of a body cell: one line (in a card 64rem wide or more,
|
|
96
|
+
# associations and the label column wrap, and long text is cut to the room left), and
|
|
97
|
+
# numeric cells align their digits
|
|
98
|
+
def cell_classes(field)
|
|
99
|
+
"whitespace-nowrap #{theme.table_cell_padding} #{theme.body_text} #{content_classes(field)}".strip
|
|
100
|
+
end
|
|
101
|
+
|
|
66
102
|
# Delegate route helpers to the view context so included helpers work
|
|
67
103
|
delegate :iron_admin, :main_app, to: :helpers
|
|
68
104
|
|
|
69
105
|
private
|
|
70
106
|
|
|
107
|
+
# How the cell's content fits: cut or wrapped in a wide card, or digits lined up.
|
|
108
|
+
def content_classes(field)
|
|
109
|
+
if TRUNCATED_TYPES.include?(field.type)
|
|
110
|
+
"@5xl:max-w-0 @5xl:min-w-48 @5xl:truncate"
|
|
111
|
+
elsif WRAPPING_TYPES.include?(field.type) || LABEL_FIELDS.include?(field.name)
|
|
112
|
+
"@5xl:whitespace-normal"
|
|
113
|
+
elsif NUMERIC_TYPES.include?(field.type)
|
|
114
|
+
"tabular-nums"
|
|
115
|
+
else
|
|
116
|
+
""
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
71
120
|
def columns_for(resource_class)
|
|
72
121
|
visible = resource_class.resolved_fields.select { |field| field.visible?(@current_user) }
|
|
73
122
|
names = resource_class.index_field_names
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
%p.mt-1.text-3xl.font-semibold{ class: theme.body_text }
|
|
7
|
-
= value
|
|
8
|
-
- if change
|
|
9
|
-
.flex.items-center.gap-1.mt-2{ class: change_classes }
|
|
10
|
-
- if change_icon
|
|
11
|
-
= heroicon change_icon, variant: :mini, options: { class: "h-4 w-4" }
|
|
12
|
-
%span.text-sm= change
|
|
1
|
+
-# Laid out like MetricCardComponent: the label wraps beside the icon instead of reaching it, and the
|
|
2
|
+
-# value sits on its own full-width row, so a long value never pushes the icon out of a narrow card.
|
|
3
|
+
%div{ class: "#{card_classes} p-5" }
|
|
4
|
+
.flex.items-center.justify-between.gap-3
|
|
5
|
+
%p.min-w-0.break-words{ class: label_classes }= label
|
|
13
6
|
- if icon
|
|
14
|
-
.
|
|
15
|
-
= heroicon icon, variant: :outline, options: { class: "h-
|
|
7
|
+
.flex.h-8.w-8.shrink-0.items-center.justify-center{ class: icon_tile_classes }
|
|
8
|
+
= heroicon icon, variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
|
|
9
|
+
%p.mt-2{ class: theme.metric_value }= value
|
|
10
|
+
- if change
|
|
11
|
+
.mt-1.flex.items-center.gap-1.text-sm.font-medium{ class: change_classes }
|
|
12
|
+
- if change_icon
|
|
13
|
+
= heroicon change_icon, variant: :mini, options: { class: "h-4 w-4" }
|
|
14
|
+
%span.tabular-nums= change
|
|
@@ -14,20 +14,24 @@ module IronAdmin
|
|
|
14
14
|
@columns = columns
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# Four columns start at the xl breakpoint, as in the dashboard's metric grid:
|
|
18
|
+
# from lg the static sidebar leaves the page about 700px, too narrow for four cards.
|
|
19
|
+
#
|
|
17
20
|
# @api private
|
|
18
21
|
# @return [String] Tailwind grid column classes based on columns count
|
|
19
22
|
def grid_classes
|
|
20
23
|
case columns
|
|
21
24
|
when 2 then "grid-cols-1 sm:grid-cols-2"
|
|
22
25
|
when 3 then "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3"
|
|
23
|
-
|
|
24
|
-
else "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4"
|
|
26
|
+
else "grid-cols-1 sm:grid-cols-2 xl:grid-cols-4"
|
|
25
27
|
end
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
# Individual statistic card component.
|
|
29
31
|
# @api private
|
|
30
32
|
class StatComponent < ViewComponent::Base
|
|
33
|
+
include Concerns::ThemedCard
|
|
34
|
+
|
|
31
35
|
# @return [String] Stat label
|
|
32
36
|
attr_reader :label
|
|
33
37
|
|
|
@@ -57,17 +61,11 @@ module IronAdmin
|
|
|
57
61
|
end
|
|
58
62
|
|
|
59
63
|
# @api private
|
|
60
|
-
# @return [
|
|
61
|
-
def theme
|
|
62
|
-
IronAdmin.configuration.theme
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# @api private
|
|
66
|
-
# @return [String] CSS classes for change indicator color
|
|
64
|
+
# @return [String] Color of the change: the theme's success, error or muted text
|
|
67
65
|
def change_classes
|
|
68
66
|
case change_type
|
|
69
|
-
when :positive then
|
|
70
|
-
when :negative then
|
|
67
|
+
when :positive then theme.success_text
|
|
68
|
+
when :negative then theme.error_text
|
|
71
69
|
else theme.muted_text
|
|
72
70
|
end
|
|
73
71
|
end
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
.flex.justify-end.mb-4
|
|
2
2
|
%details.relative.group{ open: has_active_filters? || nil }
|
|
3
3
|
%summary{ class: trigger_classes, style: "list-style: none; -webkit-appearance: none;" }
|
|
4
|
-
= heroicon "funnel", variant: :mini, options: { class: "h-4 w-4 #{theme.
|
|
4
|
+
= heroicon "funnel", variant: :mini, options: { class: "h-4 w-4 #{theme.icon_muted}" }
|
|
5
5
|
%span Filters
|
|
6
6
|
- if has_active_filters?
|
|
7
|
-
%span
|
|
7
|
+
%span{ class: count_classes }
|
|
8
8
|
= active_count
|
|
9
|
-
= heroicon "chevron-down", variant: :mini, options: { class: "h-4 w-4
|
|
9
|
+
= heroicon "chevron-down", variant: :mini, options: { class: "h-4 w-4 #{theme.icon_muted} transition-transform group-open:rotate-180" }
|
|
10
10
|
|
|
11
11
|
%div{ class: dropdown_classes }
|
|
12
12
|
= form_tag form_url, method: :get, class: "p-4" do
|
|
13
13
|
= hidden_field_tag :scope, scope, id: nil
|
|
14
14
|
= hidden_field_tag :q, query, id: nil
|
|
15
|
+
- sort_params.each do |name, value|
|
|
16
|
+
= hidden_field_tag name, value, id: nil
|
|
15
17
|
|
|
16
18
|
.space-y-3
|
|
17
19
|
- filters.each do |filter|
|
|
18
20
|
= filter
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
%button
|
|
22
|
+
%div{ class: footer_classes }
|
|
23
|
+
%button{ type: "submit", class: apply_classes }
|
|
22
24
|
Apply
|
|
23
|
-
= link_to "Clear",
|
|
25
|
+
= link_to "Clear", clear_url, class: clear_classes
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
module IronAdmin
|
|
4
4
|
# Filter components for search and filtering records.
|
|
5
5
|
module Filters
|
|
6
|
-
# Renders the filter bar containing search and filter controls.
|
|
6
|
+
# Renders the filter bar containing search and filter controls. Applying
|
|
7
|
+
# or clearing the filters keeps the scope, search query and sort.
|
|
7
8
|
class BarComponent < ViewComponent::Base
|
|
8
9
|
renders_many :filters
|
|
9
10
|
|
|
@@ -19,21 +20,46 @@ module IronAdmin
|
|
|
19
20
|
# @return [Integer] Number of active filters
|
|
20
21
|
attr_reader :active_count
|
|
21
22
|
|
|
23
|
+
# @return [String, nil] Column the index is sorted by
|
|
24
|
+
attr_reader :current_sort
|
|
25
|
+
|
|
26
|
+
# @return [String, nil] Sort direction ("asc" or "desc")
|
|
27
|
+
attr_reader :current_direction
|
|
28
|
+
|
|
22
29
|
# @param form_url [String] Form submission URL
|
|
23
30
|
# @param scope [String, nil] Current scope
|
|
24
31
|
# @param query [String, nil] Current query
|
|
25
32
|
# @param active_count [Integer] Active filter count
|
|
26
|
-
|
|
33
|
+
# @param current_sort [String, nil] Current sort column, kept when filtering
|
|
34
|
+
# @param current_direction [String, nil] Current sort direction, kept when filtering
|
|
35
|
+
def initialize(form_url:, scope: nil, query: nil, active_count: 0, current_sort: nil, current_direction: nil)
|
|
27
36
|
@form_url = form_url
|
|
28
37
|
@scope = scope
|
|
29
38
|
@query = query
|
|
30
39
|
@active_count = active_count
|
|
40
|
+
@current_sort = current_sort
|
|
41
|
+
@current_direction = current_direction
|
|
31
42
|
end
|
|
32
43
|
|
|
33
44
|
# @api private
|
|
34
|
-
# @return [IronAdmin::Configuration::Theme] Theme
|
|
45
|
+
# @return [IronAdmin::Configuration::Theme] Theme of the current request
|
|
35
46
|
def theme
|
|
36
|
-
IronAdmin.
|
|
47
|
+
IronAdmin.current_theme
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @api private
|
|
51
|
+
# @return [Hash{String => String}] The sort and direction the form keeps, when set
|
|
52
|
+
def sort_params
|
|
53
|
+
{ "sort" => current_sort, "direction" => current_direction }.compact_blank
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @api private
|
|
57
|
+
# @return [String] Index URL without filters, keeping the scope, search query and sort
|
|
58
|
+
def clear_url
|
|
59
|
+
state = { "scope" => scope, "q" => query }.compact_blank.merge(sort_params)
|
|
60
|
+
return form_url if state.empty?
|
|
61
|
+
|
|
62
|
+
"#{form_url}#{form_url.include?("?") ? "&" : "?"}#{state.to_query}"
|
|
37
63
|
end
|
|
38
64
|
|
|
39
65
|
# @api private
|
|
@@ -45,16 +71,37 @@ module IronAdmin
|
|
|
45
71
|
# @api private
|
|
46
72
|
# @return [String] CSS classes for filter dropdown trigger button
|
|
47
73
|
def trigger_classes
|
|
48
|
-
|
|
49
|
-
"#{theme.border_radius} border shadow-sm transition duration-150 " \
|
|
50
|
-
"#{theme.label_text} #{theme.card_border} #{theme.card_bg} py-2.5 hover:bg-gray-50"
|
|
74
|
+
ControlStyles.trigger(theme)
|
|
51
75
|
end
|
|
52
76
|
|
|
53
77
|
# @api private
|
|
54
78
|
# @return [String] CSS classes for filter dropdown panel
|
|
55
79
|
def dropdown_classes
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
ControlStyles.panel(theme)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @api private
|
|
84
|
+
# @return [String] CSS classes of the active filter count
|
|
85
|
+
def count_classes
|
|
86
|
+
ControlStyles.count(theme)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @api private
|
|
90
|
+
# @return [String] CSS classes of the Apply and Clear row
|
|
91
|
+
def footer_classes
|
|
92
|
+
ControlStyles.footer(theme)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# @api private
|
|
96
|
+
# @return [String] CSS classes of the Apply button
|
|
97
|
+
def apply_classes
|
|
98
|
+
ControlStyles.apply_button(theme)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# @api private
|
|
102
|
+
# @return [String] CSS classes of the Clear link
|
|
103
|
+
def clear_classes
|
|
104
|
+
ControlStyles.clear_button(theme)
|
|
58
105
|
end
|
|
59
106
|
end
|
|
60
107
|
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module IronAdmin
|
|
4
|
+
module Filters
|
|
5
|
+
# Classes of the filter controls, shared by the filter components, the index page's
|
|
6
|
+
# built-in filter bar and the audit log filters. Inputs, selects and buttons are the
|
|
7
|
+
# form controls of {IronAdmin::Form::ControlClasses}; colors, borders, radii and
|
|
8
|
+
# shadows come from the theme.
|
|
9
|
+
module ControlStyles
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
13
|
+
# @return [String] Small label of a filter control
|
|
14
|
+
def label(theme)
|
|
15
|
+
"block text-xs font-medium #{theme.label_text} #{theme.label_transform}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
19
|
+
# @return [String] Text, number and date inputs
|
|
20
|
+
def input(theme)
|
|
21
|
+
Form::ControlClasses.input(theme)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
25
|
+
# @return [String] Selects, with the engine's chevron (see engine.css)
|
|
26
|
+
def select(theme)
|
|
27
|
+
Form::ControlClasses.select(theme)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
31
|
+
# @return [String] The search input, with room for the magnifying glass on its left
|
|
32
|
+
def search_input(theme)
|
|
33
|
+
Form::ControlClasses.input(theme, padding: "pl-9 pr-3")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
37
|
+
# @return [String] The +<summary>+ that opens the filter panel, styled as a secondary button
|
|
38
|
+
def trigger(theme)
|
|
39
|
+
"#{Form::ControlClasses.button(theme, :secondary)} select-none [&::-webkit-details-marker]:hidden"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
43
|
+
# @return [String] The floating filter panel
|
|
44
|
+
def panel(theme)
|
|
45
|
+
"absolute right-0 top-full z-20 mt-2 w-72 #{theme.popover_background} #{theme.border_width} " \
|
|
46
|
+
"#{theme.card_border} #{theme.border_radius} #{theme.popover_shadow}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
50
|
+
# @return [String] Number of active filters next to the trigger's label
|
|
51
|
+
def count(theme)
|
|
52
|
+
"inline-flex items-center justify-center h-5 min-w-5 px-1.5 text-xs tabular-nums " \
|
|
53
|
+
"#{theme.badge_shape} #{theme.badge_count}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
57
|
+
# @return [String] Row of the panel's Apply and Clear actions
|
|
58
|
+
def footer(theme)
|
|
59
|
+
"flex items-center gap-3 mt-4 pt-3 border-t #{theme.card_border}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
63
|
+
# @return [String] The Apply button
|
|
64
|
+
def apply_button(theme)
|
|
65
|
+
Form::ControlClasses.button(theme, :primary)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
69
|
+
# @return [String] The Clear link, a secondary button like the audit log's Clear and the
|
|
70
|
+
# forms' Cancel
|
|
71
|
+
def clear_button(theme)
|
|
72
|
+
Form::ControlClasses.button(theme, :secondary)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @param theme [IronAdmin::Configuration::Theme]
|
|
76
|
+
# @return [String] "From" or "To" beside a date range input, which says which end it holds
|
|
77
|
+
def range_marker(theme)
|
|
78
|
+
"w-10 shrink-0 text-xs #{theme.muted_text} #{theme.label_transform}"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
.space-y-1
|
|
2
2
|
%label{ for: from_field_id, class: label_classes }
|
|
3
3
|
= label
|
|
4
|
+
-# The inputs' names say which end each holds; the markers say it on screen.
|
|
4
5
|
.space-y-2
|
|
5
|
-
|
|
6
|
-
"aria-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
.flex.items-center.gap-2
|
|
7
|
+
%span{ "aria-hidden": "true", class: marker_classes }= I18n.t("iron_admin.filters.from")
|
|
8
|
+
= date_field_tag from_field_name, from_value, id: from_field_id, class: input_classes, placeholder: "From",
|
|
9
|
+
"aria-label": I18n.t("iron_admin.filters.from_label", filter: label)
|
|
10
|
+
.flex.items-center.gap-2
|
|
11
|
+
%span{ "aria-hidden": "true", class: marker_classes }= I18n.t("iron_admin.filters.to")
|
|
12
|
+
= date_field_tag to_field_name, to_value, id: to_field_id, class: input_classes, placeholder: "To",
|
|
13
|
+
"aria-label": I18n.t("iron_admin.filters.to_label", filter: label)
|
|
@@ -28,9 +28,9 @@ module IronAdmin
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# @api private
|
|
31
|
-
# @return [IronAdmin::Configuration::Theme] Theme
|
|
31
|
+
# @return [IronAdmin::Configuration::Theme] Theme of the current request
|
|
32
32
|
def theme
|
|
33
|
-
IronAdmin.
|
|
33
|
+
IronAdmin.current_theme
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# @api private
|
|
@@ -60,15 +60,19 @@ module IronAdmin
|
|
|
60
60
|
# @api private
|
|
61
61
|
# @return [String] CSS classes for label elements
|
|
62
62
|
def label_classes
|
|
63
|
-
|
|
63
|
+
ControlStyles.label(theme)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# @api private
|
|
67
67
|
# @return [String] CSS classes for date input fields
|
|
68
68
|
def input_classes
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
ControlStyles.input(theme)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# @api private
|
|
73
|
+
# @return [String] CSS classes of the From and To markers beside the inputs
|
|
74
|
+
def marker_classes
|
|
75
|
+
ControlStyles.range_marker(theme)
|
|
72
76
|
end
|
|
73
77
|
end
|
|
74
78
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
= form_tag form_url, method: :get, class: "flex" do
|
|
1
|
+
= form_tag form_url, method: :get, class: "flex w-full sm:w-auto" do
|
|
2
2
|
- hidden_params.each do |key, val|
|
|
3
3
|
= hidden_field_tag key, val, id: nil
|
|
4
|
-
.relative
|
|
5
|
-
.pointer-events-none.absolute.inset-y-0.left-0.flex.items-center
|
|
6
|
-
= heroicon "magnifying-glass", variant: :mini, options: { class: "h-4 w-4 #{theme.
|
|
4
|
+
.relative.w-full.sm:w-64
|
|
5
|
+
.pointer-events-none.absolute.inset-y-0.left-0.flex.items-center.pl-3
|
|
6
|
+
= heroicon "magnifying-glass", variant: :mini, options: { class: "h-4 w-4 #{theme.icon_muted}" }
|
|
7
7
|
= text_field_tag :q, value, placeholder: placeholder, "aria-label": label, class: input_classes
|
|
@@ -41,17 +41,15 @@ module IronAdmin
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# @api private
|
|
44
|
-
# @return [IronAdmin::Configuration::Theme] Theme
|
|
44
|
+
# @return [IronAdmin::Configuration::Theme] Theme of the current request
|
|
45
45
|
def theme
|
|
46
|
-
IronAdmin.
|
|
46
|
+
IronAdmin.current_theme
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# @api private
|
|
50
50
|
# @return [String] CSS classes for search input field
|
|
51
51
|
def input_classes
|
|
52
|
-
|
|
53
|
-
"transition duration-150 ease-in-out #{theme.border_radius} #{theme.input_border} " \
|
|
54
|
-
"#{theme.navbar_search_bg} #{theme.body_text} #{theme.input_focus} #{theme.navbar_search_focus_bg}"
|
|
52
|
+
ControlStyles.search_input(theme)
|
|
55
53
|
end
|
|
56
54
|
end
|
|
57
55
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
.space-y-1
|
|
2
2
|
%label{ for: field_id, class: label_classes }
|
|
3
3
|
= label
|
|
4
|
-
%select{ name: field_name, id: field_id, class: select_classes
|
|
4
|
+
%select{ name: field_name, id: field_id, class: select_classes }
|
|
5
5
|
%option{ value: "" } All
|
|
6
6
|
- options.each do |option|
|
|
7
7
|
- opt_label, opt_value = option.is_a?(Array) ? option : [option.to_s.humanize, option]
|
|
@@ -28,9 +28,9 @@ module IronAdmin
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# @api private
|
|
31
|
-
# @return [IronAdmin::Configuration::Theme] Theme
|
|
31
|
+
# @return [IronAdmin::Configuration::Theme] Theme of the current request
|
|
32
32
|
def theme
|
|
33
|
-
IronAdmin.
|
|
33
|
+
IronAdmin.current_theme
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# @api private
|
|
@@ -48,24 +48,13 @@ module IronAdmin
|
|
|
48
48
|
# @api private
|
|
49
49
|
# @return [String] CSS classes for label elements
|
|
50
50
|
def label_classes
|
|
51
|
-
|
|
51
|
+
ControlStyles.label(theme)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# @api private
|
|
55
|
-
# @return [String] CSS classes for select element
|
|
55
|
+
# @return [String] CSS classes for select element, chevron included
|
|
56
56
|
def select_classes
|
|
57
|
-
|
|
58
|
-
"transition duration-150 ease-in-out #{theme.border_radius} #{theme.input_border} " \
|
|
59
|
-
"#{theme.card_bg} #{theme.body_text} #{theme.input_focus}"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# @api private
|
|
63
|
-
# @return [String] Inline CSS style for dropdown chevron
|
|
64
|
-
def chevron_style
|
|
65
|
-
"background-image: url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' " \
|
|
66
|
-
"viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' " \
|
|
67
|
-
"stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e\"); background-position: right 0.5rem center; " \
|
|
68
|
-
"background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem;"
|
|
57
|
+
ControlStyles.select(theme)
|
|
69
58
|
end
|
|
70
59
|
end
|
|
71
60
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
-# The script builds the result options, so it takes their theme classes from data attributes.
|
|
2
|
+
.relative{ id: component_id, data: { autocomplete_url: autocomplete_url, item_class: dropdown_item_classes, active_class: theme.item_active, empty_class: empty_item_classes } }
|
|
2
3
|
%input{ type: "hidden", name: name, id: "#{component_id}-hidden", value: selected_id }
|
|
3
4
|
%input{ type: "text",
|
|
4
5
|
id: input_id,
|
|
@@ -21,6 +22,9 @@
|
|
|
21
22
|
const textInput = document.getElementById('#{input_id}');
|
|
22
23
|
const dropdown = document.getElementById('#{listbox_id}');
|
|
23
24
|
const autocompleteUrl = container.dataset.autocompleteUrl;
|
|
25
|
+
const itemClass = container.dataset.itemClass;
|
|
26
|
+
const emptyClass = container.dataset.emptyClass;
|
|
27
|
+
const activeClasses = (container.dataset.activeClass || '').split(/\s+/).filter(Boolean);
|
|
24
28
|
|
|
25
29
|
let debounceTimer = null;
|
|
26
30
|
let selectedIndex = -1;
|
|
@@ -46,7 +50,7 @@
|
|
|
46
50
|
|
|
47
51
|
function createResultItem(item, index) {
|
|
48
52
|
const div = document.createElement('div');
|
|
49
|
-
div.className =
|
|
53
|
+
div.className = itemClass;
|
|
50
54
|
div.id = dropdown.id + '-option-' + index;
|
|
51
55
|
div.setAttribute('role', 'option');
|
|
52
56
|
div.setAttribute('aria-selected', 'false');
|
|
@@ -61,7 +65,7 @@
|
|
|
61
65
|
|
|
62
66
|
function createNoResultsItem() {
|
|
63
67
|
const div = document.createElement('div');
|
|
64
|
-
div.className =
|
|
68
|
+
div.className = emptyClass;
|
|
65
69
|
div.setAttribute('role', 'option');
|
|
66
70
|
div.setAttribute('aria-disabled', 'true');
|
|
67
71
|
div.textContent = 'No results found';
|
|
@@ -100,12 +104,12 @@
|
|
|
100
104
|
const items = dropdown.querySelectorAll('[data-id]');
|
|
101
105
|
items.forEach((el, i) => {
|
|
102
106
|
if (i === index) {
|
|
103
|
-
el.classList.add(
|
|
107
|
+
el.classList.add(...activeClasses);
|
|
104
108
|
el.setAttribute('aria-selected', 'true');
|
|
105
109
|
textInput.setAttribute('aria-activedescendant', el.id);
|
|
106
110
|
el.scrollIntoView({ block: 'nearest' });
|
|
107
111
|
} else {
|
|
108
|
-
el.classList.remove(
|
|
112
|
+
el.classList.remove(...activeClasses);
|
|
109
113
|
el.setAttribute('aria-selected', 'false');
|
|
110
114
|
}
|
|
111
115
|
});
|
|
@@ -74,24 +74,26 @@ module IronAdmin
|
|
|
74
74
|
# @api private
|
|
75
75
|
# @return [String] CSS classes for text input field
|
|
76
76
|
def input_classes
|
|
77
|
-
|
|
78
|
-
"#{theme.border_radius} #{theme.input_border} #{theme.card_bg} #{theme.body_text} #{theme.input_focus}"
|
|
79
|
-
base += " !border-red-400 focus:!border-red-500 focus:!ring-red-500/20" if has_error
|
|
80
|
-
base += " bg-gray-50 cursor-not-allowed" if effectively_disabled?
|
|
81
|
-
base
|
|
77
|
+
ControlClasses.input(theme, error: has_error, muted: effectively_disabled?)
|
|
82
78
|
end
|
|
83
79
|
|
|
84
80
|
# @api private
|
|
85
81
|
# @return [String] CSS classes for autocomplete dropdown panel
|
|
86
82
|
def dropdown_classes
|
|
87
|
-
"absolute z-50 mt-1 w-full max-h-60 overflow-auto #{theme.border_radius} " \
|
|
88
|
-
"#{theme.
|
|
83
|
+
"absolute z-50 mt-1 w-full max-h-60 overflow-auto p-1 #{theme.border_radius} #{theme.border_width} " \
|
|
84
|
+
"#{theme.card_border} #{theme.popover_background} #{theme.popover_shadow}"
|
|
89
85
|
end
|
|
90
86
|
|
|
91
87
|
# @api private
|
|
92
88
|
# @return [String] CSS classes for dropdown list items
|
|
93
89
|
def dropdown_item_classes
|
|
94
|
-
"px-
|
|
90
|
+
"px-2.5 py-1.5 text-sm cursor-pointer #{theme.control_radius} #{theme.body_text} #{theme.item_hover}"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @api private
|
|
94
|
+
# @return [String] CSS classes of the item shown when nothing matches
|
|
95
|
+
def empty_item_classes
|
|
96
|
+
"px-2.5 py-1.5 text-sm #{theme.muted_text}"
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
# @api private
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
%select{ name: name, id: name, class: select_classes, disabled: disabled
|
|
1
|
+
%select{ name: name, id: name, class: select_classes, disabled: disabled }
|
|
2
2
|
- if include_blank
|
|
3
3
|
%option{ value: "" } Select...
|
|
4
4
|
- options.each do |label, value|
|
|
5
5
|
%option{ value: value, selected: selected.to_s == value.to_s }= label
|
|
6
6
|
- if show_search_hint?
|
|
7
|
-
%p.text-xs.
|
|
7
|
+
%p.text-xs.mt-1{ class: theme.muted_text }
|
|
8
8
|
Showing first #{options_limit} options. Use search for more results.
|
|
@@ -76,9 +76,9 @@ module IronAdmin
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
# @api private
|
|
79
|
-
# @return [IronAdmin::Configuration::Theme] Theme
|
|
79
|
+
# @return [IronAdmin::Configuration::Theme] Theme of the current request
|
|
80
80
|
def theme
|
|
81
|
-
IronAdmin.
|
|
81
|
+
IronAdmin.current_theme
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
# @api private
|
|
@@ -124,23 +124,9 @@ module IronAdmin
|
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
# @api private
|
|
127
|
-
# @return [String] CSS classes for select element
|
|
127
|
+
# @return [String] CSS classes for select element, with the engine's chevron
|
|
128
128
|
def select_classes
|
|
129
|
-
|
|
130
|
-
"transition duration-150 ease-in-out #{theme.border_radius} #{theme.input_border} " \
|
|
131
|
-
"#{theme.card_bg} #{theme.body_text} #{theme.input_focus}"
|
|
132
|
-
base += " !border-red-400 focus:!border-red-500 focus:!ring-red-500/20" if has_error
|
|
133
|
-
base += " bg-gray-50 cursor-not-allowed" if disabled
|
|
134
|
-
base
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# @api private
|
|
138
|
-
# @return [String] Inline CSS style for dropdown chevron
|
|
139
|
-
def chevron_style
|
|
140
|
-
"background-image: url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' " \
|
|
141
|
-
"viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' " \
|
|
142
|
-
"stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e\"); background-position: right 0.5rem center; " \
|
|
143
|
-
"background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem;"
|
|
129
|
+
ControlClasses.select(theme, error: has_error, muted: disabled)
|
|
144
130
|
end
|
|
145
131
|
|
|
146
132
|
private
|