Class: DaisyUI::ChatBubble::Metadata

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/daisy_ui/data_display/chat_bubble/metadata.rb

Overview

Component for chat bubble metadata (header/footer)

Examples:

Header usage

<%= render(MetadataComponent.new(text: "John Doe", time: "12:45", type: :header)) %>

Footer usage

<%= render(MetadataComponent.new(text: "Delivered", time: "12:46", type: :footer)) %>

Constant Summary collapse

TYPES =
i[header footer].freeze
TYPE_CLASSES =
{
  header: 'chat-header',
  footer: 'chat-footer opacity-50'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text:, type:, time: nil, **system_arguments) ⇒ Metadata

Returns a new instance of Metadata.

Parameters:

  • text (String)

    The main text content

  • time (String, nil) (defaults to: nil)

    Optional timestamp

  • type (Symbol)

    Type of metadata (:header or :footer)

  • system_arguments (Hash)

    Additional HTML attributes



24
25
26
27
28
29
# File 'app/components/daisy_ui/data_display/chat_bubble/metadata.rb', line 24

def initialize(text:, type:, time: nil, **system_arguments)
  @text = text
  @time = time
  @type = validate_type!(type)
  super(**system_arguments)
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
# File 'app/components/daisy_ui/data_display/chat_bubble/metadata.rb', line 31

def call
  tag.div(**html_attributes) do
    safe_join([
      @text,
      render_time
    ].compact)
  end
end