Aspect Ratio

@sushindustries/ui

A box that keeps its shape and fills whatever is put in it. CSS aspect-ratio, as a prop.

5 min read
View as MarkdownEdit on GitHub

Props

PropTypeDefaultDoes
ratio?number16 / 9Width over height: 16/9, 1, 4/3.
childrenReactNode-

Notes

ratio takes any positive number, not a preset - 16 / 9, 1, 4 / 3 are conventions in this codebase, not values the component checks for. Passing a fraction the wrong way round (9 / 16 for a landscape image) produces a tall box rather than an error, since the component has no way to know which orientation was intended.