Class: Flowbite::Rating::Star

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/rating/star.rb

Overview

Renders a single star of a rating.

Constant Summary collapse

SIZES =
{
  default: ["w-5", "h-5"],
  md: ["w-6", "h-6"],
  lg: ["w-7", "h-7"]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filled: true, size: :default) ⇒ Star

Returns a new instance of Star.



41
42
43
44
# File 'app/components/flowbite/rating/star.rb', line 41

def initialize(filled: true, size: :default)
  @filled = filled
  @size = size
end

Instance Attribute Details

#size ⇒ Object (readonly)

Returns the value of attribute size.



39
40
41
# File 'app/components/flowbite/rating/star.rb', line 39

def size
  @size
end

Class Method Details

.classes(size: :default, state: :filled, style: :default) ⇒ Object



19
20
21
# File 'app/components/flowbite/rating/star.rb', line 19

def classes(size: :default, state: :filled, style: :default)
  sizes.fetch(size) + styles.fetch(style).fetch(state)
end

.sizes ⇒ Object



23
24
25
# File 'app/components/flowbite/rating/star.rb', line 23

def sizes
  SIZES
end

.styles ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/components/flowbite/rating/star.rb', line 27

def styles
  Flowbite::Styles.from_hash(
    {
      default: {
        empty: ["text-fg-disabled"],
        filled: ["text-fg-yellow"]
      }
    }.freeze
  )
end

Instance Method Details

#classes ⇒ Object



46
47
48
# File 'app/components/flowbite/rating/star.rb', line 46

def classes
  self.class.classes(size: size, state: state)
end

#filled? ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/components/flowbite/rating/star.rb', line 50

def filled?
  !!@filled
end

#state ⇒ Object



54
55
56
# File 'app/components/flowbite/rating/star.rb', line 54

def state
  filled? ? :filled : :empty
end