Class: Daisy::DataDisplay::TimelineEventComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/data_display/timeline_event_component.rb

Overview

Note:

The middle and middle_icon options are mutually exclusive. If both are provided, middle takes precedence.

A component for rendering individual events within a timeline. Each event can have three sections: start (typically a date or time), middle (an icon or marker), and end (the event description).

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

Creates a new timeline event component.

Options Hash (**kws):

  • :start (String)

    Text to display in the start section. You can also provide custom content using the start slot.

  • :middle (String)

    Text to display in the middle section. You can also provide custom content using the middle slot.

  • :middle_icon (String)

    Name of a heroicon to display in the middle section. Ignored if middle is provided.

  • :end (String)

    Text to display in the end section. You can also provide custom content using the end slot.



49
50
51
52
53
54
55
56
57
58
59
# File 'app/components/daisy/data_display/timeline_event_component.rb', line 49

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

  @event_index = nil
  @events_length = nil

  @simple_start = config_option(:start)
  @simple_middle = config_option(:middle)
  @simple_middle_icon = config_option(:middle_icon)
  @simple_end = config_option(:end)
end

Instance Method Details

#before_renderObject



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

def before_render
  set_tag_name(:component, :li)

  setup_parts
  setup_separator
end

#set_event_index(index) ⇒ Object



78
79
80
# File 'app/components/daisy/data_display/timeline_event_component.rb', line 78

def set_event_index(index)
  @event_index = index
end

#set_events_length(length) ⇒ Object



82
83
84
# File 'app/components/daisy/data_display/timeline_event_component.rb', line 82

def set_events_length(length)
  @events_length = length
end

#setup_partsObject



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

def setup_parts
  add_css(:start, "timeline-start")
  add_css(:middle, "timeline-middle")
  add_css(:end, "timeline-end")
end

#setup_separatorObject



74
75
76
# File 'app/components/daisy/data_display/timeline_event_component.rb', line 74

def setup_separator
  set_tag_name(:separator, :hr)
end