@lanaco/lnc-react-ui
Version:
React component library
93 lines (88 loc) • 2.81 kB
JavaScript
import { jsx as E } from "react/jsx-runtime";
import { forwardRef as S, Children as d, isValidElement as T, cloneElement as y } from "react";
import { P as L } from "./index-S5Cd7WrG.js";
import { n as C } from "./emotion-styled.browser.esm-CjCaF13H.js";
import { u as Y } from "./emotion-element-f0de968e.browser.esm-CkCiQliQ.js";
const w = 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%;
}
`, p = S((i, h) => {
const { children: l, isChild: n, __TYPE__: N = "PageLayout", ...m } = i, P = Y(), 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";
}
), b = (e) => {
let t, a, s;
if (d.forEach(e, (r, o) => {
var f, u, _;
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" || ((_ = r == null ? void 0 : r.type) == null ? void 0 : _.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";
}, x = d.map(l, (e) => {
var t, a;
if (T(e)) {
if (e.props.__TYPE__ == "Sidebar" || ((t = e.type) == null ? void 0 : t.displayName) === "Sidebar")
return y(e, {
placement: b(l)
});
if (e.props.__TYPE__ == "PageLayout" || ((a = e.type) == null ? void 0 : a.displayName) === "PageLayout")
return y(e, { isChild: !0 });
}
return e;
});
return /* @__PURE__ */ E(
w,
{
isChild: n,
hasSidebar: g,
theme: P,
ref: h,
...m,
children: x
}
);
});
p.propTypes = {
/**
* Do not override this property.
* Should only be used as indicator for type if you are passing custom component.
*/
__TYPE__: L.string
};
p.displayName = "PageLayout";
export {
p as default
};