Class: Solidstats::BaseComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/solidstats/base_component.rb

Overview

Base component class for all Solidstats ViewComponents Provides common functionality and conventions for the component system

Instance Method Summary collapse

Instance Method Details

#css_classes(*classes) ⇒ Object

CSS class helper for dynamic classes



77
78
79
# File 'app/components/solidstats/base_component.rb', line 77

def css_classes(*classes)
  classes.compact.reject(&:empty?).join(" ")
end

#format_number(number) ⇒ Object

Helper for formatting numbers with delimiters



58
59
60
61
62
63
64
65
66
67
# File 'app/components/solidstats/base_component.rb', line 58

def format_number(number)
  return "0" if number.nil?

  case number
  when Numeric
    number_with_delimiter(number)
  else
    number.to_s
  end
end

#safe_get(data, key, fallback = nil) ⇒ Object

Helper for safe data access with fallbacks



70
71
72
73
74
# File 'app/components/solidstats/base_component.rb', line 70

def safe_get(data, key, fallback = nil)
  return fallback if data.nil?

  data.is_a?(Hash) ? data[key] || data[key.to_s] || fallback : fallback
end

#status_class(status) ⇒ Object

Standard status classes for consistent styling



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/solidstats/base_component.rb', line 10

def status_class(status)
  case status&.to_sym
  when :good, :ok
    "status-good"
  when :warning
    "status-warning"
  when :critical, :danger
    "status-critical"
  when :info
    "status-info"
  else
    "status-unknown"
  end
end

#status_icon(status) ⇒ Object

Standard status icons



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/components/solidstats/base_component.rb', line 26

def status_icon(status)
  case status&.to_sym
  when :good, :ok
    "✅"
  when :warning
    "⚠️"
  when :critical, :danger
    "❌"
  when :info
    "ℹ️"
  else
    "❓"
  end
end

#status_text(status) ⇒ Object

Standard status text



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/solidstats/base_component.rb', line 42

def status_text(status)
  case status&.to_sym
  when :good, :ok
    "Good"
  when :warning
    "Warning"
  when :critical, :danger
    "Critical"
  when :info
    "Info"
  else
    "Unknown"
  end
end