Module: UI::SheetOverlayBehavior

Included in:
SheetOverlay, SheetOverlayComponent
Defined in:
app/behaviors/ui/sheet_overlay_behavior.rb

Overview

Shared behavior for Sheet Overlay component Handles backdrop/overlay styling and attributes

Instance Method Summary collapse

Instance Method Details

#merged_sheet_overlay_container_data_attributesObject

Merge user-provided data attributes for container



47
48
49
50
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 47

def merged_sheet_overlay_container_data_attributes
  user_data = @attributes&.fetch(:data, {}) || {}
  user_data.merge(sheet_overlay_container_data_attributes)
end

#sheet_overlay_base_classesObject

Base CSS classes for overlay backdrop data- prevents exit animation on page load



10
11
12
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 10

def sheet_overlay_base_classes
  "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:opacity-0 data-[state=open]:opacity-100 data-[state=open]:pointer-events-auto data-[state=closed]:pointer-events-none data-[initial]:animate-none data-[initial]:opacity-0 fixed inset-0 z-50 bg-black/50"
end

#sheet_overlay_classesObject

Merge base classes with custom classes using TailwindMerge



15
16
17
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 15

def sheet_overlay_classes
  TailwindMerge::Merger.new.merge([sheet_overlay_base_classes].compact.join(" "))
end

#sheet_overlay_container_base_classesObject

Container wrapper classes Use data-:invisible to hide on page load without animations After first open, data-initial is removed and animations work normally



22
23
24
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 22

def sheet_overlay_container_base_classes
  "data-[initial]:invisible data-[state=closed]:pointer-events-none data-[state=open]:pointer-events-auto fixed inset-0 z-50"
end

#sheet_overlay_container_classesObject

Merge container base classes with custom classes



27
28
29
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 27

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

#sheet_overlay_container_data_attributesObject

Data attributes for container



32
33
34
35
36
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 32

def sheet_overlay_container_data_attributes
  {
    ui__dialog_target: "container"
  }
end

#sheet_overlay_container_html_attributesObject

Build complete HTML attributes hash for container wrapper



53
54
55
56
57
58
59
60
61
62
63
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 53

def sheet_overlay_container_html_attributes
  base_attrs = @attributes&.except(:data) || {}
  attrs = base_attrs.merge(
    class: sheet_overlay_container_classes,
    "data-state": @open ? "open" : "closed",
    data: merged_sheet_overlay_container_data_attributes
  )
  # Add data-initial when closed to prevent exit animations on page load
  attrs["data-initial"] = "" unless @open
  attrs
end

#sheet_overlay_data_attributesObject

Data attributes for overlay backdrop



39
40
41
42
43
44
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 39

def sheet_overlay_data_attributes
  {
    ui__dialog_target: "overlay",
    action: "click->ui--dialog#closeOnOverlayClick"
  }
end

#sheet_overlay_html_attributesObject

Build complete HTML attributes hash for overlay backdrop



66
67
68
69
70
71
72
73
74
75
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 66

def sheet_overlay_html_attributes
  attrs = {
    class: sheet_overlay_classes,
    "data-state": @open ? "open" : "closed",
    data: sheet_overlay_data_attributes
  }
  # Add data-initial when closed to prevent exit animations on page load
  attrs["data-initial"] = "" unless @open
  attrs
end