import * as React from "react"; import { cn } from "../../lib/utils"; interface AspectRatioProps extends React.HTMLAttributes { /** The aspect ratio to maintain (width/height) */ ratio?: number; /** Predefined aspect ratios for common use cases */ preset?: "square" | "video" | "portrait" | "widescreen" | "ultrawide" | "golden"; /** Whether to apply rounded corners */ rounded?: boolean; /** Whether to show a border */ bordered?: boolean; /** Optional object-fit style for child elements */ objectFit?: "cover" | "contain" | "fill" | "none" | "scale-down"; } const AspectRatio = React.forwardRef( ({ className, ratio: propRatio, preset, rounded = false, bordered = false, objectFit, style, ...props }, ref) => { // Predefined aspect ratios const presetRatios = { square: 1, // 1:1 video: 16/9, // 16:9 portrait: 3/4, // 3:4 widescreen: 16/9, // 16:9 ultrawide: 21/9, // 21:9 golden: 1.618 // Golden ratio }; // Determine the final ratio to use const ratio = propRatio || (preset ? presetRatios[preset] : 1); return (
{props.children && (
img]:object-${objectFit} [&>video]:object-${objectFit}` )} > {props.children}
)}
); } ); AspectRatio.displayName = "AspectRatio"; export { AspectRatio };