Class: Daisy::DataDisplay::FigureComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataDisplay::FigureComponent
- Includes:
- LocoMotion::Concerns::LinkableComponent
- Defined in:
- app/components/daisy/data_display/figure_component.rb
Overview
before_render sets the component's tag to <figure>, but
LocoMotion::Concerns::LinkableComponent's setup runs afterward via
super and overrides it to <a> whenever href is present. Since
Figure is commonly embedded in Card's top_figure / bottom_figure
slots, passing href: there changes the wrapping element from a
<figure> to an <a>.
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
Instance Method Summary collapse
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(**kws, &block) ⇒ FigureComponent
constructor
Creates a new figure component.
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
Constructor Details
#initialize(**kws, &block) ⇒ FigureComponent
Creates a new figure component.
83 84 85 86 87 88 89 90 91 |
# File 'app/components/daisy/data_display/figure_component.rb', line 83 def initialize(**kws, &block) super @src = kws[:src] @alt = kws[:alt] @position = kws[:position] || :top validate_position! end |
Instance Method Details
#before_render ⇒ Object
93 94 95 96 97 98 |
# File 'app/components/daisy/data_display/figure_component.rb', line 93 def before_render set_tag_name(:component, :figure) add_html(:image, { src: @src, alt: @alt }) if @src super end |
#call ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/components/daisy/data_display/figure_component.rb', line 100 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 |