import * as React from 'react' import invariant from 'tiny-invariant' import { Box, PolymorphicComponentProps } from 'react-polymorphic-box' import './AspectRatio.css' const defaultElement = 'div' export type AspectRatioPropsBase = { /** The ratio of the component's width relative to its height. */ x: number /** The ratio of the component's height relative to its width. */ y: number } export type AspectRatioProps< E extends React.ElementType > = PolymorphicComponentProps /** * `` sized with a specified aspect ratio. * * @example * With a 16:9 ratio: * Content */ export const AspectRatio: ( props: AspectRatioProps, ) => React.ReactElement | null = React.forwardRef( ( { x, y, children, ...props }: AspectRatioProps, innerRef: typeof props.ref, ) => { invariant(x > 0, 'Prop x must be a number greater than 0.') invariant(y >= 0, 'Prop y must be a number greater than or equal to 0.') return (
{children}
) }, ) // @ts-expect-error: Component type does not currently include displayName AspectRatio.displayName = 'AspectRatio'