Class: Fluxbit::ButtonGroupComponent

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

Overview

The ‘Fluxbit::ButtonGroupComponent` is a component for rendering a group of buttons. It extends `Fluxbit::Component` and provides options for configuring the appearance and behavior of the button group. You can control the buttons displayed within the group. The component supports rendering multiple buttons, each of which can be styled or customized through various properties.

Constant Summary

Constants inherited from Component

Component::ComponentObj

Instance Attribute Summary collapse

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) ⇒ ButtonGroupComponent

Initializes the button group component with the given properties.

Parameters:

  • props (Hash)

    The properties to customize the button group.

Options Hash (**props):

  • **props (Hash)

    Remaining options declared as HTML attributes, applied to the button group container.



21
22
23
24
25
26
# File 'app/components/fluxbit/button_group_component.rb', line 21

def initialize(**props)
  super
  @props = props
  @buttons_group = []
  add class: styles[:group], to: @props
end

Instance Attribute Details

#buttons_groupObject

Returns the value of attribute buttons_group.



9
10
11
# File 'app/components/fluxbit/button_group_component.rb', line 9

def buttons_group
  @buttons_group
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/fluxbit/button_group_component.rb', line 28

def call
  buttons
   :div, **@props do
    @buttons_group.each_with_index do |button, index|
      button_props = button.props || {}
      button_content = button.content

      button_props[:grouped] = true
      button_props[:first_button] = true if index == 0
      button_props[:last_button] = true if index == @buttons_group.size - 1

      concat Fluxbit::ButtonComponent.new(**button_props).with_content(button_content).render_in(view_context)
    end
  end
end