@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
99 lines (75 loc) • 3.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _style = require("../blank/style");
var _helpers = require("../helpers");
var _theme = _interopRequireDefault(require("../theme"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _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); }
function _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; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
const NO_GAP = 0;
const getMarginGap = (d, gap) => d ? typeof d === 'number' ? d : gap : 0;
/**
* Space 间距
*/
const Space = _ref => {
let {
direction = 'vertical',
wrap = false,
gap = 's',
gapVertical,
gapHorizontal,
head,
tail,
justify,
align,
style,
children,
...restProps
} = _ref;
const TOKENS = _theme.default.useThemeTokens();
const CV_BLANK = _theme.default.createVar(TOKENS, _style.varCreator);
const defaultGap = typeof gap === 'string' ? CV_BLANK[`blank_size_${gap}`] : gap;
const isVertical = direction === 'vertical';
const _gapVertical = (0, _helpers.getDefaultValue)(gapVertical, defaultGap);
const _gapHorizontal = (0, _helpers.getDefaultValue)(gapHorizontal, defaultGap);
const wrapperStyle = {
flexDirection: isVertical ? 'column' : 'row',
flexWrap: wrap ? 'wrap' : 'nowrap',
justifyContent: justify,
alignItems: align,
...(isVertical ? {
paddingTop: getMarginGap(head, _gapVertical),
paddingBottom: getMarginGap(tail, _gapVertical)
} : {
paddingLeft: getMarginGap(head, _gapHorizontal),
paddingRight: getMarginGap(tail, _gapHorizontal)
})
};
const itemStyle = {
marginBottom: _gapVertical,
marginRight: isVertical ? 0 : _gapHorizontal
};
const childArray = _react.Children.toArray(children);
const count = childArray.length;
return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({}, restProps, {
style: [wrapperStyle, style]
}), childArray.map((child, index) => {
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
key: index,
style: [itemStyle, index + 1 === count ? isVertical ? {
marginBottom: NO_GAP
} : {
marginRight: NO_GAP
} : null]
}, child);
}));
};
var _default = /*#__PURE__*/(0, _react.memo)(Space);
exports.default = _default;
//# sourceMappingURL=index.js.map