Class: Daisy::DataDisplay::CountdownComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::TippableComponent
Defined in:
app/components/daisy/data_display/countdown_component.rb

Overview

The Countdown component displays a timer that counts down to or up from a specific duration. It can show days, hours, minutes, and seconds with customizable separators and formats.

Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.

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

Creates a new countdown component.

Parameters:

  • duration (ActiveSupport::Duration)

    The duration to count down from. Can be created using Rails duration helpers like 1.day, 2.hours, etc.

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • :duration (ActiveSupport::Duration)

    The duration to count down from. Alternative to providing it as the first argument.

  • :modifier (Symbol)

    Optional display modifier. Use :words for “days”, “hours”, etc., or :letters for “d”, “h”, etc.

  • :separator (String)

    The separator to use between time parts. Defaults to “:”. Ignored when using :words or :letters modifiers.

  • :parts_css (String)

    CSS classes to apply to all time parts (days, hours, minutes, seconds).

  • :parts_html (Hash)

    HTML attributes to apply to all time parts.

  • :tip (String)

    The tooltip text to display when hovering over the component.



59
60
61
62
63
64
65
66
# File 'app/components/daisy/data_display/countdown_component.rb', line 59

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

  @duration = config_option(:duration, args[0])
  @separator = config_option(:separator, ":")
  @parts_css = config_option(:parts_css)
  @parts_html = config_option(:parts_html)
end

Instance Method Details

#before_renderObject



68
69
70
71
# File 'app/components/daisy/data_display/countdown_component.rb', line 68

def before_render
  setup_component # Configure countdown parts and stimulus
  super           # Run TippableComponent hook
end