Class: BetterUi::General::Input::Rating::Component

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/input/rating/component.rb

Constant Summary collapse

RATING_THEME =

Costanti con classi Tailwind dirette

{
  default: 'text-yellow-400',
  yellow: 'text-yellow-400',
  orange: 'text-orange-400',
  red: 'text-red-400',
  pink: 'text-pink-400',
  purple: 'text-purple-400',
  blue: 'text-blue-400',
  green: 'text-green-400',
  gray: 'text-gray-400'
}.freeze
RATING_SIZE =
{
  small: 'text-sm',
  medium: 'text-xl',
  large: 'text-3xl'
}.freeze
RATING_EMPTY_COLOR =
'text-gray-300'.freeze
RATING_HALF_COLOR =
'text-yellow-300'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, value: 0, max_stars: 5, readonly: false, half_stars: true, theme: :default, size: :medium, show_value: false, form: nil, classes: '', **options) ⇒ Component

Returns a new instance of Component.

Parameters:

  • name (String) (defaults to: nil)

    Nome del campo rating (obbligatorio se non readonly)

  • value (Float, Integer) (defaults to: 0)

    Valore del rating attuale (0.0 - max_stars)

  • max_stars (Integer) (defaults to: 5)

    Numero massimo di stelle (default: 5)

  • readonly (Boolean) (defaults to: false)

    Se il rating è in sola lettura

  • half_stars (Boolean) (defaults to: true)

    Se supportare mezze stelle

  • theme (Symbol) (defaults to: :default)

    Tema del componente (:default, :yellow, :orange, :red, :pink, :purple, :blue, :green, :gray)

  • size (Symbol) (defaults to: :medium)

    Dimensione del componente (:small, :medium, :large)

  • show_value (Boolean) (defaults to: false)

    Se mostrare il valore numerico accanto alle stelle

  • form (ActionView::Helpers::FormBuilder, nil) (defaults to: nil)

    Form builder Rails opzionale

  • classes (String) (defaults to: '')

    Classi CSS aggiuntive

  • options (Hash)

    Opzioni aggiuntive per attributi HTML



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/components/better_ui/general/input/rating/component.rb', line 44

def initialize(name: nil, value: 0, max_stars: 5, readonly: false, half_stars: true,
               theme: :default, size: :medium, show_value: false, form: nil,
               classes: '', **options)
  @name = name
  @value = value.to_f
  @max_stars = max_stars.to_i
  @readonly = readonly
  @half_stars = half_stars
  @theme = theme.to_sym
  @size = size.to_sym
  @show_value = show_value
  @form = form
  @classes = classes
  @options = options

  validate_params
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def classes
  @classes
end

#formObject (readonly)

Returns the value of attribute form.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def form
  @form
end

#half_starsObject (readonly)

Returns the value of attribute half_stars.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def half_stars
  @half_stars
end

#max_starsObject (readonly)

Returns the value of attribute max_stars.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def max_stars
  @max_stars
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def options
  @options
end

#readonlyObject (readonly)

Returns the value of attribute readonly.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def readonly
  @readonly
end

#show_valueObject (readonly)

Returns the value of attribute show_value.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def show_value
  @show_value
end

#sizeObject (readonly)

Returns the value of attribute size.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def size
  @size
end

#themeObject (readonly)

Returns the value of attribute theme.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def theme
  @theme
end

#valueObject (readonly)

Returns the value of attribute value.



30
31
32
# File 'app/components/better_ui/general/input/rating/component.rb', line 30

def value
  @value
end