forked from primer/view_components
-
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.
Merge pull request #96 from opf/feature/support-dialogs-in-pageheader
Support dialogs in pageheader
- Loading branch information
Showing
10 changed files
with
219 additions
and
46 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@openproject/primer-view-components": minor | ||
--- | ||
|
||
* Add support for Dialogs inside the Primer::OpenProject::PageHeader component | ||
* Limit the number of allowed actions to 5 |
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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
class PageHeader | ||
# A Helper class to create ActionMenus inside the PageHeader action slot | ||
# Do not use standalone | ||
class Dialog < Primer::Component | ||
status :open_project | ||
|
||
# @param dialog_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Dialog) %>. | ||
# @param button_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Button) %> or <%= link_to_component(Primer::Beta::IconButton) %>, depending on the value of the `icon:` argument. | ||
def initialize(dialog_arguments: {}, button_arguments: {}) | ||
callback = button_arguments.delete(:button_block) | ||
|
||
@dialog = Primer::Alpha::Dialog.new(**dialog_arguments) | ||
@button = @dialog.with_show_button(**button_arguments) do |button| | ||
callback&.call(button) | ||
end | ||
end | ||
|
||
def render_in(view_context, &block) | ||
super(view_context) do | ||
block&.call(@dialog, @button) | ||
end | ||
end | ||
|
||
def before_render | ||
content | ||
end | ||
|
||
def call | ||
render(@dialog) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
class PageHeader | ||
# A Helper class to create ActionMenus inside the PageHeader action slot | ||
# It should not be used standalone | ||
class Menu < Primer::Component | ||
status :open_project | ||
|
||
# @param menu_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu) %>. | ||
# @param button_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Beta::Button) %> or <%= link_to_component(Primer::Beta::IconButton) %>, depending on the value of the `icon:` argument. | ||
def initialize(menu_arguments: {}, button_arguments: {}) | ||
callback = button_arguments.delete(:button_block) | ||
|
||
@menu = Primer::Alpha::ActionMenu.new(**menu_arguments) | ||
@button = @menu.with_show_button(**button_arguments) do |button| | ||
callback&.call(button) | ||
end | ||
end | ||
|
||
def render_in(view_context, &block) | ||
super(view_context) do | ||
block&.call(@menu, @button) | ||
end | ||
end | ||
|
||
def before_render | ||
content | ||
end | ||
|
||
def call | ||
render(@menu) | ||
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
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
14 changes: 14 additions & 0 deletions
14
test/components/primer/open_project/page_header/dialog_test.rb
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require "components/test_helper" | ||
|
||
class PrimerOpenProjectPageHeaderDialogTest < Minitest::Test | ||
include Primer::ComponentTestHelpers | ||
|
||
def test_renders | ||
render_inline(Primer::OpenProject::PageHeader::Dialog.new(dialog_arguments: { id: "my_dialog", title: "A great dialog"}, | ||
button_arguments: { button_block: lambda { |b| "I AM A BUTTON" } })) | ||
|
||
assert_text("I AM A BUTTON") | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
test/components/primer/open_project/page_header/menu_test.rb
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require "components/test_helper" | ||
|
||
class PrimerOpenProjectPageHeaderMenuTest < Minitest::Test | ||
include Primer::ComponentTestHelpers | ||
|
||
def test_renders | ||
render_inline(Primer::OpenProject::PageHeader::Menu.new(menu_arguments: { anchor_align: :end }, | ||
button_arguments: { button_block: lambda { |b| "I AM A BUTTON" } })) do |menu| | ||
menu.with_item(label: "Subitem 1") | ||
end | ||
|
||
assert_text("I AM A BUTTON") | ||
assert_text("Subitem 1") | ||
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