Display
AspectRatio
A box that holds a width to height ratio for a video, an embed or any child with no size of its own.
<script>
import { AspectRatio } from "@codeatlasdev/ui";
</script>
<AspectRatio ratio={16 / 9}>
<iframe title="Product tour" src="https://example.com/embed"></iframe>
</AspectRatio>
AspectRatio is the replacement for Radix AspectRatio: a width: 100% box whose height follows ratio (16 / 9, 4 / 3, 1). A direct img, video, iframe, canvas or svg child fills it (images and video are cropped with object-fit: cover); any other child is a normal block you size with height: 100%. The box clips, so a tall child never pushes it past the ratio.
For a plain picture you do not need it: <Image ratio={16 / 9}> crops the image to the ratio itself and keeps lazy loading and the no-layout-shift contract.
Embed
The box holds 16:9 at any width.
Reference #961 · Pick in the gallery
Code
It is layout only: no role, no label. Name the content inside it (an iframe needs a title).
Props
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | – | Width divided by height. Required. |
class | string | '' | Extra class names. |
children | Snippet | undefined | The content held in the box. |