Class: IronAdmin::Ui::DropdownComponent::ItemComponent Private

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/iron_admin/ui/dropdown_component.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Individual dropdown menu item.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href: nil, method: nil, icon: nil, destructive: false) ⇒ ItemComponent

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ItemComponent.

Parameters:

  • href (String, nil) (defaults to: nil)

    Link URL

  • method (Symbol, nil) (defaults to: nil)

    HTTP method

  • icon (String, nil) (defaults to: nil)

    Heroicon name

  • destructive (Boolean) (defaults to: false)

    Destructive action (default: false)



64
65
66
67
68
69
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 64

def initialize(href: nil, method: nil, icon: nil, destructive: false)
  @href = href
  @method = method
  @icon = icon
  @destructive = destructive
end

Instance Attribute Details

#destructiveBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Whether item is destructive (red styling).

Returns:

  • (Boolean)

    Whether item is destructive (red styling)



58
59
60
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 58

def destructive
  @destructive
end

#hrefString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Link URL.

Returns:

  • (String, nil)

    Link URL



49
50
51
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 49

def href
  @href
end

#iconString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Heroicon name.

Returns:

  • (String, nil)

    Heroicon name



55
56
57
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 55

def icon
  @icon
end

#methodSymbol? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns HTTP method.

Returns:

  • (Symbol, nil)

    HTTP method



52
53
54
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 52

def method
  @method
end

Instance Method Details

#callString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Renders the menu item.

Returns:

  • (String)

    HTML content



84
85
86
87
88
89
90
91
92
93
94
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 84

def call
  if href
    link_to(href, class: item_classes, data: method ? { turbo_method: method } : {}) do
      item_content
    end
  else
    tag.button(type: "button", class: item_classes) do
      item_content
    end
  end
end

#item_classesString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns CSS classes for menu item.

Returns:

  • (String)

    CSS classes for menu item



73
74
75
76
77
78
79
80
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 73

def item_classes
  base = "flex items-center gap-2 w-full px-4 py-2 text-sm text-left transition-colors duration-150"
  if destructive
    "#{base} text-red-600 hover:bg-red-50"
  else
    "#{base} text-gray-700 hover:bg-gray-50"
  end
end