Class: IronAdmin::Dashboards::StatsGridComponent::StatComponent Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Individual statistic card component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, value:, change: nil, change_type: :neutral, icon: nil) ⇒ StatComponent

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 a new instance of StatComponent.

Parameters:

  • label (String)

    Stat label

  • value (Numeric, String)

    Stat value

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

    Change amount text

  • change_type (Symbol) (defaults to: :neutral)

    Change type (default: :neutral)

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

    Optional Heroicon name



51
52
53
54
55
56
57
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 51

def initialize(label:, value:, change: nil, change_type: :neutral, icon: nil)
  @label = label
  @value = value
  @change = change
  @change_type = change_type.to_sym
  @icon = icon
end

Instance Attribute Details

#changeString? (readonly)

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 Change amount text.

Returns:

  • (String, nil)

    Change amount text



38
39
40
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 38

def change
  @change
end

#change_typeSymbol (readonly)

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 Change type (:positive, :negative, :neutral).

Returns:

  • (Symbol)

    Change type (:positive, :negative, :neutral)



41
42
43
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 41

def change_type
  @change_type
end

#iconString? (readonly)

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 Optional icon name.

Returns:

  • (String, nil)

    Optional icon name



44
45
46
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 44

def icon
  @icon
end

#labelString (readonly)

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

Returns:

  • (String)

    Stat label



32
33
34
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 32

def label
  @label
end

#valueNumeric, String (readonly)

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 Stat value.

Returns:

  • (Numeric, String)

    Stat value



35
36
37
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 35

def value
  @value
end

Instance Method Details

#change_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 change indicator color.

Returns:

  • (String)

    CSS classes for change indicator color



67
68
69
70
71
72
73
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 67

def change_classes
  case change_type
  when :positive then "text-green-600"
  when :negative then "text-red-600"
  else theme.muted_text
  end
end

#change_iconString?

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 Heroicon name for change direction.

Returns:

  • (String, nil)

    Heroicon name for change direction



77
78
79
80
81
82
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 77

def change_icon
  case change_type
  when :positive then "arrow-trending-up"
  when :negative then "arrow-trending-down"
  end
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:



61
62
63
# File 'app/components/iron_admin/dashboards/stats_grid_component.rb', line 61

def theme
  IronAdmin.configuration.theme
end