Class: Railsboot::RatingGroupComponent::FillIconComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/rating_group_component.rb

Overview

ViewComponent: renders the fill icon block.

Instance Method Summary collapse

Constructor Details

#initialize(amount:, value:, fill_color:, gap:, **html_attributes) ⇒ FillIconComponent

Returns a new instance of FillIconComponent.

Parameters:

  • amount (Integer)

    number of fill icons rendered

  • value (Numeric)

    fill percentage of the rating (0-100)

  • fill_color (String)

    Bootstrap color for the fill icons

  • gap (Integer)

    Bootstrap gap size between icons

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes

  • :style (String)

    inline styles, merged with the width style computed from the value



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/components/railsboot/rating_group_component.rb', line 55

def initialize(amount:, value:, fill_color:, gap:, **html_attributes)
  @amount = amount
  @value = value
  @fill_color = fill_color
  @gap = gap
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "position-absolute top-0 bottom-0 start-0 d-inline-flex text-#{@fill_color} overflow-hidden gap-#{@gap}",
    html_attributes.delete(:class)
  )
  @html_attributes[:style] = [html_attributes[:style], "width: #{@value}%;"].compact.join(" ")
end