Sha256: 555c35fb8caeb70e12ccf03661db88cc5954afe7127e6ae57f0161e600e19d68

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

module Trestle
  module ModalHelper
    def turbo_stream_modal(template: action_name)
      template = render_to_string template: action_name, prefixes: _prefixes, formats: [:html], layout: "trestle/modal"
      %(<turbo-stream action="modal"><template>#{template}</template></turbo-stream>).html_safe
    end

    def modal_options!(options)
      modal_options.merge!(options)
    end

    def modal_options
      @_modal_options ||= {}
    end

    def modal_wrapper_attributes
      {
        class: ["modal", "fade", modal_options[:wrapper_class]],
        tabindex: "-1",
        role: "dialog",
        data: {
          controller: ["modal", modal_options[:controller]].compact.join(" ")
        }
      }.deep_merge(modal_options.except(:class, :wrapper_class, :controller))
    end

    def modal_dialog_attributes
      {
        class: ["modal-dialog", modal_options[:class]],
        role: "document"
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trestle-0.10.0.pre app/helpers/trestle/modal_helper.rb