lole-ui
Version:
React UI Component which like a love letter
36 lines (35 loc) • 1.69 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import React from 'react';
import { SpaceContext } from "./space";
export default function Item(_a) {
var _b;
var className = _a.className, direction = _a.direction, index = _a.index, marginDirection = _a.marginDirection, children = _a.children, split = _a.split, wrap = _a.wrap;
var _c = React.useContext(SpaceContext), horizontalSize = _c.horizontalSize, verticalSize = _c.verticalSize, latestIndex = _c.latestIndex, supportFlexGap = _c.supportFlexGap;
var style = {};
if (!supportFlexGap) {
if (direction === 'vertical') {
if (index < latestIndex) {
style = { marginBottom: horizontalSize / (split ? 2 : 1) };
}
}
else {
style = __assign(__assign({}, (index < latestIndex && (_b = {}, _b[marginDirection] = horizontalSize / (split ? 2 : 1), _b))), (wrap && { paddingBottom: verticalSize }));
}
}
if (children === null || children === undefined) {
return null;
}
return (React.createElement(React.Fragment, null,
React.createElement("div", { className: className, style: style }, children),
index < latestIndex && split && (React.createElement("span", { className: "".concat(className, "-split"), style: style }, split))));
}