UNPKG

rasengan

Version:

The modern React Framework

65 lines (64 loc) 2.4 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import React, { use, useMemo } from 'react'; import { generateMetadata, getRouter } from '../utils/index.js'; import { Outlet } from 'react-router'; /** * App component that represent the entry point of the application */ export const RootComponent = ({ router: AppRouterPromise, children = undefined, }) => { // Return children if they exist if (children) return children; const AppRouter = use(AppRouterPromise); // Otherwise, get the router and return it let Router = getRouter(AppRouter); return _jsx(Router, {}); }; /** * Head component * @params data - Helmet context * @returns */ export const HeadComponent = ({ metadata, assets = [], children = undefined, }) => { // Generate meta tags const metaTags = React.useMemo(() => { const metadatas = []; if (metadata) { if (metadata.page) metadatas.push(metadata.page); if (metadata.layout) metadatas.push(metadata.layout); } return generateMetadata(metadatas); }, [metadata]); const { title, description } = useMemo(() => { if (!metadata) return { title: 'Rasengan', description: '' }; const title = metadata.page.title; const description = metadata.page.description; return { title, description }; }, [metadata]); return (_jsxs("head", { children: [_jsx("meta", { name: "generator", content: "Rasengan.js" }), metaTags, assets, _jsx("title", { children: title }), _jsx("meta", { name: "description", content: description, "data-rg": "true" }), children] })); }; /** * Body component */ export const BodyComponent = ({ children = undefined, asChild = false, AppContent = undefined, }) => { return (_jsxs("body", { children: [_jsx("noscript", { dangerouslySetInnerHTML: { __html: `<b>Enable JavaScript to run this app.</b>`, } }), _jsx("div", { id: "root", children: asChild && AppContent }), children] })); }; /** * Scripts component */ export const ScriptComponent = ({ children = undefined, }) => { return _jsx(React.Fragment, { children: children }); }; /** * Default layout component */ const DefaultLayout = () => { return (_jsx(React.Fragment, { children: _jsx(Outlet, {}) })); }; DefaultLayout.path = '/'; export { DefaultLayout };