import React, { useContext } from 'react' import { BreakpointGetter, FallbackImage, Sources } from '../ImageSet' import { ScrollyIDContext } from '.' import { ContentProps } from '../../types' import type * as ComponentWorkarounds from '../Workarounds' const scrollyGetBreakpoints: BreakpointGetter = (image) => { switch (image.format) { case 'desktop': return { s: { maxWidth: 740, orientation: 'landscape' }, m: { maxWidth: 980, orientation: 'landscape' }, l: { maxWidth: 1200, orientation: 'landscape' }, xl: { maxWidth: 1920, orientation: 'landscape' }, xxl: { maxWidth: 3840, orientation: 'landscape' }, } case 'mobile': return { s: { maxWidth: 490, orientation: 'portrait' }, m: { maxWidth: 600, orientation: 'portrait' }, l: { maxWidth: 800, orientation: 'portrait' }, xl: { maxWidth: 1200, orientation: 'portrait' }, xxl: { maxWidth: 1920, orientation: 'portrait' }, } } } interface ScrollyImageProps extends ContentProps {} export const ScrollyImage: React.FC = ({ content: { picture }, }) => { const scrollyId = useContext(ScrollyIDContext) if (!picture?.images) { throw new Error( `ScrollyImage has no images. Check that they are present in the query` ) } return (
{(picture.caption || picture.credit) && (
{picture.caption ? picture.caption + ' ' : ''} {picture.credit}
)}
) }