Class: BetterUi::General::Progress::Component

Inherits:
ViewComponent::Base
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(value: 0, theme: :white, size: :medium, label: false, classes: nil, **html_options) ⇒ Component

Returns a new instance of Component.

Parameters:

  • value (Integer) (defaults to: 0)

    percentuale di completamento (0-100)

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

    :default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet

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

    :small, :medium, :large

  • label (Boolean) (defaults to: false)

    mostra etichetta con percentuale

  • classes (String) (defaults to: nil)

    classi CSS aggiuntive per il container

  • html_options (Hash)

    opzioni HTML per il container



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,
  **html_options
)
  @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 = html_options

  validate_params
end

Instance Attribute Details

#valueObject (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_attributesObject

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 bar_attributes
  {
    class: bar_classes,
    style: "width: #{@value}%"
  }
end

#bar_classesObject

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 bar_classes
  [
    PROGRESS_BAR_BASE_CLASSES,
    get_theme_class
  ].compact.join(" ")
end

#combined_classesObject

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_attributesObject

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

Returns:

  • (Boolean)


118
119
120
# File 'app/components/better_ui/general/progress/component.rb', line 118

def show_label?
  @label
end