Class: DaisyUI::Dropdown
- Defined in:
- lib/daisy_ui/dropdown.rb
Constant Summary collapse
- PLACEMENT_MODIFIERS =
Placement modifiers that, in :popover mode, must live on the popover element itself (DaisyUI’s ‘position-area` rule is on `.dropdown`).
%i[start center end top bottom left right].freeze
- DEFAULT_STIMULUS_IDENTIFIER =
Default Stimulus identifier for the opt-in popover controller. Namespaced so it never collides with a consumer app’s own ‘dropdown` controller.
"daisy-dropdown"
Constants inherited from Base
Base::BOOLS, Base::COLOR_MODIFIERS
Instance Method Summary collapse
- #button(*modifiers, **options) ⇒ Object
- #content(*modifiers, as: :div, **options) ⇒ Object
-
#initialize(*modifiers, as: :div, id: nil, popover_id: nil, stimulus: false) ⇒ Dropdown
constructor
A new instance of Dropdown.
- #menu(*modifiers, **options) ⇒ Object
- #popover? ⇒ Boolean
- #tap_to_close? ⇒ Boolean
- #view_template ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*modifiers, as: :div, id: nil, popover_id: nil, stimulus: false) ⇒ Dropdown
Returns a new instance of Dropdown.
17 18 19 20 21 22 23 24 |
# File 'lib/daisy_ui/dropdown.rb', line 17 def initialize(*modifiers, as: :div, id: nil, popover_id: nil, stimulus: false, **) @popover = modifiers.include?(:popover) @popover_id = popover_id if @popover # stimulus: true enables the controller; a String/Symbol enables AND # overrides the identifier. Only meaningful in :popover mode. @stimulus = stimulus super(*modifiers, as:, id:, **) end |
Instance Method Details
#button(*modifiers, **options) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/daisy_ui/dropdown.rb', line 46 def (*modifiers, **, &) if popover? render Button.new(*modifiers, as: :button, **(), &) elsif tap_to_close? render Button.new(*modifiers, as: :summary, **, &) else render Button.new(*modifiers, as: :div, role: :button, tabindex: 0, **, &) end end |
#content(*modifiers, as: :div, **options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/daisy_ui/dropdown.rb', line 56 def content(*modifiers, as: :div, **, &) return render_as(*modifiers, as:, **(), &) if popover? content_classes = component_classes("dropdown-content", options:) if tap_to_close? render_as(*modifiers, as:, class: content_classes, **, &) else render_as(*modifiers, as:, tabindex: 0, class: content_classes, **, &) end end |
#menu(*modifiers, **options) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/daisy_ui/dropdown.rb', line 68 def (*modifiers, **, &) if popover? [:role] ||= "menu" return render Menu.new(*modifiers, **(), &) end = component_classes("dropdown-content", options:) if tap_to_close? render Menu.new(*modifiers, class: , **, &) else render Menu.new(*modifiers, tabindex: 0, class: , **, &) end end |
#popover? ⇒ Boolean
83 84 85 |
# File 'lib/daisy_ui/dropdown.rb', line 83 def popover? modifiers.include?(:popover) end |
#tap_to_close? ⇒ Boolean
87 88 89 |
# File 'lib/daisy_ui/dropdown.rb', line 87 def tap_to_close? modifiers.include?(:tap_to_close) end |
#view_template ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/daisy_ui/dropdown.rb', line 26 def view_template if popover? # DaisyUI's popover variant is a FLAT structure: the trigger button and # the popover menu are siblings, and `dropdown` + the placement class # ride the popover element (that is what carries `position-area`). The # wrapper here is a plain, non-positioning container. public_send(as, **popover_root_attributes) do yield self if block_given? end elsif tap_to_close? details(class: classes, **attributes) do yield self if block_given? end else public_send(as, class: classes, **attributes) do yield self if block_given? end end end |