Class: IronAdmin::Ui::ScopesComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Ui::ScopesComponent
- Defined in:
- app/components/iron_admin/ui/scopes_component.rb
Overview
Renders scope tabs for filtering resource lists.
Instance Attribute Summary collapse
-
#base_path ⇒ String
readonly
Base URL path.
-
#current_scope ⇒ String?
readonly
Currently active scope name.
-
#params ⇒ Hash
readonly
Additional query params.
-
#scopes ⇒ Array<Hash>
readonly
Scope definitions.
Instance Method Summary collapse
-
#active?(scope) ⇒ Boolean
private
Whether scope is currently active.
-
#initialize(scopes:, current_scope:, base_path:, params: {}) ⇒ ScopesComponent
constructor
A new instance of ScopesComponent.
-
#render? ⇒ Boolean
private
Whether to render the component.
-
#scope_classes(scope) ⇒ String
private
CSS classes for scope tab.
-
#scope_url(scope_name) ⇒ String
private
URL with scope parameter.
-
#theme ⇒ IronAdmin::Configuration::Theme
private
Theme configuration.
Constructor Details
#initialize(scopes:, current_scope:, base_path:, params: {}) ⇒ ScopesComponent
Returns a new instance of ScopesComponent.
30 31 32 33 34 35 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 30 def initialize(scopes:, current_scope:, base_path:, params: {}) @scopes = scopes @current_scope = current_scope @base_path = base_path @params = params end |
Instance Attribute Details
#base_path ⇒ String (readonly)
Returns Base URL path.
21 22 23 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 21 def base_path @base_path end |
#current_scope ⇒ String? (readonly)
Returns Currently active scope name.
18 19 20 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 18 def current_scope @current_scope end |
#params ⇒ Hash (readonly)
Returns Additional query params.
24 25 26 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 24 def params @params end |
#scopes ⇒ Array<Hash> (readonly)
Returns Scope definitions.
15 16 17 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 15 def scopes @scopes end |
Instance Method Details
#active?(scope) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Whether scope is currently active.
53 54 55 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 53 def active?(scope) current_scope == scope[:name].to_s end |
#render? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Whether to render the component.
71 72 73 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 71 def render? scopes.any? end |
#scope_classes(scope) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS classes for scope tab.
60 61 62 63 64 65 66 67 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 60 def scope_classes(scope) base = "px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors duration-150" if active?(scope) "#{base} #{theme.scope_active}" else "#{base} #{theme.scope_inactive}" end end |
#scope_url(scope_name) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns URL with scope parameter.
46 47 48 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 46 def scope_url(scope_name) "#{base_path}?#{params.merge(scope: scope_name).to_query}" end |
#theme ⇒ IronAdmin::Configuration::Theme
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Theme configuration.
39 40 41 |
# File 'app/components/iron_admin/ui/scopes_component.rb', line 39 def theme IronAdmin.configuration.theme end |