UNPKG

@fruits-chain/react-native-xiaoshu

Version:
87 lines (85 loc) 3.46 kB
"use strict"; 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.js"); var _index = require("../helpers/index.js"); var _index2 = _interopRequireDefault(require("../theme/index.js")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const NO_GAP = 0; const getMarginGap = (d, gap) => d ? typeof d === 'number' ? d : gap : 0; /** * Space 间距 */ const Space = ({ direction = 'vertical', wrap = false, gap = 's', gapVertical, gapHorizontal, head, tail, justify, align, minWidth, shrink = false, style, children, ...restProps }) => { const TOKENS = _index2.default.useThemeTokens(); const CV_BLANK = _index2.default.createVar(TOKENS, _style.varCreator); const defaultGap = typeof gap === 'string' ? CV_BLANK[`blank_size_${gap}`] : gap; const isVertical = direction === 'vertical'; const _gapVertical = (0, _index.getDefaultValue)(gapVertical, defaultGap); const _gapHorizontal = (0, _index.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) }), ...(shrink && direction === 'horizontal' ? { marginBottom: -_gapVertical } : {}) }; const itemStyle = { marginBottom: isVertical || wrap ? _gapVertical : 0, marginRight: isVertical ? 0 : _gapHorizontal, minWidth }; const childArray = _react.Children.toArray(children); const count = childArray.length; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { ...restProps, style: [wrapperStyle, style], children: childArray.map((child, index) => { let key = index; if (/*#__PURE__*/(0, _react.isValidElement)(child)) { key = child.key ?? index; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [itemStyle, index + 1 === count ? isVertical ? { marginBottom: NO_GAP } : { marginRight: NO_GAP } : null], children: child }, key); }) }); }; var _default = exports.default = /*#__PURE__*/(0, _react.memo)(Space); //# sourceMappingURL=index.js.map