Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
1.6 KB
Raw Blame
class Goals::StatusPillComponent < ApplicationComponent
  # Maps the goal's display_status to the DS::Pill primitive's tone +
  # glyph. Outline style is used so the pill keeps its colored border on
  # any card background (resting bg-container, hover bg-surface-hover);
  # the filled / soft variants blended into the hover state and lost
  # contrast on cards.
  VARIANTS = {
    on_track:       { tone: :green, icon: "circle-check" },
    behind:         { tone: :amber, icon: "triangle-alert" },
    reached:        { tone: :green, icon: "star" },
    completed:      { tone: :green, icon: "circle-check-big" },
    no_target_date: { tone: :gray,  icon: "infinity" },
    # No measurable pace: neither on track nor behind, so neutral, with a
    # question mark rather than the open-ended goal's infinity.
    pace_unknown:   { tone: :gray,  icon: "circle-help" },
    # A reserve at its floor is steady, not celebratory: green, but a shield
    # rather than the star a one-off gets for finishing. Below its floor it
    # reads like `behind` — something to top back up.
    funded:         { tone: :green, icon: "shield-check" },
    depleted:       { tone: :amber, icon: "shield-alert" },
    paused:         { tone: :gray,  icon: "pause" },
    archived:       { tone: :gray,  icon: "archive" }
  }.freeze

  def initialize(goal:)
    @goal = goal
  end

  def status_key
    @goal.display_status
  end

  def variant
    VARIANTS.fetch(status_key, VARIANTS[:no_target_date])
  end

  def label
    I18n.t("goals.status.#{status_key}", default: status_key.to_s.titleize)
  end
end