Class: Daisy::DataDisplay::FigureComponent

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

Overview

The FigureComponent is used to display images with optional captions. It is commonly used within cards and other content containers.

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

Creates a new figure component.

Options Hash (**kws):

  • src (String)

    URL of the image to display in the figure.

  • css (String)

    Additional CSS classes for styling.



31
32
33
34
35
# File 'app/components/daisy/data_display/figure_component.rb', line 31

def initialize(**kws, &block)
  super

  @src = kws[:src]
end

Instance Method Details

#before_renderObject



37
38
39
40
41
42
# File 'app/components/daisy/data_display/figure_component.rb', line 37

def before_render
  set_tag_name(:component, :figure)
  add_html(:image, src: @src) if @src

  super
end

#callObject



44
45
46
47
48
49
50
51
52
53
# File 'app/components/daisy/data_display/figure_component.rb', line 44

def call
  part(:component) do
    if @src
      concat(part(:image))
    end

    # Always show the content
    concat(content)
  end
end