Module: Tramway::ColorsMethods

Included in:
BadgeComponent, ButtonComponent, FlashComponent, Form::Builder
Defined in:
app/components/tramway/colors_methods.rb

Overview

Color logic implementation

Constant Summary collapse

TYPE_COLOR_MAP =
{
  default: :gray,
  life: :gray,
  primary: :blue,
  hope: :blue,
  secondary: :zinc,
  success: :green,
  will: :green,
  warning: :orange,
  greed: :orange,
  danger: :red,
  rage: :red,
  love: :violet,
  compassion: :indigo,
  compassio: :indigo,
  fear: :yellow,
  submit: :green
}.freeze

Instance Method Summary collapse

Instance Method Details

#normalized_typeObject



33
34
35
36
37
38
39
40
41
# File 'app/components/tramway/colors_methods.rb', line 33

def normalized_type
  value = type
  value = nil if value.respond_to?(:empty?) && value.empty?
  value ||= :default
  value = value.downcase if value.respond_to?(:downcase)
  value = value.to_sym if value.respond_to?(:to_sym)

  TYPE_COLOR_MAP.key?(value) ? value : :default
end

#resolved_colorObject



25
26
27
# File 'app/components/tramway/colors_methods.rb', line 25

def resolved_color
  (color || type_color).to_s
end

#type_colorObject



29
30
31
# File 'app/components/tramway/colors_methods.rb', line 29

def type_color
  TYPE_COLOR_MAP.fetch(normalized_type, TYPE_COLOR_MAP[:default]).to_sym
end