@carbon/react
Version:
React components for the Carbon Design System
56 lines (54 loc) • 1.8 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_usePrefix = require("../../internal/usePrefix.js");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/components/AspectRatio/AspectRatio.tsx
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* The AspectRatio component provides a `ratio` prop that will be used to
* specify the aspect ratio that the children you provide will be displayed in.
* This is often useful alongside our grid components, or for media assets like
* images or videos.
*/
const AspectRatio = ({ as: BaseComponent = "div", className: containerClassName, children, ratio = "1x1", ...rest }) => {
const prefix = require_usePrefix.usePrefix();
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BaseComponent, {
className: (0, classnames.default)(containerClassName, `${prefix}--aspect-ratio`, `${prefix}--aspect-ratio--${ratio}`),
...rest,
children
});
};
AspectRatio.propTypes = {
as: prop_types.default.elementType,
children: prop_types.default.node,
className: prop_types.default.string,
ratio: prop_types.default.oneOf([
"16x9",
"9x16",
"2x1",
"1x2",
"4x3",
"3x4",
"3x2",
"2x3",
"1x1"
])
};
//#endregion
exports.default = AspectRatio;