-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new HeaderComponent to eventually replace Header
We retain the existing Header component for Publish while we design how the new header should work alongside the organisation switcher.
- Loading branch information
1 parent
a9961b3
commit ddda78b
Showing
10 changed files
with
127 additions
and
20 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
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,28 @@ | ||
<%= govuk_header homepage_url: "https://www.gov.uk", classes: ["app-header--wide-logo", "govuk-header--full-width-border", "govuk-header--#{colour}"] do |header| %> | ||
<% if current_user %> | ||
<% header.with_navigation_item(text: current_user.full_name, href: Settings.dfe_signin.profile) %> | ||
<% header.with_navigation_item text: "Sign out", href: sign_out_path %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if navigation_items %> | ||
<%= govuk_service_navigation(service_name:, service_url:) do |service_navigation| %> | ||
<% navigation_items.each do |navigation_item| %> | ||
<%= service_navigation.with_navigation_item text: navigation_item.text, href: navigation_item.href %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-phase-banner"> | ||
<p class="govuk-phase-banner__content"> | ||
<%= govuk_tag(**phase_banner_tag, classes: ["govuk-phase-banner__content__tag"]) %> | ||
|
||
<% if phase_banner_text? %> | ||
<span class="govuk-phase-banner__text"> | ||
<%= sanitize phase_banner_text.to_s %> | ||
</span> | ||
<% end %> | ||
</p> | ||
</div> | ||
</div> |
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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
class HeaderComponent < ApplicationComponent | ||
renders_many :navigation_items, 'NavigationItemComponent' | ||
|
||
renders_one :phase_banner_text, ->(text) { text } | ||
|
||
def initialize(service_name:, service_url: nil, current_user: nil, classes: [], html_attributes: {}) | ||
super(classes:, html_attributes:) | ||
|
||
@service_name = service_name | ||
@service_url = service_url | ||
@current_user = current_user | ||
end | ||
|
||
private | ||
|
||
attr_reader :service_name, :current_user | ||
|
||
def service_url | ||
@service_url || root_path | ||
end | ||
|
||
def phase_banner_tag | ||
{ | ||
text: Settings.environment.label, | ||
colour: | ||
} | ||
end | ||
|
||
def colour | ||
{ | ||
development: 'grey', | ||
production: 'blue', | ||
review: 'purple', | ||
sandbox: 'purple', | ||
staging: 'red', | ||
qa: 'orange' | ||
}.fetch(Settings.environment.name.to_sym, 'grey') | ||
end | ||
|
||
class NavigationItemComponent < ApplicationComponent | ||
attr_reader :text, :href | ||
|
||
def initialize(text, href, classes: [], html_attributes: {}) | ||
super(classes:, html_attributes:) | ||
|
||
@text = text | ||
@href = href | ||
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
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class HeaderComponentPreview < ViewComponent::Preview | ||
def default | ||
render HeaderComponent.new(service_name: 'Service Name') | ||
end | ||
|
||
def with_service_navigation | ||
render HeaderComponent.new(service_name: 'Find and Publish support console') do |header| | ||
header.with_navigation_item('Home', '/') | ||
header.with_navigation_item('Home', '/') | ||
end | ||
end | ||
end |