UNPKG

@prismicio/react

Version:

React components and hooks to fetch and present Prismic content

68 lines (67 loc) 2.81 kB
import { ImageFieldImage, asImagePixelDensitySrcSet, asImageWidthSrcSet } from "@prismicio/client"; import { ComponentProps, FC, ReactNode } from "react"; //#region src/PrismicImage.d.ts type ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, "widths"> & Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities">; /** Props for `<PrismicImage>`. */ type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & { /** The Prismic image field or thumbnail to render. */field: ImageFieldImage | null | undefined; /** * An object of Imgix URL API parameters to transform the image. * * See: https://docs.imgix.com/apis/rendering */ imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }; /** * Declare an image as decorative by providing `alt=""`. * * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images */ alt?: ""; /** * Declare an image as decorative only if the image field does not have alternative text by * providing `fallbackAlt=""`. * * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images */ fallbackAlt?: ""; /** * The value to be rendered when the field is empty. If a fallback is not given, `null` will be * rendered. */ fallback?: ReactNode; } & ({ /** * Widths (in pixels) used to build a `srcset` value for the image field. * * If omitted or set to `"defaults"`, the following widths will be used: 640, 750, 828, * 1080, 1200, 1920, 2048, 3840. * * If the image field contains responsive views, each responsive view can be used as a width * in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop. */ widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults"; /** Not used when the `widths` prop is used. */ pixelDensities?: never; } | { /** Not used when the `widths` prop is used. */widths?: never; /** * Pixel densities used to build a `srcset` value for the image field. * * If a `pixelDensities` prop is passed `"defaults"`, the following pixel densities will be * used: 1, 2, 3. */ pixelDensities: NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults"; }); /** * Renders an optimized image from a Prismic image field. * * @example * ```tsx * <PrismicImage field={slice.primary.photo} />; * ``` * * @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image} */ declare const PrismicImage: FC<PrismicImageProps>; //#endregion export { PrismicImage, PrismicImageProps }; //# sourceMappingURL=PrismicImage.d.ts.map