Open this example in the interactive library
Live preview
Source code
// components/ContainFitDimensions.tsx
export default function ContainFitDimensions({
width = 12,
height = 8,
}: { width?: number; height?: number } = {}) {
const factor = Math.min(320 / Math.max(width, 1), 180 / Math.max(height, 1));
return (
<output>
Fit inside 320 × 180: {Math.round(width * factor)} × {Math.round(height * factor)}
</output>
);
}
