Class: Daisy::Navigation::MenuItemComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/navigation/menu_component.rb

Overview

A menu item component that can optionally have a title and be disabled.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Constructor Details

#initialize(*args, **kws) ⇒ MenuItemComponent

Create a new instance of the MenuItemComponent.

Parameters:

  • args (Array)

    If provided, the first argument is considered the ‘title`.

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • title (String)

    Shows an additional title above the item.

  • disabled (Boolean)

    Sets the item in a disabled state.

  • css (String)

    Additional CSS classes for styling. Common options include:

    • Text: ‘text-sm`, `text-base-content`

    • Spacing: ‘mt-4`, `mb-2`

    • State: ‘menu-active`, `menu-focus`, `menu-disabled`



73
74
75
76
77
78
# File 'app/components/daisy/navigation/menu_component.rb', line 73

def initialize(*args, **kws)
  super(**kws)

  @simple_title = config_option(:title, args[0])
  @disabled = config_option(:disabled)
end

Instance Method Details

#before_renderObject

Adds the relevant Daisy classes and applies the disabled state if provided (utilizes Tailwind pointer-events-none).



84
85
86
87
88
89
90
# File 'app/components/daisy/navigation/menu_component.rb', line 84

def before_render
  set_tag_name(:component, :li)
  add_css(:component, "menu-disabled pointer-events-none") if @disabled

  set_tag_name(:title, :h2)
  add_css(:title, "menu-title")
end

#callObject

Renders the menu item component including a title if present.



95
96
97
98
99
100
# File 'app/components/daisy/navigation/menu_component.rb', line 95

def call
  part(:component) do
    concat(part(:title) { @simple_title }) if @simple_title
    concat(content)
  end
end