UNPKG

next-nested-layout

Version:

Utility to create persistent and nested lay-outs in next-js (without the app-directory)

60 lines (53 loc) 2.31 kB
import React from 'react'; /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var LayoutNesterSymbol = Symbol("next-nested-layout"); function Root(_a) { var Component = _a.Component, pageProps = _a.pageProps; var CastComponent = Component; if ("getLayout" in Component) { return Component.getLayout({ children: React.createElement(CastComponent, __assign({}, pageProps)) }); } else { return React.createElement(CastComponent, __assign({}, pageProps)); } } function createLayout(Component, Layout, Parent) { var _Layout = (LayoutNesterSymbol in Layout ? Layout : function (props) { var CastLayout = Layout; return React.createElement(CastLayout, null, props.children); }); var NestedLayout = Parent ? function (_a) { var children = _a.children; return Parent({ children: Layout({ children: children }) }); } : _Layout; NestedLayout[LayoutNesterSymbol] = true; Component.getLayout = NestedLayout; return [Component, NestedLayout]; } export { Root, createLayout }; //# sourceMappingURL=index.esm.js.map