Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Add USWDS icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed May 22, 2024
1 parent 74077ae commit 0120c7b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/public/img/uswds-sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions frontend/src/components/USWDSIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import SpriteSVG from "public/img/uswds-sprite.svg";

interface IconProps {
name: string;
className: string;
height?: string;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const sprite_uri = SpriteSVG.src as string;

export function USWDSIcon(props: IconProps) {
return (
<svg
className={props.className}
aria-hidden="true"
height={props.height}
role="img"
>
<use href={`${sprite_uri}#${props.name}`}></use>
</svg>
);
}
12 changes: 12 additions & 0 deletions frontend/tests/components/USWDSIcon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { render, screen } from "tests/react-utils";

import { USWDSIcon } from "src/components/USWDSIcon";

describe("USWDSIcon", () => {
it("Renders without errors", () => {
render(<USWDSIcon className="usa-icon" name="search" />);
const icon = screen.getByRole("img", { hidden: true });
expect(icon).toBeInTheDocument();
expect(icon).toHaveClass("usa-icon");
});
});

0 comments on commit 0120c7b

Please sign in to comment.