Image
A picture in a box of known shape, so nothing moves when it arrives: the skeleton holds its place until it loads, and if it cannot load the box says so.
import { Image, ImageSkeleton } from '@sypnia/ui/react'
Shapes, a failure and a skeleton
Code
import { Image, ImageSkeleton } from '@sypnia/ui/react';
// A box of known shape: nothing moves when the picture arrives. The last one cannot load and says so.
const art = (hue: number) => 'data:image/svg+xml;utf8,' + encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800" viewBox="0 0 1200 800"><rect width="1200" height="800" fill="hsl(${hue} 35% 88%)"/><circle cx="880" cy="250" r="130" fill="hsl(${hue} 45% 70%)"/><path d="M0 620 L320 380 L560 560 L780 420 L1200 700 L1200 800 L0 800Z" fill="hsl(${hue} 30% 62%)"/></svg>`);
export default function Shapes() {
return (
<div className="sy-grid">
<Image src={art(30)} alt="Drawing of hills under a sun" />
<Image src={art(200)} alt="Drawing of hills, square" ratio="1" />
<Image src={art(140)} alt="Drawing of hills, shown whole" ratio="4 / 3" fit="contain" />
<Image src="data:image/png;base64,AAAA" alt="The storefront" ratio="4 / 3" />
<ImageSkeleton ratio="4 / 3" />
</div>
);
} Skeleton
Code
import { Image, ImageSkeleton } from '@sypnia/ui/react';
// A picture and its skeleton: the same box, so nothing moves when it arrives.
export default function Skeleton() {
return (
<div className="sy-cols sy-cols--stack">
<Image ratio="4 / 3" alt="A plain warm colour" src={'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300"><rect width="400" height="300" fill="hsl(30 40% 80%)"/></svg>')} />
<ImageSkeleton ratio="4 / 3" />
</div>
);
} When to use it
Use it when
- Screenshots, product photos, covers.
fit="contain"when the whole picture must show.
Do not use it when
- Icons: use Icon. Avatars: use Avatar.
For everyone
altsays what the picture shows; empty only for decoration.- A picture that fails keeps its name for screen readers.
Props
| Image | Type | Default |
|---|---|---|
altrequired | string | |
srcrequired | string | |
fitcover fills the box and crops; contain shows the whole picture. | "cover" | "contain" | cover |
lazyLoads it only when it comes near the screen. | boolean | true |
ratioWidth / height: «16 / 9», «1», «4 / 3». | string | 16 / 9 |
rounded | boolean | true |
| ImageSkeleton | Type | Default |
|---|---|---|
ratio | string | 16 / 9 |
rounded | boolean | true |