Class: LcpRuby::Display::Renderers::Badge

Inherits:
BaseRenderer show all
Defined in:
lib/lcp_ruby/display/renderers/badge.rb

Constant Summary collapse

NAMED_COLORS =
{
  "green" => "#28a745", "red" => "#dc3545", "blue" => "#007bff",
  "yellow" => "#ffc107", "orange" => "#fd7e14", "purple" => "#6f42c1",
  "gray" => "#6c757d", "teal" => "#20c997", "cyan" => "#17a2b8",
  "pink" => "#e83e8c"
}.freeze

Instance Method Summary collapse

Methods inherited from BaseRenderer

#link_producing?

Instance Method Details

#render(value, options = {}, record: nil, view_context: nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/lcp_ruby/display/renderers/badge.rb', line 12

def render(value, options = {}, record: nil, view_context: nil)
  color_map = options["color_map"] || {}
  color = color_map[value.to_s]
  style = badge_style(color)
  display_text = options["label"] || value
  view_context.(:span, display_text, class: "badge", style: style)
end