Module: RailsModalManager::ModalHelper

Defined in:
app/helpers/rails_modal_manager/modal_helper.rb

Defined Under Namespace

Modules: Icons

Instance Method Summary collapse

Instance Method Details

Helper to create footer buttons array

Examples:

rmm_footer_buttons([
  { id: "cancel", label: "Cancel", variant: "secondary" },
  { id: "save", label: "Save", variant: "primary" }
])

Parameters:

  • buttons (Array<Hash>)

    Array of button definitions

Returns:

  • (Array<Hash>)

    Formatted footer buttons



127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 127

def rmm_footer_buttons(buttons)
  buttons.map do |btn|
    {
      id: btn[:id],
      label: btn[:label],
      variant: btn[:variant] || "secondary",
      disabled: btn[:disabled] || false,
      loading: btn[:loading] || false,
      action: btn[:action]
    }
  end
end

#rmm_icon(name) ⇒ Object

Helper method to get icon SVG



208
209
210
211
212
213
214
215
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 208

def rmm_icon(name)
  method_name = name.to_s.downcase
  if RailsModalManager::ModalHelper::Icons.respond_to?(method_name)
    RailsModalManager::ModalHelper::Icons.send(method_name).html_safe
  else
    ""
  end
end

#rmm_modal(modal_id, options = {}) { ... } ⇒ String

Render a modal component

Examples:

Basic modal

<%= rmm_modal "my-modal", title: "Hello" do %>
  <p>Modal content here</p>
<% end %>

Full-featured modal

<%= rmm_modal "settings-modal",
  title: "Settings",
  size: "lg",
  draggable: true,
  resizable: true,
  minimizable: true,
  show_sidebar: true,
  show_footer: true,
  sidebar_items: [
    { id: "general", label: "General", icon_svg: icon_svg, active: true },
    { id: "account", label: "Account", icon_svg: icon_svg }
  ],
  footer_buttons: [
    { id: "cancel", label: "Cancel", variant: "secondary" },
    { id: "save", label: "Save", variant: "primary" }
  ] do %>
  <div class="p-4">Settings content</div>
<% end %>

Parameters:

  • modal_id (String)

    Unique modal identifier

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

    Modal options

Yields:

  • Modal content block

Returns:

  • (String)

    Rendered modal HTML



37
38
39
40
41
42
43
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 37

def rmm_modal(modal_id, options = {}, &block)
  content = block_given? ? capture(&block) : nil
  render(
    partial: "rails_modal_manager/modal",
    locals: options.merge(modal_id: modal_id, block_content: content)
  )
end

#rmm_open_button(modal_id, label, options = {}) ⇒ String

Generate a button that opens a modal

Examples:

<%= rmm_open_button "my-modal", "Open Modal", class: "btn btn-primary" %>

Parameters:

  • modal_id (String)

    The modal ID to open

  • label (String)

    Button label

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

    Button HTML options

Returns:

  • (String)

    Button HTML



67
68
69
70
71
72
73
74
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 67

def rmm_open_button(modal_id, label, options = {})
  options[:type] ||= "button"
  options[:data] ||= {}
  options[:data][:action] = "click->rmm-modal#open"
  options[:data][:rmm_modal_id] = modal_id

  (:button, label, options)
end

Generate a link that opens a modal

Parameters:

  • modal_id (String)

    The modal ID to open

  • label (String)

    Link label

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

    Link HTML options

Returns:

  • (String)

    Link HTML



83
84
85
86
87
88
89
90
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 83

def rmm_open_link(modal_id, label, options = {})
  options[:href] ||= "#"
  options[:data] ||= {}
  options[:data][:action] = "click->rmm-modal#open"
  options[:data][:rmm_modal_id] = modal_id

  (:a, label, options)
end

#rmm_sidebar_items(items) ⇒ Array<Hash>

Helper to create sidebar items array

Examples:

rmm_sidebar_items([
  { id: "home", label: "Home", icon: "home", active: true },
  { id: "settings", label: "Settings", icon: "settings", badge: "3" }
])

Parameters:

  • items (Array<Hash>)

    Array of item definitions

Returns:

  • (Array<Hash>)

    Formatted sidebar items



103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 103

def rmm_sidebar_items(items)
  items.map do |item|
    {
      id: item[:id],
      label: item[:label],
      icon_svg: item[:icon_svg] || item[:icon],
      badge: item[:badge],
      active: item[:active] || false,
      disabled: item[:disabled] || false
    }
  end
end

#rmm_taskbarString

Render the global taskbar component Should be included once in the layout, typically at the end of body

Examples:

In layout

<%= rmm_taskbar %>

Returns:

  • (String)

    Rendered taskbar HTML



53
54
55
# File 'app/helpers/rails_modal_manager/modal_helper.rb', line 53

def rmm_taskbar
  render partial: "rails_modal_manager/taskbar"
end