Class: Daisy::DataDisplay::FigureComponent

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

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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(**kws, &block) ⇒ FigureComponent

Creates a new figure component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • src (String)

    URL of the image to display in the figure.

  • position (Symbol)

    Position of the image relative to content. Must be :top (default) or :bottom.

  • alt (String)

    The alt text for the image, used by screen readers and shown when the image fails to load. Omitted when not provided.

  • css (String)

    Additional CSS classes for styling.



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

def initialize(**kws, &block)
  super

  @src = kws[:src]
  @alt = kws[:alt]
  @position = kws[:position] || :top

  validate_position!
end

Instance Method Details

#before_renderObject



56
57
58
59
60
61
# File 'app/components/daisy/data_display/figure_component.rb', line 56

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

  super
end

#callObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/components/daisy/data_display/figure_component.rb', line 63

def call
  part(:component) do
    if @position == :bottom
      # Show content first, then image
      concat(content)
      concat(part(:image)) if @src
    else
      # Default: show image first, then content
      concat(part(:image)) if @src
      concat(content)
    end
  end
end