Class: Daisy::Actions::DropdownComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Actions::DropdownComponent
- Includes:
- ViewComponent::SlotableDefault
- Defined in:
- app/components/daisy/actions/dropdown_component.rb
Overview
The dropdown uses slots for both the activator and menu items, allowing for maximum flexibility in how the dropdown is triggered and what content it displays.
The Dropdown component shows a Button, or any other component you wish, with a hovering menu that opens on click (or hover). It provides a flexible way to create dropdown menus with customizable triggers and content.
Defined Under Namespace
Classes: ItemComponent
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
Instance Method Summary collapse
-
#before_render ⇒ Object
Adds the relevant Daisy classes to the component.
-
#default_button ⇒ Object
Provides a default button if no button or custom activator is provided.
-
#initialize(title = nil, **kws, &block) ⇒ DropdownComponent
constructor
Creates a new instance of the DropdownComponent.
-
#setup_component ⇒ Object
Add the
dropdownCSS class to the component. -
#setup_menu ⇒ Object
Make the menu a
<ul> / <li>element and add the relevant Daisy classes.
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
Constructor Details
#initialize(title = nil, **kws, &block) ⇒ DropdownComponent
Creates a new instance of the DropdownComponent.
174 175 176 177 178 |
# File 'app/components/daisy/actions/dropdown_component.rb', line 174 def initialize(title = nil, **kws, &block) super @simple_title = config_option(:title, title) end |
Instance Method Details
#before_render ⇒ Object
Adds the relevant Daisy classes to the component.
183 184 185 186 |
# File 'app/components/daisy/actions/dropdown_component.rb', line 183 def before_render setup_component end |
#default_button ⇒ Object
Provides a default button if no button or custom activator is provided.
222 223 224 |
# File 'app/components/daisy/actions/dropdown_component.rb', line 222 def Daisy::Actions::ButtonComponent.new(title: @simple_title) end |
#setup_component ⇒ Object
Add the dropdown CSS class to the component.
191 192 193 |
# File 'app/components/daisy/actions/dropdown_component.rb', line 191 def setup_component add_css(:component, "dropdown") end |
#setup_menu ⇒ Object
Make the menu a <ul> / <li> element and add the relevant Daisy classes.
All of the defaults use the where: prefix (zero specificity), so any
classes passed via menu_css win.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/components/daisy/actions/dropdown_component.rb', line 200 def set_tag_name(:menu, :ul) # Core menu structure and styling. add_css(:menu, "dropdown-content where:menu where:bg-base-100 where:rounded-box where:shadow") # Default sizing, padding, and stacking. add_css(:menu, "where:w-52 where:p-2 where:z-[1]") # The default border keeps the menu visible when it opens over content # that shares its background color (`menu_css: "border-0"` removes it). add_css(:menu, "where:border where:border-base-300") # The vertical margin separates the menu from the trigger; only the # margin on the side the menu opens from takes effect # (`menu_css: "my-0"` removes it). add_css(:menu, "where:my-0.5") end |