@lanaco/lnc-react-ui
Version:
React component library
27 lines (22 loc) • 2.07 kB
JavaScript
;const x=require("react/jsx-runtime"),a=require("react"),E=require("./index-BPVoEhTF.cjs"),S=require("./emotion-styled.browser.esm-Cle7tAM9.cjs"),T=require("./emotion-element-f0de968e.browser.esm-B7k6i6lC.cjs"),C=S.newStyled.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%;
}
`,u=a.forwardRef((s,f)=>{const{children:o,isChild:h,__TYPE__:c="PageLayout",...p}=s,P=T.useTheme(),g=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"}),m=e=>{let t,i,l;if(a.Children.forEach(e,(r,d)=>{var _,n,y;if(r.props.__TYPE__=="Sidebar"||((_=r==null?void 0:r.type)==null?void 0:_.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"||((y=r==null?void 0:r.type)==null?void 0:y.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"},b=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:m(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:h,hasSidebar:g,theme:P,ref:f,...p,children:b})});u.propTypes={__TYPE__:E.PropTypes.string};u.displayName="PageLayout";module.exports=u;