Class: Railsboot::ProgressCircularComponent
- Inherits:
-
Component
- Object
- Component
- Railsboot::ProgressCircularComponent
- Defined in:
- app/components/railsboot/progress_circular_component.rb
Overview
ViewComponent: renders the progress circular block.
Instance Method Summary collapse
-
#before_render ⇒ void
protected
Sets the progressbar accessibility attributes on the rendered element.
-
#initialize(value: 0, min: 0, max: 100, label: "", aria_label: nil, color: DEFAULT_COLOR, **html_attributes) ⇒ ProgressCircularComponent
constructor
A new instance of ProgressCircularComponent.
-
#stroke_dasharray ⇒ Float
Computes the SVG stroke dasharray value representing the current progress.
Constructor Details
#initialize(value: 0, min: 0, max: 100, label: "", aria_label: nil, color: DEFAULT_COLOR, **html_attributes) ⇒ ProgressCircularComponent
Returns a new instance of ProgressCircularComponent.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/railsboot/progress_circular_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( { "text-#{@color}" => @color.present? }, html_attributes[:class] ) end |
Instance Method Details
#before_render ⇒ void (protected)
This method returns an undefined value.
Sets the progressbar accessibility attributes on the rendered element.
39 40 41 42 43 44 45 |
# File 'app/components/railsboot/progress_circular_component.rb', line 39 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 |
#stroke_dasharray ⇒ Float
Computes the SVG stroke dasharray value representing the current progress.
31 32 33 |
# File 'app/components/railsboot/progress_circular_component.rb', line 31 def stroke_dasharray ((51.0 / 50) * @value).round(2) end |