Class: IronAdmin::Ui::DropdownComponent

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

Overview

Renders a dropdown menu with trigger and items.

Examples:

Basic dropdown

render IronAdmin::Ui::DropdownComponent.new do |dropdown|
  dropdown.with_trigger { render ButtonComponent.new(text: "Actions") }
  dropdown.with_item(href: edit_path) { "Edit" }
  dropdown.with_item(href: delete_path, destructive: true) { "Delete" }
end

Defined Under Namespace

Classes: ItemComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(align: :right, width: 48) ⇒ DropdownComponent

Returns a new instance of DropdownComponent.

Parameters:

  • align (Symbol) (defaults to: :right)

    Alignment (default: :right)

  • width (Integer) (defaults to: 48)

    Width (default: 48)



25
26
27
28
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 25

def initialize(align: :right, width: 48)
  @align = align
  @width = width
end

Instance Attribute Details

#alignSymbol (readonly)

Returns Dropdown alignment (:left, :right).

Returns:

  • (Symbol)

    Dropdown alignment (:left, :right)



18
19
20
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 18

def align
  @align
end

#widthInteger (readonly)

Returns Dropdown width in Tailwind units.

Returns:

  • (Integer)

    Dropdown width in Tailwind units



21
22
23
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 21

def width
  @width
end

Instance Method Details

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 dropdown panel.

Returns:

  • (String)

    CSS classes for dropdown panel



38
39
40
41
42
43
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 38

def dropdown_classes
  align_class = align == :right ? "right-0" : "left-0"
  width_class = "w-#{width}"
  "absolute #{align_class} mt-2 #{width_class} origin-top-#{align} #{theme.border_radius} " \
    "#{theme.card_bg} border #{theme.card_border} #{theme.card_shadow}-lg z-50"
end

#themeIronAdmin::Configuration::Theme

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 Theme configuration.

Returns:



32
33
34
# File 'app/components/iron_admin/ui/dropdown_component.rb', line 32

def theme
  IronAdmin.configuration.theme
end