Class: Daisy::Layout::HoverGalleryComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/layout/hover_gallery_component.rb

Overview

Note:

By default the gallery is rendered with a 3:2 aspect ratio (where:aspect-[3/2]) so that images with differing aspect ratios don't shift the container's height as they are revealed on hover. The default uses DaisyUI's zero-specificity where: variant and is skipped entirely when you pass your own aspect-* utility (e.g. aspect-square) via css:, so it is easy to override.

The HoverGalleryComponent displays a container of images where the first image is visible by default and hovering horizontally reveals the others. Common use cases include product cards on e-commerce sites, portfolios, and image galleries. DaisyUI supports up to 10 images.

The underlying HTML is a <figure> containing <img> elements. DaisyUI creates invisible columns over the figure; hovering each column reveals the corresponding image.

Defined Under Namespace

Classes: ImageComponent

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(srcs: nil, **kws) ⇒ HoverGalleryComponent

Creates a new HoverGalleryComponent.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • srcs (Array<String>)

    An optional array of image source URLs for simple usage without blocks. Each URL is rendered as an <img> inside the gallery. The block-based slot API takes precedence when images are added via with_image.

  • css (String)

    Additional CSS classes for styling. Common options include sizing utilities such as max-w-60 or w-full. Pass an aspect-* utility (e.g. aspect-square) to override the default 3:2 aspect ratio.



80
81
82
83
84
# File 'app/components/daisy/layout/hover_gallery_component.rb', line 80

def initialize(srcs: nil, **kws)
  super(**kws)
  @srcs = srcs
  @css = config_option(:css, "")
end

Instance Method Details

#before_renderObject



86
87
88
89
# File 'app/components/daisy/layout/hover_gallery_component.rb', line 86

def before_render
  setup_component
  super
end