Class: Daisy::Feedback::ProgressComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/feedback/progress_component.rb

Overview

The ProgressComponent displays a horizontal bar that indicates the completion status of a process. It can show determinate progress with a specific value or indeterminate progress with an animated bar.

The component renders as an HTML <progress> element and supports various colors and styles through CSS classes.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(*args, **kws, &block) ⇒ ProgressComponent

Creates a new Progress component.

Parameters:

  • args (Array) —

    Positional arguments passed to the parent class.

  • kws (Hash) —

    Keyword arguments for customizing the progress bar.

Options Hash (**kws):

  • value (Integer, nil) —

    The current progress value. Set to nil for an indeterminate progress bar that animates continuously. Defaults to nil.

  • max (Integer) —

    The maximum value for the progress bar. Defaults to 100 to easily work with percentage values. Only rendered as the max attribute when value is also set, so daisy_progress(max: 50) alone renders no max attribute.

  • css (String) —

    Additional CSS classes for the progress bar. Available styles include: progress-primary, progress-secondary, progress-accent, progress-info, progress-success, progress-warning, and progress-error. Can be combined with utility classes like [animation-delay:250ms]! for staggered animations.



47
48
49
50
51
52
# File 'app/components/daisy/feedback/progress_component.rb', line 47

def initialize(*args, **kws, &block)
  super

  @value = config_option(:value, nil)
  @max = config_option(:max, 100)
end

Instance Method Details

#before_render ⇒ Object



54
55
56
57
58
# File 'app/components/daisy/feedback/progress_component.rb', line 54

def before_render
  set_tag_name(:component, :progress)
  add_css(:component, "progress")
  add_html(:component, { value: @value, max: @max }) unless @value.nil?
end

#call ⇒ Object



60
61
62
# File 'app/components/daisy/feedback/progress_component.rb', line 60

def call
  part(:component)
end