UNPKG

@carbon/ibm-products

Version:
60 lines (58 loc) 2.27 kB
/** * Copyright IBM Corp. 2020, 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. */ import { __toESM } from "../../../_virtual/_rolldown/runtime.js"; import { require_classnames } from "../../../node_modules/classnames/index.js"; import { pkg } from "../../../settings.js"; import { getDevtoolsProps } from "../../../global/js/utils/devtools.js"; import { useCardContext } from "./CardContext.js"; import React, { forwardRef } from "react"; import PropTypes from "prop-types"; import { AspectRatio } from "@carbon/react"; //#region src/components/Card/next/CardMedia.tsx /** * Copyright IBM Corp. 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. */ var import_classnames = /* @__PURE__ */ __toESM(require_classnames()); const blockClass = `${pkg.prefix}--card-next`; const componentName = "CardMedia"; /** * CardMedia is a media slot component that maintains aspect ratio. * * In vertical (default) mode it delegates to Carbon's AspectRatio. * In horizontal mode it renders a plain div sized to `mediaWidth` (default * 33.33%) that stretches to the full card height — no aspect-ratio math needed. */ let CardMedia = forwardRef(({ children, className, ratio, mediaWidth = "33.33%", ...rest }, ref) => { const { horizontal } = useCardContext(); const classes = (0, import_classnames.default)(`${blockClass}__media`, className); if (horizontal) return /* @__PURE__ */ React.createElement("div", { ref, className: `${blockClass}__media ${blockClass}__media--horizontal`, style: { [`--${blockClass}--media-width`]: mediaWidth }, ...getDevtoolsProps(componentName) }, children); return /* @__PURE__ */ React.createElement(AspectRatio, { ratio, ...rest, ref, className: classes, ...getDevtoolsProps(componentName) }, children); }); CardMedia.propTypes = { children: PropTypes.node, className: PropTypes.string, /** Width of the media column in horizontal layout. Any valid CSS width value. */ mediaWidth: PropTypes.string }; CardMedia = pkg.checkComponentEnabled(CardMedia, componentName); CardMedia.displayName = componentName; //#endregion export { CardMedia };