Class: CommentReplyComponent

Inherits:
Component show all
Defined in:
app/components/comment_reply_component.rb

Overview

CommentReply — a reply comment nested inside a CommentReplyGroup.

Usage:

CommentReplyGroup {
  CommentReply { |c|
    c.avatar { Image(src: "avatar.png") }
    c.author { text "Jenny" }
    c. { text "Just now" }
    c.text_slot { text "Great reply!" }
    c.actions { text "Reply" }
  }
}

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/comment_reply_component.rb', line 25

def to_s
  classes = class_names(
    { "disabled" => disabled },
    "comment"
  )

  avatar_el = @slots[:avatar] ? tag.a(class: "avatar") { @slots[:avatar] } : nil

  content_parts = [
    @slots[:author] ? tag.a(class: "author") { @slots[:author] } : nil,
    @slots[:metadata] ? tag.div(class: "metadata") { @slots[:metadata] } : nil,
    @slots[:text_slot] ? tag.div(class: "text") { @slots[:text_slot] } : nil,
    @slots[:actions] ? tag.div(class: "actions") { @slots[:actions] } : nil
  ].compact

  content_el = content_parts.any? ? tag.div(class: "content") { safe_join(content_parts) } : nil

  loose_content = @slots.values.any? ? nil : @content.presence
  tag.div(**merge_html_options(class: classes)) {
    safe_join([ avatar_el, content_el, loose_content ])
  }
end