Class: BetterUi::General::Progress::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Progress::Component
- Defined in:
- app/components/better_ui/general/progress/component.rb
Constant Summary collapse
- PROGRESS_BASE_CLASSES =
Classi base sempre presenti
"relative w-full bg-gray-200 rounded-full overflow-hidden"- PROGRESS_BAR_BASE_CLASSES =
Classi per la barra di progresso
"h-full transition-all duration-300 ease-in-out"- PROGRESS_SIZES =
Dimensioni della progress bar con classi Tailwind dirette
{ small: "h-2", medium: "h-4", large: "h-6" }
- PROGRESS_THEMES =
Temi di progress bar con classi Tailwind dirette
{ default: "bg-gray-600", white: "bg-white border border-gray-300", red: "bg-red-600", rose: "bg-rose-600", orange: "bg-orange-600", green: "bg-green-600", blue: "bg-blue-600", yellow: "bg-yellow-600", violet: "bg-violet-600" }
- PROGRESS_CONTAINER_THEMES =
Classi per il background container
{ default: "bg-gray-200", white: "bg-gray-100", red: "bg-red-100", rose: "bg-rose-100", orange: "bg-orange-100", green: "bg-green-100", blue: "bg-blue-100", yellow: "bg-yellow-100", violet: "bg-violet-100" }
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Restituisce il valore percentuale.
Instance Method Summary collapse
-
#bar_attributes ⇒ Object
Restituisce gli attributi per la barra di progresso.
-
#bar_classes ⇒ Object
Combina tutte le classi per la barra di progresso.
-
#combined_classes ⇒ Object
Combina tutte le classi per il container.
-
#initialize(value: 0, theme: :white, size: :medium, label: false, classes: nil, **html_options) ⇒ Component
constructor
A new instance of Component.
-
#progress_attributes ⇒ Object
Restituisce gli attributi per il container della progress bar.
-
#show_label? ⇒ Boolean
Verifica se mostrare l’etichetta.
Constructor Details
#initialize(value: 0, theme: :white, size: :medium, label: false, classes: nil, **html_options) ⇒ Component
Returns a new instance of Component.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/components/better_ui/general/progress/component.rb', line 50 def initialize( value: 0, theme: :white, size: :medium, label: false, classes: nil, ** ) @value = [0, [value.to_i, 100].min].max # Clamp tra 0 e 100 @theme = theme.to_sym @size = size.to_sym @label = label @classes = classes @html_options = validate_params end |
Instance Attribute Details
#value ⇒ Object (readonly)
Restituisce il valore percentuale
115 116 117 |
# File 'app/components/better_ui/general/progress/component.rb', line 115 def value @value end |
Instance Method Details
#bar_attributes ⇒ Object
Restituisce gli attributi per la barra di progresso
107 108 109 110 111 112 |
# File 'app/components/better_ui/general/progress/component.rb', line 107 def { class: , style: "width: #{@value}%" } end |
#bar_classes ⇒ Object
Combina tutte le classi per la barra di progresso
80 81 82 83 84 85 |
# File 'app/components/better_ui/general/progress/component.rb', line 80 def [ PROGRESS_BAR_BASE_CLASSES, get_theme_class ].compact.join(" ") end |
#combined_classes ⇒ Object
Combina tutte le classi per il container
69 70 71 72 73 74 75 76 77 |
# File 'app/components/better_ui/general/progress/component.rb', line 69 def combined_classes [ PROGRESS_BASE_CLASSES, get_size_class, get_container_theme_class, @classes, @html_options[:class] ].compact.join(" ") end |
#progress_attributes ⇒ Object
Restituisce gli attributi per il container della progress bar
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/components/better_ui/general/progress/component.rb', line 88 def progress_attributes attrs = { class: combined_classes, role: "progressbar", "aria-valuenow": @value, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": "Progresso: #{@value}%" } # Aggiungi altri attributi HTML se presenti @html_options.except(:class).each do |key, value| attrs[key] = value end attrs end |
#show_label? ⇒ Boolean
Verifica se mostrare l’etichetta
118 119 120 |
# File 'app/components/better_ui/general/progress/component.rb', line 118 def show_label? @label end |