Class: Daisy::Actions::DropdownComponent::ItemComponent

Inherits:
LocoMotion::BasicComponent show all
Defined in:
app/components/daisy/actions/dropdown_component.rb

Overview

A single dropdown menu item (<li class="menu-item">). Pass a block for fully custom content (the original behavior), or use the structured options/slots to build a selectable row: a leading slot, a label, a trailing slot, and an active (selected) state.

Instance Method Summary collapse

Methods inherited from LocoMotion::BasicComponent

name

Constructor Details

#initialize(label: nil, href: nil, selected: false, **kws) ⇒ ItemComponent

Returns a new instance of ItemComponent.

Parameters:

  • kws (Hash)

    a customizable set of options

Options Hash (**kws):

  • label (String)

    Text for the item's label. You can also pass the label as block content.

  • href (String)

    When present, the row is rendered as an <a> link to this URL.

  • selected (Boolean)

    Marks the row active, adding DaisyUI's menu-active class. Defaults to false.



98
99
100
101
102
103
104
# File 'app/components/daisy/actions/dropdown_component.rb', line 98

def initialize(label: nil, href: nil, selected: false, **kws)
  @label = label
  @href = href
  @selected = selected

  super(**kws)
end

Instance Method Details

#before_renderObject



106
107
108
109
110
111
# File 'app/components/daisy/actions/dropdown_component.rb', line 106

def before_render
  set_tag_name(:component, :li)
  add_css(:component, "menu-item")

  super
end

#callObject



113
114
115
116
117
# File 'app/components/daisy/actions/dropdown_component.rb', line 113

def call
  part(:component) do
    structured? ? render_row : content
  end
end