Aspect Ratio

A container that maintains a specific aspect ratio.

Installation

Import the component from the passport-ui package.

components/example.tsx
1
2
import { AspectRatio } from "passport-ui";
import { Card, CardContent } from "passport-ui";

Usage

Basic example showing how to use the component.

components/example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<div className="w-sm">
<AspectRatio ratio={16 / 9}>
<Card className="h-full">
<CardContent>
<div className="meta-container">
<h3>Aspect Ratio</h3>
<p>16:9</p>
</div>
</CardContent>
</Card>
</AspectRatio>
</div>
{/* Square aspect ratio */}
<AspectRatio ratio={1}>
<Card className="h-full">
<CardContent>
<div className="meta-container">
<h3>Aspect Ratio</h3>
<p>1:1</p>
</div>
</CardContent>
</Card>
</AspectRatio>
{/* With image */}
<AspectRatio ratio={16 / 9}>
<img
src="https://placehold.co/1600x900"
alt="Placeholder"
className="rounded-md object-cover"
/>
</AspectRatio>

Additional resources

Documentation and examples are available in Storybook.