@crossed/ui
Version:
A universal & performant styling library for React Native, Next.js & React
62 lines (61 loc) • 2.31 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Group_exports = {};
__export(Group_exports, {
CardGroup: () => CardGroup
});
module.exports = __toCommonJS(Group_exports);
var import_react = require("react");
var import_layout = require("../../layout");
var import_styled = require("@crossed/styled");
var import_Root = require("./Root");
var import_styles = require("./styles");
const CardGroup = ({ children }) => {
const childTmp = import_react.Children.toArray(children);
const size = childTmp.length;
const mappedChildren = childTmp.reduce((acc, child, index) => {
if (!(0, import_react.isValidElement)(child))
return acc;
if (child.type === import_layout.Divider)
return [...acc, child];
if (child.type === import_Root.CardRoot) {
const isFirst = index === 0;
const isLast = index === size - 1;
const isMiddle = !isFirst && !isLast;
return [
...acc,
(0, import_react.cloneElement)(child, {
style: (0, import_styled.composeStyles)(
isFirst && !isLast && import_styles.cardStyles.first,
isLast && !isFirst && import_styles.cardStyles.last,
isMiddle && import_styles.cardStyles.middle,
child.props.style
)
})
];
}
throw new Error("Direct children of CardGroup should be Divider or Card");
}, []);
return mappedChildren;
};
CardGroup.displayName = "Card.Group";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CardGroup
});
//# sourceMappingURL=Group.js.map