Class: Fluxbit::DropdownItemComponent

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

Overview

The ‘Fluxbit::DropdownItemComponent` is a component for rendering customizable Dropdown item containers.

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(param_content = "", **props) ⇒ DropdownItemComponent

Returns a new instance of DropdownItemComponent.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/fluxbit/dropdown_item_component.rb', line 9

def initialize(param_content = "", **props)
  @param_content = param_content
  @item_props = props
  @type = @item_props.delete(:as) || :div
  @height = @item_props.delete(:height) || @@height
  @icon = @item_props.delete(:icon)
  add to: @item_props, class: styles[:items][:heights][@height]
  remove_class_from_props(@item_props)

  @content_html = @item_props.delete(:content_html) || {}

  @icon_html = @item_props.delete(:icon_html) || {}
  add to: @icon_html, class: styles[:icon] if @icon.present?

  @divider = @item_props.delete(:divider) || false
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/components/fluxbit/dropdown_item_component.rb', line 26

def call
  return tag.li(class: styles[:divider]) if @divider

  if items.any?
    @content_html["data-dropdown-toggle"] = @item_props.delete(:dropdown_id) || "inner-dropdown-#{random_id}"
    @content_html["data-dropdown-placement"] = @item_props.delete(:dropdown_placement) || "right-start"
    height = @item_props.delete(:sizing) || 0
    auto_divider = @item_props.delete(:auto_divider) || true
    @type = :button
    @content_html[:type] = "button"
  end

  add to: @content_html, class: styles[:items][:types][@type]
  remove_class_from_props(@content_html)

  tag.li(**@item_props) do
    concat((@type.to_sym, **@content_html) do
      concat(tag.div(class: "flex") do
        concat(anyicon(@icon, **@icon_html)) if @icon.present?
        concat(content || @param_content)
      end)
      concat(chevron_right(class: "ms-3 ml-auto")) if items.any?
    end)
    concat(
      inner_dropdown(items, id: @content_html["data-dropdown-toggle"], sizing: height, auto_divider: auto_divider)
    ) if items.any?
  end
end