Class: Railsboot::RatingGroupComponent

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

Overview

ViewComponent: renders the rating group block.

Defined Under Namespace

Classes: BackgroundIconComponent, FillIconComponent

Constant Summary collapse

DEFAULT_AMOUNT =

Default amount.

5

Instance Method Summary collapse

Constructor Details

#initialize(amount: DEFAULT_AMOUNT, value: 0, background_color: "black", fill_color: "primary", gap: 0, **html_attributes) ⇒ RatingGroupComponent

Returns a new instance of RatingGroupComponent.

Parameters:

  • amount (Integer) (defaults to: DEFAULT_AMOUNT)

    number of icons rendered in the group

  • value (Numeric) (defaults to: 0)

    fill percentage of the rating (0-100)

  • background_color (String) (defaults to: "black")

    Bootstrap color for the background icons

  • fill_color (String) (defaults to: "primary")

    Bootstrap color for the fill icons

  • gap (Integer) (defaults to: 0)

    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



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/railsboot/rating_group_component.rb', line 17

def initialize(amount: DEFAULT_AMOUNT, value: 0, background_color: "black", fill_color: "primary", gap: 0, **html_attributes)
  @amount = amount
  @value = value
  @background_color = background_color
  @fill_color = fill_color
  @gap = gap
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "position-relative d-inline-flex text-#{@background_color} gap-#{@gap}",
    html_attributes[:class]
  )
end

Instance Method Details

#render?Boolean

Only renders when both the background and fill icon slots have content.

Returns:

  • (Boolean)

    whether the component should render



33
34
35
# File 'app/components/railsboot/rating_group_component.rb', line 33

def render?
  [background_icon, fill_icon].all?(&:present?)
end