Class: RatingComponent

Inherits:
Component show all
Defined in:
app/components/rating_component.rb

Overview

Rating — star/heart rating widget.

Usage:

Rating(max_rating: 5, rating: 3)
Rating(max_rating: 5, rating: 4, icon: :heart, size: :large)
Rating(max_rating: 10, disabled: true, rating: 7)

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/rating_component.rb', line 19

def to_s
  classes = class_names(
    "ui",
    icon,
    size,
    { "disabled" => disabled },
    "rating"
  )

  data = {
    controller: "fui-rating",
    fui_rating_max_rating_value: max_rating,
    fui_rating_initial_rating_value: rating
  }
  data[:fui_rating_clearable_value] = "true" if clearable

  name_el = name ? tag.input(type: "hidden", name: name, value: rating) : nil

  tag.div(class: classes, data: data) {
    safe_join([ name_el, @content ])
  }
end