Class: PhlexKit::Stars
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Stars
- Defined in:
- app/components/phlex_kit/stars/stars.rb
Overview
Star rating (CUSTOM — ruby_ui has no rating component). Replaces the stars
view helper: renders rating filled stars + the remainder empty, out of
max. Presentational; attrs pass through via mix. Self-colours (amber) so it
works anywhere, not just inside a review.
Instance Method Summary collapse
-
#initialize(rating:, max: 5, **attrs) ⇒ Stars
constructor
A new instance of Stars.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(rating:, max: 5, **attrs) ⇒ Stars
Returns a new instance of Stars.
7 8 9 10 11 |
# File 'app/components/phlex_kit/stars/stars.rb', line 7 def initialize(rating:, max: 5, **attrs) @rating = .to_i.clamp(0, max) @max = max @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
13 14 15 16 17 |
# File 'app/components/phlex_kit/stars/stars.rb', line 13 def view_template span(**mix({ class: "pk-stars", title: "#{@rating}/#{@max}" }, @attrs)) do plain(("★" * @rating) + ("☆" * (@max - @rating))) end end |