Class: UI::ResponsiveDialogComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ResponsiveDialogBehavior
Defined in:
app/view_components/ui/responsive_dialog_component.rb

Overview

ResponsiveDialog component (ViewComponent) Combines Dialog (desktop) and Drawer (mobile) with responsive switching

Hybrid CSS + Stimulus approach:

  • Renders both Dialog and Drawer

  • CSS hides one based on breakpoint (md:hidden / md:block)

  • Stimulus controller syncs state between them

Examples:

Basic usage

<%= render UI::ResponsiveDialogComponent.new do %>
  <!-- Content will be rendered in both Dialog and Drawer -->
  <form>...</form>
<% end %>

With custom breakpoint

<%= render UI::ResponsiveDialogComponent.new(
  breakpoint: 1024,
  direction: "right"
) do %>
  <!-- Content -->
<% end %>

Instance Method Summary collapse

Methods included from ResponsiveDialogBehavior

#merged_responsive_dialog_data_attributes, #responsive_dialog_base_classes, #responsive_dialog_classes, #responsive_dialog_data_attributes, #responsive_dialog_html_attributes

Constructor Details

#initialize(open: false, breakpoint: 768, direction: "bottom", classes: "", attributes: {}) ⇒ ResponsiveDialogComponent

Returns a new instance of ResponsiveDialogComponent.

Parameters:

  • open (Boolean) (defaults to: false)

    whether the dialog/drawer is open

  • breakpoint (Integer) (defaults to: 768)

    responsive breakpoint in pixels (default: 768 = md)

  • direction (String) (defaults to: "bottom")

    drawer direction: “bottom”, “top”, “left”, “right”

  • classes (String) (defaults to: "")

    additional CSS classes

  • attributes (Hash) (defaults to: {})

    additional HTML attributes



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/view_components/ui/responsive_dialog_component.rb', line 32

def initialize(
  open: false,
  breakpoint: 768,
  direction: "bottom",
  classes: "",
  attributes: {}
)
  @open = open
  @breakpoint = breakpoint
  @direction = direction
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



46
47
48
49
50
51
52
53
54
# File 'app/view_components/ui/responsive_dialog_component.rb', line 46

def call
  attrs = responsive_dialog_html_attributes
  attrs[:data] = attrs[:data].merge(@attributes.fetch(:data, {}))

   :div, **attrs.merge(@attributes.except(:data)) do
    # Mobile: Drawer (hidden on md and up)
    mobile_wrapper + desktop_wrapper
  end
end