Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 17 additions & 7 deletions lib/composite/header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ function Logo({ homeUrl }) {
);
}

function Header({ links, title, subtitle, navRight, fluidNav, homeUrl }) {
function Header({
links,
title,
subtitle,
navRight,
fluidNav,
homeUrl,
collapseHeader = false,
}) {
const [showOverlayLinks, setShowOverlayLinks] = useState(false);
const navContainerClass = gwMerge(
"gw-w-full gw-mx-auto gw-px-4 gw-box-border",
Expand Down Expand Up @@ -72,14 +80,16 @@ function Header({ links, title, subtitle, navRight, fluidNav, homeUrl }) {
</div>
</div>
</div>
<div className="gw-min-h-4 gw-py-2 sm:gw-py-0 gw-bg-nav-dark-gray sm:gw-bg-nav-gray">
<div className={navContainerClass}>
<div className="gw-flex gw-justify-between gw-items-center">
<span className="sm:gw-w-[94px] gw-shrink-0 "></span>
<Title title={title} subtitle={subtitle} />
{!collapseHeader && (
<div className="gw-min-h-4 gw-py-2 sm:gw-py-0 gw-bg-nav-dark-gray sm:gw-bg-nav-gray">
<div className={navContainerClass}>
<div className="gw-flex gw-justify-between gw-items-center">
<span className="sm:gw-w-[94px] gw-shrink-0 "></span>
<Title title={title} subtitle={subtitle} />
</div>
</div>
</div>
</div>
)}
</div>
</header>
{showOverlayLinks ? (
Expand Down
4 changes: 3 additions & 1 deletion lib/composite/site-wrapper/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DoDWarning from "./dod-warning";
function SiteWrapper({
children,
navRight = undefined,
collapseHeader = false,
showFooter = true,
links,
usaBanner = true,
Expand Down Expand Up @@ -44,7 +45,7 @@ function SiteWrapper({
return (
<div className="gw-grid gw-min-h-[100vh] gw-grid-rows-1fr-auto">
<div>
{usaBanner && <USABanner fluidNav={fluidNav} />}
{usaBanner && !collapseHeader && <USABanner fluidNav={fluidNav} />}
{msgBanner && msgBannerPosition === "top" ? msgBanner : null}
<Header
links={links}
Expand All @@ -53,6 +54,7 @@ function SiteWrapper({
navRight={navRight}
fluidNav={fluidNav}
homeUrl={homeUrl}
collapseHeader={collapseHeader}
/>

{msgBanner && msgBannerPosition === "bottom" ? msgBanner : null}
Expand Down
38 changes: 38 additions & 0 deletions lib/composite/site-wrapper/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import SiteWrapper from ".";

const renderSiteWrapper = (props = {}) =>
renderToStaticMarkup(
<SiteWrapper
links={[{ id: "home", text: "Home", href: "/" }]}
title="Test site title"
subtitle="Test site subtitle"
navRight={<span>Account</span>}
showFooter={false}
{...props}
>
<main>Page content</main>
</SiteWrapper>,
);

describe("SiteWrapper collapseHeader", () => {
it("renders the complete header by default", () => {
const markup = renderSiteWrapper();

expect(markup).toContain("header_banner_container");
expect(markup).toContain("Test site title");
expect(markup).toContain("Test site subtitle");
});

it("keeps navigation controls while hiding the expanded header content", () => {
const markup = renderSiteWrapper({ collapseHeader: true });

expect(markup).not.toContain("header_banner_container");
expect(markup).not.toContain("Test site title");
expect(markup).not.toContain("Test site subtitle");
expect(markup).toContain("Account");
expect(markup).toContain("Visit the homepage of this site");
expect(markup).toContain("Page content");
});
});
16 changes: 16 additions & 0 deletions src/app-pages/documentation/app-shell/site-wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const siteWrapperProps = [
default: "null",
desc: "A custom component that will render to the right of the header links.",
},
{
name: "collapseHeader",
type: "boolean",
default: "false",
desc: "If true, displays only the compact black navigation bar. The government website banner and the title and subtitle section are hidden.",
},
{
name: "usaBanner",
type: "boolean",
Expand Down Expand Up @@ -237,6 +243,16 @@ function App() {

export default App;
`}
/>
<Text className="gw-pt-3">
Set <Code>collapseHeader</Code> when a page needs more vertical space.
The compact state keeps the home link, navigation, custom controls,
and mobile menu available.
</Text>
<CodeExample
code={`<SiteWrapper links={links} collapseHeader>
<Route />
</SiteWrapper>`}
/>
<div className="gw-font-bold gw-text-lg gw-pt-6">
Component API - <Code className="gw-p-2">{`<SiteWrapper />`}</Code>
Expand Down
Loading