UNPKG

@lanaco/lnc-react-ui

Version:

React component library

27 lines (22 loc) 1.96 kB
"use strict";const x=require("react/jsx-runtime"),a=require("react"),E=require("./emotion-styled.browser.esm-DwHBgTPn.cjs"),S=require("./emotion-element-f0de968e.browser.esm-B7k6i6lC.cjs"),C=E.styled.section` display: flex; flex: auto; flex-direction: ${s=>s.hasSidebar?"row":"column"}; height: ${s=>s.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%; } `,f=a.forwardRef((s,h)=>{const{children:o,isChild:y,...m}=s,p=S.useTheme(),b=a.Children.toArray(o).some(e=>{var t;return e.props.__TYPE__||((t=e==null?void 0:e.type)==null?void 0:t.displayName)=="Sidebar"}),g=e=>{let t,i,l;if(a.Children.forEach(e,(r,d)=>{var u,n,_;if(r.props.__TYPE__=="Sidebar"||((u=r==null?void 0:r.type)==null?void 0:u.displayName)==="Sidebar"){if(i)throw"Found multiple ocurrences of Sidebar component on the same level in the component tree.";i=d+1}else if(r.props.__TYPE__=="PageLayout"||((n=r==null?void 0:r.type)==null?void 0:n.displayName)==="PageLayout"){if(t)throw"Found multiple ocurrences of PageLayout component on the same level in the component tree.";t=d+1}else if(r.props.__TYPE__=="Content"||((_=r==null?void 0:r.type)==null?void 0:_.displayName)==="Content"){if(l)throw"Found multiple ocurrences of Content component on the same level in the component tree.";l=d+1}}),t&&i)return i<t?"left":"right";if(l&&i)return i<l?"left":"right"},P=a.Children.map(o,e=>{var t,i;if(a.isValidElement(e)){if(e.props.__TYPE__=="Sidebar"||((t=e.type)==null?void 0:t.displayName)==="Sidebar")return a.cloneElement(e,{placement:g(o)});if(e.props.__TYPE__=="PageLayout"||((i=e.type)==null?void 0:i.displayName)==="PageLayout")return a.cloneElement(e,{isChild:!0})}return e});return x.jsx(C,{isChild:y,hasSidebar:b,theme:p,ref:h,...m,children:P})});f.displayName="PageLayout";module.exports=f;