Class: Bs5::Progress::BarComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/bs5/progress/bar_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, label: nil, color: nil, striped: false, animated: false) ⇒ BarComponent

Returns a new instance of BarComponent.



8
9
10
11
12
13
14
# File 'app/components/bs5/progress/bar_component.rb', line 8

def initialize(value, label: nil, color: nil, striped: false, animated: false)
  @value = value
  @label = label
  @color = color
  @striped = striped
  @animated = animated
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



6
7
8
# File 'app/components/bs5/progress/bar_component.rb', line 6

def color
  @color
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'app/components/bs5/progress/bar_component.rb', line 6

def value
  @value
end

Instance Method Details

#animated_classObject



47
48
49
50
51
# File 'app/components/bs5/progress/bar_component.rb', line 47

def animated_class
  return unless animated?

  %w[progress-bar-striped progress-bar-animated]
end

#bar_classObject



27
28
29
30
31
32
33
# File 'app/components/bs5/progress/bar_component.rb', line 27

def bar_class
  class_names = %w[progress-bar]
  class_names << contextual_class
  class_names << striped_class
  class_names << animated_class
  class_names.flatten.uniq.join(' ')
end

#contextual_classObject



35
36
37
38
39
# File 'app/components/bs5/progress/bar_component.rb', line 35

def contextual_class
  return unless color?

  "bg-#{color}"
end

#labelObject



16
17
18
19
20
21
22
23
24
25
# File 'app/components/bs5/progress/bar_component.rb', line 16

def label
  return unless @label

  case @label
  when String
    @label
  else
    "#{value}%"
  end
end

#striped_classObject



41
42
43
44
45
# File 'app/components/bs5/progress/bar_component.rb', line 41

def striped_class
  return unless striped?

  'progress-bar-striped'
end