Skip to content

Commit

Permalink
[#25,#5, #27] Header / Nav / Banner / Utility Menu (#124)
Browse files Browse the repository at this point in the history
* government banner
* header
* mobile nav

Co-authored-by: Stephen Chudleigh <[email protected]>

* shared specs for utility menu
* increase threshold for similar code

---------

Co-authored-by: Stephen Chudleigh <[email protected]>
Co-authored-by: Stephen Chudleigh <[email protected]>
  • Loading branch information
3 people authored Sep 3, 2024
1 parent 5a60d7e commit 39dee1e
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 17 deletions.
8 changes: 5 additions & 3 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
version: '2'
checks:
similar-code:
config:
threshold: 75
plugins:
brakeman:
enabled: true
Expand All @@ -11,6 +15,4 @@ exclude_patterns:
- db/
- vendor/
- "**/vendor/**/*"
- app/assets/images/
- app/assets/stylesheets/uswds.css
- app/assets/stylesheets/uswds_override.css
- app/assets/images/
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ group :development, :test do

gem "rspec-rails"

gem 'pry'

# add the Ruby LSP package so it's bundled with the rest of the gems and available to VS Code
gem "ruby-lsp"

Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ GEM
xpath (~> 3.2)
codeclimate-test-reporter (1.0.7)
simplecov
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crack (1.0.0)
Expand Down Expand Up @@ -145,6 +146,7 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.25.1)
msgpack (1.7.2)
Expand Down Expand Up @@ -183,6 +185,9 @@ GEM
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.1.2)
stringio
public_suffix (6.0.1)
Expand Down Expand Up @@ -360,6 +365,7 @@ DEPENDENCIES
jwt
pg
propshaft (~> 0.9.0)
pry
puma (>= 5.0)
rails (~> 7.2.0)
rails-controller-testing
Expand Down
13 changes: 10 additions & 3 deletions app/assets/uswds/_uswds-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ USWDS with settings overrides
Add a list of changed settings in the form $setting: value.
----------------------------------------
*/

@use "uswds-core" with ($theme-image-path: "images",
$theme-font-path: "fonts"
@use "uswds-core" with (
$theme-image-path: "images",
$theme-font-path: "fonts",
$flex-direction-settings: (
responsive: true
)
);

@use "uswds" as *;
Expand Down Expand Up @@ -50,6 +53,10 @@ Add a list of changed settings in the form $setting: value.
filter: invert(14%) sepia(17%) saturate(4304%) hue-rotate(190deg) brightness(94%) contrast(92%);
}

.icon-white {
filter: invert(99%) sepia(2%) saturate(3661%) hue-rotate(191deg) brightness(117%) contrast(80%);
}

.usa-social-link {
background-color: white;
}
Expand Down
17 changes: 17 additions & 0 deletions app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module NavigationHelper
def utility_menu_link(image_path, href, alt, button_label)
link_to(href,
class: "display-flex flex-align-center flex-column desktop:flex-row " \
"margin-x-1 desktop:margin-x-3 text-white text-no-wrap") do
image_tag(
"images/usa-icons/#{image_path}.svg",
class: "usa-icon--size-4 desktop:usa-icon--size-3 icon-white desktop:margin-right-1",
alt:
) +
tag.span(button_label, class: "display-none desktop:display-block") +
tag.span(button_label, class: "desktop:display-none", style: "font-size: 0.7rem")
end
end
end
202 changes: 191 additions & 11 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,198 @@
<header class="usa-header usa-header--basic margin-bottom-2">
<div class="usa-nav-container">
<section
class="usa-banner"
aria-label="Official website of the United States government"
>
<div class="usa-accordion">
<header class="usa-banner__header">
<div class="usa-banner__inner">
<div class="grid-col-auto">
<img
aria-hidden="true"
class="usa-banner__header-flag"
src="<%= image_path('images/us_flag_small.png') %>"
alt=""
/>
</div>
<div class="grid-col-fill tablet:grid-col-auto" aria-hidden="true">
<p class="usa-banner__header-text">
An official website of the United States government
</p>
<p class="usa-banner__header-action">Here’s how you know</p>
</div>
<button
type="button"
class="usa-accordion__button usa-banner__button"
aria-expanded="false"
aria-controls="gov-banner-default"
>
<span class="usa-banner__button-text">Here’s how you know</span>
</button>
</div>
</header>
<div
class="usa-banner__content usa-accordion__content"
id="gov-banner-default"
>
<div class="grid-row grid-gap-lg">
<div class="usa-banner__guidance tablet:grid-col-6">
<img
class="usa-banner__icon usa-media-block__img"
src="<%= image_path('images/icon-dot-gov.svg') %>"
role="img"
alt=""
aria-hidden="true"
/>
<div class="usa-media-block__body">
<p>
<strong>Official websites use .gov</strong><br />A
<strong>.gov</strong> website belongs to an official government
organization in the United States.
</p>
</div>
</div>
<div class="usa-banner__guidance tablet:grid-col-6">
<img
class="usa-banner__icon usa-media-block__img"
src="<%= image_path('images/icon-https.svg') %>"
role="img"
alt=""
aria-hidden="true"
/>
<div class="usa-media-block__body">
<p>
<strong>Secure .gov websites use HTTPS</strong><br />A
<strong>lock</strong> (
<span class="icon-lock"
><svg
xmlns="http://www.w3.org/2000/svg"
width="52"
height="64"
viewBox="0 0 52 64"
class="usa-banner__lock-image"
role="img"
aria-labelledby="banner-lock-description-default"
focusable="false"
>
<title id="banner-lock-title-default">Lock</title>
<desc id="banner-lock-description-default">Locked padlock icon</desc>
<path
fill="#000000"
fill-rule="evenodd"
d="M26 0c10.493 0 19 8.507 19 19v9h3a4 4 0 0 1 4 4v28a4 4 0 0 1-4 4H4a4 4 0 0 1-4-4V32a4 4 0 0 1 4-4h3v-9C7 8.507 15.507 0 26 0zm0 8c-5.979 0-10.843 4.77-10.996 10.712L15 19v9h22v-9c0-6.075-4.925-11-11-11z"
/>
</svg> </span
>) or <strong>https://</strong> means you’ve safely connected to
the .gov website. Share sensitive information only on official,
secure websites.
</p>
</div>
</div>
</div>
</div>
</div>
<div class="usa-overlay"></div>
</section>
<header class="usa-header usa-header--basic site-header">
<div class="desktop:display-flex desktop:width-full">
<div class="usa-navbar">
<div class="usa-logo">
<em class="usa-logo__text">
<a href="/" title="Challenge Platform">Challenge Platform</a>
</em>
<em class="usa-logo__text"
><a href="/" title="challenge.gov">
<span class="site-title--long">
<img width="300" class="usa-header__logo-img margin-left-4 desktop:margin-left-2 desktop:margin-bottom-2" src="<%= image_path("challenge-logo.svg") %>" alt="" />
</span>
</a></em
>
</div>
<button type="button" class="usa-menu-btn">Menu</button>
</div>
<nav aria-label="Primary navigation" class="usa-nav">
<% if logged_in? %>
<%= button_to("Logout", session_path, method: :delete, class: "usa-button usa-nav-link", type: "button") %>
<% else %>
<%= button_to("Login", new_session_path, method: :get, class: "usa-button usa-nav-link", type: "button") %>
<% end %>
<button type="button" class="usa-nav__close">
<img src="<%= image_path('images/usa-icons/close.svg') %>" role="img" alt="Close" />
</button>
<ul class="usa-nav__primary usa-accordion flex-align-start">
<li class="usa-nav__primary-item">
<a href="/#active-challenges" class="usa-nav-link text-no-wrap"
><span>Find a Challenge</span></a
>
</li>
<li class="usa-nav__primary-item">
<a href="/resources" class="usa-nav-link"
><span>Resources</span></a
>
</li>
<li class="usa-nav__primary-item">
<a href="/events" class="usa-nav-link"
><span>Events</span></a
>
</li>
<li class="usa-nav__primary-item">
<a href="/contact" class="usa-nav-link"
><span>Contact</span></a
>
</li>
</ul>
<!-- Desktop search and login area -->
<section class="display-none desktop:display-flex">
<section aria-label="Search component">
<form class="usa-search usa-search--small" role="search">
<label class="usa-sr-only" for="search-field">Search</label>
<input
class="usa-input"
id="search-field"
type="search"
name="search"
style="width: 140px"
/>
<button class="usa-button" type="submit">
<img
src="<%= image_path('images/usa-icons-bg/search--white.svg') %>"
class="usa-search__submit-icon"
alt="Search"
/>
</button>
</form>
</section>
<% if logged_in? %>
<%= button_to("Logout", session_path, method: :delete, class: "usa-button font-body-3xs usa-button--outline text-no-wrap desktop:margin-left-1", type: "button") %>
<button class="usa-button font-body-2xs text-no-wrap">Switch Task</button>
<% else %>
<%= button_to("Login", new_session_path, method: :get, class: "usa-button font-body-3xs usa-button--outline text-no-wrap desktop:margin-left-1", type: "button") %>
<button class="usa-button font-body-2xs text-no-wrap">Create Account</button>
<% end %>
</section>
<!-- mobile search and login area -->
<section class="desktop:display-none order-3">
<section aria-label="Search component">
<form class="usa-search usa-search--small margin-y-1" role="search">
<label class="usa-sr-only" for="search-field">Search</label>
<input
class="usa-input"
id="search-field"
type="search"
name="search"
style="width: 170px"
/>
<button class="usa-button" type="submit">
<img
src="<%= image_path('images/usa-icons-bg/search--white.svg') %>"
class="usa-search__submit-icon"
alt="Search"
/>
</button>
</form>
</section>
<% if logged_in? %>
<div class="text-primary font-body-2xs margin-y-1 padding-top-1">
<%= current_user.email %>
</div>
<%= button_to("Logout", session_path, method: :delete, class: "usa-button font-body-3xs usa-button--outline margin-y-1 text-no-wrap desktop:margin-left-1 width-full", type: "button") %>
<button class="usa-button font-body-2xs text-no-wrap width-full margin-y-1">Switch Task</button>
<% else %>
<%= button_to("Login", new_session_path, method: :get, class: "usa-button font-body-3xs usa-button--outline margin-y-1 text-no-wrap desktop:margin-left-1 width-full", type: "button") %>
<button class="usa-button font-body-2xs text-no-wrap width-full margin-y-1">Create Account</button>
<% end %>
</section>
</nav>
</div>
</header>
</header>
22 changes: 22 additions & 0 deletions app/views/layouts/_utility_menu.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Utility Menu -->
<div class="bg-primary-darker w-full display-flex flex-justify-center desktop:flex-justify-end padding-1 font-body-3xs desktop:font-body-2xs text-white">
<%= utility_menu_link('grid_view', 'dashboard', 'dashboard', 'Dashboard') %>
<% if current_user.role == "challenge_manager" %>
<%= utility_menu_link('emoji_events', 'http://localhost:4000/', 'challenges', 'Challenges') %>
<%= utility_menu_link('content_copy', 'evaluation_forms', 'Evaluation Forms', 'Evaluations') %>
<%= utility_menu_link('folder_open', 'manage_submissions', 'Manage Submissions', 'Submissions') %>
<% end %>
<% if current_user.role == "evaluator" %>
<%= utility_menu_link('content_copy', 'evaluations', 'Evaluate Submissions', 'Evaluations') %>
<% end %>
<% if current_user.role == "solver" %>
<%= utility_menu_link('folder_open', 'submissions', 'submissions', 'Submissions') %>
<% end %>
<%= utility_menu_link('map', 'user_guide', 'user guides', 'User Guides') %>
<%= utility_menu_link('support_agent', 'federal-agency-faqs', 'help', 'Help') %>
<div class="display-none desktop:display-flex flex-align-center margin-x-1 margin-top-1">
|
<%= image_tag('images/usa-icons/account_circle.svg', class: "usa-icon--size-3 icon-white margin-x-2", alt: "Help") %>
<%= current_user.email %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

<body>
<%= render "layouts/header" %>
<% if logged_in? %>
<%= render "layouts/utility_menu" %>
<% end %>
<%= render "shared/flash" %>

<%= yield %>
Expand Down
Loading

0 comments on commit 39dee1e

Please sign in to comment.