Class: ProgressComponent

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

Overview

Progress — progress bars.

Usage:

Progress(value: 65, total: 100, color: :green, active: true) { |c|
  c.bar { }
  c.label { text "65% Complete" }
}
Progress(value: 3, total: 10, indicating: true)

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/components/progress_component.rb', line 26

def to_s
  percent = total > 0 ? ((value.to_f / total) * 100).round : 0

  classes = class_names(
    "ui",
    color,
    size,
    attached && "#{attached} attached",
    { "indicating" => indicating,
      "active" => active,
      "inverted" => inverted,
      "disabled" => disabled },
    "progress"
  )

  bar_el = tag.div(class: "bar", style: "width:#{percent}%") { @slots[:bar] }
  label_el = @slots[:label] ? tag.div(class: "label") { @slots[:label] } : nil

  tag.div(class: classes, data: { controller: "fui-progress", percent: percent }) {
    safe_join([ bar_el, label_el, @content.presence ])
  }
end