Class: DaisyUI::ChatBubble
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- DaisyUI::ChatBubble
- Defined in:
- app/components/daisy_ui/data_display/chat_bubble.rb,
app/components/daisy_ui/data_display/chat_bubble/metadata.rb
Overview
Chat bubble component implementing DaisyUI’s chat bubble styles
Defined Under Namespace
Classes: Metadata
Constant Summary collapse
- COLORS =
Available chat bubble colors from DaisyUI
{ primary: 'chat-bubble-primary', secondary: 'chat-bubble-secondary', accent: 'chat-bubble-accent', neutral: 'chat-bubble-neutral', info: 'chat-bubble-info', success: 'chat-bubble-success', warning: 'chat-bubble-warning', error: 'chat-bubble-error' }.freeze
- POSITIONS =
Available positions
{ start: 'chat-start', end: 'chat-end' }.freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text = nil, position: :start, color: nil, text_class: nil, header_class: nil, footer_class: nil, avatar: {}, header: {}, footer: {}, **system_arguments) ⇒ ChatBubble
constructor
A new instance of ChatBubble.
-
#with_text(content = nil) ⇒ Object
Set the text content.
Constructor Details
#initialize(text = nil, position: :start, color: nil, text_class: nil, header_class: nil, footer_class: nil, avatar: {}, header: {}, footer: {}, **system_arguments) ⇒ ChatBubble
Returns a new instance of ChatBubble.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/components/daisy_ui/data_display/chat_bubble.rb', line 71 def initialize(text = nil, position: :start, color: nil, text_class: nil, header_class: nil, footer_class: nil, avatar: {}, header: {}, footer: {}, **system_arguments) @text = text @position = build_argument(position, POSITIONS, 'position') @color = build_argument(color, COLORS, 'color') @text_class = text_class @header_class = header_class = = avatar = header = @content_text = text super(**system_arguments) # Setup slots from provided options with_avatar(**) if &.any? with_header(**) if &.any? (**) if &.any? end |
Instance Method Details
#call ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'app/components/daisy_ui/data_display/chat_bubble.rb', line 105 def call tag.div(**html_attributes) do components = [] components << avatar if avatar? components << header if header? components << render_bubble if @content_text.present? components << if safe_join(components) end end |
#with_text(content = nil) ⇒ Object
Set the text content
97 98 99 100 101 102 103 |
# File 'app/components/daisy_ui/data_display/chat_bubble.rb', line 97 def with_text(content = nil, &) @content_text = if block_given? capture(&) else content end end |