UNPKG

@wordpress/components

Version:
50 lines (49 loc) • 1.56 kB
import clsx from "clsx"; import deprecated from "@wordpress/deprecated"; import { Children, cloneElement } from "@wordpress/element"; import { jsx } from "react/jsx-runtime"; // packages/components/src/responsive-wrapper/index.tsx /** * A wrapper component that maintains its aspect ratio when resized. * * This component is deprecated. Use the CSS `aspect-ratio` property instead. * * @deprecated * * ```jsx * import { ResponsiveWrapper } from '@wordpress/components'; * * const MyResponsiveWrapper = () => ( * <ResponsiveWrapper naturalWidth={ 2000 } naturalHeight={ 680 }> * <img * src="https://s.w.org/style/images/about/WordPress-logotype-standard.png" * alt="WordPress" * /> * </ResponsiveWrapper> * ); * ``` */ function ResponsiveWrapper({ naturalWidth, naturalHeight, children, isInline = false }) { deprecated("wp.components.ResponsiveWrapper", { since: "7.2", version: "7.4", alternative: "the CSS aspect-ratio property" }); if (Children.count(children) !== 1) return null; const TagName = isInline ? "span" : "div"; let aspectRatio; if (naturalWidth && naturalHeight) aspectRatio = `${naturalWidth} / ${naturalHeight}`; const ch = children; return /* @__PURE__ */ jsx(TagName, { className: "components-responsive-wrapper", children: /* @__PURE__ */ jsx("div", { children: cloneElement(ch, { className: clsx("components-responsive-wrapper__content", ch.props.className), style: { ...ch.props.style, aspectRatio } }) }) }); } export { ResponsiveWrapper as default }; //# sourceMappingURL=index.mjs.map