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

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.

  • 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.



42
43
44
45
46
47
# File 'app/components/daisy/feedback/progress_component.rb', line 42

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

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

Instance Method Details

#before_renderObject



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

def before_render
  set_tag_name(:component, :progress)
  add_css(:component, "progress")
  add_html(:component, { value: @value, max: @max }) if @value != nil
end

#callObject



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

def call
  part(:component)
end