import type { ReactNode } from 'react'; import { Box, Grid } from '@chakra-ui/react'; import DeferredImage from '@/components/DeferredImage/DeferredImage'; import FramedImage from '@/components/FramedImage/FramedImage'; import Reveal from '@/components/Reveal/Reveal'; import type { ContentImage, FrameColor } from '@/content/types'; // Widest a small photo column gets, stacked or next to the text: the photo // alone, or the photo with a detail photo overlapping it const SMALL_MEDIA = '20rem'; const SMALL_MEDIA_WITH_DETAIL = '28rem'; // Widest the text next to a small photo gets: about 70 characters a line const SMALL_TEXT = '36rem'; type MediaTextProps = { image: ContentImage; // CSS aspect ratio of the visible crop, e.g. '4 / 3' aspectRatio: string; // The photo is at the top of the page and should not wait (FramedImage) priority?: boolean; // Photo in the right-hand column from `lg` (design .about--reverse). // Only the visual order changes: the photo stays first in the DOM. reverse?: boolean; // half: photo and text share the width equally (design .about); // small: the photo column stays narrow (20rem, 28rem with a detail // photo); the text, at most 36rem, is centred in the rest mediaSize?: 'half' | 'small'; // A smaller square photo overlapping the main one's lower right corner detailImage?: ContentImage; // Colour of the block behind the photo (FramedImage) frameColor?: FrameColor; 'data-testid'?: string; // The text column; each page fills in its own heading and text children: ReactNode; }; // A framed photo next to a text column (design .about), used on the // homepage, the about page and the shoot types page. Stacked on phones and // tablets, two columns from `lg`; both columns fade in on scroll. export default function MediaText({ image, aspectRatio, priority, reverse = false, mediaSize = 'half', detailImage, frameColor, 'data-testid': testId, children, }: MediaTextProps) { const small = mediaSize === 'small'; const mediaWidth = detailImage ? SMALL_MEDIA_WITH_DETAIL : SMALL_MEDIA; const media = `minmax(0, ${mediaWidth})`; const columns = small ? reverse ? `minmax(0, 1fr) ${media}` : `${media} minmax(0, 1fr)` : '1fr 1fr'; return ( {detailImage ? ( // The detail photo hangs below the main one: the padding // (a share of the width) makes room for it ) : ( )} {/* Next to a small photo the text keeps a readable line length and sits centred between the photo and the edge */} {children} ); }