Module: Spree::Admin::DialogHelper

Defined in:
app/helpers/spree/admin/dialog_helper.rb

Instance Method Summary collapse

Instance Method Details

#dialog(id: nil, controller_name: 'dialog', **html_options) { ... } ⇒ String

Renders a dialog container element

Examples:

Basic usage

<%= dialog do %>
  <%= dialog_header("Confirm Delete") %>
  <div class="dialog-body">Are you sure?</div>
  <div class="dialog-footer">
    <%= dialog_discard_button %>
    <%= button_tag "Delete", class: "btn btn-danger" %>
  </div>
<% end %>

With custom id and controller

<%= dialog(id: 'my-dialog', controller_name: 'custom-dialog') do %>
  ...
<% end %>

Parameters:

  • id (String, nil) (defaults to: nil)

    the id of the dialog element

  • controller_name (String) (defaults to: 'dialog')

    the Stimulus controller name (default: ‘dialog’)

  • html_options (Hash)

    additional HTML attributes

Yields:

  • the content to render inside the dialog

Returns:

  • (String)

    the dialog HTML



25
26
27
28
29
30
31
32
# File 'app/helpers/spree/admin/dialog_helper.rb', line 25

def dialog(id: nil, controller_name: 'dialog', **html_options, &block)
  html_options[:class] = "dialog #{html_options[:class]}".strip
  html_options[:data] ||= {}
  html_options[:data]["#{controller_name}-target".to_sym] = 'dialog'
  html_options[:id] = id if id.present?

  (:dialog, html_options, &block)
end

#dialog_close_button(controller_name = 'dialog') ⇒ Object



40
41
42
# File 'app/helpers/spree/admin/dialog_helper.rb', line 40

def dialog_close_button(controller_name = 'dialog')
  button_tag('', type: 'button', class: 'btn-close', data: { action: "#{controller_name}#close", dismiss: controller_name, aria_label: Spree.t(:close) }).html_safe
end

#dialog_discard_button(controller_name = 'dialog') ⇒ Object



44
45
46
47
48
# File 'app/helpers/spree/admin/dialog_helper.rb', line 44

def dialog_discard_button(controller_name = 'dialog')
  button_tag(type: 'button', class: 'btn btn-light', data: { action: "#{controller_name}#close", dismiss: controller_name }) do
    Spree.t('actions.discard')
  end.html_safe
end

#dialog_header(title, controller_name = 'dialog') ⇒ Object



34
35
36
37
38
# File 'app/helpers/spree/admin/dialog_helper.rb', line 34

def dialog_header(title, controller_name = 'dialog')
  (:div, class: 'dialog-header') do
    (:h5, title, class: 'dialog-title') + dialog_close_button(controller_name)
  end.html_safe
end