Class: Crm::StatsCardComponent

Inherits:
Railsboot::CardComponent
  • Object
show all
Defined in:
app/components/crm/stats_card_component.rb

Overview

ViewComponent: renders the stats card block.

Instance Method Summary collapse

Constructor Details

#initialize(title:, count:, percentage: nil, without_count: nil, without_url: nil, without_label: 'without', progress_stat: nil, turbo: true) ⇒ StatsCardComponent

Returns a new instance of StatsCardComponent.

Parameters:

  • title (String)

    heading shown in the card header.

  • count (String, Integer)

    main statistic shown in the card body.

  • percentage (Numeric, nil) (defaults to: nil)

    completion percentage; drives the
    progress bar and its color. Defaults to nil (no percentage).

  • without_count (Integer, nil) (defaults to: nil)

    count of records excluded from the
    statistic; when present, renders the card footer. Defaults to nil.

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

    URL the footer link points to. Defaults
    to nil (no link rendered).

  • without_label (String) (defaults to: 'without')

    label appended to the without_count in
    the footer link. Defaults to 'without'.

  • progress_stat (Boolean, nil) (defaults to: nil)

    whether to render the percentage and
    progress bar; when nil, inferred from percentage.present?.
    Defaults to nil.

  • turbo (Boolean) (defaults to: true)

    whether the footer link requests a Turbo Stream
    response. Defaults to true.



21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/crm/stats_card_component.rb', line 21

def initialize(title:, count:, percentage: nil, without_count: nil, without_url: nil, without_label: 'without', progress_stat: nil, turbo: true, **)
  @title = title
  @count = count
  @percentage = percentage
  @without_count = without_count
  @without_url = without_url
  @without_label = without_label
  @progress_stat = progress_stat.nil? ? percentage.present? : progress_stat
  @turbo = turbo
  super(**)
end