Class: Fluxbit::TextComponent

Inherits:
Component
  • Object
show all
Includes:
Config::TextComponent
Defined in:
app/components/fluxbit/text_component.rb

Overview

The ‘Fluxbit::TextComponent` is a component for rendering customizable text elements. It extends `Fluxbit::Component` and provides options for configuring the text’s appearance and behavior. You can control the text’s tag, styles, and other attributes. The text can be rendered as different HTML tags (e.g., span, div) and can have various styles applied based on the provided properties.

Constant Summary

Constants inherited from Component

Component::ComponentObj

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #options, #random_id, #remove_class, #render_popover_or_tooltip, #target

Constructor Details

#initialize(**props) ⇒ TextComponent

Initializes the text component with the given properties.

Parameters:

  • props (Hash)

    The properties to customize the text.

Options Hash (**props):

  • :as (Symbol) — default: :span

    The HTML tag to use for the text element.

  • **props (Hash)

    Remaining options declared as HTML attributes, applied to the text element.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/fluxbit/text_component.rb', line 16

def initialize(**props)
  super
  @props = props.compact
  @as = @props.delete(:as) || :span

  styles.each do |style_type, style_values|
    if @props.key?(style_type)
      element = @props.delete(style_type)
      if style_values.is_a?(Array)
        add(class: style_values[element.to_i], to: @props)
      else
        add(class: style_values[element.to_sym], to: @props) if style_values.key?(element.to_sym)
      end
    end
  end
end

Instance Method Details

#callObject



33
34
35
# File 'app/components/fluxbit/text_component.rb', line 33

def call
   @as, content, @props
end