Module: UI::DrawerHandleBehavior

Included in:
DrawerHandle, DrawerHandleComponent
Defined in:
app/behaviors/ui/drawer_handle_behavior.rb

Overview

Shared behavior for Drawer Handle component Visual affordance for drag gesture (shown on bottom/top drawers only)

Instance Method Summary collapse

Instance Method Details

#drawer_handle_classesObject

Merge base classes with custom classes using TailwindMerge



18
19
20
# File 'app/behaviors/ui/drawer_handle_behavior.rb', line 18

def drawer_handle_classes
  TailwindMerge::Merger.new.merge([drawer_handle_container_base_classes, @classes].compact.join(" "))
end

#drawer_handle_container_base_classesObject

Base CSS classes for handle container



9
10
11
12
13
14
15
# File 'app/behaviors/ui/drawer_handle_behavior.rb', line 9

def drawer_handle_container_base_classes
  [
    "bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full",
    # Only show for bottom direction (matching shadcn/ui implementation)
    "group-data-[vaul-drawer-direction=bottom]/drawer-content:block"
  ].join(" ")
end

#drawer_handle_data_attributesObject

Data attributes for handle (Stimulus target only)



23
24
25
26
27
28
# File 'app/behaviors/ui/drawer_handle_behavior.rb', line 23

def drawer_handle_data_attributes
  user_data = @attributes&.fetch(:data, {}) || {}
  user_data.merge({
    ui__drawer_target: "handle"
  })
end

#drawer_handle_html_attributesObject

Build complete HTML attributes hash for handle



31
32
33
34
35
36
37
38
39
# File 'app/behaviors/ui/drawer_handle_behavior.rb', line 31

def drawer_handle_html_attributes
  base_attrs = @attributes&.except(:data) || {}
  base_attrs.merge(
    class: drawer_handle_classes,
    "aria-hidden": "true",
    "data-vaul-handle": "",
    data: drawer_handle_data_attributes
  )
end