@chakra-ui/react
Version:
Responsive and accessible React UI components built with React and Emotion
54 lines (50 loc) • 1.42 kB
JavaScript
"use client";
;
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var factory = require('../../styled-system/factory.cjs');
var cx = require('../../utils/cx.cjs');
var walkObject = require('../../utils/walk-object.cjs');
const AspectRatio = React.forwardRef(
function AspectRatio2(props, ref) {
const { ratio = 4 / 3, children, className, ...rest } = props;
const child = React.Children.only(children);
return /* @__PURE__ */ jsxRuntime.jsx(
factory.chakra.div,
{
ref,
position: "relative",
className: cx.cx("chakra-aspect-ratio", className),
_before: {
height: 0,
content: `""`,
display: "block",
paddingBottom: walkObject.mapObject(ratio, (r) => `${1 / r * 100}%`)
},
css: {
"& > *:not(style)": {
overflow: "hidden",
position: "absolute",
top: "0",
right: "0",
bottom: "0",
left: "0",
display: "flex",
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100%"
},
"& > img, & > video": {
objectFit: "cover"
},
...props.css
},
...rest,
children: child
}
);
}
);
exports.AspectRatio = AspectRatio;
;