Class: Daisy::Feedback::RadialProgressComponent

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

Overview

The RadialProgressComponent displays a circular progress indicator that can be customized with different sizes, thicknesses, and colors. The component can also contain content within its circular display.

The progress is always displayed as a percentage (0-100) due to the way the component is rendered using CSS custom properties.

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) ⇒ RadialProgressComponent

Creates a new Radial Progress component.

Parameters:

  • args (Array)

    Positional arguments passed to the parent class.

  • kws (Hash)

    Keyword arguments for customizing the radial progress.

Options Hash (**kws):

  • value (Integer)

    The current progress value as a percentage (0-100). Required for the progress to be displayed.

  • size (String)

    The size of the radial progress component. Must include CSS units (e.g., “5rem”, “100px”). Defaults to “5rem”.

  • thickness (String)

    The thickness of the progress ring. Must include CSS units (e.g., “4px”, “0.5rem”). Defaults to one-tenth of the size.

  • css (String)

    Additional CSS classes for styling. Common options include color classes like ‘text-success` or `text-error`, background colors like `bg-primary`, and text sizing like `text-3xl`.



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

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

  @value = config_option(:value)
  @size = config_option(:size)
  @thickness = config_option(:thickness)
end

Instance Method Details

#before_renderObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/components/daisy/feedback/radial_progress_component.rb', line 55

def before_render
  add_css(:component, "radial-progress")

  styles = []

  styles << "--value: #{@value}" if @value != nil
  styles << "--size: #{@size}" if @size != nil
  styles << "--thickness: #{@thickness}" if @thickness != nil

  add_html(:component, { role: "progressbar" })
  add_html(:component, { style: styles.join(";") }) if styles.present?
end

#callObject



68
69
70
# File 'app/components/daisy/feedback/radial_progress_component.rb', line 68

def call
  part(:component) { content }
end