-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
736474b
commit fbc50d9
Showing
8 changed files
with
131 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
Breadcrumb, | ||
BreadcrumbBar, | ||
BreadcrumbLink, | ||
GridContainer, | ||
} from "@trussworks/react-uswds"; | ||
|
||
export type Breadcrumb = { | ||
title: string; | ||
path: string; | ||
}; | ||
|
||
export type BreadcrumbList = Breadcrumb[]; | ||
|
||
type Props = { | ||
breadcrumbList: BreadcrumbList; | ||
}; | ||
|
||
const Breadcrumbs = ({ breadcrumbList }: Props) => { | ||
const rdfaMetadata = { | ||
ol: { | ||
vocab: "http://schema.org/", | ||
typeof: "BreadcrumbList", | ||
}, | ||
li: { | ||
property: "itemListElement", | ||
typeof: "ListItem", | ||
}, | ||
a: { | ||
property: "item", | ||
typeof: "WebPage", | ||
}, | ||
}; | ||
|
||
const breadcrumArray = breadcrumbList.map((breadcrumbInfo, i) => { | ||
return ( | ||
<Breadcrumb | ||
key={breadcrumbInfo.title + "-crumb"} | ||
current={i + 1 === breadcrumbList.length} | ||
{...rdfaMetadata.li} | ||
> | ||
{i + 1 !== breadcrumbList.length ? ( | ||
<BreadcrumbLink href={breadcrumbInfo.path} {...rdfaMetadata.a}> | ||
{} | ||
<span property="name">{breadcrumbInfo.title}</span> | ||
</BreadcrumbLink> | ||
) : ( | ||
<span property="name">{breadcrumbInfo.title}</span> | ||
)} | ||
<meta property="position" content={(i + 1).toString()} /> | ||
</Breadcrumb> | ||
); | ||
}); | ||
|
||
return ( | ||
<GridContainer | ||
className="padding-y-1 tablet:padding-y-3 desktop-lg:padding-y-6" | ||
data-testid="breadcrumb" | ||
> | ||
<BreadcrumbBar listProps={{ ...rdfaMetadata.ol }}> | ||
{breadcrumArray} | ||
</BreadcrumbBar> | ||
</GridContainer> | ||
); | ||
}; | ||
|
||
export default Breadcrumbs; |
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,8 @@ | ||
import { Breadcrumb, BreadcrumbList } from "src/components/Breadcrumbs"; | ||
|
||
const HOME: Breadcrumb = { title: "Home", path: "/" }; | ||
const RESEARCH: Breadcrumb = { title: "Research", path: "research/" }; | ||
const PROCESS: Breadcrumb = { title: "Process", path: "process/" }; | ||
|
||
export const RESEARCH_CRUMBS: BreadcrumbList = [HOME, RESEARCH]; | ||
export const PROCESS_CRUMBS: BreadcrumbList = [HOME, PROCESS]; |
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,36 @@ | ||
import { Meta } from "@storybook/react"; | ||
import { PROCESS_CRUMBS, RESEARCH_CRUMBS } from "src/constants/breadcrumbs"; | ||
|
||
import Breadcrumbs from "src/components/Breadcrumbs"; | ||
|
||
const meta: Meta<typeof Breadcrumbs> = { | ||
title: "Components/Breadcrumbs", | ||
component: Breadcrumbs, | ||
}; | ||
export default meta; | ||
|
||
export const Home = { | ||
parameters: { | ||
design: { | ||
type: "figma", | ||
url: "https://www.figma.com/file/lpKPdyTyLJB5JArxhGjJnE/beta.grants.gov?type=design&node-id=918%3A1698&mode=design&t=rKuHZ4QiepVfLvwq-1", | ||
}, | ||
}, | ||
args: { | ||
breadcrumbList: [{ title: "Home", path: "/" }], | ||
}, | ||
}; | ||
|
||
export const Research = { | ||
parameters: Home.parameters, | ||
args: { | ||
breadcrumbList: RESEARCH_CRUMBS, | ||
}, | ||
}; | ||
|
||
export const Process = { | ||
parameters: Home.parameters, | ||
args: { | ||
breadcrumbList: PROCESS_CRUMBS, | ||
}, | ||
}; |
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,12 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { RESEARCH_CRUMBS } from "src/constants/breadcrumbs"; | ||
|
||
import Breadcrumbs from "src/components/Breadcrumbs"; | ||
|
||
describe("Breadcrumb", () => { | ||
it("Renders without errors", () => { | ||
render(<Breadcrumbs breadcrumbList={RESEARCH_CRUMBS} />); | ||
const bc = screen.getByTestId("breadcrumb"); | ||
expect(bc).toBeInTheDocument(); | ||
}); | ||
}); |
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