/* eslint-disable @typescript-eslint/no-unused-vars */ import React from 'react'; import Page from '../Page'; import useToolkit from '../toolkit/useToolkit'; import customImageRendererConfig from './cards/customImageRendererConfig'; import internalImageRendererConfig from './cards/internalImageRendererConfig'; import imagesWithHeadersConfig from './cards/imagesWithHeadersConfig'; import InternalRendererAdmonition from '../components/InternalRendererAdmonition'; const inlineExample = ``; const objectFitExample = ``; const autoSizeExample = ``; const unreachableExample = `The Void`; // TODO document attributes // eslint-disable-next-line @typescript-eslint/no-unused-vars const imgAttributes = { alt: true, src: true, width: true, height: true, crossorigin: false, anonymous: false, 'use-credentials': false, decoding: false, ismap: false, loading: false, referrerpolicy: false, sizes: false, srcset: false, usemap: false }; export default function PageContentImages() { const { Acronym, Admonition, Bold, DList, DListItem, DListTitle, Header, Paragraph, Chapter, SourceDisplay, RefLibrary, RefRNSymbol, RefHtmlElement, RefCssProperty, RefESSymbol, RefRenderHtmlProp, RefHtmlAttr, RefDoc, RefRenderHTMLExport, RefTRE, RenderHtmlCard, Section, InlineCode, Hyperlink, List, ListItem, SvgFigure } = useToolkit(); return (
Also note that this renderer covers the {' '} tag. tag is not yet supported.
The renderer will automatically scale images down to the available width, even when the provided inline style width is greater than the container width. You need to activate{' '} enableExperimentalPercentWidth for percent-width support in images. See{' '} for reference. You are strongly advised to provide a{' '} property from{' '} official hook to help this component handle the scaling.
This library supports CSS property. In the below example, which is very similar to the previous one, we set explicitly{' '} object-fit: contain; to letterbox the image in the container of width 50% and height 100px. is a mixed style and thus you can use it in mixed styles declarations such as{' '} .
The next image will be sized automatically thanks to the{' '} and{' '} props. The latter allows you to set the maximum width from{' '} , or disabling scaling by returning .
Similarly to browsers, this library will place a print box before fetching image dimensions when both and{' '} attributes are provided, or the two dimensions are set in the attribute. This is great to avoid layout shifts when images size jumps from 0 to the view box height, and is a hint to good web design. You are kindly advised to read the{' '} page before continuing.
has a great advantage over using{' '} {' '} prop: you have access to the internal component props. In this scenario, we are going to display an interactive thumbnail which will show the full resolution image when pressed. To do so, we are going to read the URI from the internal source prop (although we could also do this from the {' '} src{' '} ), and mangle it to get our "thumbnail" URI.
You can reuse to your advantage some building blocks of the internal renderer thanks to the following exports: To render the container of the {' '} element. To render the fallback view on error state. To render the fallback view on loading state. To render the image on success state.. To get the state of the image resource fetching. In the below example, our custom renderer will display an activity indicator when the state is either "loading" or "success". This is for demonstration purposes, and of course you should handle the "success" state by rendering the{' '} component, or a custom component displaying an image.
You can take advantage of the{' '} prop to pass headers to the image fetching conditionnaly. For example: In this example, we are using a Bearer token to access a restricted resource. We could also use headers to take advantage of the new{' '} Responsive Image Client Hints {' '} standard.
We can take advantage of the{' '} to customize images behavior (see{' '} ).
); }