Class: MessageComponent

Inherits:
Component show all
Includes:
Attachable
Defined in:
app/components/message_component.rb

Overview

Message — alert/info messages.

Usage:

Message(type: :success) { text "It worked!" }
Message(type: :error, icon: "exclamation triangle") { |c|
  c.header { text "Error" }
  text "Something went wrong."
}
Message(dismissible: true) { text "Notice" }

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/message_component.rb', line 28

def to_s
  classes = class_names(
    "ui",
    size,
    color,
    type,
    { "attached" => attached,
      "icon" => icon,
      "floating" => floating,
      "compact" => compact,
      "hidden" => hidden,
      "visible" => visible },
    "message"
  )

  close_el = dismissible ? tag.i(class: "close icon") : nil
  icon_el = icon ? tag.i(class: "#{icon} icon") : nil
  header_el = @slots[:header] ? tag.div(class: "header") { @slots[:header] } : nil

  content_parts = safe_join([ header_el, @content.presence ])
  content_wrapper = icon ? tag.div(class: "content") { content_parts } : content_parts

  opts = merge_html_options(class: classes)

  tag.div(**opts) {
    safe_join([ close_el, icon_el, content_wrapper ])
  }
end