mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## 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
72 lines
1.8 KiB
TypeScript
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}
|
|
/>
|
|
);
|
|
};
|