Sha256: c1cb60429cbe99c181959e1588d4ef9b0a9b8f41019d2bff4199700c6cd99ff7

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Kpop
    module Turbo
      class TagBuilder
        delegate :action, :turbo_stream_action_tag, to: :@builder

        def initialize(builder)
          @builder = builder
        end

        # Open a modal in the kpop frame identified by <tt>id</tt> either the <tt>content</tt> passed in or a
        # rendering result determined by the <tt>rendering</tt> keyword arguments, the content in the block,
        # or the rendering of the content as a record. Examples:
        #
        #   <%= turbo_stream.kpop.open modal %>
        #   <%= turbo_stream.kpop.open partial: "modals/modal", locals: { record: } %>
        #   <%= turbo_stream.kpop.open do %>
        #     <%= render Kpop::ModalComponent.new(title: "Example") do %>
        #       ...
        #     <% end %>
        #   <% end %>
        def open(content = nil, id: "kpop", **, &)
          action(:kpop_open, id, content, **, &)
        end

        # Render a turbo stream action that will dismiss any open kpop modal.
        def dismiss(id: "kpop")
          turbo_stream_action_tag(:kpop_dismiss, target: id)
        end

        # Renders a kpop redirect controller response that will escape the frame and navigate to the given URL.
        # Note: turbo does not currently snapshot page history accurately when using "advance" (Oct 23).
        def redirect_to(href, id: "kpop", action: "replace", target: nil)
          turbo_stream_action_tag(
            :kpop_redirect_to,
            target: id,
            href:,
            data:   {
              turbo_action: action,
              turbo_frame:  target,
            },
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
katalyst-kpop-3.2.6 lib/katalyst/kpop/turbo.rb
katalyst-kpop-3.2.5 lib/katalyst/kpop/turbo.rb
katalyst-kpop-3.2.4 lib/katalyst/kpop/turbo.rb
katalyst-kpop-3.2.3 lib/katalyst/kpop/turbo.rb
katalyst-kpop-3.2.2 lib/katalyst/kpop/turbo.rb
katalyst-kpop-3.2.1 lib/katalyst/kpop/turbo.rb
katalyst-kpop-3.2.0 lib/katalyst/kpop/turbo.rb