Module: UI::DrawerBehavior
- Included in:
- Drawer, DrawerComponent
- Defined in:
- app/behaviors/ui/drawer_behavior.rb
Overview
UI::DrawerBehavior
Instance Method Summary collapse
-
#drawer_base_classes ⇒ Object
Base CSS classes.
-
#drawer_classes ⇒ Object
Generate final classes using TailwindMerge.
-
#drawer_data_attributes ⇒ Object
Generate data attributes for Stimulus controller.
-
#drawer_html_attributes ⇒ Object
Build complete HTML attributes hash.
-
#merged_drawer_data_attributes ⇒ Object
Merge user-provided data attributes.
Instance Method Details
#drawer_base_classes ⇒ Object
Base CSS classes
76 77 78 |
# File 'app/behaviors/ui/drawer_behavior.rb', line 76 def drawer_base_classes "" end |
#drawer_classes ⇒ Object
Generate final classes using TailwindMerge
81 82 83 |
# File 'app/behaviors/ui/drawer_behavior.rb', line 81 def drawer_classes TailwindMerge::Merger.new.merge([drawer_base_classes, @classes].compact.join(" ")) end |
#drawer_data_attributes ⇒ Object
Generate data attributes for Stimulus controller
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/behaviors/ui/drawer_behavior.rb', line 36 def drawer_data_attributes attrs = { controller: "ui--drawer", ui__drawer_open_value: @open, ui__drawer_direction_value: @direction, ui__drawer_dismissible_value: @dismissible, ui__drawer_modal_value: @modal } # Add snap points if provided if @snap_points && !@snap_points.empty? attrs[:ui__drawer_snap_points_value] = @snap_points.to_json attrs[:ui__drawer_active_snap_point_value] = @active_snap_point || -1 attrs[:ui__drawer_fade_from_index_value] = @fade_from_index || (@snap_points.length - 1) attrs[:ui__drawer_snap_to_sequential_point_value] = @snap_to_sequential_point if @snap_to_sequential_point end # Add advanced options attrs[:ui__drawer_handle_only_value] = @handle_only if @handle_only attrs[:ui__drawer_reposition_inputs_value] = @reposition_inputs if @reposition_inputs == false attrs end |
#drawer_html_attributes ⇒ Object
Build complete HTML attributes hash
67 68 69 70 71 72 73 |
# File 'app/behaviors/ui/drawer_behavior.rb', line 67 def drawer_html_attributes base_attrs = @attributes&.except(:data) || {} base_attrs.merge( class: drawer_classes, data: merged_drawer_data_attributes ) end |
#merged_drawer_data_attributes ⇒ Object
Merge user-provided data attributes
61 62 63 64 |
# File 'app/behaviors/ui/drawer_behavior.rb', line 61 def merged_drawer_data_attributes user_data = @attributes&.fetch(:data, {}) || {} user_data.merge(drawer_data_attributes) end |