Module: UI::DropdownMenuCheckboxItemBehavior
- Included in:
- DropdownMenuCheckboxItem, DropdownMenuCheckboxItemComponent
- Defined in:
- app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb
Overview
DropdownMenuCheckboxItemBehavior
Shared behavior for DropdownMenuCheckboxItem component across ERB, ViewComponent, and Phlex implementations.
Instance Method Summary collapse
-
#checkbox_indicator ⇒ Object
Renders the checkbox indicator.
-
#dropdown_menu_checkbox_item_classes ⇒ Object
Returns combined CSS classes for the checkbox item.
-
#dropdown_menu_checkbox_item_data_attributes ⇒ Object
Returns data attributes for Stimulus.
-
#dropdown_menu_checkbox_item_html_attributes ⇒ Object
Returns HTML attributes for the checkbox item.
Instance Method Details
#checkbox_indicator ⇒ Object
Renders the checkbox indicator
40 41 42 43 |
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 40 def checkbox_indicator # This will be implemented in the actual components @checked end |
#dropdown_menu_checkbox_item_classes ⇒ Object
Returns combined CSS classes for the checkbox item
19 20 21 22 23 24 |
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 19 def classes_value = respond_to?(:classes, true) ? classes : @classes base_classes = "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4" TailwindMerge::Merger.new.merge([base_classes, classes_value].compact.join(" ")) end |
#dropdown_menu_checkbox_item_data_attributes ⇒ Object
Returns data attributes for Stimulus
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 27 def attributes_value = respond_to?(:attributes, true) ? attributes : @attributes data_attrs = (attributes_value&.fetch(:data, {}) || {}).merge({ "ui--dropdown-target": "item", action: "mouseenter->ui--dropdown#trackHoveredItem click->ui--dropdown#toggleCheckbox", state: @checked ? "checked" : "unchecked" }) data_attrs[:disabled] = true if @disabled data_attrs end |
#dropdown_menu_checkbox_item_html_attributes ⇒ Object
Returns HTML attributes for the checkbox item
8 9 10 11 12 13 14 15 16 |
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 8 def { class: , data: , role: "menuitemcheckbox", "aria-checked": @checked, tabindex: "-1" } end |