@lanaco/lnc-react-ui
Version:
React component library
85 lines (80 loc) • 2.57 kB
JavaScript
import { jsx as x } from "react/jsx-runtime";
import { forwardRef as S, Children as d, isValidElement as E, cloneElement as h } from "react";
import { s as C } from "./emotion-styled.browser.esm-DfbrHHed.js";
import { u as L } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js";
const N = C.section`
display: flex;
flex: auto;
flex-direction: ${(i) => i.hasSidebar ? "row" : "column"};
height: ${(i) => i.isChild ? "100%" : "100dvh"};
* {
box-sizing: border-box;
}
& header,
footer {
flex: 0 0 auto;
min-height: 4rem;
}
& main {
flex: auto;
overflow: hidden;
}
& aside {
flex: 0 0 15rem;
height: 100%;
}
`, T = S((i, _) => {
const { children: l, isChild: p, ...n } = i, m = L(), g = d.toArray(l).some(
(e) => {
var t;
return e.props.__TYPE__ || ((t = e == null ? void 0 : e.type) == null ? void 0 : t.displayName) == "Sidebar";
}
), P = (e) => {
let t, a, s;
if (d.forEach(e, (r, o) => {
var f, u, y;
if (r.props.__TYPE__ == "Sidebar" || ((f = r == null ? void 0 : r.type) == null ? void 0 : f.displayName) === "Sidebar") {
if (a)
throw "Found multiple ocurrences of Sidebar component on the same level in the component tree.";
a = o + 1;
} else if (r.props.__TYPE__ == "PageLayout" || ((u = r == null ? void 0 : r.type) == null ? void 0 : u.displayName) === "PageLayout") {
if (t)
throw "Found multiple ocurrences of PageLayout component on the same level in the component tree.";
t = o + 1;
} else if (r.props.__TYPE__ == "Content" || ((y = r == null ? void 0 : r.type) == null ? void 0 : y.displayName) === "Content") {
if (s)
throw "Found multiple ocurrences of Content component on the same level in the component tree.";
s = o + 1;
}
}), t && a)
return a < t ? "left" : "right";
if (s && a)
return a < s ? "left" : "right";
}, b = d.map(l, (e) => {
var t, a;
if (E(e)) {
if (e.props.__TYPE__ == "Sidebar" || ((t = e.type) == null ? void 0 : t.displayName) === "Sidebar")
return h(e, {
placement: P(l)
});
if (e.props.__TYPE__ == "PageLayout" || ((a = e.type) == null ? void 0 : a.displayName) === "PageLayout")
return h(e, { isChild: !0 });
}
return e;
});
return /* @__PURE__ */ x(
N,
{
isChild: p,
hasSidebar: g,
theme: m,
ref: _,
...n,
children: b
}
);
});
T.displayName = "PageLayout";
export {
T as default
};