Class: Fluxbit::BadgeComponent

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

Overview

The ‘Fluxbit::BadgeComponent` is a customizable badge component that extends `Fluxbit::Component`. It allows you to create badges with different colors, sizes, borders, and shapes (pill).

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) ⇒ Fluxbit::BadgeComponent

Initializes the badge component with the given properties.

Parameters:

  • props (Hash)

    The properties to customize the badge.

Options Hash (**props):

  • :color (Symbol, String)

    The color style of the badge.

  • :pill (Boolean) — default: false

    Determines if the badge is pill-shaped.

  • :size (Symbol, Integer)

    The size of the badge (e.g., ‘0` to `1`).

  • :perfect_rounded (Symbol, String) — default: :none

    Define if the bage is a perfect rounded with size (e.g., ‘0` to `5`).

  • :as (Symbol, String)

    The HTML tag to use for the badge (e.g., ‘:span`, `:div`).

  • :remove_class (String) — default: ''

    Classes to remove from the default class list.

  • :popover_text (String) — default: nil

    Popover text (from Fluxbit::Component).

  • :popover_placement (Symbol) — default: :right

    Popover placement (e.g., ‘:right`, `:left`, `:top`, `:bottom`) (from Fluxbit::Component).

  • :popover_trigger (Symbol) — default: :hover

    Popover trigger (e.g., ‘:hover`, `:click`) (from Fluxbit::Component).

  • :tooltip_text (String) — default: nil

    Tooltip text (from Fluxbit::Component).

  • :tooltip_placement (Symbol) — default: :right

    Tooltip placement (e.g., ‘:right`, `:left`, `:top`, `:bottom`) (from Fluxbit::Component).

  • :tooltip_trigger (Symbol) — default: :hover

    Tooltip trigger (e.g., ‘:hover`, `:click`) (from Fluxbit::Component).

  • **props (Hash)

    Remaining options declared as HTML attributes.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/components/fluxbit/badge_component.rb', line 36

def initialize(**props)
  super
  @props = props
  @color = @props.delete(:color) || @@color
  @pill = @props.delete(:pill) || @@pill
  @size = @props.delete(:size) || @@size
  @perfect_rounded = @props.delete(:perfect_rounded) || @@perfect_rounded
  @notification = @props.delete(:notification) || @@notification
  @as = @props.delete(:as) || @@as
  add(class: badge_classes, to: @props, first_element: true)
  @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
end

Instance Method Details

#before_renderObject



49
50
51
# File 'app/components/fluxbit/badge_component.rb', line 49

def before_render
  add_popover_or_tooltip
end

#callObject



53
54
55
# File 'app/components/fluxbit/badge_component.rb', line 53

def call
  concat((@as, content, @props) + render_popover_or_tooltip.to_s)
end