Class: LightningUiKit::ProgressComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- LightningUiKit::ProgressComponent
- Defined in:
- app/components/lightning_ui_kit/progress_component.rb
Instance Method Summary collapse
- #aria_attributes ⇒ Object
- #classes ⇒ Object
- #data ⇒ Object
- #indicator_style ⇒ Object
-
#initialize(value: 0, max: 100, **options) ⇒ ProgressComponent
constructor
A new instance of ProgressComponent.
- #percent ⇒ Object
Constructor Details
#initialize(value: 0, max: 100, **options) ⇒ ProgressComponent
Returns a new instance of ProgressComponent.
2 3 4 5 6 |
# File 'app/components/lightning_ui_kit/progress_component.rb', line 2 def initialize(value: 0, max: 100, **) @value = value.to_f @max = max.to_f @options = end |
Instance Method Details
#aria_attributes ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/components/lightning_ui_kit/progress_component.rb', line 27 def aria_attributes { role: "progressbar", "aria-valuemin": 0, "aria-valuemax": @max.to_i, "aria-valuenow": @value.to_i } end |
#classes ⇒ Object
14 15 16 17 18 19 |
# File 'app/components/lightning_ui_kit/progress_component.rb', line 14 def classes merge_classes([ "lui:relative lui:h-2 lui:w-full lui:overflow-hidden lui:rounded-full lui:bg-surface-tertiary", @options[:class] ].compact.join(" ")) end |
#data ⇒ Object
36 37 38 |
# File 'app/components/lightning_ui_kit/progress_component.rb', line 36 def data @options[:data] || {} end |
#indicator_style ⇒ Object
21 22 23 24 25 |
# File 'app/components/lightning_ui_kit/progress_component.rb', line 21 def indicator_style value = percent formatted = (value % 1).zero? ? value.to_i : value.round(2) "width: #{formatted}%;" end |
#percent ⇒ Object
8 9 10 11 12 |
# File 'app/components/lightning_ui_kit/progress_component.rb', line 8 def percent return 0 if @max <= 0 ((@value / @max) * 100).clamp(0, 100) end |