Skip to content

Commit

Permalink
simplify Image component interface, add react-inlinesvg dependency, c…
Browse files Browse the repository at this point in the history
…onvert svgs into inline components (#1561)
  • Loading branch information
Spencer6497 authored Dec 23, 2024
1 parent 8d643e4 commit 97dbe38
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
6 changes: 1 addition & 5 deletions app/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export default function Footer({
<div className="flex flex-col flex-col-reverse sm:flex-row gap-y-8 gap-x-16">
{image?.url && (
<div>
<Image
url={image.url}
width={120}
alternativeText={image.alternativeText}
/>
<Image {...image} width={120} />
</div>
)}
<div className="ds-stack-8">
Expand Down
16 changes: 15 additions & 1 deletion app/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import SVG from "react-inlinesvg";

export type ImageProps = Readonly<{
url?: string;
ext?: string;
width?: number;
height?: number;
alternativeText?: string;
Expand All @@ -8,7 +11,18 @@ export type ImageProps = Readonly<{

function Image({ url, width, height, alternativeText, ...props }: ImageProps) {
if (!url) return null;
return (
// Need to inline SVG components for accessibility
const isSvg = props.ext === ".svg";
return isSvg ? (
<SVG

This comment has been minimized.

Copy link
@aaschlote

aaschlote Dec 23, 2024

Contributor

@Spencer6497 can we add test for this react component?

{...props}
src={url}
width={width}
title={alternativeText}
role="img"
height={"auto"}
/>
) : (
<img
{...props}
src={url}
Expand Down
10 changes: 8 additions & 2 deletions app/services/cms/models/StrapiImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export const getImageProps = (
cmsData: StrapiImage | null,
): ImageProps | undefined => {
if (!cmsData) return undefined;
const { url, width, height, alternativeText } = cmsData;
return { url, width, height, alternativeText: alternativeText ?? undefined };
const { url, width, height, alternativeText, ext } = cmsData;
return {
url,
width,
ext,
height,
alternativeText: alternativeText ?? undefined,
};
};
1 change: 1 addition & 0 deletions app/services/cms/models/__test__/StrapiImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("getImageProps", () => {

expect(result).toEqual({
url: "url",
ext: ".ext",
width: 1,
height: 2,
alternativeText: "alternativeText",
Expand Down
1 change: 1 addition & 0 deletions app/services/security/cspHeader.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const cspHeader = (args: {
"connect-src": [
"'self'",
"eu.i.posthog.com",
"https://a2j-rechtsantragstelle-infra-public-assets-bucket.obs.eu-de.otc.t-systems.com",
...(args.additionalConnectSrc ?? []),
],
"img-src": [
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"react-collapsed": "^4.1.2",
"react-dom": "^18.3.1",
"react-imask": "^7.6.1",
"react-inlinesvg": "^4.1.5",

This comment has been minimized.

Copy link
@aaschlote

aaschlote Dec 23, 2024

Contributor
"react-select": "^5.9.0",
"remix-validated-form": "^5.1.5",
"samlify": "^2.8.11",
Expand Down

0 comments on commit 97dbe38

Please sign in to comment.