@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
72 lines (71 loc) • 4.36 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Space = Space;
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _components = require("@tarojs/components");
var _defaultProps = require("../default-props");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["direction", "align", "justify", "wrap", "block", "className", "children", "style", "gap", "gapHorizontal", "gapVertical"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefix = "van-space";
function Space(props) {
var _classNames;
var _useState = (0, _react.useState)((0, _defaultProps.get)().Space),
_useState2 = (0, _slicedToArray2.default)(_useState, 1),
d = _useState2[0];
var _d$props = _objectSpread(_objectSpread({}, d), props),
_d$props$direction = _d$props.direction,
direction = _d$props$direction === void 0 ? 'horizontal' : _d$props$direction,
align = _d$props.align,
justify = _d$props.justify,
_d$props$wrap = _d$props.wrap,
wrap = _d$props$wrap === void 0 ? true : _d$props$wrap,
block = _d$props.block,
_d$props$className = _d$props.className,
className = _d$props$className === void 0 ? '' : _d$props$className,
children = _d$props.children,
_d$props$style = _d$props.style,
style = _d$props$style === void 0 ? {} : _d$props$style,
gap = _d$props.gap,
gapHorizontal = _d$props.gapHorizontal,
gapVertical = _d$props.gapVertical,
others = (0, _objectWithoutProperties2.default)(_d$props, _excluded);
var _style = (0, _react.useMemo)(function () {
var s = _objectSpread({}, style);
if (gap) {
s = {
'--space-gap-horizontal': gap + 'px',
'--space-gap-vertical': gap + 'px'
};
}
if (gapHorizontal) s['--space-gap-horizontal'] = gapHorizontal + 'px';
if (gapVertical) s['--space-gap-vertical'] = gapVertical + 'px';
return s;
}, [gap, gapHorizontal, gapVertical, style]);
return (
/*#__PURE__*/
// @ts-ignore
(0, _jsxRuntime.jsx)(_components.View, _objectSpread(_objectSpread({
style: _style,
className: (0, _classnames.default)(classPrefix, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(classPrefix, "-wrap"), wrap), (0, _defineProperty2.default)(_classNames, "".concat(classPrefix, "-block"), block), (0, _defineProperty2.default)(_classNames, "".concat(classPrefix, "-").concat(direction), true), (0, _defineProperty2.default)(_classNames, "".concat(classPrefix, "-align-").concat(align), !!align), (0, _defineProperty2.default)(_classNames, "".concat(classPrefix, "-justify-").concat(justify), !!justify), (0, _defineProperty2.default)(_classNames, className, !!className), _classNames))
}, others), {}, {
children: _react.Children.map(children, function (child) {
return child !== null && child !== undefined && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, {
className: "".concat(classPrefix, "-item"),
children: child
});
})
}))
);
}
var _default = Space;
exports.default = _default;