Class: IronAdmin::Filters::SelectFilterComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/iron_admin/filters/select_filter_component.rb

Overview

Renders a select dropdown filter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options:, label: nil, selected: nil) ⇒ SelectFilterComponent

Returns a new instance of SelectFilterComponent.

Parameters:

  • name (Symbol)

    Filter name

  • options (Array)

    Available options

  • label (String, nil) (defaults to: nil)

    Label text

  • selected (String, nil) (defaults to: nil)

    Selected value



23
24
25
26
27
28
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 23

def initialize(name:, options:, label: nil, selected: nil)
  @name = name
  @label = label || name.to_s.humanize
  @options = options
  @selected = selected
end

Instance Attribute Details

#labelString (readonly)

Returns Filter label.

Returns:

  • (String)

    Filter label



11
12
13
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 11

def label
  @label
end

#nameSymbol (readonly)

Returns Filter name.

Returns:

  • (Symbol)

    Filter name



8
9
10
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 8

def name
  @name
end

#optionsArray (readonly)

Returns Available options.

Returns:

  • (Array)

    Available options



14
15
16
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 14

def options
  @options
end

#selectedString? (readonly)

Returns Currently selected value.

Returns:

  • (String, nil)

    Currently selected value



17
18
19
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 17

def selected
  @selected
end

Instance Method Details

#chevron_styleString

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 Inline CSS style for dropdown chevron.

Returns:

  • (String)

    Inline CSS style for dropdown chevron



58
59
60
61
62
63
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 58

def 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;"
end

#field_nameString

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 Form field name.

Returns:

  • (String)

    Form field name



38
39
40
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 38

def field_name
  "filters[#{name}]"
end

#label_classesString

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 label elements.

Returns:

  • (String)

    CSS classes for label elements



44
45
46
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 44

def label_classes
  "block text-xs font-semibold uppercase tracking-wider #{theme.muted_text}"
end

#select_classesString

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 select element.

Returns:

  • (String)

    CSS classes for select element



50
51
52
53
54
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 50

def select_classes
  "block w-full appearance-none border px-3 py-2 text-sm shadow-sm outline-none " \
    "transition duration-150 ease-in-out #{theme.border_radius} #{theme.input_border} " \
    "#{theme.card_bg} #{theme.body_text} #{theme.input_focus}"
end

#themeIronAdmin::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.

Returns:



32
33
34
# File 'app/components/iron_admin/filters/select_filter_component.rb', line 32

def theme
  IronAdmin.configuration.theme
end