Skip to content

Commit 526c79e

Browse files
authored
Merge pull request #98 from opf/feature/zen-mode-button-slot-for-page-header
Add a slot for a zenModeButton to the PageHeader
2 parents c725745 + 37560d8 commit 526c79e

9 files changed

Lines changed: 45 additions & 3 deletions

File tree

.changeset/chilled-doors-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@openproject/primer-view-components": minor
3+
---
4+
5+
Add a slot for Primer::OpenProject::ZenModeButton to the Primer::OpenProject::PageHeader
73 Bytes
Loading
272 Bytes
Loading

app/components/primer/open_project/page_header.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class PageHeader < Primer::Component
7171

7272
Primer::Beta::Button.new(**system_arguments)
7373
},
74+
zen_mode_button: lambda { |mobile_icon: Primer::OpenProject::ZenModeButton::ZEN_MODE_BUTTON_ICON, mobile_label: Primer::OpenProject::ZenModeButton::ZEN_MODE_BUTTON_LABEL, **system_arguments|
75+
deny_tag_argument(**system_arguments)
76+
system_arguments = set_action_arguments(system_arguments, scheme: DEFAULT_ACTION_SCHEME)
77+
add_option_to_mobile_menu(system_arguments, mobile_icon, mobile_label, DEFAULT_ACTION_SCHEME)
78+
79+
Primer::OpenProject::ZenModeButton.new(**system_arguments)
80+
},
81+
7482
link: lambda { |mobile_icon:, mobile_label:, scheme: DEFAULT_ACTION_SCHEME, **system_arguments|
7583
deny_tag_argument(**system_arguments)
7684
system_arguments = set_action_arguments(system_arguments, scheme: scheme)

app/components/primer/open_project/zen_mode_button.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Primer::Beta::IconButton.new(
44
scheme: :default,
55
id: "zenModeButton",
6-
icon: "screen-normal",
7-
aria: { label: I18n.t("zen_mode") },
6+
icon: ZEN_MODE_BUTTON_ICON,
7+
aria: { label: ZEN_MODE_BUTTON_LABEL },
88
data: { target: "zen-mode-button.button", action: "click:zen-mode-button#performAction" }
99
)
1010
) %>

app/components/primer/open_project/zen_mode_button.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module OpenProject
88
class ZenModeButton < Primer::Component
99
status :open_project
1010

11+
ZEN_MODE_BUTTON_LABEL = I18n.t("label_zen_mode")
12+
ZEN_MODE_BUTTON_ICON = "screen-full"
13+
1114
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
1215
def initialize(**system_arguments)
1316
@system_arguments = system_arguments

previews/primer/open_project/page_header_preview.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ def dialog_actions
104104
end
105105
end
106106

107+
# @label With a ZenModeButton inside the actions
108+
# The missing label will be resolved automatically when included into the core
109+
def zen_mode_button_actions
110+
render(Primer::OpenProject::PageHeader.new) do |component|
111+
component.with_title { "Great news" }
112+
component.with_breadcrumbs([{ href: "/foo", text: "Foo" }, { href: "/bar", text: "Bar" }, "Baz"])
113+
114+
# The missing label will be resolved automatically when included into the core
115+
component.with_action_zen_mode_button
116+
component.with_action_button(mobile_icon: "plus", mobile_label: "Meeting", scheme: :primary) do |button|
117+
button.with_leading_visual_icon(icon: "plus")
118+
"Meeting"
119+
end
120+
end
121+
end
122+
107123
# @label With leading action (on wide)
108124
# **Leading action** is only shown on **wide screens** by default.
109125
# If you want to override that behaviour please use the system_argument: **display**

test/components/primer/open_project/page_header_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ def test_renders_a_dialog_as_action
133133
assert_selector("dialog#my-dialog")
134134
end
135135

136+
def test_renders_a_zen_mode_button_as_action
137+
render_inline(Primer::OpenProject::PageHeader.new) do |header|
138+
header.with_title { "Hello" }
139+
header.with_breadcrumbs(breadcrumb_elements)
140+
header.with_action_zen_mode_button
141+
end
142+
143+
assert_selector(".PageHeader-actions zen-mode-button")
144+
end
145+
136146
def test_renders_single_action
137147
render_inline(Primer::OpenProject::PageHeader.new) do |header|
138148
header.with_title { "Hello" }

test/components/primer/open_project/zen_mode_button_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class PrimerOpenProjectZenModeButtonTest < Minitest::Test
88
def test_renders
99
render_inline(Primer::OpenProject::ZenModeButton.new)
1010

11-
assert_selector(".ZenModeButton .octicon-screen-normal")
11+
assert_selector(".ZenModeButton .octicon-screen-full")
1212
end
1313
end

0 commit comments

Comments
 (0)