PromoCursed/node_modules/antd/lib/grid/col.js
2024-08-20 23:25:37 +04:00

116 lines
4.3 KiB
JavaScript

"use strict";
"use client";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _configProvider = require("../config-provider");
var _RowContext = _interopRequireDefault(require("./RowContext"));
var _style = require("./style");
var __rest = void 0 && (void 0).__rest || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
function parseFlex(flex) {
if (typeof flex === 'number') {
return `${flex} ${flex} auto`;
}
if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
return `0 0 ${flex}`;
}
return flex;
}
const sizes = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
const Col = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
getPrefixCls,
direction
} = React.useContext(_configProvider.ConfigContext);
const {
gutter,
wrap
} = React.useContext(_RowContext.default);
const {
prefixCls: customizePrefixCls,
span,
order,
offset,
push,
pull,
className,
children,
flex,
style
} = props,
others = __rest(props, ["prefixCls", "span", "order", "offset", "push", "pull", "className", "children", "flex", "style"]);
const prefixCls = getPrefixCls('col', customizePrefixCls);
const [wrapCSSVar, hashId, cssVarCls] = (0, _style.useColStyle)(prefixCls);
// ===================== Size ======================
const sizeStyle = {};
let sizeClassObj = {};
sizes.forEach(size => {
let sizeProps = {};
const propSize = props[size];
if (typeof propSize === 'number') {
sizeProps.span = propSize;
} else if (typeof propSize === 'object') {
sizeProps = propSize || {};
}
delete others[size];
sizeClassObj = Object.assign(Object.assign({}, sizeClassObj), {
[`${prefixCls}-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
[`${prefixCls}-${size}-order-${sizeProps.order}`]: sizeProps.order || sizeProps.order === 0,
[`${prefixCls}-${size}-offset-${sizeProps.offset}`]: sizeProps.offset || sizeProps.offset === 0,
[`${prefixCls}-${size}-push-${sizeProps.push}`]: sizeProps.push || sizeProps.push === 0,
[`${prefixCls}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull || sizeProps.pull === 0,
[`${prefixCls}-rtl`]: direction === 'rtl'
});
// Responsive flex layout
if (sizeProps.flex) {
sizeClassObj[`${prefixCls}-${size}-flex`] = true;
sizeStyle[`--${prefixCls}-${size}-flex`] = parseFlex(sizeProps.flex);
}
});
// ==================== Normal =====================
const classes = (0, _classnames.default)(prefixCls, {
[`${prefixCls}-${span}`]: span !== undefined,
[`${prefixCls}-order-${order}`]: order,
[`${prefixCls}-offset-${offset}`]: offset,
[`${prefixCls}-push-${push}`]: push,
[`${prefixCls}-pull-${pull}`]: pull
}, className, sizeClassObj, hashId, cssVarCls);
const mergedStyle = {};
// Horizontal gutter use padding
if (gutter && gutter[0] > 0) {
const horizontalGutter = gutter[0] / 2;
mergedStyle.paddingLeft = horizontalGutter;
mergedStyle.paddingRight = horizontalGutter;
}
if (flex) {
mergedStyle.flex = parseFlex(flex);
// Hack for Firefox to avoid size issue
// https://github.com/ant-design/ant-design/pull/20023#issuecomment-564389553
if (wrap === false && !mergedStyle.minWidth) {
mergedStyle.minWidth = 0;
}
}
// ==================== Render =====================
return wrapCSSVar( /*#__PURE__*/React.createElement("div", Object.assign({}, others, {
style: Object.assign(Object.assign(Object.assign({}, mergedStyle), style), sizeStyle),
className: classes,
ref: ref
}), children));
});
if (process.env.NODE_ENV !== 'production') {
Col.displayName = 'Col';
}
var _default = exports.default = Col;