Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update USA Banner component #37

Merged
merged 8 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ func (app *Application) handleBannerToggle(w http.ResponseWriter, r *http.Reques
action := r.PathValue("action")
var component templ.Component
if action == "close" {
component = components.UsaBanner()
component = components.UsaBanner("close")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! You could simplify it even further by removing this if statement and just doing component = components.UsaBanner(action)!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 done!

} else {
component = components.UsaBannerContents()
component = components.UsaBanner("open")
}

component.Render(r.Context(), w)
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/components/base.templ
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ templ Base() {
<script src="/assets/js/uswds-init.min.js"></script>
</head>
<body>
@UsaBanner()
@UsaBanner("close")
<header class="container cdc-header noindex" role="banner">
<div class="cdc-header__desktop">
<div class="cdc-page-offset">
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/components/base_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 0 additions & 58 deletions internal/ui/components/usa-banner-contents.templ

This file was deleted.

35 changes: 0 additions & 35 deletions internal/ui/components/usa-banner-contents_templ.go

This file was deleted.

17 changes: 14 additions & 3 deletions internal/ui/components/usa-banner.templ
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package components

templ UsaBanner() {
templ UsaBanner(action string) {
<div id="usa-banner" class="cdc-page-banner container noindex" aria-label="Official website of the United States government">
<div class="row cdc-site-gov-notice noindex noprint">
<div class="col-lg-11">
Expand All @@ -10,7 +10,11 @@ templ UsaBanner() {
</div>
<span>
<button
hx-get="/toggle-banner/open"
if action == "close" {
hx-get="/toggle-banner/open"
} else {
hx-get="/toggle-banner/close"
}
hx-trigger="click"
hx-target="#usa-banner"
hx-swap="outerHTML"
Expand All @@ -22,7 +26,14 @@ templ UsaBanner() {
</button>
</span>
</div>
<div class="collapse hide usa-accordion__content" id="gov-notice">
<div
if action == "close" {
class="collapse hide usa-accordion__content"
} else {
class="collapse show usa-accordion__content"
}
id="gov-notice"
>
<div class="row">
<div class="col-12 col-lg-6">
<img src="/assets/img/icon-dot-gov.svg" alt="" aria-hidden="true"/>
Expand Down
34 changes: 32 additions & 2 deletions internal/ui/components/usa-banner_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.