Class: Railsboot::ProgressComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/progress_component.rb

Overview

ViewComponent: renders the progress block.

Instance Method Summary collapse

Constructor Details

#initialize(value: 0, min: 0, max: 100, label: "", aria_label: nil, color: DEFAULT_COLOR, **html_attributes) ⇒ ProgressComponent

Returns a new instance of ProgressComponent.

Parameters:

  • value (Integer) (defaults to: 0)

    the value option

  • min (Integer) (defaults to: 0)

    the min option

  • max (Integer) (defaults to: 100)

    the max option

  • label (String) (defaults to: "")

    the label option

  • aria_label (Object, nil) (defaults to: nil)

    the aria label option

  • color (String) (defaults to: DEFAULT_COLOR)

    the color option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes

  • :tag (String)

    HTML tag to render for the element



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/railsboot/progress_component.rb', line 13

def initialize(value: 0, min: 0, max: 100, label: "", aria_label: nil, color: DEFAULT_COLOR, **html_attributes)
  @value = value
  @min = min
  @max = max
  @label = label
  @aria_label = aria_label
  @color = fetch_or_raise(color, COLORS)
  @html_attributes = html_attributes

  @html_attributes[:tag] = "div"
  @html_attributes[:class] = class_names(
    "progress",
    html_attributes.delete(:class)
  )
end

Instance Method Details

#before_rendervoid (protected)

This method returns an undefined value.

Sets ARIA progressbar attributes on the rendered element before render.



42
43
44
45
46
47
48
# File 'app/components/railsboot/progress_component.rb', line 42

def before_render
  @html_attributes["role"] = "progressbar"
  @html_attributes["aria-valuenow"] = @value
  @html_attributes["aria-valuemin"] = @min
  @html_attributes["aria-valuemax"] = @max
  @html_attributes["aria-label"] = @aria_label if @aria_label.present?
end

#inner_classesString

Computes the CSS classes for the inner progress bar element.

Returns:

  • (String)

    the combined class string, including the color variant when set



31
32
33
34
35
36
# File 'app/components/railsboot/progress_component.rb', line 31

def inner_classes
  class_names(
    "progress-bar",
    { "bg-#{@color}" => @color.present? }
  )
end