A monorepo hosting components for rendering image and video in a single container for easy rendering of visual elements.
- @react-visual/react - Vanilla implementation.
- @react-visual/contentful - Adapter for Contentful assets.
- @react-visual/next - Uses the
next/imagecomponent for rendering images. - @react-visual/sanity-next - Takes Sanity asset and passes them to
@react-visual/nextfor rendering.
Using sourceTypes and sourceMedia with imageLoader to produce multiple <source> tags with srcset attributes.
importVisualfrom'@react-visual/react'exportdefaultfunctionResponsiveExample(){return(<Visualimage='https://placehold.co/200x200'sourceTypes={['image/webp']}sourceMedia={['(orientation:landscape)','(orientation:portrait)']}imageLoader={({ src, type, media, width })=>{constheight=media?.includes('landscape') ? width*0.5 : widthconstext=type?.includes('webp') ? '.webp' : ''return`https://placehold.co/${width}x${height}${ext}`}}width='100%'alt='Example of responsive images'/>)}Using with a Visual entryType containing image and video fields:
importVisualfrom'@react-visual/contentful'exportdefaultfunctionExample(){return(<Visualsrc={entry.background}sizes='100vw'/>)}Using framework adapter for Next.js:
importVisualfrom'@react-visual/next'exportdefaultfunctionExample(){return(<Visualimage="https://placehold.co/1600x900.png"video="https://placehold.co/1600x900.mp4"aspect={16/9}sizes='100vw'alt='Example using placeholder assets'/>)}Using Sanity + Next.js Adapter to automatically populate aspect ratio, alt, blurred placeholder, and support both image and video in one object:
importVisualfrom'@react-visual/sanity-next'exportdefaultfunctionExample({ background }){return<Visualsrc={background}sizes='100vw'/>}This project uses Lerna to release versions, using the default versioning strategy.
yarn lerna run test- Run all testsyarn lerna version- Tag a new versionyarn lerna publish [major|minor|patch]- Tag and publish a versionyarn lerna publish from-package- Publish the current version
placeholder.co dropped it's APIs for generating test videos so I've been using this command to create videos for tests:
ffmpeg -f lavfi -i color=c=black:s=300x150:d=5 \
-vf "drawtext=text='Hello World':fontcolor=white:fontsize=32:x=(w-text_w)/2:y=(h-text_h)/2" \
-c:v libx264 -t 5 -pix_fmt yuv420p 300x150.mp4