-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move kpop_redirect_to and kpop_dismiss to turbo_stream.kpop.*
- Loading branch information
Showing
7 changed files
with
76 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ PATH | |
specs: | ||
katalyst-kpop (3.0.0.pre.alpha.1) | ||
html-attributes-utils | ||
turbo-rails | ||
view_component | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require "katalyst/kpop/engine" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Turbo | ||
class TagBuilder | ||
delegate :action, :append, :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", **, &) | ||
@builder.action(:kpop_open, id, content, **, &) | ||
end | ||
|
||
# Render a turbo stream action that will dismiss any open kpop modal. | ||
def dismiss(id: "kpop") | ||
append(id) do | ||
tag.div("", data: { | ||
controller: "kpop--close", | ||
kpop__close_kpop__frame_outlet: "##{id}", | ||
turbo_temporary: "", | ||
}) | ||
end | ||
end | ||
|
||
# Renders a kpop redirect controller response that will escape the frame and navigate to the given URL. | ||
def redirect_to(url, id: "kpop", target: nil) | ||
append(id) do | ||
tag.div("", data: { | ||
controller: "kpop--redirect", | ||
kpop__redirect_kpop__frame_outlet: "##{id}", | ||
kpop__redirect_path_value: url, | ||
kpop__redirect_target_value: target, | ||
turbo_temporary: "", | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters