Class: OkonomiUiKit::Components::ProgressBar
- Inherits:
-
OkonomiUiKit::Component
- Object
- OkonomiUiKit::Component
- OkonomiUiKit::Components::ProgressBar
- Defined in:
- app/helpers/okonomi_ui_kit/components/progress_bar.rb
Instance Attribute Summary
Attributes inherited from OkonomiUiKit::Component
Instance Method Summary collapse
Methods inherited from OkonomiUiKit::Component
#combined_styles, config_class?, config_class_name, config_classes, config_namespace, #config_styles_registry, config_styles_registry, deep_merge, #initialize, #internal_styles_registry, internal_styles_registry, #name, parent_styles_registry, register_styles, resolve_config_classes, #style, #styles, #template_path, #theme_name, #tw_merge, #variant_style
Constructor Details
This class inherits a constructor from OkonomiUiKit::Component
Instance Method Details
#render(value, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/okonomi_ui_kit/components/progress_bar.rb', line 4 def render(value, = {}) = .with_indifferent_access # Extract options color = (.delete(:color) || :primary).to_sym size = (.delete(:size) || :md).to_sym text = .delete(:text) # Ensure value is between 0 and 1 value = [ [ value.to_f, 0.0 ].max, 1.0 ].min percentage = (value * 100).round # Build classes container_classes = tw_merge( style(:container, :root), style(:container, :sizes, size), .delete(:class) ) = tw_merge( style(:bar, :root), style(:bar, :colors, color), style(:bar, :sizes, size), percentage < 100 ? "animate-pulse" : nil ) text_classes = tw_merge( style(:text, :root), style(:text, :sizes, size) ) view.render( template_path, value: value, percentage: percentage, text: text, container_classes: container_classes, bar_classes: , text_classes: text_classes, options: ) end |