Class: UI::AspectRatioComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
AspectRatioBehavior
Defined in:
app/view_components/ui/aspect_ratio_component.rb

Overview

AspectRatio - ViewComponent implementation

Displays content within a desired aspect ratio.

Constant Summary

Constants included from AspectRatioBehavior

UI::AspectRatioBehavior::DEFAULT_RATIO

Instance Method Summary collapse

Methods included from AspectRatioBehavior

#aspect_ratio_classes, #aspect_ratio_content_attributes, #aspect_ratio_html_attributes, #aspect_ratio_padding, #aspect_ratio_padding_attributes

Constructor Details

#initialize(ratio: 1.0, classes: "", **attributes) ⇒ AspectRatioComponent

Returns a new instance of AspectRatioComponent.

Parameters:

  • ratio (Float) (defaults to: 1.0)

    The desired aspect ratio (width/height, e.g., 16/9)

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



12
13
14
15
16
# File 'app/view_components/ui/aspect_ratio_component.rb', line 12

def initialize(ratio: 1.0, classes: "", **attributes)
  @ratio = ratio
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
# File 'app/view_components/ui/aspect_ratio_component.rb', line 18

def call
  tag.div(**aspect_ratio_html_attributes) do
    tag.div(**aspect_ratio_padding_attributes) +
      tag.div(**aspect_ratio_content_attributes) do
        content
      end
  end
end