Class: Fluxbit::BannerComponent

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

Overview

The ‘Fluxbit::BannerComponent` is a customizable banner component that extends `Fluxbit::Component`. It provides various options to display banner messages with different styles, positions, and behaviors such as close functionality and call-to-action elements.

Example usage:

= render Fluxbit::BannerComponent.new(position: :top, color: :info).with_content("Banner message")

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props) ⇒ Fluxbit::BannerComponent

Initializes the banner component with the given properties.

Examples:

= render Fluxbit::BannerComponent.new(position: :top, color: :info).with_content("Banner message")

Parameters:

  • props (Hash)

    The properties to customize the banner.

Options Hash (**props):

  • :position (Symbol, String) — default: :top

    The position of the banner (top, bottom, sticky_top, sticky_bottom).

  • :color (Symbol, String) — default: :info

    The color style of the banner.

  • :icon (Symbol, String, Boolean) — default: :default

    The icon to display in the banner or ‘false` to omit.

  • :icon_html (Hash) — default: {}

    Additional HTML attributes for the icon.

  • :dismissible (Boolean) — default: true

    Determines if the banner can be dismissed.

  • :full_width (Boolean) — default: true

    Determines if the banner spans the full width.

  • :remove_class (String) — default: ''

    Classes to remove from the default class list.

  • **props (Hash)

    Remaining options declared as HTML attributes.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/fluxbit/banner_component.rb', line 40

def initialize(**props)
  super
  @props = props
  @position = define_position(@props.delete(:position) || @@position)
  @color = define_color(@props.delete(:color) || @@color)
  icon_prop = @props.delete(:icon)
  icon_html = @props.delete(:icon_html) || {}
  @icon = define_icon(icon_prop.nil? ? :default : icon_prop, icon_html)
  @dismissible = @props[:dismissible].nil? ? @@dismissible : @props.delete(:dismissible)
  @full_width = @props[:full_width].nil? ? @@full_width : @props.delete(:full_width)
  @props["id"] = fx_id if @props["id"].nil?

  declare_classes
  @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
end

Instance Method Details

#callObject



56
57
58
59
60
# File 'app/components/fluxbit/banner_component.rb', line 56

def call
  tag.div(**@props) do
    concat banner_content
  end
end