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
-
#merged_sheet_overlay_container_data_attributes ⇒ Object
Merge user-provided data attributes for container.
-
#sheet_overlay_base_classes ⇒ Object
Base CSS classes for overlay backdrop data- prevents exit animation on page load.
-
#sheet_overlay_classes ⇒ Object
Merge base classes with custom classes using TailwindMerge.
-
#sheet_overlay_container_base_classes ⇒ Object
Container wrapper classes Use data-:invisible to hide on page load without animations After first open, data-initial is removed and animations work normally.
-
#sheet_overlay_container_classes ⇒ Object
Merge container base classes with custom classes.
-
#sheet_overlay_container_data_attributes ⇒ Object
Data attributes for container.
-
#sheet_overlay_container_html_attributes ⇒ Object
Build complete HTML attributes hash for container wrapper.
-
#sheet_overlay_data_attributes ⇒ Object
Data attributes for overlay backdrop.
-
#sheet_overlay_html_attributes ⇒ Object
Build complete HTML attributes hash for overlay backdrop.
Instance Method Details
#merged_sheet_overlay_container_data_attributes ⇒ Object
Merge user-provided data attributes for container
47 48 49 50 |
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 47 def user_data = @attributes&.fetch(:data, {}) || {} user_data.merge() end |
#sheet_overlay_base_classes ⇒ Object
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 "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_classes ⇒ Object
Merge base classes with custom classes using TailwindMerge
15 16 17 |
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 15 def TailwindMerge::Merger.new.merge([].compact.join(" ")) end |
#sheet_overlay_container_base_classes ⇒ Object
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 "data-[initial]:invisible data-[state=closed]:pointer-events-none data-[state=open]:pointer-events-auto fixed inset-0 z-50" end |
#sheet_overlay_container_classes ⇒ Object
Merge container base classes with custom classes
27 28 29 |
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 27 def TailwindMerge::Merger.new.merge([, @classes].compact.join(" ")) end |
#sheet_overlay_container_data_attributes ⇒ Object
Data attributes for container
32 33 34 35 36 |
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 32 def { ui__dialog_target: "container" } end |
#sheet_overlay_container_html_attributes ⇒ Object
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 base_attrs = @attributes&.except(:data) || {} attrs = base_attrs.merge( class: , "data-state": @open ? "open" : "closed", data: ) # Add data-initial when closed to prevent exit animations on page load attrs["data-initial"] = "" unless @open attrs end |
#sheet_overlay_data_attributes ⇒ Object
Data attributes for overlay backdrop
39 40 41 42 43 44 |
# File 'app/behaviors/ui/sheet_overlay_behavior.rb', line 39 def { ui__dialog_target: "overlay", action: "click->ui--dialog#closeOnOverlayClick" } end |
#sheet_overlay_html_attributes ⇒ Object
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 attrs = { class: , "data-state": @open ? "open" : "closed", data: } # Add data-initial when closed to prevent exit animations on page load attrs["data-initial"] = "" unless @open attrs end |