Class: UltimateTurboModal::Base

Inherits:
Phlex::HTML
  • Object
show all
Includes:
Phlex::DeferredRenderWithMainContent
Defined in:
lib/ultimate_turbo_modal/base.rb

Direct Known Subclasses

Flavors::Tailwind, Flavors::Vanilla

Instance Method Summary collapse

Constructor Details

#initialize(advance: UltimateTurboModal.configuration.advance, allowed_click_outside_selector: UltimateTurboModal.configuration.allowed_click_outside_selector, close_button: UltimateTurboModal.configuration.close_button, close_button_data_action: "modal#hideModal", close_button_sr_label: "Close modal", footer_divider: UltimateTurboModal.configuration.footer_divider, header: UltimateTurboModal.configuration.header, header_divider: UltimateTurboModal.configuration.header_divider, padding: UltimateTurboModal.configuration.padding, content_div_data: nil, request: nil, title: nil) ⇒ Base

Returns a new instance of Base.

Parameters:

  • advance (Boolean) (defaults to: UltimateTurboModal.configuration.advance)

    Whether to update the browser history when opening and closing the modal

  • allowed_click_outside_selector (String) (defaults to: UltimateTurboModal.configuration.allowed_click_outside_selector)

    CSS selectors for elements that are allowed to be clicked outside of the modal without dismissing the modal

  • close_button (Boolean) (defaults to: UltimateTurboModal.configuration.close_button)

    Whether to show a close button

  • close_button_data_action (String) (defaults to: "modal#hideModal")

    ‘data-action` attribute for the close button

  • close_button_sr_label (String) (defaults to: "Close modal")

    Close button label for screen readers

  • footer_divider (Boolean) (defaults to: UltimateTurboModal.configuration.footer_divider)

    Whether to show a divider between the main content and the footer

  • header_divider (Boolean) (defaults to: UltimateTurboModal.configuration.header_divider)

    Whether to show a divider between the header and the main content

  • padding (Boolean) (defaults to: UltimateTurboModal.configuration.padding)

    Whether to add padding around the modal content

  • request (ActionDispatch::Request) (defaults to: nil)

    The current Rails request object

  • content_div_data (Hash) (defaults to: nil)

    ‘data` attribute for the div where the modal content will be rendered

  • title (String) (defaults to: nil)

    The title of the modal



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ultimate_turbo_modal/base.rb', line 16

def initialize(
  advance: UltimateTurboModal.configuration.advance,
  allowed_click_outside_selector: UltimateTurboModal.configuration.allowed_click_outside_selector,
  close_button: UltimateTurboModal.configuration.close_button,
  close_button_data_action: "modal#hideModal",
  close_button_sr_label: "Close modal",
  footer_divider: UltimateTurboModal.configuration.footer_divider,
  header: UltimateTurboModal.configuration.header,
  header_divider: UltimateTurboModal.configuration.header_divider,
  padding: UltimateTurboModal.configuration.padding,
  content_div_data: nil,
  request: nil, title: nil
)
  @advance = !!advance
  @advance_url = advance if advance.present? && advance.is_a?(String)
  @allowed_click_outside_selector = allowed_click_outside_selector
  @close_button = close_button
  @close_button_data_action = close_button_data_action
  @close_button_sr_label = close_button_sr_label
  @footer_divider = footer_divider
  @header = header
  @header_divider = header_divider
  @padding = padding
  @content_div_data = content_div_data
  @request = request
  @title = title

  unless self.class.include?(Turbo::FramesHelper)
    self.class.include Turbo::FramesHelper
    self.class.include Turbo::StreamsHelper
    self.class.include Phlex::Rails::Helpers::ContentTag
    self.class.include Phlex::Rails::Helpers::Routes
    self.class.include Phlex::Rails::Helpers::Tag
  end
end

Instance Method Details



70
71
72
# File 'lib/ultimate_turbo_modal/base.rb', line 70

def footer(&block)
  @footer = block
end

#template(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ultimate_turbo_modal/base.rb', line 52

def template(&block)
  if turbo_frame?
    turbo_frame_tag("modal") do
      modal(&block)
    end
  elsif turbo_stream?
    Turbo::StreamsHelper.turbo_stream_action_tag("update", target: "modal") do
      modal(&block)
    end
  else
    render block
  end
end

#title(&block) ⇒ Object



66
67
68
# File 'lib/ultimate_turbo_modal/base.rb', line 66

def title(&block)
  @title_block = block
end