Class: IronAdmin::Filters::DateRangeComponent

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

Overview

Renders a date range filter with from/to inputs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, label: nil, from_value: nil, to_value: nil) ⇒ DateRangeComponent

Returns a new instance of DateRangeComponent.

Parameters:

  • name (Symbol)

    Filter name

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

    Label text

  • from_value (Date, nil) (defaults to: nil)

    Start date

  • to_value (Date, nil) (defaults to: nil)

    End date



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

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

Instance Attribute Details

#from_valueDate? (readonly)

Returns Start date value.

Returns:

  • (Date, nil)

    Start date value



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

def from_value
  @from_value
end

#labelString (readonly)

Returns Filter label.

Returns:

  • (String)

    Filter label



11
12
13
# File 'app/components/iron_admin/filters/date_range_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/date_range_component.rb', line 8

def name
  @name
end

#to_valueDate? (readonly)

Returns End date value.

Returns:

  • (Date, nil)

    End date value



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

def to_value
  @to_value
end

Instance Method Details

#from_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 for start date.

Returns:

  • (String)

    Form field name for start date



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

def from_field_name
  "filters[#{name}_from]"
end

#input_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 date input fields.

Returns:

  • (String)

    CSS classes for date input fields



56
57
58
59
60
# File 'app/components/iron_admin/filters/date_range_component.rb', line 56

def input_classes
  "block w-full 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

#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



50
51
52
# File 'app/components/iron_admin/filters/date_range_component.rb', line 50

def label_classes
  "block text-xs font-semibold uppercase tracking-wider #{theme.muted_text}"
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/date_range_component.rb', line 32

def theme
  IronAdmin.configuration.theme
end

#to_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 for end date.

Returns:

  • (String)

    Form field name for end date



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

def to_field_name
  "filters[#{name}_to]"
end