Class: Daisy::Actions::DropdownComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
ViewComponent::SlotableDefault
Defined in:
app/components/daisy/actions/dropdown_component.rb

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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(title = nil, **kws, &block) ⇒ DropdownComponent

Creates a new instance of the DropdownComponent.

Parameters:

  • title (String) (defaults to: nil)

    The title of the dropdown. Will be used as the button text if no custom button or activator is provided.

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • title (String)

    The title of the dropdown. You can also pass this as the first argument.



81
82
83
84
85
# File 'app/components/daisy/actions/dropdown_component.rb', line 81

def initialize(title = nil, **kws, &block)
  super

  @simple_title = config_option(:title, title)
end

Instance Method Details

#before_renderObject

Adds the relevant Daisy classes to the component.



90
91
92
93
# File 'app/components/daisy/actions/dropdown_component.rb', line 90

def before_render
  setup_component
  setup_menu
end

#default_buttonObject

Provides a default button if no button or custom activator is provided.



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

def default_button
  Daisy::Actions::ButtonComponent.new(title: @simple_title)
end

#setup_componentObject

Add the ‘dropdown` CSS class to the component.



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

def setup_component
  add_css(:component, "dropdown")
end

#setup_menuObject

Make the menu a ‘<ul> / <li>` element and add the relevant Daisy classes.



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

def setup_menu
  # Setup menu itself
  set_tag_name(:menu, :ul)
  add_css(:menu,
          "dropdown-content where:menu where:bg-base-100 where:rounded-box where:shadow where:w-52 where:p-2 where:z-[1]")
end