Class: Shadcn::MessageScroller::Item::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/message_scroller/item/component.rb

Overview

One row. Its two attributes are the markup's half of the contract with scroll_geometry.js, which reads dataset.messageId and dataset.scrollAnchor — so they are rendered whether or not a controller is present.

data-scroll-anchor is written as the string "false" rather than omitted, exactly as upstream does (components.tsx:340). Nothing here depends on the difference, but a host's CSS might.

content-visibility: auto lets the browser skip laying out rows that are off screen, and contain-intrinsic-size is the guess it uses for their height until it does. They arrive as arbitrary properties because Tailwind has no utility for either.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(message_id: nil, scroll_anchor: false, **attributes) ⇒ Component

Returns a new instance of Component.



30
31
32
33
34
# File 'app/components/shadcn/message_scroller/item/component.rb', line 30

def initialize(message_id: nil, scroll_anchor: false, **attributes)
  @message_id = message_id
  @scroll_anchor = scroll_anchor
  super(**attributes)
end

Instance Attribute Details

#message_idObject (readonly)

Returns the value of attribute message_id.



28
29
30
# File 'app/components/shadcn/message_scroller/item/component.rb', line 28

def message_id
  @message_id
end

#scroll_anchorObject (readonly)

Returns the value of attribute scroll_anchor.



28
29
30
# File 'app/components/shadcn/message_scroller/item/component.rb', line 28

def scroll_anchor
  @scroll_anchor
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



36
37
38
39
40
41
# File 'app/components/shadcn/message_scroller/item/component.rb', line 36

def element_attributes(**defaults)
  super(**{
    "data-message-id" => message_id,
    "data-scroll-anchor" => scroll_anchor.to_s
  }.compact.merge(defaults))
end