UNPKG

2.34 kBJavaScriptView Raw
1"use strict";
2"use client";
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5exports.__esModule = true;
6exports.default = void 0;
7var _classnames = _interopRequireDefault(require("classnames"));
8var React = _interopRequireWildcard(require("react"));
9var _ThemeProvider = require("./ThemeProvider");
10var _jsxRuntime = require("react/jsx-runtime");
11function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13function toPercent(num) {
14 if (num <= 0) return '100%';
15 if (num < 1) return `${num * 100}%`;
16 return `${num}%`;
17}
18const Ratio = /*#__PURE__*/React.forwardRef(({
19 bsPrefix,
20 className,
21 children,
22 aspectRatio = '1x1',
23 style,
24 ...props
25}, ref) => {
26 bsPrefix = (0, _ThemeProvider.useBootstrapPrefix)(bsPrefix, 'ratio');
27 const isCustomRatio = typeof aspectRatio === 'number';
28 return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
29 ref: ref,
30 ...props,
31 style: {
32 ...style,
33 ...(isCustomRatio && {
34 '--bs-aspect-ratio': toPercent(aspectRatio)
35 })
36 },
37 className: (0, _classnames.default)(bsPrefix, className, !isCustomRatio && `${bsPrefix}-${aspectRatio}`),
38 children: React.Children.only(children)
39 });
40});
41var _default = Ratio;
42exports.default = _default;
43module.exports = exports.default;
\No newline at end of file