Class: Daisy::DataDisplay::ListComponent

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

Overview

The List component is a vertical layout to display information in rows. It can contain various content types including text, images, and actions arranged in a consistent format.

The List component is useful for displaying structured data like user profiles, media libraries, or content collections with a consistent layout.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

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

Instance Attribute Summary collapse

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(**kws, &block) ⇒ ListComponent

Create a new List component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • :header (String)

    Optional header text to display at the top of the list. You can also provide custom header content using the header slot.

  • :header_css (String)

    Additional CSS classes to apply to the header when using the simple header text option.

  • :header_html (Hash)

    Additional HTML attributes to apply to the header when using the simple header text option.

  • :css (String)

    Additional CSS classes to apply to the list. Common options include:

    • bg-base-100 for background color
    • rounded-box for rounded corners
    • shadow-md for drop shadow
    • divide-y for dividers between items


79
80
81
82
83
84
85
# File 'app/components/daisy/data_display/list_component.rb', line 79

def initialize(**kws, &block)
  super

  @simple_header = config_option(:header)
  @header_css = config_option(:header_css)
  @header_html = config_option(:header_html)
end

Instance Attribute Details

#header_cssString (readonly)

Returns Optional header text for the list.

Returns:

  • (String)

    Optional header text for the list



55
56
57
# File 'app/components/daisy/data_display/list_component.rb', line 55

def header_css
  @header_css
end

#header_htmlString (readonly)

Returns Optional header text for the list.

Returns:

  • (String)

    Optional header text for the list



55
56
57
# File 'app/components/daisy/data_display/list_component.rb', line 55

def header_html
  @header_html
end

#simple_headerString (readonly)

Returns Optional header text for the list.

Returns:

  • (String)

    Optional header text for the list



55
56
57
# File 'app/components/daisy/data_display/list_component.rb', line 55

def simple_header
  @simple_header
end

Instance Method Details

#before_renderObject



87
88
89
90
91
92
# File 'app/components/daisy/data_display/list_component.rb', line 87

def before_render
  add_css(:component, "list")
  set_tag_name(:component, :ul)

  with_header(tag_name: :li, css: header_css, html: header_html) { simple_header } if simple_header && !header?
end