UNPKG

@crossed/ui

Version:

A universal & performant styling library for React Native, Next.js & React

113 lines (112 loc) 3.79 kB
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, { Group: () => Group, GroupRoot: () => GroupRoot }); module.exports = __toCommonJS(Group_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_react = require("react"); var import_core = require("@crossed/core"); var import_layout = require("../layout"); var import_styled = require("@crossed/styled"); const stylesVertical = (0, import_styled.createStyles)(() => ({ first: { base: { borderBottomWidth: 0, borderBottomLeftRadius: 0, borderBottomRightRadius: 0 } }, middle: { base: { borderBottomWidth: 0, borderRadius: 0, borderTopWidth: 0 } }, last: { base: { borderTopWidth: 0, borderTopLeftRadius: 0, borderTopRightRadius: 0 } } })); const stylesHorizontal = (0, import_styled.createStyles)(() => ({ first: { base: { borderRightWidth: 0, borderTopRightRadius: 0, borderBottomRightRadius: 0 } }, middle: { base: { borderLeftWidth: 0, borderRadius: 0, borderRightWidth: 0 } }, last: { base: { borderLeftWidth: 0, borderTopLeftRadius: 0, borderBottomLeftRadius: 0 } } })); const GroupRoot = (0, import_react.memo)( ({ orientation = "vertical", children, ...props }) => { const childrenModified = (0, import_react.useMemo)(() => { return import_react.Children.toArray(children).map((child, i, a) => { if (!(0, import_react.isValidElement)(child)) return child; const size = a.length; const isFirst = i === 0; const isLast = i === size - 1; const isMiddle = !isFirst && !isLast; const props2 = { style: (0, import_styled.composeStyles)( child.props.style, orientation === "vertical" && [ isFirst && !isLast && stylesVertical.first, isLast && !isFirst && stylesVertical.last, isMiddle && stylesVertical.middle ], orientation === "horizontal" && [ isFirst && !isLast && stylesHorizontal.first, isLast && !isFirst && stylesHorizontal.last, isMiddle && stylesHorizontal.middle ] ) }; if (child.type === import_layout.Divider) { props2.direction = orientation === "horizontal" ? "vertical" : "horizontal"; delete props2.style; } return (0, import_react.cloneElement)(child, props2); }); }, [children, orientation]); const Container = (0, import_react.useMemo)( () => orientation === "vertical" ? import_layout.YBox : import_layout.XBox, [orientation] ); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Container, { ...props, children: childrenModified }); } ); const Group = (0, import_core.withStaticProperties)(GroupRoot, {}); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Group, GroupRoot }); //# sourceMappingURL=Group.js.map