Files
StevenandGitHub 4466ba436b chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00

72 lines
1.8 KiB
TypeScript

import React from "react";
import NextImage, { StaticImageData } from "next/image";
import classes from "./index.module.scss";
import cssVariables from "../../../cssVariables";
import { Props } from "..";
const { breakpoints } = cssVariables;
export const Image: React.FC<Props> = (props) => {
const {
imgClassName,
onClick,
onLoad: onLoadFromProps,
resource,
priority,
fill,
src: srcFromProps,
alt: altFromProps,
} = props;
const [isLoading, setIsLoading] = React.useState(true);
let width: number | undefined;
let height: number | undefined;
let alt = altFromProps;
let src: StaticImageData | string = srcFromProps || "";
if (!src && resource && typeof resource !== "string") {
const {
width: fullWidth,
height: fullHeight,
filename: fullFilename,
alt: altFromResource,
} = resource;
width = fullWidth;
height = fullHeight;
alt = altFromResource;
let filename = fullFilename;
src = `https://${process.env.NEXT_PUBLIC_S3_HOSTNAME}/${process.env.NEXT_PUBLIC_S3_BUCKET}/${filename}`;
}
// NOTE: this is used by the browser to determine which image to download at different screen sizes
const sizes = Object.entries(breakpoints)
.map(([, value]) => `(max-width: ${value}px) ${value}px`)
.join(", ");
return (
<NextImage
className={[isLoading && classes.placeholder, classes.image, imgClassName]
.filter(Boolean)
.join(" ")}
src={src}
alt={alt || ""}
onClick={onClick}
onLoad={() => {
setIsLoading(false);
if (typeof onLoadFromProps === "function") {
onLoadFromProps();
}
}}
fill={fill}
width={!fill ? width : undefined}
height={!fill ? height : undefined}
sizes={sizes}
priority={priority}
/>
);
};